From 14f24c1cf3a3e80929b11451bece33198198a882 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 29 Dec 2023 10:31:45 +0000 Subject: Extract matchers for TypeOrConstructor --- .../typed/TypedStructDefinitionNodeMatcher.java | 22 ++++++++++++---------- .../org/shedlang/compiler/types/TypeMatchers.java | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 10 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/ast/typed/TypedStructDefinitionNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/typed/TypedStructDefinitionNodeMatcher.java index 54b6cac8..6bf0dcb9 100644 --- a/src/test/java/org/shedlang/compiler/ast/typed/TypedStructDefinitionNodeMatcher.java +++ b/src/test/java/org/shedlang/compiler/ast/typed/TypedStructDefinitionNodeMatcher.java @@ -4,12 +4,12 @@ import org.pcollections.PVector; import org.shedlang.compiler.testing.MatcherBuilder; import org.shedlang.compiler.types.StructType; import org.shedlang.compiler.types.TypeConstructor; -import org.shedlang.compiler.types.TypeOrConstructor; import org.shedlang.compiler.util.P; import org.zwobble.precisely.Matcher; +import static org.shedlang.compiler.types.TypeMatchers.isConstructorNotType; +import static org.shedlang.compiler.types.TypeMatchers.isTypeNotConstructor; import static org.zwobble.precisely.Matchers.has; -import static org.zwobble.precisely.Matchers.instanceOf; public class TypedStructDefinitionNodeMatcher extends MatcherBuilder< TypedNamespaceStatementNode, @@ -35,17 +35,19 @@ public class TypedStructDefinitionNodeMatcher extends MatcherBuilder< } public TypedStructDefinitionNodeMatcher withType(Matcher type) { - return with(has("typeOrConstructor", x -> x.typeOrConstructor(), instanceOf( - TypeOrConstructor.Type.class, - has("value", x -> x.value(), instanceOf(StructType.class, type)) - ))); + return with(has( + "typeOrConstructor", + x -> x.typeOrConstructor(), + isTypeNotConstructor(type) + )); } public TypedStructDefinitionNodeMatcher withTypeConstructor(Matcher> type) { - return with(has("typeOrConstructor", x -> x.typeOrConstructor(), instanceOf( - TypeOrConstructor.Constructor.class, - has("value", x -> (TypeConstructor) x.value(), type) - ))); + return with(has( + "typeOrConstructor", + x -> x.typeOrConstructor(), + isConstructorNotType(type) + )); } public TypedStructDefinitionNodeMatcher withFields( diff --git a/src/test/java/org/shedlang/compiler/types/TypeMatchers.java b/src/test/java/org/shedlang/compiler/types/TypeMatchers.java index 9b6f0d54..3f7de1ee 100644 --- a/src/test/java/org/shedlang/compiler/types/TypeMatchers.java +++ b/src/test/java/org/shedlang/compiler/types/TypeMatchers.java @@ -29,6 +29,24 @@ public class TypeMatchers { ); } + public static Matcher> isTypeNotConstructor( + Matcher type + ) { + return instanceOf( + TypeOrConstructor.Type.class, + has("value", x -> (T) x.value(), type) + ); + } + + public static Matcher> isConstructorNotType( + Matcher> typeConstructor + ) { + return instanceOf( + TypeOrConstructor.Constructor.class, + has("value", x -> (TypeConstructor) x.value(), typeConstructor) + ); + } + public static Matcher isStructTypeLevelParam( NamespaceName namespaceName, String structName, -- cgit v1.2.3