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.go80
1 files changed, 80 insertions, 0 deletions
diff --git a/compat/json/testcompat_test.go b/compat/json/testcompat_test.go
new file mode 100644
index 0000000..42cbf5c
--- /dev/null
+++ b/compat/json/testcompat_test.go
@@ -0,0 +1,80 @@
+// 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/jsonparse"
+ "git.lukeshu.com/go/lowmemjson/internal/jsonstring"
+ "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
+}
+
+func (es *encodeState) string(str string, _ bool) {
+ if err := jsonstring.EncodeStringFromString(&es.Buffer, lowmemjson.EscapeDefault, str); err != nil {
+ panic(err)
+ }
+}
+
+func (es *encodeState) stringBytes(str []byte, _ bool) {
+ if err := jsonstring.EncodeStringFromBytes(&es.Buffer, lowmemjson.EscapeDefault, str); err != nil {
+ panic(err)
+ }
+}
+
+type (
+ Token = json.Token
+ Delim = json.Delim
+)
+
+func (dec *Decoder) Token() (Token, error) {
+ panic("not implemented")
+}