@@ -1705,6 +1705,34 @@ def test_set_from_key(self):
17051705 self .assertEqual (operation , {'op' : 'move' , 'from' : '/c~1d/0' , 'path' : '/b' })
17061706 self .assertEqual (op .apply ({'c/d' : ['x' ]}), {'c/d' : [], 'b' : 'x' })
17071707
1708+ def test_from_path_with_pointer_object (self ):
1709+ for pointer_cls in (jsonpointer .JsonPointer , CustomJsonPointer ):
1710+ with self .subTest (pointer_cls = pointer_cls ):
1711+ op = jsonpatch .MoveOperation (
1712+ {'op' : 'move' , 'from' : pointer_cls ('/a/1/b' ), 'path' : '/c' },
1713+ pointer_cls = pointer_cls )
1714+ self .assertEqual (op .from_path , 'a/1' )
1715+
1716+ def test_from_parts_with_pointer_object (self ):
1717+ for pointer_cls in (jsonpointer .JsonPointer , CustomJsonPointer ):
1718+ with self .subTest (pointer_cls = pointer_cls ):
1719+ op = jsonpatch .MoveOperation (
1720+ {'op' : 'move' , 'from' : pointer_cls ('/a/1/b' ), 'path' : '/c' },
1721+ pointer_cls = pointer_cls )
1722+ self .assertEqual (op .from_key , 'b' )
1723+ self .assertEqual (op .get_from_part (1 ), 1 )
1724+
1725+ def test_set_from_key_with_pointer_object (self ):
1726+ for pointer_cls in (jsonpointer .JsonPointer , CustomJsonPointer ):
1727+ with self .subTest (pointer_cls = pointer_cls ):
1728+ operation = {'op' : 'move' , 'from' : pointer_cls ('/a/1' ),
1729+ 'path' : '/b' }
1730+ op = jsonpatch .MoveOperation (operation , pointer_cls = pointer_cls )
1731+ op .from_key = 0
1732+ self .assertEqual (operation ['from' ], '/a/0' )
1733+ self .assertEqual (op .apply ({'a' : ['x' , 'y' ]}),
1734+ {'a' : ['y' ], 'b' : 'x' })
1735+
17081736
17091737class CustomJsonPointer (jsonpointer .JsonPointer ):
17101738 pass
0 commit comments