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

Function TestManyBasic

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

Source from the content-addressed store, hash-verified

838var testWatchForFallback bool
839
840func TestManyBasic(t *testing.T) {
841 testWatchForFallback = true
842 defer func() {
843 testWatchForFallback = false
844 }()
845 testMany := func(shouldFallback bool, expect string, paths ...string) {
846 results := GetManyBytes(
847 []byte(manyJSON),
848 paths...,
849 )
850 if len(results) != len(paths) {
851 t.Fatalf("expected %v, got %v", len(paths), len(results))
852 }
853 if fmt.Sprintf("%v", results) != expect {
854 fmt.Printf("%v\n", paths)
855 t.Fatalf("expected %v, got %v", expect, results)
856 }
857 }
858 testMany(false, "[Point]", "position.type")
859 testMany(false, `[emptya ["world peace"] 31]`, ".a", "loves", "age")
860 testMany(false, `[["world peace"]]`, "loves")
861 testMany(false, `[{"last":"Anderson","first":"Nancy"} Nancy]`, "name",
862 "name.first")
863 testMany(true, `[]`, strings.Repeat("a.", 40)+"hello")
864 res := Get(manyJSON, strings.Repeat("a.", 48)+"a")
865 testMany(true, `[`+res.String()+`]`, strings.Repeat("a.", 48)+"a")
866 // these should fallback
867 testMany(true, `[Cat Nancy]`, "name\\.first", "name.first")
868 testMany(true, `[world]`, strings.Repeat("a.", 70)+"hello")
869}
870func testMany(t *testing.T, json string, paths, expected []string) {
871 testManyAny(t, json, paths, expected, true)
872 testManyAny(t, json, paths, expected, false)

Callers

nothing calls this directly

Calls 4

GetManyBytesFunction · 0.85
testManyFunction · 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…