lutaml-model 0.8.205 → 0.8.207

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.
@@ -97,10 +97,10 @@ module Lutaml
97
97
  # (namespaced spellings are instance-dependent; ordered,
98
98
  # wildcard, raw, and callback shapes are not
99
99
  # ops-expressible).
100
- # element_order is the order contract: a model carrying it —
101
- # parse-captured or programmatically tracked (#977) — must
102
- # serialize through the ordered walk, not the flat
103
- # schema-order native ops layout.
100
+ # element_order is the order contract: a model carrying a
101
+ # tracked one (#977) serializes through the ordered walk
102
+ # below, not the flat schema-order native ops layout — the
103
+ # native gate refuses those instances.
104
104
  return NativeEmission.emit(instance, plan, register) if
105
105
  NativeEmission.compatible?(plan, instance, register)
106
106
 
@@ -119,13 +119,11 @@ module Lutaml
119
119
  if instance.is_a?(::Lutaml::Model::Serialize) &&
120
120
  instance.raw_schema_location &&
121
121
  !instance.raw_schema_location.empty?
122
- root.set_attribute(
123
- "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"
124
- )
122
+ ns_ctx.declare_xsi_on(root)
125
123
  root.set_attribute("xsi:schemaLocation",
126
124
  instance.raw_schema_location)
127
125
  end
128
- built = if plan[:ordered] || !instance.element_order.nil?
126
+ built = if ordered_walk?(plan, instance)
129
127
  build_ordered(root, instance, plan, doc, register, ns_ctx,
130
128
  scope: BlankScope.new(ns_ctx.default_namespace,
131
129
  false, pretty))
@@ -161,6 +159,7 @@ module Lutaml
161
159
  @model_prefix = nil
162
160
  @forms = {}
163
161
  @hoisted = {}
162
+ @extra_declarations = []
164
163
  @declared = {}
165
164
  @unspellable = false
166
165
  mapping = plan[:mapping]
@@ -219,25 +218,33 @@ module Lutaml
219
218
  @hoisted[model_uri] = ns_prefix
220
219
  @forms[model_uri] = { prefix: ns_prefix, uri: model_uri }
221
220
  end
222
- # Source declaration preservation (the interpretive
223
- # writer's stored-plan merge): prefixes the parsed source
224
- # declared are kept for URIs the document emits. The
225
- # planner's class-analysis path has no stored-plan
226
- # access, so the merge reads the instance's recorded plan
227
- # directly.
221
+ # Source declaration preservation (the interpretive writer's
222
+ # stored-plan behavior): every namespace the parsed source
223
+ # declared on the root is declared again. The ones the
224
+ # planner recomputed keep the planner's spelling (format
225
+ # preservation); the rest ride along verbatim — an extra
226
+ # vocabulary the root declared, or the prefix a captured
227
+ # raw fragment spells. A default-namespace source that also
228
+ # bound a declared URI to a prefix keeps that second
229
+ # declaration (the doubly-defined root); a prefixed source
230
+ # does not (the interpretive merge skips it).
228
231
  stored = if instance.is_a?(::Lutaml::Model::Serialize)
229
232
  instance.import_declaration_plan
230
233
  end
231
234
  if stored.is_a?(Lutaml::Xml::DeclarationPlan) &&
232
235
  stored.root_node.is_a?(
233
236
  Lutaml::Xml::DeclarationPlan::ElementNode,
234
- ) && (ns_prefix.nil? || ns_prefix.empty?)
235
- original_uris = stored.original_namespace_uris || {}
237
+ )
238
+ prefixed_source = ns_prefix && !ns_prefix.empty?
236
239
  stored.root_node.hoisted_declarations.each do |prefix, uri|
237
- effective_uri = original_uris[uri] || uri
238
- already = @hoisted.value?(effective_uri) ||
239
- @hoisted.value?(uri)
240
- @hoisted[prefix] = uri if already && !@hoisted.key?(prefix)
240
+ if @hoisted.key?(uri)
241
+ next if prefixed_source || prefix.nil? || @hoisted[uri] == prefix
242
+
243
+ @extra_declarations << [prefix, uri]
244
+ else
245
+ @hoisted[uri] = prefix
246
+ @forms[uri] = { prefix: prefix, uri: uri }
247
+ end
241
248
  end
