lutaml-model 0.8.190 → 0.8.192

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 (75) hide show
  1. checksums.yaml +4 -4
  2. data/lib/compat/opal/generate_boot.rb +5 -4
  3. data/lib/compat/opal/lutaml_model_boot.rb +0 -7
  4. data/lib/lutaml/model/attribute.rb +6 -11
  5. data/lib/lutaml/model/serialize/format_conversion.rb +4 -6
  6. data/lib/lutaml/model/version.rb +1 -1
  7. data/lib/lutaml/xml/adapter/adapter_helpers.rb +3 -3
  8. data/lib/lutaml/xml/adapter/base_adapter.rb +13 -29
  9. data/lib/lutaml/xml/adapter/moxml_adapter.rb +113 -22
  10. data/lib/lutaml/xml/adapter/xml_parser.rb +6 -8
  11. data/lib/lutaml/xml/adapter/xml_serializer.rb +3 -1
  12. data/lib/lutaml/xml/adapter.rb +0 -4
  13. data/lib/lutaml/xml/adapter_element.rb +19 -9
  14. data/lib/lutaml/xml/adapter_loader.rb +26 -11
  15. data/lib/lutaml/xml/builder/base.rb +6 -7
  16. data/lib/lutaml/xml/document.rb +1 -1
  17. data/lib/lutaml/xml/format.rb +0 -10
  18. data/lib/lutaml/xml/leptris/plan_hydrator.rb +2 -2
  19. data/spec/lutaml/model/cdata_spec.rb +11 -27
  20. data/spec/lutaml/model/direct_construction_verbatim_spec.rb +82 -0
  21. data/spec/lutaml/model/encoding_spec.rb +6 -6
  22. data/spec/lutaml/model/except_spec.rb +5 -7
  23. data/spec/lutaml/model/mixed_content_spec.rb +22 -25
  24. data/spec/lutaml/model/multiple_mapping_spec.rb +8 -10
  25. data/spec/lutaml/model/ordered_content_spec.rb +5 -8
  26. data/spec/lutaml/model/processing_instruction_spec.rb +6 -9
  27. data/spec/lutaml/model/serialize/attribute_definition_block_form_spec.rb +1 -1
  28. data/spec/lutaml/model/serialize/builder_spec.rb +1 -1
  29. data/spec/lutaml/xml/adapter/base_adapter_regression_spec.rb +5 -8
  30. data/spec/lutaml/xml/adapter/empty_document_diagnostics_spec.rb +3 -4
  31. data/spec/lutaml/xml/adapter/nokogiri_adapter_spec.rb +2 -2
  32. data/spec/lutaml/xml/adapter/oga_adapter_spec.rb +2 -2
  33. data/spec/lutaml/xml/adapter/order_spec.rb +8 -22
  34. data/spec/lutaml/xml/adapter/over_cap_parse_spec.rb +2 -2
  35. data/spec/lutaml/xml/adapter/ox_adapter_spec.rb +2 -2
  36. data/spec/lutaml/xml/adapter/rexml_adapter_spec.rb +2 -2
  37. data/spec/lutaml/xml/adapter/xml_namespace_spec.rb +5 -8
  38. data/spec/lutaml/xml/adapter_loader_spec.rb +15 -3
  39. data/spec/lutaml/xml/adapter_metadata_default_spec.rb +1 -1
  40. data/spec/lutaml/xml/adapter_moxml_engine_spec.rb +1 -2
  41. data/spec/lutaml/xml/builder/builder_spec.rb +28 -20
  42. data/spec/lutaml/xml/default_namespace_spec.rb +4 -5
  43. data/spec/lutaml/xml/entity_fragmentation_spec.rb +2 -2
  44. data/spec/lutaml/xml/mapping_rule_spec.rb +1 -2
  45. data/spec/lutaml/xml/mapping_spec.rb +12 -14
  46. data/spec/lutaml/xml/namespace_missing_prefix_spec.rb +1 -1
  47. data/spec/lutaml/xml/namespace_preservation_spec.rb +11 -11
  48. data/spec/lutaml/xml/namespace_scope_vcard_spec.rb +5 -8
  49. data/spec/lutaml/xml/prefix_control_spec.rb +5 -8
  50. data/spec/lutaml/xml/type_namespace_prefix_spec.rb +2 -2
  51. data/spec/lutaml/xml/xml_adapter_spec.rb +5 -8
  52. data/spec/lutaml/xml/xml_declaration_spec.rb +19 -19
  53. data/spec/spec_helper.rb +2 -2
  54. data/spec/support/test_adapter_config.rb +9 -25
  55. metadata +2 -21
  56. data/lib/lutaml/xml/adapter/leptris_adapter.rb +0 -16
  57. data/lib/lutaml/xml/adapter/nokogiri_adapter.rb +0 -16
  58. data/lib/lutaml/xml/adapter/oga_adapter.rb +0 -20
  59. data/lib/lutaml/xml/adapter/ox_adapter.rb +0 -16
  60. data/lib/lutaml/xml/adapter/rexml_adapter.rb +0 -25
  61. data/lib/lutaml/xml/builder/leptris.rb +0 -13
  62. data/lib/lutaml/xml/builder/nokogiri.rb +0 -13
  63. data/lib/lutaml/xml/builder/oga.rb +0 -13
  64. data/lib/lutaml/xml/builder/ox.rb +0 -13
  65. data/lib/lutaml/xml/builder/rexml.rb +0 -13
  66. data/lib/lutaml/xml/leptris/element.rb +0 -34
  67. data/lib/lutaml/xml/nokogiri/element.rb +0 -34
  68. data/lib/lutaml/xml/nokogiri.rb +0 -10
  69. data/lib/lutaml/xml/oga/element.rb +0 -15
  70. data/lib/lutaml/xml/oga.rb +0 -10
  71. data/lib/lutaml/xml/ox/element.rb +0 -15
  72. data/lib/lutaml/xml/ox.rb +0 -10
  73. data/lib/lutaml/xml/rexml/element.rb +0 -15
  74. data/lib/lutaml/xml/rexml.rb +0 -10
  75. data/lib/tasks/xml_optimization_benchmark.rb +0 -178
