lutaml-model 0.8.101 → 0.8.103
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/Gemfile +6 -5
- data/lib/compat/opal/lutaml_model_boot.rb +1 -0
- data/lib/lutaml/model/configuration.rb +7 -0
- data/lib/lutaml/model/serialize/builder.rb +22 -0
- data/lib/lutaml/model/serialize/format_conversion.rb +5 -2
- data/lib/lutaml/model/serialize/initialization.rb +1 -0
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/leptris/native_emission.rb +187 -0
- data/lib/lutaml/xml/leptris/plan_compiler.rb +161 -102
- data/lib/lutaml/xml/leptris/plan_hydrator.rb +185 -23
- data/lib/lutaml/xml/leptris/plan_serializer.rb +291 -61
- data/lib/lutaml/xml/leptris/plan_walk.rb +6 -3
- data/lib/lutaml/xml/leptris.rb +11 -94
- data/spec/lutaml/xml/plan_fast_path_spec.rb +9 -4
- data/spec/lutaml/xml/plan_type_ns_attribute_spec.rb +0 -11
- data/spec/lutaml/xml/plan_uri_exact_dispatch_spec.rb +287 -0
- data/spec/lutaml/xml/plan_wildcard_any_spec.rb +0 -9
- metadata +4 -2
|
@@ -33,15 +33,18 @@ RSpec.describe "XML plan fast path" do
|
|
|
33
33
|
around do |example|
|
|
34
34
|
old = Lutaml::Model::Config.instance.xml_plan_fast_path
|
|
35
35
|
Lutaml::Model::Config.instance.xml_plan_fast_path = true
|
|
36
|
+
Lutaml::Model::Config.instance.xml_plan_ordered_path = true
|
|
36
37
|
example.run
|
|
37
38
|
ensure
|
|
38
39
|
Lutaml::Model::Config.instance.xml_plan_fast_path = old
|
|
40
|
+
Lutaml::Model::Config.instance.xml_plan_ordered_path = false
|
|
39
41
|
end
|
|
40
42
|
|
|
41
43
|
# Real-corpus crash (niso-jats): sec-in-sec nesting is a
|
|
42
|
-
# self-referential model — compile must
|
|
43
|
-
#
|
|
44
|
-
|
|
44
|
+
# self-referential model — compile must not recurse to
|
|
45
|
+
# SystemStackError. The cycle point defers the child ROW (per-node
|
|
46
|
+
# interpretive islands) instead of opting the model out.
|
|
47
|
+
it "defers the self-referential child row instead of recursing" do
|
|
45
48
|
node = Class.new(Lutaml::Model::Serializable) do
|
|
46
49
|
attribute :text, :string
|
|
47
50
|
xml do
|
|
@@ -57,7 +60,9 @@ RSpec.describe "XML plan fast path" do
|
|
|
57
60
|
end
|
|
58
61
|
stub_const("PlanFastPath::SelfRef", node)
|
|
59
62
|
|
|
60
|
-
|
|
63
|
+
plan = Lutaml::Xml::Leptris::PlanCompiler.compile(node, :default)
|
|
64
|
+
expect(plan).not_to be_nil
|
|
65
|
+
expect(plan[:rows].map { |r| r[2] }).to include(:child_deferred)
|
|
61
66
|
|
|
62
67
|
xml = "<n>#{'<n>t</n>' * 200}</n>"
|
|
63
68
|
parsed = node.from_xml(xml)
|
|
@@ -128,15 +128,4 @@ RSpec.describe "XML plan fast path: type-namespaced attribute rows" do
|
|
|
128
128
|
model, Lutaml::Model::Config.default_register
|
|
129
129
|
)).to be_nil
|
|
130
130
|
end
|
|
131
|
-
|
|
132
|
-
# Engines older than the AttrPlan ns form (libleptris 1.9.289) keep
|
|
133
|
-
# the opt-out — the existing version-gate protocol.
|
|
134
|
-
it "opts out when the engine predates attribute ns rows" do
|
|
135
|
-
allow(Lutaml::Xml::Leptris).to receive(:attr_ns_rows_compatible?)
|
|
136
|
-
.and_return(false)
|
|
137
|
-
|
|
138
|
-
expect(Lutaml::Xml::Leptris::PlanCompiler.compile(
|
|
139
|
-
klass, Lutaml::Model::Config.default_register
|
|
140
|
-
)).to be_nil
|
|
141
|
-
end
|
|
142
131
|
end
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe "XML plan fast path: (URI, local) dispatch and W3C xml:* attributes" do
|
|
6
|
+
# Same-name element rows in different namespaces must dispatch by
|
|
7
|
+
# the child type's exact URI — the interpretive matcher's
|
|
8
|
+
# typed-element identity. The w14/w15 docId shape (OOXML
|
|
9
|
+
# settings.xml) collapsed to name-only binding: one row captured
|
|
10
|
+
# both elements and the other stayed empty, so round-trips lost a
|
|
11
|
+
# docId and downstream reconcilers regenerated it.
|
|
12
|
+
let(:w14_ns_class) do
|
|
13
|
+
klass = Class.new(Lutaml::Xml::Namespace) do
|
|
14
|
+
uri "http://schemas.microsoft.com/office/word/2010/wordml"
|
|
15
|
+
prefix_default "w14"
|
|
16
|
+
attribute_form_default :qualified
|
|
17
|
+
end
|
|
18
|
+
stub_const("PlanUriLocal::W14Ns", klass)
|
|
19
|
+
klass
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
let(:w15_ns_class) do
|
|
23
|
+
klass = Class.new(Lutaml::Xml::Namespace) do
|
|
24
|
+
uri "http://schemas.microsoft.com/office/word/2012/wordml"
|
|
25
|
+
prefix_default "w15"
|
|
26
|
+
attribute_form_default :qualified
|
|
27
|
+
end
|
|
28
|
+
stub_const("PlanUriLocal::W15Ns", klass)
|
|
29
|
+
klass
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
let(:w_ns_class) do
|
|
33
|
+
klass = Class.new(Lutaml::Xml::Namespace) do
|
|
34
|
+
uri "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
|
|
35
|
+
prefix_default "w"
|
|
36
|
+
end
|
|
37
|
+
stub_const("PlanUriLocal::WNs", klass)
|
|
38
|
+
klass
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
let(:w14_doc_id_class) do
|
|
42
|
+
w14_ns_class
|
|
43
|
+
klass = Class.new(Lutaml::Model::Serializable) do
|
|
44
|
+
attribute :val, :string
|
|
45
|
+
|
|
46
|
+
xml do
|
|
47
|
+
element "docId"
|
|
48
|
+
namespace PlanUriLocal::W14Ns
|
|
49
|
+
map_attribute "val", to: :val
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
stub_const("PlanUriLocal::W14DocId", klass)
|
|
53
|
+
klass
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
let(:w15_doc_id_class) do
|
|
57
|
+
w15_ns_class
|
|
58
|
+
klass = Class.new(Lutaml::Model::Serializable) do
|
|
59
|
+
attribute :val, :string
|
|
60
|
+
|
|
61
|
+
xml do
|
|
62
|
+
element "docId"
|
|
63
|
+
namespace PlanUriLocal::W15Ns
|
|
64
|
+
map_attribute "val", to: :val
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
stub_const("PlanUriLocal::W15DocId", klass)
|
|
68
|
+
klass
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def define_settings_class
|
|
72
|
+
w_ns_class
|
|
73
|
+
w14_doc_id_class
|
|
74
|
+
w15_doc_id_class
|
|
75
|
+
Class.new(Lutaml::Model::Serializable) do
|
|
76
|
+
attribute :w14_doc_id, PlanUriLocal::W14DocId
|
|
77
|
+
attribute :w15_doc_id, PlanUriLocal::W15DocId
|
|
78
|
+
|
|
79
|
+
xml do
|
|
80
|
+
element "settings"
|
|
81
|
+
namespace PlanUriLocal::WNs
|
|
82
|
+
namespace_scope [
|
|
83
|
+
{ namespace: PlanUriLocal::W14Ns, declare: :always },
|
|
84
|
+
{ namespace: PlanUriLocal::W15Ns, declare: :always },
|
|
85
|
+
]
|
|
86
|
+
map_element "docId", to: :w14_doc_id, render_nil: false
|
|
87
|
+
map_element "docId", to: :w15_doc_id, render_nil: false
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def settings_xml(body)
|
|
93
|
+
"<w:settings xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" " \
|
|
94
|
+
"xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" " \
|
|
95
|
+
"xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\">#{body}</w:settings>"
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
around do |example|
|
|
99
|
+
old = Lutaml::Model::Config.instance.xml_plan_fast_path
|
|
100
|
+
Lutaml::Model::Config.instance.xml_plan_fast_path = true
|
|
101
|
+
Lutaml::Model::Config.with_adapter(xml: :leptris) { example.run }
|
|
102
|
+
ensure
|
|
103
|
+
Lutaml::Model::Config.instance.xml_plan_fast_path = old
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
it "binds same-name rows by exact URI regardless of document order" do
|
|
107
|
+
settings_class = define_settings_class
|
|
108
|
+
|
|
109
|
+
[%(<w14:docId w14:val="{A}"/><w15:docId w15:val="{B}"/>),
|
|
110
|
+
%(<w15:docId w15:val="{B}"/><w14:docId w14:val="{A}"/>)].each do |body|
|
|
111
|
+
settings = settings_class.from_xml(settings_xml(body))
|
|
112
|
+
|
|
113
|
+
expect(settings.w14_doc_id&.val).to eq("{A}")
|
|
114
|
+
expect(settings.w15_doc_id&.val).to eq("{B}")
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it "leaves the absent-namespace row unset for single-docId documents" do
|
|
119
|
+
settings_class = define_settings_class
|
|
120
|
+
|
|
121
|
+
only_w14 = settings_class.from_xml(
|
|
122
|
+
settings_xml(%(<w14:docId w14:val="{A}"/>)),
|
|
123
|
+
)
|
|
124
|
+
expect(only_w14.w14_doc_id&.val).to eq("{A}")
|
|
125
|
+
expect(only_w14.w15_doc_id).to be_nil
|
|
126
|
+
|
|
127
|
+
only_w15 = settings_class.from_xml(
|
|
128
|
+
settings_xml(%(<w15:docId w15:val="{B}"/>)),
|
|
129
|
+
)
|
|
130
|
+
expect(only_w15.w14_doc_id).to be_nil
|
|
131
|
+
expect(only_w15.w15_doc_id&.val).to eq("{B}")
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it "emits each docId under its own namespace on serialize" do
|
|
135
|
+
settings_class = define_settings_class
|
|
136
|
+
settings = settings_class.from_xml(
|
|
137
|
+
settings_xml(%(<w14:docId w14:val="{A}"/><w15:docId w15:val="{B}"/>)),
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
output = settings.to_xml
|
|
141
|
+
expect(output).to include("<w14:docId w14:val=\"{A}\"/>")
|
|
142
|
+
expect(output).to include("<w15:docId w15:val=\"{B}\"/>")
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Exact-URI attribute rows capture by (URI, local): a prefixed rule
|
|
146
|
+
# spelling with a namespaced type (xlink:href over XlinkHrefType)
|
|
147
|
+
# binds its local part under the row's URI — the full raw name
|
|
148
|
+
# matched nothing and the attribute was dropped.
|
|
149
|
+
it "binds prefixed attribute rules with namespaced types by (URI, local)" do
|
|
150
|
+
text_class = Class.new(Lutaml::Model::Serializable) do
|
|
151
|
+
attribute :xlink_href, Lutaml::Xml::W3c::XlinkHrefType
|
|
152
|
+
|
|
153
|
+
xml do
|
|
154
|
+
element "link"
|
|
155
|
+
map_attribute "xlink:href", to: :xlink_href
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
stub_const("PlanUriLocal::Xlink", text_class)
|
|
159
|
+
|
|
160
|
+
source = '<link xmlns:xlink="http://www.w3.org/1999/xlink" ' \
|
|
161
|
+
'xlink:href="https://example.com"/>'
|
|
162
|
+
link = text_class.from_xml(source)
|
|
163
|
+
|
|
164
|
+
expect(link.xlink_href).to eq("https://example.com")
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# The xml prefix is implicit (W3C-reserved): xml:* attribute rules
|
|
168
|
+
# bind by raw name and must not be qualified under the model's
|
|
169
|
+
# namespace by attribute form defaults (w:t's xml:space under a
|
|
170
|
+
# :qualified WML mapping dropped the attribute entirely).
|
|
171
|
+
it "round-trips xml:space through the plan lane" do
|
|
172
|
+
w_ns_class
|
|
173
|
+
text_class = Class.new(Lutaml::Model::Serializable) do
|
|
174
|
+
attribute :content, :string
|
|
175
|
+
attribute :xml_space, :string
|
|
176
|
+
|
|
177
|
+
xml do
|
|
178
|
+
element "t"
|
|
179
|
+
namespace PlanUriLocal::WNs
|
|
180
|
+
map_content to: :content
|
|
181
|
+
map_attribute "xml:space", to: :xml_space
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
stub_const("PlanUriLocal::Text", text_class)
|
|
185
|
+
|
|
186
|
+
source = '<w:t xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" ' \
|
|
187
|
+
'xml:space="preserve">hi </w:t>'
|
|
188
|
+
text = text_class.from_xml(source)
|
|
189
|
+
|
|
190
|
+
expect(text.xml_space).to eq("preserve")
|
|
191
|
+
expect(text.content).to eq("hi ")
|
|
192
|
+
expect(text.to_xml).to include('xml:space="preserve"')
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# Writer-added values sit outside the parse-built element_order.
|
|
196
|
+
# The ordered serialize lane reconciles them at the interpretive
|
|
197
|
+
# anchors — but only for instances a writer has touched; pristine
|
|
198
|
+
# parsed instances skip the reconciliation scan entirely.
|
|
199
|
+
it "emits writer-added children after parse and skips the scan when pristine" do
|
|
200
|
+
w_ns_class
|
|
201
|
+
w14_doc_id_class
|
|
202
|
+
zoom_class = Class.new(Lutaml::Model::Serializable) do
|
|
203
|
+
attribute :percent, :string
|
|
204
|
+
|
|
205
|
+
xml do
|
|
206
|
+
element "zoom"
|
|
207
|
+
namespace PlanUriLocal::WNs
|
|
208
|
+
map_attribute "percent", to: :percent
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
stub_const("PlanUriLocal::Zoom", zoom_class)
|
|
212
|
+
settings_class = Class.new(Lutaml::Model::Serializable) do
|
|
213
|
+
attribute :zoom, PlanUriLocal::Zoom
|
|
214
|
+
attribute :w14_doc_id, PlanUriLocal::W14DocId
|
|
215
|
+
|
|
216
|
+
xml do
|
|
217
|
+
element "settings"
|
|
218
|
+
namespace PlanUriLocal::WNs
|
|
219
|
+
map_element "zoom", to: :zoom
|
|
220
|
+
map_element "docId", to: :w14_doc_id
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
stub_const("PlanUriLocal::Settings", settings_class)
|
|
224
|
+
|
|
225
|
+
source = settings_xml(%(<w:zoom w:percent="100"/>))
|
|
226
|
+
pristine = settings_class.from_xml(source)
|
|
227
|
+
expect(pristine.zoom.percent).to eq("100")
|
|
228
|
+
expect(pristine.to_xml).not_to include("docId")
|
|
229
|
+
|
|
230
|
+
mutated = settings_class.from_xml(source)
|
|
231
|
+
mutated.w14_doc_id = w14_doc_id_class.new(val: "{A}")
|
|
232
|
+
output = mutated.to_xml
|
|
233
|
+
expect(output).to include("<docId")
|
|
234
|
+
expect(output).to include('val="{A}"')
|
|
235
|
+
expect(output.index("zoom")).to be < output.index("docId")
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
# Root declaration-plan parity: plan-hydrated roots carry the same
|
|
239
|
+
# import_declaration_plan state the interpretive parse records, so
|
|
240
|
+
# consumers and the interpretive serialize fallback see in-scope
|
|
241
|
+
# declarations (#872).
|
|
242
|
+
it "records the source declaration plan on plan-hydrated roots" do
|
|
243
|
+
settings_class = define_settings_class
|
|
244
|
+
settings = settings_class.from_xml(
|
|
245
|
+
settings_xml(%(<w14:docId w14:val="{A}"/>)),
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
plan = settings.import_declaration_plan
|
|
249
|
+
expect(plan).to be_a(Lutaml::Xml::DeclarationPlan)
|
|
250
|
+
hoisted = plan.root_node.hoisted_declarations
|
|
251
|
+
expect(hoisted["w14"]).to eq("http://schemas.microsoft.com/office/word/2010/wordml")
|
|
252
|
+
|
|
253
|
+
skipped = settings_class.from_xml(
|
|
254
|
+
settings_xml(%(<w14:docId w14:val="{A}"/>)),
|
|
255
|
+
import_declaration_plan: :skip,
|
|
256
|
+
)
|
|
257
|
+
expect(skipped.import_declaration_plan).to be_nil
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
# Processing-instruction mappings (rfcxml's <?rfc toc?>) have no
|
|
261
|
+
# plan-row spelling: compiling the model silently dropped
|
|
262
|
+
# pi_settings. The compiler refuses such models — the interpretive
|
|
263
|
+
# path owns PIs.
|
|
264
|
+
it "opts models with processing-instruction mappings out of the plan path" do
|
|
265
|
+
rfc_class = Class.new(Lutaml::Model::Serializable) do
|
|
266
|
+
attribute :pi_settings, :hash
|
|
267
|
+
attribute :version, :string
|
|
268
|
+
|
|
269
|
+
xml do
|
|
270
|
+
element "rfc"
|
|
271
|
+
map_processing_instruction "rfc", to: :pi_settings
|
|
272
|
+
map_attribute "version", to: :version
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
stub_const("PlanUriLocal::Rfc", rfc_class)
|
|
276
|
+
|
|
277
|
+
plan = Lutaml::Xml::Leptris::PlanCompiler.compile(
|
|
278
|
+
rfc_class, Lutaml::Model::Config.default_register
|
|
279
|
+
)
|
|
280
|
+
expect(plan).to be_nil
|
|
281
|
+
|
|
282
|
+
source = %(<?rfc toc="yes"?>\n<rfc version="3"/>)
|
|
283
|
+
rfc = rfc_class.from_xml(source)
|
|
284
|
+
expect(rfc.version).to eq("3")
|
|
285
|
+
expect(rfc.pi_settings["toc"]).to eq("yes")
|
|
286
|
+
end
|
|
287
|
+
end
|
|
@@ -93,13 +93,4 @@ RSpec.describe "XML plan fast path: map_any_element catch-all" do
|
|
|
93
93
|
member_shapes(interpretive.others).map { |n| n.sub("Nokogiri", "Leptris") },
|
|
94
94
|
)
|
|
95
95
|
end
|
|
96
|
-
|
|
97
|
-
it "compiles under engines without wildcard rows to nil" do
|
|
98
|
-
allow(Lutaml::Xml::Leptris).to receive(:wildcard_rows_compatible?)
|
|
99
|
-
.and_return(false)
|
|
100
|
-
|
|
101
|
-
expect(Lutaml::Xml::Leptris::PlanCompiler.compile(
|
|
102
|
-
host_class, Lutaml::Model::Config.default_register
|
|
103
|
-
)).to be_nil
|
|
104
|
-
end
|
|
105
96
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lutaml-model
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.8.
|
|
4
|
+
version: 0.8.103
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -787,6 +787,7 @@ files:
|
|
|
787
787
|
- lib/lutaml/xml/html_entities.rb
|
|
788
788
|
- lib/lutaml/xml/leptris.rb
|
|
789
789
|
- lib/lutaml/xml/leptris/element.rb
|
|
790
|
+
- lib/lutaml/xml/leptris/native_emission.rb
|
|
790
791
|
- lib/lutaml/xml/leptris/plan_compiler.rb
|
|
791
792
|
- lib/lutaml/xml/leptris/plan_hydrator.rb
|
|
792
793
|
- lib/lutaml/xml/leptris/plan_order.rb
|
|
@@ -1997,6 +1998,7 @@ files:
|
|
|
1997
1998
|
- spec/lutaml/xml/plan_ns_less_document_spec.rb
|
|
1998
1999
|
- spec/lutaml/xml/plan_partition_spec.rb
|
|
1999
2000
|
- spec/lutaml/xml/plan_type_ns_attribute_spec.rb
|
|
2001
|
+
- spec/lutaml/xml/plan_uri_exact_dispatch_spec.rb
|
|
2000
2002
|
- spec/lutaml/xml/plan_walk_spec.rb
|
|
2001
2003
|
- spec/lutaml/xml/plan_wildcard_any_spec.rb
|
|
2002
2004
|
- spec/lutaml/xml/prefix_control_spec.rb
|