lutaml-model 0.8.199 → 0.8.201

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.
@@ -0,0 +1,150 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+ require "tmpdir"
5
+ require "fileutils"
6
+
7
+ # lutaml-model#1299: a chase that revisits a location already on the
8
+ # current chain stops. A composed view belongs to its override entry and
9
+ # is shared by every reference to that entry, so a document that
10
+ # overrides back finds the entry either already composed or still on the
11
+ # chain, and never chases its own assembly. XSD 1.1 s4.2.4 allows a
12
+ # document in its own override's target set, composing like a cyclic
13
+ # include.
14
+ RSpec.describe "xs:override chase cycle guard" do
15
+ let(:dir) { Dir.mktmpdir }
16
+
17
+ # W3C saxonData/Override/over023: each document overrides the other;
18
+ # the main document replaces the peer's doc element, the peer's
19
+ # override back carries no children.
20
+ let(:main_schema) do
21
+ <<~XSD
22
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
23
+ <xs:override schemaLocation="over023a.xsd">
24
+ <xs:element name="doc" type="xs:date"/>
25
+ </xs:override>
26
+ </xs:schema>
27
+ XSD
28
+ end
29
+
30
+ let(:peer_schema) do
31
+ <<~XSD
32
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
33
+ <xs:override schemaLocation="over023.xsd"/>
34
+ <xs:element name="doc">
35
+ <xs:complexType>
36
+ <xs:sequence>
37
+ <xs:element name="para" maxOccurs="unbounded"/>
38
+ </xs:sequence>
39
+ </xs:complexType>
40
+ </xs:element>
41
+ </xs:schema>
42
+ XSD
43
+ end
44
+
45
+ before do
46
+ File.write(File.join(dir, "over023.xsd"), main_schema)
47
+ File.write(File.join(dir, "over023a.xsd"), peer_schema)
48
+ end
49
+
50
+ after do
51
+ FileUtils.rm_rf(dir)
52
+ end
53
+
54
+ def assembled
55
+ Lutaml::Xml::Schema::Xsd.parse(main_schema, location: dir, register: :xsd)
56
+ end
57
+
58
+ def view_of(schema)
59
+ schema.override.first.composed
60
+ end
61
+
62
+ it "terminates on a mutual override pair" do
63
+ expect { assembled }.not_to raise_error
64
+ end
65
+
66
+ it "applies each document against the other's originals" do
67
+ view = view_of(assembled)
68
+ doc = view.element.find { |e| e.name == "doc" }
69
+ expect(doc.type).to eq("xs:date")
70
+ # the peer's original keeps its own doc element
71
+ peer = Lutaml::Xml::Schema::Xsd::Schema.processed_schemas["over023a.xsd"]
72
+ expect(peer.element.find { |e| e.name == "doc" }.type).to be_nil
73
+ end
74
+
75
+ it "ends the chain at the revisit instead of composing it again" do
76
+ view = view_of(assembled)
77
+ back = view_of(view)
78
+ expect(back.element).to be_empty
79
+ # the main document's entry, reached through the peer's view, was on
80
+ # the chain and stays uncomposed
81
+ expect(view.override.first.composed).to equal(back)
82
+ expect(back.override.first.composed).to be_nil
83
+ end
84
+
85
+ it "leaves no location on the chain once the parse completes" do
86
+ assembled
87
+ expect(Lutaml::Xml::Schema::Xsd::Schema.in_progress).to be_empty
88
+ end
89
+
90
+ context "with an include riding the cycle" do
91
+ let(:main_schema) do
92
+ <<~XSD
93
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
94
+ <xs:override schemaLocation="base.xsd">
95
+ <xs:element name="para" type="xs:dateTime"/>
96
+ </xs:override>
97
+ </xs:schema>
98
+ XSD
99
+ end
100
+
101
+ let(:peer_schema) do
102
+ <<~XSD
103
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
104
+ <xs:include schemaLocation="peer.xsd"/>
105
+ <xs:element name="para" type="xs:string"/>
106
+ </xs:schema>
107
+ XSD
108
+ end
109
+
110
+ let(:peer_include) do
111
+ <<~XSD
112
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
113
+ <xs:override schemaLocation="base.xsd">
114
+ <xs:element name="other" type="xs:integer"/>
115
+ </xs:override>
116
+ </xs:schema>
117
+ XSD
118
+ end
119
+
120
+ before do
121
+ File.write(File.join(dir, "base.xsd"), peer_schema)
122
+ File.write(File.join(dir, "peer.xsd"), peer_include)
123
+ end
124
+
125
+ it "terminates when the included document overrides its includer" do
126
+ expect { assembled }.not_to raise_error
127
+ expect(view_of(assembled).element.find { |e| e.name == "para" }.type)
128
+ .to eq("xs:dateTime")
129
+ end
130
+ end
131
+
132
+ context "with a document overriding itself" do
133
+ let(:main_schema) do
134
+ <<~XSD
135
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
136
+ <xs:override schemaLocation="over023.xsd">
137
+ <xs:element name="doc" type="xs:date"/>
138
+ </xs:override>
139
+ <xs:element name="doc" type="xs:string"/>
140
+ </xs:schema>
141
+ XSD
142
+ end
143
+
144
+ it "terminates and applies the replacement" do
145
+ expect { assembled }.not_to raise_error
146
+ expect(view_of(assembled).element.find { |e| e.name == "doc" }.type)
147
+ .to eq("xs:date")
148
+ end
149
+ end
150
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lutaml-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.199
4
+ version: 0.8.201
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -2026,6 +2026,7 @@ files:
2026
2026
  - spec/lutaml/key_value/adapter/toml/teptris_adapter_spec.rb
2027
2027
  - spec/lutaml/key_value/child_map_plan_spec.rb
2028
2028
  - spec/lutaml/key_value/group_instantiate_spec.rb
2029
+ - spec/lutaml/key_value/recursive_plan_spec.rb
2029
2030
  - spec/lutaml/key_value/subclass_remap_spec.rb
2030
2031
  - spec/lutaml/key_value/transformation/collection_serializer_spec.rb
2031
2032
  - spec/lutaml/key_value/transformation/rule_compiler_spec.rb
@@ -2428,6 +2429,7 @@ files:
2428
2429
  - spec/lutaml/xml/schema/xsd_all_any_spec.rb
2429
2430
  - spec/lutaml/xml/schema/xsd_identity_ref_spec.rb
2430
2431
  - spec/lutaml/xml/schema/xsd_override_assembly_spec.rb
2432
+ - spec/lutaml/xml/schema/xsd_override_cycle_spec.rb
2431
2433
  - spec/lutaml/xml/schema/xsd_override_spec.rb
2432
2434
  - spec/lutaml/xml/schema/xsd_scale_vc_spec.rb
2433
2435
  - spec/lutaml/xml/schema_primer_spec.rb