From 3e8e6c04e585df85fb0ca19867aba7fda65fa348 Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Mon, 6 May 2024 05:05:29 +0200 Subject: [PATCH] Let wrong indentation produce Tree.Invalid --- .../enso/compiler/core/EnsoParserTest.java | 23 ++++++++++++++++--- lib/rust/parser/debug/tests/parse.rs | 17 +++----------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/engine/runtime-parser/src/test/java/org/enso/compiler/core/EnsoParserTest.java b/engine/runtime-parser/src/test/java/org/enso/compiler/core/EnsoParserTest.java index 92f0d00c9657..fc7deedc0e1b 100644 --- a/engine/runtime-parser/src/test/java/org/enso/compiler/core/EnsoParserTest.java +++ b/engine/runtime-parser/src/test/java/org/enso/compiler/core/EnsoParserTest.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.function.Function; import org.enso.compiler.core.ir.Module; +import org.enso.compiler.core.ir.expression.errors.Syntax; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -1432,15 +1433,31 @@ public void ise_184219679() throws IOException { """); } - private static void parseTest(String code) throws IOException { - parseTest(code, true, true, true); + @Test + public void testWrongIndentation() throws IOException { + var code = """ + group = + space4 + space8 + space5 + """; + var ir = parseTest(code); + var errors = ir.preorder().filter((node) -> node instanceof Syntax); + assertEquals(1, errors.size()); + var first = (Syntax) errors.head(); + assertEquals(Syntax.UnexpectedExpression$.MODULE$, first.reason()); + } + + private static IR parseTest(String code) throws IOException { + return parseTest(code, true, true, true); } @SuppressWarnings("unchecked") - private static void parseTest(String code, boolean noIds, boolean noLocations, boolean lessDocs) + private static IR parseTest(String code, boolean noIds, boolean noLocations, boolean lessDocs) throws IOException { var ir = compile(code); assertNotNull(ir); + return ir; } private static void equivalenceTest(String code1, String code2) throws IOException { diff --git a/lib/rust/parser/debug/tests/parse.rs b/lib/rust/parser/debug/tests/parse.rs index cdb8f038d8a1..942b6f390b01 100644 --- a/lib/rust/parser/debug/tests/parse.rs +++ b/lib/rust/parser/debug/tests/parse.rs @@ -669,30 +669,19 @@ fn code_block_empty() { #[test] fn code_block_bad_indents1() { let code = ["main =", " foo", " bar", " baz"]; - let expected = block![ - (Function (Ident main) #() () "=" (BodyBlock #((Ident foo) (Ident bar) (Ident baz)))) - ]; - test(&code.join("\n"), expected); + expect_invalid_node(&code.join("\n")); } #[test] fn fail_on_bad_indents() { let code = ["group =", " space4", " space8", " space5"]; - - let expected = block![ - (Function (Ident group) #() () "=" (BodyBlock #((ArgumentBlockApplication (Ident space4) #((Ident space8) (Ident space5)))))) - ]; - test(&code.join("\n"), expected); + expect_invalid_node(&code.join("\n")); } #[test] fn code_block_bad_indents2() { let code = ["main =", " foo", " bar", "baz"]; - let expected = block![ - (Function (Ident main) #() () "=" (BodyBlock #((Ident foo) (Ident bar)))) - (Ident baz) - ]; - test(&code.join("\n"), expected); + expect_invalid_node(&code.join("\n")); } #[test]