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,128 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "lutaml/model/lml"
|
|
4
|
+
|
|
5
|
+
module LmlValueDeclarationFixtures
|
|
6
|
+
class Code < Lutaml::Model::Type::String
|
|
7
|
+
VALUES = %w[a b].freeze
|
|
8
|
+
|
|
9
|
+
def self.cast(value, options = {})
|
|
10
|
+
return if value.nil?
|
|
11
|
+
|
|
12
|
+
super(value, options.dup.tap { |copy| copy[:values] ||= VALUES })
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class QualifiedNamespace < Lutaml::Xml::Namespace
|
|
17
|
+
uri "urn:declared-values"
|
|
18
|
+
prefix_default "d"
|
|
19
|
+
attribute_form_default :qualified
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class QualifiedModel < Lutaml::Model::Serializable
|
|
23
|
+
attribute :code, Code
|
|
24
|
+
xml do
|
|
25
|
+
root "qualified"
|
|
26
|
+
namespace QualifiedNamespace
|
|
27
|
+
map_attribute "code", to: :code
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
class Model < Lutaml::Model::Serializable
|
|
32
|
+
choice(min: 1, max: 1) do
|
|
33
|
+
attribute :code, Code, default: "a"
|
|
34
|
+
attribute :other, :string
|
|
35
|
+
end
|
|
36
|
+
json do
|
|
37
|
+
map "code", to: :code
|
|
38
|
+
map "other", to: :other
|
|
39
|
+
end
|
|
40
|
+
xml do
|
|
41
|
+
root "declared"
|
|
42
|
+
map_element "code", to: :code
|
|
43
|
+
map_element "other", to: :other
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
RSpec.describe Lutaml::Model::Lml::ValueDeclarations do
|
|
49
|
+
let(:source) { LmlValueDeclarationFixtures::Model }
|
|
50
|
+
let(:scalar) { LmlValueDeclarationFixtures::Code }
|
|
51
|
+
let(:definition) { { "base" => "string", "facets" => { "enumeration" => %w[a b] } } }
|
|
52
|
+
let(:registry) { described_class.new({ scalar => definition }) }
|
|
53
|
+
let(:lml) { Lutaml::Model::Lml }
|
|
54
|
+
|
|
55
|
+
it "keeps arbitrary named casters refused without explicit declarations" do
|
|
56
|
+
expect { lml.export_bundle(source) }.to raise_error(lml::RejectedError) { |error| expect(error.reason).to eq(:unsupported_type) }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "exports named identity, declared facets, defaults and choices without flattening" do
|
|
60
|
+
tree = lml.export_bundle(source, value_declarations: registry).to_h
|
|
61
|
+
id = "#{scalar.name}@default"
|
|
62
|
+
expect(tree.fetch("value_types")).to eq(id => definition)
|
|
63
|
+
model = tree.fetch("models").values.first
|
|
64
|
+
expect(model.fetch("attributes").first.fetch("type")).to eq("kind" => "value", "id" => id)
|
|
65
|
+
expect(model.fetch("attributes").first.fetch("default")).to eq("present" => true, "value" => "a")
|
|
66
|
+
expect(model.fetch("choices").fetch("validation")).to eq("explicit")
|
|
67
|
+
expect(lml::Importer.bundle(tree).to_h).to eq(tree)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "requires native bindings and preserves their source reader and validation behavior" do
|
|
71
|
+
bundle = lml.export_bundle(source, value_declarations: registry)
|
|
72
|
+
expect { lml.import_bundle(bundle) }.to raise_error(lml::RejectedError) { |error| expect(error.reason).to eq(:missing_type_binding) }
|
|
73
|
+
imported = lml.import_bundle(bundle, type_bindings: { "#{scalar.name}@default" => scalar }).fetch("#{source.name}@default")
|
|
74
|
+
[{ code: "a" }, { code: "b" }, { code: "a", other: "x" }].each do |input|
|
|
75
|
+
original = source.new(input)
|
|
76
|
+
actual = imported.new(input)
|
|
77
|
+
expect(actual.to_json).to eq(original.to_json)
|
|
78
|
+
expect(actual.to_xml).to eq(original.to_xml)
|
|
79
|
+
expect(actual.validate.map(&:class)).to eq(original.validate.map(&:class))
|
|
80
|
+
end
|
|
81
|
+
expect { imported.from_json('{"code":"unknown"}') }.to raise_error(Lutaml::Model::Type::InvalidValueError)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "preserves qualified attribute namespaces while importing declared scalar models" do
|
|
85
|
+
original_class = LmlValueDeclarationFixtures::QualifiedModel
|
|
86
|
+
bundle = lml.export_bundle(original_class, value_declarations: registry)
|
|
87
|
+
rule = bundle.models.values.first.fetch("mappings").fetch("xml").fetch("rules").first
|
|
88
|
+
expect(rule.fetch("namespace")).to eq("mode" => "uri", "uri" => "urn:declared-values", "prefix" => "d")
|
|
89
|
+
imported = lml.import_bundle(bundle, type_bindings: { "#{scalar.name}@default" => scalar }).fetch("#{original_class.name}@default")
|
|
90
|
+
original = original_class.new(code: "a").to_xml(prefix: true)
|
|
91
|
+
expect(imported.from_xml(original).to_xml(prefix: true)).to eq(original)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "treats facet payloads as data rather than model references" do
|
|
95
|
+
definition.fetch("facets")["opaque_payload"] = { "kind" => "model", "id" => "Missing@default" }
|
|
96
|
+
tree = lml.export_bundle(source, value_declarations: registry).to_h
|
|
97
|
+
expect(tree.fetch("models").keys).to eq(["#{source.name}@default"])
|
|
98
|
+
expect(tree.fetch("value_types").values.first.fetch("facets").fetch("opaque_payload")).to eq("kind" => "model", "id" => "Missing@default")
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "uses exact source class identity rather than names or inherited behavior" do
|
|
102
|
+
expect(registry.fetch(scalar.name)).to be_nil
|
|
103
|
+
subclass = Class.new(scalar)
|
|
104
|
+
stub_const("LmlUnregisteredCode", subclass)
|
|
105
|
+
expect(registry.fetch(subclass)).to be_nil
|
|
106
|
+
expect { described_class.new({ scalar.name => definition }) }.to raise_error(lml::RejectedError)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it "freezes a private data copy without freezing the caller's declarations" do
|
|
110
|
+
item = described_class.new({ scalar => definition })
|
|
111
|
+
definition.fetch("facets").fetch("enumeration") << "c"
|
|
112
|
+
expect(item.fetch(scalar).fetch("facets").fetch("enumeration")).to eq(%w[a b])
|
|
113
|
+
expect(item.fetch(scalar)).to be_frozen
|
|
114
|
+
expect(item.to_h.fetch("version")).to eq(1)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "refuses unsupported registry versions and executable metadata" do
|
|
118
|
+
expect { described_class.new({ scalar => definition }, version: 2) }.to raise_error(lml::RejectedError) { |error| expect(error.reason).to eq(:unsupported_version) }
|
|
119
|
+
invoked = false
|
|
120
|
+
definition["facets"]["callback"] = -> { invoked = true }
|
|
121
|
+
expect { described_class.new({ scalar => definition }) }.to raise_error(lml::RejectedError) { |error| expect(error.reason).to eq(:invalid_document) }
|
|
122
|
+
expect(invoked).to be(false)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it "refuses unvalidated raw registries at the public exporter boundary" do
|
|
126
|
+
expect { lml.export_bundle(source, value_declarations: { scalar => definition }) }.to raise_error(ArgumentError, /ValueDeclarations/)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require "lutaml/model/schema"
|
|
5
|
+
|
|
6
|
+
RSpec.describe Lutaml::Model::Schema::ClassLoader do
|
|
7
|
+
let(:definition) do
|
|
8
|
+
Lutaml::Model::Schema::Definitions::Model.new(
|
|
9
|
+
class_name: "Entry",
|
|
10
|
+
xml_root: Lutaml::Model::Schema::Definitions::XmlRoot.new(
|
|
11
|
+
kind: :element, name: "entry",
|
|
12
|
+
),
|
|
13
|
+
)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
let(:entry) do
|
|
17
|
+
Lutaml::Model::Schema::CompiledOutput::Entry.new(
|
|
18
|
+
"Entry", definition, :model
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "loads generated classes from a nested namespace directory" do
|
|
23
|
+
stub_const("ClassLoaderRegression", Module.new)
|
|
24
|
+
|
|
25
|
+
output = Lutaml::Model::Schema::CompiledOutput.new(
|
|
26
|
+
entries: [entry],
|
|
27
|
+
module_namespace: "ClassLoaderRegression::Nested",
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
expect { described_class.load(output) }.not_to raise_error
|
|
31
|
+
|
|
32
|
+
expect(ClassLoaderRegression::Nested::Entry.ancestors)
|
|
33
|
+
.to include(Lutaml::Model::Serialize::ClassMethods)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "keeps single-level namespace autoloads working" do
|
|
37
|
+
registry = Lutaml::Model::Schema::RegistryGenerator.generate(
|
|
38
|
+
[entry], module_namespace: "SingleLevel"
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
expect(registry).to include('File.join(__dir__, "singlelevel", "entry")')
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "keeps flat class output free of a registry namespace" do
|
|
45
|
+
registry = Lutaml::Model::Schema::RegistryGenerator.generate(
|
|
46
|
+
[entry], module_namespace: nil
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
expect(registry).to be_nil
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -52,6 +52,26 @@ RSpec.describe "runtime XSD class loading" do
|
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
+
# `use="required"` on an xs:attribute compiles to a required model
|
|
56
|
+
# attribute, so an instance the schema forbids fails validation.
|
|
57
|
+
it "carries use=\"required\" through to the generated attribute" do
|
|
58
|
+
Dir.mktmpdir do |dir|
|
|
59
|
+
Lutaml::Model::Schema.from_xml(
|
|
60
|
+
xsd, output_dir: File.join(dir, "required_attribute_models"),
|
|
61
|
+
load_classes: true
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
expect(RequiredAttributeModels::EntryType.attributes[:id].options[:required])
|
|
65
|
+
.to be true
|
|
66
|
+
|
|
67
|
+
missing = RequiredAttributeModels::EntryType.from_xml(
|
|
68
|
+
"<entry><name>Alpha</name><year>2024</year></entry>",
|
|
69
|
+
)
|
|
70
|
+
expect { missing.validate! }
|
|
71
|
+
.to raise_error(Lutaml::Model::ValidationError, /id/)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
55
75
|
# Anonymous (inline) complexTypes get CT_-prefixed internal names;
|
|
56
76
|
# the generated classes must still (a) map skippable XSD built-ins
|
|
57
77
|
# like xs:int to Lutaml primitives and (b) serialize the owning
|
|
@@ -396,6 +396,54 @@ RSpec.describe "Sequence" do
|
|
|
396
396
|
end
|
|
397
397
|
let(:klass) { SequenceSpec::CeramicRestricted }
|
|
398
398
|
|
|
399
|
+
# An optional scalar member (XSD minOccurs="0", maxOccurs="1") may be
|
|
400
|
+
# absent: the sequence validator skips it and continues with the next
|
|
401
|
+
# member instead of reporting the element that follows as out of order.
|
|
402
|
+
context "with an optional scalar member between required ones" do
|
|
403
|
+
let(:model) do
|
|
404
|
+
Class.new(Lutaml::Model::Serializable) do
|
|
405
|
+
attribute :title, :string, required: true
|
|
406
|
+
attribute :note, :string
|
|
407
|
+
attribute :meta, :string
|
|
408
|
+
attribute :items, :string, collection: 0..Float::INFINITY
|
|
409
|
+
|
|
410
|
+
xml do
|
|
411
|
+
element "Doc"
|
|
412
|
+
sequence do
|
|
413
|
+
map_element :title, to: :title
|
|
414
|
+
map_element :note, to: :note
|
|
415
|
+
map_element :meta, to: :meta
|
|
416
|
+
map_element :items, to: :items
|
|
417
|
+
end
|
|
418
|
+
end
|
|
419
|
+
end
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
it "accepts an instance that omits the optional member" do
|
|
423
|
+
instance = model.from_xml("<Doc><title>t</title><meta>m</meta></Doc>")
|
|
424
|
+
expect { instance.validate! }.not_to raise_error
|
|
425
|
+
end
|
|
426
|
+
|
|
427
|
+
it "accepts an instance that omits the optional member before a collection" do
|
|
428
|
+
instance = model.from_xml(
|
|
429
|
+
"<Doc><title>t</title><items>a</items><items>b</items></Doc>",
|
|
430
|
+
)
|
|
431
|
+
expect { instance.validate! }.not_to raise_error
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
it "still rejects a member that is out of order" do
|
|
435
|
+
instance = model.from_xml("<Doc><meta>m</meta><title>t</title></Doc>")
|
|
436
|
+
expect { instance.validate! }
|
|
437
|
+
.to raise_error(Lutaml::Model::ValidationError, /title/)
|
|
438
|
+
end
|
|
439
|
+
|
|
440
|
+
it "still rejects a missing required member" do
|
|
441
|
+
instance = model.from_xml("<Doc><note>n</note></Doc>")
|
|
442
|
+
expect { instance.validate! }
|
|
443
|
+
.to raise_error(Lutaml::Model::ValidationError, /title/)
|
|
444
|
+
end
|
|
445
|
+
end
|
|
446
|
+
|
|
399
447
|
it "does not raise for correct order" do
|
|
400
448
|
expect do
|
|
401
449
|
sequence.validate_content!(
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
# cdata: true must serialize as a CDATA section, not escaped text, on
|
|
6
|
+
# every engine lane. The equivalence-based cdata specs compare XML
|
|
7
|
+
# semantically (CDATA and escaped text are equivalent under that
|
|
8
|
+
# comparison), which is how the leptris plan lanes came to emit plain
|
|
9
|
+
# text nodes for cdata rules.
|
|
10
|
+
module CdataEmissionSpec
|
|
11
|
+
class Content < Lutaml::Model::Serializable
|
|
12
|
+
attribute :id, :string
|
|
13
|
+
attribute :label, :string
|
|
14
|
+
|
|
15
|
+
xml do
|
|
16
|
+
element "item"
|
|
17
|
+
map_attribute "id", to: :id
|
|
18
|
+
map_content to: :label, cdata: true
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class Element < Lutaml::Model::Serializable
|
|
23
|
+
attribute :label, :string
|
|
24
|
+
|
|
25
|
+
xml do
|
|
26
|
+
element "labeled"
|
|
27
|
+
map_element "label", to: :label, cdata: true
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
class Plain < Lutaml::Model::Serializable
|
|
32
|
+
attribute :label, :string
|
|
33
|
+
|
|
34
|
+
xml do
|
|
35
|
+
element "plain"
|
|
36
|
+
map_element "label", to: :label
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
RSpec.describe "CDATA emission" do
|
|
42
|
+
%i[leptris nokogiri].each do |engine|
|
|
43
|
+
context "on the #{engine} lane" do
|
|
44
|
+
around do |example|
|
|
45
|
+
previous = Lutaml::Model::Config.xml_adapter_type
|
|
46
|
+
Lutaml::Model::Config.xml_adapter_type = engine
|
|
47
|
+
example.run
|
|
48
|
+
ensure
|
|
49
|
+
Lutaml::Model::Config.xml_adapter_type = previous
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "emits a CDATA section for a content rule with cdata: true" do
|
|
53
|
+
expect(CdataEmissionSpec::Content.new(id: "i", label: "<x>").to_xml)
|
|
54
|
+
.to include("<item id=\"i\"><![CDATA[<x>]]></item>")
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "emits a CDATA section for an element rule with cdata: true" do
|
|
58
|
+
expect(CdataEmissionSpec::Element.new(label: "<x>").to_xml)
|
|
59
|
+
.to include("<label><![CDATA[<x>]]></label>")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "keeps escaped text for a rule without cdata" do
|
|
63
|
+
expect(CdataEmissionSpec::Plain.new(label: "<x>").to_xml)
|
|
64
|
+
.to include("<label><x></label>")
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|