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;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -139,7 +140,29 @@ public abstract class WMLTests extends AbstractXtextTests
|
|||
*/
|
||||
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 );
|
||||
for ( INode node : la.getSyntaxErrors( ) ) {
|
||||
System.out.println( node.getSyntaxErrorMessage( ) );
|
||||
System.out.println( node.getSyntaxErrorMessage( ).getMessage( ) );
|
||||
}
|
||||
assertEquals( input, false, la.hasSyntaxErrors( ) );
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ package org.wesnoth.tests.grammar;
|
|||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.eclipse.xtext.parser.IParseResult;
|
||||
import org.junit.Ignore;
|
||||
import org.wesnoth.tests.WMLTests;
|
||||
|
||||
|
@ -125,10 +124,8 @@ public class WMLFilesTests extends WMLTests
|
|||
|
||||
System.out.print( "\nTesting file: " + path + "..." );
|
||||
|
||||
IParseResult res;
|
||||
try {
|
||||
res = getParser( ).parse( new FileReader( path ) );
|
||||
assertEquals( false, res.hasSyntaxErrors( ) );
|
||||
checkParsing( new FileReader( path ) );
|
||||
System.out.print( " OK" );
|
||||
}
|
||||
catch ( FileNotFoundException e ) {
|
||||
|
|
|
@ -12,7 +12,6 @@ public class WMLGrammarTokensTests extends WMLTests
|
|||
// the names of terminal rules will be capitalised
|
||||
// and "RULE_" will be appended to the front
|
||||
private static final String ID = "RULE_ID";
|
||||
private static final String WS = "RULE_WS";
|
||||
private static final String SL_COMMENT = "RULE_SL_COMMENT";
|
||||
|
||||
public void testID()
|
||||
|
@ -31,13 +30,13 @@ public class WMLGrammarTokensTests extends WMLTests
|
|||
checkTokenisation( "# comment \t\t comment\r\n", SL_COMMENT );
|
||||
}
|
||||
|
||||
public void testTokenSequences()
|
||||
public void testTokenParsing()
|
||||
{
|
||||
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 );
|
||||
checkTokenisation( "123 \t#comment\n abc", ID, WS, SL_COMMENT, WS, ID );
|
||||
// note that no white space is necessary!
|
||||
checkTokenisation( "123abc", ID );
|
||||
failParsing( "name=value", grammar_.getWMLKeyRule( ) );
|
||||
failParsing( "name=\n", grammar_.getWMLKeyRule( ) );
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue