moxml 0.5.147 → 0.5.149

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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/nightly-fuzz.yml +80 -0
  3. data/docs/_pages/divergences.adoc +58 -0
  4. data/docs/_references/processing-model.adoc +30 -3
  5. data/lib/compat/opal/moxml_boot.rb +4 -0
  6. data/lib/moxml/adapter/leptris.rb +180 -20
  7. data/lib/moxml/adapter/libxml.rb +145 -23
  8. data/lib/moxml/adapter/oga.rb +33 -3
  9. data/lib/moxml/adapter/ox.rb +26 -2
  10. data/lib/moxml/adapter/rexml.rb +65 -15
  11. data/lib/moxml/context.rb +5 -1
  12. data/lib/moxml/document.rb +24 -10
  13. data/lib/moxml/node.rb +34 -6
  14. data/lib/moxml/node_set.rb +11 -0
  15. data/lib/moxml/reference/normalizer.rb +63 -0
  16. data/lib/moxml/reference/parser.rb +417 -0
  17. data/lib/moxml/reference/writer.rb +121 -0
  18. data/lib/moxml/reference.rb +205 -0
  19. data/lib/moxml/version.rb +1 -1
  20. data/lib/moxml/xpath/compiler.rb +17 -2
  21. data/lib/moxml/xpath/ordering.rb +97 -0
  22. data/lib/moxml/xpath.rb +1 -0
  23. data/lib/moxml.rb +1 -0
  24. data/spec/consistency/adapter_parity_spec.rb +2 -0
  25. data/spec/consistency/differential_taxonomy_spec.rb +117 -0
  26. data/spec/consistency/divergence_register_spec.rb +9 -1
  27. data/spec/consistency/eol_normalization_spec.rb +2 -0
  28. data/spec/consistency/loud_degradation_spec.rb +2 -0
  29. data/spec/consistency/metamorphic_properties_spec.rb +195 -0
  30. data/spec/consistency/metamorphic_spec.rb +138 -0
  31. data/spec/consistency/model_coverage_audit_spec.rb +108 -0
  32. data/spec/consistency/reference_differential_spec.rb +186 -0
  33. data/spec/consistency/xpath_idioms_spec.rb +11 -0
  34. data/spec/consistency/xslt_spec.rb +2 -0
  35. data/spec/moxml/adapter/leptris_attribute_snapshot_spec.rb +10 -7
  36. data/spec/moxml/adapter/leptris_contract_reads_spec.rb +29 -0
  37. data/spec/moxml/adapter/leptris_detached_text_spec.rb +10 -3
  38. data/spec/moxml/adapter/leptris_parse_lint_spec.rb +12 -0
  39. data/spec/moxml/adapter/ox_spec.rb +1 -1
  40. data/spec/moxml/attribute_resolver_spec.rb +2 -0
  41. data/spec/moxml/c14n/adapter_delegation_spec.rb +2 -0
  42. data/spec/moxml/doctype_spec.rb +7 -0
  43. data/spec/moxml/document_parse_diagnostics_spec.rb +2 -0
  44. data/spec/moxml/entity_spec.rb +2 -0
  45. data/spec/moxml/plan_conformance_spec.rb +2 -0
  46. data/spec/moxml/processing_instruction_spec.rb +9 -0
  47. data/spec/moxml/reference_opal_spec.rb +29 -0
  48. data/spec/moxml/reference_spec.rb +162 -0
  49. data/spec/moxml/sax_spec.rb +2 -0
  50. data/spec/moxml/text_spec.rb +2 -0
  51. data/spec/moxml/to_html_spec.rb +2 -0
  52. data/spec/moxml/xhtml_output_spec.rb +2 -0
  53. data/spec/moxml/xpath/axes_spec.rb +2 -2
  54. data/spec/moxml/xsd_spec.rb +38 -0
  55. data/spec/support/input_generator.rb +154 -0
  56. data/spec/support/input_taxonomy.rb +212 -0
  57. data/spec/support/xml_generator.rb +54 -0
  58. metadata +17 -2
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Processing model §Names and namespaces (normative): pinned here.
4
+ # Processing model §XPath evaluation (normative): pinned here.
5
+
3
6
  require "spec_helper"
4
7
 
5
8
  # Cross-adapter XPath idioms that nokogiri consumers rely on:
@@ -107,6 +110,14 @@ RSpec.describe "XPath idioms across adapters" do
107
110
  expect(doc.at_xpath("/*")&.name).to eq("r")
