diff options
| author | Michael Williamson <mike@zwobble.org> | 2024-03-02 13:48:27 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2024-03-02 13:48:27 +0000 |
| commit | 8a1a44ca6e4e5307ef81e47a810cf2dfe401ffa7 (patch) | |
| tree | cb640a4b8776b8156412b0322598eb2745f2d610 /src/test/java | |
| parent | 346616ef0d875222cd50b594e91a448ab1d627a1 (diff) | |
Add test for parsing type param
Diffstat (limited to 'src/test/java')
5 files changed, 38 insertions, 17 deletions
diff --git a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java index 7ad42734..cf28b0ad 100644 --- a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java +++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java @@ -366,8 +366,11 @@ public class UntypedNodeMatchers { ); } - public static Matcher<UntypedTypeLevelParamNode> isUntypedTypeLevelParamNode(String name) { - return has("name", x -> x.name(), equalTo(name)); + public static Matcher<UntypedTypeLevelParamNode> isUntypedTypeParamNode(String name) { + return instanceOf( + UntypedTypeParamNode.class, + has("name", x -> x.name(), equalTo(name)) + ); } public static Matcher<UntypedTypeLevelExpressionNode> isUntypedTypeLevelReferenceNode(String name) { diff --git a/src/test/java/org/shedlang/compiler/parser/ParserFunctionSignatureTests.java b/src/test/java/org/shedlang/compiler/parser/ParserFunctionSignatureTests.java index 1e639069..f52b5a12 100644 --- a/src/test/java/org/shedlang/compiler/parser/ParserFunctionSignatureTests.java +++ b/src/test/java/org/shedlang/compiler/parser/ParserFunctionSignatureTests.java @@ -232,7 +232,7 @@ public class ParserFunctionSignatureTests { assertThat( node, isUntypedFunctionSignatureNode().withTypeLevelParams(isOptionalOf(isSequence( - isUntypedTypeLevelParamNode("A") + isUntypedTypeParamNode("A") ))) ); } @@ -246,9 +246,9 @@ public class ParserFunctionSignatureTests { assertThat( node, isUntypedFunctionSignatureNode().withTypeLevelParams(isOptionalOf(isSequence( - isUntypedTypeLevelParamNode("A"), - isUntypedTypeLevelParamNode("B"), - isUntypedTypeLevelParamNode("C") + isUntypedTypeParamNode("A"), + isUntypedTypeParamNode("B"), + isUntypedTypeParamNode("C") ))) ); } diff --git a/src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java b/src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java index ff8f3559..903c4c52 100644 --- a/src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java +++ b/src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java @@ -99,7 +99,7 @@ public class ParserStructDefinitionTests { node, isUntypedStructDefinitionNode() .withTypeLevelParams(isOptionalOf(isSequence( - isUntypedTypeLevelParamNode("T1") + isUntypedTypeParamNode("T1") ))) ); } @@ -116,9 +116,9 @@ public class ParserStructDefinitionTests { node, isUntypedStructDefinitionNode() .withTypeLevelParams(isOptionalOf(isSequence( - isUntypedTypeLevelParamNode("T1"), - isUntypedTypeLevelParamNode("T2"), - isUntypedTypeLevelParamNode("T3") + isUntypedTypeParamNode("T1"), + isUntypedTypeParamNode("T2"), + isUntypedTypeParamNode("T3") ))) ); } @@ -135,7 +135,7 @@ public class ParserStructDefinitionTests { node, isUntypedStructDefinitionNode() .withTypeLevelParams(isOptionalOf(isSequence( - isUntypedTypeLevelParamNode("T1") + isUntypedTypeParamNode("T1") ))) ); } diff --git a/src/test/java/org/shedlang/compiler/parser/ParserSumTypeDefinitionTests.java b/src/test/java/org/shedlang/compiler/parser/ParserSumTypeDefinitionTests.java index eb8285aa..0d593217 100644 --- a/src/test/java/org/shedlang/compiler/parser/ParserSumTypeDefinitionTests.java +++ b/src/test/java/org/shedlang/compiler/parser/ParserSumTypeDefinitionTests.java @@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test; import org.shedlang.compiler.types.Visibility; import static org.shedlang.compiler.ast.untyped.UntypedNodeMatchers.*; -import static org.shedlang.compiler.ast.untyped.UntypedNodeMatchers.isUntypedTypeLevelParamNode; +import static org.shedlang.compiler.ast.untyped.UntypedNodeMatchers.isUntypedTypeParamNode; import static org.shedlang.compiler.parser.ParserTesting.parseString; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.*; @@ -92,7 +92,7 @@ public class ParserSumTypeDefinitionTests { node, isUntypedSumTypeDefinitionNode() .withTypeLevelParams(isOptionalOf(isSequence( - isUntypedTypeLevelParamNode("T1") + isUntypedTypeParamNode("T1") ))) ); } @@ -107,9 +107,9 @@ public class ParserSumTypeDefinitionTests { node, isUntypedSumTypeDefinitionNode() .withTypeLevelParams(isOptionalOf(isSequence( - isUntypedTypeLevelParamNode("T1"), - isUntypedTypeLevelParamNode("T2"), - isUntypedTypeLevelParamNode("T3") + isUntypedTypeParamNode("T1"), + isUntypedTypeParamNode("T2"), + isUntypedTypeParamNode("T3") ))) ); } @@ -124,7 +124,7 @@ public class ParserSumTypeDefinitionTests { node, isUntypedSumTypeDefinitionNode() .withTypeLevelParams(isOptionalOf(isSequence( - isUntypedTypeLevelParamNode("T1") + isUntypedTypeParamNode("T1") ))) ); } diff --git a/src/test/java/org/shedlang/compiler/parser/ParserTypeParamTests.java b/src/test/java/org/shedlang/compiler/parser/ParserTypeParamTests.java new file mode 100644 index 00000000..3c90256c --- /dev/null +++ b/src/test/java/org/shedlang/compiler/parser/ParserTypeParamTests.java @@ -0,0 +1,18 @@ +package org.shedlang.compiler.parser; + +import org.junit.jupiter.api.Test; + +import static org.shedlang.compiler.ast.untyped.UntypedNodeMatchers.*; +import static org.shedlang.compiler.parser.ParserTesting.parseString; +import static org.zwobble.precisely.AssertThat.assertThat; + +public class ParserTypeParamTests { + @Test + public void canParseTypeParam() { + var source = "T"; + + var node = parseString(source, Parser::parseTypeLevelParam); + + assertThat(node, isUntypedTypeParamNode("T")); + } +} |