242
249
  end
243
250
  collect(plan[:tree])
@@ -265,6 +272,19 @@ module Lutaml
265
272
  @unspellable
266
273
  end
267
274
 
275
+ # The xsi prefix for a raw xsi:schemaLocation — declared once
276
+ # with the plan's other declarations (a parsed source's own
277
+ # declaration is kept above).
278
+ def declare_xsi_on(root)
279
+ uri = Lutaml::Xml::W3c::XsiNamespace.uri
280
+ return if @declared[uri]
281
+
282
+ root.add_namespace_definition(
283
+ Lutaml::Xml::W3c::XsiNamespace.prefix_default, uri
284
+ )
285
+ @declared[uri] = true
286
+ end
287
+
268
288
  # Whether the root declares a default namespace — every
269
289
  # element then has one in scope until a :blank child opts
270
290
  # out with xmlns="".
@@ -335,6 +355,13 @@ module Lutaml
335
355
  @declared[uri] = true
336
356
  root.add_namespace_definition(prefix, uri)
337
357
  end
358
+ @extra_declarations.each do |prefix, uri|
359
+ next if uri.nil? || uri == XML_NAMESPACE_URI ||
360
+ @declared[[prefix, uri]]
361
+
362
+ @declared[[prefix, uri]] = true
363
+ root.add_namespace_definition(prefix, uri)
364
+ end
338
365
  end
339
366
  end
340
367
 
@@ -433,7 +460,7 @@ module Lutaml
433
460
  scope, ns_ctx),
434
461
  )
435
462
  ns_ctx&.collect(child_plan[:tree])
436
- if child_plan[:ordered] || !item.element_order.nil?
463
+ if ordered_walk?(child_plan, item)
437
464
  build_ordered(child, item, child_plan,
438
465
  doc, reg, ns_ctx, form,
439
466
  scope: child_scope) || return
@@ -452,8 +479,14 @@ module Lutaml
452
479
  # deferred rows ride the fast lane untouched.
453
480
  return nil unless Array(value).empty?
454
481
  when :content, :content_deferred
455
- Array(value).each do |run|
456
- append_text(element, run.to_s, doc, cdata: rule.cdata)
482
+ if value.is_a?(::Array)
483
+ # The interpretive apply_mixed_content: the runs
484
+ # interleave with the element children emitted so far
485
+ # — the first before the first element, each next one
486
+ # after an element, a trailing run appended.
487
+ interleave_runs(element, value, doc, cdata: rule.cdata)
488
+ else
489
+ append_text(element, value.to_s, doc, cdata: rule.cdata)
457
490
  end
458
491
  end
459
492
  end
@@ -685,7 +718,7 @@ module Lutaml
685
718
  scope,
686
719
  qualify!(child, child_ns, blank, scope, ns_ctx),
687
720
  )
688
- if child_plan[:ordered] || !item.element_order.nil?
721
+ if ordered_walk?(child_plan, item)
689
722
  return nil unless build_ordered(child, item, child_plan,
690
723
  doc, reg, ns_ctx, child_ns,
691
724
  scope: child_scope)
@@ -694,7 +727,18 @@ module Lutaml
694
727
  scope: child_scope) || return
695
728
  end
696
729
  when :raw
697
- element.add_child(value.to_s) unless value.nil?
730
+ # One captured fragment per order entry — the
731
+ # interpretive walk's per-value raw injection. A
732
+ # collection's fragments were injected whole at the
733
+ # first entry (the rest arriving as a Ruby array
734
+ # spelling).
735
+ items = value.is_a?(::Array) ? value : [value]
736
+ index = element_indices[dispatch_key]
737
+ next unless index < items.length
738
+
739
+ element_indices[dispatch_key] += 1
740
+ raw = items[index]
741
+ element.add_child(raw.to_s) unless raw.nil? || raw.to_s.empty?
698
742
  when :child_deferred