108
111
  expect(doc.at_xpath("/r")&.name).to eq("r")
109
112
  end
113
+
114
+ it "answers scalar XPath functions unwrapped and uniform" do
115
+ doc = ctx.parse(plain_xml)
116
+ expect(doc.xpath("count(//a)")).to eq(1.0)
117
+ expect(doc.xpath("string(//a/@id)")).to eq("x")
118
+ expect(doc.xpath("boolean(//b)")).to be(true)
119
+ expect(doc.at_xpath("count(//a)")).to eq(1.0)
120
+ end
110
121
  end
111
122
  end
112
123
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Processing model §XSLT (normative): pinned here.
4
+
3
5
  require "spec_helper"
4
6
  require "moxml/c14n"
5
7
 
@@ -5,10 +5,13 @@ require "spec_helper"
5
5
  # moxml#375 — element hydration through the binding's
6
6
  # attributes_snapshot face (libleptris 1.9.353, engine
7
7
  # leptris#1689): one crossing for every attribute instead of one
8
- # per attribute. The output contract is stride-identical to the
9
- # binding's per-attribute face: qualified names, document order,
10
- # fresh values.
8
+ # per attribute. The facade listing face is bare names (uniform with
9
+ # every adapter, and with Attribute#name), document order, fresh
10
+ # values.
11
11
  RSpec.describe "leptris element-attribute snapshot hydration" do
12
+ def bare(pairs)
13
+ pairs.map { |(name, value)| [name.split(":", 2).last, value] }
14
+ end
12
15
  let(:ctx) { Moxml.new(:leptris) }
13
16
 
14
17
  context "when the snapshot face is armed (>= 1.9.353.0)" do
@@ -23,11 +26,11 @@ RSpec.describe "leptris element-attribute snapshot hydration" do
23
26
  '<root a="1" xml:lang="en" xmlns:ns="urn:u" ns:p="v"/>',
24
27
  )
25
28
  binding_element = Moxml::Adapter::Leptris.to_binding(doc.root)
26
- expected = binding_element.attribute_pairs
29
+ expected = bare(binding_element.attribute_pairs)
27
30
 
28
31
  expect(doc.root.attribute_pairs).to eq(expected)
29
32
  expect(doc.root.attribute_pairs).to eq(
30
- [["a", "1"], ["xml:lang", "en"], ["ns:p", "v"]],
33
+ [["a", "1"], ["lang", "en"], ["p", "v"]],
31
34
  )
32
35
  end
33
36
 
@@ -36,7 +39,7 @@ RSpec.describe "leptris element-attribute snapshot hydration" do
36
39
  '<root z="9" xmlns:m="urn:m" m:x="8" k="7"/>',
37
40
  )
38
41
  expect(doc.root.attribute_pairs.map(&:first)).to eq(
39
- %w[z m:x k],
42
+ %w[z x k],
40
43
  )
41
44
  end
42
45
 
@@ -71,7 +74,7 @@ RSpec.describe "leptris element-attribute snapshot hydration" do
71
74
  )
72
75
  binding_element = Moxml::Adapter::Leptris.to_binding(doc.root)
73
76
  expect(doc.root.attribute_pairs).to eq(
74
- binding_element.attribute_pairs,
77
+ bare(binding_element.attribute_pairs),
75
78
  )
76
79
  end
77
80
  end
@@ -130,4 +130,33 @@ RSpec.describe "leptris Identity contract reads" do
130
130
  expect(el.text).to eq("v")
131
131
  end
132
132
  end
133
+
134
+ describe "children" do
135
+ it "answers without the adapter children crossing (children_read)" do
136
+ unless Leptris::XML::NativeNode.method_defined?(:children_read)
137
+ skip "binding #{Leptris::VERSION} has no children_read face"
138
+ end
139
+ doc = ctx.parse("<root><item>v</item></root>")
140
+ el = doc.root.children.first
141
+
142
+ singleton = Moxml::Adapter::Leptris.singleton_class
143
+ singleton.send(:alias_method, :children_without_walk, :children)
144
+ singleton.send(:define_method, :children) { |*| raise "adapter children crossing" }
145
+ begin
146
+ kids = el.children
147
+ expect(kids.to_a.map(&:name)).to eq(["text"])
148
+ ensure
149
+ singleton.send(:alias_method, :children, :children_without_walk)
150
+ singleton.send(:remove_method, :children_without_walk)
151
+ end
152
+ end
153
+
154
+ it "returns a NodeSet carrying the contract wrappers" do
155
+ doc = ctx.parse("<root><item>v</item></root>")
156
+ kids = doc.root.children.first.children
157
+ expect(kids).to be_a(Moxml::NodeSet)
158
+ expect(kids.to_a.first.name).to eq("text")
159
+ expect(kids.to_a.first.content).to eq("v")
160
+ end
161
+ end
133
162
  end
