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

Function TestSingleArrayValue

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

Source from the content-addressed store, hash-verified

795}
796
797func TestSingleArrayValue(t *testing.T) {
798 var json = `{"key": "value","key2":[1,2,3,4,"A"]}`
799 var result = Get(json, "key")
800 var array = result.Array()
801 if len(array) != 1 {
802 t.Fatal("array is empty")
803 }
804 if array[0].String() != "value" {
805 t.Fatalf("got %s, should be %s", array[0].String(), "value")
806 }
807
808 array = Get(json, "key2.#").Array()
809 if len(array) != 1 {
810 t.Fatalf("got '%v', expected '%v'", len(array), 1)
811 }
812
813 array = Get(json, "key3").Array()
814 if len(array) != 0 {
815 t.Fatalf("got '%v', expected '%v'", len(array), 0)
816 }
817
818}
819
820var manyJSON = ` {
821 "a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{

Callers

nothing calls this directly

Calls 3

GetFunction · 0.85
ArrayMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…