@@ -307,6 +307,23 @@ def test_test_error(self):
307307 jsonpatch .apply_patch ,
308308 obj , [{'op' : 'test' , 'path' : '/bar' , 'value' : 'bar' }])
309309
310+ def test_test_numbers_by_value (self ):
311+ obj = {'a' : 1 , 'b' : [0.0 ], 'c' : {'d' : 2 }}
312+ jsonpatch .apply_patch (obj , [{'op' : 'test' , 'path' : '/a' , 'value' : 1.0 },
313+ {'op' : 'test' , 'path' : '/b' , 'value' : [0 ]},
314+ {'op' : 'test' , 'path' : '/c' , 'value' : {'d' : 2.0 }}])
315+
316+ def test_test_literals_differ_from_numbers (self ):
317+ # RFC 6902, 4.6: true and false are only equal to themselves, #216
318+ for doc , value in [({'a' : 1 }, True ),
319+ ({'a' : [1 ]}, [True ]),
320+ ({'a' : {'a' : 0 }}, {'a' : False }),
321+ ({'a' : True }, 1 ),
322+ ({'a' : False }, 0 )]:
323+ with self .assertRaises (jsonpatch .JsonPatchTestFailed ):
324+ jsonpatch .apply_patch (
325+ doc , [{'op' : 'test' , 'path' : '/a' , 'value' : value }])
326+
310327
311328 def test_test_not_existing (self ):
312329 obj = {'bar' : 'qux' }
@@ -382,6 +399,17 @@ def test_patch_unequal(self):
382399 patch2 = jsonpatch .JsonPatch ([{'op' : 'test' , 'path' : '/test1' }])
383400 self .assertNotEqual (patch1 , patch2 )
384401
402+ def test_patch_unequal_literal_and_number (self ):
403+ # the patches behave differently, #216
404+ patch1 = jsonpatch .JsonPatch ([{'op' : 'test' , 'path' : '/a' , 'value' : 1 }])
405+ patch2 = jsonpatch .JsonPatch ([{'op' : 'test' , 'path' : '/a' , 'value' : True }])
406+ self .assertNotEqual (patch1 , patch2 )
407+
408+ def test_patch_equal_numbers_by_value (self ):
409+ patch1 = jsonpatch .JsonPatch ([{'op' : 'test' , 'path' : '/a' , 'value' : [1 ]}])
410+ patch2 = jsonpatch .JsonPatch ([{'op' : 'test' , 'path' : '/a' , 'value' : [1.0 ]}])
411+ self .assertEqual (patch1 , patch2 )
412+
385413 def test_patch_hash_equality (self ):
386414 patch1 = jsonpatch .JsonPatch ([{ "op" : "add" , "path" : "/a/b/c" , "value" : "foo" }])
387415 patch2 = jsonpatch .JsonPatch ([{ "path" : "/a/b/c" , "op" : "add" , "value" : "foo" }])
0 commit comments