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

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

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

public class ShidCodeGenEffectDefinitionTests {
    @Test
    public void effectDefinitionIsCompiledToDefineEffectInstruction() {
        var effect = Effects.userDefined(NamespaceName.of("Example", "Project"), "State");
        var node = Typed.effectDefinition(effect);
        var context = ShidCodeGen.Context.EMPTY
            .addShedVal("State");

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

        assertThat(result.instructions(), isSequence(
            instanceOf(
                ShidDefineEffect.class,
                has("effect", x -> x.effect(), equalTo(effect))
            ),
            isShidLocalStore("State__0")
        ));
    }
}