diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-06-13 20:59:52 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-06-13 20:59:52 +0100 |
| commit | 39928746d5d65f74061aae83e0d1ace7b17a3bb3 (patch) | |
| tree | ca8bd2dce9123ce165c6824543d64f64e5d5b8ae /src/test/java/org | |
| parent | 5e90ace4f2729da69a0819d6b48968d0605def52 (diff) | |
Parse fields in sum definition
Diffstat (limited to 'src/test/java/org')
| -rw-r--r-- | src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserSumDefinitionTests.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserSumDefinitionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserSumDefinitionTests.java index 34b94fc..20de7ba 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserSumDefinitionTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserSumDefinitionTests.java @@ -6,6 +6,9 @@ import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumDefinitionNode; import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode; import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode; +import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructFieldDefinitionNodeMatcher.isUntypedStructFieldDefinitionNode; +import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumDefinitionNodeMatcher.isUntypedSumDefinitionNode; +import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNodeMatcher.isUntypedTypeLevelReferenceNode; import static org.zwobble.hobgoblin.compiler.parser.ParserTesting.parseString; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.*; @@ -82,6 +85,48 @@ public class ParserSumDefinitionTests { } @Test + public void emptySumHasNoFields() { + var source = """ + sum Shape { + }"""; + + var node = parseString( + source, + Parser::parseNamespaceStatement + ); + + assertThat(node, instanceOf( + UntypedSumDefinitionNode.class, + has("fields", UntypedSumDefinitionNode::fields, isSequence()) + )); + } + + @Test + public void sumWithFields() { + var source = """ + sum Shape { + field height: Int32; + field width: Int64; + }"""; + + var node = parseString( + source, + Parser::parseNamespaceStatement + ); + + assertThat(node, isUntypedSumDefinitionNode() + .withFields(isSequence( + isUntypedStructFieldDefinitionNode() + .withName(equalTo("height")) + .withType(isUntypedTypeLevelReferenceNode().withName(equalTo("Int32"))), + isUntypedStructFieldDefinitionNode() + .withName(equalTo("width")) + .withType(isUntypedTypeLevelReferenceNode().withName(equalTo("Int64"))) + )) + ); + } + + @Test public void sumWithDocComment() { var source = """ /// A 2D shape. |
