about summary refs log tree commit diff
path: root/pkg/lang/compiler/compiler_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/lang/compiler/compiler_test.go')
-rw-r--r--pkg/lang/compiler/compiler_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/pkg/lang/compiler/compiler_test.go b/pkg/lang/compiler/compiler_test.go
index a6a1ba7..88413c7 100644
--- a/pkg/lang/compiler/compiler_test.go
+++ b/pkg/lang/compiler/compiler_test.go
@@ -203,6 +203,37 @@ func TestIfNoElse(t *testing.T) {
 	mustCompileTo(t, src, expected)
 }
 
+func TestNestedIfs(t *testing.T) {
+	src := `
+	if true {
+		if false {
+			1
+		} else {
+			2
+		}
+	}
+	`
+
+	expected := `
+	push_true
+	jf @end
+
+	push_false
+	jf @else
+
+	push_int 1
+	jmp @end
+
+	@else:
+	push_int 2
+	
+	@end:
+	halt
+	`
+
+	mustCompileTo(t, src, expected)
+}
+
 func mustCompileTo(t *testing.T, src, expected string) {
 	scanner := scanner.New(strings.NewReader(src))
 	tokens, err := scanner.Scan()