Question

I have the following grammar:

grammar ru.focusmedia.fire.idl.IDL with org.eclipse.xtext.xbase.Xbase

generate idl "http://www.focusmedia.ru/fire/idl/IDL"

Model:
    'package' package=QualifiedName
    imports+=Import*
    typeDefs+=TypeDef+;

...

So the string asd should fail to parse, as should anything not starting with package. I expected ParseHelper.parse("asd") to throw an exception or to return null, but it does neither. How do I recognize that parsing failed?

Was it helpful?

Solution

You can query the resource that contains the parse result for errors by means of Resource#getErrors. Something like resultFromParseHelper.eResource().getErrors() should do the trick.

Using junit:

Assert.assertEquals(result.eResource().getErrors().toString,0,result.eResource().getErrors().size)

OTHER TIPS

Another option is to use ValidationTestHelper.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top