lutaml-model 0.6.0 → 0.6.2
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/.github/workflows/dependent-repos.json +2 -1
- data/.rubocop_todo.yml +10 -80
- data/lib/lutaml/model/attribute.rb +9 -5
- data/lib/lutaml/model/schema/xml_compiler.rb +3 -1
- data/lib/lutaml/model/serialize.rb +6 -8
- data/lib/lutaml/model/type/float.rb +0 -4
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/model/xml_adapter/xml_document.rb +0 -4
- data/lib/lutaml/model/xml_adapter/xml_element.rb +1 -3
- data/spec/address_spec.rb +3 -3
- data/spec/benchmarks/xml_parsing_benchmark_spec.rb +3 -3
- data/spec/lutaml/model/collection_spec.rb +0 -16
- data/spec/lutaml/model/custom_model_spec.rb +49 -1
- data/spec/lutaml/model/json_adapter_spec.rb +26 -24
- data/spec/lutaml/model/key_value_mapping_spec.rb +1 -13
- data/spec/lutaml/model/schema/json_schema_spec.rb +12 -12
- data/spec/lutaml/model/schema/relaxng_schema_spec.rb +12 -12
- data/spec/lutaml/model/schema/xml_compiler_spec.rb +447 -147
- data/spec/lutaml/model/schema/xsd_schema_spec.rb +12 -12
- data/spec/lutaml/model/schema/yaml_schema_spec.rb +12 -12
- data/spec/lutaml/model/sequence_spec.rb +129 -113
- data/spec/lutaml/model/toml_adapter_spec.rb +27 -25
- data/spec/lutaml/model/transformation_spec.rb +80 -80
- data/spec/lutaml/model/type/boolean_spec.rb +4 -10
- data/spec/lutaml/model/type/decimal_spec.rb +3 -3
- data/spec/lutaml/model/type/hash_spec.rb +39 -26
- data/spec/lutaml/model/type/integer_spec.rb +2 -2
- data/spec/lutaml/model/type/time_without_date_spec.rb +0 -6
- data/spec/lutaml/model/type_spec.rb +6 -26
- data/spec/lutaml/model/utils_spec.rb +25 -30
- data/spec/lutaml/model/validation_spec.rb +9 -6
- data/spec/lutaml/model/xml_adapter/oga_adapter_spec.rb +2 -2
- data/spec/lutaml/model/xml_adapter/ox_adapter_spec.rb +2 -2
- data/spec/lutaml/model/xml_adapter/xml_namespace_spec.rb +280 -281
- data/spec/lutaml/model/xml_adapter_spec.rb +128 -120
- data/spec/lutaml/model/xml_mapping_spec.rb +47 -16
- data/spec/person_spec.rb +6 -16
- metadata +2 -2
@@ -65,7 +65,8 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
65
65
|
|
66
66
|
it "raises InvalidValueError" do
|
67
67
|
expect(defined?(MathDocument)).to eq("constant")
|
68
|
-
expect { MathDocument.from_xml(invalid_example) }
|
68
|
+
expect { MathDocument.from_xml(invalid_example) }
|
69
|
+
.to raise_error(Lutaml::Model::Type::InvalidValueError)
|
69
70
|
end
|
70
71
|
end
|
71
72
|
end
|
@@ -167,6 +168,10 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
167
168
|
|
168
169
|
describe "structure setup methods" do
|
169
170
|
describe ".as_models" do
|
171
|
+
let(:as_models) do
|
172
|
+
described_class.send(:as_models, schema)
|
173
|
+
end
|
174
|
+
|
170
175
|
context "when the XML adapter is not set" do
|
171
176
|
before do
|
172
177
|
Lutaml::Model::Config.xml_adapter_type = :ox
|
@@ -176,21 +181,39 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
176
181
|
Lutaml::Model::Config.xml_adapter_type = :nokogiri
|
177
182
|
end
|
178
183
|
|
184
|
+
let(:schema) do
|
185
|
+
'<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>'
|
186
|
+
end
|
187
|
+
|
179
188
|
it "raises an error" do
|
180
|
-
expect {
|
189
|
+
expect { as_models }.to raise_error(Lutaml::Model::Error)
|
181
190
|
end
|
182
191
|
end
|
183
192
|
|
184
193
|
context "when the XML adapter is set and schema is given" do
|
185
|
-
let(:schema)
|
194
|
+
let(:schema) do
|
195
|
+
'<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>'
|
196
|
+
end
|
197
|
+
|
198
|
+
let(:instance_variables) do
|
199
|
+
%i[
|
200
|
+
@elements
|
201
|
+
@attributes
|
202
|
+
@group_types
|
203
|
+
@simple_types
|
204
|
+
@complex_types
|
205
|
+
@attribute_groups
|
206
|
+
]
|
207
|
+
end
|
186
208
|
|
187
209
|
it "initializes the instance variables with empty MappingHash" do
|
188
|
-
|
189
|
-
|
190
|
-
variables.each do |variable|
|
210
|
+
as_models
|
211
|
+
instance_variables.each do |variable|
|
191
212
|
instance_variable = described_class.instance_variable_get(variable)
|
192
|
-
|
193
|
-
expect(instance_variable)
|
213
|
+
|
214
|
+
expect(instance_variable)
|
215
|
+
.to be_a(Lutaml::Model::MappingHash)
|
216
|
+
.and be_empty
|
194
217
|
end
|
195
218
|
end
|
196
219
|
|
@@ -217,7 +240,10 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
217
240
|
context "when given schema contains all the elements" do
|
218
241
|
before do
|
219
242
|
variables.each_key do |key|
|
220
|
-
described_class.instance_variable_set(
|
243
|
+
described_class.instance_variable_set(
|
244
|
+
:"@#{key}",
|
245
|
+
to_mapping_hash({}),
|
246
|
+
)
|
221
247
|
end
|
222
248
|
end
|
223
249
|
|
@@ -242,8 +268,18 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
242
268
|
|
243
269
|
let(:variables) do
|
244
270
|
{
|
245
|
-
elements: {
|
246
|
-
|
271
|
+
elements: {
|
272
|
+
"test_element" => {
|
273
|
+
element_name: "test_element",
|
274
|
+
type_name: nil,
|
275
|
+
},
|
276
|
+
},
|
277
|
+
attributes: {
|
278
|
+
"test_attribute" => {
|
279
|
+
name: "test_attribute",
|
280
|
+
base_class: "xsd:string",
|
281
|
+
},
|
282
|
+
},
|
247
283
|
group_types: { "test_group" => {} },
|
248
284
|
simple_types: { "test_simple_type" => {} },
|
249
285
|
complex_types: { "test_complex_type" => { mixed: true } },
|
@@ -254,15 +290,21 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
254
290
|
it "initializes the instance variables with empty MappingHash" do
|
255
291
|
described_class.send(:schema_to_models, [schema])
|
256
292
|
variables.each do |variable, expected_value|
|
257
|
-
|
258
|
-
|
259
|
-
expect(
|
293
|
+
value = described_class.instance_variable_get(:"@#{variable}")
|
294
|
+
|
295
|
+
expect(value)
|
296
|
+
.to be_a(Lutaml::Model::MappingHash)
|
297
|
+
.and eql(expected_value)
|
260
298
|
end
|
261
299
|
end
|
262
300
|
end
|
263
301
|
end
|
264
302
|
|
265
303
|
describe ".setup_simple_type" do
|
304
|
+
let(:setup_simple_type) do
|
305
|
+
described_class.send(:setup_simple_type, simple_type)
|
306
|
+
end
|
307
|
+
|
266
308
|
context "when given simple_type contains restriction and union" do
|
267
309
|
let(:simple_type) do
|
268
310
|
Lutaml::Xsd::SimpleType.new.tap do |st|
|
@@ -271,8 +313,10 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
271
313
|
end
|
272
314
|
end
|
273
315
|
|
316
|
+
let(:expected_output) { { base_class: "test_base", union: [] } }
|
317
|
+
|
274
318
|
it "initializes the instance variables with empty MappingHash" do
|
275
|
-
expect(
|
319
|
+
expect(setup_simple_type).to eql(expected_output)
|
276
320
|
end
|
277
321
|
end
|
278
322
|
|
@@ -280,7 +324,7 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
280
324
|
let(:simple_type) { Lutaml::Xsd::SimpleType.new }
|
281
325
|
|
282
326
|
it "initializes the instance variables with empty MappingHash" do
|
283
|
-
expect(
|
327
|
+
expect(setup_simple_type).to eql({})
|
284
328
|
end
|
285
329
|
end
|
286
330
|
end
|
@@ -297,9 +341,19 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
297
341
|
end
|
298
342
|
end
|
299
343
|
|
344
|
+
let(:expected_output) do
|
345
|
+
{
|
346
|
+
max_length: 10,
|
347
|
+
min_length: 1,
|
348
|
+
min_inclusive: "1",
|
349
|
+
max_inclusive: "10",
|
350
|
+
length: [{ value: 10 }],
|
351
|
+
}
|
352
|
+
end
|
353
|
+
|
300
354
|
it "initializes the instance variables with empty MappingHash" do
|
301
355
|
described_class.send(:restriction_content, hash = {}, restriction)
|
302
|
-
expect(hash).to eql(
|
356
|
+
expect(hash).to eql(expected_output)
|
303
357
|
end
|
304
358
|
end
|
305
359
|
|
@@ -314,6 +368,10 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
314
368
|
end
|
315
369
|
|
316
370
|
describe ".restriction_length" do
|
371
|
+
let(:restriction_length) do
|
372
|
+
described_class.send(:restriction_length, lengths)
|
373
|
+
end
|
374
|
+
|
317
375
|
context "when given restriction contains max_length, min_length, min_inclusive, max_inclusive, length" do
|
318
376
|
let(:lengths) do
|
319
377
|
[
|
@@ -336,13 +394,15 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
336
394
|
end
|
337
395
|
|
338
396
|
it "initializes the instance variables with empty MappingHash" do
|
339
|
-
expect(
|
397
|
+
expect(restriction_length).to eql(expected_content)
|
340
398
|
end
|
341
399
|
end
|
342
400
|
|
343
401
|
context "when restriction contains nothing" do
|
402
|
+
let(:lengths) { [] }
|
403
|
+
|
344
404
|
it "initializes the instance variables with empty MappingHash" do
|
345
|
-
expect(
|
405
|
+
expect(restriction_length).to be_empty
|
346
406
|
end
|
347
407
|
end
|
348
408
|
end
|
@@ -402,18 +462,24 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
402
462
|
end
|
403
463
|
|
404
464
|
describe ".setup_simple_content" do
|
465
|
+
let(:setup_simple_content) do
|
466
|
+
described_class.send(:setup_simple_content, complex_type)
|
467
|
+
end
|
468
|
+
|
405
469
|
context "when given complex_type contains extension" do
|
406
470
|
let(:complex_type) do
|
407
471
|
Lutaml::Xsd::SimpleContent.new.tap do |ct|
|
408
472
|
ct.extension = Lutaml::Xsd::ExtensionSimpleContent.new(base: "test_extension")
|
409
|
-
ct.element_order = [
|
473
|
+
ct.element_order = [
|
474
|
+
Lutaml::Model::XmlAdapter::Element.new("Element", "extension"),
|
475
|
+
]
|
410
476
|
end
|
411
477
|
end
|
412
478
|
|
413
479
|
let(:expected_hash) { { extension_base: "test_extension" } }
|
414
480
|
|
415
481
|
it "initializes the instance variables with empty MappingHash" do
|
416
|
-
expect(
|
482
|
+
expect(setup_simple_content).to eql(expected_hash)
|
417
483
|
end
|
418
484
|
end
|
419
485
|
|
@@ -421,17 +487,25 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
421
487
|
let(:complex_type) do
|
422
488
|
Lutaml::Xsd::SimpleContent.new.tap do |ct|
|
423
489
|
ct.restriction = Lutaml::Xsd::RestrictionSimpleContent.new(base: "test_restriction")
|
424
|
-
ct.element_order = [
|
490
|
+
ct.element_order = [
|
491
|
+
Lutaml::Model::XmlAdapter::Element.new("Element", "restriction"),
|
492
|
+
]
|
425
493
|
end
|
426
494
|
end
|
427
495
|
|
496
|
+
let(:expected_hash) { { base_class: "test_restriction" } }
|
497
|
+
|
428
498
|
it "initializes the instance variables with empty MappingHash" do
|
429
|
-
expect(
|
499
|
+
expect(setup_simple_content).to eql(expected_hash)
|
430
500
|
end
|
431
501
|
end
|
432
502
|
end
|
433
503
|
|
434
504
|
describe ".setup_sequence" do
|
505
|
+
let(:setup_sequence) do
|
506
|
+
described_class.send(:setup_sequence, sequence)
|
507
|
+
end
|
508
|
+
|
435
509
|
context "when given sequence contains sequence, element, choice, group" do
|
436
510
|
let(:sequence) do
|
437
511
|
Lutaml::Xsd::Sequence.new.tap do |ct|
|
@@ -459,14 +533,17 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
459
533
|
let(:expected_hash) do
|
460
534
|
{
|
461
535
|
sequences: [{}],
|
462
|
-
elements: [
|
536
|
+
elements: [
|
537
|
+
{ element_name: "test_element", type_name: nil },
|
538
|
+
{ ref_class: "test_ref" },
|
539
|
+
],
|
463
540
|
choice: [{}],
|
464
541
|
groups: [{}, { ref_class: "test_ref" }],
|
465
542
|
}
|
466
543
|
end
|
467
544
|
|
468
545
|
it "initializes the instance variables with empty MappingHash" do
|
469
|
-
expect(
|
546
|
+
expect(setup_sequence).to eql(expected_hash)
|
470
547
|
end
|
471
548
|
end
|
472
549
|
|
@@ -478,12 +555,16 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
478
555
|
end
|
479
556
|
|
480
557
|
it "initializes the instance variables with empty MappingHash" do
|
481
|
-
expect(
|
558
|
+
expect(setup_sequence).to be_empty
|
482
559
|
end
|
483
560
|
end
|
484
561
|
end
|
485
562
|
|
486
563
|
describe ".setup_group_type" do
|
564
|
+
let(:setup_group_type) do
|
565
|
+
described_class.send(:setup_group_type, group)
|
566
|
+
end
|
567
|
+
|
487
568
|
context "when given group contains sequence, choice" do
|
488
569
|
let(:group) do
|
489
570
|
Lutaml::Xsd::Group.new.tap do |ct|
|
@@ -499,7 +580,7 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
499
580
|
let(:expected_hash) { { sequence: {}, choice: {} } }
|
500
581
|
|
501
582
|
it "initializes the instance variables with empty MappingHash" do
|
502
|
-
expect(
|
583
|
+
expect(setup_group_type).to eql(expected_hash)
|
503
584
|
end
|
504
585
|
end
|
505
586
|
|
@@ -511,12 +592,16 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
511
592
|
end
|
512
593
|
|
513
594
|
it "initializes the instance variables with empty MappingHash" do
|
514
|
-
expect(
|
595
|
+
expect(setup_group_type).to be_empty
|
515
596
|
end
|
516
597
|
end
|
517
598
|
end
|
518
599
|
|
519
600
|
describe ".setup_choice" do
|
601
|
+
let(:setup_choice) do
|
602
|
+
described_class.send(:setup_choice, choice)
|
603
|
+
end
|
604
|
+
|
520
605
|
context "when given choice contains sequence, choice" do
|
521
606
|
let(:choice) do
|
522
607
|
Lutaml::Xsd::Choice.new.tap do |ct|
|
@@ -533,10 +618,20 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
533
618
|
end
|
534
619
|
end
|
535
620
|
|
536
|
-
let(:expected_hash)
|
621
|
+
let(:expected_hash) do
|
622
|
+
{
|
623
|
+
sequence: {},
|
624
|
+
choice: {},
|
625
|
+
group: {},
|
626
|
+
"test_element" => {
|
627
|
+
element_name: "test_element",
|
628
|
+
type_name: nil,
|
629
|
+
},
|
630
|
+
}
|
631
|
+
end
|
537
632
|
|
538
633
|
it "initializes the instance variables with empty MappingHash" do
|
539
|
-
expect(
|
634
|
+
expect(setup_choice).to eql(expected_hash)
|
540
635
|
end
|
541
636
|
end
|
542
637
|
|
@@ -548,12 +643,16 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
548
643
|
end
|
549
644
|
|
550
645
|
it "initializes the instance variables with empty MappingHash" do
|
551
|
-
expect(
|
646
|
+
expect(setup_choice).to be_empty
|
552
647
|
end
|
553
648
|
end
|
554
649
|
end
|
555
650
|
|
556
651
|
describe ".setup_union" do
|
652
|
+
let(:setup_union) do
|
653
|
+
described_class.send(:setup_union, union)
|
654
|
+
end
|
655
|
+
|
557
656
|
context "when given union contains member_types" do
|
558
657
|
before do
|
559
658
|
described_class.instance_variable_set(:@simple_types, simple_types)
|
@@ -576,10 +675,15 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
576
675
|
end
|
577
676
|
end
|
578
677
|
|
579
|
-
let(:
|
678
|
+
let(:expected_output) do
|
679
|
+
[
|
680
|
+
{ name: "test_member_type" },
|
681
|
+
{ name: "test_member_type1" },
|
682
|
+
]
|
683
|
+
end
|
580
684
|
|
581
685
|
it "returns the expected hash" do
|
582
|
-
expect(
|
686
|
+
expect(setup_union).to eql(expected_output)
|
583
687
|
end
|
584
688
|
end
|
585
689
|
|
@@ -587,12 +691,16 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
587
691
|
let(:union) { Lutaml::Xsd::Union.new }
|
588
692
|
|
589
693
|
it "returns the empty hash" do
|
590
|
-
expect(
|
694
|
+
expect(setup_union).to be_empty
|
591
695
|
end
|
592
696
|
end
|
593
697
|
end
|
594
698
|
|
595
699
|
describe ".setup_attribute" do
|
700
|
+
let(:setup_attribute) do
|
701
|
+
described_class.send(:setup_attribute, attribute)
|
702
|
+
end
|
703
|
+
|
596
704
|
context "when given attribute contains name and type" do
|
597
705
|
let(:attribute) do
|
598
706
|
Lutaml::Xsd::Attribute.new.tap do |attr|
|
@@ -604,7 +712,7 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
604
712
|
let(:expected_hash) { { name: "test_name", base_class: "test_type" } }
|
605
713
|
|
606
714
|
it "returns the expected hash" do
|
607
|
-
expect(
|
715
|
+
expect(setup_attribute).to eql(expected_hash)
|
608
716
|
end
|
609
717
|
end
|
610
718
|
|
@@ -618,7 +726,7 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
618
726
|
let(:expected_hash) { { ref_class: "test_ref" } }
|
619
727
|
|
620
728
|
it "returns the expected hash" do
|
621
|
-
expect(
|
729
|
+
expect(setup_attribute).to eql(expected_hash)
|
622
730
|
end
|
623
731
|
end
|
624
732
|
|
@@ -627,12 +735,16 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
627
735
|
let(:expected_hash) { { name: nil, base_class: nil } }
|
628
736
|
|
629
737
|
it "returns the empty hash" do
|
630
|
-
expect(
|
738
|
+
expect(setup_attribute).to eql(expected_hash)
|
631
739
|
end
|
632
740
|
end
|
633
741
|
end
|
634
742
|
|
635
743
|
describe ".setup_attribute_groups" do
|
744
|
+
let(:setup_attribute_groups) do
|
745
|
+
described_class.send(:setup_attribute_groups, attribute_group)
|
746
|
+
end
|
747
|
+
|
636
748
|
context "when given attribute_group contains attribute and attribute_group" do
|
637
749
|
let(:attribute_group) do
|
638
750
|
Lutaml::Xsd::AttributeGroup.new.tap do |attr_group|
|
@@ -645,10 +757,17 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
645
757
|
end
|
646
758
|
end
|
647
759
|
|
648
|
-
let(:expected_hash)
|
760
|
+
let(:expected_hash) do
|
761
|
+
{
|
762
|
+
attributes: [
|
763
|
+
{ name: "test_name", base_class: "test_type" },
|
764
|
+
],
|
765
|
+
attribute_groups: [{}],
|
766
|
+
}
|
767
|
+
end
|
649
768
|
|
650
769
|
it "returns the expected hash" do
|
651
|
-
expect(
|
770
|
+
expect(setup_attribute_groups).to eql(expected_hash)
|
652
771
|
end
|
653
772
|
end
|
654
773
|
|
@@ -662,7 +781,7 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
662
781
|
let(:expected_hash) { { ref_class: "test_ref" } }
|
663
782
|
|
664
783
|
it "returns the expected hash" do
|
665
|
-
expect(
|
784
|
+
expect(setup_attribute_groups).to eql(expected_hash)
|
666
785
|
end
|
667
786
|
end
|
668
787
|
|
@@ -670,7 +789,7 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
670
789
|
let(:attribute_group) { Lutaml::Xsd::AttributeGroup.new }
|
671
790
|
|
672
791
|
it "returns the empty hash" do
|
673
|
-
expect(
|
792
|
+
expect(setup_attribute_groups).to be_empty
|
674
793
|
end
|
675
794
|
end
|
676
795
|
end
|
@@ -722,6 +841,10 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
722
841
|
described_class.instance_variable_set(:@complex_types, nil)
|
723
842
|
end
|
724
843
|
|
844
|
+
let(:setup_element) do
|
845
|
+
described_class.send(:setup_element, element)
|
846
|
+
end
|
847
|
+
|
725
848
|
let(:complex_types) { { "test_complex_type" => {} } }
|
726
849
|
|
727
850
|
context "when given element contains ref" do
|
@@ -734,7 +857,7 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
734
857
|
let(:expected_hash) { { ref_class: "test_ref" } }
|
735
858
|
|
736
859
|
it "returns the expected hash" do
|
737
|
-
expect(
|
860
|
+
expect(setup_element).to eql(expected_hash)
|
738
861
|
end
|
739
862
|
end
|
740
863
|
|
@@ -754,7 +877,7 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
754
877
|
let(:expected_hash) { { ref_class: "test_ref" } }
|
755
878
|
|
756
879
|
it "returns the expected hash" do
|
757
|
-
expect(
|
880
|
+
expect(setup_element).to eql(expected_hash)
|
758
881
|
end
|
759
882
|
end
|
760
883
|
|
@@ -768,10 +891,16 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
768
891
|
end
|
769
892
|
end
|
770
893
|
|
771
|
-
let(:expected_hash)
|
894
|
+
let(:expected_hash) do
|
895
|
+
{
|
896
|
+
type_name: "test_type",
|
897
|
+
element_name: "test_name",
|
898
|
+
arguments: { min_occurs: "0", max_occurs: "1" },
|
899
|
+
}
|
900
|
+
end
|
772
901
|
|
773
902
|
it "returns the expected hash" do
|
774
|
-
expect(
|
903
|
+
expect(setup_element).to eql(expected_hash)
|
775
904
|
end
|
776
905
|
end
|
777
906
|
|
@@ -785,10 +914,16 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
785
914
|
end
|
786
915
|
end
|
787
916
|
|
788
|
-
let(:expected_hash)
|
917
|
+
let(:expected_hash) do
|
918
|
+
{
|
919
|
+
type_name: "test_type",
|
920
|
+
element_name: "test_name",
|
921
|
+
complex_type: { mixed: false },
|
922
|
+
}
|
923
|
+
end
|
789
924
|
|
790
925
|
it "returns the expected hash" do
|
791
|
-
expect(
|
926
|
+
expect(setup_element).to eql(expected_hash)
|
792
927
|
end
|
793
928
|
end
|
794
929
|
|
@@ -797,12 +932,16 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
797
932
|
let(:expected_hash) { { type_name: nil, element_name: nil } }
|
798
933
|
|
799
934
|
it "returns the expected hash" do
|
800
|
-
expect(
|
935
|
+
expect(setup_element).to eql(expected_hash)
|
801
936
|
end
|
802
937
|
end
|
803
938
|
end
|
804
939
|
|
805
940
|
describe ".setup_restriction" do
|
941
|
+
let(:setup_restriction) do
|
942
|
+
described_class.send(:setup_restriction, restriction, {})
|
943
|
+
end
|
944
|
+
|
806
945
|
context "when given restriction contains base and pattern" do
|
807
946
|
let(:restriction) do
|
808
947
|
Lutaml::Xsd::RestrictionSimpleType.new.tap do |restriction|
|
@@ -818,10 +957,16 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
818
957
|
end
|
819
958
|
end
|
820
959
|
|
821
|
-
let(:expected_hash)
|
960
|
+
let(:expected_hash) do
|
961
|
+
{
|
962
|
+
base_class: "test_base",
|
963
|
+
pattern: "((?-mix:test_pattern))|((?-mix:test_pattern1))",
|
964
|
+
values: ["test_value", "test_value1"],
|
965
|
+
}
|
966
|
+
end
|
822
967
|
|
823
968
|
it "returns the expected hash" do
|
824
|
-
expect(
|
969
|
+
expect(setup_restriction).to eql(expected_hash)
|
825
970
|
end
|
826
971
|
end
|
827
972
|
|
@@ -829,12 +974,16 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
829
974
|
let(:restriction) { Lutaml::Xsd::RestrictionSimpleType.new }
|
830
975
|
|
831
976
|
it "returns the expected hash" do
|
832
|
-
expect(
|
977
|
+
expect(setup_restriction).to eql({ base_class: nil })
|
833
978
|
end
|
834
979
|
end
|
835
980
|
end
|
836
981
|
|
837
982
|
describe ".restriction_patterns" do
|
983
|
+
let(:restriction_patterns) do
|
984
|
+
described_class.send(:restriction_patterns, patterns, {})
|
985
|
+
end
|
986
|
+
|
838
987
|
context "when given patterns are not empty" do
|
839
988
|
let(:patterns) do
|
840
989
|
[
|
@@ -843,10 +992,12 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
843
992
|
]
|
844
993
|
end
|
845
994
|
|
846
|
-
let(:expected_hash)
|
995
|
+
let(:expected_hash) do
|
996
|
+
{ pattern: "((?-mix:test_pattern))|((?-mix:test_pattern1))" }
|
997
|
+
end
|
847
998
|
|
848
999
|
it "returns the expected hash" do
|
849
|
-
expect(
|
1000
|
+
expect(restriction_patterns).to eql(expected_hash)
|
850
1001
|
end
|
851
1002
|
end
|
852
1003
|
|
@@ -854,43 +1005,55 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
854
1005
|
let(:patterns) { [] }
|
855
1006
|
|
856
1007
|
it "returns the expected hash" do
|
857
|
-
expect(
|
1008
|
+
expect(restriction_patterns).to be_nil
|
858
1009
|
end
|
859
1010
|
end
|
860
1011
|
end
|
861
1012
|
|
862
1013
|
describe ".setup_complex_content" do
|
863
|
-
|
1014
|
+
let(:setup_complex_content) do
|
1015
|
+
described_class.send(:setup_complex_content, complex_content)
|
1016
|
+
end
|
1017
|
+
|
1018
|
+
context "when complex_content contains extension with mixed attribute" do
|
864
1019
|
let(:complex_content) do
|
865
1020
|
Lutaml::Xsd::ComplexContent.new.tap do |complex_content|
|
866
1021
|
complex_content.mixed = true
|
867
|
-
complex_content.extension =
|
1022
|
+
complex_content.extension =
|
1023
|
+
Lutaml::Xsd::ExtensionComplexContent.new(base: "test_base")
|
868
1024
|
end
|
869
1025
|
end
|
870
1026
|
|
871
|
-
let(:expected_hash)
|
1027
|
+
let(:expected_hash) do
|
1028
|
+
{ mixed: true, extension: { extension_base: "test_base" } }
|
1029
|
+
end
|
872
1030
|
|
873
1031
|
it "returns the expected hash" do
|
874
|
-
expect(
|
1032
|
+
expect(setup_complex_content).to eql(expected_hash)
|
875
1033
|
end
|
876
1034
|
end
|
877
1035
|
|
878
|
-
context "when
|
1036
|
+
context "when complex_content contains restriction" do
|
879
1037
|
let(:complex_content) do
|
880
1038
|
Lutaml::Xsd::ComplexContent.new.tap do |complex_content|
|
881
|
-
complex_content.restriction =
|
1039
|
+
complex_content.restriction =
|
1040
|
+
Lutaml::Xsd::RestrictionComplexContent.new(base: "test_base")
|
882
1041
|
end
|
883
1042
|
end
|
884
1043
|
|
885
1044
|
let(:expected_hash) { { base_class: "test_base" } }
|
886
1045
|
|
887
1046
|
it "returns the expected hash" do
|
888
|
-
expect(
|
1047
|
+
expect(setup_complex_content).to eql(expected_hash)
|
889
1048
|
end
|
890
1049
|
end
|
891
1050
|
end
|
892
1051
|
|
893
1052
|
describe ".setup_extension" do
|
1053
|
+
let(:setup_extension) do
|
1054
|
+
described_class.send(:setup_extension, extension)
|
1055
|
+
end
|
1056
|
+
|
894
1057
|
context "when given extension contains attributes" do
|
895
1058
|
let(:extension) do
|
896
1059
|
Lutaml::Xsd::ExtensionComplexContent.new.tap do |extension|
|
@@ -920,7 +1083,7 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
920
1083
|
end
|
921
1084
|
|
922
1085
|
it "returns the expected hash" do
|
923
|
-
expect(
|
1086
|
+
expect(setup_extension).to eql(expected_hash)
|
924
1087
|
end
|
925
1088
|
end
|
926
1089
|
|
@@ -928,12 +1091,16 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
928
1091
|
let(:extension) { Lutaml::Xsd::ExtensionComplexContent.new }
|
929
1092
|
|
930
1093
|
it "returns the expected hash" do
|
931
|
-
expect(
|
1094
|
+
expect(setup_extension).to eql({ extension_base: nil })
|
932
1095
|
end
|
933
1096
|
end
|
934
1097
|
end
|
935
1098
|
|
936
1099
|
describe ".element_arguments" do
|
1100
|
+
let(:element_arguments) do
|
1101
|
+
described_class.send(:element_arguments, element, {})
|
1102
|
+
end
|
1103
|
+
|
937
1104
|
context "when given element contains min_occurs and max_occurs" do
|
938
1105
|
let(:element) do
|
939
1106
|
Lutaml::Xsd::Element.new.tap do |element|
|
@@ -945,7 +1112,7 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
945
1112
|
let(:expected_hash) { { min_occurs: "0", max_occurs: "1" } }
|
946
1113
|
|
947
1114
|
it "returns the expected hash" do
|
948
|
-
expect(
|
1115
|
+
expect(element_arguments).to eql(expected_hash)
|
949
1116
|
end
|
950
1117
|
end
|
951
1118
|
|
@@ -953,12 +1120,16 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
953
1120
|
let(:element) { Lutaml::Xsd::Element.new }
|
954
1121
|
|
955
1122
|
it "returns the expected hash" do
|
956
|
-
expect(
|
1123
|
+
expect(element_arguments).to be_empty
|
957
1124
|
end
|
958
1125
|
end
|
959
1126
|
end
|
960
1127
|
|
961
1128
|
describe ".resolved_element_order" do
|
1129
|
+
let(:resolved_element_order) do
|
1130
|
+
described_class.send(:resolved_element_order, element)
|
1131
|
+
end
|
1132
|
+
|
962
1133
|
context "when given element contains element_order but no instance relevant elements/instances" do
|
963
1134
|
let(:element) do
|
964
1135
|
Lutaml::Xsd::Element.new.tap do |element|
|
@@ -973,12 +1144,12 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
973
1144
|
|
974
1145
|
it "raises an error when element_order contains elements that isn't an attribute of the instance" do
|
975
1146
|
element.element_order << Lutaml::Model::XmlAdapter::Element.new("Element", "test_element")
|
976
|
-
expect {
|
1147
|
+
expect { resolved_element_order }.to raise_error(NoMethodError)
|
977
1148
|
end
|
978
1149
|
|
979
1150
|
it "returns the array with nil values" do
|
980
1151
|
expected_hash = [nil, nil, nil, nil]
|
981
|
-
expect(
|
1152
|
+
expect(resolved_element_order).to eql(expected_hash)
|
982
1153
|
end
|
983
1154
|
end
|
984
1155
|
|
@@ -998,10 +1169,17 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
998
1169
|
end
|
999
1170
|
end
|
1000
1171
|
|
1001
|
-
let(:expected_hash)
|
1172
|
+
let(:expected_hash) do
|
1173
|
+
[
|
1174
|
+
element.annotation,
|
1175
|
+
element.simple_type,
|
1176
|
+
element.complex_type,
|
1177
|
+
element.key,
|
1178
|
+
]
|
1179
|
+
end
|
1002
1180
|
|
1003
1181
|
it "returns the expected hash" do
|
1004
|
-
expect(
|
1182
|
+
expect(resolved_element_order).to eql(expected_hash)
|
1005
1183
|
end
|
1006
1184
|
end
|
1007
1185
|
|
@@ -1013,7 +1191,7 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
1013
1191
|
end
|
1014
1192
|
|
1015
1193
|
it "returns the expected hash" do
|
1016
|
-
expect(
|
1194
|
+
expect(resolved_element_order).to be_empty
|
1017
1195
|
end
|
1018
1196
|
end
|
1019
1197
|
end
|
@@ -1021,73 +1199,115 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
1021
1199
|
|
1022
1200
|
describe "structure to template content resolving methods" do
|
1023
1201
|
describe ".resolve_parent_class" do
|
1202
|
+
let(:resolve_parent_class) do
|
1203
|
+
described_class.send(:resolve_parent_class, content)
|
1204
|
+
end
|
1205
|
+
|
1024
1206
|
context "when complex_content.extension is not present" do
|
1207
|
+
let(:content) { {} }
|
1208
|
+
|
1025
1209
|
it "returns Lutaml::Model::Serializable" do
|
1026
|
-
expect(
|
1210
|
+
expect(resolve_parent_class).to eql("Lutaml::Model::Serializable")
|
1027
1211
|
end
|
1028
1212
|
end
|
1029
1213
|
|
1030
1214
|
context "when complex_content.extension is present" do
|
1215
|
+
let(:content) do
|
1216
|
+
{ complex_content: { extension: { extension_base: "ST_Parent" } } }
|
1217
|
+
end
|
1218
|
+
|
1031
1219
|
it "returns the extension_base value" do
|
1032
|
-
|
1033
|
-
expect(described_class.send(:resolve_parent_class, content)).to eql("STParent")
|
1220
|
+
expect(resolve_parent_class).to eql("STParent")
|
1034
1221
|
end
|
1035
1222
|
end
|
1036
1223
|
end
|
1037
1224
|
|
1038
1225
|
describe ".resolve_attribute_class" do
|
1039
|
-
|
1040
|
-
described_class
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1226
|
+
let(:resolve_attribute_class) do
|
1227
|
+
described_class.send(:resolve_attribute_class, base_class_hash)
|
1228
|
+
end
|
1229
|
+
|
1230
|
+
described_class::DEFAULT_CLASSES.each do |standard_class|
|
1231
|
+
context "when #{standard_class.capitalize}" do
|
1232
|
+
let(:base_class_hash) do
|
1233
|
+
to_mapping_hash({ base_class: "xsd:#{standard_class}" })
|
1234
|
+
end
|
1235
|
+
|
1236
|
+
it "returns :#{standard_class}" do
|
1237
|
+
expect(resolve_attribute_class).to eql(":#{standard_class}")
|
1044
1238
|
end
|
1045
1239
|
end
|
1046
1240
|
end
|
1047
1241
|
|
1048
1242
|
context "when attribute.base_class is not one of the standard classes" do
|
1243
|
+
let(:base_class_hash) do
|
1244
|
+
to_mapping_hash({ base_class: "test_st_attr1" })
|
1245
|
+
end
|
1246
|
+
|
1049
1247
|
it "returns the attribute_class value" do
|
1050
|
-
|
1051
|
-
expect(described_class.send(:resolve_attribute_class, base_class_hash)).to eql("TestStAttr1")
|
1248
|
+
expect(resolve_attribute_class).to eql("TestStAttr1")
|
1052
1249
|
end
|
1053
1250
|
end
|
1054
1251
|
end
|
1055
1252
|
|
1056
1253
|
describe ".resolve_element_class" do
|
1057
|
-
|
1058
|
-
described_class
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1254
|
+
let(:resolve_element_class) do
|
1255
|
+
described_class.send(:resolve_element_class, type_name_hash)
|
1256
|
+
end
|
1257
|
+
|
1258
|
+
described_class::DEFAULT_CLASSES.each do |standard_class|
|
1259
|
+
context "when #{standard_class.capitalize}" do
|
1260
|
+
let(:type_name_hash) do
|
1261
|
+
to_mapping_hash({ type_name: "xsd:#{standard_class}" })
|
1262
|
+
end
|
1263
|
+
|
1264
|
+
it "returns :#{standard_class}" do
|
1265
|
+
expect(resolve_element_class).to eql(":#{standard_class}")
|
1062
1266
|
end
|
1063
1267
|
end
|
1064
1268
|
end
|
1065
1269
|
|
1066
1270
|
context "when element.type_name is not one of the standard classes" do
|
1271
|
+
let(:type_name_hash) do
|
1272
|
+
to_mapping_hash({ type_name: "test_st_element1" })
|
1273
|
+
end
|
1274
|
+
|
1067
1275
|
it "returns the element_class value" do
|
1068
|
-
|
1069
|
-
expect(described_class.send(:resolve_element_class, type_name_hash)).to eql("TestStElement1")
|
1276
|
+
expect(resolve_element_class).to eql("TestStElement1")
|
1070
1277
|
end
|
1071
1278
|
end
|
1072
1279
|
end
|
1073
1280
|
|
1074
1281
|
describe ".resolve_occurs" do
|
1075
|
-
|
1282
|
+
let(:resolve_occours) do
|
1283
|
+
described_class.send(:resolve_occurs, base_class_hash)
|
1284
|
+
end
|
1285
|
+
|
1286
|
+
context "when max_occurs is unbounded" do
|
1287
|
+
let(:base_class_hash) do
|
1288
|
+
to_mapping_hash({ min_occurs: 0, max_occurs: "unbounded" })
|
1289
|
+
end
|
1290
|
+
|
1076
1291
|
it "returns the collection: true" do
|
1077
|
-
|
1078
|
-
|
1292
|
+
expect(resolve_occours).to eql(", collection: true")
|
1293
|
+
end
|
1294
|
+
end
|
1295
|
+
|
1296
|
+
context "when max_occurs is 1" do
|
1297
|
+
let(:base_class_hash) do
|
1298
|
+
to_mapping_hash({ min_occurs: 0, max_occurs: 1 })
|
1079
1299
|
end
|
1080
1300
|
|
1081
1301
|
it "returns the collection: 0..1" do
|
1082
|
-
|
1083
|
-
expect(described_class.send(:resolve_occurs, base_class_hash)).to eql(", collection: 0..1")
|
1302
|
+
expect(resolve_occours).to eql(", collection: 0..1")
|
1084
1303
|
end
|
1085
1304
|
end
|
1086
1305
|
|
1087
1306
|
context "when min_occurs/max_occurs are not present" do
|
1307
|
+
let(:base_class_hash) { {} }
|
1308
|
+
|
1088
1309
|
it "returns the collection: 0.." do
|
1089
|
-
|
1090
|
-
expect(described_class.send(:resolve_occurs, base_class_hash)).to eql(", collection: 0..1")
|
1310
|
+
expect(resolve_occours).to eql(", collection: true")
|
1091
1311
|
end
|
1092
1312
|
end
|
1093
1313
|
end
|
@@ -1101,15 +1321,33 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
1101
1321
|
described_class.instance_variable_set(:@elements, nil)
|
1102
1322
|
end
|
1103
1323
|
|
1324
|
+
let(:resolve_elements) do
|
1325
|
+
described_class.send(:resolve_elements, content)
|
1326
|
+
end
|
1327
|
+
|
1104
1328
|
let(:elements) do
|
1105
|
-
to_mapping_hash(
|
1329
|
+
to_mapping_hash(
|
1330
|
+
{ "testRef" => to_mapping_hash({ element_name: "testElement" }) },
|
1331
|
+
)
|
1106
1332
|
end
|
1107
1333
|
|
1108
1334
|
context "when elements contain ref_class and base_class elements" do
|
1335
|
+
let(:content) do
|
1336
|
+
[
|
1337
|
+
to_mapping_hash({ ref_class: "testRef" }),
|
1338
|
+
to_mapping_hash({ element_name: "testElement1" }),
|
1339
|
+
]
|
1340
|
+
end
|
1341
|
+
|
1342
|
+
let(:expected_elements) do
|
1343
|
+
{
|
1344
|
+
"testElement" => { element_name: "testElement" },
|
1345
|
+
"testElement1" => { element_name: "testElement1" },
|
1346
|
+
}
|
1347
|
+
end
|
1348
|
+
|
1109
1349
|
it "returns the elements hash" do
|
1110
|
-
|
1111
|
-
expected_elements = { "testElement" => { element_name: "testElement" }, "testElement1" => { element_name: "testElement1" } }
|
1112
|
-
expect(described_class.send(:resolve_elements, content)).to eql(expected_elements)
|
1350
|
+
expect(resolve_elements).to eql(expected_elements)
|
1113
1351
|
end
|
1114
1352
|
end
|
1115
1353
|
end
|
@@ -1140,7 +1378,7 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
1140
1378
|
}
|
1141
1379
|
end
|
1142
1380
|
|
1143
|
-
context "when sequence contain empty elements and
|
1381
|
+
context "when sequence contain empty elements and empty attributes" do
|
1144
1382
|
it "returns the elements empty hash" do
|
1145
1383
|
expect(described_class.send(:resolve_sequence, sequence)).to be_empty
|
1146
1384
|
end
|
@@ -1148,6 +1386,10 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
1148
1386
|
end
|
1149
1387
|
|
1150
1388
|
describe ".resolve_choice" do
|
1389
|
+
let(:resolve_choice) do
|
1390
|
+
described_class.send(:resolve_choice, choice)
|
1391
|
+
end
|
1392
|
+
|
1151
1393
|
let(:choice) do
|
1152
1394
|
{
|
1153
1395
|
"string" => to_mapping_hash({ element_name: "testElement" }),
|
@@ -1159,7 +1401,8 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
1159
1401
|
|
1160
1402
|
context "when choice contain empty elements and other empty attributes" do
|
1161
1403
|
it "returns the one element hash" do
|
1162
|
-
expect(
|
1404
|
+
expect(resolve_choice)
|
1405
|
+
.to eql({ "string" => { element_name: "testElement" } })
|
1163
1406
|
end
|
1164
1407
|
end
|
1165
1408
|
end
|
@@ -1192,6 +1435,10 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
1192
1435
|
end
|
1193
1436
|
|
1194
1437
|
describe ".resolve_complex_content" do
|
1438
|
+
let(:resolve_complex_content) do
|
1439
|
+
described_class.send(:resolve_complex_content, complex_content)
|
1440
|
+
end
|
1441
|
+
|
1195
1442
|
let(:complex_content) do
|
1196
1443
|
{
|
1197
1444
|
extension: {},
|
@@ -1201,15 +1448,22 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
1201
1448
|
|
1202
1449
|
context "when complex_content contain extension and restriction" do
|
1203
1450
|
it "returns the one element hash" do
|
1204
|
-
expect(
|
1451
|
+
expect(resolve_complex_content).to be_empty
|
1205
1452
|
end
|
1206
1453
|
end
|
1207
1454
|
end
|
1208
1455
|
|
1209
1456
|
describe ".resolve_extension" do
|
1457
|
+
let(:resolve_extension) do
|
1458
|
+
described_class.send(:resolve_extension, to_mapping_hash(extension))
|
1459
|
+
end
|
1460
|
+
|
1210
1461
|
let(:extension) do
|
1211
1462
|
{
|
1212
|
-
attributes: [
|
1463
|
+
attributes: [
|
1464
|
+
{ base_class: "ST_Attr1", default: "1" },
|
1465
|
+
{ base_class: "ST_Attr2", default: "2" },
|
1466
|
+
],
|
1213
1467
|
sequence: {},
|
1214
1468
|
choice: {},
|
1215
1469
|
}
|
@@ -1217,63 +1471,105 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
1217
1471
|
|
1218
1472
|
context "when extension contain attributes, sequence and choice" do
|
1219
1473
|
it "returns the one element hash" do
|
1220
|
-
expect(
|
1474
|
+
expect(resolve_extension)
|
1475
|
+
.to eql({ attributes: extension[:attributes] })
|
1221
1476
|
end
|
1222
1477
|
end
|
1223
1478
|
end
|
1224
1479
|
|
1225
1480
|
describe ".resolve_attribute_default" do
|
1481
|
+
let(:resolve_attribute_default) do
|
1482
|
+
described_class.send(:resolve_attribute_default, attribute)
|
1483
|
+
end
|
1484
|
+
|
1226
1485
|
context "when attribute contain default" do
|
1486
|
+
let(:attribute) do
|
1487
|
+
to_mapping_hash({ base_class: "ST_Attr1", default: "1" })
|
1488
|
+
end
|
1489
|
+
|
1227
1490
|
it "returns the string with default value" do
|
1228
|
-
|
1229
|
-
expect(described_class.send(:resolve_attribute_default, attribute)).to eql(", default: \"1\"")
|
1491
|
+
expect(resolve_attribute_default).to eql(", default: \"1\"")
|
1230
1492
|
end
|
1231
1493
|
end
|
1232
1494
|
|
1233
1495
|
context "when attribute contain no default" do
|
1496
|
+
let(:attribute) { to_mapping_hash({ base_class: "ST_Attr1" }) }
|
1497
|
+
|
1234
1498
|
it "returns the string with nil as default value" do
|
1235
|
-
|
1236
|
-
expect(described_class.send(:resolve_attribute_default, attribute)).to eql(", default: nil")
|
1499
|
+
expect(resolve_attribute_default).to eql(", default: nil")
|
1237
1500
|
end
|
1238
1501
|
end
|
1239
1502
|
end
|
1240
1503
|
|
1241
1504
|
describe ".resolve_attribute_default_value" do
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1505
|
+
let(:resolve_attribute_default_value) do
|
1506
|
+
described_class.send(
|
1507
|
+
:resolve_attribute_default_value,
|
1508
|
+
class_name,
|
1509
|
+
input,
|
1510
|
+
)
|
1511
|
+
end
|
1512
|
+
|
1513
|
+
let(:standard_class_value) do
|
1514
|
+
{
|
1515
|
+
"int" => { input: "1", output: 1 },
|
1516
|
+
"integer" => { input: "12", output: 12 },
|
1517
|
+
"string" => { input: "test_string", output: "test_string" },
|
1518
|
+
"boolean" => { input: "false", output: false },
|
1519
|
+
}
|
1520
|
+
end
|
1251
1521
|
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1522
|
+
described_class::DEFAULT_CLASSES.each do |standard_class|
|
1523
|
+
describe "for #{standard_class.capitalize} class" do
|
1524
|
+
let(:default_value) { standard_class_value[standard_class] }
|
1525
|
+
let(:class_name) { standard_class }
|
1526
|
+
let(:input) { default_value[:input] }
|
1527
|
+
|
1528
|
+
it "returns an instance of #{standard_class.capitalize}" do
|
1529
|
+
expect(resolve_attribute_default_value)
|
1530
|
+
.to eql(default_value[:output])
|
1256
1531
|
end
|
1257
1532
|
end
|
1258
1533
|
end
|
1259
1534
|
|
1260
1535
|
context "when attribute data type is not one of the standard classes" do
|
1536
|
+
let(:class_name) { "BooleanTestClass" }
|
1537
|
+
let(:input) { "1" }
|
1538
|
+
|
1261
1539
|
it "returns the string with default value" do
|
1262
|
-
expect(
|
1540
|
+
expect(resolve_attribute_default_value).to eql("\"1\"")
|
1263
1541
|
end
|
1264
1542
|
end
|
1265
1543
|
end
|
1266
1544
|
|
1267
1545
|
describe ".resolve_namespace" do
|
1546
|
+
let(:resolved_namespace) do
|
1547
|
+
described_class.send(
|
1548
|
+
:resolve_namespace,
|
1549
|
+
namespace_attrs,
|
1550
|
+
)
|
1551
|
+
end
|
1552
|
+
|
1268
1553
|
context "when namespace is given" do
|
1554
|
+
let(:namespace_attrs) { { namespace: "testNamespace" } }
|
1555
|
+
|
1269
1556
|
it "returns the string with namespace" do
|
1270
|
-
expect(
|
1557
|
+
expect(resolved_namespace)
|
1558
|
+
.to eql("namespace \"testNamespace\"\n")
|
1271
1559
|
end
|
1272
1560
|
end
|
1273
1561
|
|
1274
1562
|
context "when namespace and prefix are given" do
|
1563
|
+
let(:namespace_attrs) do
|
1564
|
+
{
|
1565
|
+
namespace: "testNamespace",
|
1566
|
+
prefix: "testPrefix",
|
1567
|
+
}
|
1568
|
+
end
|
1569
|
+
|
1275
1570
|
it "returns the string with namespace and prefix" do
|
1276
|
-
expect(
|
1571
|
+
expect(resolved_namespace)
|
1572
|
+
.to eql("namespace \"testNamespace\", \"testPrefix\"\n")
|
1277
1573
|
end
|
1278
1574
|
end
|
1279
1575
|
|
@@ -1286,6 +1582,10 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
1286
1582
|
end
|
1287
1583
|
|
1288
1584
|
describe "required files list compiler methods" do
|
1585
|
+
let(:required_files) do
|
1586
|
+
described_class.instance_variable_get(:@required_files)
|
1587
|
+
end
|
1588
|
+
|
1289
1589
|
describe ".resolve_required_files" do
|
1290
1590
|
context "when elements are given" do
|
1291
1591
|
before do
|
@@ -1308,9 +1608,9 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
1308
1608
|
}
|
1309
1609
|
end
|
1310
1610
|
|
1311
|
-
it "populates @required_files
|
1611
|
+
it "populates @required_files" do
|
1312
1612
|
described_class.send(:resolve_required_files, content)
|
1313
|
-
expect(
|
1613
|
+
expect(required_files).to eql([])
|
1314
1614
|
end
|
1315
1615
|
end
|
1316
1616
|
end
|
@@ -1334,9 +1634,9 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
1334
1634
|
}
|
1335
1635
|
end
|
1336
1636
|
|
1337
|
-
it "populates @required_files
|
1637
|
+
it "populates @required_files" do
|
1338
1638
|
described_class.send(:required_files_simple_content, content)
|
1339
|
-
expect(
|
1639
|
+
expect(required_files).to eql([])
|
1340
1640
|
end
|
1341
1641
|
end
|
1342
1642
|
end
|
@@ -1358,9 +1658,9 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
1358
1658
|
}
|
1359
1659
|
end
|
1360
1660
|
|
1361
|
-
it "populates @required_files
|
1661
|
+
it "populates @required_files" do
|
1362
1662
|
described_class.send(:required_files_complex_content, content)
|
1363
|
-
expect(
|
1663
|
+
expect(required_files).to eql([])
|
1364
1664
|
end
|
1365
1665
|
end
|
1366
1666
|
end
|
@@ -1386,9 +1686,9 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
1386
1686
|
}
|
1387
1687
|
end
|
1388
1688
|
|
1389
|
-
it "populates @required_files
|
1689
|
+
it "populates @required_files" do
|
1390
1690
|
described_class.send(:required_files_extension, content)
|
1391
|
-
expect(
|
1691
|
+
expect(required_files).to eql([])
|
1392
1692
|
end
|
1393
1693
|
end
|
1394
1694
|
end
|
@@ -1405,9 +1705,9 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
1405
1705
|
|
1406
1706
|
let(:content) { { base: "testId" } }
|
1407
1707
|
|
1408
|
-
it "populates @required_files
|
1708
|
+
it "populates @required_files" do
|
1409
1709
|
described_class.send(:required_files_restriction, content)
|
1410
|
-
expect(
|
1710
|
+
expect(required_files).to eql(["test_id"])
|
1411
1711
|
end
|
1412
1712
|
end
|
1413
1713
|
end
|
@@ -1434,9 +1734,9 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
1434
1734
|
}
|
1435
1735
|
end
|
1436
1736
|
|
1437
|
-
it "populates @required_files
|
1737
|
+
it "populates @required_files" do
|
1438
1738
|
described_class.send(:required_files_attribute_groups, content)
|
1439
|
-
expect(
|
1739
|
+
expect(required_files).to eql([])
|
1440
1740
|
end
|
1441
1741
|
end
|
1442
1742
|
end
|
@@ -1466,9 +1766,9 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
1466
1766
|
]
|
1467
1767
|
end
|
1468
1768
|
|
1469
|
-
it "populates @required_files
|
1769
|
+
it "populates @required_files" do
|
1470
1770
|
described_class.send(:required_files_attribute, content)
|
1471
|
-
expect(
|
1771
|
+
expect(required_files).to eql(["st_attr1", "st_attr2"])
|
1472
1772
|
end
|
1473
1773
|
end
|
1474
1774
|
end
|
@@ -1488,9 +1788,9 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
1488
1788
|
}
|
1489
1789
|
end
|
1490
1790
|
|
1491
|
-
it "populates @required_files
|
1791
|
+
it "populates @required_files" do
|
1492
1792
|
described_class.send(:required_files_choice, content)
|
1493
|
-
expect(
|
1793
|
+
expect(required_files).to eql(["st_attr1"])
|
1494
1794
|
end
|
1495
1795
|
end
|
1496
1796
|
end
|
@@ -1516,9 +1816,9 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
1516
1816
|
}
|
1517
1817
|
end
|
1518
1818
|
|
1519
|
-
it "populates @required_files
|
1819
|
+
it "populates @required_files" do
|
1520
1820
|
described_class.send(:required_files_group, content)
|
1521
|
-
expect(
|
1821
|
+
expect(required_files).to eql([])
|
1522
1822
|
end
|
1523
1823
|
end
|
1524
1824
|
end
|
@@ -1542,9 +1842,9 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
1542
1842
|
}
|
1543
1843
|
end
|
1544
1844
|
|
1545
|
-
it "populates @required_files
|
1845
|
+
it "populates @required_files" do
|
1546
1846
|
described_class.send(:required_files_sequence, content)
|
1547
|
-
expect(
|
1847
|
+
expect(required_files).to eql([])
|
1548
1848
|
end
|
1549
1849
|
end
|
1550
1850
|
end
|
@@ -1574,9 +1874,9 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
1574
1874
|
]
|
1575
1875
|
end
|
1576
1876
|
|
1577
|
-
it "populates @required_files
|
1877
|
+
it "populates @required_files" do
|
1578
1878
|
described_class.send(:required_files_elements, content)
|
1579
|
-
expect(
|
1879
|
+
expect(required_files).to eql(["ct_element1", "ct_element2"])
|
1580
1880
|
end
|
1581
1881
|
end
|
1582
1882
|
|
@@ -1605,9 +1905,9 @@ RSpec.describe Lutaml::Model::Schema::XmlCompiler do
|
|
1605
1905
|
]
|
1606
1906
|
end
|
1607
1907
|
|
1608
|
-
it "populates @required_files
|
1908
|
+
it "populates @required_files excluding default classes" do
|
1609
1909
|
described_class.send(:required_files_elements, content)
|
1610
|
-
expect(
|
1910
|
+
expect(required_files).to eql(["ct_element1"])
|
1611
1911
|
end
|
1612
1912
|
end
|
1613
1913
|
end
|