aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/shedlang/compiler/shid/ShidCodeGenBreakTests.java
blob: aa931f9e31f3e91c8551952e757b21722d2026ae (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.shid;

import org.junit.jupiter.api.Test;
import org.shedlang.compiler.ast.typed.Typed;
import org.shedlang.compiler.types.Effects;
import org.shedlang.compiler.types.NamespaceName;
import org.shedlang.compiler.types.UserDefinedEffect;

import static org.shedlang.compiler.shid.instructions.ShidMatchers.*;
import static org.zwobble.precisely.AssertThat.assertThat;
import static org.zwobble.precisely.Matchers.isSequence;

public class ShidCodeGenBreakTests {
    private static final NamespaceName NAMESPACE_NAME = NamespaceName.of("Example");
    private static final UserDefinedEffect EFFECT = Effects.userDefined(NAMESPACE_NAME, "Effect");

    @Test
    public void expressionIsEvaluatedAndReturned() {
        var node = Typed.break_(EFFECT, Typed.stringLiteral("hello"));
        var context = ShidCodeGen.Context.EMPTY;

        var result = ShidCodeGen.compileFunctionStatement(node, context);

        assertThat(result.instructions(), isSequence(
            isShidPushString("hello"),
            isShidEffectHandlerBreak(EFFECT)
        ));
    }
}