From 1468049fe9f4eab862b33d057fd60728f4ba950e Mon Sep 17 00:00:00 2001 From: meisl Date: Sun, 13 Jun 2021 20:47:14 +0200 Subject: [PATCH] + #40: test that (module-level) blocks *before the last* still must have a newline after their closing `}` --- compilerAst/test/TestAntlrParser.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/compilerAst/test/TestAntlrParser.kt b/compilerAst/test/TestAntlrParser.kt index b58f91e2b..ada57937e 100644 --- a/compilerAst/test/TestAntlrParser.kt +++ b/compilerAst/test/TestAntlrParser.kt @@ -54,6 +54,21 @@ class TestAntlrParser { assertEquals(parseTree.block().size, 1) } + @Test + fun testAllBlocksButLastMustEndWithNewline() { + val nl = "\n" // say, Unix-style (different flavours tested elsewhere) + + // BAD: 2nd block `bar` does NOT start on new line; however, there's is a nl at the very end + val srcBad = "foo {" + nl + "}" + " bar {" + nl + "}" + nl + + // GOOD: 2nd block `bar` does start on a new line; however, a nl at the very end ain't needed + val srcGood = "foo {" + nl + "}" + nl + "bar {" + nl + "}" + + assertFailsWith { parseModule(srcBad) } + val parseTree = parseModule(srcGood) + assertEquals(parseTree.block().size, 2) + } + @Test fun testProg8Ast() { // can create charstreams from many other sources as well;