@@ -1,8 +1,8 @@
1
1
  require "spec_helper"
2
2
  require "nokogiri"
3
- require_relative "../../../../lib/lutaml/xml/adapter/nokogiri_adapter"
3
+ require "lutaml/xml/adapter/moxml_adapter"
4
4
 
5
- RSpec.describe Lutaml::Xml::Adapter::NokogiriAdapter do
5
+ RSpec.describe Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:nokogiri) do
6
6
  let(:xml_string) do
7
7
  <<-XML
8
8
  <root xmlns="http://example.com/default" xmlns:prefix="http://example.com/prefixed">
@@ -1,8 +1,8 @@
1
1
  require "spec_helper"
2
2
  require "oga"
3
- require_relative "../../../../lib/lutaml/xml/adapter/oga_adapter"
3
+ require "lutaml/xml/adapter/moxml_adapter"
4
4
 
5
- RSpec.describe Lutaml::Xml::Adapter::OgaAdapter, :oga_adapter do
5
+ RSpec.describe Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:oga), :oga_adapter do
6
6
  let(:xml_string) do
7
7
  <<~XML
8
8
  <root xmlns="http://example.com/default" xmlns:prefix="http://example.com/prefixed">
@@ -1,10 +1,7 @@
1
1
  require "spec_helper"
2
2
  require "lutaml/model"
3
3
  require "lutaml/xml"
4
- require "lutaml/xml/adapter/nokogiri_adapter"
5
- require "lutaml/xml/adapter/ox_adapter"
6
- require "lutaml/xml/adapter/oga_adapter"
7
- require "lutaml/xml/adapter/rexml_adapter"
4
+ require "lutaml/xml/adapter/moxml_adapter"
8
5
 
9
6
  module XmlAdapterSharedFeaturesSpec
10
7
  class ProcessingInstructionLookupElement < Lutaml::Model::Serializable
@@ -128,23 +125,12 @@ RSpec.describe "XML adapter order metadata" do
128
125
  end
129
126
  end
130
127
 
131
- describe Lutaml::Xml::Adapter::NokogiriAdapter do
132
- it_behaves_like "consistent order metadata", described_class
133
- it_behaves_like "consistent shared adapter features", described_class
134
- end
135
-
136
- describe Lutaml::Xml::Adapter::OxAdapter do
137
- it_behaves_like "consistent order metadata", described_class
138
- it_behaves_like "consistent shared adapter features", described_class
139
- end
140
-
141
- describe Lutaml::Xml::Adapter::OgaAdapter do
142
- it_behaves_like "consistent order metadata", described_class
143
- it_behaves_like "consistent shared adapter features", described_class
144
- end
145
-
146
- describe Lutaml::Xml::Adapter::RexmlAdapter do
147
- it_behaves_like "consistent order metadata", described_class
148
- it_behaves_like "consistent shared adapter features", described_class
128
+ %i[nokogiri ox oga rexml].each do |engine|
129
+ describe "the :#{engine} lane" do
130
+ it_behaves_like "consistent order metadata",
131
+ Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(engine)
132
+ it_behaves_like "consistent shared adapter features",
133
+ Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(engine)
134
+ end
149
135
  end
150
136
  end
@@ -4,7 +4,7 @@ require "spec_helper"
4
4
  require "nokogiri"
5
5
  require "lutaml/model"
