diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-10-22 13:16:44 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-10-22 13:16:44 +0100 |
| commit | 5831a308f4d8f9e83821fffff67a2141cc76d26b (patch) | |
| tree | ac57df32c229f745b4d38b88c29bb1a1896d5c47 /src/test/java | |
| parent | 21c2c5075467151be765b4e77e59d876d258b0c1 (diff) | |
Parse visibility for vals
Diffstat (limited to 'src/test/java')
3 files changed, 39 insertions, 2 deletions
diff --git a/src/test/java/org/shedlang/compiler/ast/untyped/Untyped.java b/src/test/java/org/shedlang/compiler/ast/untyped/Untyped.java index 3e925601..9e4ac8cd 100644 --- a/src/test/java/org/shedlang/compiler/ast/untyped/Untyped.java +++ b/src/test/java/org/shedlang/compiler/ast/untyped/Untyped.java @@ -2,6 +2,7 @@ package org.shedlang.compiler.ast.untyped; import org.shedlang.compiler.sources.Sources; import org.shedlang.compiler.types.NamespaceName; +import org.shedlang.compiler.types.Visibility; import java.math.BigInteger; import java.util.List; @@ -181,7 +182,7 @@ public class Untyped { } public static UntypedTargetNode targetVal(String name) { - return new UntypedTargetNode.Val(name, Sources.NULL); + return new UntypedTargetNode.Val(name, Visibility.PRIVATE, Sources.NULL); } public static UntypedTargetNode targetVar(String 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 6d426bf4..26716e3d 100644 --- a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java +++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java @@ -1,6 +1,7 @@ package org.shedlang.compiler.ast.untyped; import org.shedlang.compiler.types.NamespaceName; +import org.shedlang.compiler.types.Visibility; import org.zwobble.precisely.Matcher; import java.math.BigInteger; @@ -20,7 +21,7 @@ public class UntypedNodeMatchers { public static Matcher<UntypedNode> isUntypedAssignNode( Matcher<UntypedTargetNode> target, - Matcher<UntypedExpressionNode> expression + Matcher<? super UntypedExpressionNode> expression ) { return instanceOf( UntypedAssignNode.class, @@ -254,6 +255,15 @@ public class UntypedNodeMatchers { ); } + public static Matcher<UntypedTargetNode> isUntypedTargetValNode( + Visibility visibility + ) { + return instanceOf( + UntypedTargetNode.Val.class, + has("visibility", x -> x.visibility(), equalTo(visibility)) + ); + } + public static Matcher<UntypedTargetNode> isUntypedTargetVarNode(String name) { return instanceOf( UntypedTargetNode.Var.class, diff --git a/src/test/java/org/shedlang/compiler/parser/ParserValTests.java b/src/test/java/org/shedlang/compiler/parser/ParserValTests.java index 6b01fc17..ba28f4f9 100644 --- a/src/test/java/org/shedlang/compiler/parser/ParserValTests.java +++ b/src/test/java/org/shedlang/compiler/parser/ParserValTests.java @@ -1,10 +1,12 @@ 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.*; import static org.shedlang.compiler.parser.ParserTesting.parseString; import static org.zwobble.precisely.AssertThat.assertThat; +import static org.zwobble.precisely.Matchers.anything; public class ParserValTests { @Test @@ -30,4 +32,28 @@ public class ParserValTests { isUntypedReferenceNode("y") )); } + + @Test + public void defaultVisibilityIsPrivate() { + var source = "val x = y;"; + + var node = parseString(source, Parser::parseNamespaceStatement); + + assertThat(node, isUntypedAssignNode( + isUntypedTargetValNode(Visibility.PRIVATE), + anything() + )); + } + + @Test + public void whenValIsPrefixWithPubThenVisibilityIsPublic() { + var source = "pub val x = y;"; + + var node = parseString(source, Parser::parseNamespaceStatement); + + assertThat(node, isUntypedAssignNode( + isUntypedTargetValNode(Visibility.PUBLIC), + anything() + )); + } } |
