mirror of
https://github.com/json-iterator/go.git
synced 2025-01-17 18:44:50 +02:00
sync up some straggler json_tests
This commit is contained in:
parent
7fa780bd5d
commit
79c4040505
@ -3,6 +3,8 @@ package test
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
@ -18,29 +20,37 @@ func Test_Roundtrip(t *testing.T) {
|
||||
|
||||
jbStd, err := json.Marshal(before)
|
||||
if err != nil {
|
||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||
t.Fatalf("failed to marshal with stdlib: %v", err)
|
||||
}
|
||||
if len(strings.TrimSpace(string(jbStd))) == 0 {
|
||||
t.Fatal("stdlib marshal produced empty result and no error")
|
||||
}
|
||||
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||
if err != nil {
|
||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||
t.Fatalf("failed to marshal with jsoniter: %v", err)
|
||||
}
|
||||
if len(strings.TrimSpace(string(jbIter))) == 0 {
|
||||
t.Fatal("jsoniter marshal produced empty result and no error")
|
||||
}
|
||||
if string(jbStd) != string(jbIter) {
|
||||
t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||
t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||
indent(jbStd, " "), indent(jbIter, " "), dump(before))
|
||||
}
|
||||
|
||||
var afterStd T
|
||||
err = json.Unmarshal(jbIter, &afterStd)
|
||||
if err != nil {
|
||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||
t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s",
|
||||
err, indent(jbIter, " "))
|
||||
}
|
||||
var afterIter T
|
||||
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||
if err != nil {
|
||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||
t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s",
|
||||
err, indent(jbIter, " "))
|
||||
}
|
||||
if fingerprint(afterStd) != fingerprint(afterIter) {
|
||||
t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||
t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||
dump(afterStd), dump(afterIter), indent(jbIter, " "))
|
||||
}
|
||||
}
|
||||
@ -65,7 +75,10 @@ func dump(obj interface{}) string {
|
||||
|
||||
func indent(src []byte, prefix string) string {
|
||||
var buf bytes.Buffer
|
||||
json.Indent(&buf, src, prefix, indentStr)
|
||||
err := json.Indent(&buf, src, prefix, indentStr)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("!!! %v", err)
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,8 @@ package test
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
@ -18,29 +20,37 @@ func Test_Roundtrip(t *testing.T) {
|
||||
|
||||
jbStd, err := json.Marshal(before)
|
||||
if err != nil {
|
||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||
t.Fatalf("failed to marshal with stdlib: %v", err)
|
||||
}
|
||||
if len(strings.TrimSpace(string(jbStd))) == 0 {
|
||||
t.Fatal("stdlib marshal produced empty result and no error")
|
||||
}
|
||||
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||
if err != nil {
|
||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||
t.Fatalf("failed to marshal with jsoniter: %v", err)
|
||||
}
|
||||
if len(strings.TrimSpace(string(jbIter))) == 0 {
|
||||
t.Fatal("jsoniter marshal produced empty result and no error")
|
||||
}
|
||||
if string(jbStd) != string(jbIter) {
|
||||
t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||
t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||
indent(jbStd, " "), indent(jbIter, " "), dump(before))
|
||||
}
|
||||
|
||||
var afterStd T
|
||||
err = json.Unmarshal(jbIter, &afterStd)
|
||||
if err != nil {
|
||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||
t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s",
|
||||
err, indent(jbIter, " "))
|
||||
}
|
||||
var afterIter T
|
||||
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||
if err != nil {
|
||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||
t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s",
|
||||
err, indent(jbIter, " "))
|
||||
}
|
||||
if fingerprint(afterStd) != fingerprint(afterIter) {
|
||||
t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||
t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||
dump(afterStd), dump(afterIter), indent(jbIter, " "))
|
||||
}
|
||||
}
|
||||
@ -65,7 +75,10 @@ func dump(obj interface{}) string {
|
||||
|
||||
func indent(src []byte, prefix string) string {
|
||||
var buf bytes.Buffer
|
||||
json.Indent(&buf, src, prefix, indentStr)
|
||||
err := json.Indent(&buf, src, prefix, indentStr)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("!!! %v", err)
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,8 @@ package test
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
@ -18,29 +20,37 @@ func Test_Roundtrip(t *testing.T) {
|
||||
|
||||
jbStd, err := json.Marshal(before)
|
||||
if err != nil {
|
||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||
t.Fatalf("failed to marshal with stdlib: %v", err)
|
||||
}
|
||||
if len(strings.TrimSpace(string(jbStd))) == 0 {
|
||||
t.Fatal("stdlib marshal produced empty result and no error")
|
||||
}
|
||||
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||
if err != nil {
|
||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||
t.Fatalf("failed to marshal with jsoniter: %v", err)
|
||||
}
|
||||
if len(strings.TrimSpace(string(jbIter))) == 0 {
|
||||
t.Fatal("jsoniter marshal produced empty result and no error")
|
||||
}
|
||||
if string(jbStd) != string(jbIter) {
|
||||
t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||
t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||
indent(jbStd, " "), indent(jbIter, " "), dump(before))
|
||||
}
|
||||
|
||||
var afterStd T
|
||||
err = json.Unmarshal(jbIter, &afterStd)
|
||||
if err != nil {
|
||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||
t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s",
|
||||
err, indent(jbIter, " "))
|
||||
}
|
||||
var afterIter T
|
||||
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||
if err != nil {
|
||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||
t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s",
|
||||
err, indent(jbIter, " "))
|
||||
}
|
||||
if fingerprint(afterStd) != fingerprint(afterIter) {
|
||||
t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||
t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||
dump(afterStd), dump(afterIter), indent(jbIter, " "))
|
||||
}
|
||||
}
|
||||
@ -65,7 +75,10 @@ func dump(obj interface{}) string {
|
||||
|
||||
func indent(src []byte, prefix string) string {
|
||||
var buf bytes.Buffer
|
||||
json.Indent(&buf, src, prefix, indentStr)
|
||||
err := json.Indent(&buf, src, prefix, indentStr)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("!!! %v", err)
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,8 @@ package test
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
@ -18,29 +20,37 @@ func Test_Roundtrip(t *testing.T) {
|
||||
|
||||
jbStd, err := json.Marshal(before)
|
||||
if err != nil {
|
||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||
t.Fatalf("failed to marshal with stdlib: %v", err)
|
||||
}
|
||||
if len(strings.TrimSpace(string(jbStd))) == 0 {
|
||||
t.Fatal("stdlib marshal produced empty result and no error")
|
||||
}
|
||||
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||
if err != nil {
|
||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||
t.Fatalf("failed to marshal with jsoniter: %v", err)
|
||||
}
|
||||
if len(strings.TrimSpace(string(jbIter))) == 0 {
|
||||
t.Fatal("jsoniter marshal produced empty result and no error")
|
||||
}
|
||||
if string(jbStd) != string(jbIter) {
|
||||
t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||
t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||
indent(jbStd, " "), indent(jbIter, " "), dump(before))
|
||||
}
|
||||
|
||||
var afterStd T
|
||||
err = json.Unmarshal(jbIter, &afterStd)
|
||||
if err != nil {
|
||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||
t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s",
|
||||
err, indent(jbIter, " "))
|
||||
}
|
||||
var afterIter T
|
||||
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||
if err != nil {
|
||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||
t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s",
|
||||
err, indent(jbIter, " "))
|
||||
}
|
||||
if fingerprint(afterStd) != fingerprint(afterIter) {
|
||||
t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||
t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||
dump(afterStd), dump(afterIter), indent(jbIter, " "))
|
||||
}
|
||||
}
|
||||
@ -65,7 +75,10 @@ func dump(obj interface{}) string {
|
||||
|
||||
func indent(src []byte, prefix string) string {
|
||||
var buf bytes.Buffer
|
||||
json.Indent(&buf, src, prefix, indentStr)
|
||||
err := json.Indent(&buf, src, prefix, indentStr)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("!!! %v", err)
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,8 @@ package test
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
@ -18,29 +20,37 @@ func Test_Roundtrip(t *testing.T) {
|
||||
|
||||
jbStd, err := json.Marshal(before)
|
||||
if err != nil {
|
||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||
t.Fatalf("failed to marshal with stdlib: %v", err)
|
||||
}
|
||||
if len(strings.TrimSpace(string(jbStd))) == 0 {
|
||||
t.Fatal("stdlib marshal produced empty result and no error")
|
||||
}
|
||||
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||
if err != nil {
|
||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||
t.Fatalf("failed to marshal with jsoniter: %v", err)
|
||||
}
|
||||
if len(strings.TrimSpace(string(jbIter))) == 0 {
|
||||
t.Fatal("jsoniter marshal produced empty result and no error")
|
||||
}
|
||||
if string(jbStd) != string(jbIter) {
|
||||
t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||
t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||
indent(jbStd, " "), indent(jbIter, " "), dump(before))
|
||||
}
|
||||
|
||||
var afterStd T
|
||||
err = json.Unmarshal(jbIter, &afterStd)
|
||||
if err != nil {
|
||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||
t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s",
|
||||
err, indent(jbIter, " "))
|
||||
}
|
||||
var afterIter T
|
||||
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||
if err != nil {
|
||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||
t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s",
|
||||
err, indent(jbIter, " "))
|
||||
}
|
||||
if fingerprint(afterStd) != fingerprint(afterIter) {
|
||||
t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||
t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||
dump(afterStd), dump(afterIter), indent(jbIter, " "))
|
||||
}
|
||||
}
|
||||
@ -65,7 +75,10 @@ func dump(obj interface{}) string {
|
||||
|
||||
func indent(src []byte, prefix string) string {
|
||||
var buf bytes.Buffer
|
||||
json.Indent(&buf, src, prefix, indentStr)
|
||||
err := json.Indent(&buf, src, prefix, indentStr)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("!!! %v", err)
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,8 @@ package test
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
@ -18,29 +20,37 @@ func Test_Roundtrip(t *testing.T) {
|
||||
|
||||
jbStd, err := json.Marshal(before)
|
||||
if err != nil {
|
||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||
t.Fatalf("failed to marshal with stdlib: %v", err)
|
||||
}
|
||||
if len(strings.TrimSpace(string(jbStd))) == 0 {
|
||||
t.Fatal("stdlib marshal produced empty result and no error")
|
||||
}
|
||||
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||
if err != nil {
|
||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||
t.Fatalf("failed to marshal with jsoniter: %v", err)
|
||||
}
|
||||
if len(strings.TrimSpace(string(jbIter))) == 0 {
|
||||
t.Fatal("jsoniter marshal produced empty result and no error")
|
||||
}
|
||||
if string(jbStd) != string(jbIter) {
|
||||
t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||
t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||
indent(jbStd, " "), indent(jbIter, " "), dump(before))
|
||||
}
|
||||
|
||||
var afterStd T
|
||||
err = json.Unmarshal(jbIter, &afterStd)
|
||||
if err != nil {
|
||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||
t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s",
|
||||
err, indent(jbIter, " "))
|
||||
}
|
||||
var afterIter T
|
||||
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||
if err != nil {
|
||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||
t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s",
|
||||
err, indent(jbIter, " "))
|
||||
}
|
||||
if fingerprint(afterStd) != fingerprint(afterIter) {
|
||||
t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||
t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||
dump(afterStd), dump(afterIter), indent(jbIter, " "))
|
||||
}
|
||||
}
|
||||
@ -65,7 +75,10 @@ func dump(obj interface{}) string {
|
||||
|
||||
func indent(src []byte, prefix string) string {
|
||||
var buf bytes.Buffer
|
||||
json.Indent(&buf, src, prefix, indentStr)
|
||||
err := json.Indent(&buf, src, prefix, indentStr)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("!!! %v", err)
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,8 @@ package test
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
@ -18,29 +20,37 @@ func Test_Roundtrip(t *testing.T) {
|
||||
|
||||
jbStd, err := json.Marshal(before)
|
||||
if err != nil {
|
||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||
t.Fatalf("failed to marshal with stdlib: %v", err)
|
||||
}
|
||||
if len(strings.TrimSpace(string(jbStd))) == 0 {
|
||||
t.Fatal("stdlib marshal produced empty result and no error")
|
||||
}
|
||||
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||
if err != nil {
|
||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||
t.Fatalf("failed to marshal with jsoniter: %v", err)
|
||||
}
|
||||
if len(strings.TrimSpace(string(jbIter))) == 0 {
|
||||
t.Fatal("jsoniter marshal produced empty result and no error")
|
||||
}
|
||||
if string(jbStd) != string(jbIter) {
|
||||
t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||
t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||
indent(jbStd, " "), indent(jbIter, " "), dump(before))
|
||||
}
|
||||
|
||||
var afterStd T
|
||||
err = json.Unmarshal(jbIter, &afterStd)
|
||||
if err != nil {
|
||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||
t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s",
|
||||
err, indent(jbIter, " "))
|
||||
}
|
||||
var afterIter T
|
||||
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||
if err != nil {
|
||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||
t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s",
|
||||
err, indent(jbIter, " "))
|
||||
}
|
||||
if fingerprint(afterStd) != fingerprint(afterIter) {
|
||||
t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||
t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||
dump(afterStd), dump(afterIter), indent(jbIter, " "))
|
||||
}
|
||||
}
|
||||
@ -65,7 +75,10 @@ func dump(obj interface{}) string {
|
||||
|
||||
func indent(src []byte, prefix string) string {
|
||||
var buf bytes.Buffer
|
||||
json.Indent(&buf, src, prefix, indentStr)
|
||||
err := json.Indent(&buf, src, prefix, indentStr)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("!!! %v", err)
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user