6
6
  require "lutaml/xml"
7
- require "lutaml/xml/adapter/nokogiri_adapter"
7
+ require "lutaml/xml/adapter/moxml_adapter"
8
8
 
9
9
  # Regression coverage for lutaml-model#871: very large documents must
10
10
  # deserialize completely, with no silent truncation and no data loss.
@@ -76,7 +76,7 @@ RSpec.describe "parsing documents past libxml2's 10 MB buffer cap" do
76
76
 
77
77
  it "returns the complete tree from the adapter layer" do
78
78
  Lutaml::Model::Config.with_adapter(xml: :nokogiri) do
79
- document = Lutaml::Xml::Adapter::NokogiriAdapter.parse(over_cap_document)
79
+ document = Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:nokogiri).parse(over_cap_document)
80
80
 
81
81
  expect(document.root.children.count).to eq(7)
82
82
  end
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
- require_relative "../../../../lib/lutaml/xml/adapter/ox_adapter"
2
+ require "lutaml/xml/adapter/moxml_adapter"
3
3
 
4
- RSpec.describe Lutaml::Xml::Adapter::OxAdapter, :ox_adapter do
4
+ RSpec.describe Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:ox), :ox_adapter do
5
5
  let(:xml_string) do
6
6
  <<-XML
7
7
  <root xmlns="http://example.com/default" xmlns:prefix="http://example.com/prefixed">
@@ -2,9 +2,9 @@ require "spec_helper"
2
2
 
3
3
  if TestAdapterConfig.adapter_enabled?(:rexml)
4
4
  require "rexml/document"
5
- require_relative "../../../../lib/lutaml/xml/adapter/rexml_adapter"
5
+ require "lutaml/xml/adapter/moxml_adapter"
6
6
 
7
- RSpec.describe Lutaml::Xml::Adapter::RexmlAdapter do
7
+ RSpec.describe Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:rexml) do
8
8
  let(:xml_string) do
9
9
  <<~XML
10
10
  <root xmlns="http://example.com/default" xmlns:prefix="http://example.com/prefixed">
@@ -1,8 +1,5 @@
1
1
  require "spec_helper"
2
- require "lutaml/xml/adapter/nokogiri_adapter"
3
- require "lutaml/xml/adapter/ox_adapter"
4
- require "lutaml/xml/adapter/oga_adapter"
5
- require "lutaml/xml/adapter/rexml_adapter"
2
+ require "lutaml/xml/adapter/moxml_adapter"
6
3
  require_relative "../../../../lib/lutaml/model"
7
4
  require_relative "../../../support/xml_mapping_namespaces"
8
5
 
@@ -496,11 +493,11 @@ RSpec.describe "XmlNamespace" do
496
493
  end
497
494
  end
498
495
 
499
- describe Lutaml::Xml::Adapter::NokogiriAdapter do
496
+ describe Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:nokogiri) do
500
497
  it_behaves_like "an XML namespace parser", described_class
501
498
  end
502
499
 
503
- describe Lutaml::Xml::Adapter::OxAdapter do
500
+ describe Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:ox) do
504
501
  around do |example|
505
502
  if /(with prefixed namespace|with default namespace|mixing different namespaces)/.match?(example.metadata[:description])
506
503
  skip "Ox adapter has known broken namespace implementation"
@@ -515,14 +512,14 @@ RSpec.describe "XmlNamespace" do
515
512
  end
516
513
  end
517
514
 
518
- describe Lutaml::Xml::Adapter::OgaAdapter do
515
+ describe Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:oga) do
519
516
  if TestAdapterConfig.adapter_enabled?(:oga)
520
517
  it_behaves_like "an XML namespace parser",
521
518
  described_class
522
519
  end
523
520
  end
524
521
 
525
- describe Lutaml::Xml::Adapter::RexmlAdapter do
522
+ describe Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:rexml) do
526
523
  if TestAdapterConfig.adapter_enabled?(:rexml)
527
524
  it_behaves_like "an XML namespace parser",
528
525
  described_class
@@ -3,12 +3,24 @@
3
3
  require "spec_helper"
4
4
 
5
5
  RSpec.describe Lutaml::Xml::AdapterLoader do
6
- it "chains the LoadError cause instead of masking it" do
6
+ # Every adapter type loads the one shared adapter file; the
7
+ # chained-cause contract lives at the ENGINE preload — a missing
8
+ # engine gem must name the real gap, not present as a bare
9
+ # unknown-type error.
10
+ it "chains the engine LoadError cause instead of masking it" do
11
+ allow(Moxml::Adapter).to receive(:load)
12
+ .and_raise(LoadError, "cannot load such file -- nokogiri")
7
13
  expect do
