You've already forked json-iterator
mirror of
https://github.com/json-iterator/go.git
synced 2025-06-15 22:50:24 +02:00
support TextMarshaler as map key
This commit is contained in:
@ -3,6 +3,7 @@ package jsoniter
|
||||
import (
|
||||
"testing"
|
||||
"github.com/json-iterator/go/require"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
func Test_read_map(t *testing.T) {
|
||||
@ -81,4 +82,22 @@ func Test_decode_int_key_map(t *testing.T) {
|
||||
var val map[int]string
|
||||
should.Nil(UnmarshalFromString(`{"1":"2"}`, &val))
|
||||
should.Equal(map[int]string{1: "2"}, val)
|
||||
}
|
||||
|
||||
func Test_encode_TextMarshaler_key_map(t *testing.T) {
|
||||
should := require.New(t)
|
||||
f, _, _ := big.ParseFloat("1", 10, 64, big.ToZero)
|
||||
val := map[*big.Float]string{f: "2"}
|
||||
str, err := MarshalToString(val)
|
||||
should.Nil(err)
|
||||
should.Equal(`{"1":"2"}`, str)
|
||||
}
|
||||
|
||||
func Test_decode_TextMarshaler_key_map(t *testing.T) {
|
||||
should := require.New(t)
|
||||
var val map[*big.Float]string
|
||||
should.Nil(UnmarshalFromString(`{"1":"2"}`, &val))
|
||||
str, err := MarshalToString(val)
|
||||
should.Nil(err)
|
||||
should.Equal(`{"1":"2"}`, str)
|
||||
}
|
Reference in New Issue
Block a user