moxml 0.6.3 → 0.6.5

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.
@@ -0,0 +1,171 @@
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 address-native lane rides the binding's shadow faces
11
+ # (children_addrs / walk_addresses, leptris-ruby#587/#589/#591);
12
+ # older bindings keep the columnar per-subtree crossing, so the
13
+ # routing cannot be pinned there.
14
+ return unless defined?(Leptris::XML::Native) &&
15
+ Leptris::XML::Native.respond_to?(:children_addrs)
16
+
17
+ require "moxml/adapter/leptris"
18
+
19
+ RSpec.describe "Moxml::Adapter::Leptris address-native children (shadow lane)" do
20
+ around do |example|
21
+ Moxml.with_config(:leptris, true, "UTF-8") do
22
+ example.run
23
+ end
24
+ end
25
+
26
+ let(:xml) do
27
+ <<~XML
28
+ <?xml version="1.0"?><r><a x="1">t</a><b/><c><d/></c><tail>z</tail></r>
29
+ XML
30
+ end
31
+
32
+ let(:doc) { Moxml.parse(xml) }
33
+ let(:root) { doc.root }
34
+ let(:root_native) { root.native }
35
+
36
+ # Counts real Native.children_addrs C crossings inside the block —
37
+ # no stubs, the actual boundary traffic the address lane pays.
38
+ def with_crossing_count(method_id = :children_addrs)
39
+ calls = 0
40
+ tp = TracePoint.new(:c_call) do |t|
41
+ calls += 1 if t.method_id == method_id
42
+ end
43
+ result = nil
44
+ tp.enable { result = yield }
45
+ [calls, result]
46
+ end
47
+
48
+ describe "the address gate" do
49
+ it "face-probes the shadow faces on the binding" do
50
+ expect(Moxml::Adapter::Leptris::ADDRESS_NATIVE).to be(true)
51
+ expect(Leptris::XML::Native.respond_to?(:children_addrs)).to be(true)
52
+ end
53
+ end
54
+
55
+ describe "plain children reads" do
56
+ it "answer address tokens matching the native children face" do
57
+ got = Moxml::Adapter::Leptris.children(root_native)
58
+ expected = Leptris::XML::NativeNode
59
+ .instance_method(:children).bind_call(root_native).to_a
60
+ expect(got).to all(be_a(Moxml::Adapter::Leptris::AddressNode))
61
+ expect(got.size).to eq(expected.size)
62
+ expect(got.map { |n| Moxml::Adapter::Leptris.node_name(n) })
63
+ .to eq(expected.map(&:name))
64
+ got.each_with_index do |token, i|
65
+ # Address equality: the token stands for the same C node.
66
+ expect(token.address).to eq(expected[i].address)
67
+ expect(Moxml::Adapter::Leptris.node_type(token))
68
+ .to eq(Moxml::Adapter::Leptris.node_type(expected[i]))
69
+ end
70
+ end
71
+
72
+ it "hand back the SAME token per address across traversals" do
73
+ first = Moxml::Adapter::Leptris.children(root_native)
74
+ second = Moxml::Adapter::Leptris.children(root_native)
75
+ expect(second).to eq(first)
76
+ expect(second.first).to equal(first.first)
77
+ end
78
+
79
+ # Parsed-document wrappers mint with Identity::ChildReads above
80
+ # Moxml::Node, so consumer iteration on those wrappers dispatches
81
+ # to the binding's C read layer. The address face pays one
82
+ # children_addrs crossing per element receiver — the token mint
83
+ # replaces the TypedData wrap + identity-cache write the columnar
84
+ # lane pays per node in C.
85
+ it "pay one crossing per element receiver, none on repeat reads" do
86
+ calls, = with_crossing_count do
87
+ walk_face = lambda do |token|
88
+ Moxml::Adapter::Leptris.children(token).each do |child|
89
+ walk_face.call(child)
90
+ end
91
+ end
92
+ walk_face.call(root_native)
93
+ end
94
+ # The subtree has 6 elements (r, a, b, c, d, tail): one crossing
95
+ # each, no walk_columnar at all.
96
+ expect(calls).to eq(6)
97
+ calls2, = with_crossing_count do
98
+ Moxml::Adapter::Leptris.children(root_native)
99
+ end
100
+ expect(calls2).to eq(1)
101
+ end
102
+
103
+ it "serve element reads through the address-keyed faces" do
104
+ target = Moxml::Adapter::Leptris.children(root_native)
105
+ .find { |t| Moxml::Adapter::Leptris.node_name(t) == "a" }
106
+ expect(Moxml::Adapter::Leptris.bare_attr_value(target, "x")).to eq("1")
107
+ expect(Moxml::Adapter::Leptris.text_content(target)).to eq("t")
108
+ expect(Moxml::Adapter::Leptris.attributes(target).map(&:value))
109
+ .to eq(["1"])
110
+ end
111
+
112
+ it "keep the document assembly path on document receivers" do
113
+ calls, doc_children = with_crossing_count do
114
+ Moxml::Adapter::Leptris.children(doc.native)
115
+ end
116
+ # No token crossings: the document's child list rides the
117
+ # assembly path (declaration/doctype kinds are outside the
118
+ # address lane's WS enum).
119
+ expect(calls).to eq(0)
120
+ expect(doc_children.map do |n|
121
+ Moxml::Adapter::Leptris.node_name(n)
122
+ end).to include("r")
123
+ end
124
+ end
125
+
126
+ describe "mutation invalidation" do
127
+ # Read back through the adapter face: the token map must never
128
+ # serve a list a mutation has invalidated.
129
+ def face_children_names
130
+ Moxml::Adapter::Leptris.children(root_native)
131
+ .map { |n| Moxml::Adapter::Leptris.node_name(n) }
132
+ end
133
+
134
+ it "sees children added after the map was primed" do
135
+ face_children_names # prime the map
136
+ root.add_child(doc.create_element("late"))
137
+ expect(face_children_names).to include("late")
138
+ end
139
+
140
+ it "sees children removed after the map was primed" do
141
+ face_children_names # prime the map
142
+ root.children.to_a.first.remove
143
+ expect(face_children_names).not_to include("a")
144
+ end
145
+
146
+ it "sees sibling insertions after the map was primed" do
147
+ face_children_names # prime the map
148
+ anchor = root.children.to_a.first
149
+ anchor.add_previous_sibling(doc.create_element("before2"))
150
+ expect(face_children_names).to include("before2")
151
+ end
152
+
153
+ it "sees replace after the map was primed" do
154
+ face_children_names # prime the map
155
+ victim = root.children.to_a.find { |n| n.name == "b" }
156
+ victim.replace(doc.create_element("swapped"))
157
+ expect(face_children_names).to include("swapped")
158
+ expect(face_children_names).not_to include("b")
159
+ end
160
+
161
+ it "sees content rewrites after the map was primed" do
162
+ face_children_names # prime the map
163
+ target = root.children.to_a.find { |n| n.name == "a" }
164
+ target.content = "rewritten"
165
+ names = face_children_names
166
+ expect(names).to include("a")
167
+ expect(root.children.to_a.find { |n| n.name == "a" }.text)
168
+ .to eq("rewritten")
169
+ end
170
+ end
171
+ end
@@ -53,10 +53,6 @@ RSpec.describe Moxml::Adapter::Leptris do
53
53
  end