8
- described_class.load_adapter_file("xml", "bogus_adapter")
14
+ described_class.load_moxml_adapter(:nokogiri, :xml)
9
15
  end.to raise_error(Lutaml::Model::UnknownAdapterTypeError) do |error|
10
16
  expect(error.cause).to be_a(LoadError)
11
- expect(error.cause.message).to include("bogus_adapter")
17
+ expect(error.cause.message).to include("nokogiri")
12
18
  end
13
19
  end
20
+
21
+ it "raises for an unknown engine at the adapter factory" do
22
+ expect do
23
+ Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:bogus)
24
+ end.to raise_error(ArgumentError, /unknown XML engine/)
25
+ end
14
26
  end
@@ -28,7 +28,7 @@ RSpec.describe "XML adapter metadata default (#908, #1224)" do
28
28
  .and_return(:leptris)
29
29
 
30
30
  adapter = Lutaml::Model::Config.adapter_for(:xml)
31
- expect(adapter.name).to eq("Lutaml::Xml::Adapter::LeptrisAdapter")
31
+ expect(adapter.engine_name).to eq(:leptris)
32
32
  ensure
33
33
  Lutaml::Model::AdapterResolver.reset!
34
34
  end
@@ -17,8 +17,7 @@ RSpec.describe "the deferred lane's engine resolution seams" do
17
17
  end
18
18
 
19
19
  it "answers the engine Moxml deploys through the adapter seam" do
20
- expect(Lutaml::Model::Config.xml_adapter.engine_adapter_class.name)
21
- .to eq("Lutaml::Xml::Adapter::LeptrisAdapter")
20
+ expect(Lutaml::Model::Config.xml_adapter.engine_name).to eq(:leptris)
22
21
  end
23
22
 
24
23
  it "parses an XSD schema under the deferred lane" do
@@ -5,7 +5,7 @@ require "spec_helper"
5
5
  RSpec.shared_examples "a consistent XML builder" do
6
6
  describe "#create_and_add_element" do
7
7
  it "creates an element with attributes" do
8
- builder = described_class.build do |xml|
8
+ builder = Lutaml::Xml::Builder::Base.build(engine: engine) do |xml|
9
9
  xml.create_and_add_element("root", attributes: { "id" => "1" })
10
10
  end
11
11
 
@@ -15,7 +15,7 @@ RSpec.shared_examples "a consistent XML builder" do
15
15
  end
16
16
 
17
17
  it "nests elements via block" do
18
- builder = described_class.build do |xml|
18
+ builder = Lutaml::Xml::Builder::Base.build(engine: engine) do |xml|
19
19
  xml.create_and_add_element("root") do
20
20
  xml.create_and_add_element("child")
21
21
  end
@@ -29,7 +29,7 @@ RSpec.shared_examples "a consistent XML builder" do
29
29
 
30
30
  describe "#add_text" do
31
31
  it "adds a text node to an element" do
32
- builder = described_class.build do |xml|
32
+ builder = Lutaml::Xml::Builder::Base.build(engine: engine) do |xml|
33
33
  xml.create_and_add_element("root") do
34
34
  xml.text("hello")
35
35
  end
@@ -41,7 +41,7 @@ RSpec.shared_examples "a consistent XML builder" do
41
41
 
42
42
  describe "#add_cdata" do
43
43
  it "adds a CDATA section to an element" do
44
- builder = described_class.build do |xml|
44
+ builder = Lutaml::Xml::Builder::Base.build(engine: engine) do |xml|
45
45
  xml.create_and_add_element("root") do
46
46
  xml.cdata("some data")
47
47
  end
@@ -53,7 +53,7 @@ RSpec.shared_examples "a consistent XML builder" do
53
53
 
54
54
  describe "#add_comment" do
55
55
  it "appends a comment node to an element" do
56
- builder = described_class.build do |xml|
56
+ builder = Lutaml::Xml::Builder::Base.build(engine: engine) do |xml|
57
57
  xml.create_and_add_element("root") do
58
58
  xml.add_comment(xml.current_node, "a comment")
59
59
  end
@@ -70,7 +70,7 @@ RSpec.shared_examples "a consistent XML builder" do
70
70
 
71
71
  describe "#add_xml_fragment" do
72
72
  it "parses and inserts XML fragment" do
73
- builder = described_class.build do |xml|
73
+ builder = Lutaml::Xml::Builder::Base.build(engine: engine) do |xml|
74
74
  xml.create_and_add_element("root") do
75
75
  xml.add_xml_fragment(xml.current_node, "<child>text</child>")
76
76
  end
@@ -82,7 +82,7 @@ RSpec.shared_examples "a consistent XML builder" do
82
82
 
83
83
  describe "#to_xml" do
84
84
  it "serializes the built document" do
85
- builder = described_class.build do |xml|
85
+ builder = Lutaml::Xml::Builder::Base.build(engine: engine) do |xml|
86
86
  xml.create_and_add_element("root", attributes: { "key" => "val" }) do
