diff options
| author | Mel <einebeere@gmail.com> | 2022-08-11 01:25:47 +0000 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-08-11 01:25:47 +0000 |
| commit | 86f31acf6789be116dcc54ed85b069a37c0f7aa8 (patch) | |
| tree | bc7afd6a8c340825996d29c6cfd392ae42b4fbd5 /pkg/lang/compiler/compiler_test.go | |
| parent | c46b2bc7ce6df1f2c6c9494ef08015ec29992da5 (diff) | |
| download | jinx-86f31acf6789be116dcc54ed85b069a37c0f7aa8.tar.zst jinx-86f31acf6789be116dcc54ed85b069a37c0f7aa8.zip | |
Actual modules and core
Diffstat (limited to 'pkg/lang/compiler/compiler_test.go')
| -rw-r--r-- | pkg/lang/compiler/compiler_test.go | 27 |
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()) } } |
