Apply goext specific patches to gojson
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Has been cancelled
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Has been cancelled
This commit is contained in:
@@ -1219,3 +1219,55 @@ func TestIssue63379(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMarshalSafeCollections(t *testing.T) {
|
||||
var (
|
||||
nilSlice []interface{}
|
||||
pNilSlice *[]interface{}
|
||||
nilMap map[string]interface{}
|
||||
pNilMap *map[string]interface{}
|
||||
)
|
||||
|
||||
type (
|
||||
nilSliceStruct struct {
|
||||
NilSlice []interface{} `json:"nil_slice"`
|
||||
}
|
||||
nilMapStruct struct {
|
||||
NilMap map[string]interface{} `json:"nil_map"`
|
||||
}
|
||||
testWithFilter struct {
|
||||
Test1 string `json:"test1" jsonfilter:"FILTERONE"`
|
||||
Test2 string `json:"test2" jsonfilter:"FILTERTWO"`
|
||||
}
|
||||
)
|
||||
|
||||
tests := []struct {
|
||||
in interface{}
|
||||
want string
|
||||
}{
|
||||
{nilSlice, "[]"},
|
||||
{[]interface{}{}, "[]"},
|
||||
{make([]interface{}, 0), "[]"},
|
||||
{[]int{1, 2, 3}, "[1,2,3]"},
|
||||
{pNilSlice, "null"},
|
||||
{nilSliceStruct{}, "{\"nil_slice\":[]}"},
|
||||
{nilMap, "{}"},
|
||||
{map[string]interface{}{}, "{}"},
|
||||
{make(map[string]interface{}, 0), "{}"},
|
||||
{map[string]interface{}{"1": 1, "2": 2, "3": 3}, "{\"1\":1,\"2\":2,\"3\":3}"},
|
||||
{pNilMap, "null"},
|
||||
{nilMapStruct{}, "{\"nil_map\":{}}"},
|
||||
{testWithFilter{}, "{\"test1\":\"\"}"},
|
||||
}
|
||||
|
||||
filter := "FILTERONE"
|
||||
for i, tt := range tests {
|
||||
b, err := MarshalSafeCollections(tt.in, true, true, nil, &filter)
|
||||
if err != nil {
|
||||
t.Errorf("test %d, unexpected failure: %v", i, err)
|
||||
}
|
||||
if got := string(b); got != tt.want {
|
||||
t.Errorf("test %d, Marshal(%#v) = %q, want %q", i, tt.in, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user