You've already forked json-iterator
mirror of
https://github.com/json-iterator/go.git
synced 2025-06-21 23:07:33 +02:00
separate 1.8 tests
This commit is contained in:
43
jsoniter_1dot8_only_test.go
Normal file
43
jsoniter_1dot8_only_test.go
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
// +build go1.8
|
||||||
|
package jsoniter
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/json-iterator/go/require"
|
||||||
|
"bytes"
|
||||||
|
"unicode/utf8"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_new_encoder(t *testing.T) {
|
||||||
|
should := require.New(t)
|
||||||
|
buf1 := &bytes.Buffer{}
|
||||||
|
encoder1 := json.NewEncoder(buf1)
|
||||||
|
encoder1.SetEscapeHTML(false)
|
||||||
|
encoder1.Encode([]int{1})
|
||||||
|
should.Equal("[1]\n", buf1.String())
|
||||||
|
buf2 := &bytes.Buffer{}
|
||||||
|
encoder2 := NewEncoder(buf2)
|
||||||
|
encoder2.SetEscapeHTML(false)
|
||||||
|
encoder2.Encode([]int{1})
|
||||||
|
should.Equal("[1]", buf2.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_string_encode_with_std_without_html_escape(t *testing.T) {
|
||||||
|
api := Config{EscapeHtml: false}.Froze()
|
||||||
|
should := require.New(t)
|
||||||
|
for i := 0; i < utf8.RuneSelf; i++ {
|
||||||
|
input := string([]byte{byte(i)})
|
||||||
|
buf := &bytes.Buffer{}
|
||||||
|
encoder := json.NewEncoder(buf)
|
||||||
|
encoder.SetEscapeHTML(false)
|
||||||
|
err := encoder.Encode(input)
|
||||||
|
should.Nil(err)
|
||||||
|
stdOutput := buf.String()
|
||||||
|
stdOutput = stdOutput[:len(stdOutput)-1]
|
||||||
|
jsoniterOutputBytes, err := api.Marshal(input)
|
||||||
|
should.Nil(err)
|
||||||
|
jsoniterOutput := string(jsoniterOutputBytes)
|
||||||
|
should.Equal(stdOutput, jsoniterOutput)
|
||||||
|
}
|
||||||
|
}
|
@ -33,20 +33,6 @@ func Test_new_decoder(t *testing.T) {
|
|||||||
should.False(decoder2.More())
|
should.False(decoder2.More())
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_new_encoder(t *testing.T) {
|
|
||||||
should := require.New(t)
|
|
||||||
buf1 := &bytes.Buffer{}
|
|
||||||
encoder1 := json.NewEncoder(buf1)
|
|
||||||
encoder1.SetEscapeHTML(false)
|
|
||||||
encoder1.Encode([]int{1})
|
|
||||||
should.Equal("[1]\n", buf1.String())
|
|
||||||
buf2 := &bytes.Buffer{}
|
|
||||||
encoder2 := NewEncoder(buf2)
|
|
||||||
encoder2.SetEscapeHTML(false)
|
|
||||||
encoder2.Encode([]int{1})
|
|
||||||
should.Equal("[1]", buf2.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
func Test_use_number(t *testing.T) {
|
func Test_use_number(t *testing.T) {
|
||||||
should := require.New(t)
|
should := require.New(t)
|
||||||
decoder1 := json.NewDecoder(bytes.NewBufferString(`123`))
|
decoder1 := json.NewDecoder(bytes.NewBufferString(`123`))
|
||||||
|
@ -121,25 +121,6 @@ func Test_string_encode_with_std(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_string_encode_with_std_without_html_escape(t *testing.T) {
|
|
||||||
api := Config{EscapeHtml: false}.Froze()
|
|
||||||
should := require.New(t)
|
|
||||||
for i := 0; i < utf8.RuneSelf; i++ {
|
|
||||||
input := string([]byte{byte(i)})
|
|
||||||
buf := &bytes.Buffer{}
|
|
||||||
encoder := json.NewEncoder(buf)
|
|
||||||
encoder.SetEscapeHTML(false)
|
|
||||||
err := encoder.Encode(input)
|
|
||||||
should.Nil(err)
|
|
||||||
stdOutput := buf.String()
|
|
||||||
stdOutput = stdOutput[:len(stdOutput)-1]
|
|
||||||
jsoniterOutputBytes, err := api.Marshal(input)
|
|
||||||
should.Nil(err)
|
|
||||||
jsoniterOutput := string(jsoniterOutputBytes)
|
|
||||||
should.Equal(stdOutput, jsoniterOutput)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func Test_unicode(t *testing.T) {
|
func Test_unicode(t *testing.T) {
|
||||||
should := require.New(t)
|
should := require.New(t)
|
||||||
output, _ := MarshalToString(map[string]interface{}{"a": "数字山谷"})
|
output, _ := MarshalToString(map[string]interface{}{"a": "数字山谷"})
|
||||||
|
Reference in New Issue
Block a user