| 1905 | } |
| 1906 | |
| 1907 | func 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 | |
| 1924 | func TestFlatten(t *testing.T) { |
| 1925 | json := `[1,[2],[3,4],[5,[6,[7]]],{"hi":"there"},8,[9]]` |