aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioCallTests.java
blob: 24ea7bbfd6c38b4baa98439217f9d49577871dd8 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
package org.shedlang.compiler.shidtopatio;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.shedlang.compiler.patio.operands.PatioLocalRef;
import org.shedlang.compiler.shid.instructions.Shid;
import org.shedlang.compiler.testing.snapshots.SnapshotResolver;
import org.shedlang.compiler.testing.snapshots.Snapshotter;

import java.io.IOException;
import java.util.List;

import static org.shedlang.compiler.shidtopatio.ShidToPatioTesting.serialize;

@ExtendWith({SnapshotResolver.class})
public class ShidToPatioCallTests {
    @Test
    public void canCallFunctionWithNoArgs(Snapshotter snapshotter) throws IOException {
        var instruction = Shid.call(0, List.of());
        var context = ShidToPatioContext.EMPTY
            .temporaryPush(new PatioLocalRef("other"))
            .temporaryPush(new PatioLocalRef("receiver"));

        var result = ShidToPatio.generateInstruction(instruction, context);

        snapshotter.assertSnapshot(serialize(result));
    }

    @Test
    public void canCallFunctionWithArgs(Snapshotter snapshotter) throws IOException {
        var instruction = Shid.call(2, List.of("b", "a"));
        var context = ShidToPatioContext.EMPTY
            .temporaryPush(new PatioLocalRef("other"))
            .temporaryPush(new PatioLocalRef("receiver"))
            .temporaryPush(new PatioLocalRef("pos1"))
            .temporaryPush(new PatioLocalRef("pos2"))
            .temporaryPush(new PatioLocalRef("namedB"))
            .temporaryPush(new PatioLocalRef("namedA"));

        var result = ShidToPatio.generateInstruction(instruction, context);

        snapshotter.assertSnapshot(serialize(result));
    }
}