diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-12-29 10:31:45 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-12-29 10:31:45 +0000 |
| commit | 14f24c1cf3a3e80929b11451bece33198198a882 (patch) | |
| tree | b5bc09ae0dd337b3ebe9f64426bbe8b7a543d2ad /src/test/java | |
| parent | 15a356d4c09944174e482b75f6dab24ca474b285 (diff) | |
Extract matchers for TypeOrConstructor
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/ast/typed/TypedStructDefinitionNodeMatcher.java | 22 | ||||
| -rw-r--r-- | src/test/java/org/shedlang/compiler/types/TypeMatchers.java | 18 |
2 files changed, 30 insertions, 10 deletions
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<? super StructType> 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<? super TypeConstructor<?>> type) { - return with(has("typeOrConstructor", x -> x.typeOrConstructor(), instanceOf( - TypeOrConstructor.Constructor.class, - has("value", x -> (TypeConstructor<StructType>) 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 <T extends StructuredType> Matcher<TypeOrConstructor<T>> isTypeNotConstructor( + Matcher<? super T> type + ) { + return instanceOf( + TypeOrConstructor.Type.class, + has("value", x -> (T) x.value(), type) + ); + } + + public static <T extends StructuredType> Matcher<TypeOrConstructor<T>> isConstructorNotType( + Matcher<? super TypeConstructor<T>> typeConstructor + ) { + return instanceOf( + TypeOrConstructor.Constructor.class, + has("value", x -> (TypeConstructor<T>) x.value(), typeConstructor) + ); + } + public static Matcher<Type> isStructTypeLevelParam( NamespaceName namespaceName, String structName, |
