diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-09-28 10:25:04 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-09-28 10:25:04 +0100 |
| commit | 34b02197132f215f651bb3ee3d54b16cc2fc0836 (patch) | |
| tree | 6a0b88df70893932e2119c4ba78ba706ac720201 /src/test/java/org/shedlang/compiler/ast | |
| parent | 4e34463f83f7ca08070565351df06eb06f67be94 (diff) | |
Type check struct definition fields
Diffstat (limited to 'src/test/java/org/shedlang/compiler/ast')
3 files changed, 56 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 bc5da178..82221c08 100644 --- a/src/test/java/org/shedlang/compiler/ast/typed/TypedNodeMatchers.java +++ b/src/test/java/org/shedlang/compiler/ast/typed/TypedNodeMatchers.java @@ -225,6 +225,10 @@ public class TypedNodeMatchers { return TypedStructDefinitionNodeMatcher.empty(); } + public static TypedStructFieldDefinitionNodeMatcher isTypedStructFieldDefinitionNode() { + return TypedStructFieldDefinitionNodeMatcher.empty(); + } + public static Matcher<TypedTargetNode> isTypedTargetIgnore() { return instanceOf(TypedTargetNode.Ignore.class); } diff --git a/src/test/java/org/shedlang/compiler/ast/typed/TypedStructFieldDefinitionNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/typed/TypedStructFieldDefinitionNodeMatcher.java new file mode 100644 index 00000000..f8ba23ae --- /dev/null +++ b/src/test/java/org/shedlang/compiler/ast/typed/TypedStructFieldDefinitionNodeMatcher.java @@ -0,0 +1,45 @@ +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 TypedStructFieldDefinitionNodeMatcher extends MatcherBuilder< + TypedStructFieldDefinitionNode, + TypedStructFieldDefinitionNode, + TypedStructFieldDefinitionNodeMatcher +> { + public static TypedStructFieldDefinitionNodeMatcher empty() { + return new TypedStructFieldDefinitionNodeMatcher(P.vector()); + } + + private TypedStructFieldDefinitionNodeMatcher(PVector<Matcher<? super TypedStructFieldDefinitionNode>> submatchers) { + super(submatchers); + } + + @Override + protected Class<TypedStructFieldDefinitionNode> expectedType() { + return TypedStructFieldDefinitionNode.class; + } + + @Override + protected TypedStructFieldDefinitionNodeMatcher create( + PVector<Matcher<? super TypedStructFieldDefinitionNode>> submatchers + ) { + return new TypedStructFieldDefinitionNodeMatcher(submatchers); + } + + public TypedStructFieldDefinitionNodeMatcher withName(String name) { + return with(has("name", x -> x.name(), equalTo(name))); + } + + public TypedStructFieldDefinitionNodeMatcher withType( + Matcher<TypedTypeLevelExpressionNode<?>> type + ) { + return with(has("type", x -> x.type(), type)); + } +} 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 a87b1c48..dcdb9f46 100644 --- a/src/test/java/org/shedlang/compiler/ast/untyped/Untyped.java +++ b/src/test/java/org/shedlang/compiler/ast/untyped/Untyped.java @@ -138,6 +138,13 @@ public class Untyped { return new UntypedStringLiteralNode(value, Sources.NULL); } + public static UntypedStructFieldDefinitionNode structFieldDefinition( + String name, + UntypedTypeLevelReferenceNode type + ) { + return new UntypedStructFieldDefinitionNode(name, type, Sources.NULL); + } + public static UntypedBinaryOperationNode sub( UntypedExpressionNode left, UntypedExpressionNode right |
