+ #40: test for mixed (Unix/Win/Mac) line endings - *TODO: test doesn't actually fail with old grammar, but a built jar does - WHY?!*

This commit is contained in:
meisl 2021-06-13 22:49:54 +02:00
parent 1468049fe9
commit 7daad57862
2 changed files with 31 additions and 2 deletions

View File

@ -68,7 +68,30 @@ class TestAntlrParser {
val parseTree = parseModule(srcGood)
assertEquals(parseTree.block().size, 2)
}
@Test
fun testWindowsAndMacNewlinesAreAlsoFine() {
val nlWin = "\r\n"
val nlUnix = "\n"
val nlMac = "\r"
// a good mix of all kinds of newlines:
val srcText =
"foo {" +
nlWin +
"}" +
nlUnix +
nlMac + // both these newlines should be "eaten up" by just one EOL token
"bar {" +
nlMac +
nlWin +
nlUnix + // all three should be "eaten up" by just one EOL token
"}"
val parseTree = parseModule(srcText)
assertEquals(parseTree.block().size, 2)
}
@Test
fun testProg8Ast() {
// can create charstreams from many other sources as well;

View File

@ -14,10 +14,16 @@ grammar prog8;
package prog8.parser;
}
//TODO: why isn't testWindowsAndMacNewlinesAreAlsoFine *failing* with this old stuff?!
// note: when we build the whole thing with it, then non-Unix newlines actually DO NOT work with it...?!
//LINECOMMENT : '\n' [ \t]* COMMENT -> channel(HIDDEN);
//COMMENT : ';' ~[\n]* -> channel(HIDDEN) ;
//EOL : '\n'+ ;
LINECOMMENT : ('\r'? '\n' | '\r') [ \t]* COMMENT -> channel(HIDDEN);
COMMENT : ';' ~[\r\n]* -> channel(HIDDEN) ;
WS : [ \t] -> skip ;
EOL : ('\r'? '\n' | '\r')+ ;
WS : [ \t] -> skip ;
// WS2 : '\\' EOL -> skip;
VOID: 'void';
NAME : [a-zA-Z][a-zA-Z0-9_]* ;