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

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

public class ShidCodeGenTupleTests {
    @Test
    public void stringAddIsCompiledToStringAddInstruction() {
        var node = Typed.tuple(List.of(
            Typed.stringLiteral("a"),
            Typed.boolLiteral(true),
            Typed.intLiteral(4)
        ));
        var context = ShidCodeGen.Context.EMPTY;

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

        assertThat(result.instructions(), isSequence(
            isShidPushString("a"),
            isShidPushBool(true),
            isShidPushInt(4),
            isShidTupleCreate(3)
        ));
    }
}