From 1e6b65207e0fc3ead1edbd2bb56b1578cfc647ec Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 10 Dec 2024 23:29:42 +0000 Subject: Add basic parsing of positional struct fields --- .../parser/ParserStructDefinitionTests.java | 29 +++++++++++++++++++++- 1 file changed, 28 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 903c4c52..4f0698ad 100644 --- a/src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java +++ b/src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java @@ -40,10 +40,37 @@ public class ParserStructDefinitionTests { .withFields(isSequence( isUntypedStructFieldDefinitionNode() .withName("name") - .withType(isUntypedTypeLevelReferenceNode("String")), + .withType(isUntypedTypeLevelReferenceNode("String")) + .withIsPositional(false), isUntypedStructFieldDefinitionNode() .withName("accessLevel") .withType(isUntypedTypeLevelReferenceNode("AccessLevel")) + .withIsPositional(false) + )) + ); + } + + @Test + public void canParseStructWithPositionalFields() { + 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")) + .withIsPositional(true), + isUntypedStructFieldDefinitionNode() + .withName("accessLevel") + .withType(isUntypedTypeLevelReferenceNode("AccessLevel")) + .withIsPositional(true) )) ); } -- cgit v1.2.3