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())) )) ); } }