@@ -22,6 +22,7 @@ import (
2222 "testing"
2323
2424 "github.com/version-fox/vfox/internal/logger"
25+ "github.com/version-fox/vfox/internal/plugin/luai/codec"
2526 lua "github.com/yuin/gopher-lua"
2627)
2728
@@ -80,7 +81,7 @@ func TestExample(t *testing.T) {
8081 }
8182
8283 table := L .ReturnedValue ()
83- err := Unmarshal (table , & output )
84+ err := codec . Unmarshal (table , & output )
8485 if err != nil {
8586 t .Fatalf ("unmarshal map failed: %v" , err )
8687 }
@@ -111,7 +112,7 @@ func TestMarshalGoFunctions2(t *testing.T) {
111112 goFunc := func () {
112113 called = true
113114 }
114- luaFunc , err := Marshal (L .Instance , goFunc )
115+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
115116 if err != nil {
116117 t .Fatalf ("Marshal failed: %v" , err )
117118 }
@@ -132,7 +133,7 @@ func TestMarshalGoFunctions2(t *testing.T) {
132133 receivedInt = a
133134 receivedString = b
134135 }
135- luaFunc , err := Marshal (L .Instance , goFunc )
136+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
136137 if err != nil {
137138 t .Fatalf ("Marshal failed: %v" , err )
138139 }
@@ -153,7 +154,7 @@ func TestMarshalGoFunctions2(t *testing.T) {
153154 goFunc := func () (int , string ) {
154155 return 42 , "world"
155156 }
156- luaFunc , err := Marshal (L .Instance , goFunc )
157+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
157158 if err != nil {
158159 t .Fatalf ("Marshal failed: %v" , err )
159160 }
@@ -176,7 +177,7 @@ func TestMarshalGoFunctions2(t *testing.T) {
176177 goFunc := func (x int , y int ) int {
177178 return x + y
178179 }
179- luaFunc , err := Marshal (L .Instance , goFunc )
180+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
180181 if err != nil {
181182 t .Fatalf ("Marshal failed: %v" , err )
182183 }
@@ -199,7 +200,7 @@ func TestMarshalGoFunctions2(t *testing.T) {
199200 }
200201 return fmt .Sprintf ("%s%d" , prefix , sum )
201202 }
202- luaFunc , err := Marshal (L .Instance , goFunc )
203+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
203204 if err != nil {
204205 t .Fatalf ("Marshal failed: %v" , err )
205206 }
@@ -222,16 +223,16 @@ func TestMarshalGoFunctions2(t *testing.T) {
222223 goFunc := func (s MyStruct ) MyStruct {
223224 return MyStruct {Name : s .Name + "_processed" , Value : s .Value * 2 }
224225 }
225- luaFunc , err := Marshal (L .Instance , goFunc )
226+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
226227 if err != nil {
227228 t .Fatalf ("Marshal failed: %v" , err )
228229 }
229230 L .Instance .SetGlobal ("testFunc" , luaFunc )
230- // Marshal the input struct for Lua
231+ // codec. Marshal the input struct for Lua
231232 inputStruct := MyStruct {Name : "input" , Value : 10 }
232- luaInput , err := Marshal (L .Instance , inputStruct )
233+ luaInput , err := codec . Marshal (L .Instance , inputStruct )
233234 if err != nil {
234- t .Fatalf ("Failed to marshal input struct: %v" , err )
235+ t .Fatalf ("Failed to codec. marshal input struct: %v" , err )
235236 }
236237 L .Instance .SetGlobal ("inputData" , luaInput )
237238
@@ -243,7 +244,7 @@ func TestMarshalGoFunctions2(t *testing.T) {
243244
244245 outputDataLua := L .Instance .GetGlobal ("outputData" )
245246 var outputStruct MyStruct
246- if err := Unmarshal (outputDataLua , & outputStruct ); err != nil {
247+ if err := codec . Unmarshal (outputDataLua , & outputStruct ); err != nil {
247248 t .Fatalf ("Failed to unmarshal output struct: %v" , err )
248249 }
249250
@@ -424,7 +425,7 @@ func TestCases(t *testing.T) {
424425 L := lua .NewState ()
425426 defer L .Close ()
426427
427- table , err := Marshal (L , tt .in )
428+ table , err := codec . Marshal (L , tt .in )
428429 if err != nil {
429430 t .Fatalf ("marshal map failed: %v" , err )
430431 }
@@ -461,7 +462,7 @@ func TestCases(t *testing.T) {
461462 t .Fatalf ("%s: unmarshalTest.ptr %#v is not a pointer to a zero value" , tt .CaseName , tt .ptr )
462463 }
463464
464- err = Unmarshal (table , v .Interface ())
465+ err = codec . Unmarshal (table , v .Interface ())
465466
466467 if err != tt .err {
467468 t .Errorf ("expected %+v, got %+v" , tt .err , err )
@@ -499,7 +500,7 @@ func TestEncodeFunc(t *testing.T) {
499500 L := NewLuaVM ()
500501 defer L .Close ()
501502
502- table , err := Marshal (L .Instance , testdata )
503+ table , err := codec . Marshal (L .Instance , testdata )
503504 if err != nil {
504505 t .Fatalf ("marshal map failed: %v" , err )
505506 }
@@ -526,7 +527,7 @@ func TestMarshalGoFunctions(t *testing.T) {
526527 goFunc := func () {
527528 called = true
528529 }
529- luaFunc , err := Marshal (L .Instance , goFunc )
530+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
530531 if err != nil {
531532 t .Fatalf ("Marshal failed: %v" , err )
532533 }
@@ -547,7 +548,7 @@ func TestMarshalGoFunctions(t *testing.T) {
547548 receivedInt = a
548549 receivedString = b
549550 }
550- luaFunc , err := Marshal (L .Instance , goFunc )
551+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
551552 if err != nil {
552553 t .Fatalf ("Marshal failed: %v" , err )
553554 }
@@ -568,7 +569,7 @@ func TestMarshalGoFunctions(t *testing.T) {
568569 goFunc := func () (int , string ) {
569570 return 42 , "world"
570571 }
571- luaFunc , err := Marshal (L .Instance , goFunc )
572+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
572573 if err != nil {
573574 t .Fatalf ("Marshal failed: %v" , err )
574575 }
@@ -591,7 +592,7 @@ func TestMarshalGoFunctions(t *testing.T) {
591592 goFunc := func (x int , y int ) int {
592593 return x + y
593594 }
594- luaFunc , err := Marshal (L .Instance , goFunc )
595+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
595596 if err != nil {
596597 t .Fatalf ("Marshal failed: %v" , err )
597598 }
@@ -614,7 +615,7 @@ func TestMarshalGoFunctions(t *testing.T) {
614615 }
615616 return fmt .Sprintf ("%s%d" , prefix , sum )
616617 }
617- luaFunc , err := Marshal (L .Instance , goFunc )
618+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
618619 if err != nil {
619620 t .Fatalf ("Marshal failed: %v" , err )
620621 }
@@ -637,16 +638,16 @@ func TestMarshalGoFunctions(t *testing.T) {
637638 goFunc := func (s MyStruct ) MyStruct {
638639 return MyStruct {Name : s .Name + "_processed" , Value : s .Value * 2 }
639640 }
640- luaFunc , err := Marshal (L .Instance , goFunc )
641+ luaFunc , err := codec . Marshal (L .Instance , goFunc )
641642 if err != nil {
642643 t .Fatalf ("Marshal failed: %v" , err )
643644 }
644645 L .Instance .SetGlobal ("testFunc" , luaFunc )
645- // Marshal the input struct for Lua
646+ // codec. Marshal the input struct for Lua
646647 inputStruct := MyStruct {Name : "input" , Value : 10 }
647- luaInput , err := Marshal (L .Instance , inputStruct )
648+ luaInput , err := codec . Marshal (L .Instance , inputStruct )
648649 if err != nil {
649- t .Fatalf ("Failed to marshal input struct: %v" , err )
650+ t .Fatalf ("Failed to codec. marshal input struct: %v" , err )
650651 }
651652 L .Instance .SetGlobal ("inputData" , luaInput )
652653
@@ -656,7 +657,7 @@ func TestMarshalGoFunctions(t *testing.T) {
656657
657658 outputDataLua := L .Instance .GetGlobal ("outputData" )
658659 var outputStruct MyStruct
659- if err := Unmarshal (outputDataLua , & outputStruct ); err != nil {
660+ if err := codec . Unmarshal (outputDataLua , & outputStruct ); err != nil {
660661 t .Fatalf ("Failed to unmarshal output struct: %v" , err )
661662 }
662663
0 commit comments