@@ -22,6 +22,7 @@ import (
22
22
"testing"
23
23
24
24
"github.com/version-fox/vfox/internal/logger"
25
+ "github.com/version-fox/vfox/internal/plugin/luai/codec"
25
26
lua "github.com/yuin/gopher-lua"
26
27
)
27
28
@@ -80,7 +81,7 @@ func TestExample(t *testing.T) {
80
81
}
81
82
82
83
table := L .ReturnedValue ()
83
- err := Unmarshal (table , & output )
84
+ err := codec . Unmarshal (table , & output )
84
85
if err != nil {
85
86
t .Fatalf ("unmarshal map failed: %v" , err )
86
87
}
@@ -111,7 +112,7 @@ func TestMarshalGoFunctions2(t *testing.T) {
111
112
goFunc := func () {
112
113
called = true
113
114
}
114
- luaFunc , err := Marshal (L .Instance , goFunc )
115
+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
115
116
if err != nil {
116
117
t .Fatalf ("Marshal failed: %v" , err )
117
118
}
@@ -132,7 +133,7 @@ func TestMarshalGoFunctions2(t *testing.T) {
132
133
receivedInt = a
133
134
receivedString = b
134
135
}
135
- luaFunc , err := Marshal (L .Instance , goFunc )
136
+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
136
137
if err != nil {
137
138
t .Fatalf ("Marshal failed: %v" , err )
138
139
}
@@ -153,7 +154,7 @@ func TestMarshalGoFunctions2(t *testing.T) {
153
154
goFunc := func () (int , string ) {
154
155
return 42 , "world"
155
156
}
156
- luaFunc , err := Marshal (L .Instance , goFunc )
157
+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
157
158
if err != nil {
158
159
t .Fatalf ("Marshal failed: %v" , err )
159
160
}
@@ -176,7 +177,7 @@ func TestMarshalGoFunctions2(t *testing.T) {
176
177
goFunc := func (x int , y int ) int {
177
178
return x + y
178
179
}
179
- luaFunc , err := Marshal (L .Instance , goFunc )
180
+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
180
181
if err != nil {
181
182
t .Fatalf ("Marshal failed: %v" , err )
182
183
}
@@ -199,7 +200,7 @@ func TestMarshalGoFunctions2(t *testing.T) {
199
200
}
200
201
return fmt .Sprintf ("%s%d" , prefix , sum )
201
202
}
202
- luaFunc , err := Marshal (L .Instance , goFunc )
203
+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
203
204
if err != nil {
204
205
t .Fatalf ("Marshal failed: %v" , err )
205
206
}
@@ -222,16 +223,16 @@ func TestMarshalGoFunctions2(t *testing.T) {
222
223
goFunc := func (s MyStruct ) MyStruct {
223
224
return MyStruct {Name : s .Name + "_processed" , Value : s .Value * 2 }
224
225
}
225
- luaFunc , err := Marshal (L .Instance , goFunc )
226
+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
226
227
if err != nil {
227
228
t .Fatalf ("Marshal failed: %v" , err )
228
229
}
229
230
L .Instance .SetGlobal ("testFunc" , luaFunc )
230
- // Marshal the input struct for Lua
231
+ // codec. Marshal the input struct for Lua
231
232
inputStruct := MyStruct {Name : "input" , Value : 10 }
232
- luaInput , err := Marshal (L .Instance , inputStruct )
233
+ luaInput , err := codec . Marshal (L .Instance , inputStruct )
233
234
if err != nil {
234
- t .Fatalf ("Failed to marshal input struct: %v" , err )
235
+ t .Fatalf ("Failed to codec. marshal input struct: %v" , err )
235
236
}
236
237
L .Instance .SetGlobal ("inputData" , luaInput )
237
238
@@ -243,7 +244,7 @@ func TestMarshalGoFunctions2(t *testing.T) {
243
244
244
245
outputDataLua := L .Instance .GetGlobal ("outputData" )
245
246
var outputStruct MyStruct
246
- if err := Unmarshal (outputDataLua , & outputStruct ); err != nil {
247
+ if err := codec . Unmarshal (outputDataLua , & outputStruct ); err != nil {
247
248
t .Fatalf ("Failed to unmarshal output struct: %v" , err )
248
249
}
249
250
@@ -424,7 +425,7 @@ func TestCases(t *testing.T) {
424
425
L := lua .NewState ()
425
426
defer L .Close ()
426
427
427
- table , err := Marshal (L , tt .in )
428
+ table , err := codec . Marshal (L , tt .in )
428
429
if err != nil {
429
430
t .Fatalf ("marshal map failed: %v" , err )
430
431
}
@@ -461,7 +462,7 @@ func TestCases(t *testing.T) {
461
462
t .Fatalf ("%s: unmarshalTest.ptr %#v is not a pointer to a zero value" , tt .CaseName , tt .ptr )
462
463
}
463
464
464
- err = Unmarshal (table , v .Interface ())
465
+ err = codec . Unmarshal (table , v .Interface ())
465
466
466
467
if err != tt .err {
467
468
t .Errorf ("expected %+v, got %+v" , tt .err , err )
@@ -499,7 +500,7 @@ func TestEncodeFunc(t *testing.T) {
499
500
L := NewLuaVM ()
500
501
defer L .Close ()
501
502
502
- table , err := Marshal (L .Instance , testdata )
503
+ table , err := codec . Marshal (L .Instance , testdata )
503
504
if err != nil {
504
505
t .Fatalf ("marshal map failed: %v" , err )
505
506
}
@@ -526,7 +527,7 @@ func TestMarshalGoFunctions(t *testing.T) {
526
527
goFunc := func () {
527
528
called = true
528
529
}
529
- luaFunc , err := Marshal (L .Instance , goFunc )
530
+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
530
531
if err != nil {
531
532
t .Fatalf ("Marshal failed: %v" , err )
532
533
}
@@ -547,7 +548,7 @@ func TestMarshalGoFunctions(t *testing.T) {
547
548
receivedInt = a
548
549
receivedString = b
549
550
}
550
- luaFunc , err := Marshal (L .Instance , goFunc )
551
+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
551
552
if err != nil {
552
553
t .Fatalf ("Marshal failed: %v" , err )
553
554
}
@@ -568,7 +569,7 @@ func TestMarshalGoFunctions(t *testing.T) {
568
569
goFunc := func () (int , string ) {
569
570
return 42 , "world"
570
571
}
571
- luaFunc , err := Marshal (L .Instance , goFunc )
572
+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
572
573
if err != nil {
573
574
t .Fatalf ("Marshal failed: %v" , err )
574
575
}
@@ -591,7 +592,7 @@ func TestMarshalGoFunctions(t *testing.T) {
591
592
goFunc := func (x int , y int ) int {
592
593
return x + y
593
594
}
594
- luaFunc , err := Marshal (L .Instance , goFunc )
595
+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
595
596
if err != nil {
596
597
t .Fatalf ("Marshal failed: %v" , err )
597
598
}
@@ -614,7 +615,7 @@ func TestMarshalGoFunctions(t *testing.T) {
614
615
}
615
616
return fmt .Sprintf ("%s%d" , prefix , sum )
616
617
}
617
- luaFunc , err := Marshal (L .Instance , goFunc )
618
+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
618
619
if err != nil {
619
620
t .Fatalf ("Marshal failed: %v" , err )
620
621
}
@@ -637,16 +638,16 @@ func TestMarshalGoFunctions(t *testing.T) {
637
638
goFunc := func (s MyStruct ) MyStruct {
638
639
return MyStruct {Name : s .Name + "_processed" , Value : s .Value * 2 }
639
640
}
640
- luaFunc , err := Marshal (L .Instance , goFunc )
641
+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
641
642
if err != nil {
642
643
t .Fatalf ("Marshal failed: %v" , err )
643
644
}
644
645
L .Instance .SetGlobal ("testFunc" , luaFunc )
645
- // Marshal the input struct for Lua
646
+ // codec. Marshal the input struct for Lua
646
647
inputStruct := MyStruct {Name : "input" , Value : 10 }
647
- luaInput , err := Marshal (L .Instance , inputStruct )
648
+ luaInput , err := codec . Marshal (L .Instance , inputStruct )
648
649
if err != nil {
649
- t .Fatalf ("Failed to marshal input struct: %v" , err )
650
+ t .Fatalf ("Failed to codec. marshal input struct: %v" , err )
650
651
}
651
652
L .Instance .SetGlobal ("inputData" , luaInput )
652
653
@@ -656,7 +657,7 @@ func TestMarshalGoFunctions(t *testing.T) {
656
657
657
658
outputDataLua := L .Instance .GetGlobal ("outputData" )
658
659
var outputStruct MyStruct
659
- if err := Unmarshal (outputDataLua , & outputStruct ); err != nil {
660
+ if err := codec . Unmarshal (outputDataLua , & outputStruct ); err != nil {
660
661
t .Fatalf ("Failed to unmarshal output struct: %v" , err )
661
662
}
662
663
0 commit comments