From 4e34463f83f7ca08070565351df06eb06f67be94 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 28 Sep 2023 10:13:17 +0100 Subject: Add basic type checking for struct definitions --- .../compiler/ast/typed/TypedNodeMatchers.java | 4 ++ .../typed/TypedStructDefinitionNodeMatcher.java | 43 ++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/test/java/org/shedlang/compiler/ast/typed/TypedStructDefinitionNodeMatcher.java (limited to 'src/test/java/org/shedlang/compiler/ast') 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 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> submatchers) { + super(submatchers); + } + + @Override + protected Class expectedType() { + return TypedStructDefinitionNode.class; + } + + @Override + protected TypedStructDefinitionNodeMatcher create(PVector> submatchers) { + return new TypedStructDefinitionNodeMatcher(submatchers); + } + + public TypedStructDefinitionNodeMatcher withName(String name) { + return with(has("name", x -> x.name(), equalTo(name))); + } + + public TypedStructDefinitionNodeMatcher withFields( + Matcher> fields + ) { + return with(has("fields", x -> x.fields(), fields)); + } +} -- cgit v1.2.3