blob: f3ca07a0c747da817bd49c401a60987e8759452e (
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
45
46
47
|
package org.shedlang.compiler.shidtopatio;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
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.TypeInfos;
import org.shedlang.compiler.types.*;
import java.io.IOException;
import static org.shedlang.compiler.shidtopatio.ShidToPatioTesting.serialize;
@ExtendWith({SnapshotResolver.class})
public class ShidToPatioDefineEffectTests {
@Test
public void canGenerateCodeForDefineEffect(Snapshotter snapshotter) throws IOException {
var effect = Effects.userDefined(NamespaceName.of("Example", "Project"), "State");
var instruction = Shid.defineEffect(effect);
var typeInfos = TypeInfos.EMPTY
.addUserDefinedEffectInfo(
effect,
UserDefinedEffectInfo.builder()
.addMethod(
"read",
FunctionType.builder()
.addNamedParam("fence", Types.BOOL)
.withReturnType(Types.INT)
.build()
)
.addMethod(
"write",
FunctionType.builder()
.addPositionalParam(Types.INT)
.withReturnType(Types.UNIT)
.build()
)
.build()
);
var context = ShidToPatioTesting.createContext(typeInfos);
var result = ShidToPatio.generateInstruction(instruction, context);
snapshotter.assertSnapshot(serialize(result));
}
}
|