699
743
  # Valued cycle-point children: interpretive lane (see
700
744
  # build).
@@ -748,6 +792,60 @@ module Lutaml
748
792
  RECONCILER.order_entry?(object)
749
793
  end
750
794
 
795
+ # Whether the parsed source declared anything the plan's own
796
+ # namespaces do not cover — an extra vocabulary on the root, or
797
+ # a second prefix for a declared namespace. The ops layout
798
+ # cannot spell those; the DOM lane re-declares them (the
799
+ # interpretive writer's stored-plan behavior).
800
+ def stored_declarations_uncovered?(plan, instance)
801
+ return false unless instance.is_a?(::Lutaml::Model::Serialize)
802
+
803
+ stored = instance.import_declaration_plan
804
+ return false unless stored.is_a?(Lutaml::Xml::DeclarationPlan) &&
805
+ stored.root_node.is_a?(Lutaml::Xml::DeclarationPlan::ElementNode)
806
+
807
+ declared = stored.root_node.hoisted_declarations
808
+ return false if declared.empty?
809
+
810
+ uris = declared_uris(plan)
811
+ declared.values.uniq.size != declared.size ||
812
+ declared.values.any? { |uri| !uris.include?(uri) }
813
+ end
814
+
815
+ # The namespace URIs the plan's emission declares on its root.
816
+ def declared_uris(plan)
817
+ plan[:declared_uris] ||= tree_uris(plan[:tree], {}).freeze
818
+ end
819
+
820
+ def tree_uris(tree, uris)
821
+ collect_uri = lambda do |ns|
822
+ uris[ns[:exact]] = true if ns.is_a?(::Hash) && ns[:exact]
823
+ end
824
+ collect_uri.call(tree[:ns])
825
+ (tree[:attributes] || []).each { |a| collect_uri.call(a[:ns]) }
826
+ (tree[:children] || []).each do |row|
827
+ collect_uri.call(row[:ns])
828
+ tree_uris(row[:plan], uris) if row[:plan]
829
+ end
830
+ uris
831
+ end
832
+
833
+ # Whether an instance serializes through the ordered walk: an
834
+ # ordered/mixed plan, or an instance carrying a programmatically
835
+ # tracked element_order (the order-tracker pattern, lutaml-model
836
+ # #977) whatever its mapping declares. A parse-built record on
837
+ # an unordered plan does not reroute — sequence validation reads
838
+ # it, and the interpretive writer emits mapping order there. The
839
+ # plan lane's parse-built record is PlanOrder.build's frozen
840
+ # array; a tracked one is mutable (entries are appended).
841
+ def ordered_walk?(plan, instance)
842
+ return true if plan[:ordered]
843
+ return false unless instance.is_a?(::Lutaml::Model::Serialize)
844
+
845
+ order = instance.element_order
846
+ !order.nil? && !order.empty? && !order.frozen?
847
+ end
848
+
751
849
  # [attribute name, serialized name] -> CompiledRule for one
752
850
  # transformation, identity-keyed by its frozen rule array.
753
851
  def compiled_rule_index_for(klass, reg)
@@ -858,7 +956,7 @@ module Lutaml
858
956
  child_scope = subtree_scope(
859
957
  scope, qualify!(child, child_ns, blank, scope, ns_ctx)
860
958
  )
861
- if child_plan[:ordered] || !item.element_order.nil?
959
+ if ordered_walk?(child_plan, item)
862
960
  return nil unless build_ordered(child, item, child_plan,
863
961
  doc, reg, ns_ctx, child_ns,
864
962
  scope: child_scope)
@@ -1015,7 +1113,10 @@ module Lutaml
1015
1113
  xsi_nil: false)
1016
1114
  child = element.create_child(name)
1017
1115
  attrs&.each { |k, v| child[k.to_s] = v.to_s }
