@@ -33,6 +33,10 @@ func TestPathElementSet(t *testing.T) {
3333 if ! s2 .Has (PathElement {}) {
3434 t .Errorf ("expected to have something: %#v" , s2 )
3535 }
36+ c2 := s2 .Copy ()
37+ if ! c2 .Equals (s2 ) {
38+ t .Errorf ("expected copy to equal original: %#v, %#v" , s2 , c2 )
39+ }
3640
3741 n1 := "aoeu"
3842 n2 := "asdf"
@@ -60,6 +64,20 @@ func TestPathElementSet(t *testing.T) {
6064 }
6165 i ++
6266 })
67+ i = 0
68+ for pe := range s2 .All () {
69+ e , a := expected [i ], pe .FieldName
70+ if e == nil || a == nil {
71+ if e != a {
72+ t .Errorf ("index %v wanted %#v, got %#v" , i , e , a )
73+ }
74+ } else {
75+ if * e != * a {
76+ t .Errorf ("index %v wanted %#v, got %#v" , i , * e , * a )
77+ }
78+ }
79+ i ++
80+ }
6381}
6482
6583func strptr (s string ) * string { return & s }
@@ -68,6 +86,9 @@ func valptr(i interface{}) *value.Value {
6886 v := value .NewValueInterface (i )
6987 return & v
7088}
89+ func val (i interface {}) value.Value {
90+ return value .NewValueInterface (i )
91+ }
7192
7293func TestPathElementLess (t * testing.T ) {
7394 table := []struct {
@@ -84,71 +105,71 @@ func TestPathElementLess(t *testing.T) {
84105 eq : true ,
85106 }, {
86107 name : "FieldName-1" ,
87- a : PathElement { FieldName : strptr ("anteater" )} ,
88- b : PathElement { FieldName : strptr ("zebra" )} ,
108+ a : FieldNameElement ("anteater" ),
109+ b : FieldNameElement ("zebra" ),
89110 }, {
90111 name : "FieldName-2" ,
91- a : PathElement { FieldName : strptr ("bee" )} ,
92- b : PathElement { FieldName : strptr ("bee" )} ,
112+ a : FieldNameElement ("bee" ),
113+ b : FieldNameElement ("bee" ),
93114 eq : true ,
94115 }, {
95116 name : "FieldName-3" ,
96- a : PathElement { FieldName : strptr ("capybara" )} ,
97- b : PathElement { Key : KeyByFields ("dog" , 3 )} ,
117+ a : FieldNameElement ("capybara" ),
118+ b : KeyElementByFields ("dog" , 3 ),
98119 }, {
99120 name : "FieldName-4" ,
100- a : PathElement { FieldName : strptr ("elephant" )} ,
101- b : PathElement { Value : valptr ( 4 )} ,
121+ a : FieldNameElement ("elephant" ),
122+ b : ValueElement ( val ( 4 )) ,
102123 }, {
103124 name : "FieldName-5" ,
104- a : PathElement { FieldName : strptr ("falcon" )} ,
105- b : PathElement { Index : intptr (5 )} ,
125+ a : FieldNameElement ("falcon" ),
126+ b : IndexElement (5 ),
106127 }, {
107128 name : "Key-1" ,
108- a : PathElement { Key : KeyByFields ("goat" , 1 )} ,
109- b : PathElement { Key : KeyByFields ("goat" , 1 )} ,
129+ a : KeyElementByFields ("goat" , 1 ),
130+ b : KeyElementByFields ("goat" , 1 ),
110131 eq : true ,
111132 }, {
112133 name : "Key-2" ,
113- a : PathElement { Key : KeyByFields ("horse" , 1 )} ,
114- b : PathElement { Key : KeyByFields ("horse" , 2 )} ,
134+ a : KeyElementByFields ("horse" , 1 ),
135+ b : KeyElementByFields ("horse" , 2 ),
115136 }, {
116137 name : "Key-3" ,
117- a : PathElement { Key : KeyByFields ("ibex" , 1 )} ,
118- b : PathElement { Key : KeyByFields ("jay" , 1 )} ,
138+ a : KeyElementByFields ("ibex" , 1 ),
139+ b : KeyElementByFields ("jay" , 1 ),
119140 }, {
120141 name : "Key-4" ,
121- a : PathElement { Key : KeyByFields ("kite" , 1 )} ,
122- b : PathElement { Key : KeyByFields ("kite" , 1 , "kite-2" , 1 )} ,
142+ a : KeyElementByFields ("kite" , 1 ),
143+ b : KeyElementByFields ("kite" , 1 , "kite-2" , 1 ),
123144 }, {
124145 name : "Key-5" ,
125- a : PathElement { Key : KeyByFields ("kite" , 1 )} ,
126- b : PathElement { Value : valptr ( 1 )} ,
146+ a : KeyElementByFields ("kite" , 1 ),
147+ b : ValueElement ( val ( 1 )) ,
127148 }, {
128149 name : "Key-6" ,
129- a : PathElement { Key : KeyByFields ("kite" , 1 )} ,
130- b : PathElement { Index : intptr (5 )} ,
150+ a : KeyElementByFields ("kite" , 1 ),
151+ b : IndexElement (5 ),
131152 }, {
132153 name : "Value-1" ,
133- a : PathElement { Value : valptr ( 1 )} ,
134- b : PathElement { Value : valptr ( 2 )} ,
154+ a : ValueElement ( val ( 1 )) ,
155+ b : ValueElement ( val ( 2 )) ,
135156 }, {
136157 name : "Value-2" ,
137- a : PathElement { Value : valptr ( 1 )} ,
138- b : PathElement { Value : valptr ( 1 )} ,
158+ a : ValueElement ( val ( 1 )) ,
159+ b : ValueElement ( val ( 1 )) ,
139160 eq : true ,
140161 }, {
141162 name : "Value-3" ,
142- a : PathElement { Value : valptr ( 1 )} ,
143- b : PathElement { Index : intptr (1 )} ,
163+ a : ValueElement ( val ( 1 )) ,
164+ b : IndexElement (1 ),
144165 }, {
145166 name : "Index-1" ,
146- a : PathElement { Index : intptr (1 )} ,
147- b : PathElement { Index : intptr (2 )} ,
167+ a : IndexElement (1 ),
168+ b : IndexElement (2 ),
148169 }, {
149170 name : "Index-2" ,
150- a : PathElement { Index : intptr (1 )} ,
151- b : PathElement { Index : intptr (1 )} ,
171+ a : IndexElement (1 ),
172+ b : IndexElement (1 ),
152173 eq : true ,
153174 },
154175 }
0 commit comments