54
54
 
55
55
  it "evaluates attribute-node queries with proper wrappers" do
56
- # Native since 1.9.105 (leptris-ruby#153: ResultAttr with
57
- # name/value); earlier bindings returned generic nodes whose
58
- # #name raised, so the Ruby engine owned them.
59
- skip "requires native attr results (leptris 1.9.105+)" unless described_class::ATTR_RESULT_NATIVE
60
56
  attrs = doc.xpath("//item/@id")
61
57
  expect(attrs.map(&:name)).to eq(%w[id id])
62
58
  expect(attrs.map(&:value)).to eq(%w[1 2])
@@ -759,8 +755,6 @@ RSpec.describe Moxml::Adapter::Leptris do
759
755
  let(:ctx) { Moxml.new(:leptris) }
760
756
 
761
757
  it "answers engine source positions for parsed nodes" do
762
- skip "requires leptris 1.9.181" unless described_class::NATIVE_SOURCE_POSITION
763
-
764
758
  doc = ctx.parse("<root>\n <child>text</child>\n</root>")
765
759
  expect(doc.root.source_position).to include(line: 1)
766
760
  expect(doc.root.source_position).to be_a(Hash)
@@ -46,18 +46,27 @@ RSpec.describe Moxml::Adapter do
46
46
  end