87
87
  xml.text("content")
88
88
  end
@@ -94,14 +94,14 @@ RSpec.shared_examples "a consistent XML builder" do
94
94
  end
95
95
 
96
96
  it "returns empty string when no root" do
97
- builder = described_class.build
97
+ builder = Lutaml::Xml::Builder::Base.build(engine: engine)
98
98
  expect(builder.to_xml).to eq("")
99
99
  end
100
100
  end
101
101
 
102
102
  describe "method_missing DSL" do
103
103
  it "creates elements dynamically" do
104
- builder = described_class.build do |xml|
104
+ builder = Lutaml::Xml::Builder::Base.build(engine: engine) do |xml|
105
105
  xml.create_and_add_element("root") do
106
106
  xml.create_and_add_element("item", attributes: { "id" => "1" })
107
107
  end
@@ -113,17 +113,17 @@ RSpec.shared_examples "a consistent XML builder" do
113
113
 
114
114
  describe "encoding" do
115
115
  it "stores encoding from build options" do
116
- builder = described_class.build(encoding: "ISO-8859-1")
116
+ builder = Lutaml::Xml::Builder::Base.build(engine: engine, encoding: "ISO-8859-1")
117
117
  expect(builder.encoding).to eq("ISO-8859-1")
118
118
  end
119
119
 
120
120
  it "defaults encoding to nil" do
121
- builder = described_class.build
121
+ builder = Lutaml::Xml::Builder::Base.build(engine: engine)
122
122
  expect(builder.encoding).to be_nil
123
123
  end
124
124
 
125
125
  it "encodes output XML with specified encoding" do
126
- builder = described_class.build(encoding: "ISO-8859-1") do |xml|
126
+ builder = Lutaml::Xml::Builder::Base.build(engine: engine, encoding: "ISO-8859-1") do |xml|
127
127
  xml.create_and_add_element("root") do
128
128
  xml.text("café")
129
129
  end
@@ -135,7 +135,7 @@ RSpec.shared_examples "a consistent XML builder" do
135
135
  end
136
136
 
137
137
  it "keeps UTF-8 when no encoding specified" do
138
- builder = described_class.build do |xml|
138
+ builder = Lutaml::Xml::Builder::Base.build(engine: engine) do |xml|
139
139
  xml.create_and_add_element("root") do
140
140
  xml.text("café")
141
141
  end
@@ -149,7 +149,7 @@ RSpec.shared_examples "a consistent XML builder" do
149
149
 
150
150
  describe "namespace handling" do
151
151
  it "declares xmlns attributes as namespaces" do
152
- builder = described_class.build do |xml|
152
+ builder = Lutaml::Xml::Builder::Base.build(engine: engine) do |xml|
153
153
  xml.create_and_add_element("root",
154
154
  attributes: { "xmlns:ns" => "http://example.com" })
155
155
  end
@@ -159,7 +159,7 @@ RSpec.shared_examples "a consistent XML builder" do
159
159
  end
160
160
 
161
161
  it "keeps default namespace elements unprefixed" do
162
- builder = described_class.build do |xml|
162
+ builder = Lutaml::Xml::Builder::Base.build(engine: engine) do |xml|
163
163
  xml.create_and_add_element("root",
164
164
  attributes: { "xmlns" => "urn:example" }) do
165
165
  xml.create_and_add_element("child") do
@@ -180,22 +180,28 @@ RSpec.shared_examples "a consistent XML builder" do
180
180
  end
181
181
 
182
182
  RSpec.describe "XML Builder consistency" do
183
- describe Lutaml::Xml::Builder::Nokogiri do
183
+ describe "on :nokogiri" do
184
+ let(:engine) { :nokogiri }
185
+
184
186
  it_behaves_like "a consistent XML builder"
185
187
  end
186
188
 
187
- describe Lutaml::Xml::Builder::Ox do
189
+ describe "on :ox" do
190
+ let(:engine) { :ox }
191
+
188
192
  it_behaves_like "a consistent XML builder"
189
193
  end
190
194
 
191
- describe Lutaml::Xml::Builder::Oga do
195
+ describe "on :oga" do
196
+ let(:engine) { :oga }
197
+
192
198
  it_behaves_like "a consistent XML builder"
193
199
 
194
200
  it "defaults namespace validation to lenient under Opal" do
195
201
  allow(Lutaml::Model::RuntimeCompatibility).to receive(:opal?)
196
202
  .and_return(true)
197
203
 
