diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-10-31 19:09:16 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-10-31 19:09:16 +0000 |
| commit | 7a72d57dae13ab993baaa77f54023c062e56025d (patch) | |
| tree | 66399c2e1e96c9d1fd3797d26d7efd08d532511d /src/test/java/org/shedlang/compiler/parser | |
| parent | 01193de5040c7200de359ed0775b9ec5c7537ca2 (diff) | |
Parse effect functions
Diffstat (limited to 'src/test/java/org/shedlang/compiler/parser')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/parser/ParserEffectDefinitionTests.java | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/src/test/java/org/shedlang/compiler/parser/ParserEffectDefinitionTests.java b/src/test/java/org/shedlang/compiler/parser/ParserEffectDefinitionTests.java index 6fc623ca..03204719 100644 --- a/src/test/java/org/shedlang/compiler/parser/ParserEffectDefinitionTests.java +++ b/src/test/java/org/shedlang/compiler/parser/ParserEffectDefinitionTests.java @@ -3,13 +3,14 @@ package org.shedlang.compiler.parser; import org.junit.jupiter.api.Test; import org.shedlang.compiler.types.Visibility; -import static org.shedlang.compiler.ast.untyped.UntypedNodeMatchers.isUntypedEffectDefinitionNode; +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 ParserEffectDefinitionTests { @Test - public void canParseEffectWithNoFunctions() { + public void canParseEffectName() { var source = """ effect State { }"""; @@ -50,4 +51,52 @@ public class ParserEffectDefinitionTests { isUntypedEffectDefinitionNode().withVisibility(Visibility.PUBLIC) ); } + + @Test + public void canParseEffectWithNoFunctions() { + var source = """ + effect State { + }"""; + + var node = parseString(source, Parser::parseNamespaceStatement); + + assertThat( + node, + isUntypedEffectDefinitionNode() + .withFunctions(isSequence()) + ); + } + + @Test + public void canParseEffectFunctions() { + var source = """ + effect State { + fun get() -> Int; + fun set(Int) -> Unit; + }"""; + + var node = parseString(source, Parser::parseNamespaceStatement); + + assertThat( + node, + isUntypedEffectDefinitionNode() + .withFunctions(isSequence( + isUntypedEffectDefinitionFunctionNode( + "get", + isUntypedFunctionTypeNode() + .withParams(isUntypedFunctionTypeParamsNode(isSequence(), isSequence())) + .withReturnType(isUntypedTypeLevelReferenceNode("Int")) + ), + isUntypedEffectDefinitionFunctionNode( + "set", + isUntypedFunctionTypeNode() + .withParams(isUntypedFunctionTypeParamsNode( + isSequence(isUntypedTypeLevelReferenceNode("Int")), + isSequence() + )) + .withReturnType(isUntypedTypeLevelReferenceNode("Unit")) + ) + )) + ); + } } |
