From de320dfc664bc926686938e75ef4a9c6d42c947c Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 11 Dec 2024 20:34:14 +0000 Subject: Parse empty inline extend --- .../untyped/UntypedExtendInlineNodeMatcher.java | 44 ++++++++++++++++++++++ .../compiler/ast/untyped/UntypedNodeMatchers.java | 4 ++ .../compiler/parser/ParserExtendInlineTests.java | 25 ++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 src/test/java/org/shedlang/compiler/ast/untyped/UntypedExtendInlineNodeMatcher.java create mode 100644 src/test/java/org/shedlang/compiler/parser/ParserExtendInlineTests.java (limited to 'src/test/java') 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> submatchers) { + super(submatchers); + } + + @Override + protected Class expectedType() { + return UntypedExtendInlineNode.class; + } + + @Override + protected UntypedExtendInlineNodeMatcher create( + PVector> submatchers + ) { + return new UntypedExtendInlineNodeMatcher(submatchers); + } + + public UntypedExtendInlineNodeMatcher withExtendedType( + Matcher 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 isUntypedFieldAccessNode( Matcher 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")) + ); + } +} -- cgit v1.2.3