From 71544066ce3b74c18973e00348ea44faf052d5e5 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 2 Nov 2023 18:59:09 +0000 Subject: Parse try expressions --- .../shedlang/compiler/parser/ParserTryTests.java | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/test/java/org/shedlang/compiler/parser/ParserTryTests.java (limited to 'src/test/java/org/shedlang/compiler/parser') 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") + )) + ); + } +} -- cgit v1.2.3