blob: 3a1a2ac2bdcc0d61ad0723e9ed8da36f9cfa68d8 (
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
|
package org.shedlang.compiler.parser;
import org.junit.jupiter.api.Test;
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.*;
public class ParserTryTests {
@Test
public void canParseTry() {
var source = """
try {
1;
} handle State {
fun read() {
resume 42;
}
fun write(value) {
}
}
""";
var node = parseString(source, Parser::parseTopLevelExpression);
assertThat(
node,
isUntypedTryNode()
.withBody(isUntypedBlockNode(isSequence(
isUntypedExpressionStatementNode(isUntypedIntLiteralNode(1))
)))
.withHandledEffect(isUntypedTypeLevelReferenceNode("State"))
.withHandlerMethods(isSequence(
isUntypedTryHandlerMethodNode()
.withName("read")
.withParams(isUntypedParamsNode(isSequence(), isSequence()))
.withBody(isUntypedBlockNode(isSequence(
isUntypedResumeNode(isOptionalOf(isUntypedIntLiteralNode(42)))
))),
isUntypedTryHandlerMethodNode()
.withName("write")
.withParams(isUntypedParamsNode(
isSequence(
isUntypedParamNode("value", isOptionalEmpty())
),
isSequence()
))
.withBody(isUntypedBlockNode(isSequence()))
))
);
}
}
|