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,337 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require "tempfile"
|
|
5
|
+
require "parsanol"
|
|
6
|
+
|
|
7
|
+
RSpec.describe "LML declarations (isa, defaults, derive, payloads, string_format)" do
|
|
8
|
+
def compile_lml(source)
|
|
9
|
+
file = Tempfile.new(%w[test .lml])
|
|
10
|
+
file.write(source)
|
|
11
|
+
file.rewind
|
|
12
|
+
Lutaml::Lml::ModelCompiler.new.tap { |c| c.compile(file) }
|
|
13
|
+
ensure
|
|
14
|
+
file.close!
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def write_grammar_artifact
|
|
18
|
+
source = <<~PARG
|
|
19
|
+
grammar CodeFmt version "1" {
|
|
20
|
+
code = ( 1*%x30-39 ) as code
|
|
21
|
+
entry code: code
|
|
22
|
+
bindings code {
|
|
23
|
+
code -> code (string)
|
|
24
|
+
}
|
|
25
|
+
test { accept "42" }
|
|
26
|
+
}
|
|
27
|
+
PARG
|
|
28
|
+
document = Parsanol::PARG::Parser.new(source).parse
|
|
29
|
+
envelope = Parsanol::PARG::Compiler.compile(document).envelope
|
|
30
|
+
# A Tempfile is GC-unlinked when the object goes out of scope, so
|
|
31
|
+
# the path must outlive the helper: a real directory file keeps the
|
|
32
|
+
# artifact alive for the suite's duration.
|
|
33
|
+
dir = Dir.mktmpdir("code-artifact")
|
|
34
|
+
path = File.join(dir, "code.artifact.json")
|
|
35
|
+
File.write(path, JSON.generate(envelope.respond_to?(:to_h) ? envelope.to_h : envelope))
|
|
36
|
+
path
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe "isa instance-type override (L6)" do
|
|
40
|
+
it "routes hydration through isa and keeps type as data" do
|
|
41
|
+
compiler = compile_lml(<<~LML)
|
|
42
|
+
models M {
|
|
43
|
+
class Item {
|
|
44
|
+
attribute type { type String cardinality 0..1 }
|
|
45
|
+
attribute size { type String cardinality 1 }
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
LML
|
|
49
|
+
data = Tempfile.new(%w[d .lml])
|
|
50
|
+
data.write("instance Item {\n isa Item\n type = \"standard\"\n size = \"L\"\n}\n")
|
|
51
|
+
data.rewind
|
|
52
|
+
item = compiler.hydrate(data)
|
|
53
|
+
expect(item).to be_a(compiler.compiled_classes["Item"])
|
|
54
|
+
expect(item.type).to eq("standard")
|
|
55
|
+
expect(item.size).to eq("L")
|
|
56
|
+
ensure
|
|
57
|
+
data.close!
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
describe "attribute defaults and render_nil (L7b)" do
|
|
62
|
+
it "compiles declared default literals and render_nil" do
|
|
63
|
+
compiler = compile_lml(<<~LML)
|
|
64
|
+
models M {
|
|
65
|
+
class C {
|
|
66
|
+
attribute originator { type String cardinality 0..1 default "iso" }
|
|
67
|
+
attribute remark { type String cardinality 0..1 render_nil true }
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
LML
|
|
71
|
+
options = compiler.compiled_classes["C"].attributes[:originator].options
|
|
72
|
+
expect(options[:default]).to eq("iso")
|
|
73
|
+
remark_rule = compiler.compiled_classes["C"].mappings_for(:yaml)
|
|
74
|
+
.mappings.find { |rule| rule.name == "remark" }
|
|
75
|
+
expect(remark_rule.render_nil).to be(true)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
describe "derive declarations (L7b)" do
|
|
80
|
+
it "declares the attribute and records the derivation" do
|
|
81
|
+
compiler = compile_lml(<<~LML)
|
|
82
|
+
models M {
|
|
83
|
+
class Doc {
|
|
84
|
+
attribute urn { type String cardinality 0..1 }
|
|
85
|
+
derive tiny: String
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
LML
|
|
89
|
+
klass = compiler.compiled_classes["Doc"]
|
|
90
|
+
expect(klass.attributes).to have_key(:tiny)
|
|
91
|
+
expect(klass.derived_fields).to eq([:tiny])
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
describe "enum member payloads (L7a)" do
|
|
96
|
+
it "carries typed payloads on members" do
|
|
97
|
+
compiler = compile_lml(<<~LML)
|
|
98
|
+
models M {
|
|
99
|
+
enum Stage {
|
|
100
|
+
member_fields { abbreviation String urn_segment String }
|
|
101
|
+
draft10 { abbreviation = "WD" urn_segment = "wd" }
|
|
102
|
+
published { abbreviation = "IS" urn_segment = "published" }
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
LML
|
|
106
|
+
stage = compiler.compiled_classes["Stage"]
|
|
107
|
+
expect(stage.draft10.abbreviation).to eq("WD")
|
|
108
|
+
expect(stage.published.urn_segment).to eq("published")
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it "rejects undeclared payload fields" do
|
|
112
|
+
expect do
|
|
113
|
+
compile_lml(<<~LML)
|
|
114
|
+
models M {
|
|
115
|
+
enum Stage {
|
|
116
|
+
member_fields { abbreviation String }
|
|
117
|
+
draft10 { abbreviation = "WD" oops = "x" }
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
LML
|
|
121
|
+
end.to raise_error(ArgumentError, /undeclared payload fields/)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
describe "string_format declarations (L5)" do
|
|
126
|
+
let(:artifact_path) { write_grammar_artifact }
|
|
127
|
+
|
|
128
|
+
it "registers a grammar-backed format on the class" do
|
|
129
|
+
compiler = Lutaml::Lml::ModelCompiler.new(
|
|
130
|
+
artifact_paths: { "code_fmt" => artifact_path },
|
|
131
|
+
)
|
|
132
|
+
source = Tempfile.new(%w[test .lml])
|
|
133
|
+
source.write(<<~LML)
|
|
134
|
+
models M {
|
|
135
|
+
class Widget {
|
|
136
|
+
attribute code { type String cardinality 1 }
|
|
137
|
+
string_format code_id {
|
|
138
|
+
artifact "code_fmt"
|
|
139
|
+
root "code"
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
LML
|
|
144
|
+
source.rewind
|
|
145
|
+
compiler.compile(source)
|
|
146
|
+
widget = compiler.compiled_classes["Widget"]
|
|
147
|
+
expect(widget).to respond_to(:from_code_id)
|
|
148
|
+
expect(widget.from_code_id("42").code).to eq("42")
|
|
149
|
+
ensure
|
|
150
|
+
source.close!
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
describe "RS 3001 canonical value construct" do
|
|
155
|
+
it "compiles value members with descriptions and payloads" do
|
|
156
|
+
compiler = compile_lml(<<~LML)
|
|
157
|
+
models M {
|
|
158
|
+
enum Finish {
|
|
159
|
+
member_fields { label String }
|
|
160
|
+
value "Celadon" {
|
|
161
|
+
definition "Pale green glaze"
|
|
162
|
+
label = "cel"
|
|
163
|
+
}
|
|
164
|
+
value matte { definition "Non-reflective" }
|
|
165
|
+
gloss
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
LML
|
|
169
|
+
finish = compiler.compiled_classes["Finish"]
|
|
170
|
+
expect(finish.values.map(&:name)).to eq(["Celadon", "matte", "gloss"])
|
|
171
|
+
expect(finish.values.first.description).to eq("Pale green glaze")
|
|
172
|
+
expect(finish.values.first.payload).to eq("label" => "cel")
|
|
173
|
+
expect(finish.matte.value).to eq("matte")
|
|
174
|
+
expect(finish.gloss.value).to eq("gloss")
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
it "treats quoted member names as canonical values with safe accessors" do
|
|
178
|
+
compiler = compile_lml(<<~LML)
|
|
179
|
+
models M {
|
|
180
|
+
enum Glaze {
|
|
181
|
+
value "Raku Glaze" { }
|
|
182
|
+
plain
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
LML
|
|
186
|
+
glaze = compiler.compiled_classes["Glaze"]
|
|
187
|
+
expect(glaze.values.map(&:name)).to eq(["Raku Glaze", "plain"])
|
|
188
|
+
expect(glaze.Raku_Glaze.value).to eq("Raku Glaze")
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
describe "RS 3001 comma attribute form" do
|
|
193
|
+
it "compiles `attribute name, Type { ... }` like the keyword form" do
|
|
194
|
+
compiler = compile_lml(<<~LML)
|
|
195
|
+
models M {
|
|
196
|
+
class Ceramic {
|
|
197
|
+
attribute location, String { cardinality 0..n }
|
|
198
|
+
attribute firing, String
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
LML
|
|
202
|
+
klass = compiler.compiled_classes["Ceramic"]
|
|
203
|
+
expect(klass.attributes.keys).to include(:location, :firing)
|
|
204
|
+
inst = klass.new(location: "kiln", firing: "low")
|
|
205
|
+
expect(inst.location).to eq(["kiln"])
|
|
206
|
+
expect(inst.firing).to eq("low")
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
describe "RS 3001 attribute values argument" do
|
|
211
|
+
it "expands an inline value set into an anonymous enum" do
|
|
212
|
+
compiler = compile_lml(<<~LML)
|
|
213
|
+
models M {
|
|
214
|
+
class Tile {
|
|
215
|
+
attribute status, String { values { draft, published } }
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
LML
|
|
219
|
+
status_type = compiler.compiled_classes["Tile"].attributes[:status].type
|
|
220
|
+
expect(status_type).to be_a(Class)
|
|
221
|
+
expect(status_type.values.map(&:name)).to eq(%w[draft published])
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
it "types the attribute with a referenced enum" do
|
|
225
|
+
compiler = compile_lml(<<~LML)
|
|
226
|
+
models M {
|
|
227
|
+
enum Finish { celadon matte }
|
|
228
|
+
class Tile {
|
|
229
|
+
attribute finish, String { values Finish }
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
LML
|
|
233
|
+
finish_type = compiler.compiled_classes["Tile"].attributes[:finish].type
|
|
234
|
+
expect(finish_type).to be(compiler.compiled_classes["Finish"])
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
describe "RS 3001 single-line definition" do
|
|
239
|
+
it "sets the entity definition from the quoted form" do
|
|
240
|
+
doc = Lutaml::Lml.parse_document(<<~LML)
|
|
241
|
+
models M {
|
|
242
|
+
enum Stage {
|
|
243
|
+
definition "Stage codes"
|
|
244
|
+
draft
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
LML
|
|
248
|
+
expect(doc.enums.first.definition).to eq("Stage codes")
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
describe "RS 3001 ref: reference spelling" do
|
|
253
|
+
it "parses ref:(...) identically to reference:(...)" do
|
|
254
|
+
src = lambda do |keyword|
|
|
255
|
+
"instances {\n Product \"p\" {\n r = #{keyword}:(Product.id)\n }\n}\n"
|
|
256
|
+
end
|
|
257
|
+
from_ref = Lutaml::Lml.parse_document(src.call("ref"))
|
|
258
|
+
from_full = Lutaml::Lml.parse_document(src.call("reference"))
|
|
259
|
+
ref_attr = from_ref.instances.instances.first.attributes.find { |a| a.name == "r" }
|
|
260
|
+
full_attr = from_full.instances.instances.first.attributes.find { |a| a.name == "r" }
|
|
261
|
+
expect(ref_attr.value.value).to eq(full_attr.value.value)
|
|
262
|
+
expect(ref_attr.reference).to be_a(Lutaml::Lml::Reference)
|
|
263
|
+
expect(ref_attr.reference.path).to eq("Product.id")
|
|
264
|
+
end
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
describe "enum from_table (L7a, artifact-table reference)" do
|
|
268
|
+
it "bakes artifact table rows as members at compile time" do
|
|
269
|
+
artifact_path = write_grammar_artifact
|
|
270
|
+
envelope = JSON.parse(File.read(artifact_path))
|
|
271
|
+
envelope["tables"] = {
|
|
272
|
+
"stages" => {
|
|
273
|
+
"file" => "stages.yaml",
|
|
274
|
+
"rows" => [
|
|
275
|
+
{ "name" => "draft10", "abbreviation" => "WD", "urn_segment" => "wd" },
|
|
276
|
+
{ "name" => "published", "abbreviation" => "IS", "urn_segment" => "published" },
|
|
277
|
+
{ "name" => "withdrawn", "abbreviation" => nil },
|
|
278
|
+
],
|
|
279
|
+
},
|
|
280
|
+
}
|
|
281
|
+
File.write(artifact_path, JSON.generate(envelope))
|
|
282
|
+
|
|
283
|
+
compiler = Lutaml::Lml::ModelCompiler.new(
|
|
284
|
+
artifact_paths: { "code_fmt" => artifact_path },
|
|
285
|
+
)
|
|
286
|
+
source = Tempfile.new(%w[test .lml])
|
|
287
|
+
source.write(<<~LML)
|
|
288
|
+
models M {
|
|
289
|
+
enum Stage {
|
|
290
|
+
member_fields { abbreviation String urn_segment String }
|
|
291
|
+
from_table "stages" {
|
|
292
|
+
artifact "code_fmt"
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
LML
|
|
297
|
+
source.rewind
|
|
298
|
+
compiler.compile(source)
|
|
299
|
+
|
|
300
|
+
stage = compiler.compiled_classes["Stage"]
|
|
301
|
+
expect(stage.draft10.abbreviation).to eq("WD")
|
|
302
|
+
expect(stage.published.urn_segment).to eq("published")
|
|
303
|
+
expect(stage.withdrawn.abbreviation).to be_nil
|
|
304
|
+
expect(stage.values.map(&:name)).to eq(%w[draft10 published withdrawn])
|
|
305
|
+
ensure
|
|
306
|
+
source.close!
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
it "rejects unknown table fields" do
|
|
310
|
+
artifact_path = write_grammar_artifact
|
|
311
|
+
envelope = JSON.parse(File.read(artifact_path))
|
|
312
|
+
envelope["tables"] = {
|
|
313
|
+
"stages" => { "file" => "stages.yaml", "rows" => [{ "name" => "draft10", "oops" => "x" }] },
|
|
314
|
+
}
|
|
315
|
+
File.write(artifact_path, JSON.generate(envelope))
|
|
316
|
+
|
|
317
|
+
compiler = Lutaml::Lml::ModelCompiler.new(
|
|
318
|
+
artifact_paths: { "code_fmt" => artifact_path },
|
|
319
|
+
)
|
|
320
|
+
source = Tempfile.new(%w[test .lml])
|
|
321
|
+
source.write(<<~LML)
|
|
322
|
+
models M {
|
|
323
|
+
enum Stage {
|
|
324
|
+
member_fields { abbreviation String }
|
|
325
|
+
from_table "stages" {
|
|
326
|
+
artifact "code_fmt"
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
LML
|
|
331
|
+
source.rewind
|
|
332
|
+
expect { compiler.compile(source) }.to raise_error(ArgumentError, /undeclared fields/)
|
|
333
|
+
ensure
|
|
334
|
+
source.close!
|
|
335
|
+
end
|
|
336
|
+
end
|
|
337
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require_relative "../../lml_spec_setup"
|
|
5
|
+
|
|
6
|
+
RSpec.describe Lutaml::Lml::DocumentBuilder, ".default_registry" do
|
|
7
|
+
let(:registry) { described_class.default_registry }
|
|
8
|
+
|
|
9
|
+
it "is a Hash" do
|
|
10
|
+
expect(registry).to be_a(Hash)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "is frozen" do
|
|
14
|
+
expect(registry).to be_frozen
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "maps all builder keys to LML model classes" do
|
|
18
|
+
aggregate_failures do
|
|
19
|
+
expect(registry[:document]).to eq(Lutaml::Lml::Document)
|
|
20
|
+
expect(registry[:package]).to eq(Lutaml::Lml::Package)
|
|
21
|
+
expect(registry[:class]).to eq(Lutaml::Lml::UmlClass)
|
|
22
|
+
expect(registry[:enum]).to eq(Lutaml::Lml::Enum)
|
|
23
|
+
expect(registry[:data_type]).to eq(Lutaml::Lml::DataType)
|
|
24
|
+
expect(registry[:diagram]).to eq(Lutaml::Lml::Diagram)
|
|
25
|
+
expect(registry[:attribute]).to eq(Lutaml::Lml::TopElementAttribute)
|
|
26
|
+
expect(registry[:cardinality]).to eq(Lutaml::Lml::Cardinality)
|
|
27
|
+
expect(registry[:association]).to eq(Lutaml::Lml::Association)
|
|
28
|
+
expect(registry[:operation]).to eq(Lutaml::Lml::Operation)
|
|
29
|
+
expect(registry[:constraint]).to eq(Lutaml::Lml::Constraint)
|
|
30
|
+
expect(registry[:value]).to eq(Lutaml::Lml::Value)
|
|
31
|
+
expect(registry[:view_import]).to eq(Lutaml::Lml::ViewImport)
|
|
32
|
+
expect(registry[:view_filter]).to eq(Lutaml::Lml::ViewFilter)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "uses itself as the default constructor argument" do
|
|
37
|
+
builder = described_class.new
|
|
38
|
+
expect(builder.registry).to eq(registry)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "accepts a custom registry" do
|
|
42
|
+
custom = { document: Lutaml::Lml::Document }
|
|
43
|
+
builder = described_class.new(custom)
|
|
44
|
+
expect(builder.registry).to eq(custom)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe "LmlConverter is no longer defined (regression guard)" do
|
|
48
|
+
it "is not present in the Lml namespace" do
|
|
49
|
+
expect(Lutaml::Lml.constants).not_to include(:LmlConverter)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require_relative "../../lml_spec_setup"
|
|
5
|
+
|
|
6
|
+
RSpec.describe Lutaml::Lml::DocumentBuilder do
|
|
7
|
+
let(:registry) { described_class.default_registry }
|
|
8
|
+
let(:builder) { described_class.new(registry) }
|
|
9
|
+
|
|
10
|
+
describe "#build" do
|
|
11
|
+
it "creates a document from a hash" do
|
|
12
|
+
doc = builder.build(:document, { title: "Test" })
|
|
13
|
+
expect(doc).to be_a(Lutaml::Lml::Document)
|
|
14
|
+
expect(doc.title).to eq("Test")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "creates a class with name" do
|
|
18
|
+
klass = builder.build(:class, { name: "MyClass" })
|
|
19
|
+
expect(klass).to be_a(Lutaml::Lml::UmlClass)
|
|
20
|
+
expect(klass.name).to eq("MyClass")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "creates an enum" do
|
|
24
|
+
enum = builder.build(:enum, { name: "Color" })
|
|
25
|
+
expect(enum).to be_a(Lutaml::Lml::Enum)
|
|
26
|
+
expect(enum.name).to eq("Color")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "creates an attribute with type" do
|
|
30
|
+
attr = builder.build(:attribute, { name: "id", type: "String" })
|
|
31
|
+
expect(attr).to be_a(Lutaml::Lml::TopElementAttribute)
|
|
32
|
+
expect(attr.name).to eq("id")
|
|
33
|
+
expect(attr.type).to eq("String")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "creates a cardinality" do
|
|
37
|
+
card = builder.build(:cardinality, { min: "0", max: "*" })
|
|
38
|
+
expect(card).to be_a(Lutaml::Lml::Cardinality)
|
|
39
|
+
expect(card.min).to eq("0")
|
|
40
|
+
expect(card.max).to eq("*")
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe "#build with members" do
|
|
45
|
+
it "builds nested members from members key" do
|
|
46
|
+
hash = {
|
|
47
|
+
title: "Doc",
|
|
48
|
+
members: [
|
|
49
|
+
{ classes: { name: "ClassA" } },
|
|
50
|
+
{ enums: { name: "EnumA" } },
|
|
51
|
+
],
|
|
52
|
+
}
|
|
53
|
+
doc = builder.build(:document, hash)
|
|
54
|
+
expect(doc.title).to eq("Doc")
|
|
55
|
+
expect(doc.classes.length).to eq(1)
|
|
56
|
+
expect(doc.enums.length).to eq(1)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "appends to existing collections" do
|
|
60
|
+
doc = builder.build(:document, {
|
|
61
|
+
title: "First",
|
|
62
|
+
members: [{ classes: { name: "ClassA" } }],
|
|
63
|
+
})
|
|
64
|
+
expect(doc.classes.length).to eq(1)
|
|
65
|
+
expect(doc.classes.first.name).to eq("ClassA")
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
describe "with the default registry" do
|
|
70
|
+
it "creates LML-specific models" do
|
|
71
|
+
doc = builder.build(:document, {})
|
|
72
|
+
expect(doc).to be_a(Lutaml::Lml::Document)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "creates LML UmlClass with parent_class" do
|
|
76
|
+
klass = builder.build(:class, { name: "Child", parent_class: "Parent" })
|
|
77
|
+
expect(klass).to be_a(Lutaml::Lml::UmlClass)
|
|
78
|
+
expect(klass.parent_class).to eq("Parent")
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
describe "registry" do
|
|
83
|
+
it "maps document to LML Document" do
|
|
84
|
+
expect(registry[:document]).to eq(Lutaml::Lml::Document)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "maps class to LML UmlClass" do
|
|
88
|
+
expect(registry[:class]).to eq(Lutaml::Lml::UmlClass)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "maps all factory types" do
|
|
92
|
+
expect(registry.keys).to include(
|
|
93
|
+
:document, :class, :enum, :data_type, :attribute,
|
|
94
|
+
:association, :operation, :constraint, :value, :cardinality,
|
|
95
|
+
:diagram, :view_import, :view_filter
|
|
96
|
+
)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe "Element visibility modifier" do
|
|
6
|
+
def parse(src)
|
|
7
|
+
Lutaml::Lml.parse_document(StringIO.new(src))
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "defaults to public" do
|
|
11
|
+
doc = parse("class Foo { }\n")
|
|
12
|
+
expect(doc.classes.first.visibility).to eq("public")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
%w[public private protected package].each do |level|
|
|
16
|
+
it "parses #{level} on a class" do
|
|
17
|
+
doc = parse("#{level} class Foo { }\n")
|
|
18
|
+
expect(doc.classes.first.visibility).to eq(level)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "parses visibility on enums, data types and package contents" do
|
|
23
|
+
doc = parse(<<~LML)
|
|
24
|
+
private enum Finish { matte }
|
|
25
|
+
protected data_type MyString { }
|
|
26
|
+
package Pkg {
|
|
27
|
+
private class Hidden { }
|
|
28
|
+
public enum Open { a }
|
|
29
|
+
}
|
|
30
|
+
LML
|
|
31
|
+
expect(doc.enums.first.visibility).to eq("private")
|
|
32
|
+
expect(doc.data_types.first.visibility).to eq("protected")
|
|
33
|
+
expect(doc.packages.first.classes.first.visibility).to eq("private")
|
|
34
|
+
expect(doc.packages.first.enums.first.visibility).to eq("public")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "combines with the abstract/interface modifier" do
|
|
38
|
+
doc = parse("private abstract class Base { }\n")
|
|
39
|
+
expect(doc.classes.first.visibility).to eq("private")
|
|
40
|
+
expect(doc.classes.first.modifier).to eq("abstract")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "binds `package class` as a package-visible class, not a package named class" do
|
|
44
|
+
doc = parse("package class Foo { }\n")
|
|
45
|
+
expect(doc.packages).to be_empty
|
|
46
|
+
expect(doc.classes.first.name).to eq("Foo")
|
|
47
|
+
expect(doc.classes.first.visibility).to eq("package")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe "canonical in-block declarations (par. Declaration modifiers)" do
|
|
51
|
+
it "sets visibility from the block declaration" do
|
|
52
|
+
doc = parse(<<~LML)
|
|
53
|
+
class Glaze {
|
|
54
|
+
visibility private
|
|
55
|
+
attribute color, String
|
|
56
|
+
}
|
|
57
|
+
LML
|
|
58
|
+
expect(doc.classes.first.visibility).to eq("private")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "maps abstract true/false onto is_abstract" do
|
|
62
|
+
doc = parse(<<~LML)
|
|
63
|
+
class Base { abstract true }
|
|
64
|
+
class Leaf { abstract false }
|
|
65
|
+
LML
|
|
66
|
+
expect(doc.classes.first.is_abstract).to be(true)
|
|
67
|
+
expect(doc.classes.last.is_abstract).to be(false)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "applies to enum bodies" do
|
|
71
|
+
doc = parse("enum Finish {\n visibility protected\n matte\n}\n")
|
|
72
|
+
expect(doc.enums.first.visibility).to eq("protected")
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "applies to data_type bodies" do
|
|
76
|
+
doc = parse("data_type MyString {\n visibility private\n}\n")
|
|
77
|
+
expect(doc.data_types.first.visibility).to eq("private")
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "expands the abstract prefix to the canonical declaration" do
|
|
81
|
+
doc = parse("abstract class Base { }\n")
|
|
82
|
+
expect(doc.classes.first.is_abstract).to be(true)
|
|
83
|
+
expect(doc.classes.first.modifier).to eq("abstract")
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
describe "visibility inside models blocks" do
|
|
88
|
+
%w[public private protected package].each do |level|
|
|
89
|
+
it "parses #{level} on a class inside models" do
|
|
90
|
+
doc = parse("models P {\n #{level} class C { attribute a, String }\n}\n")
|
|
91
|
+
expect(doc.classes.first.visibility).to eq(level)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it "parses all visibility levels on class/enum/data_type inside models" do
|
|
96
|
+
doc = parse(<<~LML)
|
|
97
|
+
models P {
|
|
98
|
+
private class Hidden { }
|
|
99
|
+
public enum Open { a }
|
|
100
|
+
protected data_type Safe { }
|
|
101
|
+
}
|
|
102
|
+
LML
|
|
103
|
+
expect(doc.classes.first.visibility).to eq("private")
|
|
104
|
+
expect(doc.enums.first.visibility).to eq("public")
|
|
105
|
+
expect(doc.data_types.first.visibility).to eq("protected")
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "combines with abstract modifier inside models" do
|
|
109
|
+
doc = parse("models P {\n private abstract class Base { }\n}\n")
|
|
110
|
+
expect(doc.classes.first.visibility).to eq("private")
|
|
111
|
+
expect(doc.classes.first.modifier).to eq("abstract")
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
describe "package visibility" do
|
|
116
|
+
it "parses visibility on package declarations" do
|
|
117
|
+
doc = parse("private package Ceramics {\n class Tile { }\n}\n")
|
|
118
|
+
expect(doc.packages.first.visibility).to eq("private")
|
|
119
|
+
expect(doc.packages.first.classes.first.name).to eq("Tile")
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it "keeps bare package declarations binding as packages" do
|
|
123
|
+
doc = parse("package Ceramics {\n class Tile { }\n}\n")
|
|
124
|
+
expect(doc.packages.first.name).to eq("Ceramics")
|
|
125
|
+
expect(doc.packages.first.classes.first.name).to eq("Tile")
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require "tmpdir"
|
|
5
|
+
require "fileutils"
|
|
6
|
+
|
|
7
|
+
RSpec.describe Lutaml::Lml::EntityTypes do
|
|
8
|
+
it "registers all four entity models" do
|
|
9
|
+
expect(described_class.all).to eq(
|
|
10
|
+
[
|
|
11
|
+
Lutaml::Lml::UmlClass,
|
|
12
|
+
Lutaml::Lml::Enum,
|
|
13
|
+
Lutaml::Lml::DataType,
|
|
14
|
+
Lutaml::Lml::PrimitiveType,
|
|
15
|
+
],
|
|
16
|
+
)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "indexes models by their declared entity_type symbol" do
|
|
20
|
+
expect(described_class.by_symbol).to eq(
|
|
21
|
+
classes: Lutaml::Lml::UmlClass,
|
|
22
|
+
enums: Lutaml::Lml::Enum,
|
|
23
|
+
data_types: Lutaml::Lml::DataType,
|
|
24
|
+
primitives: Lutaml::Lml::PrimitiveType,
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "excludes enums from classifiable types" do
|
|
29
|
+
expect(described_class.classifiable).not_to include(Lutaml::Lml::Enum)
|
|
30
|
+
expect(described_class.classifiable).to include(Lutaml::Lml::UmlClass)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "keeps every entity_type symbol a Document collection reader" do
|
|
34
|
+
doc = Lutaml::Lml::Document.new
|
|
35
|
+
described_class.symbols.each do |symbol|
|
|
36
|
+
expect { doc.public_send(symbol) }.not_to raise_error
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "preserves imported primitives through view resolution" do
|
|
41
|
+
dir = Dir.mktmpdir
|
|
42
|
+
model = File.join(dir, "model.lutaml")
|
|
43
|
+
File.write(model, <<~LML)
|
|
44
|
+
class Foo { }
|
|
45
|
+
primitive Bar
|
|
46
|
+
LML
|
|
47
|
+
view = File.join(dir, "view.lutaml")
|
|
48
|
+
File.write(view, 'view V { import "model.lutaml" }')
|
|
49
|
+
|
|
50
|
+
doc = Lutaml::Lml.parse(File.open(view))
|
|
51
|
+
expect(doc.classes.map(&:name)).to eq(["Foo"])
|
|
52
|
+
expect(doc.primitives.map(&:name)).to eq(["Bar"])
|
|
53
|
+
ensure
|
|
54
|
+
FileUtils.rm_rf(dir)
|
|
55
|
+
end
|
|
56
|
+
end
|