Add Dumas JSON object iterator node

This commit is contained in:
2026-07-21 10:52:48 +00:00
parent 6994cb64c5
commit 5446a5c068
3 changed files with 75 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ from dumas_json_nodes import (
DumasJSONGetValueNode,
DumasJSONKeysNode,
DumasJSONMergeObjectsNode,
DumasJSONObjectIteratorNode,
DumasJSONObjectToStringNode,
DumasJSONStringToObjectNode,
DumasJSONSetValueNode,
@@ -109,6 +110,41 @@ class DumasJSONNodeTests(unittest.TestCase):
self.assertEqual(result, (None, -1, 0))
def test_object_iterator_fixed_mode_uses_given_index(self):
node = DumasJSONObjectIteratorNode()
result = node.iterate({"first": "a", "second": "b", "third": "c"}, 1, "fixed")
self.assertEqual(result, ("second", "b", 1, 3))
def test_object_iterator_incr_mode_advances_index(self):
node = DumasJSONObjectIteratorNode()
result = node.iterate({"first": "a", "second": "b", "third": "c"}, 1, "incr")
self.assertEqual(result, ("third", "c", 2, 3))
def test_object_iterator_decr_mode_decrements_index(self):
node = DumasJSONObjectIteratorNode()
result = node.iterate({"first": "a", "second": "b", "third": "c"}, 1, "decr")
self.assertEqual(result, ("first", "a", 0, 3))
def test_object_iterator_clamps_out_of_range_index(self):
node = DumasJSONObjectIteratorNode()
result = node.iterate({"first": "a", "second": "b", "third": "c"}, 99, "fixed")
self.assertEqual(result, ("third", "c", 2, 3))
def test_object_iterator_handles_empty_objects(self):
node = DumasJSONObjectIteratorNode()
result = node.iterate({}, 0, "fixed")
self.assertEqual(result, (None, None, -1, 0))
if __name__ == "__main__":
unittest.main()