diff options
Diffstat (limited to 'compat')
-rw-r--r-- | compat/json/README.md | 12 | ||||
-rw-r--r-- | compat/json/borrowed_encode_test.go | 3 | ||||
-rw-r--r-- | compat/json/borrowed_example_marshaling_test.go | 3 | ||||
-rw-r--r-- | compat/json/borrowed_example_test.go | 7 | ||||
-rw-r--r-- | compat/json/borrowed_example_text_marshaling_test.go | 3 | ||||
-rw-r--r-- | compat/json/borrowed_fuzz_test.go | 5 | ||||
-rw-r--r-- | compat/json/borrowed_stream_test.go | 5 | ||||
-rw-r--r-- | compat/json/compat_test.go | 27 |
8 files changed, 46 insertions, 19 deletions
diff --git a/compat/json/README.md b/compat/json/README.md index ec8dbed..531b87e 100644 --- a/compat/json/README.md +++ b/compat/json/README.md @@ -50,11 +50,11 @@ Types that are deprecated in `encoding/json` are not mimiced here: <!-- packages --> [`lowmemjson`]: https://pkg.go.dev/git.lukeshu.com/go/lowmemjson -[`encoding/json`]: https://pkg.go.dev/encoding/json@go1.18 +[`encoding/json`]: https://pkg.go.dev/encoding/json@go1.20 <!-- symbols --> -[`Delim`]: https://pkg.go.dev/encoding/json@go1.18#Delim -[`Token`]: https://pkg.go.dev/encoding/json@go1.18#Token -[`Decoder.Token`]: https://pkg.go.dev/encoding/json@go1.18#Decoder.Token -[`InvalidUTF8Error`]: https://pkg.go.dev/encoding/json@go1.18#InvalidUTF8Error -[`UnmarshalFieldError`]: https://pkg.go.dev/encoding/json@go1.18#UnmarshalFieldError +[`Delim`]: https://pkg.go.dev/encoding/json@go1.20#Delim +[`Token`]: https://pkg.go.dev/encoding/json@go1.20#Token +[`Decoder.Token`]: https://pkg.go.dev/encoding/json@go1.20#Decoder.Token +[`InvalidUTF8Error`]: https://pkg.go.dev/encoding/json@go1.20#InvalidUTF8Error +[`UnmarshalFieldError`]: https://pkg.go.dev/encoding/json@go1.20#UnmarshalFieldError diff --git a/compat/json/borrowed_encode_test.go b/compat/json/borrowed_encode_test.go index 999c694..d602934 100644 --- a/compat/json/borrowed_encode_test.go +++ b/compat/json/borrowed_encode_test.go @@ -10,7 +10,6 @@ import ( "bytes" "encoding" "fmt" - "log" "math" "reflect" "regexp" @@ -1085,7 +1084,7 @@ func TestMarshalFloat(t *testing.T) { s := fmt.Sprintf("%c%se%d", sign, digits[:i], exp) f, err := strconv.ParseFloat(s, bits) if err != nil { - log.Fatal(err) + t.Fatal(err) // MODIFIED: changed from log.Fatal to t.Fatal } next := math.Nextafter if bits == 32 { diff --git a/compat/json/borrowed_example_marshaling_test.go b/compat/json/borrowed_example_marshaling_test.go index 44a7c5d..e1af4df 100644 --- a/compat/json/borrowed_example_marshaling_test.go +++ b/compat/json/borrowed_example_marshaling_test.go @@ -7,10 +7,11 @@ package json_test import ( - "encoding/json" "fmt" "log" "strings" + + "git.lukeshu.com/go/lowmemjson/compat/json" ) type Animal int diff --git a/compat/json/borrowed_example_test.go b/compat/json/borrowed_example_test.go index fd984cd..5c612eb 100644 --- a/compat/json/borrowed_example_test.go +++ b/compat/json/borrowed_example_test.go @@ -8,12 +8,13 @@ package json_test import ( "bytes" - "encoding/json" "fmt" "io" "log" "os" "strings" + + "git.lukeshu.com/go/lowmemjson/compat/json" ) func ExampleMarshal() { @@ -85,6 +86,7 @@ func ExampleDecoder() { // Ed: Go fmt yourself! } +/* // MODIFIED: we don't have tokens // This example uses a Decoder to decode a stream of distinct JSON values. func ExampleDecoder_Token() { const jsonStream = ` @@ -121,7 +123,9 @@ func ExampleDecoder_Token() { // float64: 1.234 // json.Delim: } } +*/ // MODIFIED: we don't have tokens +/* // MODIFIED: we don't have tokens // This example uses a Decoder to decode a streaming array of JSON objects. func ExampleDecoder_Decode_stream() { const jsonStream = ` @@ -173,6 +177,7 @@ func ExampleDecoder_Decode_stream() { // Ed: Go fmt yourself! // json.Delim: ] } +*/ // MODIFIED: we don't have tokens // This example uses RawMessage to delay parsing part of a JSON message. func ExampleRawMessage_unmarshal() { diff --git a/compat/json/borrowed_example_text_marshaling_test.go b/compat/json/borrowed_example_text_marshaling_test.go index 3bfcd34..821851c 100644 --- a/compat/json/borrowed_example_text_marshaling_test.go +++ b/compat/json/borrowed_example_text_marshaling_test.go @@ -7,10 +7,11 @@ package json_test import ( - "encoding/json" "fmt" "log" "strings" + + "git.lukeshu.com/go/lowmemjson/compat/json" ) type Size int diff --git a/compat/json/borrowed_fuzz_test.go b/compat/json/borrowed_fuzz_test.go index 6a0b0d1..a909d75 100644 --- a/compat/json/borrowed_fuzz_test.go +++ b/compat/json/borrowed_fuzz_test.go @@ -7,6 +7,8 @@ package json import ( + "bytes" + "io" "testing" ) @@ -50,8 +52,8 @@ func FuzzUnmarshalJSON(f *testing.F) { }) } -/* // MODIFIED: we don't do tokens func FuzzDecoderToken(f *testing.F) { + f.Skip("we don't have tokens") // MODIFIED: added f.Add([]byte(`{ "object": { "slice": [ @@ -82,4 +84,3 @@ func FuzzDecoderToken(f *testing.F) { } }) } -*/ // MODIFIED: we don't do tokens diff --git a/compat/json/borrowed_stream_test.go b/compat/json/borrowed_stream_test.go index d90898b..d50898a 100644 --- a/compat/json/borrowed_stream_test.go +++ b/compat/json/borrowed_stream_test.go @@ -363,8 +363,6 @@ func TestBlocking(t *testing.T) { } } -//nolint:dupword // False positive, this is commented-out code, not a real comment. // MODIFIED: added nolint declaration -/* // MODIFIED: we don't have tokens type tokenStreamCase struct { json string expTokens []any @@ -446,6 +444,8 @@ var tokenStreamCases = []tokenStreamCase{ } func TestDecodeInStream(t *testing.T) { + t.Parallel() // MODIFIED: added + t.Skip("we don't have tokens") // MODIFIED: added for ci, tcase := range tokenStreamCases { dec := NewDecoder(strings.NewReader(tcase.json)) @@ -479,7 +479,6 @@ func TestDecodeInStream(t *testing.T) { } } } -*/ // MODIFIED: we don't have tokens // Test from golang.org/issue/11893 func TestHTTPDecoding(t *testing.T) { diff --git a/compat/json/compat_test.go b/compat/json/compat_test.go index 203594f..07c75bc 100644 --- a/compat/json/compat_test.go +++ b/compat/json/compat_test.go @@ -6,12 +6,14 @@ package json import ( "bytes" + "encoding/json" "io" + _ "unsafe" "git.lukeshu.com/go/lowmemjson" + "git.lukeshu.com/go/lowmemjson/internal/fastio" "git.lukeshu.com/go/lowmemjson/internal/jsonparse" "git.lukeshu.com/go/lowmemjson/internal/jsonstruct" - "git.lukeshu.com/go/lowmemjson/internal/jsontest" ) var ( @@ -56,10 +58,29 @@ type encodeState struct { bytes.Buffer } +//go:linkname encodeStringFromString git.lukeshu.com/go/lowmemjson.encodeStringFromString +func encodeStringFromString(w fastio.AllWriter, escaper lowmemjson.BackslashEscaper, str string) error + +//go:linkname encodeStringFromBytes git.lukeshu.com/go/lowmemjson.encodeStringFromBytes +func encodeStringFromBytes(w fastio.AllWriter, escaper lowmemjson.BackslashEscaper, str []byte) error + func (es *encodeState) string(str string, _ bool) { - jsontest.EncodeStringFromString(&es.Buffer, str) + if err := encodeStringFromString(&es.Buffer, nil, str); err != nil { + panic(err) + } } func (es *encodeState) stringBytes(str []byte, _ bool) { - jsontest.EncodeStringFromBytes(&es.Buffer, str) + if err := encodeStringFromBytes(&es.Buffer, nil, str); err != nil { + panic(err) + } +} + +type ( + Token = json.Token + Delim = json.Delim +) + +func (dec *Decoder) Token() (Token, error) { + panic("not implemented") } |