aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-03-15 19:42:17 +0800
committerzelig <viktor.tron@gmail.com>2015-03-15 19:42:17 +0800
commit7bc40aa963626383dbb6a5cb6fe10736dc1d74fa (patch)
treefcf6ca86b4f5960e7432647e6520068f472b831e
parent7279a485c24de3f0aaf839e1884151322a97dbf7 (diff)
downloadgo-tangerine-7bc40aa963626383dbb6a5cb6fe10736dc1d74fa.tar
go-tangerine-7bc40aa963626383dbb6a5cb6fe10736dc1d74fa.tar.gz
go-tangerine-7bc40aa963626383dbb6a5cb6fe10736dc1d74fa.tar.bz2
go-tangerine-7bc40aa963626383dbb6a5cb6fe10736dc1d74fa.tar.lz
go-tangerine-7bc40aa963626383dbb6a5cb6fe10736dc1d74fa.tar.xz
go-tangerine-7bc40aa963626383dbb6a5cb6fe10736dc1d74fa.tar.zst
go-tangerine-7bc40aa963626383dbb6a5cb6fe10736dc1d74fa.zip
jsre: remove assetpath using GOPATH from test
-rw-r--r--jsre/jsre_test.go41
1 files changed, 20 insertions, 21 deletions
diff --git a/jsre/jsre_test.go b/jsre/jsre_test.go
index 67b5ea906..e4decf2f4 100644
--- a/jsre/jsre_test.go
+++ b/jsre/jsre_test.go
@@ -2,15 +2,11 @@ package jsre
import (
"github.com/obscuren/otto"
- "os"
- "path"
"testing"
"github.com/ethereum/go-ethereum/ethutil"
)
-var defaultAssetPath = path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist", "assets", "ext")
-
type testNativeObjectBinding struct {
toVal func(interface{}) otto.Value
}
@@ -42,20 +38,15 @@ func TestExec(t *testing.T) {
if !val.IsString() {
t.Errorf("expected string value, got %v", val)
}
-
- // this errors
- err = jsre.Exec(path.Join(defaultAssetPath, "bignumber.min.js"))
- if err != nil {
- t.Errorf("expected no error, got %v", err)
- }
- _, err = jsre.Run("x = new BigNumber(123.4567);")
- if err != nil {
- t.Errorf("expected no error, got %v", err)
+ exp := "testMsg"
+ got, _ := val.ToString()
+ if exp != got {
+ t.Errorf("expected '%v', got '%v'", exp, got)
}
}
func TestBind(t *testing.T) {
- jsre := New(defaultAssetPath)
+ jsre := New("/tmp")
jsre.Bind("no", &testNativeObjectBinding{jsre.ToVal})
@@ -70,16 +61,24 @@ func TestBind(t *testing.T) {
t.Logf("no: %v", pp)
}
-func TestRequire(t *testing.T) {
- jsre := New(defaultAssetPath)
+func TestLoadScript(t *testing.T) {
+ jsre := New("/tmp")
- _, err := jsre.Run("x = new BigNumber(123.4567);")
- if err == nil {
- t.Errorf("expected error, got nothing")
+ ethutil.WriteFile("/tmp/test.js", []byte(`msg = "testMsg"`))
+ _, err := jsre.Run(`loadScript("test.js")`)
+ if err != nil {
+ t.Errorf("expected no error, got %v", err)
}
- _, err = jsre.Run(`loadScript("bignumber.min.js"); x = new BigNumber(123.4567)`)
+ val, err := jsre.Run("msg")
if err != nil {
t.Errorf("expected no error, got %v", err)
}
-
+ if !val.IsString() {
+ t.Errorf("expected string value, got %v", val)
+ }
+ exp := "testMsg"
+ got, _ := val.ToString()
+ if exp != got {
+ t.Errorf("expected '%v', got '%v'", exp, got)
+ }
}