aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/shedlang/compiler/parser/ParserBreakTests.java
blob: 53031e211d0be719309c89440f409137304a621f (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
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.isOptionalEmpty;
import static org.zwobble.precisely.Matchers.isOptionalOf;

public class ParserBreakTests {
    @Test
    public void canParseBreakWithExpression() {
        var source = "break x;";

        var node = parseString(source, Parser::parseFunctionStatement);

        assertThat(node, isUntypedBreakNode(isOptionalOf(
            isUntypedReferenceNode("x"))
        ));
    }

    @Test
    public void canParseBreakWithoutExpression() {
        var source = "break;";

        var node = parseString(source, Parser::parseFunctionStatement);

        assertThat(node, isUntypedBreakNode(isOptionalEmpty()));
    }
}