File tree Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -108,11 +108,15 @@ func Parse(pathString string) (Path, error) {
108108}
109109
110110func (p Path ) WithProperty (part string ) Path {
111- return append (p , mapPathComponent (part ))
111+ nePath := append (Path {}, p ... )
112+ nePath = append (nePath , mapPathComponent (part ))
113+ return nePath
112114}
113115
114116func (p Path ) WithIndex (idx int ) Path {
115- return append (p , arrayPathComponent (idx ))
117+ nePath := append (Path {}, p ... )
118+ nePath = append (nePath , arrayPathComponent (idx ))
119+ return nePath
116120}
117121
118122func (p Path ) Property () pathComponent {
Original file line number Diff line number Diff line change @@ -73,3 +73,33 @@ func TestParsePath(t *testing.T) {
7373 })
7474 }
7575}
76+
77+ func TestWithProperty (t * testing.T ) {
78+ rootPath := Path {}.WithProperty ("foo" ).WithProperty ("bar" ).WithProperty ("aaaa" )
79+
80+ path1 := rootPath .WithProperty ("baz1" )
81+ path2 := rootPath .WithProperty ("baz2" )
82+
83+ if path1 .String () != "foo.bar.aaaa.baz1" {
84+ t .Errorf ("path1.String() = %v, expected %v" , path1 .String (), "foo.bar.aaaa.baz1" )
85+ }
86+
87+ if path2 .String () != "foo.bar.aaaa.baz2" {
88+ t .Errorf ("path2.String() = %v, expected %v" , path2 .String (), "foo.bar.aaaa.baz2" )
89+ }
90+ }
91+
92+ func TestWithIndex (t * testing.T ) {
93+ rootPath := Path {}.WithProperty ("foo" ).WithProperty ("bar" ).WithProperty ("aaaa" )
94+
95+ path1 := rootPath .WithIndex (0 )
96+ path2 := rootPath .WithIndex (1 )
97+
98+ if path1 .String () != "foo.bar.aaaa[0]" {
99+ t .Errorf ("path1.String() = %v, expected %v" , path1 .String (), "foo.bar.aaaa[0]" )
100+ }
101+
102+ if path2 .String () != "foo.bar.aaaa[1]" {
103+ t .Errorf ("path2.String() = %v, expected %v" , path2 .String (), "foo.bar.aaaa[1]" )
104+ }
105+ }
You can’t perform that action at this time.
0 commit comments