aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2024-01-21 19:10:39 +0000
committerMichael Williamson <mike@zwobble.org>2024-01-21 19:10:39 +0000
commit36124bbfe721aedf17089b82fcc433592366ae4e (patch)
tree640b197864343caa03d5e5de75da3f1071032de1 /src/test/java
parent8147341b40ea563e8bdabfab1a71dd9c39d72a7c (diff)
Implement Patio byte-offset-of instruction
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java
index d485e9e5..8582cfd0 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java
@@ -818,6 +818,42 @@ public abstract class PatioExampleTests {
assertThat(result, isSilentExit(47));
}
+ @Test
+ public void canGetByteOffset() throws IOException, InterruptedException {
+ var patioFunction = PatioFunctionDefinition.builder()
+ .withName(FUNCTION_NAME)
+ .withReturnType(PatioTypes.INT)
+ .addLocal(Patio.val("x", PatioTypes.INT))
+ .addBodyInstruction(Patio.byteOffsetOf(
+ Patio.localRef("x"),
+ PatioDataLayouts.struct(List.of(
+ PatioDataLayouts.struct(List.of(
+ PatioDataLayouts.BYTE,
+ PatioDataLayouts.BYTE
+ )),
+ PatioDataLayouts.struct(List.of(
+ PatioDataLayouts.BYTE,
+ PatioDataLayouts.BYTE,
+ PatioDataLayouts.BYTE,
+ PatioDataLayouts.BYTE
+ )),
+ PatioDataLayouts.BYTE
+ )),
+ List.of(1, 2)
+ ))
+ .addBodyInstruction(Patio.return_(
+ Patio.localRef("x")
+ ))
+ .build();
+ var patio = Patio.compilationUnit(List.of(
+ patioFunction
+ ));
+
+ var result = run(patio);
+
+ assertThat(result, isSilentExit(4));
+ }
+
private Matcher<ExecutionResult> isSilentExit(int exitCode) {
return allOf(
has("stderr", x -> x.stderr(), equalTo("")),