From 375a1bfb7fbc08a55bde8866a3f67fc6e460c808 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 31 Oct 2023 18:49:10 +0000 Subject: Parse empty effect definitions --- .../UntypedEffectDefinitionNodeMatcher.java | 41 ++++++++++++++++++++++ .../compiler/ast/untyped/UntypedNodeMatchers.java | 4 +++ .../parser/ParserEffectDefinitionTests.java | 24 +++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 src/test/java/org/shedlang/compiler/ast/untyped/UntypedEffectDefinitionNodeMatcher.java create mode 100644 src/test/java/org/shedlang/compiler/parser/ParserEffectDefinitionTests.java (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedEffectDefinitionNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedEffectDefinitionNodeMatcher.java new file mode 100644 index 00000000..33c64c7d --- /dev/null +++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedEffectDefinitionNodeMatcher.java @@ -0,0 +1,41 @@ +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.equalTo; +import static org.zwobble.precisely.Matchers.has; + +public class UntypedEffectDefinitionNodeMatcher extends MatcherBuilder< + UntypedNamespaceStatementNode, + UntypedEffectDefinitionNode, + UntypedEffectDefinitionNodeMatcher +> { + public static UntypedEffectDefinitionNodeMatcher empty() { + return new UntypedEffectDefinitionNodeMatcher(P.vector()); + } + + public UntypedEffectDefinitionNodeMatcher( + PVector> submatchers + ) { + super(submatchers); + } + + @Override + protected Class expectedType() { + return UntypedEffectDefinitionNode.class; + } + + @Override + protected UntypedEffectDefinitionNodeMatcher create( + PVector> submatchers + ) { + return new UntypedEffectDefinitionNodeMatcher(submatchers); + } + + public UntypedEffectDefinitionNodeMatcher withName(String name) { + return with(has("name", x -> x.name(), equalTo(name))); + } +} 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 4810f7e7..cadf11f8 100644 --- a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java +++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java @@ -84,6 +84,10 @@ public class UntypedNodeMatchers { ); } + public static UntypedEffectDefinitionNodeMatcher isUntypedEffectDefinitionNode() { + return UntypedEffectDefinitionNodeMatcher.empty(); + } + public static Matcher isUntypedEqualsNode( Matcher left, Matcher right diff --git a/src/test/java/org/shedlang/compiler/parser/ParserEffectDefinitionTests.java b/src/test/java/org/shedlang/compiler/parser/ParserEffectDefinitionTests.java new file mode 100644 index 00000000..e697c542 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/parser/ParserEffectDefinitionTests.java @@ -0,0 +1,24 @@ +package org.shedlang.compiler.parser; + +import org.junit.jupiter.api.Test; + +import static org.shedlang.compiler.ast.untyped.UntypedNodeMatchers.isUntypedEffectDefinitionNode; +import static org.shedlang.compiler.parser.ParserTesting.parseString; +import static org.zwobble.precisely.AssertThat.assertThat; + +public class ParserEffectDefinitionTests { + @Test + public void canParseEffectWithNoFunctions() { + var source = """ + effect State { + }"""; + + var node = parseString(source, Parser::parseNamespaceStatement); + + assertThat( + node, + isUntypedEffectDefinitionNode() + .withName("State") + ); + } +} -- cgit v1.2.3