diff options
| author | Michael Williamson <mike@zwobble.org> | 2024-12-11 20:34:14 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2024-12-11 20:34:14 +0000 |
| commit | de320dfc664bc926686938e75ef4a9c6d42c947c (patch) | |
| tree | 316ddd7073aed3452683763fc4239e978c2b90f6 /src/test/java | |
| parent | 525a4c6576c287cdaaeced4e4f1f53bb82515ad9 (diff) | |
Parse empty inline extend
Diffstat (limited to 'src/test/java')
3 files changed, 73 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedExtendInlineNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedExtendInlineNodeMatcher.java new file mode 100644 index 00000000..d8dc26a1 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedExtendInlineNodeMatcher.java @@ -0,0 +1,44 @@ +package org.shedlang.compiler.ast.untyped; + +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.has; + +public class UntypedExtendInlineNodeMatcher extends MatcherBuilder< + UntypedNamespaceStatementNode, + UntypedExtendInlineNode, + UntypedExtendInlineNodeMatcher +> { + public static UntypedExtendInlineNodeMatcher empty() { + return new UntypedExtendInlineNodeMatcher(P.vector()); + } + + public UntypedExtendInlineNodeMatcher(PVector<Matcher<? super UntypedExtendInlineNode>> submatchers) { + super(submatchers); + } + + @Override + protected Class<UntypedExtendInlineNode> expectedType() { + return UntypedExtendInlineNode.class; + } + + @Override + protected UntypedExtendInlineNodeMatcher create( + PVector<Matcher<? super UntypedExtendInlineNode>> submatchers + ) { + return new UntypedExtendInlineNodeMatcher(submatchers); + } + + public UntypedExtendInlineNodeMatcher withExtendedType( + Matcher<UntypedTypeLevelExpressionNode> extendedType + ) { + return with(has( + "extendedType", + x -> x.extendedType(), + extendedType + )); + } +} 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 e0597387..6e98a788 100644 --- a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java +++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java @@ -141,6 +141,10 @@ public class UntypedNodeMatchers { ); } + public static UntypedExtendInlineNodeMatcher isUntypedExtendInlineNode() { + return UntypedExtendInlineNodeMatcher.empty(); + } + public static Matcher<UntypedExpressionNode> isUntypedFieldAccessNode( Matcher<UntypedExpressionNode> receiver, String fieldName diff --git a/src/test/java/org/shedlang/compiler/parser/ParserExtendInlineTests.java b/src/test/java/org/shedlang/compiler/parser/ParserExtendInlineTests.java new file mode 100644 index 00000000..75030e4b --- /dev/null +++ b/src/test/java/org/shedlang/compiler/parser/ParserExtendInlineTests.java @@ -0,0 +1,25 @@ +package org.shedlang.compiler.parser; + +import org.junit.jupiter.api.Test; + +import static org.shedlang.compiler.ast.untyped.UntypedNodeMatchers.isUntypedExtendInlineNode; +import static org.shedlang.compiler.ast.untyped.UntypedNodeMatchers.isUntypedTypeLevelReferenceNode; +import static org.shedlang.compiler.parser.ParserTesting.parseString; +import static org.zwobble.precisely.AssertThat.assertThat; + +public class ParserExtendInlineTests { + @Test + public void canParseExtendInlineWithNoMethods() { + var source = """ + extend Count {} + """; + + var node = parseString(source, Parser::parseNamespaceStatement); + + assertThat( + node, + isUntypedExtendInlineNode() + .withExtendedType(isUntypedTypeLevelReferenceNode("Count")) + ); + } +} |
