summaryrefslogtreecommitdiff
path: root/compat/json/testcompat_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'compat/json/testcompat_test.go')
-rw-r--r--compat/json/testcompat_test.go86
1 files changed, 86 insertions, 0 deletions
diff --git a/compat/json/testcompat_test.go b/compat/json/testcompat_test.go
new file mode 100644
index 0000000..07c75bc
--- /dev/null
+++ b/compat/json/testcompat_test.go
@@ -0,0 +1,86 @@
+// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com>
+//
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+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"
+)
+
+var (
+ parseTag = jsonstruct.ParseTag
+ clearCache = jsonstruct.ClearCache
+ cachedTypeFields = jsonstruct.IndexStruct
+)
+
+type scanner = lowmemjson.ReEncoderConfig
+
+func checkValid(in []byte, scan *lowmemjson.ReEncoderConfig) error {
+ return reencode(io.Discard, in, *scan)
+}
+
+func isValidNumber(s string) bool {
+ var parser jsonparse.Parser
+ for _, r := range s {
+ if t, _ := parser.HandleRune(r); !t.IsNumber() {
+ return false
+ }
+ }
+ if t, _ := parser.HandleEOF(); t == jsonparse.RuneTypeError {
+ return false
+ }
+ return true
+}
+
+const (
+ startDetectingCyclesAfter = 1000
+)
+
+func isSpace(c byte) bool {
+ switch c {
+ case 0x0020, 0x000A, 0x000D, 0x0009:
+ return true
+ default:
+ return false
+ }
+}
+
+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) {
+ if err := encodeStringFromString(&es.Buffer, nil, str); err != nil {
+ panic(err)
+ }
+}
+
+func (es *encodeState) stringBytes(str []byte, _ bool) {
+ 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")
+}