@@ -1676,6 +1676,34 @@ def test_set_from_key(self):
16761676 self .assertEqual (operation , {'op' : 'move' , 'from' : '/c~1d/0' , 'path' : '/b' })
16771677 self .assertEqual (op .apply ({'c/d' : ['x' ]}), {'c/d' : [], 'b' : 'x' })
16781678
1679+ def test_from_path_with_pointer_object (self ):
1680+ for pointer_cls in (jsonpointer .JsonPointer , CustomJsonPointer ):
1681+ with self .subTest (pointer_cls = pointer_cls ):
1682+ op = jsonpatch .MoveOperation (
1683+ {'op' : 'move' , 'from' : pointer_cls ('/a/1/b' ), 'path' : '/c' },
1684+ pointer_cls = pointer_cls )
1685+ self .assertEqual (op .from_path , 'a/1' )
1686+
1687+ def test_from_parts_with_pointer_object (self ):
1688+ for pointer_cls in (jsonpointer .JsonPointer , CustomJsonPointer ):
1689+ with self .subTest (pointer_cls = pointer_cls ):
1690+ op = jsonpatch .MoveOperation (
1691+ {'op' : 'move' , 'from' : pointer_cls ('/a/1/b' ), 'path' : '/c' },
1692+ pointer_cls = pointer_cls )
1693+ self .assertEqual (op .from_key , 'b' )
1694+ self .assertEqual (op .get_from_part (1 ), 1 )
1695+
1696+ def test_set_from_key_with_pointer_object (self ):
1697+ for pointer_cls in (jsonpointer .JsonPointer , CustomJsonPointer ):
1698+ with self .subTest (pointer_cls = pointer_cls ):
1699+ operation = {'op' : 'move' , 'from' : pointer_cls ('/a/1' ),
1700+ 'path' : '/b' }
1701+ op = jsonpatch .MoveOperation (operation , pointer_cls = pointer_cls )
1702+ op .from_key = 0
1703+ self .assertEqual (operation ['from' ], '/a/0' )
1704+ self .assertEqual (op .apply ({'a' : ['x' , 'y' ]}),
1705+ {'a' : ['y' ], 'b' : 'x' })
1706+
16791707
16801708class CustomJsonPointer (jsonpointer .JsonPointer ):
16811709 pass
0 commit comments