@@ -336,11 +336,33 @@ func TestDecodePath(t *testing.T) {
336336 require .NoError (t , result .DecodePath (& u , "array" , 0 ))
337337 assert .Equal (t , uint (1 ), u )
338338
339- require .NoError (t , result .DecodePath (& u , "array" , 2 ))
340- assert .Equal (t , uint (3 ), u )
339+ var u2 uint
340+ require .NoError (t , result .DecodePath (& u2 , "array" , 2 ))
341+ assert .Equal (t , uint (3 ), u2 )
341342
342- require .NoError (t , result .DecodePath (& u , "map" , "mapX" , "arrayX" , 1 ))
343- assert .Equal (t , uint (8 ), u )
343+ // This is past the end of the array
344+ var u3 uint
345+ require .NoError (t , result .DecodePath (& u3 , "array" , 3 ))
346+ assert .Equal (t , uint (0 ), u3 )
347+
348+ // Negative offsets
349+
350+ var n1 uint
351+ require .NoError (t , result .DecodePath (& n1 , "array" , - 1 ))
352+ assert .Equal (t , uint (3 ), n1 )
353+
354+ var n2 uint
355+ require .NoError (t , result .DecodePath (& n2 , "array" , - 3 ))
356+ assert .Equal (t , uint (1 ), n2 )
357+
358+ var u4 uint
359+ require .NoError (t , result .DecodePath (& u4 , "map" , "mapX" , "arrayX" , 1 ))
360+ assert .Equal (t , uint (8 ), u4 )
361+
362+ // Does key not exist
363+ var ne uint
364+ require .NoError (t , result .DecodePath (& ne , "does-not-exist" , 1 ))
365+ assert .Equal (t , uint (0 ), ne )
344366}
345367
346368type TestInterface interface {
0 commit comments