diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-02 16:28:03 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-02 16:35:19 +0100 |
| commit | 00a97675f5f6cef672495371a6b7e36a372586ab (patch) | |
| tree | ccb46f9848feab63db4cc8dd75e97f7f5e857807 /src/test/java/org/zwobble | |
| parent | 9127c59648ffc3f8606aceff4d5e3fdcbe96413b (diff) | |
Parse sum variant boxing
Diffstat (limited to 'src/test/java/org/zwobble')
4 files changed, 66 insertions, 24 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedSumVariantDefinitionNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedSumVariantDefinitionNodeMatcher.java index 9f28f26..721a7ea 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedSumVariantDefinitionNodeMatcher.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedSumVariantDefinitionNodeMatcher.java @@ -34,6 +34,12 @@ public class UntypedSumVariantDefinitionNodeMatcher implements org.zwobble.preci return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNodeMatcher(submatchers); } + public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNodeMatcher withIsBox(org.zwobble.precisely.Matcher<? super java.lang.Boolean> isBox) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("isBox", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode::isBox, isBox)); + return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNodeMatcher(submatchers); + } + public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNodeMatcher withSource(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.sources.Source> source) { var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode>>(this.submatchers); submatchers.add(org.zwobble.precisely.Matchers.has("source", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode::source, source)); diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaBooleanLiteralMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaBooleanLiteralMatcher.java index 56308d4..80583b0 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaBooleanLiteralMatcher.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaBooleanLiteralMatcher.java @@ -28,7 +28,7 @@ public class JavaBooleanLiteralMatcher implements org.zwobble.precisely.Matcher< return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaBooleanLiteral.class, this.submatchers); } - public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaBooleanLiteralMatcher withValue(org.zwobble.precisely.Matcher<? super Boolean> value) { + public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaBooleanLiteralMatcher withValue(org.zwobble.precisely.Matcher<? super java.lang.Boolean> value) { var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaBooleanLiteral>>(this.submatchers); submatchers.add(org.zwobble.precisely.Matchers.has("value", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaBooleanLiteral::value, value)); return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaBooleanLiteralMatcher(submatchers); diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserEnumDefinitionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserEnumDefinitionTests.java index 925077f..b7b03fa 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserEnumDefinitionTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserEnumDefinitionTests.java @@ -1,17 +1,13 @@ package org.zwobble.hobgoblin.compiler.parser; import org.junit.jupiter.api.Test; -import org.zwobble.hobgoblin.compiler.ast.DocComment; -import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumDefinitionNode; import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumDefinitionNodeMatcher.isUntypedEnumDefinitionNode; import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumVariantDefinitionNodeMatcher.isUntypedEnumVariantDefinitionNode; -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.*; +import static org.zwobble.precisely.Matchers.equalTo; +import static org.zwobble.precisely.Matchers.isSequence; public class ParserEnumDefinitionTests { @Test @@ -66,21 +62,4 @@ public class ParserEnumDefinitionTests { )) ); } - - @Test - public void enumWithDocComment() { - var source = """ - /// A small number. - enum SmallNumber { - }"""; - - var node = parseString( - source, - Parser::parseNamespaceStatement - ); - - assertThat(node, isUntypedEnumDefinitionNode() - .withDocComment(equalTo(new DocComment("A small number.\n"))) - ); - } } 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 20de7ba..1a13bff 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserSumDefinitionTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserSumDefinitionTests.java @@ -6,8 +6,10 @@ 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.UntypedEnumDefinitionNodeMatcher.isUntypedEnumDefinitionNode; 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.UntypedSumVariantDefinitionNodeMatcher.isUntypedSumVariantDefinitionNode; 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; @@ -85,6 +87,61 @@ public class ParserSumDefinitionTests { } @Test + public void variantIsNotBoxedByDefault() { + var source = """ + sum Shape { + variant Rectangle; + }"""; + + var node = parseString( + source, + Parser::parseNamespaceStatement + ); + + assertThat(node, isUntypedSumDefinitionNode() + .withVariants(isSequence( + isUntypedSumVariantDefinitionNode().withIsBox(equalTo(false)) + )) + ); + } + + @Test + public void variantIsBoxedWhenAnnotatedWithBox() { + var source = """ + sum Shape { + variant Rectangle box; + }"""; + + var node = parseString( + source, + Parser::parseNamespaceStatement + ); + + assertThat(node, isUntypedSumDefinitionNode() + .withVariants(isSequence( + isUntypedSumVariantDefinitionNode().withIsBox(equalTo(true)) + )) + ); + } + + @Test + public void enumWithDocComment() { + var source = """ + /// A small number. + enum SmallNumber { + }"""; + + var node = parseString( + source, + Parser::parseNamespaceStatement + ); + + assertThat(node, isUntypedEnumDefinitionNode() + .withDocComment(equalTo(new DocComment("A small number.\n"))) + ); + } + + @Test public void emptySumHasNoFields() { var source = """ sum Shape { |
