1
0
mirror of https://github.com/json-iterator/go.git synced 2025-04-20 11:28:49 +02:00
json-iterator/value_tests/marshaler_test.go

67 lines
1.2 KiB
Go
Raw Normal View History

2018-02-13 23:49:40 +08:00
package test
2018-02-18 21:05:42 +08:00
import (
"encoding/json"
"encoding"
)
2018-02-13 23:49:40 +08:00
func init() {
2018-02-18 21:05:42 +08:00
jsonMarshaler := json.Marshaler(fakeJsonMarshaler{})
textMarshaler := encoding.TextMarshaler(fakeTextMarshaler{})
2018-02-18 22:49:06 +08:00
textMarshaler2 := encoding.TextMarshaler(&fakeTextMarshaler2{})
2018-02-13 23:49:40 +08:00
marshalCases = append(marshalCases,
2018-02-18 21:05:42 +08:00
fakeJsonMarshaler{},
&jsonMarshaler,
fakeTextMarshaler{},
&textMarshaler,
2018-02-18 22:49:06 +08:00
fakeTextMarshaler2{},
&textMarshaler2,
map[fakeTextMarshaler]int{
fakeTextMarshaler{}: 100,
},
map[*fakeTextMarshaler]int{
&fakeTextMarshaler{}: 100,
},
map[encoding.TextMarshaler]int{
textMarshaler: 100,
},
2018-02-13 23:49:40 +08:00
)
}
2018-02-18 21:05:42 +08:00
type fakeJsonMarshaler struct {
F2 chan []byte
}
func (q fakeJsonMarshaler) MarshalJSON() ([]byte, error) {
return []byte(`""`), nil
}
func (q *fakeJsonMarshaler) UnmarshalJSON(value []byte) error {
return nil
}
type fakeTextMarshaler struct {
2018-02-13 23:49:40 +08:00
F2 chan []byte
}
2018-02-18 21:05:42 +08:00
func (q fakeTextMarshaler) MarshalText() ([]byte, error) {
2018-02-13 23:49:40 +08:00
return []byte(`""`), nil
}
2018-02-18 21:05:42 +08:00
func (q *fakeTextMarshaler) UnmarshalText(value []byte) error {
2018-02-13 23:49:40 +08:00
return nil
}
2018-02-18 22:49:06 +08:00
type fakeTextMarshaler2 struct {
Field2 int
}
func (q *fakeTextMarshaler2) MarshalText() ([]byte, error) {
return []byte(`"abc"`), nil
}
func (q *fakeTextMarshaler2) UnmarshalText(value []byte) error {
return nil
}