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 --- .../compiler/ast/untyped/UntypedNodeMatchers.java | 4 +++ .../UntypedStructFieldDefinitionNodeMatcher.java | 37 ++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/test/java/org/shedlang/compiler/ast/untyped/UntypedStructFieldDefinitionNodeMatcher.java (limited to 'src/test/java/org/shedlang/compiler/ast') diff --git a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java index 95d666cd..d08e784d 100644 --- a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java +++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java @@ -198,6 +198,10 @@ public class UntypedNodeMatchers { return UntypedStructDefinitionNodeMatcher.empty(); } + public static UntypedStructFieldDefinitionNodeMatcher isUntypedStructFieldDefinitionNode() { + return UntypedStructFieldDefinitionNodeMatcher.empty(); + } + public static Matcher isUntypedSubNode( Matcher left, Matcher right diff --git a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedStructFieldDefinitionNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedStructFieldDefinitionNodeMatcher.java new file mode 100644 index 00000000..2e0f1d63 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedStructFieldDefinitionNodeMatcher.java @@ -0,0 +1,37 @@ +package org.shedlang.compiler.ast.untyped; + +import org.pcollections.PVector; +import org.shedlang.compiler.testing.MatcherBuilder; +import org.shedlang.compiler.util.P; +import org.zwobble.precisely.Matcher; + +import static org.zwobble.precisely.Matchers.equalTo; +import static org.zwobble.precisely.Matchers.has; + +public class UntypedStructFieldDefinitionNodeMatcher extends MatcherBuilder { + public static UntypedStructFieldDefinitionNodeMatcher empty() { + return new UntypedStructFieldDefinitionNodeMatcher(P.vector()); + } + + public UntypedStructFieldDefinitionNodeMatcher(PVector> submatchers) { + super(submatchers); + } + + @Override + protected Class expectedType() { + return UntypedStructFieldDefinitionNode.class; + } + + @Override + protected UntypedStructFieldDefinitionNodeMatcher create(PVector> submatchers) { + return new UntypedStructFieldDefinitionNodeMatcher(submatchers); + } + + public UntypedStructFieldDefinitionNodeMatcher withName(String name) { + return with(has("name", x -> x.name(), equalTo(name))); + } + + public UntypedStructFieldDefinitionNodeMatcher withType(Matcher type) { + return with(has("type", x -> x.type(), type)); + } +} -- cgit v1.2.3