lutaml-model 0.8.187 → 0.8.188
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-tools-informational.json +8 -0
- data/.github/workflows/dependent-repos-tools.json +1 -5
- data/.github/workflows/dependent-tests.yml +26 -2
- data/Gemfile +2 -0
- data/Rakefile +6 -0
- data/exe/lutaml-lml-lsp +11 -0
- data/lib/compat/opal/generate_boot.rb +12 -5
- data/lib/compat/opal/lutaml_model_boot.rb +96 -4
- data/lib/lutaml/lml/association_label_resolver.rb +52 -0
- data/lib/lutaml/lml/data_processor/attribute_processing.rb +133 -0
- data/lib/lutaml/lml/data_processor/collection_processing.rb +37 -0
- data/lib/lutaml/lml/data_processor/instance_processing.rb +77 -0
- data/lib/lutaml/lml/data_processor/value_declaration_processing.rb +70 -0
- data/lib/lutaml/lml/data_processor/value_processing.rb +103 -0
- data/lib/lutaml/lml/data_processor/view_processing.rb +26 -0
- data/lib/lutaml/lml/data_processor.rb +66 -0
- data/lib/lutaml/lml/diagnostic.rb +149 -0
- data/lib/lutaml/lml/document_builder.rb +486 -0
- data/lib/lutaml/lml/entity_types.rb +31 -0
- data/lib/lutaml/lml/executor/adapter_helpers.rb +45 -0
- data/lib/lutaml/lml/executor/condition_evaluator.rb +175 -0
- data/lib/lutaml/lml/executor/csv_adapter.rb +89 -0
- data/lib/lutaml/lml/executor/format_adapter.rb +54 -0
- data/lib/lutaml/lml/executor/xml_adapter.rb +102 -0
- data/lib/lutaml/lml/executor.rb +96 -0
- data/lib/lutaml/lml/format/adapter/document.rb +11 -0
- data/lib/lutaml/lml/format/adapter/mapping.rb +31 -0
- data/lib/lutaml/lml/format/adapter/standard_adapter.rb +164 -0
- data/lib/lutaml/lml/format/adapter/transform.rb +11 -0
- data/lib/lutaml/lml/format.rb +34 -0
- data/lib/lutaml/lml/formatter/base.rb +81 -0
- data/lib/lutaml/lml/formatter/canonical.rb +738 -0
- data/lib/lutaml/lml/formatter.rb +11 -0
- data/lib/lutaml/lml/grammar/lml.artifact.json +14993 -0
- data/lib/lutaml/lml/grammar/lml.parg +389 -0
- data/lib/lutaml/lml/grammar.rb +60 -0
- data/lib/lutaml/lml/has_attributes.rb +14 -0
- data/lib/lutaml/lml/import_resolver.rb +96 -0
- data/lib/lutaml/lml/layout/engine.rb +17 -0
- data/lib/lutaml/lml/layout.rb +9 -0
- data/lib/lutaml/lml/literal_value.rb +32 -0
- data/lib/lutaml/lml/lsp/conversions.rb +78 -0
- data/lib/lutaml/lml/lsp/keywords.rb +43 -0
- data/lib/lutaml/lml/lsp/server.rb +380 -0
- data/lib/lutaml/lml/lsp/store.rb +68 -0
- data/lib/lutaml/lml/lsp/transport.rb +53 -0
- data/lib/lutaml/lml/lsp.rb +16 -0
- data/lib/lutaml/lml/model_compiler/enums.rb +170 -0
- data/lib/lutaml/lml/model_compiler/hydration.rb +122 -0
- data/lib/lutaml/lml/model_compiler/serialization_mappings.rb +188 -0
- data/lib/lutaml/lml/model_compiler/string_formats.rb +42 -0
- data/lib/lutaml/lml/model_compiler/validation.rb +65 -0
- data/lib/lutaml/lml/model_compiler.rb +329 -0
- data/lib/lutaml/lml/models/action.rb +10 -0
- data/lib/lutaml/lml/models/association.rb +31 -0
- data/lib/lutaml/lml/models/cardinality.rb +10 -0
- data/lib/lutaml/lml/models/collection.rb +11 -0
- data/lib/lutaml/lml/models/constraint.rb +25 -0
- data/lib/lutaml/lml/models/data_type.rb +43 -0
- data/lib/lutaml/lml/models/derived_field.rb +14 -0
- data/lib/lutaml/lml/models/diagram.rb +22 -0
- data/lib/lutaml/lml/models/document.rb +86 -0
- data/lib/lutaml/lml/models/enum.rb +40 -0
- data/lib/lutaml/lml/models/fidelity.rb +10 -0
- data/lib/lutaml/lml/models/group.rb +11 -0
- data/lib/lutaml/lml/models/instance.rb +28 -0
- data/lib/lutaml/lml/models/instance_collection.rb +18 -0
- data/lib/lutaml/lml/models/instances_export.rb +10 -0
- data/lib/lutaml/lml/models/instances_import.rb +11 -0
- data/lib/lutaml/lml/models/mapping.rb +15 -0
- data/lib/lutaml/lml/models/mapping_rule.rb +16 -0
- data/lib/lutaml/lml/models/member_field.rb +16 -0
- data/lib/lutaml/lml/models/namespace.rb +18 -0
- data/lib/lutaml/lml/models/operation.rb +28 -0
- data/lib/lutaml/lml/models/operation_parameter.rb +12 -0
- data/lib/lutaml/lml/models/package.rb +28 -0
- data/lib/lutaml/lml/models/primitive_type.rb +35 -0
- data/lib/lutaml/lml/models/reference.rb +23 -0
- data/lib/lutaml/lml/models/serialization_mapping.rb +21 -0
- data/lib/lutaml/lml/models/string_format.rb +16 -0
- data/lib/lutaml/lml/models/top_element_attribute.rb +118 -0
- data/lib/lutaml/lml/models/uml_class.rb +87 -0
- data/lib/lutaml/lml/models/value.rb +17 -0
- data/lib/lutaml/lml/models/view_filter.rb +11 -0
- data/lib/lutaml/lml/models/view_import.rb +11 -0
- data/lib/lutaml/lml/parser.rb +19 -0
- data/lib/lutaml/lml/pipeline.rb +73 -0
- data/lib/lutaml/lml/positioned.rb +13 -0
- data/lib/lutaml/lml/preprocessor.rb +132 -0
- data/lib/lutaml/lml/quoting.rb +60 -0
- data/lib/lutaml/lml/source.rb +49 -0
- data/lib/lutaml/lml/source_position.rb +20 -0
- data/lib/lutaml/lml/symbol_index.rb +202 -0
- data/lib/lutaml/lml/transform.rb +119 -0
- data/lib/lutaml/lml/types/text_type.rb +28 -0
- data/lib/lutaml/lml/types.rb +10 -0
- data/lib/lutaml/lml/validator.rb +460 -0
- data/lib/lutaml/lml/view_resolution.rb +32 -0
- data/lib/lutaml/lml/view_resolver.rb +48 -0
- data/lib/lutaml/lml/yaml_parser.rb +17 -0
- data/lib/lutaml/lml.rb +130 -0
- data/lib/lutaml/model/adapter_resolver.rb +21 -2
- data/lib/lutaml/model/config.rb +22 -0
- data/lib/lutaml/model/serialize/format_conversion.rb +8 -6
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/adapter/base_adapter.rb +26 -0
- data/lib/lutaml/xml/adapter/moxml_adapter.rb +49 -0
- data/lib/lutaml/xml/adapter/xml_parser.rb +4 -4
- data/lib/lutaml/xml/adapter/xml_serializer.rb +1 -1
- data/lib/lutaml/xml/adapter.rb +5 -0
- data/lib/lutaml/xml/adapter_loader.rb +5 -0
- data/lib/lutaml/xml/format.rb +23 -2
- data/lib/lutaml/xml/leptris/native_emission.rb +6 -1
- data/lib/lutaml/xml/leptris/plan_serializer.rb +5 -1
- data/lib/lutaml/xml/parse_session.rb +8 -1
- data/lib/lutaml/xml/schema/builder/moxml.rb +1 -1
- data/lib/lutaml/xml/schema/builder.rb +1 -1
- data/lib/lutaml/xml/schema/relaxng_schema.rb +1 -1
- data/lib/lutaml/xml/schema/vc_namespace.rb +24 -0
- data/lib/lutaml/xml/schema/xsd/any.rb +4 -0
- data/lib/lutaml/xml/schema/xsd/any_attribute.rb +4 -0
- data/lib/lutaml/xml/schema/xsd/base.rb +7 -0
- data/lib/lutaml/xml/schema/xsd/schema.rb +38 -0
- data/lib/lutaml/xml/schema/xsd/schema_validator.rb +1 -1
- data/lib/lutaml/xml/schema/xsd.rb +1 -0
- data/lib/lutaml/xml/schema/xsd_schema.rb +1 -1
- data/lib/lutaml/xml/serialization/format_conversion.rb +6 -0
- data/lib/lutaml/xml/xsd_validator.rb +1 -1
- data/lutaml-model.gemspec +2 -0
- data/spec/lml/fixtures/dsl/broken_diagram.lutaml +34 -0
- data/spec/lml/fixtures/dsl/diagram.lutaml +4 -0
- data/spec/lml/fixtures/dsl/diagram_attributes.lutaml +6 -0
- data/spec/lml/fixtures/dsl/diagram_blank_definion.lutaml +6 -0
- data/spec/lml/fixtures/dsl/diagram_blank_entities.lutaml +8 -0
- data/spec/lml/fixtures/dsl/diagram_class_assocation.lutaml +29 -0
- data/spec/lml/fixtures/dsl/diagram_class_fields.lutaml +25 -0
- data/spec/lml/fixtures/dsl/diagram_commented_includes.lutaml +5 -0
- data/spec/lml/fixtures/dsl/diagram_comments.lutaml +28 -0
- data/spec/lml/fixtures/dsl/diagram_concept_model.lutaml +132 -0
- data/spec/lml/fixtures/dsl/diagram_data_types.lutaml +44 -0
- data/spec/lml/fixtures/dsl/diagram_definitions.lutaml +25 -0
- data/spec/lml/fixtures/dsl/diagram_includes.lutaml +6 -0
- data/spec/lml/fixtures/dsl/diagram_multiply_classes.lutaml +7 -0
- data/spec/lml/fixtures/dsl/diagram_non_existing_include.lutaml +6 -0
- data/spec/lml/fixtures/dsl/shared.lutaml +5 -0
- data/spec/lml/fixtures/dsl/shared1.lutaml +4 -0
- data/spec/lml/fixtures/generated_dot/AddressClassProfile.dot +170 -0
- data/spec/lml/fixtures/generated_dot/AddressProfile.dot +34 -0
- data/spec/lml/fixtures/generated_dot/address_class_profile_with_associations.dot +127 -0
- data/spec/lml/fixtures/generated_dot/address_profile_with_associations.dot +28 -0
- data/spec/lml/fixtures/generated_dot/document.dot +28 -0
- data/spec/lml/fixtures/generated_dot/document.dot.backup +33 -0
- data/spec/lml/fixtures/generated_dot/document_with_fidelity.dot +27 -0
- data/spec/lml/fixtures/lml/data_s102_check.lml +79 -0
- data/spec/lml/fixtures/lml/data_s158_metadata.lml +28 -0
- data/spec/lml/fixtures/lml/iho_data_models.lml +59 -0
- data/spec/lml/fixtures/lml/iho_s102_check.lml +101 -0
- data/spec/lml/fixtures/mixed_lml/diagram.lml +26 -0
- data/spec/lml/fixtures/mixed_lml/instances.lml +72 -0
- data/spec/lml/fixtures/mixed_lml/model.lml +30 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/AdmonitionType.lutaml +32 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/BasicBlock.lutaml +11 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/BasicDocument.lutaml +41 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/BasicSection.lutaml +38 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/BibliographicItem.lutaml +6 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/FigureBlock.lutaml +65 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/FormattedString.lutaml +12 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/List.lutaml +12 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/OrderedListType.lutaml +32 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/Signature.lutaml +22 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/String.lutaml +2 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/TableBlock.lutaml +60 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/TextElement.lutaml +13 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/Uri.lutaml +7 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/BibliographicItem.lutaml +4 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoAdmonitionType.lutaml +31 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoBibDataExtensionType.lutaml +40 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoSections.lutaml +30 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoStandardDocument.lutaml +46 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoTerm.lutaml +20 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/StandardBibDataExtensionType.lutaml +2 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/StandardDocument.lutaml +2 -0
- data/spec/lml/fixtures/rs3001/01_class_tail_comment.lml +5 -0
- data/spec/lml/fixtures/rs3001/02_definition_block.lml +9 -0
- data/spec/lml/fixtures/rs3001/03_package_ceramics.lml +20 -0
- data/spec/lml/fixtures/rs3001/04_attribute_definition_form.lml +10 -0
- data/spec/lml/fixtures/rs3001/05_attribute_cardinality_unbounded.lml +10 -0
- data/spec/lml/fixtures/rs3001/06_attribute_values_set.lml +10 -0
- data/spec/lml/fixtures/rs3001/07_attribute_pattern.lml +10 -0
- data/spec/lml/fixtures/rs3001/08_attribute_default_colon.lml +15 -0
- data/spec/lml/fixtures/rs3001/09_value_porcelain.lml +9 -0
- data/spec/lml/fixtures/rs3001/10_enum_glaze_technique.lml +19 -0
- data/spec/lml/fixtures/rs3001/11_enum_values_as_instances.lml +29 -0
- data/spec/lml/fixtures/rs3001/12_instance_named.lml +13 -0
- data/spec/lml/fixtures/rs3001/13_instances_collection_refs.lml +11 -0
- data/spec/lml/fixtures/rs3001/14_require_models.lml +7 -0
- data/spec/lml/fixtures/rs3001/15_comment_line.lml +1 -0
- data/spec/lml/fixtures/rs3001/16_comment_tail.lml +5 -0
- data/spec/lml/fixtures/rs3001/17_comment_documented_class.lml +5 -0
- data/spec/lml/fixtures/rs3001/18_comment_block.lml +4 -0
- data/spec/lml/fixtures/rs3001/19_top_level_instance_definition.lml +21 -0
- data/spec/lml/fixtures/rs3001/20_instance_typed_definition.lml +22 -0
- data/spec/lml/fixtures/rs3001/21_instance_collection_studios.lml +19 -0
- data/spec/lml/fixtures/rs3001/22_instance_collection_tiles.lml +15 -0
- data/spec/lml/fixtures/rs3001/23_reference_cross_collection.lml +11 -0
- data/spec/lml/fixtures/rs3001/24_null_and_empty.lml +15 -0
- data/spec/lml/fixtures/rs3001/25_string_escapes.lml +23 -0
- data/spec/lml/fixtures/rs3001/26_quoted_keys.lml +7 -0
- data/spec/lml/fixtures/test.lutaml +20 -0
- data/spec/lml/fixtures/test_data/components.csv +4 -0
- data/spec/lml/fixtures/test_data/products.xml +18 -0
- data/spec/lml/fixtures/uml/address_class_profile_with_associations.yml +58 -0
- data/spec/lml/fixtures/uml/address_profile_with_associations.yml +31 -0
- data/spec/lml/fixtures/uml/association.yml +11 -0
- data/spec/lml/fixtures/uml/class.yml +28 -0
- data/spec/lml/fixtures/uml/data_type.yml +30 -0
- data/spec/lml/fixtures/uml/diagram.yml +7 -0
- data/spec/lml/fixtures/uml/document.yml +44 -0
- data/spec/lml/fixtures/uml/document_with_fidelity.yml +47 -0
- data/spec/lml/fixtures/uml/enum.yml +14 -0
- data/spec/lml/fixtures/uml/operation.yml +8 -0
- data/spec/lml/fixtures/uml/package.yml +10 -0
- data/spec/lml/fixtures/uml/top_element.yml +11 -0
- data/spec/lml/fixtures/uml/top_element_attribute.yml +10 -0
- data/spec/lml/fixtures/uml/trigger.yml +12 -0
- data/spec/lml/fixtures/uml/value.yml +8 -0
- data/spec/lml/fixtures/view/cycle_a.lutaml +3 -0
- data/spec/lml/fixtures/view/cycle_b.lutaml +3 -0
- data/spec/lml/fixtures/view/import_model.lutaml +3 -0
- data/spec/lml/fixtures/view/import_view.lutaml +3 -0
- data/spec/lml/fixtures/view/import_with_hide.lutaml +4 -0
- data/spec/lml/fixtures/view/import_with_show.lutaml +4 -0
- data/spec/lml/fixtures/view/models/bar.lutaml +3 -0
- data/spec/lml/fixtures/view/models/baz.lutaml +3 -0
- data/spec/lml/fixtures/view/models/foo.lutaml +4 -0
- data/spec/lml/integration/instance_import_export_spec.rb +102 -0
- data/spec/lml/lml_spec_setup.rb +25 -0
- data/spec/lml/lutaml/lml/association_label_resolver_spec.rb +139 -0
- data/spec/lml/lutaml/lml/data_processor_spec.rb +274 -0
- data/spec/lml/lutaml/lml/declarations_spec.rb +337 -0
- data/spec/lml/lutaml/lml/document_builder_registry_spec.rb +52 -0
- data/spec/lml/lutaml/lml/document_builder_spec.rb +99 -0
- data/spec/lml/lutaml/lml/element_visibility_spec.rb +128 -0
- data/spec/lml/lutaml/lml/entity_types_spec.rb +56 -0
- data/spec/lml/lutaml/lml/enum_spec.rb +77 -0
- data/spec/lml/lutaml/lml/executor/adapter_helpers_spec.rb +96 -0
- data/spec/lml/lutaml/lml/executor/condition_evaluator_spec.rb +393 -0
- data/spec/lml/lutaml/lml/executor/csv_adapter_spec.rb +151 -0
- data/spec/lml/lutaml/lml/executor/format_adapter_spec.rb +31 -0
- data/spec/lml/lutaml/lml/executor/xml_adapter_spec.rb +201 -0
- data/spec/lml/lutaml/lml/executor_spec.rb +71 -0
- data/spec/lml/lutaml/lml/format_adapter_spec.rb +272 -0
- data/spec/lml/lutaml/lml/format_autoload_spec.rb +31 -0
- data/spec/lml/lutaml/lml/grammar_spec.rb +581 -0
- data/spec/lml/lutaml/lml/has_attributes_spec.rb +54 -0
- data/spec/lml/lutaml/lml/import_resolver_spec.rb +116 -0
- data/spec/lml/lutaml/lml/instance_hydration_spec.rb +178 -0
- data/spec/lml/lutaml/lml/lsp/server_spec.rb +285 -0
- data/spec/lml/lutaml/lml/model_compiler_spec.rb +406 -0
- data/spec/lml/lutaml/lml/models/association_spec.rb +40 -0
- data/spec/lml/lutaml/lml/models/collection_spec.rb +27 -0
- data/spec/lml/lutaml/lml/models/data_type_spec.rb +34 -0
- data/spec/lml/lutaml/lml/models/diagram_spec.rb +18 -0
- data/spec/lml/lutaml/lml/models/document_spec.rb +64 -0
- data/spec/lml/lutaml/lml/models/enum_spec.rb +42 -0
- data/spec/lml/lutaml/lml/models/inheritance_spec.rb +77 -0
- data/spec/lml/lutaml/lml/models/instance_collection_spec.rb +62 -0
- data/spec/lml/lutaml/lml/models/instance_spec.rb +81 -0
- data/spec/lml/lutaml/lml/models/instances_export_spec.rb +23 -0
- data/spec/lml/lutaml/lml/models/instances_import_spec.rb +28 -0
- data/spec/lml/lutaml/lml/models/package_spec.rb +26 -0
- data/spec/lml/lutaml/lml/models/primitive_type_spec.rb +34 -0
- data/spec/lml/lutaml/lml/models/top_element_attribute_spec.rb +153 -0
- data/spec/lml/lutaml/lml/models/uml_class_spec.rb +70 -0
- data/spec/lml/lutaml/lml/models_version_spec.rb +27 -0
- data/spec/lml/lutaml/lml/operations_spec.rb +59 -0
- data/spec/lml/lutaml/lml/parser_spec.rb +348 -0
- data/spec/lml/lutaml/lml/pipeline_spec.rb +93 -0
- data/spec/lml/lutaml/lml/preprocessor_spec.rb +174 -0
- data/spec/lml/lutaml/lml/property_laws_spec.rb +344 -0
- data/spec/lml/lutaml/lml/real_world_spec.rb +191 -0
- data/spec/lml/lutaml/lml/reference_spec.rb +64 -0
- data/spec/lml/lutaml/lml/round_trip_spec.rb +457 -0
- data/spec/lml/lutaml/lml/rs3001_corpus_spec.rb +83 -0
- data/spec/lml/lutaml/lml/rs3001_syntax_spec.rb +77 -0
- data/spec/lml/lutaml/lml/serialization_mapping_spec.rb +127 -0
- data/spec/lml/lutaml/lml/source_spec.rb +62 -0
- data/spec/lml/lutaml/lml/transform_spec.rb +37 -0
- data/spec/lml/lutaml/lml/types/text_type_spec.rb +43 -0
- data/spec/lml/lutaml/lml/validator_spec.rb +238 -0
- data/spec/lml/lutaml/lml/view_resolver_spec.rb +78 -0
- data/spec/lml/lutaml/lml/view_spec.rb +112 -0
- data/spec/lml/lutaml/parsers/dsl_spec.rb +275 -0
- data/spec/lml/lutaml/parsers/yaml_spec.rb +52 -0
- data/spec/lml/lutaml/qualified_type_spec.rb +33 -0
- data/spec/lutaml/model/adapter_type_unset_restore_spec.rb +61 -0
- data/spec/lutaml/model/custom_bibtex_adapter_spec.rb +4 -1
- data/spec/lutaml/xml/adapter/moxml_lane_spec.rb +112 -0
- data/spec/lutaml/xml/adapter_metadata_default_spec.rb +21 -2
- data/spec/lutaml/xml/adapter_moxml_engine_spec.rb +57 -0
- data/spec/lutaml/xml/leptris/native_emission_plain_model_spec.rb +50 -0
- data/spec/lutaml/xml/plain_model_mapping_resolution_spec.rb +88 -0
- data/spec/lutaml/xml/schema/xsd/vc_versioning_spec.rb +49 -0
- data/spec/lutaml/xml/schema/xsd/xsd_11_constructs_spec.rb +43 -0
- metadata +286 -2
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require_relative "../../lml_spec_setup"
|
|
5
|
+
require "lutaml/lml/format"
|
|
6
|
+
|
|
7
|
+
RSpec.describe "LML format adapter" do
|
|
8
|
+
before do
|
|
9
|
+
require "lutaml/lml/format" unless Lutaml::Model::FormatRegistry.registered?(:lml)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
let(:model_class) do
|
|
13
|
+
Class.new(Lutaml::Model::Serializable) do
|
|
14
|
+
attribute :name, :string
|
|
15
|
+
attribute :age, :integer
|
|
16
|
+
attribute :active, :boolean, default: false
|
|
17
|
+
|
|
18
|
+
lml do
|
|
19
|
+
map :name, to: :name
|
|
20
|
+
map :age, to: :age
|
|
21
|
+
map :active, to: :active
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe "from_lml" do
|
|
27
|
+
it "parses LML instance syntax into model objects" do
|
|
28
|
+
lml = "instance Data {\n name = \"Alice\"\n age = 25\n active = true\n}"
|
|
29
|
+
obj = model_class.from_lml(lml)
|
|
30
|
+
expect(obj.name).to eq("Alice")
|
|
31
|
+
expect(obj.age).to eq(25)
|
|
32
|
+
expect(obj.active).to be(true)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "handles string values without quotes" do
|
|
36
|
+
lml = "instance Data {\n name = SimpleWord\n age = 1\n active = false\n}"
|
|
37
|
+
obj = model_class.from_lml(lml)
|
|
38
|
+
expect(obj.name).to eq("SimpleWord")
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
describe "to_lml" do
|
|
43
|
+
it "serializes model objects to LML instance syntax" do
|
|
44
|
+
obj = model_class.new(name: "Bob", age: 30, active: true)
|
|
45
|
+
lml = obj.to_lml
|
|
46
|
+
expect(lml).to include("name = Bob")
|
|
47
|
+
expect(lml).to include("age = 30")
|
|
48
|
+
expect(lml).to include("active = true")
|
|
49
|
+
expect(lml).to start_with("instance ")
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Keys are `variable`s in the grammar: bare words emit unquoted,
|
|
53
|
+
# anything else must be quoted to re-parse (issue #78).
|
|
54
|
+
it "quotes non-word attribute keys so they re-parse" do
|
|
55
|
+
data = {
|
|
56
|
+
"name" => "Top",
|
|
57
|
+
"data" => { " company name/address" => "Germany / DEU", "" => "Mr Stephan" },
|
|
58
|
+
}
|
|
59
|
+
lml = Lutaml::Lml::Format::Adapter::StandardAdapter.new(data).to_lml
|
|
60
|
+
expect(lml).to include('" company name/address" = "Germany / DEU"')
|
|
61
|
+
expect(lml).to include('"" = "Mr Stephan"')
|
|
62
|
+
|
|
63
|
+
reparsed = Lutaml::Lml.parse_document(lml)
|
|
64
|
+
outer = reparsed.instance.each_attribute.find { |n, _| n == "data" }
|
|
65
|
+
names = []
|
|
66
|
+
outer[2].first.each_attribute { |k, _| names << k }
|
|
67
|
+
expect(names).to eq([" company name/address", ""])
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Keys escape like values: a key containing a quote or backslash
|
|
71
|
+
# must emit a form that re-parses to the same key (issue #78).
|
|
72
|
+
it "escapes quotes and backslashes inside attribute keys" do
|
|
73
|
+
data = { %(bo"th) => "x", "C:\\Users" => "y" }
|
|
74
|
+
lml = Lutaml::Lml::Format::Adapter::StandardAdapter.new(data).to_lml
|
|
75
|
+
reparsed = Lutaml::Lml.parse_document(lml)
|
|
76
|
+
keys = []
|
|
77
|
+
reparsed.instance.each_attribute { |k, _| keys << k }
|
|
78
|
+
expect(keys).to contain_exactly(%(bo"th), "C:\\Users")
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "quotes strings with special characters" do
|
|
82
|
+
obj = model_class.new(name: "Hello World", age: 1, active: false)
|
|
83
|
+
lml = obj.to_lml
|
|
84
|
+
expect(lml).to include('name = "Hello World"')
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
describe "round-trip" do
|
|
89
|
+
it "round-trips through from_lml/to_lml" do
|
|
90
|
+
original = model_class.new(name: "Carol", age: 42, active: false)
|
|
91
|
+
lml = original.to_lml
|
|
92
|
+
restored = model_class.from_lml(lml)
|
|
93
|
+
expect(restored.name).to eq(original.name)
|
|
94
|
+
expect(restored.age).to eq(original.age)
|
|
95
|
+
expect(restored.active).to eq(original.active)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it "round-trips floats and booleans" do
|
|
99
|
+
sensor_class = Class.new(Lutaml::Model::Serializable) do
|
|
100
|
+
attribute :sensor_id, :string
|
|
101
|
+
attribute :reading, :float
|
|
102
|
+
attribute :active, :boolean, default: true
|
|
103
|
+
|
|
104
|
+
lml do
|
|
105
|
+
map :sensor_id, to: :sensor_id
|
|
106
|
+
map :reading, to: :reading
|
|
107
|
+
map :active, to: :active
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
original = sensor_class.new(sensor_id: "TH-042", reading: 21.7, active: false)
|
|
112
|
+
restored = sensor_class.from_lml(original.to_lml)
|
|
113
|
+
expect(restored.sensor_id).to eq("TH-042")
|
|
114
|
+
expect(restored.reading).to eq(21.7)
|
|
115
|
+
expect(restored.active).to be(false)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# The grammar's bare word is [A-Za-z0-9_]; its value parser commits to
|
|
119
|
+
# `number` on a leading digit run, so an unquoted "2012-03-15" can
|
|
120
|
+
# never re-parse. quote_value must quote anything beyond bare words.
|
|
121
|
+
it "quotes dash-bearing strings so they re-parse" do
|
|
122
|
+
event_class = Class.new(Lutaml::Model::Serializable) do
|
|
123
|
+
attribute :date_str, :string
|
|
124
|
+
|
|
125
|
+
lml do
|
|
126
|
+
map :date_str, to: :date_str
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
lml = event_class.new(date_str: "2012-03-15").to_lml
|
|
131
|
+
expect(lml).to include('date_str = "2012-03-15"')
|
|
132
|
+
expect(event_class.from_lml(lml).date_str).to eq("2012-03-15")
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
describe "nested round-trip" do
|
|
137
|
+
it "preserves __type__ in nested instance output" do
|
|
138
|
+
data = {
|
|
139
|
+
"name" => "Outer",
|
|
140
|
+
"__type__" => "OuterType",
|
|
141
|
+
"inner" => {
|
|
142
|
+
"__type__" => "InnerType",
|
|
143
|
+
"value" => "hello",
|
|
144
|
+
},
|
|
145
|
+
}
|
|
146
|
+
adapter = Lutaml::Lml::Format::Adapter::StandardAdapter.new(data)
|
|
147
|
+
lml = adapter.to_lml
|
|
148
|
+
expect(lml).to include("instance OuterType {")
|
|
149
|
+
expect(lml).to include("instance InnerType {")
|
|
150
|
+
expect(lml).to include("value = hello")
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
it "preserves __type__ in array of nested instances" do
|
|
154
|
+
data = {
|
|
155
|
+
"__type__" => "Container",
|
|
156
|
+
"items" => [
|
|
157
|
+
{ "__type__" => "Item", "name" => "first" },
|
|
158
|
+
{ "__type__" => "Item", "name" => "second" },
|
|
159
|
+
],
|
|
160
|
+
}
|
|
161
|
+
adapter = Lutaml::Lml::Format::Adapter::StandardAdapter.new(data)
|
|
162
|
+
lml = adapter.to_lml
|
|
163
|
+
expect(lml).to include("instance Container {")
|
|
164
|
+
expect(lml).to include("instance Item {")
|
|
165
|
+
expect(lml).to include("name = first")
|
|
166
|
+
expect(lml).to include("name = second")
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# StandardAdapter.instance_to_hash branches on `value.is_a?(Array)` to map
|
|
170
|
+
# a list element-wise. `value_from` decides the in-memory shape after a
|
|
171
|
+
# reload, so this pins that a reloaded list still arrives as a bare Array
|
|
172
|
+
# and does not get stringified into a single scalar.
|
|
173
|
+
it "maps a list-valued attribute element-wise after a YAML reload" do
|
|
174
|
+
lml = "instance Checklist {\n type AuditList\n items = [\"verify\", \"validate\"]\n}\n"
|
|
175
|
+
doc = Lutaml::Lml::Document.from_yaml(
|
|
176
|
+
Lutaml::Lml::Pipeline.call(StringIO.new(lml)).to_yaml,
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
hash = Lutaml::Lml::Format::Adapter::StandardAdapter.instance_to_hash(doc.instance)
|
|
180
|
+
|
|
181
|
+
expect(hash["items"]).to eq(%w[verify validate])
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
it "handles nested instances without __type__" do
|
|
185
|
+
data = {
|
|
186
|
+
"name" => "Top",
|
|
187
|
+
"nested" => { "key" => "value" },
|
|
188
|
+
}
|
|
189
|
+
adapter = Lutaml::Lml::Format::Adapter::StandardAdapter.new(data)
|
|
190
|
+
lml = adapter.to_lml
|
|
191
|
+
expect(lml).to include("name = Top")
|
|
192
|
+
expect(lml).to include("nested = instance {")
|
|
193
|
+
expect(lml).to include("key = value")
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
it "round-trips typed nested single instance through from_lml/to_lml" do
|
|
197
|
+
address_cls = Class.new(Lutaml::Model::Serializable) do
|
|
198
|
+
attribute :street, :string
|
|
199
|
+
attribute :city, :string
|
|
200
|
+
lml do
|
|
201
|
+
map :street, to: :street
|
|
202
|
+
map :city, to: :city
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
person_cls = Class.new(Lutaml::Model::Serializable) do
|
|
206
|
+
attribute :name, :string
|
|
207
|
+
attribute :address, address_cls
|
|
208
|
+
lml do
|
|
209
|
+
map :name, to: :name
|
|
210
|
+
map :address, to: :address
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
original = person_cls.new(
|
|
215
|
+
name: "Alice",
|
|
216
|
+
address: address_cls.new(street: "Main", city: "NYC"),
|
|
217
|
+
)
|
|
218
|
+
restored = person_cls.from_lml(original.to_lml)
|
|
219
|
+
expect(restored.name).to eq("Alice")
|
|
220
|
+
expect(restored.address).to be_a(address_cls)
|
|
221
|
+
expect(restored.address.street).to eq("Main")
|
|
222
|
+
expect(restored.address.city).to eq("NYC")
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
it "round-trips typed nested collection through from_lml/to_lml" do
|
|
226
|
+
item_cls = Class.new(Lutaml::Model::Serializable) do
|
|
227
|
+
attribute :sku, :string
|
|
228
|
+
attribute :qty, :integer
|
|
229
|
+
lml do
|
|
230
|
+
map :sku, to: :sku
|
|
231
|
+
map :qty, to: :qty
|
|
232
|
+
end
|
|
233
|
+
end
|
|
234
|
+
order_cls = Class.new(Lutaml::Model::Serializable) do
|
|
235
|
+
attribute :id, :string
|
|
236
|
+
attribute :items, item_cls, collection: true
|
|
237
|
+
lml do
|
|
238
|
+
map :id, to: :id
|
|
239
|
+
map :items, to: :items
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
original = order_cls.new(
|
|
244
|
+
id: "ORD-1",
|
|
245
|
+
items: [
|
|
246
|
+
item_cls.new(sku: "A1", qty: 3),
|
|
247
|
+
item_cls.new(sku: "B2", qty: 1),
|
|
248
|
+
],
|
|
249
|
+
)
|
|
250
|
+
restored = order_cls.from_lml(original.to_lml)
|
|
251
|
+
expect(restored.id).to eq("ORD-1")
|
|
252
|
+
expect(restored.items.size).to eq(2)
|
|
253
|
+
expect(restored.items.first).to be_a(item_cls)
|
|
254
|
+
expect(restored.items.first.sku).to eq("A1")
|
|
255
|
+
expect(restored.items.last.qty).to eq(1)
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
describe "format registration" do
|
|
260
|
+
it "registers :lml in FormatRegistry" do
|
|
261
|
+
expect(Lutaml::Model::FormatRegistry.registered?(:lml)).to be true
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
it "provides from_lml class method" do
|
|
265
|
+
expect(model_class).to respond_to(:from_lml)
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
it "provides to_lml instance method" do
|
|
269
|
+
expect(model_class.new).to respond_to(:to_lml)
|
|
270
|
+
end
|
|
271
|
+
end
|
|
272
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require_relative "../../lml_spec_setup"
|
|
5
|
+
|
|
6
|
+
RSpec.describe "Lutaml::Lml::Format autoload" do
|
|
7
|
+
it "registers :lml with FormatRegistry when the Format constant is accessed" do
|
|
8
|
+
Lutaml::Lml::Format
|
|
9
|
+
expect(Lutaml::Model::FormatRegistry.registered?(:lml)).to be true
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "autoloads StandardAdapter" do
|
|
13
|
+
expect(Lutaml::Lml::Format::Adapter::StandardAdapter)
|
|
14
|
+
.to be_a(Class)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "autoloads Mapping" do
|
|
18
|
+
expect(Lutaml::Lml::Format::Adapter::Mapping)
|
|
19
|
+
.to be_a(Class)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "autoloads Transform" do
|
|
23
|
+
expect(Lutaml::Lml::Format::Adapter::Transform)
|
|
24
|
+
.to be_a(Class)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "autoloads Document" do
|
|
28
|
+
expect(Lutaml::Lml::Format::Adapter::Document)
|
|
29
|
+
.to be_a(Class)
|
|
30
|
+
end
|
|
31
|
+
end
|