Commits

adamschmideg committed 540ae06

Test case for simple parse failure @1.5

Comments (0)

Files changed (3)

csep.tests/src/csep/tests/ParserTest.xtend

     right: NumberLiteral
       value: 1''')
 	}
+	
+	@Test
+	def void testWrongAssignment() {
+		// TODO: this should fail, not just parse partially
+		checkLine('1 = 2', '''
+NumberLiteral
+  value: 1''')
+	}
 }

csep.tests/src/csep/tests/ParserTestBase.java

 
 import org.eclipse.xtext.junit4.InjectWith;
 import org.eclipse.xtext.junit4.util.ParseHelper;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.Diagnostician;
 
 import com.google.inject.Inject;
 
   
   @Inject
   private ParseHelper<Root> parser;
+  private Diagnostician diagnostician = new Diagnostician();
   
 	public void check(final Object snippet, final Object expected)
 			throws Exception {
 		if (expected != null && snippet != null) {
 			Root root = parser.parse(snippet.toString());
-			String parsed = Helper.stringify(root).trim();
-			String expectedStr = expected.toString().trim();
-			Assert.assertEquals(expectedStr, parsed);
+			compare(root, expected);
 		}
 	}
 	
 		if (expected != null && snippet != null) {
 			Body body = (Body)parser.parse(snippet.toString());
 			Line line = body.getLines().get(0);
-			String parsed = Helper.stringify(line).trim();
-			String expectedStr = expected.toString().trim();
-			Assert.assertEquals(expectedStr, parsed);
+			compare(line, expected);
 		}
+	}	
+	
+	public void compare(EObject parseResult, Object expected) throws Exception {
+		Diagnostic issues = diagnostician.validate(parseResult);
+		if (issues.getSeverity() != Diagnostic.OK) {
+			Assert.fail(issues.getMessage());
+		}
+		String parsed = Helper.stringify(parseResult).trim();
+		String expectedStr = expected.toString().trim();
+		Assert.assertEquals(expectedStr, parsed);
 	}
 }
 * Terminals in a separate file.
   Well, [I've struggled with it][7].
 
+* Partial parsing instead of failure: `1 = 2` should fail, but it the first token gets parsed, the rest discarded without any error message.
+
   [1]: http://jevopisdeveloperblog.blogspot.com/2011/03/implement-tostring-with-xtexts.html
   [2]: http://www.eclipse.org/Xtext/documentation/2_1_0/100-serialization.php#serializationcontract 
   [3]: http://stackoverflow.com/questions/8154790/visualize-lalr-grammar