47
47
 
48
48
  it "prefers leptris only when the installed binding meets the floor" do
49
+ # Resolve under cold selection: the degradation specs may have
50
+ # left nokogiri pinned while the probe memo is warm-true (the
51
+ # #523 ordering contract) — the invariant tests the RESOLVED
52
+ # answer, not whichever ambient half-state a random order
53
+ # happens to leave.
54
+ ambient = Moxml::Config.default_adapter
55
+ Moxml::Config.reset_adapter_selection!
49
56
  if Moxml::Config.leptris_preferred_available?
50
57
  expect(Moxml::Config.runtime_default_adapter).to eq(:leptris)
51
58
  else
52
59
  expect(Moxml::Config.runtime_default_adapter).not_to eq(:leptris)
53
60
  end
61
+ ensure
62
+ Moxml::Config.default_adapter = ambient
54
63
  end
55
64
 
56
- it "pins the leptris binding floor at 1.9.386.0 (raised 2026-09-20, raised again 2026-10-30; enforced at load)" do
65
+ it "pins the leptris binding floor at 1.9.410.0 (raised 2026-09-20, 2026-10-30, and 2026-11-10; enforced at load)" do
57
66
  skip "leptris not installed" unless described_class.available?(:leptris)
58
67
 
59
68
  adapter = described_class.load(:leptris)
60
- expect(adapter::MINIMUM_BINDING_VERSION).to eq("1.9.386.0")
69
+ expect(adapter::MINIMUM_BINDING_VERSION).to eq("1.9.410.0")
61
70
  expect(Gem::Version.new(Leptris::VERSION))
62
71
  .to be >= Gem::Version.new(adapter::MINIMUM_BINDING_VERSION)
63
72
  end
@@ -71,7 +71,15 @@ RSpec.describe Moxml::Context do
71
71
 
72
72
  refreshed = doc.root
73
73
  expect(refreshed.name).to eq("x")
74
- expect(context.wrapper_for(refreshed.native)).to equal(refreshed)
74
+
75
+ # Exercise the swap explicitly: the map must answer the wrapper
76
+ # under its CURRENT native after refresh_native!. (Probing the
77
+ # pre-swap mint instead raced the wrap path — identity mints
78
+ # register the map only when the canonical fast path was not
79
+ # taken, which made the assertion order-sensitive.)
80
+ replacement = doc.create_element("y")
81
+ refreshed.refresh_native!(replacement.native)
82
+ expect(context.wrapper_for(replacement.native)).to equal(refreshed)
75
83
  end
76
84
  end
77
85
  end
