eclipse plugin: Small refactoring on test
This commit is contained in:
parent
90d6ecb8fc
commit
a62c6b2da9
3 changed files with 31 additions and 12 deletions
|
@ -1,6 +1,7 @@
|
||||||
package org.wesnoth.tests;
|
package org.wesnoth.tests;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.Reader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -139,7 +140,29 @@ public abstract class WMLTests extends AbstractXtextTests
|
||||||
*/
|
*/
|
||||||
protected IParseResult getParseResult( String input, ParserRule entryRule )
|
protected IParseResult getParseResult( String input, ParserRule entryRule )
|
||||||
{
|
{
|
||||||
return getParser( ).parse( entryRule, new StringReader( input ) );
|
return getParseResult( new StringReader( input ), entryRule );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return the parse result for an input given a specific entry rule of the
|
||||||
|
* grammar
|
||||||
|
*/
|
||||||
|
protected IParseResult getParseResult( Reader reader, ParserRule entryRule )
|
||||||
|
{
|
||||||
|
return getParser( ).parse( entryRule, reader );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check that the input can be successfully parsed given a specific entry
|
||||||
|
* rule of the grammar
|
||||||
|
*/
|
||||||
|
protected void checkParsing( Reader reader )
|
||||||
|
{
|
||||||
|
IParseResult la = getParser( ).parse( reader );;
|
||||||
|
for ( INode node : la.getSyntaxErrors( ) ) {
|
||||||
|
System.out.println( node.getSyntaxErrorMessage( ).getMessage( ) );
|
||||||
|
}
|
||||||
|
assertEquals( false, la.hasSyntaxErrors( ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -150,7 +173,7 @@ public abstract class WMLTests extends AbstractXtextTests
|
||||||
{
|
{
|
||||||
IParseResult la = getParseResult( input, entryRule );
|
IParseResult la = getParseResult( input, entryRule );
|
||||||
for ( INode node : la.getSyntaxErrors( ) ) {
|
for ( INode node : la.getSyntaxErrors( ) ) {
|
||||||
System.out.println( node.getSyntaxErrorMessage( ) );
|
System.out.println( node.getSyntaxErrorMessage( ).getMessage( ) );
|
||||||
}
|
}
|
||||||
assertEquals( input, false, la.hasSyntaxErrors( ) );
|
assertEquals( input, false, la.hasSyntaxErrors( ) );
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ package org.wesnoth.tests.grammar;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
|
|
||||||
import org.eclipse.xtext.parser.IParseResult;
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.wesnoth.tests.WMLTests;
|
import org.wesnoth.tests.WMLTests;
|
||||||
|
|
||||||
|
@ -125,10 +124,8 @@ public class WMLFilesTests extends WMLTests
|
||||||
|
|
||||||
System.out.print( "\nTesting file: " + path + "..." );
|
System.out.print( "\nTesting file: " + path + "..." );
|
||||||
|
|
||||||
IParseResult res;
|
|
||||||
try {
|
try {
|
||||||
res = getParser( ).parse( new FileReader( path ) );
|
checkParsing( new FileReader( path ) );
|
||||||
assertEquals( false, res.hasSyntaxErrors( ) );
|
|
||||||
System.out.print( " OK" );
|
System.out.print( " OK" );
|
||||||
}
|
}
|
||||||
catch ( FileNotFoundException e ) {
|
catch ( FileNotFoundException e ) {
|
||||||
|
|
|
@ -12,7 +12,6 @@ public class WMLGrammarTokensTests extends WMLTests
|
||||||
// the names of terminal rules will be capitalised
|
// the names of terminal rules will be capitalised
|
||||||
// and "RULE_" will be appended to the front
|
// and "RULE_" will be appended to the front
|
||||||
private static final String ID = "RULE_ID";
|
private static final String ID = "RULE_ID";
|
||||||
private static final String WS = "RULE_WS";
|
|
||||||
private static final String SL_COMMENT = "RULE_SL_COMMENT";
|
private static final String SL_COMMENT = "RULE_SL_COMMENT";
|
||||||
|
|
||||||
public void testID()
|
public void testID()
|
||||||
|
@ -31,13 +30,13 @@ public class WMLGrammarTokensTests extends WMLTests
|
||||||
checkTokenisation( "# comment \t\t comment\r\n", SL_COMMENT );
|
checkTokenisation( "# comment \t\t comment\r\n", SL_COMMENT );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTokenSequences()
|
public void testTokenParsing()
|
||||||
{
|
{
|
||||||
checkParsing( "amount=+$random\r\n", grammar_.getWMLKeyRule( ) );
|
checkParsing( "amount=+$random\r\n", grammar_.getWMLKeyRule( ) );
|
||||||
|
checkParsing( "name={VALUE}\n", grammar_.getWMLKeyRule( ) );
|
||||||
|
checkParsing( "{NAME}={VALUE}\n", grammar_.getWMLKeyRule( ) );
|
||||||
|
|
||||||
checkTokenisation( "123 abc", ID, WS, ID );
|
failParsing( "name=value", grammar_.getWMLKeyRule( ) );
|
||||||
checkTokenisation( "123 \t#comment\n abc", ID, WS, SL_COMMENT, WS, ID );
|
failParsing( "name=\n", grammar_.getWMLKeyRule( ) );
|
||||||
// note that no white space is necessary!
|
|
||||||
checkTokenisation( "123abc", ID );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue