Git Product home page Git Product logo

Comments (10)

wangkechun avatar wangkechun commented on July 24, 2024
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.

chenzhuoyu avatar chenzhuoyu commented on July 24, 2024
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.

chenzhuoyu avatar chenzhuoyu commented on July 24, 2024
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

maps 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.

PureWhiteWu avatar PureWhiteWu commented on July 24, 2024

Do you use HTMLEscape in your production code? @wangkechun

from sonic.

wangkechun avatar wangkechun commented on July 24, 2024

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.

wangkechun avatar wangkechun commented on July 24, 2024
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.

wangkechun avatar wangkechun commented on July 24, 2024

The key order of map

maps 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.

PureWhiteWu avatar PureWhiteWu commented on July 24, 2024

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.

PureWhiteWu avatar PureWhiteWu commented on July 24, 2024

The key order of map

maps 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.

PureWhiteWu avatar PureWhiteWu commented on July 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.