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

Function TestChainedModifierStringArgs

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

Source from the content-addressed store, hash-verified

1905}
1906
1907func TestChainedModifierStringArgs(t *testing.T) {
1908 // issue #143
1909 AddModifier("push", func(json, arg string) string {
1910 json = strings.TrimSpace(json)
1911 if len(json) < 2 || !Parse(json).IsArray() {
1912 return json
1913 }
1914 json = strings.TrimSpace(json[1 : len(json)-1])
1915 if len(json) == 0 {
1916 return "[" + arg + "]"
1917 }
1918 return "[" + json + "," + arg + "]"
1919 })
1920 res := Get("[]", `@push:"2"|@push:"3"|@push:{"a":"b","c":["e","f"]}|@push:true|@push:10.23`)
1921 assert(t, res.String() == `["2","3",{"a":"b","c":["e","f"]},true,10.23]`)
1922}
1923
1924func TestFlatten(t *testing.T) {
1925 json := `[1,[2],[3,4],[5,[6,[7]]],{"hi":"there"},8,[9]]`

Callers

nothing calls this directly

Calls 6

AddModifierFunction · 0.85
ParseFunction · 0.85
GetFunction · 0.85
assertFunction · 0.85
IsArrayMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…