198
- builder = described_class.build do |xml|
204
+ builder = Lutaml::Xml::Builder::Base.build(engine: engine) do |xml|
199
205
  xml.create_and_add_element(
200
206
  "root",
201
207
  attributes: {
@@ -210,7 +216,9 @@ RSpec.describe "XML Builder consistency" do
210
216
  end
211
217
  end
212
218
 
213
- describe Lutaml::Xml::Builder::Rexml do
219
+ describe "on :rexml" do
220
+ let(:engine) { :rexml }
221
+
214
222
  it_behaves_like "a consistent XML builder"
215
223
  end
216
224
  end
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "spec_helper"
4
- require "lutaml/xml/adapter/ox_adapter"
5
- require "lutaml/xml/adapter/oga_adapter"
4
+ require "lutaml/xml/adapter/moxml_adapter"
6
5
  require_relative "../../support/xml_mapping_namespaces"
7
6
 
8
7
  # Test for issue #504: Default namespace handling
@@ -170,18 +169,18 @@ RSpec.describe DefaultNamespaceSpec do
170
169
  end
171
170
  end
172
171
 
173
- describe Lutaml::Xml::Adapter::NokogiriAdapter do
172
+ describe Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:nokogiri) do
174
173
  it_behaves_like "default namespace serialization", described_class
175
174
  end
176
175
 
177
- describe Lutaml::Xml::Adapter::OxAdapter do
176
+ describe Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:ox) do
178
177
  if TestAdapterConfig.adapter_enabled?(:ox)
179
178
  it_behaves_like "default namespace serialization",
180
179
  described_class
181
180
  end
182
181
  end
183
182
 
184
- describe Lutaml::Xml::Adapter::OgaAdapter do
183
+ describe Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:oga) do
185
184
  if TestAdapterConfig.adapter_enabled?(:oga)
186
185
  it_behaves_like "default namespace serialization",
187
186
  described_class
@@ -429,7 +429,7 @@ RSpec.describe "XML Entity Fragmentation Issue #5" do
429
429
  # These tests exercise the adapter's to_xml path (build_xml → native
430
430
  # Nokogiri serialization), which is distinct from NokogiriElement#to_xml.
431
431
  context "adapter-level to_xml round-trip" do
432
- let(:adapter_class) { Lutaml::Xml::Adapter::NokogiriAdapter }
432
+ let(:adapter_class) { Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:nokogiri) }
433
433
 
434
434
  it "preserves non-standard entity references" do
435
435
  doc = adapter_class.parse("<copyright>&copy; 2005 Mulberry</copyright>")
@@ -463,7 +463,7 @@ RSpec.describe "XML Entity Fragmentation Issue #5" do
463
463
  end
464
464
 
465
465
  context "entity references in attribute values" do
466
- let(:adapter_class) { Lutaml::Xml::Adapter::NokogiriAdapter }
466
+ let(:adapter_class) { Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:nokogiri) }
467
467
 
468
468
  it "preserves non-standard entities in attributes via element to_xml" do
469
469
  root = adapter_class.parse('<root attr="&copy; 2024"/>').root
@@ -1,7 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- require "lutaml/xml/adapter/ox_adapter"
4
- require "lutaml/xml/adapter/oga_adapter"
3
+ require "lutaml/xml/adapter/moxml_adapter"
5
4
 
6
5
  def content_to_xml(model, parent, doc)
7
6
  content = model.all_content.sub(/^<div>/, "").sub(/<\/div>$/, "")
@@ -1,8 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- require "lutaml/xml/adapter/ox_adapter"
4
- require "lutaml/xml/adapter/oga_adapter"
5
- require "lutaml/xml/adapter/rexml_adapter"
3
+ require "lutaml/xml/adapter/moxml_adapter"
6
4
  require_relative "../../support/xml_mapping_namespaces"
7
5
 
8
6
  # Define a sample class for testing map content
@@ -498,7 +496,7 @@ RSpec.describe Lutaml::Xml::Mapping do
498
496
  expect(parsed.beta).to eq("bye")
499
497
 
500
498
  # Ox adapter omits xmlns:ex1 declaration (namespace hoisting difference)
501
- expected = if adapter_class == Lutaml::Xml::Adapter::OxAdapter
499
+ expected = if adapter_class == Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:ox)
502
500
  <<~XML
503
501
  <example xmlns="http://www.check.com" ex1:alpha="hello" beta="bye"/>
504
502
  XML
@@ -628,7 +626,7 @@ RSpec.describe Lutaml::Xml::Mapping do
628
626
  # Different adapters have different hoisting behaviors:
629
627
  # - Nokogiri/Oga: Hoists namespace to parent
630
628
  # - Ox: No namespace declaration (uses inline xmi prefix without xmlns)
631
- expected = if adapter_class == Lutaml::Xml::Adapter::OxAdapter
629
+ expected = if adapter_class == Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:ox)
632
630
  # Ox doesn't add xmlns declaration when model has no namespace
633
631
  <<~XML.strip
