@@ -2898,104 +2898,3 @@ func TestToDecimal(t *testing.T) {
28982898 })
28992899 }
29002900}
2901-
2902- func TestAllPaths (t * testing.T ) {
2903- cases := []struct {
2904- json string
2905- expected []string
2906- }{
2907- {`{}` , []string {`{}` }},
2908- {`[]` , []string {`[]` }},
2909- {`[1, 2, 3]` , []string {`[1]` , `[2]` , `[3]` }},
2910- {`{"foo": {"bar": [1, 2, 3]}}` , []string {`{"foo": {"bar": [1]}}` , `{"foo": {"bar": [2]}}` , `{"foo": {"bar": [3]}}` }},
2911- {
2912- `{"a": [1, 2, true, false], "b": {"ba": 0, "bb": null}, "c": {}}` ,
2913- []string {`{"a": [1]}` , `{"a": [2]}` , `{"a": [true]}` , `{"a": [false]}` , `{"b": {"ba": 0}}` , `{"b": {"bb": null}}` , `{"c": {}}` },
2914- },
2915- }
2916-
2917- for i , tc := range cases {
2918- t .Run (fmt .Sprintf ("all paths - %d" , i ), func (t * testing.T ) {
2919- j := parseJSON (t , tc .json )
2920- paths , err := AllPaths (j )
2921- if err != nil {
2922- t .Fatal (err )
2923- }
2924- if len (paths ) != len (tc .expected ) {
2925- t .Fatalf ("expected %d paths, got %d" , len (tc .expected ), len (paths ))
2926- }
2927- for k , p := range paths {
2928- cmp , err := p .Compare (parseJSON (t , tc .expected [k ]))
2929- if err != nil {
2930- t .Fatal (err )
2931- }
2932- if cmp != 0 {
2933- t .Fatalf ("expected %s, got %s" , tc .expected [k ], p .String ())
2934- }
2935- }
2936- })
2937- }
2938- }
2939-
2940- func TestAllPathsWithDepth (t * testing.T ) {
2941- cases := []struct {
2942- json string
2943- depthToExpected map [int ][]string
2944- }{
2945- {`{}` , map [int ][]string {
2946- - 1 : {`{}` },
2947- 0 : {`{}` },
2948- 1 : {`{}` },
2949- 2 : {`{}` },
2950- }},
2951- {`[]` , map [int ][]string {
2952- - 1 : {`[]` },
2953- 0 : {`[]` },
2954- 1 : {`[]` },
2955- 2 : {`[]` },
2956- }},
2957- {`[1, 2, 3]` , map [int ][]string {
2958- - 1 : {`[1]` , `[2]` , `[3]` },
2959- 0 : {`[1, 2, 3]` },
2960- 1 : {`[1]` , `[2]` , `[3]` },
2961- 2 : {`[1]` , `[2]` , `[3]` },
2962- }},
2963- {`{"foo": {"bar": [1, 2, 3]}}` , map [int ][]string {
2964- - 1 : {`{"foo": {"bar": [1]}}` , `{"foo": {"bar": [2]}}` , `{"foo": {"bar": [3]}}` },
2965- 0 : {`{"foo": {"bar": [1, 2, 3]}}` },
2966- 1 : {`{"foo": {"bar": [1, 2, 3]}}` },
2967- 2 : {`{"foo": {"bar": [1, 2, 3]}}` },
2968- 3 : {`{"foo": {"bar": [1]}}` , `{"foo": {"bar": [2]}}` , `{"foo": {"bar": [3]}}` },
2969- }},
2970- {`{"a": [1, 2, true, false], "b": {"ba": 0, "bb": null}, "c": {}}` , map [int ][]string {
2971- - 1 : {`{"a": [1]}` , `{"a": [2]}` , `{"a": [true]}` , `{"a": [false]}` , `{"b": {"ba": 0}}` , `{"b": {"bb": null}}` , `{"c": {}}` },
2972- 0 : {`{"a": [1, 2, true, false], "b": {"ba": 0, "bb": null}, "c": {}}` },
2973- 1 : {`{"a": [1, 2, true, false]}` , `{"b": {"ba": 0, "bb": null}}` , `{"c": {}}` },
2974- 2 : {`{"a": [1]}` , `{"a": [2]}` , `{"a": [true]}` , `{"a": [false]}` , `{"b": {"ba": 0}}` , `{"b": {"bb": null}}` , `{"c": {}}` },
2975- }},
2976- }
2977-
2978- for i , tc := range cases {
2979- t .Run (fmt .Sprintf ("all paths with depth - %d" , i ), func (t * testing.T ) {
2980- j := parseJSON (t , tc .json )
2981- for depth , expected := range tc .depthToExpected {
2982- paths , err := AllPathsWithDepth (j , depth )
2983- if err != nil {
2984- t .Fatal (err )
2985- }
2986- if len (paths ) != len (expected ) {
2987- t .Fatalf ("expected %d paths, got %d" , len (expected ), len (paths ))
2988- }
2989- for k , p := range paths {
2990- cmp , err := p .Compare (parseJSON (t , expected [k ]))
2991- if err != nil {
2992- t .Fatal (err )
2993- }
2994- if cmp != 0 {
2995- t .Fatalf ("expected %s, got %s" , expected [k ], p .String ())
2996- }
2997- }
2998- }
2999- })
3000- }
3001- }
0 commit comments