blob: ba28f4f997d22a64628d0fe7a6fecea81fe84cf9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
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
public void canParseValAsFunctionStatement() {
var source = "val x = y;";
var node = parseString(source, Parser::parseFunctionStatement);
assertThat(node, isUntypedAssignNode(
isUntypedTargetValNode("x"),
isUntypedReferenceNode("y")
));
}
@Test
public void canParseValAsNamespaceStatement() {
var source = "val x = y;";
var node = parseString(source, Parser::parseNamespaceStatement);
assertThat(node, isUntypedAssignNode(
isUntypedTargetValNode("x"),
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()
));
}
}
|