1018
- child.set_attribute("xsi:nil", "true") if xsi_nil
1116
+ if xsi_nil
1117
+ child.set_attribute("xsi:nil", "true")
1118
+ declare_xsi_prefix(doc)
1119
+ end
1019
1120
  # An uninitialized value rendered under its value_map is an
1020
1121
  # empty element (the interpretive serialize_value yields no
1021
1122
  # text for it).
@@ -1025,6 +1126,21 @@ module Lutaml
1025
1126
  child
1026
1127
  end
1027
1128
 
1129
+ # xsi:nil spells the xsi prefix: the document root declares it,
1130
+ # as a parsed source's own declaration is kept (the stored
1131
+ # plan re-emits it) — a constructed tree carries none.
1132
+ def declare_xsi_prefix(doc)
1133
+ root = doc.root
1134
+ return unless root
1135
+
1136
+ prefix = Lutaml::Xml::W3c::XsiNamespace.prefix_default
1137
+ return if root["xmlns:#{prefix}"] ||
1138
+ root.namespace_definitions.any? { |ns| ns.prefix == prefix }
1139
+
1140
+ root.add_namespace_definition(prefix,
1141
+ Lutaml::Xml::W3c::XsiNamespace.uri)
1142
+ end
1143
+
1028
1144
  # A collection row's emission (the interpretive
1029
1145
  # apply_collection_element contract): one leaf per item — a
1030
1146
  # nil item goes unrendered when the value_map omits nil — and
@@ -1079,7 +1195,8 @@ module Lutaml
1079
1195
  # Shared with NativeEmission's gate: the order-entry predicate,
1080
1196
  # the render-policy placeholder and the coverage pre-check
1081
1197
  # decide what the ops lane cannot serve.
1082
- public :order_entry?, :placeholder_for, :order_uncovered?
1198
+ public :order_entry?, :ordered_walk?, :placeholder_for, :order_uncovered?,
1199
+ :stored_declarations_uncovered?
1083
1200
 
1084
1201
  # Whether a row's value reaches the output at all — the
1085
1202
  # interpretive should_skip_value? contract (RenderPolicy): an
@@ -1112,7 +1229,7 @@ module Lutaml
1112
1229
  # FFI::Pointer wrapper per fresh node, the last per-row
1113
1230
  # Ruby-side allocation on the DOM build.
1114
1231
  def append_text(parent, text, doc, cdata: false)
1115
- node = cdata ? doc.create_cdata(text) : doc.create_text_node(text)
1232
+ node = text_node(doc, text, cdata)
1116
1233
  status = ::Leptris::XML::FFI.leptris_element_add_child_addr(
1117
1234
  parent.c_address, node.c_address
1118
1235
  )
@@ -1124,6 +1241,27 @@ module Lutaml
1124
1241
  node
1125
1242
  end
1126
1243
 
1244
+ def text_node(doc, text, cdata)
1245
+ cdata ? doc.create_cdata(text) : doc.create_text_node(text)
1246
+ end
1247
+
1248
+ # The interpretive apply_mixed_content over the children emitted
1249
+ # so far: the runs interleave with them — the first before the
1250
+ # first child, each next one after a child, a trailing run
1251
+ # appended (the #1164 tail).
1252
+ def interleave_runs(element, runs, doc, cdata: false)
1253
+ existing = element.children
1254
+ nodes = runs.map do |run|
1255
+ run.nil? || run.to_s.empty? ? nil : text_node(doc, run.to_s, cdata)
1256
+ end
1257
+ interleaved = [nodes[0]]
1258
+ existing.each_with_index do |child, index|
1259
+ interleaved << child << nodes[index + 1]
1260
+ end
1261
+ interleaved.concat(nodes[(existing.size + 1)..] || [])
1262
+ element.children = interleaved.compact
1263
+ end
1264
+
1127
1265
  # Whether a Value type hooks the XML format through its own
1128
1266
  # methods (instance to_xml, class from_xml) instead of a
1129
1267
  # registered format serializer. The interpretive writer calls
@@ -146,8 +146,15 @@ module Lutaml
146
146
  end
147
147
  end
148
148
  root_and_parent_assignment(instance, options)
