summaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/zwobble')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserSumDefinitionTests.java45
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.