aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2024-12-11 20:51:26 +0000
committerMichael Williamson <mike@zwobble.org>2024-12-11 20:51:26 +0000
commit85e0fc7a603e832205a7eef34930e8901fefd77d (patch)
tree1326f656d7250890e61eea9559cbf37a993e34a2 /src/test/java
parentde320dfc664bc926686938e75ef4a9c6d42c947c (diff)
Parse methods in extend inline node
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/ast/untyped/UntypedExtendInlineNodeMatcher.java10
-rw-r--r--src/test/java/org/shedlang/compiler/parser/ParserExtendInlineTests.java26
2 files changed, 34 insertions, 2 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
index d8dc26a1..1c82f937 100644
--- a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedExtendInlineNodeMatcher.java
+++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedExtendInlineNodeMatcher.java
@@ -41,4 +41,14 @@ public class UntypedExtendInlineNodeMatcher extends MatcherBuilder<
extendedType
));
}
+
+ public UntypedExtendInlineNodeMatcher withMethods(
+ Matcher<Iterable<? extends UntypedFunctionDefinitionNode>> methods
+ ) {
+ return with(has(
+ "methods",
+ x -> x.methods(),
+ methods
+ ));
+ }
}
diff --git a/src/test/java/org/shedlang/compiler/parser/ParserExtendInlineTests.java b/src/test/java/org/shedlang/compiler/parser/ParserExtendInlineTests.java
index 75030e4b..6652a46e 100644
--- a/src/test/java/org/shedlang/compiler/parser/ParserExtendInlineTests.java
+++ b/src/test/java/org/shedlang/compiler/parser/ParserExtendInlineTests.java
@@ -2,10 +2,10 @@ 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.ast.untyped.UntypedNodeMatchers.*;
import static org.shedlang.compiler.parser.ParserTesting.parseString;
import static org.zwobble.precisely.AssertThat.assertThat;
+import static org.zwobble.precisely.Matchers.isSequence;
public class ParserExtendInlineTests {
@Test
@@ -20,6 +20,28 @@ public class ParserExtendInlineTests {
node,
isUntypedExtendInlineNode()
.withExtendedType(isUntypedTypeLevelReferenceNode("Count"))
+ .withMethods(isSequence())
+ );
+ }
+
+ @Test
+ public void canParseExtendInlineWithSingleMethod() {
+ var source = """
+ extend Count {
+ fun message(this) {
+ }
+ }
+ """;
+
+ var node = parseString(source, Parser::parseNamespaceStatement);
+
+ assertThat(
+ node,
+ isUntypedExtendInlineNode()
+ .withExtendedType(isUntypedTypeLevelReferenceNode("Count"))
+ .withMethods(isSequence(
+ isUntypedFunctionDefinitionNode().withName("message")
+ ))
);
}
}