From 059d6276a4d2ef23672adb009e633a06f3603a8c Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 27 Sep 2023 20:28:09 +0100 Subject: Parse struct definition fields --- .../parser/ParserStructDefinitionTests.java | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/test/java/org/shedlang/compiler/parser') diff --git a/src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java b/src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java index 8a0fe6b6..3fd640b1 100644 --- a/src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java +++ b/src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java @@ -2,7 +2,7 @@ package org.shedlang.compiler.parser; import org.junit.jupiter.api.Test; -import static org.shedlang.compiler.ast.untyped.UntypedNodeMatchers.isUntypedStructDefinitionNode; +import static org.shedlang.compiler.ast.untyped.UntypedNodeMatchers.*; import static org.shedlang.compiler.parser.ParserTesting.parseString; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -23,4 +23,27 @@ public class ParserStructDefinitionTests { .withFields(isSequence()) ); } + + @Test + public void canParseStructWithFields() { + var source = """ + struct X(.name: String, .accessLevel: AccessLevel) {} + """; + + var node = parseString(source, Parser::parseNamespaceStatement); + + assertThat( + node, + isUntypedStructDefinitionNode() + .withName("X") + .withFields(isSequence( + isUntypedStructFieldDefinitionNode() + .withName("name") + .withType(isUntypedTypeLevelReferenceNode("String")), + isUntypedStructFieldDefinitionNode() + .withName("accessLevel") + .withType(isUntypedTypeLevelReferenceNode("AccessLevel")) + )) + ); + } } -- cgit v1.2.3