diff options
Diffstat (limited to 'src/test/java/org/shedlang/compiler/stackir')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/stackir/StackCompilerIntSubTests.java | 26 | ||||
| -rw-r--r-- | src/test/java/org/shedlang/compiler/stackir/instructions/InstructionMatchers.java | 4 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerIntSubTests.java b/src/test/java/org/shedlang/compiler/stackir/StackCompilerIntSubTests.java new file mode 100644 index 00000000..b11863c5 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/stackir/StackCompilerIntSubTests.java @@ -0,0 +1,26 @@ +package org.shedlang.compiler.stackir; + +import org.junit.jupiter.api.Test; +import org.shedlang.compiler.ast.typed.Typed; + +import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.*; +import static org.zwobble.precisely.AssertThat.assertThat; +import static org.zwobble.precisely.Matchers.isSequence; + +public class StackCompilerIntSubTests { + @Test + public void intSubIsCompiledToIntSubInstruction() { + var node = Typed.intSub( + Typed.intLiteral(42), + Typed.intLiteral(47) + ); + + var instructions = StackCompiler.compileExpression(node); + + assertThat(instructions, isSequence( + isPushIntInstruction(42), + isPushIntInstruction(47), + isIntSubInstruction() + )); + } +} diff --git a/src/test/java/org/shedlang/compiler/stackir/instructions/InstructionMatchers.java b/src/test/java/org/shedlang/compiler/stackir/instructions/InstructionMatchers.java index 201a69c2..08f02227 100644 --- a/src/test/java/org/shedlang/compiler/stackir/instructions/InstructionMatchers.java +++ b/src/test/java/org/shedlang/compiler/stackir/instructions/InstructionMatchers.java @@ -37,6 +37,10 @@ public class InstructionMatchers { return instanceOf(IntAddInstruction.class); } + public static Matcher<Instruction> isIntSubInstruction() { + return instanceOf(IntSubInstruction.class); + } + public static Matcher<Instruction> isLocalLoadInstruction(String name) { return instanceOf( LocalLoadInstruction.class, |
