Skip to content

Commit

Permalink
Let wrong indentation produce Tree.Invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed May 6, 2024
1 parent 350c2c3 commit 3e8e6c0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
17 changes: 3 additions & 14 deletions lib/rust/parser/debug/tests/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 3e8e6c0

Please sign in to comment.