1111from dottxt .streaming import PatchEvent , PatchStreamError , apply_add , stream
1212
1313
14- def test_patch_event_is_leaf_for_top_level_leaf () -> None :
15- """A non-empty add at a non-root path is a leaf."""
16- event = PatchEvent (
17- op = {"op" : "add" , "path" : "/intent" , "value" : "billing" },
18- snapshot = {"intent" : "billing" },
19- )
20- assert event .is_leaf is True
21- assert event .field == "intent"
22- assert event .value == "billing"
23-
24-
25- def test_patch_event_is_leaf_false_for_root_seed () -> None :
26- """The root seed op is structural, not a leaf."""
27- event = PatchEvent (op = {"op" : "add" , "path" : "" , "value" : {}}, snapshot = {})
28- assert event .is_leaf is False
29- assert event .field == ""
30-
31-
32- def test_patch_event_is_leaf_false_for_empty_container () -> None :
33- """Empty-object and empty-array seed ops are structural."""
34- obj_seed = PatchEvent (
35- op = {"op" : "add" , "path" : "/address" , "value" : {}}, snapshot = {"address" : {}}
36- )
37- arr_seed = PatchEvent (
38- op = {"op" : "add" , "path" : "/steps" , "value" : []}, snapshot = {"steps" : []}
39- )
40- assert obj_seed .is_leaf is False
41- assert arr_seed .is_leaf is False
42-
43-
4414def test_patch_event_field_for_array_index_and_nested_path () -> None :
4515 """Array indices and nested object paths keep their joined segments."""
4616 arr = PatchEvent (
@@ -55,15 +25,6 @@ def test_patch_event_field_for_array_index_and_nested_path() -> None:
5525 assert nested .field == "address/city"
5626
5727
58- def test_patch_event_is_leaf_handles_falsy_primitives () -> None :
59- """Falsy primitives (0, "", False) are still leaves, only {} / [] are structural."""
60- for value in (0 , "" , False , None ):
61- event = PatchEvent (
62- op = {"op" : "add" , "path" : "/x" , "value" : value }, snapshot = {"x" : value }
63- )
64- assert event .is_leaf is True , value
65-
66-
6728def test_apply_add_replaces_root_for_empty_path () -> None :
6829 """An op with ``path == ""`` replaces the document root."""
6930 assert apply_add (None , "" , {}) == {}
0 commit comments