aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
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
parente0bbcd3fb41b54f8d72bf2d08a592def2e44d3b7 (diff)
Add basic parsing of positional struct fields
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/ast/untyped/Untyped.java2
-rw-r--r--src/test/java/org/shedlang/compiler/ast/untyped/UntypedStructFieldDefinitionNodeMatcher.java4
-rw-r--r--src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java29
3 files changed, 33 insertions, 2 deletions
diff --git a/src/test/java/org/shedlang/compiler/ast/untyped/Untyped.java b/src/test/java/org/shedlang/compiler/ast/untyped/Untyped.java
index 2eacfade..43e8154c 100644
--- a/src/test/java/org/shedlang/compiler/ast/untyped/Untyped.java
+++ b/src/test/java/org/shedlang/compiler/ast/untyped/Untyped.java
@@ -189,7 +189,7 @@ public class Untyped {
String name,
UntypedTypeLevelExpressionNode type
) {
- return new UntypedStructFieldDefinitionNode(name, type, Sources.NULL);
+ return new UntypedStructFieldDefinitionNode(name, type, false, Sources.NULL);
}
public static UntypedBinaryOperationNode sub(
diff --git a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedStructFieldDefinitionNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedStructFieldDefinitionNodeMatcher.java
index 2e0f1d63..5ca0d994 100644
--- a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedStructFieldDefinitionNodeMatcher.java
+++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedStructFieldDefinitionNodeMatcher.java
@@ -34,4 +34,8 @@ public class UntypedStructFieldDefinitionNodeMatcher extends MatcherBuilder<Unty
public UntypedStructFieldDefinitionNodeMatcher withType(Matcher<UntypedTypeLevelExpressionNode> type) {
return with(has("type", x -> x.type(), type));
}
+
+ public UntypedStructFieldDefinitionNodeMatcher withIsPositional(boolean isPositional) {
+ return with(has("isPositional", x -> x.isPositional(), equalTo(isPositional)));
+ }
}
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)
))
);
}