From b09fce67753e199d4ae0fe6138f909b5e3413208 Mon Sep 17 00:00:00 2001 From: Mel Date: Tue, 5 Jul 2022 22:15:29 +0200 Subject: Fix nested if block compiling --- pkg/lang/compiler/compiler_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'pkg/lang/compiler/compiler_test.go') 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() -- cgit 1.4.1