aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/shedlang/compiler/parser
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2024-12-10 23:29:42 +0000
committerMichael Williamson <mike@zwobble.org>2024-12-10 23:29:42 +0000
commit1e6b65207e0fc3ead1edbd2bb56b1578cfc647ec (patch)
treed32151788f91a045b8172e6f2c9267ce889ab14b /src/test/java/org/shedlang/compiler/parser
parente0bbcd3fb41b54f8d72bf2d08a592def2e44d3b7 (diff)
Add basic parsing of positional struct fields
Diffstat (limited to 'src/test/java/org/shedlang/compiler/parser')
-rw-r--r--src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java29
1 files changed, 28 insertions, 1 deletions
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)
))
);
}