MCPcopy
hub / github.com/tidwall/gjson / TestRandomValidStrings

Function TestRandomValidStrings

gjson_test.go:42–65  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

40}
41
42func TestRandomValidStrings(t *testing.T) {
43 rand.Seed(time.Now().UnixNano())
44 b := make([]byte, 200)
45 for i := 0; i < 100000; i++ {
46 n, err := rand.Read(b[:rand.Int()%len(b)])
47 if err != nil {
48 t.Fatal(err)
49 }
50 sm, err := json.Marshal(string(b[:n]))
51 if err != nil {
52 t.Fatal(err)
53 }
54 var su string
55 if err := json.Unmarshal([]byte(sm), &su); err != nil {
56 t.Fatal(err)
57 }
58 token := Get(`{"str":`+string(sm)+`}`, "str")
59 if token.Type != String || token.Str != su {
60 println("["+token.Raw+"]", "["+token.Str+"]", "["+su+"]",
61 "["+string(sm)+"]")
62 t.Fatal("string mismatch")
63 }
64 }
65}
66
67func TestEmoji(t *testing.T) {
68 const input = `{"utf8":"Example emoji, KO: \ud83d\udd13, \ud83c\udfc3 ` +

Callers

nothing calls this directly

Calls 2

GetFunction · 0.85
IntMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…