Skip to content
Permalink
Browse files

move test to the correct files

  • Loading branch information...
rogchap committed Sep 1, 2019
1 parent 6529858 commit 854bedddb39de41d6da5995706a9c7dcd1f5c49e
Showing with 57 additions and 21 deletions.
  1. +1 −0 cgo.go
  2. +17 −21 context_test.go
  3. +2 −0 deps/darwin-x86_64/.empty
  4. +2 −0 deps/linux-x86_64/.empty
  5. +35 −0 value_test.go
1 cgo.go
@@ -3,4 +3,5 @@ package v8go
// #cgo CXXFLAGS: -fno-rtti -fpic -std=c++14 -I${SRCDIR}/deps/include
// #cgo LDFLAGS: -pthread -lv8
// #cgo darwin LDFLAGS: -L${SRCDIR}/deps/darwin-x86_64
// #cgo linux LDFLAGS: -L${SRCDIR}/deps/linux-x86_64
import "C"
@@ -6,30 +6,26 @@ import (
"rogchap.com/v8go"
)

func TestRunScriptStringer(t *testing.T) {
func TestContextExec(t *testing.T) {
t.Parallel()
ctx, _ := v8go.NewContext(nil)
var tests = [...]struct {
name string
source string
out string
}{
{"Addition", `2 + 2`, "4"},
{"Multiplication", `13 * 2`, "26"},
{"String", `"string"`, "string"},
{"Object", `let obj = {}; obj`, "[object Object]"},
{"Function", `let fn = function(){}; fn`, "function(){}"},
ctx.RunScript(`function add(a, b) { return a + b }`, "add.js")
val, _ := ctx.RunScript(`add(3, 4)`, "main.js")
rtn := val.String()
if rtn != "7" {
t.Errorf("script returned an unexpected value: expected %q, got %q", "7", rtn)
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
result, _ := ctx.RunScript(tt.source, "test.js")
str := result.String()
if str != tt.out {
t.Errorf("unespected result: expected %q, got %q", tt.out, str)
}
})
_, err := ctx.RunScript(`add`, "func.js")
if err != nil {
t.Errorf("function should be defined: %v", err)
}

/*iso, _ := ctx.Isolate()
ctx2, _ := v8go.NewContext(iso)
val, _ = ctx2.RunScript(`add`, "ctx2.js")
rtn = val.String()
if rtn != "undefined" {
t.Errorf("%q", rtn)
}*/
}
@@ -0,0 +1,2 @@
libv8.a is currently ignored during initial development
Once we optomize the size of libv8.a it will be included as part of this project
@@ -0,0 +1,2 @@
libv8.a is currently ignored during initial development
Once we optomize the size of libv8.a it will be included as part of this project
@@ -0,0 +1,35 @@
package v8go_test

import (
"testing"

"rogchap.com/v8go"
)

func TestValueString(t *testing.T) {
t.Parallel()
ctx, _ := v8go.NewContext(nil)
var tests = [...]struct {
name string
source string
out string
}{
{"Number", `13 * 2`, "26"},
{"String", `"string"`, "string"},
{"Object", `let obj = {}; obj`, "[object Object]"},
{"Date", `new Date("Sun Sep 01 2019 17:11:06 GMT+1000 (AEST)")`, "Sun Sep 01 2019 17:11:06 GMT+1000 (AEST)"},
{"Function", `let fn = function(){}; fn`, "function(){}"},
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
result, _ := ctx.RunScript(tt.source, "test.js")
str := result.String()
if str != tt.out {
t.Errorf("unespected result: expected %q, got %q", tt.out, str)
}
})
}
}

0 comments on commit 854bedd

Please sign in to comment.
You can’t perform that action at this time.