Comments (10)
func TestPrefilledArr(t *testing.T) {
a := &[...]int{1, 2}
b := &[...]int{1, 2}
err1 := json.Unmarshal([]byte(`[3]`), a)
err2 := Unmarshal([]byte(`[3]`), b)
require.Equal(t, err1, err2)
require.Equal(t, a, b)
}
=== RUN TestPrefilledArr
fuzz_test.go:109:
Error Trace: fuzz_test.go:109
Error: Not equal:
expected: &[2]int{3, 0}
actual : &[2]int{3, 2}
Diff:
--- Expected
+++ Actual
@@ -2,3 +2,3 @@
(int) 3,
- (int) 0
+ (int) 2
})
Test: TestPrefilledArr
--- FAIL: TestPrefilledArr (0.00s)
FAIL
exit status 1
from sonic.
func TestPrefilledArr(t *testing.T) { a := &[...]int{1, 2} b := &[...]int{1, 2} err1 := json.Unmarshal([]byte(`[3]`), a) err2 := Unmarshal([]byte(`[3]`), b) require.Equal(t, err1, err2) require.Equal(t, a, b) }
=== RUN TestPrefilledArr fuzz_test.go:109: Error Trace: fuzz_test.go:109 Error: Not equal: expected: &[2]int{3, 0} actual : &[2]int{3, 2} Diff: --- Expected +++ Actual @@ -2,3 +2,3 @@ (int) 3, - (int) 0 + (int) 2 }) Test: TestPrefilledArr --- FAIL: TestPrefilledArr (0.00s) FAIL exit status 1
@wangkechun Please move this into a separate issue. Thanks.
from sonic.
func TestCompatibility(t *testing.T) { inputs := []interface{}{`"<&>"`, `"\"<&>\""`, "\b", float64(-0), float32(-0), map[string]int{"3": 3, "2": 2, "1": 1}} for _, input := range inputs { t.Run(fmt.Sprintf("case %v", input), func(t *testing.T) { buf1, err1 := json.Marshal(input) buf2, err2 := Marshal(input) require.Nil(t, err1) require.Nil(t, err2) require.Equal(t, string(buf1), string(buf2)) }) } }
--- FAIL: TestCompatibility (0.00s) --- FAIL: TestCompatibility/case_"<&>" (0.00s) fuzz_test.go:112: Error Trace: fuzz_test.go:112 Error: Not equal: expected: "\"\\\"\\u003c\\u0026\\u003e\\\"\"" actual : "\"\\\"<&>\\\"\"" Diff: --- Expected +++ Actual @@ -1 +1 @@ -"\"\u003c\u0026\u003e\"" +"\"<&>\"" Test: TestCompatibility/case_"<&>" --- FAIL: TestCompatibility/case_"\"<&>\"" (0.00s) fuzz_test.go:112: Error Trace: fuzz_test.go:112 Error: Not equal: expected: "\"\\\"\\\\\\\"\\u003c\\u0026\\u003e\\\\\\\"\\\"\"" actual : "\"\\\"\\\\\\\"<&>\\\\\\\"\\\"\"" Diff: --- Expected +++ Actual @@ -1 +1 @@ -"\"\\\"\u003c\u0026\u003e\\\"\"" +"\"\\\"<&>\\\"\"" Test: TestCompatibility/case_"\"<&>\"" --- FAIL: TestCompatibility/case_\b (0.00s) fuzz_test.go:112: Error Trace: fuzz_test.go:112 Error: Not equal: expected: "\"\\u0008\"" actual : "\"\\b\"" Diff: --- Expected +++ Actual @@ -1 +1 @@ -"\u0008" +"\b" Test: TestCompatibility/case_\b --- FAIL: TestCompatibility/case_map[1:1_2:2_3:3] (0.00s) fuzz_test.go:112: Error Trace: fuzz_test.go:112 Error: Not equal: expected: "{\"1\":1,\"2\":2,\"3\":3}" actual : "{\"2\":2,\"1\":1,\"3\":3}" Diff: --- Expected +++ Actual @@ -1 +1 @@ -{"1":1,"2":2,"3":3} +{"2":2,"1":1,"3":3} Test: TestCompatibility/case_map[1:1_2:2_3:3] FAIL exit status 1 FAIL github.com/bytedance/sonic 0.144s
This IS compatible with stdlib. Compatibility does not mean it should operates exactly like stdlib, minor diffs does not affect compatibility.
The \b
escape
According to RFC8259, \b
is a valid escape sequence, and the stdlib does not explain why it don't escape to \b
. So I consider it's a bug in the stdlib.
HTMLEscape
Should we support this? @PureWhiteWu
The key order of map
map
s in Go are intrinsically unordered, the Go Spec also says you should NOT rely on the traversal order. And for performance reason, the key is not ordered by design.
from sonic.
Do you use HTMLEscape in your production code? @wangkechun
from sonic.
Do you use HTMLEscape in your production code? @wangkechun
Never, but I want it to be configurable, like https://pkg.go.dev/github.com/json-iterator/go#pkg-variables
from sonic.
func TestPrefilledArr(t *testing.T) { a := &[...]int{1, 2} b := &[...]int{1, 2} err1 := json.Unmarshal([]byte(`[3]`), a) err2 := Unmarshal([]byte(`[3]`), b) require.Equal(t, err1, err2) require.Equal(t, a, b) }
=== RUN TestPrefilledArr fuzz_test.go:109: Error Trace: fuzz_test.go:109 Error: Not equal: expected: &[2]int{3, 0} actual : &[2]int{3, 2} Diff: --- Expected +++ Actual @@ -2,3 +2,3 @@ (int) 3, - (int) 0 + (int) 2 }) Test: TestPrefilledArr --- FAIL: TestPrefilledArr (0.00s) FAIL exit status 1
@wangkechun Please move this into a separate issue. Thanks.
done #7
from sonic.
The key order of
map
map
s in Go are intrinsically unordered, the Go Spec also says you should NOT rely on the traversal order. And for performance reason, the key is not ordered by design.
For unit test, reproducible serialization results are very important.
from sonic.
Do you use HTMLEscape in your production code? @wangkechun
Never, but I want it to be configurable, like https://pkg.go.dev/github.com/json-iterator/go#pkg-variables
I think we can support it if there's real needs for it, but in our investigation, this function is rarely used.
Maybe you can submit another issue if you really need it in your production code.
from sonic.
The key order of
map
map
s in Go are intrinsically unordered, the Go Spec also says you should NOT rely on the traversal order. And for performance reason, the key is not ordered by design.For unit test, reproducible serialization results are very important.
I think you should not rely on the undefined behaviour in your unit tests. Instead, you can test your code by marshal and unmarshal it and compare to the original value.
So I think this is not really an issue.
from sonic.
Closed since there's no more replies.
If you still have questions, feel free to comment or open another issue.
from sonic.
Related Issues (20)
- Depress WARNING: sonic only supports Go1.16~1.22 && CPU amd64, but your environment is not suitable on Apple Chip Macs HOT 4
- bug: `unset()` misbehavior on v1.11.0-x
- can not compile at linux/amd64 and go 1.22 HOT 1
- [ast] invalid memory address or nil pointer dereference HOT 3
- Support golang v1.22 HOT 1
- 使用go的docker镜像编译时cgo报错 HOT 1
- optimize: extra string/[]byte copies when calling Unmarshal HOT 1
- frozenconfig.Unmarshal consumes a large amount of memory. HOT 3
- can sonic support fuzzy decode like jsonitor HOT 3
- 使用sync.Pool管理buf的时候,高QPS可能会导致类似内存占用过大 HOT 9
- go: module github.com/cloudwego/iasm@upgrade found (v0.1.0), but does not contain package github.com/cloudwego/iasm/x86_64 HOT 15
- github.com/bytedance/sonic/[email protected]: verifying go.mod: checksum mismatch HOT 9
- windows use sonic error
- 使用 marshal 方法出现问题 _blankCharsMask overflows int HOT 3
- github.com/bytedance/sonic/ast not support ARM32 "_blankCharsMask overflows int" HOT 2
- Go1.16 Encode/Marshal maybe OOM when high QPS for sonic v1.10.0~v1.11.6
- Go is going to lock down future uses of `linkname` HOT 6
- optimize stream decoder SkipOneFast
- 在启用cgo环境中的情况下,编译出错ast\decode.go:31:29: cannot use 4294977024 (untyped int constant) as int value in constant declaration (overflows) HOT 3
- Error: relocation target github.com/bytedance/sonic/internal/rt.StartProf not defined HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sonic.