@@ -10,13 +10,20 @@ require "spec_helper"
10
10
  RSpec.describe "detached text content= names the cause" do
11
11
  let(:ctx) { Moxml.new(:leptris) }
12
12
 
13
- it "raises a named Moxml error for a removed text node" do
13
+ it "answers removed text nodes: mutable on fixed engines (1.9.374+), named error before" do
14
14
  doc = ctx.parse("<r><a>x</a><b>y</b></r>")
15
15
  text = doc.root.children[0].children[0]
16
16
  text.remove
17
17
 
18
- expect { text.content = "z" }
19
- .to raise_error(Moxml::Error, /detached \(parentless\).*issue #401/)
18
+ if Gem::Version.new(Leptris::VERSION) >= Gem::Version.new("1.9.374")
19
+ # leptris/leptris#1785 fixed the engine root cause: detached
20
+ # text resolves its owning document, so the mutation succeeds.
21
+ text.content = "z"
22
+ expect(text.content).to eq("z")
23
+ else
24
+ expect { text.content = "z" }
25
+ .to raise_error(Moxml::Error, /detached \(parentless\).*issue #401/)
26
+ end
20
27
  end
21
28
 
22
29
  it "keeps created-unattached nodes mutable" do
@@ -23,6 +23,18 @@ RSpec.describe "parse_html collect_errors forwarding" do
23
23
  expect(diags.first).to have_key(:message)
24
24
  end
25
25
 
26
+ # Issue #408: the #1771 reader fields ride the diag hash — the
27
+ # token code and position canon's HtmlValidator maps onto
28
+ # validation errors (nil where the engine has no token code).
29
+ it "carries the token code and position (issue #408)" do
30
+ doc = ctx.parse_html(src, collect_errors: true)
31
+ eof = doc.parse_diagnostics.find { |d| d[:message].include?("EOF") }
32
+ expect(eof).not_to be_nil
33
+ expect(eof[:code]).to eq("eof-in-tag")
34
+ expect(eof[:line]).to eq(1)
35
+ expect(eof[:column]).to eq(1)
36
+ end
37
+
26
38
  it "keeps the default lane silent (no option, no diagnostics)" do
27
39
  doc = ctx.parse_html(src)
28
40
  expect(doc.parse_diagnostics).to be_empty
@@ -94,7 +94,7 @@ RSpec.describe Moxml::Adapter::Ox do
94
94
 
95
95
  it "fails loudly on ox_mode: :hash (the adapter walks a tree, not a Hash)" do
96
96
  expect { described_class.parse("<r><t> x </t></r>", ox_mode: :hash) }
97
- .to raise_error(RuntimeError, /must be a String or Ox::Node/)
97
+ .to raise_error(Moxml::ParseError, /must be a String or Ox::Node/)
98
98
  end
99
99
 
100
100
  it "surfaces an invalid ox_skip as Moxml::ParseError" do
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Processing model §Access semantics (normative): pinned here.
4
+
3
5
  require "spec_helper"
4
6
 
5
7
  RSpec.describe Moxml::AttributeResolver do
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Processing model §Canonicalization (normative): pinned here.
4
+
3
5
  require "spec_helper"
4
6
  require "moxml/c14n"
5
7
 
@@ -84,6 +84,13 @@ RSpec.describe Moxml::Doctype do
84
84
  expect(doctype.external_id).to be_nil
85
85
  expect(doctype.system_id).to be_nil
86
86
  end
87
+
88
+ it "preserves a DOCTYPE internal subset on serialization" do
89
+ xml = '<!DOCTYPE r [<!ENTITY x "v">]><r>&x;</r>'
90
+ parsed = ctx.parse(xml)
91
+
92
+ expect(parsed.to_xml(indent: 0)).to include('<!ENTITY x "v">')
93
+ end
87
94
  end
88
95
  end
89
96
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Processing model §Parsing (normative): pinned here.
4
+
3
5
  require "spec_helper"
4
6
 
5
7
  # Document#parse_diagnostics (issue #271, option A — additive):
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Processing model §Parsing (normative): pinned here.
4
+
3
5
  require "spec_helper"
4
6
 
5
7
  RSpec.describe Moxml::Entity do
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Processing model §Materialization (normative): pinned here.
4
+
3
5
  require "spec_helper"
4
6
 
5
7
  # Moxml::Plan adapter-contract conformance (leptris follow-up to
@@ -21,6 +21,15 @@ RSpec.describe Moxml::ProcessingInstruction do
21
21
  expect(pi.content).to include("type=")
22
22
  expect(pi.content).to include("href=")
23
23
  end
24
+
25
+ it "answers the empty string for a PI with no data on every adapter" do
26
+ Moxml::Adapter::AVAILABLE_ADAPTERS.each do |name|
27
+ parsed = Moxml.new(name).parse("<r><?pi?></r>")
28
+ pi = parsed.children.first.children
29
+ .find { |n| n.is_a?(described_class) }
30
+ expect(pi.content).to eq(""), "empty PI content on #{name}"
31
+ end
32
+ end
24
33
  end
25
34
 
26
35
  describe "creation" do
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ # The engine-free lane (TODO.sota/03): the reference is pure Ruby and
6
+ # answers the model where no native engine exists. This spec proves it
7
+ # transpiles and runs under Opal.
8
+ RSpec.describe "Moxml::Reference under Opal", if: RUBY_ENGINE == "opal" do
9
+ it "parses, answers faces, and writes without a native engine" do
10
+ document = Moxml::Reference.parse(
11
+ '<r a="1"><b>t&amp;u</b><![CDATA[c]]><?pi d?></r>',
12
+ )
13
+ expect(Moxml::Reference.element_names(document)).to eq(%w[r b])
14
+ expect(Moxml::Reference.child_element_names(document)).to eq([["b"], []])
15
+ element = document.root.children.find(&:element?)
16
+ expect(element.children.map(&:kind)).to eq([:text])
17
+ expect(element.children.first.data).to eq("t&u")
18
+ expect(document.root.text).to eq("t&uc")
19
+ expect(Moxml::Reference.processing_instructions(document))
20
+ .to eq([["pi", "d"]])
21
+ expect(Moxml::Reference.to_xml(document))
22
+ .to include("<r a=\"1\">", "<b>t&amp;u</b>", "<![CDATA[c]]>")
23
+ end
24
+
25
+ it "raises a named ParseError for malformed input" do
26
+ expect { Moxml::Reference.parse("<r><c></r>") }
27
+ .to raise_error(Moxml::ParseError)
28
+ end
29
+ end
@@ -0,0 +1,162 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+ require "support/input_taxonomy"
5
+ require "support/xml_generator"
6
+
7
+ # The executable reference (TODO.sota/03): a pure-Ruby reader,
8
+ # writer, and normalizer that answer the processing model with no
9
+ # engine involved. The differential suite tests adapters against it;
10
+ # these specs pin the reference itself.
11
+ RSpec.describe Moxml::Reference do
12
+ describe "parsing" do
13
+ it "reads the object model, declaration, and document parts" do
14
+ doc = described_class.parse(
15
+ '<?xml version="1.0" encoding="UTF-8"?><!--lead--><r a="1"><b>t</b></r>',
16
+ )
17
+ expect(doc.declaration[:version]).to eq("1.0")
18
+ expect(doc.declaration[:encoding]).to eq("UTF-8")
19
+ expect(described_class.element_names(doc)).to eq(%w[r b])
20
+ expect(doc.root.attribute_pairs).to eq([["a", "1"]])
21
+ expect(described_class.comments(doc)).to eq(["lead"])
22
+ end
23
+
24
+ it "answers bare local names for prefixed sources" do
25
+ doc = described_class.parse('<r xmlns:p="urn:a"><p:c p:x="1"/></r>')
26
+ expect(described_class.element_names(doc)).to eq(%w[r c])
27
+ expect(described_class.child_element_names(doc)).to eq([["c"], []])
28
+ expect(doc.root.children.first.attribute_pairs).to eq([["x", "1"]])
29
+ end
30
+
31
+ it "expands built-in and numeric references, never comments or PI data" do
32
+ doc = described_class.parse(
33
+ "<r>&amp;&#65;&#x42;<![CDATA[<raw>]]><!-- c --><?pi d?></r>",
34
+ )
35
+ expect(doc.root.text).to eq("&AB<raw>")
36
+ expect(described_class.processing_instructions(doc)).to eq([["pi", "d"]])
37
+ end
38
+
39
+ it "preserves DTD-declared general entities lexically (uniform lane)" do
40
+ doc = described_class.parse(
41
+ '<!DOCTYPE r [<!ENTITY x "expanded">]><r>&x;</r>',
42
+ )
43
+ expect(doc.root.text).to eq("&x;")
44
+ end
45
+
46
+ it "normalizes literal line endings but not character references" do
47
+ doc = described_class.parse("<r>a\r\nb\rc&#xD;d</r>")
48
+ expect(doc.root.text).to eq("a\nb\nc\rd")
49
+ end
50
+
51
+ it "normalizes literal attribute whitespace" do
52
+ doc = described_class.parse(%(<r a="x\ty\nz"/>))
53
+ expect(doc.root.attribute_pairs).to eq([["a", "x y z"]])
54
+ end
55
+
56
+ it "drops the PI separator from PI data" do
57
+ doc = described_class.parse("<r><?pi data ?></r>")
58
+ expect(described_class.processing_instructions(doc))
59
+ .to eq([["pi", "data "]])
60
+ end
61
+
62
+ it "answers the empty string for PI with no data" do
63
+ doc = described_class.parse("<r><?pi?></r>")
64
+ expect(described_class.processing_instructions(doc)).to eq([["pi", ""]])
65
+ end
66
+ end
67
+
68
+ describe "totality over the input taxonomy" do
69
+ it "parses every well-formed taxonomy fixture" do
70
+ InputTaxonomy.well_formed.each do |input|
71
+ expect { described_class.parse(input.xml) }
72
+ .not_to raise_error, "#{input.id} must parse in the reference"
73
+ end
74
+ end
75
+
76
+ it "raises a named ParseError for every malformed taxonomy fixture" do
77
+ InputTaxonomy.malformed.each do |input|
78
+ expect { described_class.parse(input.xml) }
79
+ .to raise_error(Moxml::ParseError),
80
+ "#{input.id} must raise in the reference"
81
+ end
82
+ end
83
+
84
+ it "parses every generated document" do
85
+ (1..10).each do |seed|
86
+ expect { described_class.parse(XmlGenerator.generate(seed)) }
87
+ .not_to raise_error
88
+ end
89
+ end
90
+ end
91
+
92
+ describe "writers" do
93
+ let(:doc) do
94
+ described_class.parse(
95
+ '<r a="&lt;&amp;&quot;"><b/>t<!--c--><![CDATA[x<y]]></r>',
96
+ )
97
+ end
98
+
99
+ it "emits XML that re-parses to the same information set" do
100
+ xml = described_class.to_xml(doc)
101
+ again = described_class.parse(xml)
102
+ expect(described_class.element_names(again))
103
+ .to eq(described_class.element_names(doc))
104
+ expect(again.root.attribute_pairs).to eq(doc.root.attribute_pairs)
105
+ expect(again.root.text).to eq(doc.root.text)
106
+ end
107
+
108
+ it "emits the canonical facade escaping" do
109
+ expect(described_class.to_xml(doc))
110
+ .to include('<r a="&lt;&amp;&quot;">')
111
+ expect(described_class.to_xml(doc)).to include("<![CDATA[x<y]]>")
112
+ expect(described_class.to_xml(doc)).to include("<b/>")
113
+ end
114
+
115
+ it "splits a CDATA end sequence" do
116
+ document = Moxml::Reference::Document.new
117
+ root = Moxml::Reference::Node.new(kind: :element, name: "r")
118
+ root.children << Moxml::Reference::Node.new(kind: :cdata, data: "a]]>b")
119
+ document.children << root
120
+ expect(described_class.to_xml(document)).to include("]]]]><![CDATA[>")
121
+ end
122
+
123
+ it "leaves void elements unclosed in HTML and self-closed in XHTML" do
124
+ html_doc = described_class.parse("<html><body>a<br/>b</body></html>")
125
+ expect(described_class.to_html(html_doc)).to include("<br>")
126
+ expect(described_class.to_xhtml(html_doc)).to include("<br/>")
127
+ end
128
+
129
+ it "emits raw text inside HTML script and style, escaped in XHTML" do
130
+ html_doc = described_class.parse("<html><script>a &lt; b</script></html>")
131
+ expect(described_class.to_html(html_doc))
132
+ .to include("<script>a < b</script>")
133
+ expect(described_class.to_xhtml(html_doc))
134
+ .to include("<script>a &lt; b</script>")
135
+ end
136
+
137
+ it "emits no XML declaration unless the source had one" do
138
+ expect(described_class.to_html(described_class.parse("<r/>")))
139
+ .to eq("<r></r>")
140
+ with_declaration = described_class.parse('<?xml version="1.0"?><r/>')
141
+ expect(described_class.to_xml(with_declaration))
142
+ .to start_with('<?xml version="1.0"?>')
143
+ end
144
+ end
145
+
146
+ describe "normalizer" do
147
+ it "normalizes CRLF and bare CR to LF" do
148
+ expect(Moxml::Reference::Normalizer.normalize_eol("a\r\nb\rc"))
149
+ .to eq("a\nb\nc")
150
+ end
151
+
152
+ it "expands built-ins and numeric references" do
153
+ expect(Moxml::Reference::Normalizer.expand_entities("&lt;&#65;"))
154
+ .to eq("<A")
155
+ end
156
+
157
+ it "raises for an undefined reference" do
158
+ expect { Moxml::Reference::Normalizer.expand_entities("&nope;") }
159
+ .to raise_error(Moxml::ParseError)
160
+ end
161
+ end
162
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Processing model §SAX (normative): pinned here.
4
+
3
5
  require "spec_helper"
4
6
 
5
7
  RSpec.describe Moxml::SAX do
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Processing model §Access semantics (normative): pinned here.
4
+
3
5
  require "spec_helper"
4
6
 
5
7
  RSpec.describe Moxml::Text do
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Processing model §Serialization (normative): pinned here.
4
+
3
5
  require "spec_helper"
4
6
 
5
7
  # Document#to_html (issue #354): HTML-method serialization with the
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Processing model §Serialization (normative): pinned here.
4
+
3
5
  require "spec_helper"
4
6
 
5
7
  # Issue #390: XHTML-shaped serialization — void elements self-closed
@@ -217,11 +217,11 @@ RSpec.describe "XPath Axes" do
217
217
  end
218
218
 
219
219
  it "selects ancestors with ancestor::" do
220
- expect(select("//c/ancestor::*")).to eq(%w[parent root])
220
+ expect(select("//c/ancestor::*")).to eq(%w[root parent])
221
221
  end
222
222
 
223
223
  it "includes the context node with ancestor-or-self::" do
224
- expect(select("//c/ancestor-or-self::*")).to eq(%w[c parent root])
224
+ expect(select("//c/ancestor-or-self::*")).to eq(%w[root parent c])
225
225
  end
226
226
 
227
227
  it "selects following siblings" do
@@ -141,4 +141,42 @@ RSpec.describe Moxml::XSD do
141
141
  .to eq(Moxml::Adapter::Leptris::NATIVE_XSD)
142
142
  end
143
143
  end
144
+
145
+ describe "content_valid? with C-minted identity children (moxml#410)",
146
+ if: Moxml::Adapter::Leptris::XSD_SUPPORTED do
147
+ let(:ctx) { Moxml.new(:leptris) }
148
+ let(:schema_text) do
149
+ <<~XML
150
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
151
+ <xs:element name="person">
152
+ <xs:complexType>
153
+ <xs:sequence>
154
+ <xs:element name="name" type="xs:string"/>
155
+ </xs:sequence>
156
+ </xs:complexType>
157
+ </xs:element>
158
+ </xs:schema>
159
+ XML
160
+ end
161
+
162
+ it "answers for identity wrappers minted at create (1.9.374+)" do
163
+ schema = ctx.xsd(schema_text)
164
+ doc = ctx.create_document
165
+ root = doc.create_element("person")
166
+ doc.root = root
167
+ name = doc.create_element("name")
168
+ name.text = "A"
169
+ root.add_child(name)
170
+
171
+ expect(root.native.class.name).to include("Identity")
172
+ expect(schema.content_valid?("person", root.children.to_a)).to be(true)
173
+ end
174
+
175
+ it "answers for identity children from parse" do
176
+ schema = ctx.xsd(schema_text)
177
+ root = ctx.parse("<person><name>A</name></person>").root
178
+ expect(schema.content_valid?("person", root.children.to_a)).to be(true)
179
+ expect(schema.content_valid?("person", [])).to be(false)
180
+ end
181
+ end
144
182
  end