aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioNamespaceFieldStoreTests.java
blob: 436bd92cb5445e2cdd9acb3f4547ea6bc62c7925 (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
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 org.shedlang.compiler.typechecker.TypeCheckerContext;
import org.shedlang.compiler.types.NamespaceName;
import org.shedlang.compiler.types.NamespaceTypeInfo;
import org.shedlang.compiler.types.Types;

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

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

@ExtendWith({SnapshotResolver.class})
public class ShidToPatioNamespaceFieldStoreTests {
    @Test
    public void canGenerateCodeForNamespaceFieldStore(Snapshotter snapshotter) throws IOException {
        var namespaceName = new NamespaceName(List.of("Example", "Project"));
        var shidInstruction = Shid.namespaceFieldStore(namespaceName, "y");
        var typeInfo = TypeCheckerContext.EMPTY
            .addNamespaceTypeInfo(
                namespaceName,
                NamespaceTypeInfo.builder()
                    .addField("x", Types.INT)
                    .addField("y", Types.INT)
                    .addField("z", Types.INT)
                    .build()
            )
            .toTypeInfos();
        var context = ShidToPatioTesting.createContext(typeInfo)
            .temporaryPush(new PatioLocalRef("a"))
            .temporaryPush(new PatioLocalRef("b"));

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

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