about summary refs log tree commit diff
path: root/pkg/lang/vm/text/compiler_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/lang/vm/text/compiler_test.go')
-rw-r--r--pkg/lang/vm/text/compiler_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/pkg/lang/vm/text/compiler_test.go b/pkg/lang/vm/text/compiler_test.go
index 237e884..56b886d 100644
--- a/pkg/lang/vm/text/compiler_test.go
+++ b/pkg/lang/vm/text/compiler_test.go
@@ -129,6 +129,35 @@ func TestLabels(t *testing.T) {
 	require.Equal(t, joinSlices(parts), res.Code())
 }
 
+func TestDebugInfo(t *testing.T) {
+	src := `
+	push_int 1
+	push_int 2
+
+	add
+	add
+	
+	@1:
+		nop
+		ret
+	`
+
+	c := text.NewCompiler(strings.NewReader(src))
+	res, err := c.Compile()
+	require.NoError(t, err)
+
+	expected := code.NewDebugInfo("unknown file")
+
+	expected.AppendLine(8, 1)
+	expected.AppendLine(17, 2)
+	expected.AppendLine(18, 4)
+	expected.AppendLine(19, 5)
+	expected.AppendLine(20, 8)
+	expected.AppendLine(21, 9)
+
+	require.Equal(t, expected, *res.Debug())
+}
+
 func opBin(op code.Op) []byte {
 	return []byte{byte(op)}
 }