lutaml-model 0.8.203 → 0.8.205
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.
- checksums.yaml +4 -4
- data/.gitattributes +5 -0
- data/.github/workflows/lml-conformance.yml +71 -0
- data/.gitignore +7 -0
- data/README.adoc +1 -0
- data/docs/_guides/lml-cross-language.adoc +128 -0
- data/docs/_guides/native-engines.adoc +10 -0
- data/docs/_references/lml-conformance.adoc +78 -0
- data/docs/_references/lml-contract.adoc +290 -0
- data/lib/lutaml/model/lml/artifact_verifier.rb +205 -0
- data/lib/lutaml/model/lml/bundle.rb +171 -0
- data/lib/lutaml/model/lml/document.rb +46 -10
- data/lib/lutaml/model/lml/document_validator.rb +840 -0
- data/lib/lutaml/model/lml/exporter/v1_projector.rb +102 -0
- data/lib/lutaml/model/lml/exporter/v2_projector.rb +401 -0
- data/lib/lutaml/model/lml/exporter.rb +223 -87
- data/lib/lutaml/model/lml/graph_exporter.rb +248 -0
- data/lib/lutaml/model/lml/importer.rb +180 -0
- data/lib/lutaml/model/lml/mapping_compiler.rb +401 -0
- data/lib/lutaml/model/lml/materialization.rb +257 -0
- data/lib/lutaml/model/lml/ordered_content.rb +577 -0
- data/lib/lutaml/model/lml/portable_json.rb +385 -0
- data/lib/lutaml/model/lml/rejected_error.rb +64 -15
- data/lib/lutaml/model/lml/round_trip.rb +86 -0
- data/lib/lutaml/model/lml/value_declarations.rb +84 -0
- data/lib/lutaml/model/lml.rb +61 -0
- data/lib/lutaml/model/schema/definitions/attribute.rb +4 -2
- data/lib/lutaml/model/schema/registry_generator.rb +1 -1
- data/lib/lutaml/model/schema/renderers/member_decls.rb +1 -0
- data/lib/lutaml/model/schema/xml_compiler/spec_builder/members.rb +10 -0
- data/lib/lutaml/model/sequence.rb +7 -0
- data/lib/lutaml/model/serialize/format_conversion.rb +22 -8
- data/lib/lutaml/model/serialize/initialization.rb +2 -0
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/leptris/native_emission.rb +85 -3
- data/lib/lutaml/xml/leptris/plan_compiler.rb +190 -45
- data/lib/lutaml/xml/leptris/plan_hydrator.rb +209 -56
- data/lib/lutaml/xml/leptris/plan_serializer.rb +533 -102
- data/lib/lutaml/xml/leptris/plan_walk.rb +1 -0
- data/lib/lutaml/xml/schema/builder/moxml.rb +7 -3
- data/lib/lutaml/xml/transformation/order_reconciler.rb +4 -0
- data/lib/lutaml/xml/transformation/ordered_applier.rb +8 -7
- data/schema/lml/document.schema.json +179 -0
- data/scripts/lml/export_choices.rb +57 -0
- data/scripts/lml/export_conformance.rb +23 -0
- data/scripts/lml/export_mml.rb +253 -0
- data/scripts/lml/export_preservation.rb +421 -0
- data/scripts/lml/verify_artifacts.rb +31 -0
- data/spec/fixtures/lml_artifacts/model.json +1 -0
- data/spec/fixtures/lml_artifacts/valid.json +1 -0
- data/spec/fixtures/lml_artifacts/valid.sha256 +1 -0
- data/spec/fixtures/lml_conformance/core/index.json +1 -0
- data/spec/fixtures/lml_conformance/core/manifest.json +1 -0
- data/spec/fixtures/lml_conformance/core/schema.json +1 -0
- data/spec/fixtures/lml_conformance/core/schema.yaml +79 -0
- data/spec/fixtures/lml_conformance/float_vectors.generator.rb +60 -0
- data/spec/fixtures/lml_conformance/float_vectors.json +21550 -0
- data/spec/fixtures/lml_conformance/preservation/index.json +1 -0
- data/spec/fixtures/lml_conformance/preservation/manifest.json +1 -0
- data/spec/fixtures/lml_conformance/preservation/schema.json +1 -0
- data/spec/fixtures/lml_conformance/preservation/schema.yaml +319 -0
- data/spec/fixtures/lml_conformance/r2_refusals.generator.rb +153 -0
- data/spec/fixtures/lml_conformance/r2_refusals.json +1662 -0
- data/spec/fixtures/lml_conformance/ruby_portable_interop.generator.rb +40 -0
- data/spec/fixtures/lml_conformance/ruby_portable_interop.json +1 -0
- data/spec/fixtures/lml_contract/bundle.json +81 -0
- data/spec/fixtures/lml_contract/manifest.json +30 -0
- data/spec/fixtures/lml_contract/v1_unit.canonical.json +1 -0
- data/spec/fixtures/lml_contract/v1_unit.json +1 -0
- data/spec/fixtures/lml_contract/v2_node.canonical.json +1 -0
- data/spec/fixtures/lml_contract/v2_node.json +32 -0
- data/spec/fixtures/lml_mml/inventory.json +1 -0
- data/spec/fixtures/lml_mml/manifest.json +1 -0
- data/spec/fixtures/lml_mml/oracle.json +1 -0
- data/spec/fixtures/lml_mml/v3-mi-mixed.json +1 -0
- data/spec/fixtures/lml_mml/v3-mi-mixed.yaml +970 -0
- data/spec/fixtures/lml_mml/v4-mi-mixed.json +1 -0
- data/spec/fixtures/lml_mml/v4-mi-mixed.yaml +1516 -0
- data/spec/fixtures/lml_mml_materialization/replay.rb +37 -0
- data/spec/lutaml/model/lml_any_attribute_spec.rb +91 -0
- data/spec/lutaml/model/lml_artifact_verifier_spec.rb +86 -0
- data/spec/lutaml/model/lml_builtin_types_spec.rb +49 -0
- data/spec/lutaml/model/lml_conformance_spec.rb +178 -0
- data/spec/lutaml/model/lml_document_spec.rb +279 -0
- data/spec/lutaml/model/lml_export_validation_spec.rb +96 -0
- data/spec/lutaml/model/lml_exporter_spec.rb +127 -5
- data/spec/lutaml/model/lml_graph_exporter_spec.rb +205 -0
- data/spec/lutaml/model/lml_importer_spec.rb +290 -0
- data/spec/lutaml/model/lml_input_hardening_spec.rb +156 -0
- data/spec/lutaml/model/lml_mapping_compiler_spec.rb +256 -0
- data/spec/lutaml/model/lml_materialization_spec.rb +138 -0
- data/spec/lutaml/model/lml_mml_materialization_spec.rb +54 -0
- data/spec/lutaml/model/lml_mml_pilot_spec.rb +150 -0
- data/spec/lutaml/model/lml_model_choices_spec.rb +88 -0
- data/spec/lutaml/model/lml_ordered_content_spec.rb +243 -0
- data/spec/lutaml/model/lml_portable_json_spec.rb +310 -0
- data/spec/lutaml/model/lml_preservation_spec.rb +211 -0
- data/spec/lutaml/model/lml_review_export_spec.rb +247 -0
- data/spec/lutaml/model/lml_review_import_spec.rb +390 -0
- data/spec/lutaml/model/lml_review_misc_spec.rb +152 -0
- data/spec/lutaml/model/lml_review_round4_spec.rb +200 -0
- data/spec/lutaml/model/lml_review_round5_spec.rb +194 -0
- data/spec/lutaml/model/lml_ruby_interop_fixture_spec.rb +37 -0
- data/spec/lutaml/model/lml_shared_corpus_spec.rb +132 -0
- data/spec/lutaml/model/lml_value_declarations_spec.rb +128 -0
- data/spec/lutaml/model/schema/class_loader_spec.rb +51 -0
- data/spec/lutaml/model/schema/xml_compiler_runtime_spec.rb +20 -0
- data/spec/lutaml/model/sequence_spec.rb +48 -0
- data/spec/lutaml/xml/cdata_emission_spec.rb +68 -0
- data/spec/lutaml/xml/production_lane_parity_spec.rb +632 -0
- data/spec/support/lml_any_attribute_fixtures.rb +26 -0
- data/spec/support/lml_conformance.rb +292 -0
- data/spec/support/lml_corpus.rb +75 -0
- data/spec/support/lml_export_fixtures.rb +190 -0
- data/spec/support/lml_graph_fixtures.rb +108 -0
- data/spec/support/lml_import_fixtures.rb +52 -0
- data/spec/support/lml_mapping_fixtures.rb +170 -0
- data/spec/support/lml_materialization_fixtures.rb +53 -0
- data/spec/support/lml_model_choices_fixtures.rb +150 -0
- data/spec/support/lml_order_fixtures.rb +151 -0
- metadata +94 -3
- data/lib/lutaml/model/schema/schema_builder/nokogiri.rb +0 -41
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require "lutaml/store"
|
|
5
|
+
|
|
6
|
+
# Production-lane parity for shapes the XML plan lanes got wrong while a
|
|
7
|
+
# leaked adapter pin kept most of the suite off leptris: every example
|
|
8
|
+
# pins the leptris lane itself and asserts the interpretive writer's
|
|
9
|
+
# output, so the coverage does not depend on suite-wide lane integrity.
|
|
10
|
+
module ProductionLaneParitySpec
|
|
11
|
+
class TextElement < Lutaml::Model::Serializable
|
|
12
|
+
attribute :sup, :string
|
|
13
|
+
attribute :sub, :string
|
|
14
|
+
attribute :text, :string, collection: true
|
|
15
|
+
|
|
16
|
+
xml do
|
|
17
|
+
element "text-element"
|
|
18
|
+
|
|
19
|
+
map_content to: :text
|
|
20
|
+
|
|
21
|
+
map_element "sup", to: :sup
|
|
22
|
+
map_element "sub", to: :sub
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class DocidModel
|
|
27
|
+
attr_accessor :id, :prefix
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
class Docid < Lutaml::Model::Serializable
|
|
31
|
+
model DocidModel
|
|
32
|
+
attribute :id, TextElement
|
|
33
|
+
|
|
34
|
+
xml do
|
|
35
|
+
element "docid"
|
|
36
|
+
mixed_content
|
|
37
|
+
|
|
38
|
+
map_content to: :text, delegate: :id
|
|
39
|
+
map_element :sub, to: :sub, delegate: :id
|
|
40
|
+
map_element :sup, to: :sup, delegate: :id
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# elementFormDefault not set: local elements are in no namespace.
|
|
45
|
+
UnsetFormNs = Class.new(Lutaml::Xml::W3c::XmlNamespace) do
|
|
46
|
+
uri "http://example.com/production-lane/unset"
|
|
47
|
+
prefix_default "ex"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
class UnsetForm < Lutaml::Model::Serializable
|
|
51
|
+
attribute :a, :string
|
|
52
|
+
attribute :b, :string
|
|
53
|
+
|
|
54
|
+
xml do
|
|
55
|
+
element "unset"
|
|
56
|
+
namespace UnsetFormNs
|
|
57
|
+
map_element "a", to: :a
|
|
58
|
+
map_element "b", to: :b
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# elementFormDefault explicitly :unqualified: the root keeps the
|
|
63
|
+
# default-namespace format and locals spell bare.
|
|
64
|
+
UnqualifiedFormNs = Class.new(Lutaml::Xml::W3c::XmlNamespace) do
|
|
65
|
+
uri "http://example.com/production-lane/unqualified"
|
|
66
|
+
prefix_default "ex"
|
|
67
|
+
element_form_default :unqualified
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
class UnqualifiedForm < Lutaml::Model::Serializable
|
|
71
|
+
attribute :a, :string
|
|
72
|
+
|
|
73
|
+
xml do
|
|
74
|
+
element "unqualified"
|
|
75
|
+
namespace UnqualifiedFormNs
|
|
76
|
+
map_element "a", to: :a
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
QualifiedNs = Class.new(Lutaml::Xml::W3c::XmlNamespace) do
|
|
81
|
+
uri "http://example.com/production-lane/qualified"
|
|
82
|
+
prefix_default "ex"
|
|
83
|
+
element_form_default :qualified
|
|
84
|
+
attribute_form_default :qualified
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
class FormOverride < Lutaml::Model::Serializable
|
|
88
|
+
attribute :content, :string
|
|
89
|
+
|
|
90
|
+
xml do
|
|
91
|
+
element "override"
|
|
92
|
+
namespace QualifiedNs
|
|
93
|
+
map_element "content", to: :content, form: :unqualified
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
class BlankRule < Lutaml::Model::Serializable
|
|
98
|
+
attribute :note, :string
|
|
99
|
+
|
|
100
|
+
xml do
|
|
101
|
+
element "blank-rule"
|
|
102
|
+
namespace UnsetFormNs
|
|
103
|
+
map_element "note", to: :note, namespace: nil
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
class Declared < Lutaml::Model::Serializable
|
|
108
|
+
attribute :name, :string
|
|
109
|
+
|
|
110
|
+
xml do
|
|
111
|
+
element "declared"
|
|
112
|
+
map_element "name", to: :name
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
class Actual < Lutaml::Model::Serializable
|
|
117
|
+
attribute :different_name, :string
|
|
118
|
+
|
|
119
|
+
xml do
|
|
120
|
+
element "actual"
|
|
121
|
+
map_element "different-name", to: :different_name
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
class Holder < Lutaml::Model::Serializable
|
|
126
|
+
attribute :child, Declared
|
|
127
|
+
|
|
128
|
+
xml do
|
|
129
|
+
element "holder"
|
|
130
|
+
map_element "child", to: :child
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
class Vase < Lutaml::Model::Serializable
|
|
135
|
+
attribute :material, :string
|
|
136
|
+
attribute :height, :integer
|
|
137
|
+
|
|
138
|
+
xml do
|
|
139
|
+
element "Vase"
|
|
140
|
+
map_element "material", to: :material
|
|
141
|
+
map_element "height", to: :height
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
class Cached < Lutaml::Model::Serializable
|
|
146
|
+
attribute :name, :string
|
|
147
|
+
|
|
148
|
+
xml do
|
|
149
|
+
element "cached"
|
|
150
|
+
map_element "name", to: :name
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
cache_conversions
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
class ExplicitNil < Lutaml::Model::Serializable
|
|
157
|
+
attribute :items, :string, collection: true
|
|
158
|
+
|
|
159
|
+
xml do
|
|
160
|
+
element "explicit-nil"
|
|
161
|
+
map_element "items", to: :items, render_nil: :as_nil
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
class ExplicitBlank < Lutaml::Model::Serializable
|
|
166
|
+
attribute :items, :string, collection: true
|
|
167
|
+
|
|
168
|
+
xml do
|
|
169
|
+
element "explicit-blank"
|
|
170
|
+
map_element "items", to: :items, render_empty: :as_blank
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
class NilScalar < Lutaml::Model::Serializable
|
|
175
|
+
attribute :name, :string, default: "Unnamed"
|
|
176
|
+
|
|
177
|
+
xml do
|
|
178
|
+
element "nil-scalar"
|
|
179
|
+
map_element "name", to: :name, render_nil: true
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
class Pushed < Lutaml::Model::Serializable
|
|
184
|
+
attribute :lead, :string
|
|
185
|
+
attribute :items, :string, collection: true, default: -> { [] }
|
|
186
|
+
|
|
187
|
+
xml do
|
|
188
|
+
element "pushed"
|
|
189
|
+
ordered
|
|
190
|
+
map_element "lead", to: :lead
|
|
191
|
+
map_element "item", to: :items
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
class Nilled < Lutaml::Model::Serializable
|
|
196
|
+
attribute :lead, :string
|
|
197
|
+
attribute :items, :string, collection: true
|
|
198
|
+
|
|
199
|
+
xml do
|
|
200
|
+
element "nilled"
|
|
201
|
+
ordered
|
|
202
|
+
map_element "lead", to: :lead
|
|
203
|
+
map_element "item", to: :items, render_nil: :as_nil
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
class OrderedBlank < Lutaml::Model::Serializable
|
|
208
|
+
attribute :authority, :string
|
|
209
|
+
attribute :topic, :string, collection: true
|
|
210
|
+
|
|
211
|
+
xml do
|
|
212
|
+
element "subject"
|
|
213
|
+
ordered
|
|
214
|
+
map_attribute "authority", to: :authority
|
|
215
|
+
map_element "topic", to: :topic, render_empty: :as_nil
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
class ReservedPrefix < Lutaml::Model::Serializable
|
|
220
|
+
attribute :lang, :string
|
|
221
|
+
|
|
222
|
+
xml do
|
|
223
|
+
element "reserved"
|
|
224
|
+
map_attribute "xml:lang", to: :lang
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
class ForeignOrder < Lutaml::Model::Serializable
|
|
229
|
+
attribute :lead, :string
|
|
230
|
+
|
|
231
|
+
xml do
|
|
232
|
+
element "foreign"
|
|
233
|
+
ordered
|
|
234
|
+
map_element "lead", to: :lead
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
class Hashed < Lutaml::Model::Serializable
|
|
239
|
+
attribute :h, :hash
|
|
240
|
+
|
|
241
|
+
xml do
|
|
242
|
+
element "hashed"
|
|
243
|
+
map_element "h", to: :h
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
class OverCount < Lutaml::Model::Serializable
|
|
248
|
+
attribute :name, :string
|
|
249
|
+
|
|
250
|
+
xml do
|
|
251
|
+
element "over-count"
|
|
252
|
+
map_element "name", to: :name
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
class HookedType < Lutaml::Model::Type::Value
|
|
257
|
+
def self.from_xml(_value)
|
|
258
|
+
"from_xml_hooked"
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
def to_xml
|
|
262
|
+
"to_xml_hooked"
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
class Hooked < Lutaml::Model::Serializable
|
|
267
|
+
attribute :value, HookedType
|
|
268
|
+
attribute :attr, HookedType
|
|
269
|
+
|
|
270
|
+
xml do
|
|
271
|
+
element "hooked"
|
|
272
|
+
map_element "value", to: :value
|
|
273
|
+
map_attribute "attr", to: :attr
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
class RefBase < Lutaml::Model::Serializable
|
|
278
|
+
attribute :name, :string
|
|
279
|
+
|
|
280
|
+
xml do
|
|
281
|
+
map_element "name", to: :name
|
|
282
|
+
end
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
class DocRef < RefBase
|
|
286
|
+
attribute :_class, :string
|
|
287
|
+
attribute :document_id, :string
|
|
288
|
+
|
|
289
|
+
xml do
|
|
290
|
+
map_element "document_id", to: :document_id
|
|
291
|
+
map_attribute "_class", to: :_class
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
class RefSet < Lutaml::Model::Serializable
|
|
296
|
+
attribute :references, RefBase, collection: true, polymorphic: [DocRef]
|
|
297
|
+
|
|
298
|
+
xml do
|
|
299
|
+
element "refset"
|
|
300
|
+
map_element "references", to: :references, polymorphic: {
|
|
301
|
+
attribute: "_class",
|
|
302
|
+
class_map: { "document-ref" => "ProductionLaneParitySpec::DocRef" },
|
|
303
|
+
}
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
class Animal < Lutaml::Model::Serializable
|
|
308
|
+
attribute :type, :string
|
|
309
|
+
attribute :name, :string
|
|
310
|
+
|
|
311
|
+
xml do
|
|
312
|
+
element "animal"
|
|
313
|
+
map_attribute "type", to: :type
|
|
314
|
+
map_element "name", to: :name
|
|
315
|
+
end
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
class Dog < Animal
|
|
319
|
+
attribute :breed, :string
|
|
320
|
+
|
|
321
|
+
xml do
|
|
322
|
+
map_element "breed", to: :breed
|
|
323
|
+
end
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
class Zoo < Lutaml::Model::Collection
|
|
327
|
+
instances :animals, Animal, polymorphic: true
|
|
328
|
+
|
|
329
|
+
xml do
|
|
330
|
+
element "zoo"
|
|
331
|
+
map_element "animal", to: :animals, polymorphic: {
|
|
332
|
+
attribute: "type",
|
|
333
|
+
class_map: { "dog" => "ProductionLaneParitySpec::Dog" },
|
|
334
|
+
}
|
|
335
|
+
end
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
class Omitted < Lutaml::Model::Serializable
|
|
339
|
+
attribute :as_nil, :string
|
|
340
|
+
attribute :as_empty, :string
|
|
341
|
+
|
|
342
|
+
xml do
|
|
343
|
+
element "omitted"
|
|
344
|
+
map_element "as_nil", to: :as_nil, value_map: { to: { omitted: :nil } }
|
|
345
|
+
map_element "as_empty", to: :as_empty,
|
|
346
|
+
value_map: { from: { omitted: :empty } }
|
|
347
|
+
end
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
class Imported < Lutaml::Model::Serializable
|
|
351
|
+
attribute :shout, :string
|
|
352
|
+
|
|
353
|
+
xml do
|
|
354
|
+
element "imported"
|
|
355
|
+
map_element "shout", to: :shout,
|
|
356
|
+
transform: { import: ->(v) { v.to_s.upcase } }
|
|
357
|
+
end
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
class LateBound < Lutaml::Model::Serializable
|
|
361
|
+
attribute :name, :string
|
|
362
|
+
|
|
363
|
+
xml do
|
|
364
|
+
element "late"
|
|
365
|
+
map_element "name", to: :name
|
|
366
|
+
end
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
class TypeOnly < Lutaml::Model::Serializable
|
|
370
|
+
attribute :type, :string
|
|
371
|
+
|
|
372
|
+
xml do
|
|
373
|
+
map_element "type", to: :type
|
|
374
|
+
end
|
|
375
|
+
end
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
RSpec.describe "production-lane parity" do
|
|
379
|
+
around do |example|
|
|
380
|
+
previous = Lutaml::Model::Config.xml_adapter_type
|
|
381
|
+
fixed = previous == Lutaml::Model::FIXED_ADAPTER_TYPE
|
|
382
|
+
previous_adapter = Lutaml::Model::Config.xml_adapter if fixed
|
|
383
|
+
Lutaml::Model::Config.xml_adapter_type = :leptris
|
|
384
|
+
example.run
|
|
385
|
+
ensure
|
|
386
|
+
if fixed
|
|
387
|
+
Lutaml::Model::Config.xml_adapter = previous_adapter
|
|
388
|
+
elsif previous
|
|
389
|
+
Lutaml::Model::Config.xml_adapter_type = previous
|
|
390
|
+
else
|
|
391
|
+
Lutaml::Model::Config.unset_xml_adapter_type
|
|
392
|
+
end
|
|
393
|
+
end
|
|
394
|
+
|
|
395
|
+
it "round-trips rules delegated to a mapped child" do
|
|
396
|
+
xml = "<docid>Str<sub>2</sub>text<sup>1</sup>123</docid>"
|
|
397
|
+
docid = ProductionLaneParitySpec::Docid.from_xml(xml)
|
|
398
|
+
|
|
399
|
+
expect(ProductionLaneParitySpec::Docid.to_xml(docid)).to be_xml_equivalent_to(xml)
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
describe "elementFormDefault" do
|
|
403
|
+
it "opts form-not-set locals out of the default namespace" do
|
|
404
|
+
model = ProductionLaneParitySpec::UnsetForm.new(a: "1", b: "2")
|
|
405
|
+
|
|
406
|
+
expect(model.to_xml).to include('<unset xmlns="http://example.com/production-lane/unset">')
|
|
407
|
+
expect(model.to_xml).to include('<a xmlns="">1</a>', '<b xmlns="">2</b>')
|
|
408
|
+
expect(model.to_xml(pretty: true)).to include('<a xmlns="">1</a>', "<b>2</b>")
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
it "keeps the default-namespace root and bare locals under an explicit :unqualified form" do
|
|
412
|
+
model = ProductionLaneParitySpec::UnqualifiedForm.new(a: "1")
|
|
413
|
+
xml = model.to_xml
|
|
414
|
+
|
|
415
|
+
expect(xml).to include('<unqualified xmlns="http://example.com/production-lane/unqualified">')
|
|
416
|
+
expect(xml).to include("<a>1</a>")
|
|
417
|
+
expect(xml).not_to include("xmlns=\"\"", "<ex:a")
|
|
418
|
+
end
|
|
419
|
+
|
|
420
|
+
it "spells a form: :unqualified rule bare under a qualified namespace" do
|
|
421
|
+
model = ProductionLaneParitySpec::FormOverride.new(content: "x")
|
|
422
|
+
|
|
423
|
+
expect(model.to_xml).to include("<content>x</content>")
|
|
424
|
+
expect(model.to_xml).not_to include("<ex:content")
|
|
425
|
+
end
|
|
426
|
+
|
|
427
|
+
it "opts a namespace: nil rule out of the default namespace" do
|
|
428
|
+
model = ProductionLaneParitySpec::BlankRule.new(note: "n")
|
|
429
|
+
|
|
430
|
+
expect(model.to_xml).to include('<note xmlns="">n</note>')
|
|
431
|
+
end
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
it "serializes a nested value of another class through its own mapping" do
|
|
435
|
+
model = ProductionLaneParitySpec::Holder.new
|
|
436
|
+
model.child = ProductionLaneParitySpec::Actual.new(different_name: "x")
|
|
437
|
+
|
|
438
|
+
expect(model.to_xml).to include("<different-name>x</different-name>")
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
it "never declares the reserved xml prefix" do
|
|
442
|
+
model = ProductionLaneParitySpec::ReservedPrefix.new(lang: "en")
|
|
443
|
+
|
|
444
|
+
expect(model.to_xml).to include('xml:lang="en"')
|
|
445
|
+
expect(model.to_xml).not_to include("xmlns:xml=")
|
|
446
|
+
end
|
|
447
|
+
|
|
448
|
+
it "generates schemas in the Nokogiri wrapper's byte shape" do
|
|
449
|
+
nokogiri = Lutaml::Xml::Schema::XsdSchema.generate(ProductionLaneParitySpec::Vase,
|
|
450
|
+
pretty: true, adapter: :nokogiri)
|
|
451
|
+
leptris = Lutaml::Xml::Schema::XsdSchema.generate(ProductionLaneParitySpec::Vase,
|
|
452
|
+
pretty: true, adapter: :leptris)
|
|
453
|
+
|
|
454
|
+
expect(leptris).to eq(nokogiri)
|
|
455
|
+
end
|
|
456
|
+
|
|
457
|
+
describe "render policies" do
|
|
458
|
+
it "renders an explicit nil element" do
|
|
459
|
+
model = ProductionLaneParitySpec::ExplicitNil.new(items: nil)
|
|
460
|
+
|
|
461
|
+
expect(model.to_xml).to include('<items xsi:nil="true"/>')
|
|
462
|
+
end
|
|
463
|
+
|
|
464
|
+
it "renders a blank element for an empty collection" do
|
|
465
|
+
model = ProductionLaneParitySpec::ExplicitBlank.new(items: [])
|
|
466
|
+
|
|
467
|
+
expect(model.to_xml).to include("<items/>")
|
|
468
|
+
end
|
|
469
|
+
|
|
470
|
+
it "binds an xsi:nil element as an empty collection" do
|
|
471
|
+
parsed = ProductionLaneParitySpec::ExplicitNil
|
|
472
|
+
.from_xml('<explicit-nil><items xsi:nil="true"/></explicit-nil>')
|
|
473
|
+
|
|
474
|
+
expect(parsed.items).to eq([])
|
|
475
|
+
end
|
|
476
|
+
|
|
477
|
+
it "binds an xsi:nil element as a nil scalar" do
|
|
478
|
+
parsed = ProductionLaneParitySpec::NilScalar
|
|
479
|
+
.from_xml('<nil-scalar><name xsi:nil="true"/></nil-scalar>')
|
|
480
|
+
|
|
481
|
+
expect(parsed.name).to be_nil
|
|
482
|
+
end
|
|
483
|
+
|
|
484
|
+
it "renders the nil element of a parsed ordered model" do
|
|
485
|
+
xml = '<subject authority="lcsh"><topic xsi:nil="true"/></subject>'
|
|
486
|
+
parsed = ProductionLaneParitySpec::OrderedBlank.from_xml(xml)
|
|
487
|
+
|
|
488
|
+
expect(parsed.to_xml).to include('<topic xsi:nil="true"/>')
|
|
489
|
+
end
|
|
490
|
+
end
|
|
491
|
+
|
|
492
|
+
describe "parsed-model mutation" do
|
|
493
|
+
it "emits an item pushed onto a default collection after parse" do
|
|
494
|
+
model = ProductionLaneParitySpec::Pushed.from_xml("<pushed><lead>L</lead></pushed>")
|
|
495
|
+
model.items << "y"
|
|
496
|
+
|
|
497
|
+
expect(model.to_xml).to include("<item>y</item>")
|
|
498
|
+
end
|
|
499
|
+
|
|
500
|
+
it "renders a collection set to nil after parse when the element was present" do
|
|
501
|
+
model = ProductionLaneParitySpec::Nilled.from_xml("<nilled><lead>L</lead><item>x</item></nilled>")
|
|
502
|
+
model.items = nil
|
|
503
|
+
|
|
504
|
+
expect(model.to_xml).to include('xsi:nil="true"')
|
|
505
|
+
end
|
|
506
|
+
|
|
507
|
+
it "emits nothing when the element was absent" do
|
|
508
|
+
model = ProductionLaneParitySpec::Nilled.from_xml("<nilled><lead>L</lead></nilled>")
|
|
509
|
+
model.items = nil
|
|
510
|
+
|
|
511
|
+
expect(model.to_xml).not_to include("<item")
|
|
512
|
+
end
|
|
513
|
+
|
|
514
|
+
it "skips foreign entries in element_order" do
|
|
515
|
+
model = ProductionLaneParitySpec::ForeignOrder.from_xml("<foreign><lead>L</lead></foreign>")
|
|
516
|
+
model.element_order = model.element_order.dup << 42
|
|
517
|
+
|
|
518
|
+
expect { model.to_xml }.not_to raise_error
|
|
519
|
+
expect(model.to_xml).to include("<lead>L</lead>")
|
|
520
|
+
end
|
|
521
|
+
end
|
|
522
|
+
|
|
523
|
+
it "expands a Hash-typed element into child elements and reads it back" do
|
|
524
|
+
xml = "<hashed><h><key>value</key></h></hashed>"
|
|
525
|
+
expect(ProductionLaneParitySpec::Hashed.new(h: { key: "value" }).to_xml)
|
|
526
|
+
.to be_xml_equivalent_to(xml)
|
|
527
|
+
expect(ProductionLaneParitySpec::Hashed.from_xml(xml).h).to eq("key" => "value")
|
|
528
|
+
end
|
|
529
|
+
|
|
530
|
+
it "keeps an over-count for a singular attribute so validate reports it" do
|
|
531
|
+
obj = ProductionLaneParitySpec::OverCount.from_xml(
|
|
532
|
+
"<over-count><name>A</name><name>B</name></over-count>",
|
|
533
|
+
)
|
|
534
|
+
|
|
535
|
+
expect(obj.name).to eq(%w[A B])
|
|
536
|
+
expect(obj.validate).to include(an_instance_of(Lutaml::Model::CollectionTrueMissingError))
|
|
537
|
+
end
|
|
538
|
+
|
|
539
|
+
it "spells a Value type's own XML hooks" do
|
|
540
|
+
model = ProductionLaneParitySpec::Hooked.new(value: "x", attr: "y")
|
|
541
|
+
|
|
542
|
+
expect(model.to_xml).to include("<value>to_xml_hooked</value>", 'attr="to_xml_hooked"')
|
|
543
|
+
parsed = ProductionLaneParitySpec::Hooked.from_xml("<hooked attr=\"v\"><value>v</value></hooked>")
|
|
544
|
+
expect(parsed.value).to eq("from_xml_hooked")
|
|
545
|
+
expect(parsed.attr).to eq("from_xml_hooked")
|
|
546
|
+
end
|
|
547
|
+
|
|
548
|
+
it "resolves a polymorphic class map on deferred rows" do
|
|
549
|
+
xml = '<refset><references _class="document-ref"><name>n</name>' \
|
|
550
|
+
"<document_id>d</document_id></references></refset>"
|
|
551
|
+
parsed = ProductionLaneParitySpec::RefSet.from_xml(xml)
|
|
552
|
+
|
|
553
|
+
expect(parsed.references.first).to be_a(ProductionLaneParitySpec::DocRef)
|
|
554
|
+
expect(ProductionLaneParitySpec::RefSet.to_xml(parsed)).to be_xml_equivalent_to(xml)
|
|
555
|
+
end
|
|
556
|
+
|
|
557
|
+
it "resolves a polymorphic Collection's instances by their class map" do
|
|
558
|
+
zoo = ProductionLaneParitySpec::Zoo.from_xml(
|
|
559
|
+
'<zoo><animal type="dog"><name>Fido</name><breed>Lab</breed></animal></zoo>',
|
|
560
|
+
)
|
|
561
|
+
|
|
562
|
+
expect(zoo.animals.first).to be_a(ProductionLaneParitySpec::Dog)
|
|
563
|
+
expect(zoo.animals.first.breed).to eq("Lab")
|
|
564
|
+
end
|
|
565
|
+
|
|
566
|
+
it "renders an uninitialized value under its value_map and binds an omitted one" do
|
|
567
|
+
# An uninitialized value is decided by its value_map's :omitted key:
|
|
568
|
+
# :nil renders the xsi:nil element.
|
|
569
|
+
model = ProductionLaneParitySpec::Omitted.new({}, { omitted: :omitted })
|
|
570
|
+
|
|
571
|
+
expect(model.to_xml).to include('as_nil xsi:nil="true"')
|
|
572
|
+
expect(ProductionLaneParitySpec::Omitted.from_xml("<omitted/>").as_empty).to eq("")
|
|
573
|
+
end
|
|
574
|
+
|
|
575
|
+
it "applies a hash/proc import transform" do
|
|
576
|
+
parsed = ProductionLaneParitySpec::Imported.from_xml("<imported><shout>soft</shout></imported>")
|
|
577
|
+
|
|
578
|
+
expect(parsed.shout).to eq("SOFT")
|
|
579
|
+
end
|
|
580
|
+
|
|
581
|
+
it "follows an attribute and mapping added after the first parse" do
|
|
582
|
+
klass = ProductionLaneParitySpec::LateBound
|
|
583
|
+
klass.from_xml("<late><name>initial</name></late>")
|
|
584
|
+
klass.class_eval do
|
|
585
|
+
attribute :extra, :string
|
|
586
|
+
|
|
587
|
+
xml do
|
|
588
|
+
map_element "extra", to: :extra
|
|
589
|
+
end
|
|
590
|
+
end
|
|
591
|
+
parsed = klass.from_xml("<late><name>hello</name><extra>world</extra></late>")
|
|
592
|
+
|
|
593
|
+
expect(parsed.name).to eq("hello")
|
|
594
|
+
expect(parsed.extra).to eq("world")
|
|
595
|
+
end
|
|
596
|
+
|
|
597
|
+
it "leaves the encoding option and a type-only model's error to the standard pipeline" do
|
|
598
|
+
expect { ProductionLaneParitySpec::ForeignOrder.new(lead: "L").to_xml(encoding: "ABC") }
|
|
599
|
+
.to raise_error(StandardError, /ABC/)
|
|
600
|
+
expect { ProductionLaneParitySpec::TypeOnly.from_xml("<type>Data</type>") }
|
|
601
|
+
.to raise_error(Lutaml::Model::TypeOnlyMappingError)
|
|
602
|
+
end
|
|
603
|
+
|
|
604
|
+
describe "conversion caching" do
|
|
605
|
+
let(:store) { Lutaml::Store::BasicStore.new(adapter: { type: :memory }) }
|
|
606
|
+
|
|
607
|
+
around do |example|
|
|
608
|
+
previous = Lutaml::Model::Config.conversion_cache
|
|
609
|
+
Lutaml::Model::Config.conversion_cache = store
|
|
610
|
+
example.run
|
|
611
|
+
ensure
|
|
612
|
+
Lutaml::Model::Config.conversion_cache = previous
|
|
613
|
+
end
|
|
614
|
+
|
|
615
|
+
it "serves repeated XML serialization from the store" do
|
|
616
|
+
instance = ProductionLaneParitySpec::Cached.new(name: "a")
|
|
617
|
+
instance.to_xml
|
|
618
|
+
expect(store.size).to eq(1)
|
|
619
|
+
store.each_key { |key| store.set(key, "<sentinel/>") }
|
|
620
|
+
|
|
621
|
+
expect(instance.to_xml).to eq("<sentinel/>")
|
|
622
|
+
end
|
|
623
|
+
|
|
624
|
+
it "serves repeated XML parsing from the store" do
|
|
625
|
+
xml = "<cached><name>a</name></cached>"
|
|
626
|
+
first = ProductionLaneParitySpec::Cached.from_xml(xml)
|
|
627
|
+
expect(store.size).to eq(1)
|
|
628
|
+
|
|
629
|
+
expect(ProductionLaneParitySpec::Cached.from_xml(xml)).to equal(first)
|
|
630
|
+
end
|
|
631
|
+
end
|
|
632
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "lutaml/model"
|
|
4
|
+
|
|
5
|
+
# Named fixtures for LML any_attribute (map_all_attributes) specs.
|
|
6
|
+
module LmlAnyAttributeFixtures
|
|
7
|
+
class Tag < Lutaml::Model::Serializable
|
|
8
|
+
attribute :id, :string
|
|
9
|
+
attribute :other_attributes, :hash
|
|
10
|
+
|
|
11
|
+
xml do
|
|
12
|
+
element "tag"
|
|
13
|
+
map_attribute "id", to: :id
|
|
14
|
+
map_all_attributes to: :other_attributes
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class Filtered < Lutaml::Model::Serializable
|
|
19
|
+
attribute :other_attributes, :hash
|
|
20
|
+
|
|
21
|
+
xml do
|
|
22
|
+
element "filtered"
|
|
23
|
+
map_all_attributes to: :other_attributes, matching: /\Adata-/
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|