diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-10-31 18:51:21 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-10-31 18:51:21 +0000 |
| commit | 01193de5040c7200de359ed0775b9ec5c7537ca2 (patch) | |
| tree | d71f83de1d586b215c7ac899e8aa783ef7d088ce /src/test/java | |
| parent | 375a1bfb7fbc08a55bde8866a3f67fc6e460c808 (diff) | |
Parse effect visibility
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/ast/untyped/UntypedEffectDefinitionNodeMatcher.java | 5 | ||||
| -rw-r--r-- | src/test/java/org/shedlang/compiler/parser/ParserEffectDefinitionTests.java | 29 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedEffectDefinitionNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedEffectDefinitionNodeMatcher.java index 33c64c7d..a0730475 100644 --- a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedEffectDefinitionNodeMatcher.java +++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedEffectDefinitionNodeMatcher.java @@ -2,6 +2,7 @@ package org.shedlang.compiler.ast.untyped; import org.pcollections.PVector; import org.shedlang.compiler.testing.MatcherBuilder; +import org.shedlang.compiler.types.Visibility; import org.shedlang.compiler.util.P; import org.zwobble.precisely.Matcher; @@ -38,4 +39,8 @@ public class UntypedEffectDefinitionNodeMatcher extends MatcherBuilder< public UntypedEffectDefinitionNodeMatcher withName(String name) { return with(has("name", x -> x.name(), equalTo(name))); } + + public UntypedEffectDefinitionNodeMatcher withVisibility(Visibility visibility) { + return with(has("visibility", x -> x.visibility(), equalTo(visibility))); + } } diff --git a/src/test/java/org/shedlang/compiler/parser/ParserEffectDefinitionTests.java b/src/test/java/org/shedlang/compiler/parser/ParserEffectDefinitionTests.java index e697c542..6fc623ca 100644 --- a/src/test/java/org/shedlang/compiler/parser/ParserEffectDefinitionTests.java +++ b/src/test/java/org/shedlang/compiler/parser/ParserEffectDefinitionTests.java @@ -1,6 +1,7 @@ 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.parser.ParserTesting.parseString; @@ -21,4 +22,32 @@ public class ParserEffectDefinitionTests { .withName("State") ); } + + @Test + public void defaultVisibilityIsPrivate() { + var source = """ + effect State { + }"""; + + var node = parseString(source, Parser::parseNamespaceStatement); + + assertThat( + node, + isUntypedEffectDefinitionNode().withVisibility(Visibility.PRIVATE) + ); + } + + @Test + public void whenEffectIsPrefixedWithPubThenVisibilityIsPublic() { + var source = """ + pub effect State { + }"""; + + var node = parseString(source, Parser::parseNamespaceStatement); + + assertThat( + node, + isUntypedEffectDefinitionNode().withVisibility(Visibility.PUBLIC) + ); + } } |
