aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/shedlang/compiler/parser/ParserWhileTests.java
blob: 8382f2fad2ca4d7cec0578a564e6c513ada619e0 (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
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 ParserWhileTests {
    @Test
    public void canParseWhile() {
        var source = """
            while (true) {
                f();
            }""";

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

        assertThat(node, isUntypedWhileNode(
            isUntypedBoolLiteralNode(true),
            isUntypedBlockNode(isSequence(
                isUntypedExpressionStatementNode(
                    isUntypedCallNode().withReceiver(isUntypedReferenceNode("f"))
                )
            ))
        ));
    }
}