From 6f54e6fbcda49ba481ac934f26db9add9ffe7c0d Mon Sep 17 00:00:00 2001 From: Brett Broadhurst Date: Thu, 26 Mar 2026 08:48:27 -0600 Subject: [PATCH] chore: add test cases for choice statement parsing --- src/parser_tests.zig | 85 +++++++++++++++++++ .../regression/syntax/choice-branch-mixed.ink | 11 --- .../syntax/choice-nesting-normalize.ink | 26 ------ .../regression/syntax/empty-choice-branch.ink | 9 -- testing/regression/syntax/simple-choice.ink | 18 ---- 5 files changed, 85 insertions(+), 64 deletions(-) delete mode 100644 testing/regression/syntax/choice-branch-mixed.ink delete mode 100644 testing/regression/syntax/choice-nesting-normalize.ink delete mode 100644 testing/regression/syntax/empty-choice-branch.ink delete mode 100644 testing/regression/syntax/simple-choice.ink diff --git a/src/parser_tests.zig b/src/parser_tests.zig index 9822b0c..aeecf45 100644 --- a/src/parser_tests.zig +++ b/src/parser_tests.zig @@ -105,6 +105,91 @@ test "parser: temporary assignment" { ); } +test "parser: choice statements, simple" { + try testEqual( + \\* A + \\* B + \\* C + , + \\File "" + \\`--BlockStmt + \\ `--ChoiceStmt + \\ |--ChoiceStarStmt + \\ | `--ChoiceContentExpr + \\ | `--ChoiceStartContentExpr `A` + \\ |--ChoiceStarStmt + \\ | `--ChoiceContentExpr + \\ | `--ChoiceStartContentExpr `B` + \\ `--ChoiceStarStmt + \\ `--ChoiceContentExpr + \\ `--ChoiceStartContentExpr `C` + \\ + , + ); +} + +test "parser: choice statements, empty branch" { + try testEqual( + \\* + , + \\File "" + \\`--BlockStmt + \\ `--ChoiceStmt + \\ `--ChoiceStarStmt + \\ `--ChoiceContentExpr + \\ `--EmptyString + \\ + , + ); +} + +test "parser: choice statements, level normalization" { + try testEqual( + \\***** A + \\**** B + \\*** C + \\** D + \\* E + , + \\File "" + \\`--BlockStmt + \\ `--ChoiceStmt + \\ |--ChoiceStarStmt + \\ | `--ChoiceContentExpr + \\ | `--ChoiceStartContentExpr `A` + \\ |--ChoiceStarStmt + \\ | `--ChoiceContentExpr + \\ | `--ChoiceStartContentExpr `B` + \\ |--ChoiceStarStmt + \\ | `--ChoiceContentExpr + \\ | `--ChoiceStartContentExpr `C` + \\ |--ChoiceStarStmt + \\ | `--ChoiceContentExpr + \\ | `--ChoiceStartContentExpr `D` + \\ `--ChoiceStarStmt + \\ `--ChoiceContentExpr + \\ `--ChoiceStartContentExpr `E` + \\ + , + ); +} + +test "parser: choice statements, mixed context" { + try testEqual( + \\* A[]B + , + \\File "" + \\`--BlockStmt + \\ `--ChoiceStmt + \\ `--ChoiceStarStmt + \\ `--ChoiceContentExpr + \\ |--ChoiceStartContentExpr `A` + \\ `--ChoiceInnerContentExpr `B` + \\ + , + ); +} + test "parser: simple knot" { try testEqual( \\=== knot === diff --git a/testing/regression/syntax/choice-branch-mixed.ink b/testing/regression/syntax/choice-branch-mixed.ink deleted file mode 100644 index ece24ca..0000000 --- a/testing/regression/syntax/choice-branch-mixed.ink +++ /dev/null @@ -1,11 +0,0 @@ -// RUN: %ink-compiler --stdin --compile-only --dump-ast < %s | FileCheck %s - -// CHECK: File "" -// CHECK-NEXT: `--BlockStmt -// CHECK-NEXT: `--ChoiceStmt -// CHECK-NEXT: `--ChoiceStarStmt -// CHECK-NEXT: `--ChoiceContentExpr -// CHECK-NEXT: |--ChoiceStartContentExpr `A` -// CHECK-NEXT: `--ChoiceInnerContentExpr `B` - -* A[]B diff --git a/testing/regression/syntax/choice-nesting-normalize.ink b/testing/regression/syntax/choice-nesting-normalize.ink deleted file mode 100644 index 384f461..0000000 --- a/testing/regression/syntax/choice-nesting-normalize.ink +++ /dev/null @@ -1,26 +0,0 @@ -// RUN: %ink-compiler --stdin --compile-only --dump-ast < %s | FileCheck %s - -// CHECK: File "" -// CHECK-NEXT: `--BlockStmt -// CHECK-NEXT: `--ChoiceStmt -// CHECK-NEXT: |--ChoiceStarStmt -// CHECK-NEXT: | `--ChoiceContentExpr -// CHECK-NEXT: | `--ChoiceStartContentExpr `A` -// CHECK-NEXT: |--ChoiceStarStmt -// CHECK-NEXT: | `--ChoiceContentExpr -// CHECK-NEXT: | `--ChoiceStartContentExpr `B` -// CHECK-NEXT: |--ChoiceStarStmt -// CHECK-NEXT: | `--ChoiceContentExpr -// CHECK-NEXT: | `--ChoiceStartContentExpr `C` -// CHECK-NEXT: |--ChoiceStarStmt -// CHECK-NEXT: | `--ChoiceContentExpr -// CHECK-NEXT: | `--ChoiceStartContentExpr `D` -// CHECK-NEXT: `--ChoiceStarStmt -// CHECK-NEXT: `--ChoiceContentExpr -// CHECK-NEXT: `--ChoiceStartContentExpr `E` - -***** A -**** B -*** C -** D -* E diff --git a/testing/regression/syntax/empty-choice-branch.ink b/testing/regression/syntax/empty-choice-branch.ink deleted file mode 100644 index 1b98e2f..0000000 --- a/testing/regression/syntax/empty-choice-branch.ink +++ /dev/null @@ -1,9 +0,0 @@ -// RUN: %ink-compiler --stdin --compile-only --dump-ast < %s | FileCheck %s - -// CHECK: File "" -// CHECK-NEXT: `--BlockStmt -// CHECK-NEXT: `--ChoiceStmt -// CHECK-NEXT: `--ChoiceStarStmt -// CHECK-NEXT: `--ChoiceContentExpr - -* diff --git a/testing/regression/syntax/simple-choice.ink b/testing/regression/syntax/simple-choice.ink deleted file mode 100644 index 25cd253..0000000 --- a/testing/regression/syntax/simple-choice.ink +++ /dev/null @@ -1,18 +0,0 @@ -// RUN: %ink-compiler --stdin --compile-only --dump-ast < %s | FileCheck %s - -// CHECK: File "" -// CHECK-NEXT: `--BlockStmt -// CHECK-NEXT: `--ChoiceStmt -// CHECK-NEXT: |--ChoiceStarStmt -// CHECK-NEXT: | `--ChoiceContentExpr -// CHECK-NEXT: | `--ChoiceStartContentExpr `A` -// CHECK-NEXT: |--ChoiceStarStmt -// CHECK-NEXT: | `--ChoiceContentExpr -// CHECK-NEXT: | `--ChoiceStartContentExpr `B` -// CHECK-NEXT: `--ChoiceStarStmt -// CHECK-NEXT: `--ChoiceContentExpr -// CHECK-NEXT: `--ChoiceStartContentExpr `C` - -* A -* B -* C