634
632
  <ownedComment>
@@ -657,7 +655,7 @@ RSpec.describe Lutaml::Xml::Mapping do
657
655
  # Different adapters have different hoisting behaviors:
658
656
  # - Nokogiri/Oga: Hoists namespace to parent
659
657
  # - Ox: No namespace declaration (uses inline xmi prefix without xmlns)
660
- expected = if adapter_class == Lutaml::Xml::Adapter::OxAdapter
658
+ expected = if adapter_class == Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:ox)
661
659
  # Ox doesn't add xmlns declaration when model has no namespace
662
660
  <<~XML.strip
663
661
  <ownedComment annotatedElement="test2">
@@ -696,7 +694,7 @@ RSpec.describe Lutaml::Xml::Mapping do
696
694
  # GML uses DEFAULT format (format info lost due to namespace_locations sibling collision)
697
695
  # Note: Ox adapter always uses prefix format
698
696
  let(:expected_xml) do
699
- if adapter_class == Lutaml::Xml::Adapter::OxAdapter
697
+ if adapter_class == Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:ox)
700
698
  # Ox uses prefix format
701
699
  <<~XML
702
700
  <SameElementName App="hello" xmlns="http://www.omg.org/spec/XMI/20131001">
@@ -804,7 +802,7 @@ RSpec.describe Lutaml::Xml::Mapping do
804
802
  # NOTE: mapping with namespace: nil, prefix: nil has differing adapter behavior:
805
803
  # - Nokogiri: Cannot parse element with parent namespace prefix, returns nil
806
804
  # - Ox/Oga: Can parse element with parent namespace prefix successfully
807
- if adapter_class == Lutaml::Xml::Adapter::NokogiriAdapter
805
+ if adapter_class == Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:nokogiri)
808
806
  expect(parsed.without_namespace).to be_nil
809
807
  else
810
808
  expect(parsed.without_namespace.value).to eq("without namespace text")
@@ -815,7 +813,7 @@ RSpec.describe Lutaml::Xml::Mapping do
815
813
  # Serialize the parsed model
816
814
  serialized = parsed.to_xml
817
815
 
818
- if adapter_class == Lutaml::Xml::Adapter::NokogiriAdapter
816
+ if adapter_class == Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:nokogiri)
819
817
  # Nokogiri cannot parse the pn:WithoutNamespace element, so it's nil
820
818
  # and won't be in the serialized output. Verify other elements round-trip.
821
819
  reparsed = XmlMappingSpec::WithChildExplicitNamespace.from_xml(serialized)
@@ -920,7 +918,7 @@ RSpec.describe Lutaml::Xml::Mapping do
920
918
  # Both are W3C compliant.
921
919
  let(:expected_xml) do
922
920
  # Ox uses prefix format, Nokogiri/Oga use default format
923
- if adapter_class == Lutaml::Xml::Adapter::OxAdapter
921
+ if adapter_class == Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:ox)
924
922
  <<~XML
925
923
  <ChildNamespaceNil xmlns="http://www.omg.org/spec/XMI/20131001">
926
924
  <ElementDefaultNamespace>Default namespace</ElementDefaultNamespace>
@@ -1125,25 +1123,25 @@ RSpec.describe Lutaml::Xml::Mapping do
1125
1123
  end
1126
1124
  end
1127
1125
 
1128
- describe Lutaml::Xml::Adapter::NokogiriAdapter do
1126
+ describe Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:nokogiri) do
1129
1127
  it_behaves_like "having XML Mappings", described_class
1130
1128
  end
1131
1129
 
1132
- describe Lutaml::Xml::Adapter::OxAdapter do
1130
+ describe Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:ox) do
1133
1131
  if TestAdapterConfig.adapter_enabled?(:ox)
1134
1132
  it_behaves_like "having XML Mappings",
1135
1133
  described_class
1136
1134
  end
1137
1135
  end
1138
1136
 
1139
- describe Lutaml::Xml::Adapter::OgaAdapter do
1137
+ describe Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:oga) do
1140
1138
  if TestAdapterConfig.adapter_enabled?(:oga)
1141
1139
  it_behaves_like "having XML Mappings",
1142
1140
  described_class
1143
1141
  end
1144
1142
  end
1145
1143
 
1146
- describe Lutaml::Xml::Adapter::RexmlAdapter do
1144
+ describe Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:rexml) do
1147
1145
  if TestAdapterConfig.adapter_enabled?(:rexml)
1148
1146
  it_behaves_like "having XML Mappings", described_class
1149
1147
  end
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
  require_relative "../../../lib/lutaml/model"
3
- require "lutaml/xml/adapter/nokogiri_adapter"
3
+ require "lutaml/xml/adapter/moxml_adapter"
4
4
 
5
5
  # Namespace Prefix Missing on First Element in Chain