@@ -0,0 +1,183 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+ require "fileutils"
5
+ require "tmpdir"
6
+
7
+ # moxml#522: composed-schema strict admission. The facade owns the
8
+ # composition — it resolves the instance's xsi:schemaLocation hints
9
+ # against the schema's own path, walks the schema graph
10
+ # (include/import/redefine) for the unit closure, and dismisses
11
+ # engine "not declared (strict)" rows the composed declaration index
12
+ # refutes — global declarations AND attributeGroup members. The
13
+ # engine admission gap itself is RESOLVED in leptris 1.9.409
14
+ # (leptris#1964 — register entry D-23). The 1.9.409 namespace-aware
15
+ # particle wave carries an upstream schG2 lexical regression
16
+ # (leptris#1979 — register entry D-24, RESOLVED: the engine fix landed in 1.9.410
17
+ # and the vendored corpus was missing the schG1_c.xsd C unit); 16/16 verified.
18
+ RSpec.describe "Moxml::XSD::Schema composed-schema validation (#522)" do
19
+ let(:ctx) { Moxml.new(:leptris) }
20
+ let(:main_xsd) do
21
+ <<~XSD
22
+ <?xml version="1.0"?>
23
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
24
+ <xsd:attribute name="att1" type="xsd:string"/>
25
+ <xsd:element name="doc">
26
+ <xsd:complexType>
27
+ <xsd:attributeGroup ref="main"/>
28
+ </xsd:complexType>
29
+ </xsd:element>
30
+ <xsd:attributeGroup name="main">
31
+ <xsd:attribute ref="att1"/>
32
+ <xsd:anyAttribute namespace="##any"/>
33
+ </xsd:attributeGroup>
34
+ </xsd:schema>
35
+ XSD
36
+ end
37
+ # The auxiliary unit: a global declaration the head unit never saw.
38
+ let(:aux_xsd) do
39
+ <<~XSD
40
+ <?xml version="1.0"?>
41
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
42
+ targetNamespace="http://aux">
43
+ <xsd:attribute name="ext" type="xsd:string"/>
44
+ </xsd:schema>
45
+ XSD
46
+ end
47
+
48
+ # Per-example fixture tempdir: created by the let, removed in the
49
+ # after hook. Plain lets + methods keep the suite ivar-free
50
+ # (house law).
51
+ let(:dir) { Dir.mktmpdir("moxml522") }
52
+
53
+ after { FileUtils.remove_entry(dir) }
54
+
55
+ def unit(name)
56
+ File.join(dir, name)
57
+ end
58
+
59
+ before do
60
+ File.write(unit("main.xsd"), main_xsd)
61
+ File.write(unit("aux.xsd"), aux_xsd)
62
+ end
63
+
64
+ it "unions the instance's hint documents into the validation" do
65
+ schema = ctx.xsd_file(unit("main.xsd"))
66
+ doc = ctx.parse(
67
+ '<doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' \
68
+ 'xmlns:e="http://aux" xsi:noNamespaceSchemaLocation="main.xsd" ' \
69
+ 'xsi:schemaLocation="http://aux aux.xsd" att1="x" e:ext="y"/>',
70
+ )
71
+ expect(schema.validate(doc)).to be_empty
72
+ end
73
+
74
+ it "dismisses the engine's not-declared rows the union refutes" do
75
+ # Without the union the engine reports the aux attribute as
76
+ # undeclared; with it, the composed declaration index refutes
77
+ # the row. The engine may carry either the attribute-level row
78
+ # or the element-level root row (mixed-tns mis-admission) —
79
+ # both are refutable.
80
+ schema = ctx.xsd_file(unit("main.xsd"))
81
+ doc = ctx.parse(
82
+ '<doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' \
83
+ 'xmlns:e="http://aux" xsi:noNamespaceSchemaLocation="main.xsd" ' \
84
+ 'xsi:schemaLocation="http://aux aux.xsd" att1="x" e:ext="y">text</doc>',
85
+ )
86
+ errors = schema.validate(doc)
87
+ expect(errors.map(&:message)).not_to include(
88
+ /not declared \(strict\)/,
89
+ )
90
+ end
91
+
92
+ it "keeps genuinely undeclared attribute rows" do
93
+ schema = ctx.xsd_file(unit("main.xsd"))
94
+ doc = ctx.parse(
95
+ '<doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' \
96
+ 'xsi:noNamespaceSchemaLocation="main.xsd" att1="x" ghost="z"/>',
97
+ )
98
+ # `ghost` is declared nowhere: the strict row (when the engine
99
+ # emits one) must survive the dismissal.
100
+ errors = schema.validate(doc).map(&:message)
101
+ expect(errors.grep_v(/ghost.*not declared/)).to be_empty
102
+ end
103
+
104
+ it "does not build a union for string-compiled schemas" do
105
+ schema = ctx.xsd(main_xsd)
106
+ doc = ctx.parse("<doc att1=\"x\"/>")
107
+ expect(schema.validate(doc)).to be_empty
108
+ end
109
+
110
+ # The attgC class (moxml#522): the attribute is a member of an
111
+ # attributeGroup reached through xs:redefine (the body hooks the
112
+ # original with a self-ref — 4.2.2) and an import. The instance
113
+ # carries no xsi hints; the composed unit closure must see the
114
+ # redefined/imported documents through the schema graph alone.
115
+ describe "group-member admission through the schema graph" do
116
+ let(:group_xsd) do
117
+ <<~XSD
118
+ <?xml version="1.0"?>
119
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
120
+ xmlns:imp="http://imported">
121
+ <xsd:import namespace="http://imported" schemaLocation="group.imp"/>
122
+ <xsd:redefine schemaLocation="group.red">
123
+ <xsd:attributeGroup name="car">
124
+ <xsd:attributeGroup ref="car"/>
125
+ <xsd:attributeGroup ref="imp:bar"/>
126
+ </xsd:attributeGroup>
127
+ </xsd:redefine>
128
+ <xsd:element name="doc" type="test"/>
129
+ <xsd:complexType name="test">
130
+ <xsd:attributeGroup ref="car"/>
131
+ </xsd:complexType>
132
+ </xsd:schema>
133
+ XSD
134
+ end
135
+ let(:group_red_xsd) do
136
+ <<~XSD
137
+ <?xml version="1.0"?>
138
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
139
+ <xsd:attributeGroup name="car">
140
+ <xsd:attribute name="att1" type="xsd:int"/>
141
+ </xsd:attributeGroup>
142
+ </xsd:schema>
143
+ XSD
144
+ end
145
+ let(:group_imp_xsd) do
146
+ <<~XSD
147
+ <?xml version="1.0"?>
148
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
149
+ targetNamespace="http://imported">
150
+ <xsd:attributeGroup name="bar">
151
+ <xsd:attribute name="att4" type="xsd:int"/>
152
+ </xsd:attributeGroup>
153
+ </xsd:schema>
154
+ XSD
155
+ end
156
+
157
+ before do
158
+ File.write(unit("group.xsd"), group_xsd)
159
+ File.write(unit("group.red"), group_red_xsd)
160
+ File.write(unit("group.imp"), group_imp_xsd)
161
+ end
162
+
163
+ it "admits redefined and imported group members on the element" do
164
+ schema = ctx.xsd_file(unit("group.xsd"))
165
+ doc = ctx.parse(
166
+ '<doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' \
167
+ 'xmlns:imp="http://imported" ' \
168
+ 'xsi:noNamespaceSchemaLocation="group.xsd" att1="1" imp:att4="2"/>',
169
+ )
170
+ expect(schema.validate(doc)).to be_empty
171
+ end
172
+
173
+ it "keeps rows for attributes no unit of the composition declares" do
174
+ schema = ctx.xsd_file(unit("group.xsd"))
175
+ doc = ctx.parse(
176
+ '<doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' \
177
+ 'xsi:noNamespaceSchemaLocation="group.xsd" att1="1" ghost="z"/>',
178
+ )
179
+ errors = schema.validate(doc).map(&:message)
180
+ expect(errors.grep_v(/ghost.*not declared/)).to be_empty
181
+ end
182
+ end
183
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moxml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-11-05 00:00:00.000000000 Z
11
+ date: 2026-11-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Moxml is a unified XML manipulation library that provides a common API
@@ -79,6 +79,7 @@ files:
79
79
  - docs/_pages/best-practices.adoc
