moxml 0.6.2 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,146 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- begin
4
- require "leptris"
5
- rescue LoadError
6
- # Leptris gem not available - skip all specs in this file
7
- return
8
- end
9
- return unless Leptris::XML::Document.respond_to?(:create)
10
- # The columnar children lane rides the binding's walk_columnar face
11
- # (leptris-ruby#527/#532); older bindings keep the per-node children
12
- # crossing, so the routing cannot be pinned there.
13
- return unless defined?(Leptris::XML::Native) &&
14
- Leptris::XML::Native.respond_to?(:walk_columnar)
15
-
16
- require "moxml/adapter/leptris"
17
-
18
- RSpec.describe "Moxml::Adapter::Leptris columnar children (SOTA B2 walk row)" do
19
- around do |example|
20
- Moxml.with_config(:leptris, true, "UTF-8") do
21
- example.run
22
- end
23
- end
24
-
25
- let(:xml) do
26
- <<~XML
27
- <?xml version="1.0"?><r><a x="1">t</a><b/><c><d/></c><tail>z</tail></r>
28
- XML
29
- end
30
-
31
- let(:doc) { Moxml.parse(xml) }
32
- let(:root) { doc.root }
33
- let(:root_native) { root.native }
34
-
35
- # Counts real Native.walk_columnar C crossings inside the block —
36
- # no stubs, the actual boundary traffic the walk row pays.
37
- def with_crossing_count
38
- calls = 0
39
- tp = TracePoint.new(:c_call) do |t|
40
- calls += 1 if t.method_id == :walk_columnar
41
- end
42
- result = nil
43
- tp.enable { result = yield }
44
- [calls, result]
45
- end
46
-
47
- describe "the columnar gate" do
48
- it "face-probes walk_columnar on the binding" do
49
- expect(Moxml::Adapter::Leptris::COLUMNAR_WALK).to be(true)
50
- expect(Leptris::XML::Native.respond_to?(:walk_columnar)).to be(true)
51
- end
52
- end
53
-
54
- describe "plain children reads" do
55
- it "answer natives identical to the native children face" do
56
- got = Moxml::Adapter::Leptris.children(root_native)
57
- expected = Leptris::XML::NativeNode
58
- .instance_method(:children).bind_call(root_native).to_a
59
- expect(got.size).to eq(expected.size)
60
- expect(got.map { |n| Moxml::Adapter::Leptris.node_name(n) })
61
- .to eq(expected.map(&:name))
62
- got.each_with_index do |native, i|
63
- # native-cache identity: cached handles ARE the children_read
64
- # wrappers, so the NodeSet contract holds.
65
- expect(native).to equal(expected[i])
66
- end
67
- end
68
-
69
- # Parsed-document wrappers mint with Identity::ChildReads above
70
- # Moxml::Node, so consumer iteration on those wrappers dispatches
71
- # to the binding's C read layer. The children FACE is pinned by
72
- # driving it for every node of the cold subtree: one walk_columnar
73
- # crossing primes the whole map, every deeper face read hits it.
74
- it "pay ONE columnar crossing for a whole cold subtree" do
75
- calls, = with_crossing_count do
76
- walk_face = lambda do |native|
77
- Moxml::Adapter::Leptris.children(native).each do |child|
78
- walk_face.call(child)
79
- end
80
- end
81
- walk_face.call(root_native)
82
- end
83
- expect(calls).to eq(1)
84
- end
85
-
86
- it "serve repeat face reads from the primed map without a crossing" do
87
- calls, first = with_crossing_count do
88
- Moxml::Adapter::Leptris.children(root_native)
89
- end
90
- expect(calls).to eq(1)
91
- first_names = first.map { |n| Moxml::Adapter::Leptris.node_name(n) }
92
- calls2, second = with_crossing_count do
93
- Moxml::Adapter::Leptris.children(root_native)
94
- end
95
- expect(calls2).to eq(0)
96
- expect(second.map { |n| Moxml::Adapter::Leptris.node_name(n) })
97
- .to eq(first_names)
98
- end
99
- end
100
-
101
- describe "mutation invalidation" do
102
- # Read back through the adapter face: the map must never serve a
103
- # list a mutation has invalidated.
104
- def face_children_names
105
- Moxml::Adapter::Leptris.children(root_native)
106
- .map { |n| Moxml::Adapter::Leptris.node_name(n) }
107
- end
108
-
109
- it "sees children added after the map was primed" do
110
- face_children_names # prime the map
111
- root.add_child(doc.create_element("late"))
112
- expect(face_children_names).to include("late")
113
- end
114
-
115
- it "sees children removed after the map was primed" do
116
- face_children_names # prime the map
117
- root.children.to_a.first.remove
118
- expect(face_children_names).not_to include("a")
119
- end
120
-
121
- it "sees sibling insertions after the map was primed" do
122
- face_children_names # prime the map
123
- anchor = root.children.to_a.first
124
- anchor.add_previous_sibling(doc.create_element("before2"))
125
- expect(face_children_names).to include("before2")
126
- end
127
-
128
- it "sees replace after the map was primed" do
129
- face_children_names # prime the map
130
- victim = root.children.to_a.find { |n| n.name == "b" }
131
- victim.replace(doc.create_element("swapped"))
132
- expect(face_children_names).to include("swapped")
133
- expect(face_children_names).not_to include("b")
134
- end
135
-
136
- it "sees content rewrites after the map was primed" do
137
- face_children_names # prime the map
138
- target = root.children.to_a.find { |n| n.name == "a" }
139
- target.content = "rewritten"
140
- names = face_children_names
141
- expect(names).to include("a")
142
- expect(root.children.to_a.find { |n| n.name == "a" }.text)
143
- .to eq("rewritten")
144
- end
145
- end
146
- end