@@ -142,6 +142,122 @@ func isEqualFunc(val interface{}, current interface{}, field interface{}, param
142142 return current .(string ) == field .(string )
143143}
144144
145+ func (ms * MySuite ) TestIsNeFieldValidation (c * C ) {
146+
147+ var j uint64
148+ var k float64
149+ s := "abcd"
150+ i := 1
151+ j = 1
152+ k = 1.543
153+ arr := []string {"test" }
154+ now := time .Now ().UTC ()
155+
156+ var j2 uint64
157+ var k2 float64
158+ s2 := "abcdef"
159+ i2 := 3
160+ j2 = 2
161+ k2 = 1.5434456
162+ arr2 := []string {"test" , "test2" }
163+ arr3 := []string {"test" }
164+ now2 := now
165+
166+ err := validate .FieldWithValue (s , s2 , "nefield" )
167+ c .Assert (err , IsNil )
168+
169+ err = validate .FieldWithValue (i2 , i , "nefield" )
170+ c .Assert (err , IsNil )
171+
172+ err = validate .FieldWithValue (j2 , j , "nefield" )
173+ c .Assert (err , IsNil )
174+
175+ err = validate .FieldWithValue (k2 , k , "nefield" )
176+ c .Assert (err , IsNil )
177+
178+ err = validate .FieldWithValue (arr2 , arr , "nefield" )
179+ c .Assert (err , IsNil )
180+
181+ err = validate .FieldWithValue (now2 , now , "nefield" )
182+ c .Assert (err , NotNil )
183+
184+ err = validate .FieldWithValue (arr3 , arr , "nefield" )
185+ c .Assert (err , NotNil )
186+
187+ type Test struct {
188+ Start * time.Time `validate:"nefield=End"`
189+ End * time.Time
190+ }
191+
192+ sv := & Test {
193+ Start : & now ,
194+ End : & now ,
195+ }
196+
197+ errs := validate .Struct (sv )
198+ c .Assert (errs , NotNil )
199+
200+ now3 := time .Now ().UTC ()
201+
202+ sv = & Test {
203+ Start : & now ,
204+ End : & now3 ,
205+ }
206+
207+ errs = validate .Struct (sv )
208+ c .Assert (errs , IsNil )
209+
210+ channel := make (chan string )
211+
212+ c .Assert (func () { validate .FieldWithValue (nil , 1 , "nefield" ) }, PanicMatches , "struct not passed for cross validation" )
213+ c .Assert (func () { validate .FieldWithValue (5 , channel , "nefield" ) }, PanicMatches , "Bad field type chan string" )
214+ c .Assert (func () { validate .FieldWithValue (5 , now , "nefield" ) }, PanicMatches , "Bad Top Level field type" )
215+
216+ type Test2 struct {
217+ Start * time.Time `validate:"nefield=NonExistantField"`
218+ End * time.Time
219+ }
220+
221+ sv2 := & Test2 {
222+ Start : & now ,
223+ End : & now ,
224+ }
225+
226+ c .Assert (func () { validate .Struct (sv2 ) }, PanicMatches , "Field \" NonExistantField\" not found in struct" )
227+ }
228+
229+ func (ms * MySuite ) TestIsNeValidation (c * C ) {
230+
231+ var j uint64
232+ var k float64
233+ s := "abcdef"
234+ i := 3
235+ j = 2
236+ k = 1.5434
237+ arr := []string {"test" }
238+ now := time .Now ().UTC ()
239+
240+ err := validate .Field (s , "ne=abcd" )
241+ c .Assert (err , IsNil )
242+
243+ err = validate .Field (i , "ne=1" )
244+ c .Assert (err , IsNil )
245+
246+ err = validate .Field (j , "ne=1" )
247+ c .Assert (err , IsNil )
248+
249+ err = validate .Field (k , "ne=1.543" )
250+ c .Assert (err , IsNil )
251+
252+ err = validate .Field (arr , "ne=2" )
253+ c .Assert (err , IsNil )
254+
255+ err = validate .Field (arr , "ne=1" )
256+ c .Assert (err , NotNil )
257+
258+ c .Assert (func () { validate .Field (now , "ne=now" ) }, PanicMatches , "Bad field type time.Time" )
259+ }
260+
145261func (ms * MySuite ) TestIsEqFieldValidation (c * C ) {
146262
147263 var j uint64
0 commit comments