diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-10-22 13:32:01 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-10-22 13:32:17 +0100 |
| commit | f3bcdfe21627f64c11abda54596eb1388caa74e7 (patch) | |
| tree | 7608ee3c1d03272fc4b7ebf1477c51b1600ac1e4 /src/test/java | |
| parent | 296fa6ee9ee63089603c8bb13bb7d3346f85a037 (diff) | |
Add visibility for structs
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/ast/untyped/UntypedStructDefinitionNodeMatcher.java | 5 | ||||
| -rw-r--r-- | src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java | 25 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedStructDefinitionNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedStructDefinitionNodeMatcher.java index 5a73f49b..98bb535f 100644 --- a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedStructDefinitionNodeMatcher.java +++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedStructDefinitionNodeMatcher.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; @@ -34,4 +35,8 @@ public class UntypedStructDefinitionNodeMatcher extends MatcherBuilder<UntypedNa public UntypedStructDefinitionNodeMatcher withFields(Matcher<Iterable<? extends UntypedStructFieldDefinitionNode>> fields) { return with(has("fields", x -> x.fields(), fields)); } + + public UntypedStructDefinitionNodeMatcher withVisibility(Visibility visibility) { + return with(has("visibility", x -> x.visibility(), equalTo(visibility))); + } } diff --git a/src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java b/src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java index 3fd640b1..cfe3e58e 100644 --- a/src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java +++ b/src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.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.*; import static org.shedlang.compiler.parser.ParserTesting.parseString; @@ -46,4 +47,28 @@ public class ParserStructDefinitionTests { )) ); } + + @Test + public void defaultVisibilityIsPrivate() { + var source = "struct X() {}"; + + var node = parseString(source, Parser::parseNamespaceStatement); + + assertThat( + node, + isUntypedStructDefinitionNode().withVisibility(Visibility.PRIVATE) + ); + } + + @Test + public void whenHasPubPrefixThenVisibilityIsPublic() { + var source = "pub struct X() {}"; + + var node = parseString(source, Parser::parseNamespaceStatement); + + assertThat( + node, + isUntypedStructDefinitionNode().withVisibility(Visibility.PUBLIC) + ); + } } |
