chore: add test cases for choice statement parsing

This commit is contained in:
Brett Broadhurst 2026-03-26 08:48:27 -06:00
parent 7afc6719d9
commit 6f54e6fbcd
Failed to generate hash of commit
5 changed files with 85 additions and 64 deletions

View file

@ -105,6 +105,91 @@ test "parser: temporary assignment" {
); );
} }
test "parser: choice statements, simple" {
try testEqual(
\\* A
\\* B
\\* C
,
\\File "<STDIN>"
\\`--BlockStmt <line:1, line:3>
\\ `--ChoiceStmt <line:1, line:3>
\\ |--ChoiceStarStmt <line:1, col:1:4>
\\ | `--ChoiceContentExpr <col:3, col:4>
\\ | `--ChoiceStartContentExpr `A` <col:3, col:4>
\\ |--ChoiceStarStmt <line:2, col:1:4>
\\ | `--ChoiceContentExpr <col:3, col:4>
\\ | `--ChoiceStartContentExpr `B` <col:3, col:4>
\\ `--ChoiceStarStmt <line:3, col:1:4>
\\ `--ChoiceContentExpr <col:3, col:4>
\\ `--ChoiceStartContentExpr `C` <col:3, col:4>
\\
,
);
}
test "parser: choice statements, empty branch" {
try testEqual(
\\*
,
\\File "<STDIN>"
\\`--BlockStmt <line:1, line:1>
\\ `--ChoiceStmt <line:1, line:1>
\\ `--ChoiceStarStmt <line:1, col:1:2>
\\ `--ChoiceContentExpr <col:2, col:2>
\\ `--EmptyString <col:2, col:2>
\\
,
);
}
test "parser: choice statements, level normalization" {
try testEqual(
\\***** A
\\**** B
\\*** C
\\** D
\\* E
,
\\File "<STDIN>"
\\`--BlockStmt <line:1, line:5>
\\ `--ChoiceStmt <line:1, line:5>
\\ |--ChoiceStarStmt <line:1, col:1:8>
\\ | `--ChoiceContentExpr <col:7, col:8>
\\ | `--ChoiceStartContentExpr `A` <col:7, col:8>
\\ |--ChoiceStarStmt <line:2, col:1:7>
\\ | `--ChoiceContentExpr <col:6, col:7>
\\ | `--ChoiceStartContentExpr `B` <col:6, col:7>
\\ |--ChoiceStarStmt <line:3, col:1:6>
\\ | `--ChoiceContentExpr <col:5, col:6>
\\ | `--ChoiceStartContentExpr `C` <col:5, col:6>
\\ |--ChoiceStarStmt <line:4, col:1:5>
\\ | `--ChoiceContentExpr <col:4, col:5>
\\ | `--ChoiceStartContentExpr `D` <col:4, col:5>
\\ `--ChoiceStarStmt <line:5, col:1:4>
\\ `--ChoiceContentExpr <col:3, col:4>
\\ `--ChoiceStartContentExpr `E` <col:3, col:4>
\\
,
);
}
test "parser: choice statements, mixed context" {
try testEqual(
\\* A[]B
,
\\File "<STDIN>"
\\`--BlockStmt <line:1, line:1>
\\ `--ChoiceStmt <line:1, line:1>
\\ `--ChoiceStarStmt <line:1, col:1:7>
\\ `--ChoiceContentExpr <col:3, col:7>
\\ |--ChoiceStartContentExpr `A` <col:3, col:4>
\\ `--ChoiceInnerContentExpr `B` <col:6, col:7>
\\
,
);
}
test "parser: simple knot" { test "parser: simple knot" {
try testEqual( try testEqual(
\\=== knot === \\=== knot ===

View file

@ -1,11 +0,0 @@
// RUN: %ink-compiler --stdin --compile-only --dump-ast < %s | FileCheck %s
// CHECK: File "<STDIN>"
// CHECK-NEXT: `--BlockStmt <line:11, line:11>
// CHECK-NEXT: `--ChoiceStmt <line:11, line:11>
// CHECK-NEXT: `--ChoiceStarStmt <line:11, col:1:7>
// CHECK-NEXT: `--ChoiceContentExpr <col:3, col:7>
// CHECK-NEXT: |--ChoiceStartContentExpr `A` <col:3, col:4>
// CHECK-NEXT: `--ChoiceInnerContentExpr `B` <col:6, col:7>
* A[]B

View file

@ -1,26 +0,0 @@
// RUN: %ink-compiler --stdin --compile-only --dump-ast < %s | FileCheck %s
// CHECK: File "<STDIN>"
// CHECK-NEXT: `--BlockStmt <line:22, line:26>
// CHECK-NEXT: `--ChoiceStmt <line:22, line:26>
// CHECK-NEXT: |--ChoiceStarStmt <line:22, col:1:8>
// CHECK-NEXT: | `--ChoiceContentExpr <col:7, col:8>
// CHECK-NEXT: | `--ChoiceStartContentExpr `A` <col:7, col:8>
// CHECK-NEXT: |--ChoiceStarStmt <line:23, col:1:7>
// CHECK-NEXT: | `--ChoiceContentExpr <col:6, col:7>
// CHECK-NEXT: | `--ChoiceStartContentExpr `B` <col:6, col:7>
// CHECK-NEXT: |--ChoiceStarStmt <line:24, col:1:6>
// CHECK-NEXT: | `--ChoiceContentExpr <col:5, col:6>
// CHECK-NEXT: | `--ChoiceStartContentExpr `C` <col:5, col:6>
// CHECK-NEXT: |--ChoiceStarStmt <line:25, col:1:5>
// CHECK-NEXT: | `--ChoiceContentExpr <col:4, col:5>
// CHECK-NEXT: | `--ChoiceStartContentExpr `D` <col:4, col:5>
// CHECK-NEXT: `--ChoiceStarStmt <line:26, col:1:4>
// CHECK-NEXT: `--ChoiceContentExpr <col:3, col:4>
// CHECK-NEXT: `--ChoiceStartContentExpr `E` <col:3, col:4>
***** A
**** B
*** C
** D
* E

View file

@ -1,9 +0,0 @@
// RUN: %ink-compiler --stdin --compile-only --dump-ast < %s | FileCheck %s
// CHECK: File "<STDIN>"
// CHECK-NEXT: `--BlockStmt <line:9, line:9>
// CHECK-NEXT: `--ChoiceStmt <line:9, line:9>
// CHECK-NEXT: `--ChoiceStarStmt <line:9, col:1:2>
// CHECK-NEXT: `--ChoiceContentExpr <col:2, col:2>
*

View file

@ -1,18 +0,0 @@
// RUN: %ink-compiler --stdin --compile-only --dump-ast < %s | FileCheck %s
// CHECK: File "<STDIN>"
// CHECK-NEXT: `--BlockStmt <line:16, line:18>
// CHECK-NEXT: `--ChoiceStmt <line:16, line:18>
// CHECK-NEXT: |--ChoiceStarStmt <line:16, col:1:4>
// CHECK-NEXT: | `--ChoiceContentExpr <col:3, col:4>
// CHECK-NEXT: | `--ChoiceStartContentExpr `A` <col:3, col:4>
// CHECK-NEXT: |--ChoiceStarStmt <line:17, col:1:4>
// CHECK-NEXT: | `--ChoiceContentExpr <col:3, col:4>
// CHECK-NEXT: | `--ChoiceStartContentExpr `B` <col:3, col:4>
// CHECK-NEXT: `--ChoiceStarStmt <line:18, col:1:4>
// CHECK-NEXT: `--ChoiceContentExpr <col:3, col:4>
// CHECK-NEXT: `--ChoiceStartContentExpr `C` <col:3, col:4>
* A
* B
* C