Skip to content

Commit ef7a41c

Browse files
committed
add tests for JsonPointer.to_last()
1 parent 03abbd7 commit ef7a41c

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

tests.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,29 @@ def test_oob(self):
9292
self.assertRaises(JsonPointerException, resolve_pointer, doc, '/10')
9393

9494

95+
class ToLastTests(unittest.TestCase):
96+
97+
def test_empty_path(self):
98+
doc = {'a': [1, 2, 3]}
99+
ptr = JsonPointer('')
100+
last, nxt = ptr.to_last(doc)
101+
self.assertEqual(doc, last)
102+
self.assertTrue(nxt is None)
103+
104+
105+
def test_path(self):
106+
doc = {'a': [{'b': 1, 'c': 2}, 5]}
107+
ptr = JsonPointer('/a/0/b')
108+
last, nxt = ptr.to_last(doc)
109+
self.assertEqual(last, {'b': 1, 'c': 2})
110+
self.assertEqual(nxt, 'b')
111+
112+
95113
suite = unittest.TestSuite()
96114
suite.addTest(unittest.makeSuite(SpecificationTests))
97115
suite.addTest(unittest.makeSuite(ComparisonTests))
98116
suite.addTest(unittest.makeSuite(WrongInputTests))
117+
suite.addTest(unittest.makeSuite(ToLastTests))
99118

100119
modules = ['jsonpointer']
101120

0 commit comments

Comments
 (0)