6
6
  #
@@ -13,7 +13,7 @@ RSpec.describe "Namespace Preservation Issue #3" do
13
13
  XML
14
14
 
15
15
  # Parse the XML
16
- doc = Lutaml::Xml::Adapter::NokogiriAdapter.parse(xml_input)
16
+ doc = Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:nokogiri).parse(xml_input)
17
17
 
18
18
  # Re-serialize
19
19
  output = doc.to_xml
@@ -32,7 +32,7 @@ RSpec.describe "Namespace Preservation Issue #3" do
32
32
  </root>
33
33
  XML
34
34
 
35
- doc = Lutaml::Xml::Adapter::NokogiriAdapter.parse(xml_input)
35
+ doc = Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:nokogiri).parse(xml_input)
36
36
  output = doc.to_xml
37
37
 
38
38
  # All three namespaces should be preserved
@@ -50,7 +50,7 @@ RSpec.describe "Namespace Preservation Issue #3" do
50
50
  </article>
51
51
  XML
52
52
 
53
- doc = Lutaml::Xml::Adapter::NokogiriAdapter.parse(xml_input)
53
+ doc = Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:nokogiri).parse(xml_input)
54
54
  output = doc.to_xml
55
55
 
56
56
  # Should preserve mml namespace
@@ -72,7 +72,7 @@ RSpec.describe "Namespace Preservation Issue #3" do
72
72
  </article>
73
73
  XML
74
74
 
75
- doc = Lutaml::Xml::Adapter::NokogiriAdapter.parse(xml_input)
75
+ doc = Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:nokogiri).parse(xml_input)
76
76
  output = doc.to_xml
77
77
 
78
78
  expect(output).to include('xmlns="http://jats.nlm.nih.gov/publishing/1.3"')
@@ -86,7 +86,7 @@ RSpec.describe "Namespace Preservation Issue #3" do
86
86
  </article>
87
87
  XML
88
88
 
89
- doc = Lutaml::Xml::Adapter::NokogiriAdapter.parse(xml_input)
89
+ doc = Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:nokogiri).parse(xml_input)
90
90
  output = doc.to_xml
91
91
 
92
92
  expect(output).to include('xmlns="http://example.com/default"')
@@ -112,7 +112,7 @@ RSpec.describe "Namespace Preservation Issue #3" do
112
112
  </article>
113
113
  XML
114
114
 
115
- doc = Lutaml::Xml::Adapter::NokogiriAdapter.parse(xml_input)
115
+ doc = Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:nokogiri).parse(xml_input)
116
116
  output = doc.to_xml
117
117
 
118
118
  # All four namespaces should be preserved
@@ -131,7 +131,7 @@ RSpec.describe "Namespace Preservation Issue #3" do
131
131
  </root>
132
132
  XML
133
133
 
134
- doc = Lutaml::Xml::Adapter::NokogiriAdapter.parse(xml_input)
134
+ doc = Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:nokogiri).parse(xml_input)
135
135
  output = doc.to_xml
136
136
 
137
137
  # All namespaces should be present (order not strictly required by XML spec)
@@ -149,7 +149,7 @@ RSpec.describe "Namespace Preservation Issue #3" do
149
149
  </root>
150
150
  XML
151
151
 
152
- doc = Lutaml::Xml::Adapter::NokogiriAdapter.parse(xml_input)
152
+ doc = Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:nokogiri).parse(xml_input)
153
153
  output = doc.to_xml
154
154
 
155
155
  # Empty namespace (explicit no namespace)
@@ -163,7 +163,7 @@ RSpec.describe "Namespace Preservation Issue #3" do
163
163
  </root>
164
164
  XML
165
165
 
166
- doc = Lutaml::Xml::Adapter::NokogiriAdapter.parse(xml_input)
166
+ doc = Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:nokogiri).parse(xml_input)
167
167
 
168
168
  output = doc.to_xml
169
169
  # Should not have any xmlns declarations
@@ -184,7 +184,7 @@ RSpec.describe "Namespace Preservation Issue #3" do
184
184
  </article>
185
185
  XML
186
186
 
187
- doc = Lutaml::Xml::Adapter::NokogiriAdapter.parse(xml_input)
187
+ doc = Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:nokogiri).parse(xml_input)
188
188
  output = doc.to_xml
189
189
 
190
190
  # All namespaces preserved, including unused
@@ -218,7 +218,7 @@ RSpec.describe "Namespace Preservation Issue #3" do
218
218
  </article>
219
219
  XML
220
220
 
221
- doc = Lutaml::Xml::Adapter::NokogiriAdapter.parse(xml_input)
221
+ doc = Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:nokogiri).parse(xml_input)
222
222
  output = doc.to_xml
223
223
 
224
224
  # Verify all JATS namespaces are preserved