lutaml-model 0.8.187 → 0.8.189
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/key_value/adapter/hash/standard_adapter.rb +12 -0
- 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/attribute.rb +72 -0
- data/lib/lutaml/model/config.rb +22 -0
- data/lib/lutaml/model/serialize/format_conversion.rb +8 -6
- data/lib/lutaml/model/services/rule_value_extractor.rb +19 -1
- 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 +31 -4
- 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/model/from_json_scalar_cast_spec.rb +40 -12
- 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,127 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require "tempfile"
|
|
5
|
+
|
|
6
|
+
RSpec.describe "RS 3010 serialization mappings" do
|
|
7
|
+
def compile_lml(src)
|
|
8
|
+
file = Tempfile.new(%w[s .lml])
|
|
9
|
+
file.write(src)
|
|
10
|
+
file.rewind
|
|
11
|
+
compiler = Lutaml::Lml::ModelCompiler.new
|
|
12
|
+
compiler.compile(file)
|
|
13
|
+
compiler
|
|
14
|
+
ensure
|
|
15
|
+
file.close!
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
let(:compiler) do
|
|
19
|
+
compile_lml(<<~LML)
|
|
20
|
+
models Ceramics {
|
|
21
|
+
namespace CeramicsNs {
|
|
22
|
+
uri "http://example.com/ceramics"
|
|
23
|
+
prefix "cer"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
class Ceramic {
|
|
27
|
+
attribute location, String
|
|
28
|
+
attribute kiln, String
|
|
29
|
+
attribute notes, String
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
mapping xml Ceramic {
|
|
34
|
+
element "ceramic"
|
|
35
|
+
namespace CeramicsNs
|
|
36
|
+
map_element "location" location
|
|
37
|
+
map_attribute "kiln" kiln
|
|
38
|
+
map_content notes
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
mapping key_value Ceramic {
|
|
42
|
+
map "full-name" location
|
|
43
|
+
}
|
|
44
|
+
LML
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "emits the mapped element name, wire names, attribute and content" do
|
|
48
|
+
klass = compiler.compiled_classes["Ceramic"]
|
|
49
|
+
xml = klass.new(location: "Paris", kiln: "Electric", notes: "fine").to_xml
|
|
50
|
+
expect(xml).to include("<ceramic")
|
|
51
|
+
expect(xml).to include('kiln="Electric"')
|
|
52
|
+
expect(xml).to include("<location")
|
|
53
|
+
expect(xml).to include("Paris")
|
|
54
|
+
expect(xml).to include("fine</ceramic>")
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "emits the key-value mapping wire names" do
|
|
58
|
+
klass = compiler.compiled_classes["Ceramic"]
|
|
59
|
+
json = klass.new(location: "Paris", kiln: "E", notes: "n").to_json
|
|
60
|
+
expect(json).to include('"full-name"')
|
|
61
|
+
expect(json).to include("Paris")
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "links sibling mappings by target and namespaces by context reference" do
|
|
65
|
+
mapping = compiler.instance_variable_get(:@serialization_mappings).first
|
|
66
|
+
expect(mapping.format).to eq("xml")
|
|
67
|
+
expect(mapping.target).to eq("Ceramic")
|
|
68
|
+
expect(mapping.element_name).to eq("ceramic")
|
|
69
|
+
expect(mapping.namespace_ref).to eq("CeramicsNs")
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "accepts the in-class mapping shortcut targeting the enclosing class" do
|
|
73
|
+
compiler = compile_lml(<<~LML)
|
|
74
|
+
models M {
|
|
75
|
+
class Tile {
|
|
76
|
+
attribute code, String
|
|
77
|
+
|
|
78
|
+
mapping xml {
|
|
79
|
+
element "tile"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
LML
|
|
84
|
+
xml = compiler.compiled_classes["Tile"].new(code: "C1").to_xml
|
|
85
|
+
expect(xml).to include("<tile")
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "raises on an ambiguous default namespace" do
|
|
89
|
+
expect do
|
|
90
|
+
compile_lml(<<~LML)
|
|
91
|
+
models M {
|
|
92
|
+
namespace A {
|
|
93
|
+
uri "http://example.com/a"
|
|
94
|
+
prefix "a"
|
|
95
|
+
}
|
|
96
|
+
namespace B {
|
|
97
|
+
uri "http://example.com/b"
|
|
98
|
+
prefix "b"
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
class Tile {
|
|
102
|
+
attribute code, String
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
mapping xml Tile {
|
|
107
|
+
element "tile"
|
|
108
|
+
}
|
|
109
|
+
LML
|
|
110
|
+
end.to raise_error(ArgumentError, /ambiguous default namespace/)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "keeps the legacy in-class map line syntax working" do
|
|
114
|
+
compiler = compile_lml(<<~LML)
|
|
115
|
+
models M {
|
|
116
|
+
class Widget {
|
|
117
|
+
attribute name { type String cardinality 1 }
|
|
118
|
+
|
|
119
|
+
mapping yaml { map "full-name", to: "name" }
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
LML
|
|
123
|
+
klass = compiler.compiled_classes["Widget"]
|
|
124
|
+
yaml = klass.new(name: "w").to_yaml
|
|
125
|
+
expect(yaml).to include("full-name")
|
|
126
|
+
end
|
|
127
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require "tempfile"
|
|
5
|
+
|
|
6
|
+
RSpec.describe Lutaml::Lml::Source do
|
|
7
|
+
describe ".wrap" do
|
|
8
|
+
it "passes through an existing Source" do
|
|
9
|
+
source = described_class.wrap("text")
|
|
10
|
+
expect(described_class.wrap(source)).to equal(source)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "wraps other input kinds" do
|
|
14
|
+
expect(described_class.wrap(StringIO.new("x"))).to be_a(described_class)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe "#read" do
|
|
19
|
+
it "returns a String input directly" do
|
|
20
|
+
expect(described_class.new("literal text").read).to eq("literal text")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "rewinds and reads an IO" do
|
|
24
|
+
io = StringIO.new("diagram Test\nend")
|
|
25
|
+
io.read
|
|
26
|
+
expect(described_class.new(io).read).to eq("diagram Test\nend")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "is repeatable on the same StringIO" do
|
|
30
|
+
source = described_class.new(StringIO.new("abc"))
|
|
31
|
+
expect(source.read).to eq("abc")
|
|
32
|
+
expect(source.read).to eq("abc")
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe "#path" do
|
|
37
|
+
it "returns the path for a File" do
|
|
38
|
+
file = Tempfile.new(%w[test .lutaml])
|
|
39
|
+
source = described_class.new(file)
|
|
40
|
+
expect(source.path).to eq(file.path)
|
|
41
|
+
file.close!
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "returns nil for anonymous input" do
|
|
45
|
+
expect(described_class.new(StringIO.new("x")).path).to be_nil
|
|
46
|
+
expect(described_class.new("x").path).to be_nil
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe "#base_dir" do
|
|
51
|
+
it "is the dirname of the path for files" do
|
|
52
|
+
file = Tempfile.new(%w[test .lutaml])
|
|
53
|
+
source = described_class.new(file)
|
|
54
|
+
expect(source.base_dir).to eq(File.dirname(file.path))
|
|
55
|
+
file.close!
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "falls back to the working directory for anonymous input" do
|
|
59
|
+
expect(described_class.new(StringIO.new("x")).base_dir).to eq(Dir.pwd)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require_relative "../../lml_spec_setup"
|
|
5
|
+
|
|
6
|
+
RSpec.describe Lutaml::Lml::Transform do
|
|
7
|
+
let(:transform) { described_class.new }
|
|
8
|
+
|
|
9
|
+
describe "visibility modifier rule" do
|
|
10
|
+
it "converts '-' to 'private'" do
|
|
11
|
+
result = transform.apply({ visibility_modifier: "-" })
|
|
12
|
+
expect(result).to eq("private")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "converts '#' to 'protected'" do
|
|
16
|
+
result = transform.apply({ visibility_modifier: "#" })
|
|
17
|
+
expect(result).to eq("protected")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "converts '~' to 'package'" do
|
|
21
|
+
result = transform.apply({ visibility_modifier: "~" })
|
|
22
|
+
expect(result).to eq("package")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "converts '+' to 'public'" do
|
|
26
|
+
result = transform.apply({ visibility_modifier: "+" })
|
|
27
|
+
expect(result).to eq("public")
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe "simple member rule" do
|
|
32
|
+
it "leaves scalar leaves verbatim" do
|
|
33
|
+
result = transform.apply({ outer: " hello " })
|
|
34
|
+
expect(result[:outer]).to eq(" hello ")
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Lutaml::Lml::Types::TextType do
|
|
6
|
+
def cast(text)
|
|
7
|
+
described_class.cast(text)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it 'unescapes \\\\{ and \\\\}' do
|
|
11
|
+
expect(cast('a \\{foo\\} b')).to eq("a {foo} b")
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "strips leading/trailing whitespace per line and rejoins" do
|
|
15
|
+
expect(cast("one\n two \n\tthree")).to eq("one\ntwo\nthree")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "passes nil through" do
|
|
19
|
+
expect(cast(nil)).to be_nil
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "casts on model assignment" do
|
|
23
|
+
attr = Lutaml::Lml::TopElementAttribute.new
|
|
24
|
+
attr.definition = ' raw \\{ x \\} '
|
|
25
|
+
expect(attr.definition).to eq("raw { x }")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "casts on model construction" do
|
|
29
|
+
attr = Lutaml::Lml::TopElementAttribute.new(definition: '\\{y\\}')
|
|
30
|
+
expect(attr.definition).to eq("{y}")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "round-trips through yaml without mapping procs" do
|
|
34
|
+
klass = Lutaml::Lml::UmlClass.new(name: "P", definition: 'kept \\{ z \\}')
|
|
35
|
+
restored = Lutaml::Lml::UmlClass.from_yaml(klass.to_yaml)
|
|
36
|
+
expect(restored.definition).to eq("kept { z }")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "omits nil definitions from yaml" do
|
|
40
|
+
yaml = Lutaml::Lml::UmlClass.new(name: "P").to_yaml
|
|
41
|
+
expect(yaml).not_to include("definition")
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Lutaml::Lml::Validator do
|
|
6
|
+
def violations_for(src)
|
|
7
|
+
document = Lutaml::Lml.parse_document(StringIO.new(src))
|
|
8
|
+
described_class.violations(document)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe "class constraints" do
|
|
12
|
+
it "flags duplicate type names" do
|
|
13
|
+
violations = violations_for(<<~LML)
|
|
14
|
+
models M {
|
|
15
|
+
class Tile { }
|
|
16
|
+
class Tile { }
|
|
17
|
+
}
|
|
18
|
+
LML
|
|
19
|
+
expect(violations.map(&:rule)).to eq(["unique_names"])
|
|
20
|
+
expect(violations.first.message).to include("Tile")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "flags duplicate attribute names within a class" do
|
|
24
|
+
violations = violations_for(<<~LML)
|
|
25
|
+
models M {
|
|
26
|
+
class Tile {
|
|
27
|
+
attribute size, String
|
|
28
|
+
attribute size, String
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
LML
|
|
32
|
+
expect(violations.map(&:rule)).to eq(["unique_attribute_names"])
|
|
33
|
+
expect(violations.first.message).to include('"size"')
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe "attribute constraints" do
|
|
38
|
+
it "flags a missing mandatory attribute on an instance" do
|
|
39
|
+
violations = violations_for(<<~LML)
|
|
40
|
+
models M {
|
|
41
|
+
class Product {
|
|
42
|
+
attribute code, String { cardinality 1 }
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
instances {
|
|
46
|
+
Product "p1" {
|
|
47
|
+
label = "x"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
LML
|
|
51
|
+
expect(violations.map(&:rule))
|
|
52
|
+
.to contain_exactly("mandatory_attributes", "unknown_attributes")
|
|
53
|
+
mandatory = violations.find { |v| v.rule == "mandatory_attributes" }
|
|
54
|
+
expect(mandatory.message).to include("'p1'")
|
|
55
|
+
expect(mandatory.message).to include("'code'")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "accepts a populated mandatory attribute" do
|
|
59
|
+
violations = violations_for(<<~LML)
|
|
60
|
+
models M {
|
|
61
|
+
class Product {
|
|
62
|
+
attribute code, String { cardinality 1 }
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
instances {
|
|
66
|
+
Product "p1" {
|
|
67
|
+
code = "ABC"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
LML
|
|
71
|
+
expect(violations).to be_empty
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "accepts values matching the declared type" do
|
|
75
|
+
violations = violations_for(<<~LML)
|
|
76
|
+
models M {
|
|
77
|
+
class Product {
|
|
78
|
+
attribute count, Integer
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
instances {
|
|
82
|
+
Product "p1" {
|
|
83
|
+
count = 42
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
LML
|
|
87
|
+
expect(violations).to be_empty
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "flags a non-numeric value for an Integer attribute" do
|
|
91
|
+
violations = violations_for(<<~LML)
|
|
92
|
+
models M {
|
|
93
|
+
class Product {
|
|
94
|
+
attribute count, Integer
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
instances {
|
|
98
|
+
Product "p1" {
|
|
99
|
+
count = "many"
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
LML
|
|
103
|
+
expect(violations.map(&:rule)).to eq(["type_conformity"])
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
describe "reference validity" do
|
|
108
|
+
it "flags references to unknown instances" do
|
|
109
|
+
violations = violations_for(<<~LML)
|
|
110
|
+
instances {
|
|
111
|
+
Product "p1" {
|
|
112
|
+
other = reference:(Missing.x)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
LML
|
|
116
|
+
expect(violations.map(&:rule)).to eq(["reference_validity"])
|
|
117
|
+
expect(violations.first.message).to include("'Missing.x'")
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it "flags circular references" do
|
|
121
|
+
violations = violations_for(<<~LML)
|
|
122
|
+
instances {
|
|
123
|
+
Product "a" {
|
|
124
|
+
next = reference:(b)
|
|
125
|
+
}
|
|
126
|
+
Product "b" {
|
|
127
|
+
next = reference:(a)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
LML
|
|
131
|
+
expect(violations.map(&:rule)).to include("reference_circularity")
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it "accepts resolvable references" do
|
|
135
|
+
violations = violations_for(<<~LML)
|
|
136
|
+
instances {
|
|
137
|
+
Product "a" {
|
|
138
|
+
part = reference:(b.code)
|
|
139
|
+
}
|
|
140
|
+
Product "b" {
|
|
141
|
+
code = "B1"
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
LML
|
|
145
|
+
expect(violations).to be_empty
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
describe "values sets" do
|
|
150
|
+
it "accepts membership for values-set attributes" do
|
|
151
|
+
violations = violations_for(<<~LML)
|
|
152
|
+
models M {
|
|
153
|
+
class Tile {
|
|
154
|
+
attribute status, String { values { draft, published } }
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
instances {
|
|
158
|
+
Tile "t" {
|
|
159
|
+
status = "draft"
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
LML
|
|
163
|
+
expect(violations).to be_empty
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
it "flags a value outside the declared set" do
|
|
167
|
+
violations = violations_for(<<~LML)
|
|
168
|
+
models M {
|
|
169
|
+
class Tile {
|
|
170
|
+
attribute status, String { values { draft, published } }
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
instances {
|
|
174
|
+
Tile "t" {
|
|
175
|
+
status = "archived"
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
LML
|
|
179
|
+
expect(violations.map(&:rule)).to eq(["values_set_membership"])
|
|
180
|
+
expect(violations.first.message).to include("archived")
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
describe "unknown instance attributes" do
|
|
185
|
+
it "flags attributes absent from the class definition" do
|
|
186
|
+
violations = violations_for(<<~LML)
|
|
187
|
+
models M {
|
|
188
|
+
class Product {
|
|
189
|
+
attribute code, String
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
instances {
|
|
193
|
+
Product "p1" {
|
|
194
|
+
code = "A"
|
|
195
|
+
mystery = "x"
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
LML
|
|
199
|
+
expect(violations.map(&:rule)).to eq(["unknown_attributes"])
|
|
200
|
+
expect(violations.first.message).to include("'mystery'")
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
describe "package-scoped uniqueness" do
|
|
205
|
+
it "allows the same name in sibling packages" do
|
|
206
|
+
violations = violations_for(<<~LML)
|
|
207
|
+
package Ceramics {
|
|
208
|
+
class Tile { }
|
|
209
|
+
}
|
|
210
|
+
package Textiles {
|
|
211
|
+
class Tile { }
|
|
212
|
+
}
|
|
213
|
+
LML
|
|
214
|
+
expect(violations).to be_empty
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
it "flags duplicates within one package" do
|
|
218
|
+
violations = violations_for(<<~LML)
|
|
219
|
+
package Ceramics {
|
|
220
|
+
class Tile { }
|
|
221
|
+
class Tile { }
|
|
222
|
+
}
|
|
223
|
+
LML
|
|
224
|
+
expect(violations.map(&:rule)).to eq(["unique_names"])
|
|
225
|
+
expect(violations.first.message).to include("package 'Ceramics'")
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
it "flags duplicates between a package and the document root" do
|
|
229
|
+
violations = violations_for(<<~LML)
|
|
230
|
+
class Tile { }
|
|
231
|
+
package Ceramics {
|
|
232
|
+
class Tile { }
|
|
233
|
+
}
|
|
234
|
+
LML
|
|
235
|
+
expect(violations).to be_empty
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require_relative "../../lml_spec_setup"
|
|
5
|
+
|
|
6
|
+
RSpec.describe Lutaml::Lml::ViewResolver do
|
|
7
|
+
let(:resolver) { described_class.new }
|
|
8
|
+
|
|
9
|
+
describe "#resolve" do
|
|
10
|
+
it "returns all entities when no filters" do
|
|
11
|
+
klass1 = Lutaml::Lml::UmlClass.new(name: "Foo")
|
|
12
|
+
klass2 = Lutaml::Lml::UmlClass.new(name: "Bar")
|
|
13
|
+
doc = Lutaml::Lml::Document.new
|
|
14
|
+
entities = { "Foo" => klass1, "Bar" => klass2 }
|
|
15
|
+
associations = []
|
|
16
|
+
|
|
17
|
+
visible, = resolver.resolve(doc, entities, associations)
|
|
18
|
+
expect(visible.map(&:name)).to eq(["Foo", "Bar"])
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "filters to show_list only" do
|
|
22
|
+
foo = Lutaml::Lml::UmlClass.new(name: "Foo")
|
|
23
|
+
bar = Lutaml::Lml::UmlClass.new(name: "Bar")
|
|
24
|
+
baz = Lutaml::Lml::UmlClass.new(name: "Baz")
|
|
25
|
+
doc = Lutaml::Lml::Document.new(
|
|
26
|
+
show_filter: Lutaml::Lml::ViewFilter.new(entity_names: ["Foo", "Bar"]),
|
|
27
|
+
)
|
|
28
|
+
entities = { "Foo" => foo, "Bar" => bar, "Baz" => baz }
|
|
29
|
+
|
|
30
|
+
visible, = resolver.resolve(doc, entities, [])
|
|
31
|
+
expect(visible.map(&:name)).to eq(["Foo", "Bar"])
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "filters out hide_list entities" do
|
|
35
|
+
foo = Lutaml::Lml::UmlClass.new(name: "Foo")
|
|
36
|
+
bar = Lutaml::Lml::UmlClass.new(name: "Bar")
|
|
37
|
+
baz = Lutaml::Lml::UmlClass.new(name: "Baz")
|
|
38
|
+
doc = Lutaml::Lml::Document.new(
|
|
39
|
+
hide_filter: Lutaml::Lml::ViewFilter.new(entity_names: ["Baz"]),
|
|
40
|
+
)
|
|
41
|
+
entities = { "Foo" => foo, "Bar" => bar, "Baz" => baz }
|
|
42
|
+
|
|
43
|
+
visible, = resolver.resolve(doc, entities, [])
|
|
44
|
+
expect(visible.map(&:name)).to eq(["Foo", "Bar"])
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "combines show and hide filters" do
|
|
48
|
+
foo = Lutaml::Lml::UmlClass.new(name: "Foo")
|
|
49
|
+
bar = Lutaml::Lml::UmlClass.new(name: "Bar")
|
|
50
|
+
baz = Lutaml::Lml::UmlClass.new(name: "Baz")
|
|
51
|
+
doc = Lutaml::Lml::Document.new(
|
|
52
|
+
show_filter: Lutaml::Lml::ViewFilter.new(entity_names: ["Foo", "Bar", "Baz"]),
|
|
53
|
+
hide_filter: Lutaml::Lml::ViewFilter.new(entity_names: ["Baz"]),
|
|
54
|
+
)
|
|
55
|
+
entities = { "Foo" => foo, "Bar" => bar, "Baz" => baz }
|
|
56
|
+
|
|
57
|
+
visible, = resolver.resolve(doc, entities, [])
|
|
58
|
+
expect(visible.map(&:name)).to eq(["Foo", "Bar"])
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "filters associations to only those with both ends visible" do
|
|
62
|
+
foo = Lutaml::Lml::UmlClass.new(name: "Foo")
|
|
63
|
+
bar = Lutaml::Lml::UmlClass.new(name: "Bar")
|
|
64
|
+
baz = Lutaml::Lml::UmlClass.new(name: "Baz")
|
|
65
|
+
assoc1 = Lutaml::Lml::Association.new(owner_end: "Foo", member_end: "Bar")
|
|
66
|
+
assoc2 = Lutaml::Lml::Association.new(owner_end: "Foo", member_end: "Baz")
|
|
67
|
+
doc = Lutaml::Lml::Document.new(
|
|
68
|
+
hide_filter: Lutaml::Lml::ViewFilter.new(entity_names: ["Baz"]),
|
|
69
|
+
)
|
|
70
|
+
entities = { "Foo" => foo, "Bar" => bar, "Baz" => baz }
|
|
71
|
+
|
|
72
|
+
_, filtered_assoc = resolver.resolve(doc, entities, [assoc1, assoc2])
|
|
73
|
+
expect(filtered_assoc.length).to eq(1)
|
|
74
|
+
expect(filtered_assoc.first.owner_end).to eq("Foo")
|
|
75
|
+
expect(filtered_assoc.first.member_end).to eq("Bar")
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require_relative "../../lml_spec_setup"
|
|
5
|
+
require "lutaml/lml"
|
|
6
|
+
require "tmpdir"
|
|
7
|
+
require "fileutils"
|
|
8
|
+
|
|
9
|
+
RSpec.describe "View import and filtering" do
|
|
10
|
+
let(:fixtures_dir) { File.expand_path("../../fixtures/view", __dir__) }
|
|
11
|
+
|
|
12
|
+
describe "ImportResolver" do
|
|
13
|
+
it "imports model files via glob pattern" do
|
|
14
|
+
file_path = File.join(fixtures_dir, "import_model.lutaml")
|
|
15
|
+
doc = Lutaml::Lml.parse(File.new(file_path))
|
|
16
|
+
|
|
17
|
+
class_names = doc.classes.map(&:name)
|
|
18
|
+
expect(class_names).to include("Foo", "Bar", "Baz")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "imports model files from nested view" do
|
|
22
|
+
file_path = File.join(fixtures_dir, "import_view.lutaml")
|
|
23
|
+
doc = Lutaml::Lml.parse(File.new(file_path))
|
|
24
|
+
|
|
25
|
+
class_names = doc.classes.map(&:name)
|
|
26
|
+
expect(class_names).to include("Foo", "Bar", "Baz")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "handles circular imports without infinite loop" do
|
|
30
|
+
file_path = File.join(fixtures_dir, "cycle_a.lutaml")
|
|
31
|
+
expect { Lutaml::Lml.parse(File.new(file_path)) }.not_to raise_error
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe "ViewResolver show/hide filtering" do
|
|
36
|
+
it "filters entities with show directive" do
|
|
37
|
+
file_path = File.join(fixtures_dir, "import_with_show.lutaml")
|
|
38
|
+
doc = Lutaml::Lml.parse(File.new(file_path))
|
|
39
|
+
|
|
40
|
+
class_names = doc.classes.map(&:name)
|
|
41
|
+
expect(class_names).to include("Foo", "Bar")
|
|
42
|
+
expect(class_names).not_to include("Baz")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "filters entities with hide directive" do
|
|
46
|
+
file_path = File.join(fixtures_dir, "import_with_hide.lutaml")
|
|
47
|
+
doc = Lutaml::Lml.parse(File.new(file_path))
|
|
48
|
+
|
|
49
|
+
class_names = doc.classes.map(&:name)
|
|
50
|
+
expect(class_names).not_to include("Baz")
|
|
51
|
+
expect(class_names).to include("Foo", "Bar")
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe "inline and imported entities combined" do
|
|
56
|
+
it "merges inline class definitions with imported ones" do
|
|
57
|
+
dir = Dir.mktmpdir
|
|
58
|
+
File.write(File.join(dir, "model.lutaml"), "class Imported {}")
|
|
59
|
+
view = File.join(dir, "view.lutaml")
|
|
60
|
+
File.write(view, "view V {\n import \"model.lutaml\"\n class Inline {}\n}")
|
|
61
|
+
|
|
62
|
+
doc = Lutaml::Lml.parse(File.new(view))
|
|
63
|
+
expect(doc.classes.map(&:name)).to contain_exactly("Imported", "Inline")
|
|
64
|
+
ensure
|
|
65
|
+
FileUtils.rm_rf(dir)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
describe "show/hide naming unknown entities" do
|
|
70
|
+
it "does not error; the name is simply not present" do
|
|
71
|
+
dir = Dir.mktmpdir
|
|
72
|
+
File.write(File.join(dir, "model.lutaml"), "class Foo {}")
|
|
73
|
+
view = File.join(dir, "view.lutaml")
|
|
74
|
+
File.write(view, "view V {\n import \"model.lutaml\"\n show Foo, DoesNotExist\n}")
|
|
75
|
+
|
|
76
|
+
doc = Lutaml::Lml.parse(File.new(view))
|
|
77
|
+
expect(doc.classes.map(&:name)).to eq(["Foo"])
|
|
78
|
+
ensure
|
|
79
|
+
FileUtils.rm_rf(dir)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
describe "glob mixing model and view files" do
|
|
84
|
+
it "imports entities from both kinds through one glob" do
|
|
85
|
+
dir = Dir.mktmpdir
|
|
86
|
+
File.write(File.join(dir, "a_model.lutaml"), "class FromModel {}")
|
|
87
|
+
File.write(File.join(dir, "b_view.lutaml"), "view Inner {\n class FromView {}\n}")
|
|
88
|
+
view = File.join(dir, "view.lutaml")
|
|
89
|
+
File.write(view, "view V { import \"*_*.lutaml\" }")
|
|
90
|
+
|
|
91
|
+
doc = Lutaml::Lml.parse(File.new(view))
|
|
92
|
+
expect(doc.classes.map(&:name)).to contain_exactly("FromModel", "FromView")
|
|
93
|
+
ensure
|
|
94
|
+
FileUtils.rm_rf(dir)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
describe "backward compatibility" do
|
|
99
|
+
it "diagram keyword with preprocessor include still works" do
|
|
100
|
+
dir = Dir.mktmpdir
|
|
101
|
+
shared = File.join(dir, "shared.lutaml")
|
|
102
|
+
File.write(shared, "class Shared {}")
|
|
103
|
+
main = File.join(dir, "main.lutaml")
|
|
104
|
+
File.write(main, "diagram D {\n include #{shared}\n}")
|
|
105
|
+
|
|
106
|
+
doc = Lutaml::Lml.parse(File.new(main))
|
|
107
|
+
expect(doc.classes.map(&:name)).to eq(["Shared"])
|
|
108
|
+
ensure
|
|
109
|
+
FileUtils.rm_rf(dir)
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|