diff options
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedReturnNodeMatcher.java | 47 | ||||
| -rw-r--r-- | src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserReturnTests.java | 25 |
2 files changed, 72 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedReturnNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedReturnNodeMatcher.java new file mode 100644 index 0000000..7825b0d --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedReturnNodeMatcher.java @@ -0,0 +1,47 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.ast.untyped; + +// Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNodeMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNodeMatcher imports + +public final class UntypedReturnNodeMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNodeMatcher isUntypedReturnNode() { + return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNodeMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNode>> submatchers; + + private UntypedReturnNodeMatcher( + java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNode>> submatchers + ) { + this.submatchers = submatchers; + } + + public org.zwobble.precisely.MatchResult match(java.lang.Object actual) { + return this.toMatcher().match(actual); + } + + public org.zwobble.precisely.TextTree describe() { + return this.toMatcher().describe(); + } + + private org.zwobble.precisely.Matcher<java.lang.Object> toMatcher() { + return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNode.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNodeMatcher withExpression(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode> expression) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNode>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("expression", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNode::expression, (org.zwobble.precisely.Matcher) expression)); + return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNodeMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNodeMatcher withSource(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.sources.Source> source) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNode>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("source", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNode::source, (org.zwobble.precisely.Matcher) source)); + return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNodeMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNodeMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNodeMatcher body +} diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserReturnTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserReturnTests.java new file mode 100644 index 0000000..64ce562 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserReturnTests.java @@ -0,0 +1,25 @@ +package org.zwobble.hobgoblin.compiler.parser; + +import org.junit.jupiter.api.Test; + +import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReferenceNodeMatcher.isUntypedReferenceNode; +import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNodeMatcher.isUntypedReturnNode; +import static org.zwobble.hobgoblin.compiler.parser.ParserTesting.parseString; +import static org.zwobble.precisely.AssertThat.assertThat; +import static org.zwobble.precisely.Matchers.equalTo; + +public class ParserReturnTests { + @Test + public void canParseReturn() { + var source = "return x;"; + + var node = parseString(source, Parser::parseStatement); + + assertThat(node, isUntypedReturnNode() + .withExpression(isUntypedReferenceNode() + .withName(equalTo("x")) + ) + ); + } +} + |
