Skip to content

Commit

Permalink
test: add more testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed Mar 7, 2024
1 parent 4f7b5d3 commit 1a98f94
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
13 changes: 0 additions & 13 deletions internal/luai/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,3 @@ func Unmarshal(value lua.LValue, v any) error {

return unmarshalWorker(value, reflected)
}

func applyValue(value lua.LValue, field reflect.Value) {
switch value.Type() {
case lua.LTString:
field.SetString(value.String())
case lua.LTNumber:
field.SetInt(int64(value.(lua.LNumber)))
case lua.LTBool:
field.SetBool(bool(value.(lua.LBool)))
case lua.LTTable:
Unmarshal(value.(*lua.LTable), field.Interface())
}
}
13 changes: 11 additions & 2 deletions internal/luai/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type complexStruct struct {
Field1 string
Field2 int
Field3 bool
Struct testStructTag
Map map[string]interface{}
Slice []any
}
Expand Down Expand Up @@ -207,8 +208,13 @@ func TestEncoding(t *testing.T) {
Field1: "value1",
Field2: 123,
Field3: true,
Map: m,
Slice: s,
Struct: testStructTag{
Field1: "value1",
Field2: 2,
Field3: true,
},
Map: m,
Slice: s,
}

table, err := Marshal(L, input)
Expand All @@ -222,6 +228,9 @@ func TestEncoding(t *testing.T) {
assert(m.Field1 == "value1")
assert(m.Field2 == 123)
assert(m.Field3 == true)
assert(m.Struct.field1 == "value1")
assert(m.Struct.field2 == 2)
assert(m.Struct.field3 == true)
assert(m.Map.key1 == "value1")
assert(m.Map.key2 == 2)
assert(m.Map.key3 == true)
Expand Down

0 comments on commit 1a98f94

Please sign in to comment.