Author: timotei
Date: Sat Jul 30 09:48:14 2011
New Revision: 50467
URL: http://svn.gna.org/viewcvs/wesnoth?rev=50467&view=rev
Log:
eclipse plugin: Small refactoring on test
Modified:
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/tests/WMLTests.java
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/tests/grammar/WMLFilesTests.java
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/tests/grammar/WMLGrammarTokensTests.java
Modified: trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/tests/WMLTests.java
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/tests/WMLTests.java?rev=50467&r1=50466&r2=50467&view=diff
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/tests/WMLTests.java
(original)
+++ trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/tests/WMLTests.java Sat Jul
30 09:48:14 2011
@@ -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,18 +140,40 @@
*/
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( ) );
+ }
+
+ /**
+ * check that the input can be successfully parsed given a specific entry
+ * rule of the grammar
+ */
protected void checkParsing( String input, ParserRule entryRule )
{
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( ) );
}
Modified:
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/tests/grammar/WMLFilesTests.java
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/tests/grammar/WMLFilesTests.java?rev=50467&r1=50466&r2=50467&view=diff
==============================================================================
---
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/tests/grammar/WMLFilesTests.java
(original)
+++
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/tests/grammar/WMLFilesTests.java
Sat Jul 30 09:48:14 2011
@@ -11,7 +11,6 @@
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 @@
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 ) {
Modified:
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/tests/grammar/WMLGrammarTokensTests.java
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/tests/grammar/WMLGrammarTokensTests.java?rev=50467&r1=50466&r2=50467&view=diff
==============================================================================
---
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/tests/grammar/WMLGrammarTokensTests.java
(original)
+++
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/tests/grammar/WMLGrammarTokensTests.java
Sat Jul 30 09:48:14 2011
@@ -12,7 +12,6 @@
// 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 @@
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( ) );
}
}
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits