-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from d5/scriptmodule
Script Imports
- Loading branch information
Showing
8 changed files
with
370 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package script_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/d5/tengo/assert" | ||
"github.com/d5/tengo/script" | ||
) | ||
|
||
func TestScript_AddModule(t *testing.T) { | ||
// mod1 module | ||
mod1 := script.New([]byte(`a := 5`)) | ||
|
||
// script1 imports "mod1" | ||
scr1 := script.New([]byte(`mod1 := import("mod1"); out := mod1.a`)) | ||
scr1.AddModule("mod1", mod1) | ||
c, err := scr1.Run() | ||
assert.Equal(t, int64(5), c.Get("out").Value()) | ||
|
||
// mod2 module imports "mod1" | ||
mod2 := script.New([]byte(`mod1 := import("mod1"); b := mod1.a * 2`)) | ||
mod2.AddModule("mod1", mod1) | ||
|
||
// script2 imports "mod2" (which imports "mod1") | ||
scr2 := script.New([]byte(`mod2 := import("mod2"); out := mod2.b`)) | ||
scr2.AddModule("mod2", mod2) | ||
c, err = scr2.Run() | ||
assert.NoError(t, err) | ||
assert.Equal(t, int64(10), c.Get("out").Value()) | ||
} |