-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: bug when serde with nil function
- Loading branch information
Showing
12 changed files
with
161 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package issue_test | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/bytedance/sonic" | ||
"github.com/davecgh/go-spew/spew" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type Function = func() | ||
|
||
func MockFunc() { | ||
|
||
} | ||
|
||
type Unable struct { | ||
Functions []Function | ||
} | ||
|
||
type StructWithUnable struct { | ||
Foo *Unable `json:"foo"` | ||
Bar *Unable `json:"bar,omitempty"` | ||
} | ||
|
||
func TestIssue491_MarshalNilFunction(t *testing.T) { | ||
// Wrapper a unbale serde type | ||
tests := []interface{} { | ||
map[string]*Function{}, | ||
map[*Function]*Function{}, | ||
[]Function{}, | ||
StructWithUnable{}, | ||
struct { | ||
Foo *int | ||
}{}, | ||
struct { | ||
Foo Function | ||
}{}, | ||
chan int(nil), | ||
} | ||
for _, v := range(tests) { | ||
assertMarshal(t, sonic.ConfigDefault, v) | ||
} | ||
} | ||
|
||
func TestIssue491_UnmarshalUnsupportedNil(t *testing.T) { | ||
type Test struct { | ||
data string | ||
value interface{} | ||
} | ||
|
||
tests := []Test{ | ||
{ | ||
data: "null", | ||
value: new([]Function), | ||
}, | ||
{ | ||
data: "[null, null]", | ||
value: new([]Function), | ||
}, | ||
{ | ||
data: "{\"foo\": null}", | ||
value: new(struct { | ||
Foo *Function | ||
}), | ||
}, | ||
} | ||
for _, v := range(tests) { | ||
spew.Dump(v) | ||
jerr := json.Unmarshal([]byte(v.data), &v.value) | ||
require.NoError(t, jerr) | ||
serr := sonic.Unmarshal([]byte(v.data), &v.value) | ||
require.NoError(t, serr) | ||
} | ||
} | ||
|