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.go27
1 files changed, 24 insertions, 3 deletions
diff --git a/pkg/lang/compiler/compiler_test.go b/pkg/lang/compiler/compiler_test.go
index 04bf425..725620c 100644
--- a/pkg/lang/compiler/compiler_test.go
+++ b/pkg/lang/compiler/compiler_test.go
@@ -552,6 +552,7 @@ func TestType(t *testing.T) {
 	set_arg_count 2
 
 	call 2
+	drop 1
 
 	get_local 0
 	get_member "$add_method"
@@ -560,6 +561,7 @@ func TestType(t *testing.T) {
 	push_function @Cat:meow
 
 	call 2
+	drop 1
 
 	get_local 0
 	push_string "Kitty"
@@ -601,6 +603,25 @@ func TestType(t *testing.T) {
 	mustCompileTo(t, src, expected)
 }
 
+func TestGlobals(t *testing.T) {
+	src := `
+	use mul from hello by mel
+	use pi from math
+
+	var result = mul(pi, 2)
+	`
+
+	expected := `
+	get_global "mel:hello:mul"
+	get_global ":math:pi"
+	push_int 2
+	call 2
+	halt
+	`
+
+	mustCompileTo(t, src, expected)
+}
+
 func mustCompileTo(t *testing.T, src, expected string) {
 	scanner := scanner.New(strings.NewReader(src))
 	tokens, err := scanner.Scan()
@@ -610,7 +631,7 @@ func mustCompileTo(t *testing.T, src, expected string) {
 	program, err := parser.Parse()
 	require.NoError(t, err)
 
-	langCompiler := compiler.New(program)
+	langCompiler := compiler.New("test_program", "test", program)
 	testResult, err := langCompiler.Compile()
 	require.NoError(t, err)
 
@@ -618,9 +639,9 @@ func mustCompileTo(t *testing.T, src, expected string) {
 	expectedResult, err := textCompiler.Compile()
 	require.NoError(t, err)
 
-	if !assert.Equal(t, expectedResult.Code(), testResult.Code()) {
+	if !assert.Equal(t, expectedResult.Code(), testResult.Code().Code()) {
 		d1 := text.NewDecompiler(expectedResult)
-		d2 := text.NewDecompiler(testResult)
+		d2 := text.NewDecompiler(*testResult.Code())
 		require.Equal(t, d1.Decompile(), d2.Decompile())
 	}
 }