Search code examples
junitwhitespacextextxtend

Xtext: Testing whitespace language - missing RULE_BEGIN in JUnit


I have this fancy white space language and I'm traing to test it. For now grammar is simple (base on Terminals)

Model:
  {Model}
BEGIN
    package=PackageDeclaration?
    class=ClassDeclaration?
END
methods+=MethodDeclaration*
;

PackageDeclaration: 'package' name=ID;
ClassDeclaration: 'class' name=ID;
MethodDeclaration: 'def' name=ID;

terminal BEGIN:
    'synthetic:BEGIN';

terminal END:
    'synthetic:END';

And now when it comes to JUnit:

@Test
def void packageSimpleNoErrors() {
    val result = '''

        package testPack
        '''.parse
    // Parsed without errors
    result.assertNoErrors
}

Multiline string is 2x new line, tab, 'package testPack' and new line. Checked with debug in parse method.

If I put it this way in Eclipse editor it is completly fine, no problems. But I can't make JUnit to pass this test:

java.lang.AssertionError: Expected no errors, 
but got :ERROR (org.eclipse.xtext.diagnostics.Diagnostic.Syntax) 
'missing RULE_BEGIN at 'package’’ on PackageDeclaration, 
ERROR (org.eclipse.xtext.diagnostics.Diagnostic.Syntax) 
'mismatched input '<EOF>' expecting RULE_END' on Model

For now it's not a show stoper as rest of test on this code are looking fine, but I prefer to have them all green :)

Thanks


Solution

  • the problem is that rich stings empty lines get lost by intent. maybe you should read the model from a file or try something

    '''
    «"\n"»
        package testPack
    '''.parse