80
80
  - docs/_pages/compatibility.adoc
81
81
  - docs/_pages/configuration.adoc
82
+ - docs/_pages/conformance.adoc
82
83
  - docs/_pages/conversion-apis.adoc
83
84
  - docs/_pages/divergences.adoc
84
85
  - docs/_pages/ecosystem.adoc
@@ -202,6 +203,7 @@ files:
202
203
  - lib/moxml/c14n/processor.rb
203
204
  - lib/moxml/c14n/writer.rb
204
205
  - lib/moxml/c14n/xml_base_handler.rb
206
+ - lib/moxml/c14n_cases.rb
205
207
  - lib/moxml/cdata.rb
206
208
  - lib/moxml/comment.rb
207
209
  - lib/moxml/config.rb
@@ -239,6 +241,7 @@ files:
239
241
  - lib/moxml/sax/element_handler.rb
240
242
  - lib/moxml/sax/handler.rb
241
243
  - lib/moxml/sax/namespace_splitter.rb
244
+ - lib/moxml/serialization_cases.rb
242
245
  - lib/moxml/signature.rb
243
246
  - lib/moxml/signature/algorithms.rb
244
247
  - lib/moxml/signature/algorithms/base64_transform.rb
@@ -311,6 +314,7 @@ files:
311
314
  - lib/moxml/xsd.rb
