aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/shedlang/compiler/parser
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-11-02 18:59:09 +0000
committerMichael Williamson <mike@zwobble.org>2023-11-02 19:00:09 +0000
commit71544066ce3b74c18973e00348ea44faf052d5e5 (patch)
tree305635d30c993db52a75512c37704aa60424b1a3 /src/test/java/org/shedlang/compiler/parser
parent7f6bc2dcceb75538993af15167ca291db63107a8 (diff)
Parse try expressions
Diffstat (limited to 'src/test/java/org/shedlang/compiler/parser')
-rw-r--r--src/test/java/org/shedlang/compiler/parser/ParserTryTests.java42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/parser/ParserTryTests.java b/src/test/java/org/shedlang/compiler/parser/ParserTryTests.java
new file mode 100644
index 00000000..951fd687
--- /dev/null
+++ b/src/test/java/org/shedlang/compiler/parser/ParserTryTests.java
@@ -0,0 +1,42 @@
+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.isSequence;
+
+public class ParserTryTests {
+ @Test
+ public void canParseTry() {
+ var source = """
+ try {
+ 1;
+ } handle State {
+ fun read() {
+ }
+
+ fun write() {
+ }
+ }
+ """;
+
+ var node = parseString(source, Parser::parseTopLevelExpression);
+
+ assertThat(
+ node,
+ isUntypedTryNode()
+ .withBody(isUntypedBlockNode(isSequence(
+ isUntypedExpressionStatementNode(isUntypedIntLiteralNode(1))
+ )))
+ .withHandledEffect(isUntypedTypeLevelReferenceNode("State"))
+ .withHandlers(isSequence(
+ isUntypedFunctionDefinitionNode()
+ .withName("read"),
+ isUntypedFunctionDefinitionNode()
+ .withName("write")
+ ))
+ );
+ }
+}