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

Function TestJSONString

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

Source from the content-addressed store, hash-verified

2572}
2573
2574func TestJSONString(t *testing.T) {
2575 testJSONString(t, "hello")
2576 testJSONString(t, "he\"llo")
2577 testJSONString(t, "he\"l\\lo")
2578 const input = `{"utf8":"Example emoji, KO: \ud83d\udd13, \ud83c\udfc3 ` +
2579 `OK: \u2764\ufe0f "}`
2580 value := Get(input, "utf8")
2581 var s string
2582 json.Unmarshal([]byte(value.Raw), &s)
2583 if value.String() != s {
2584 t.Fatalf("expected '%v', got '%v'", s, value.String())
2585 }
2586 testJSONString(t, s)
2587 testJSONString(t, "R\xfd\xfc\a!\x82eO\x16?_\x0f\x9ab\x1dr")
2588 testJSONString(t, "_\xb9\v\xad\xb3|X!\xb6\xd9U&\xa4\x1a\x95\x04")
2589 data, _ := json.Marshal("\b\f")
2590 if string(data) == "\"\\b\\f\"" {
2591 // Go version 1.22+ encodes "\b" and "\f" correctly.
2592 testJSONString(t, "\b\f")
2593 rng := rand.New(rand.NewSource(time.Now().UnixNano()))
2594 start := time.Now()
2595 var buf [16]byte
2596 for time.Since(start) < time.Second*2 {
2597 if _, err := rng.Read(buf[:]); err != nil {
2598 t.Fatal(err)
2599 }
2600 testJSONString(t, string(buf[:]))
2601 }
2602 }
2603}
2604
2605func TestIndexAtSymbol(t *testing.T) {
2606 json := `{

Callers

nothing calls this directly

Calls 3

testJSONStringFunction · 0.85
GetFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…