summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserStructDefinitionTests.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserStructDefinitionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserStructDefinitionTests.java
index 8c692fd..9dae394 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserStructDefinitionTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserStructDefinitionTests.java
@@ -2,6 +2,8 @@ package org.zwobble.hobgoblin.compiler.parser;
import org.junit.jupiter.api.Test;
import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructDefinitionNode;
+import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructFieldDefinitionNode;
+import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode;
import static org.zwobble.hobgoblin.compiler.parser.ParserTesting.parseString;
import static org.zwobble.precisely.AssertThat.assertThat;
@@ -24,4 +26,48 @@ public class ParserStructDefinitionTests {
has("name", UntypedStructDefinitionNode::name, equalTo("Point"))
));
}
+
+ @Test
+ public void structWithFields() {
+ var source = """
+ struct Point {
+ field x: Int;
+ field y: Int;
+ }""";
+
+ var node = parseString(
+ source,
+ Parser::parseNamespaceStatement
+ );
+
+ assertThat(node, instanceOf(
+ UntypedStructDefinitionNode.class,
+ has("fields", UntypedStructDefinitionNode::fields, isSequence(
+ instanceOf(
+ UntypedStructFieldDefinitionNode.class,
+ has("name", UntypedStructFieldDefinitionNode::name, equalTo("x")),
+ has(
+ "type",
+ UntypedStructFieldDefinitionNode::type,
+ instanceOf(
+ UntypedTypeLevelReferenceNode.class,
+ has("name", UntypedTypeLevelReferenceNode::name, equalTo("Int"))
+ )
+ )
+ ),
+ instanceOf(
+ UntypedStructFieldDefinitionNode.class,
+ has("name", UntypedStructFieldDefinitionNode::name, equalTo("y")),
+ has(
+ "type",
+ UntypedStructFieldDefinitionNode::type,
+ instanceOf(
+ UntypedTypeLevelReferenceNode.class,
+ has("name", UntypedTypeLevelReferenceNode::name, equalTo("Int"))
+ )
+ )
+ )
+ ))
+ ));
+ }
}