149
- apply_xml_mapping(ParseSession.new(data, instance, options,
150
- child_register))
149
+ parsed = apply_xml_mapping(ParseSession.new(data, instance, options,
150
+ child_register))
151
+ # A parsed instance is pristine on every lane: the parse's own
152
+ # writer calls are not a mutation of the parsed state (the plan
153
+ # lanes' hydrator resets the same flag after construction).
154
+ if instance_is_serialize
155
+ instance.clear_mutated_after_parse!
156
+ end
157
+ parsed
151
158
  end
152
159
 
153
160
  # Build a DeclarationPlan from the parsed element tree's namespace declarations.
data/lutaml-model.gemspec CHANGED
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.add_dependency "bigdecimal"
36
36
  spec.add_dependency "canon"
37
37
  spec.add_dependency "concurrent-ruby"
38
- spec.add_dependency "liquid", ">= 4.0", "< 6.0"
38
+ spec.add_dependency "liquid", "~> 5.14"
39
39
  # 0.5.84 always passes XML_PARSE_HUGE to libxml2: very large documents
40
40
  # parse completely instead of being silently truncated at the 10 MB
41
41
  # input-buffer cap (lutaml-model#871).
@@ -1 +1 @@
1
- {"capabilities":["json","xml"],"corpora":[{"generation":"core-v2","sha256":"sha256:fd1de9747a78a71d737a4076ebfb0cf4a561d96dba9156a43afb5a337ebad0d2"}],"dependencies":[{"name":"lutaml-model","revision":"8a8ef040963b7965388b01b58af33af2b0995f91","sha256":"sha256:14c85f76a3cf2ebb18aa3c97186840897bf2147c886818a5c73670d3a6db170a"}],"files":[{"path":"index.json","sha256":"sha256:fd1de9747a78a71d737a4076ebfb0cf4a561d96dba9156a43afb5a337ebad0d2"},{"path":"schema.json","sha256":"sha256:ce5cc1c61e4a97bc71b2683b71e56c5488dbd3f41fdfa2802c01c4c2cd34fa1e"},{"path":"schema.yaml","sha256":"sha256:5c6f2cf9ddb907bd2aaff813711a6ed0d35e0ff1563d5b4f893301f803dac8e0"}],"generator_version":"ruby-core-oracle-v2","lml_checksum":"sha256:a7fac433ca7be94a6a66f6b8d0dab8134747860cf8076dffc4aaa92a24d1cb34","manifest":1,"schema_version":2,"target":"ruby"}
1
+ {"capabilities":["json","xml"],"corpora":[{"generation":"core-v2","sha256":"sha256:fd1de9747a78a71d737a4076ebfb0cf4a561d96dba9156a43afb5a337ebad0d2"}],"dependencies":[{"name":"lutaml-model","revision":"8a8ef040963b7965388b01b58af33af2b0995f91","sha256":"sha256:480e5a78e34f290b28420d56b1f4aad0162a16c87067c21597e99e9b1dbca39e"}],"files":[{"path":"index.json","sha256":"sha256:fd1de9747a78a71d737a4076ebfb0cf4a561d96dba9156a43afb5a337ebad0d2"},{"path":"schema.json","sha256":"sha256:ce5cc1c61e4a97bc71b2683b71e56c5488dbd3f41fdfa2802c01c4c2cd34fa1e"},{"path":"schema.yaml","sha256":"sha256:5c6f2cf9ddb907bd2aaff813711a6ed0d35e0ff1563d5b4f893301f803dac8e0"}],"generator_version":"ruby-core-oracle-v2","lml_checksum":"sha256:a7fac433ca7be94a6a66f6b8d0dab8134747860cf8076dffc4aaa92a24d1cb34","manifest":1,"schema_version":2,"target":"ruby"}
@@ -1 +1 @@
1
- {"capabilities":["json","xml"],"corpora":[{"generation":"preservation-v1","sha256":"sha256:76d942557692ee653136f10fcf98e5b3beef43d9ed9a9082eb6d17002b64ddd9"}],"dependencies":[{"name":"lutaml-model","revision":"8a8ef040963b7965388b01b58af33af2b0995f91","sha256":"sha256:14c85f76a3cf2ebb18aa3c97186840897bf2147c886818a5c73670d3a6db170a"}],"files":[{"path":"index.json","sha256":"sha256:76d942557692ee653136f10fcf98e5b3beef43d9ed9a9082eb6d17002b64ddd9"},{"path":"schema.json","sha256":"sha256:66b86b75d36568c1c353a2d5cf32d0e6562e21e7dfea0004a757d0f774761264"},{"path":"schema.yaml","sha256":"sha256:cf40d46e901e4a8e7bb4b7f7ad4365ffec687bef81832663dc136626b3963c3d"}],"generator_version":"ruby-preservation-oracle-v1","lml_checksum":"sha256:81eaac6230a81d4285fb4ea743f202234ef3f3c48482ca60ce9e9b642a5622e5","manifest":1,"schema_version":2,"target":"ruby"}
1
+ {"capabilities":["json","xml"],"corpora":[{"generation":"preservation-v1","sha256":"sha256:76d942557692ee653136f10fcf98e5b3beef43d9ed9a9082eb6d17002b64ddd9"}],"dependencies":[{"name":"lutaml-model","revision":"8a8ef040963b7965388b01b58af33af2b0995f91","sha256":"sha256:480e5a78e34f290b28420d56b1f4aad0162a16c87067c21597e99e9b1dbca39e"}],"files":[{"path":"index.json","sha256":"sha256:76d942557692ee653136f10fcf98e5b3beef43d9ed9a9082eb6d17002b64ddd9"},{"path":"schema.json","sha256":"sha256:66b86b75d36568c1c353a2d5cf32d0e6562e21e7dfea0004a757d0f774761264"},{"path":"schema.yaml","sha256":"sha256:cf40d46e901e4a8e7bb4b7f7ad4365ffec687bef81832663dc136626b3963c3d"}],"generator_version":"ruby-preservation-oracle-v1","lml_checksum":"sha256:81eaac6230a81d4285fb4ea743f202234ef3f3c48482ca60ce9e9b642a5622e5","manifest":1,"schema_version":2,"target":"ruby"}
@@ -334,15 +334,14 @@ RSpec.describe Lutaml::Model::Cli do
334
334
 
