Skip to content

Commit

Permalink
move test to the correct files
Browse files Browse the repository at this point in the history
  • Loading branch information
rogchap committed Sep 1, 2019
1 parent 6529858 commit 854bedd
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 21 deletions.
1 change: 1 addition & 0 deletions cgo.go
Expand Up @@ -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"
38 changes: 17 additions & 21 deletions context_test.go
Expand Up @@ -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)
}*/
}
2 changes: 2 additions & 0 deletions deps/darwin-x86_64/.empty
@@ -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
2 changes: 2 additions & 0 deletions deps/linux-x86_64/.empty
@@ -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
35 changes: 35 additions & 0 deletions value_test.go
@@ -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.