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

Function TestByteSafety

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

Source from the content-addressed store, hash-verified

253 assert(t, GetMany(json, path)[0].String() == "b")
254}
255func TestByteSafety(t *testing.T) {
256 jsonb := []byte(`{"name":"Janet","age":38}`)
257 mtok := GetBytes(jsonb, "name")
258 if mtok.String() != "Janet" {
259 t.Fatalf("expected %v, got %v", "Jason", mtok.String())
260 }
261 mtok2 := GetBytes(jsonb, "age")
262 if mtok2.Raw != "38" {
263 t.Fatalf("expected %v, got %v", "Jason", mtok2.Raw)
264 }
265 jsonb[9] = 'T'
266 jsonb[12] = 'd'
267 jsonb[13] = 'y'
268 if mtok.String() != "Janet" {
269 t.Fatalf("expected %v, got %v", "Jason", mtok.String())
270 }
271}
272
273func get(json, path string) Result {
274 return GetBytes([]byte(json), path)

Callers

nothing calls this directly

Calls 2

GetBytesFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…