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

Function TestForEach

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

Source from the content-addressed store, hash-verified

405 assert(t, (Result{Type: Number, Num: 1}).Float() == 1)
406}
407func TestForEach(t *testing.T) {
408 Result{}.ForEach(nil)
409 Result{Type: String, Str: "Hello"}.ForEach(func(_, value Result) bool {
410 assert(t, value.String() == "Hello")
411 return false
412 })
413 Result{Type: JSON, Raw: "*invalid*"}.ForEach(nil)
414
415 json := ` {"name": {"first": "Janet","last": "Prichard"},
416 "asd\nf":"\ud83d\udd13","age": 47}`
417 var count int
418 ParseBytes([]byte(json)).ForEach(func(key, value Result) bool {
419 count++
420 return true
421 })
422 assert(t, count == 3)
423 ParseBytes([]byte(`{"bad`)).ForEach(nil)
424 ParseBytes([]byte(`{"ok":"bad`)).ForEach(nil)
425}
426func TestMap(t *testing.T) {
427 assert(t, len(ParseBytes([]byte(`"asdf"`)).Map()) == 0)
428 assert(t, ParseBytes([]byte(`{"asdf":"ghjk"`)).Map()["asdf"].String() ==

Callers

nothing calls this directly

Calls 4

assertFunction · 0.85
ParseBytesFunction · 0.85
ForEachMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…