diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-09-28 10:13:17 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-09-28 10:13:17 +0100 |
| commit | 4e34463f83f7ca08070565351df06eb06f67be94 (patch) | |
| tree | cbbd43b41e1e2b5a04f7217fd6edf1f3a4aa8a26 /src/test/java/org/shedlang/compiler/ast | |
| parent | bc0bbc8fa0d48c1c87244e45908290c4b723d757 (diff) | |
Add basic type checking for struct definitions
Diffstat (limited to 'src/test/java/org/shedlang/compiler/ast')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/ast/typed/TypedNodeMatchers.java | 4 | ||||
| -rw-r--r-- | src/test/java/org/shedlang/compiler/ast/typed/TypedStructDefinitionNodeMatcher.java | 43 |
2 files changed, 47 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/ast/typed/TypedNodeMatchers.java b/src/test/java/org/shedlang/compiler/ast/typed/TypedNodeMatchers.java index 52d91cdf..bc5da178 100644 --- a/src/test/java/org/shedlang/compiler/ast/typed/TypedNodeMatchers.java +++ b/src/test/java/org/shedlang/compiler/ast/typed/TypedNodeMatchers.java @@ -221,6 +221,10 @@ public class TypedNodeMatchers { ); } + public static TypedStructDefinitionNodeMatcher isTypedStructDefinitionNode() { + return TypedStructDefinitionNodeMatcher.empty(); + } + public static Matcher<TypedTargetNode> isTypedTargetIgnore() { return instanceOf(TypedTargetNode.Ignore.class); } diff --git a/src/test/java/org/shedlang/compiler/ast/typed/TypedStructDefinitionNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/typed/TypedStructDefinitionNodeMatcher.java new file mode 100644 index 00000000..489fb558 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/ast/typed/TypedStructDefinitionNodeMatcher.java @@ -0,0 +1,43 @@ +package org.shedlang.compiler.ast.typed; + +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 TypedStructDefinitionNodeMatcher extends MatcherBuilder< + TypedNamespaceStatementNode, + TypedStructDefinitionNode, + TypedStructDefinitionNodeMatcher +> { + public static TypedStructDefinitionNodeMatcher empty() { + return new TypedStructDefinitionNodeMatcher(P.vector()); + } + + private TypedStructDefinitionNodeMatcher(PVector<Matcher<? super TypedStructDefinitionNode>> submatchers) { + super(submatchers); + } + + @Override + protected Class<TypedStructDefinitionNode> expectedType() { + return TypedStructDefinitionNode.class; + } + + @Override + protected TypedStructDefinitionNodeMatcher create(PVector<Matcher<? super TypedStructDefinitionNode>> submatchers) { + return new TypedStructDefinitionNodeMatcher(submatchers); + } + + public TypedStructDefinitionNodeMatcher withName(String name) { + return with(has("name", x -> x.name(), equalTo(name))); + } + + public TypedStructDefinitionNodeMatcher withFields( + Matcher<Iterable<? extends TypedStructFieldDefinitionNode>> fields + ) { + return with(has("fields", x -> x.fields(), fields)); + } +} |
