You've already forked json-iterator
mirror of
https://github.com/json-iterator/go.git
synced 2025-06-12 22:47:42 +02:00
consolidate more tests
This commit is contained in:
36
api_tests/marshal_indent_test.go
Normal file
36
api_tests/marshal_indent_test.go
Normal file
@ -0,0 +1,36 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
"github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
func Test_marshal_indent(t *testing.T) {
|
||||
should := require.New(t)
|
||||
obj := struct {
|
||||
F1 int
|
||||
F2 []int
|
||||
}{1, []int{2, 3, 4}}
|
||||
output, err := json.MarshalIndent(obj, "", " ")
|
||||
should.Nil(err)
|
||||
should.Equal("{\n \"F1\": 1,\n \"F2\": [\n 2,\n 3,\n 4\n ]\n}", string(output))
|
||||
output, err = jsoniter.MarshalIndent(obj, "", " ")
|
||||
should.Nil(err)
|
||||
should.Equal("{\n \"F1\": 1,\n \"F2\": [\n 2,\n 3,\n 4\n ]\n}", string(output))
|
||||
}
|
||||
|
||||
func Test_marshal_indent_map(t *testing.T) {
|
||||
should := require.New(t)
|
||||
obj := map[int]int{1: 2}
|
||||
output, err := json.MarshalIndent(obj, "", " ")
|
||||
should.Nil(err)
|
||||
should.Equal("{\n \"1\": 2\n}", string(output))
|
||||
output, err = jsoniter.MarshalIndent(obj, "", " ")
|
||||
should.Nil(err)
|
||||
should.Equal("{\n \"1\": 2\n}", string(output))
|
||||
output, err = jsoniter.ConfigCompatibleWithStandardLibrary.MarshalIndent(obj, "", " ")
|
||||
should.Nil(err)
|
||||
should.Equal("{\n \"1\": 2\n}", string(output))
|
||||
}
|
Reference in New Issue
Block a user