312
315
  - lib/moxml/xsd/builtin_lexical.rb
313
316
  - lib/moxml/xsd/schema_rules.rb
317
+ - lib/moxml/xsd_structural_cases.rb
314
318
  - lib/moxml/xslt.rb
315
319
  - lib/moxml/xslt/stylesheet.rb
316
320
  - moxml.gemspec
@@ -323,6 +327,7 @@ files:
323
327
  - spec/consistency/README.md
324
328
  - spec/consistency/adapter_parity_spec.rb
325
329
  - spec/consistency/citation_hygiene_spec.rb
330
+ - spec/consistency/conformance_families_spec.rb
326
331
  - spec/consistency/differential_taxonomy_spec.rb
327
332
  - spec/consistency/divergence_register_spec.rb
328
333
  - spec/consistency/document_text_spec.rb
@@ -335,6 +340,7 @@ files:
335
340
  - spec/consistency/published_docs_spec.rb
336
341
  - spec/consistency/reference_differential_spec.rb
337
342
  - spec/consistency/round_trip_spec.rb
343
+ - spec/consistency/serialization_family_spec.rb
338
344
  - spec/consistency/spec_constant_uniqueness_spec.rb
339
345
  - spec/consistency/xpath_idioms_spec.rb
340
346
  - spec/consistency/xslt_spec.rb
@@ -478,7 +484,7 @@ files:
478
484
  - spec/moxml/adapter/leptris_attribute_packet_spec.rb
479
485
  - spec/moxml/adapter/leptris_attribute_snapshot_spec.rb
480
486
  - spec/moxml/adapter/leptris_binding_cap_spec.rb
481
- - spec/moxml/adapter/leptris_children_columnar_spec.rb
487
+ - spec/moxml/adapter/leptris_children_address_spec.rb
482
488
  - spec/moxml/adapter/leptris_composed_schema_spec.rb
483
489
  - spec/moxml/adapter/leptris_contract_reads_spec.rb
484
490
  - spec/moxml/adapter/leptris_crossdoc_replace_spec.rb
@@ -626,6 +632,7 @@ files:
626
632
  - spec/moxml/xpath_capabilities_spec.rb
627
633
  - spec/moxml/xpath_spec.rb
628
634
  - spec/moxml/xsd_builtin_lexical_spec.rb
635
+ - spec/moxml/xsd_composed_spec.rb
629
636
  - spec/moxml/xsd_conformance_cases_spec.rb
630
637
  - spec/moxml/xsd_engine_meta_spec.rb
631
638
  - spec/moxml/xsd_error_contract_spec.rb
@@ -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