335
335
  after { FileUtils.rm_rf(temp_dir) }
336
336
 
337
- it "handles malformed XML gracefully" do
337
+ it "reports malformed XML instead of comparing a recovered tree" do
338
338
  cli.options = options
339
339
 
340
- # The XML parser is forgiving and creates empty models for malformed XML
340
+ # The comparison parses strictly: a malformed document is an
341
+ # error on every engine, never a best-effort tree to diff.
341
342
  expect do
342
343
  cli.compare(malformed_xml, files[:target_xml_path])
343
- end.to output(
344
- a_string_including("Differences between", "Similarity score:"),
345
- ).to_stdout
344
+ end.to raise_error(StandardError, /Error parsing file .*malformed\.xml/)
346
345
  end
347
346
 
348
347
  it "raises error when parsing malformed YAML" do
@@ -266,9 +266,14 @@ RSpec.describe "Group" do
266
266
  let(:mapper) { GroupSpec::CeramicCollection }
267
267
 
268
268
  it "raises error if type-only class used directly for parsing" do
269
+ # A well-formed document: the model's own error must be the one
270
+ # raised, not an engine's verdict on the input (a strict lane
271
+ # rejects a two-root fragment before the model is consulted).
269
272
  xml = <<~XML
270
- <type>Data</type>
271
- <name>Smith</name>
273
+ <ceramic>
274
+ <type>Data</type>
275
+ <name>Smith</name>
276
+ </ceramic>
272
277
  XML
273
278
 
