forked from nyaosorg/nyagos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclone_test.go
52 lines (42 loc) · 903 Bytes
/
clone_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//go:build !vanilla
// +build !vanilla
package mains_test
import (
"testing"
"github.com/yuin/gopher-lua"
"github.com/nyaosorg/nyagos/mains"
)
type Lua = mains.Lua
func makeSource(L Lua) {
tbl := L.NewTable()
L.SetTable(tbl, lua.LString("alpha"), lua.LString("beta"))
L.SetGlobal("gamma", tbl)
}
func testDestinate(t *testing.T, L Lua) {
tbl := L.GetGlobal("gamma")
if tbl.Type() != lua.LTTable {
t.Fatal("Failed to copy table.")
return
}
val := L.GetField(tbl, "alpha")
if val != lua.LString("beta") {
t.Fatalf("Failed to copy all of instance(%s)", val.String())
return
}
}
func TestClone(t *testing.T) {
L1 := lua.NewState()
makeSource(L1)
L2, err := mains.Clone(L1)
if err != nil {
t.Fatalf("Failed to create instance: %s", err.Error())
return
}
L1.Close()
if L2 == nil {
t.Fatal("Failed to create instance")
return
}
testDestinate(t, L2)
L2.Close()
}