274
279
  expect { GroupSpec::Ceramic.from_xml(xml) }.to raise_error(
@@ -84,6 +84,10 @@ RSpec.describe "LML review round-4 probe fixes (encoding, float enums, bundle in
84
84
  end
85
85
 
86
86
  describe "Bundle construction" do
87
+ # The sets are large enough that a build takes tens of milliseconds: at
88
+ # 1000/4000 models the builds took 5-25 ms, and a shared runner could
89
+ # report a 14x ratio for the same linear code (lutaml-model#1328). The
90
+ # best of three drops the stragglers.
87
91
  it "scales linearly with the number of models" do
88
92
  build = lambda do |count|
89
93
  models = (0...count).to_h { |i| ["R5M#{i}@default", minimal_model("R5M#{i}")] }
@@ -91,9 +95,9 @@ RSpec.describe "LML review round-4 probe fixes (encoding, float enums, bundle in
91
95
  lml::Bundle.new(roots: [], models: models)
92
96
  Process.clock_gettime(Process::CLOCK_MONOTONIC) - started
93
97
  end
94
- build.call(500)
95
- small = [build.call(1000), build.call(1000)].min
96
- large = [build.call(4000), build.call(4000)].min
98
+ build.call(2_000)
99
+ small = Array.new(3) { build.call(10_000) }.min
100
+ large = Array.new(3) { build.call(40_000) }.min
97
101
 
98
102
  expect(large / small).to be < 12
99
103
  end
@@ -132,8 +132,9 @@ RSpec.describe RenderNil do
132
132
  end
133
133
 
134
134
  it "serializes to XML with render_nil option" do
135
+ # xsi:nil spells the xsi prefix: the root declares it.
135
136
  expected_xml = <<~XML
136
- <render_nil>
137
+ <render_nil xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
137
138
  <name xsi:nil="true"/>
138
139
  <glaze xsi:nil="true"/>
139
140
  <render_nil_nested/>
@@ -185,8 +185,9 @@ RSpec.describe "ValueMap" do
185
185
  end
186
186
 
187
187
  let(:expected_xml) do
188
+ # xsi:nil spells the xsi prefix: the root declares it.
188
189
  <<~XML.strip
189
- <WithValueMaps>
190
+ <WithValueMaps xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
190
191
  <omittedAsNil xsi:nil="true"/>
191
192
  <omittedAsEmpty/>
192
193
  <nilAsNil xsi:nil="true"/>
@@ -218,22 +219,23 @@ RSpec.describe "ValueMap" do
218
219
 
219
220
  let(:parsed) { ValueMapSpec::WithValueMaps.from_xml(xml) }
220
221
 
221
- let(:expected) do
222
- ValueMapSpec::WithValueMaps.new(
223
- {
224
- nil_as_nil: nil,
225
- nil_as_empty: "",
226
- empty_as_empty: "",
227
- empty_as_nil: nil,
228
- omitted_as_nil: nil,
229
- omitted_as_empty: "",
230
- },
231
- { omitted: :omitted },
232
- )
233
- end
234
-
235
222
  it "sets correct values when deserializing" do
236
- expect(parsed).to eq(expected)
223
+ # The bound attributes carry their value_map's binding.
224
+ expect(parsed.nil_as_nil).to be_nil
225
+ expect(parsed.nil_as_empty).to eq("")
226
+ expect(parsed.empty_as_empty).to eq("")
227
+ expect(parsed.empty_as_nil).to be_nil
228
+ expect(parsed.omitted_as_nil).to be_nil
229
+ expect(parsed.omitted_as_empty).to eq("")
230
+
231
+ # :omitted binds no value — whether the element was absent,
232
+ # nil-marked, or empty. (How an unbound attribute is held is the
233
+ # constructor's business: the deserialization seed keeps the
234
+ # uninitialized sentinel, the plan lane's seed a nil.)
235
+ unbound = ->(value) { value.nil? || Lutaml::Model::Utils.uninitialized?(value) }
236
+ %i[omitted_as_omitted nil_as_omitted empty_as_omitted].each do |name|
237
+ expect(unbound.call(parsed.public_send(name))).to be(true), "#{name} should bind no value"
238
+ end
237
239
  end
238
240
  end
239
241
  end