lutaml-model 0.8.186 → 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.
Files changed (308) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/dependent-repos-tools-informational.json +8 -0
  3. data/.github/workflows/dependent-repos-tools.json +1 -5
  4. data/.github/workflows/dependent-tests.yml +26 -2
  5. data/Gemfile +2 -0
  6. data/Rakefile +6 -0
  7. data/exe/lutaml-lml-lsp +11 -0
  8. data/lib/compat/opal/generate_boot.rb +12 -5
  9. data/lib/compat/opal/lutaml_model_boot.rb +96 -4
  10. data/lib/lutaml/lml/association_label_resolver.rb +52 -0
  11. data/lib/lutaml/lml/data_processor/attribute_processing.rb +133 -0
  12. data/lib/lutaml/lml/data_processor/collection_processing.rb +37 -0
  13. data/lib/lutaml/lml/data_processor/instance_processing.rb +77 -0
  14. data/lib/lutaml/lml/data_processor/value_declaration_processing.rb +70 -0
  15. data/lib/lutaml/lml/data_processor/value_processing.rb +103 -0
  16. data/lib/lutaml/lml/data_processor/view_processing.rb +26 -0
  17. data/lib/lutaml/lml/data_processor.rb +66 -0
  18. data/lib/lutaml/lml/diagnostic.rb +149 -0
  19. data/lib/lutaml/lml/document_builder.rb +486 -0
  20. data/lib/lutaml/lml/entity_types.rb +31 -0
  21. data/lib/lutaml/lml/executor/adapter_helpers.rb +45 -0
  22. data/lib/lutaml/lml/executor/condition_evaluator.rb +175 -0
  23. data/lib/lutaml/lml/executor/csv_adapter.rb +89 -0
  24. data/lib/lutaml/lml/executor/format_adapter.rb +54 -0
  25. data/lib/lutaml/lml/executor/xml_adapter.rb +102 -0
  26. data/lib/lutaml/lml/executor.rb +96 -0
  27. data/lib/lutaml/lml/format/adapter/document.rb +11 -0
  28. data/lib/lutaml/lml/format/adapter/mapping.rb +31 -0
  29. data/lib/lutaml/lml/format/adapter/standard_adapter.rb +164 -0
  30. data/lib/lutaml/lml/format/adapter/transform.rb +11 -0
  31. data/lib/lutaml/lml/format.rb +34 -0
  32. data/lib/lutaml/lml/formatter/base.rb +81 -0
  33. data/lib/lutaml/lml/formatter/canonical.rb +738 -0
  34. data/lib/lutaml/lml/formatter.rb +11 -0
  35. data/lib/lutaml/lml/grammar/lml.artifact.json +14993 -0
  36. data/lib/lutaml/lml/grammar/lml.parg +389 -0
  37. data/lib/lutaml/lml/grammar.rb +60 -0
  38. data/lib/lutaml/lml/has_attributes.rb +14 -0
  39. data/lib/lutaml/lml/import_resolver.rb +96 -0
  40. data/lib/lutaml/lml/layout/engine.rb +17 -0
  41. data/lib/lutaml/lml/layout.rb +9 -0
  42. data/lib/lutaml/lml/literal_value.rb +32 -0
  43. data/lib/lutaml/lml/lsp/conversions.rb +78 -0
  44. data/lib/lutaml/lml/lsp/keywords.rb +43 -0
  45. data/lib/lutaml/lml/lsp/server.rb +380 -0
  46. data/lib/lutaml/lml/lsp/store.rb +68 -0
  47. data/lib/lutaml/lml/lsp/transport.rb +53 -0
  48. data/lib/lutaml/lml/lsp.rb +16 -0
  49. data/lib/lutaml/lml/model_compiler/enums.rb +170 -0
  50. data/lib/lutaml/lml/model_compiler/hydration.rb +122 -0
  51. data/lib/lutaml/lml/model_compiler/serialization_mappings.rb +188 -0
  52. data/lib/lutaml/lml/model_compiler/string_formats.rb +42 -0
  53. data/lib/lutaml/lml/model_compiler/validation.rb +65 -0
  54. data/lib/lutaml/lml/model_compiler.rb +329 -0
  55. data/lib/lutaml/lml/models/action.rb +10 -0
  56. data/lib/lutaml/lml/models/association.rb +31 -0
  57. data/lib/lutaml/lml/models/cardinality.rb +10 -0
  58. data/lib/lutaml/lml/models/collection.rb +11 -0
  59. data/lib/lutaml/lml/models/constraint.rb +25 -0
  60. data/lib/lutaml/lml/models/data_type.rb +43 -0
  61. data/lib/lutaml/lml/models/derived_field.rb +14 -0
  62. data/lib/lutaml/lml/models/diagram.rb +22 -0
  63. data/lib/lutaml/lml/models/document.rb +86 -0
  64. data/lib/lutaml/lml/models/enum.rb +40 -0
  65. data/lib/lutaml/lml/models/fidelity.rb +10 -0
  66. data/lib/lutaml/lml/models/group.rb +11 -0
  67. data/lib/lutaml/lml/models/instance.rb +28 -0
  68. data/lib/lutaml/lml/models/instance_collection.rb +18 -0
  69. data/lib/lutaml/lml/models/instances_export.rb +10 -0
  70. data/lib/lutaml/lml/models/instances_import.rb +11 -0
  71. data/lib/lutaml/lml/models/mapping.rb +15 -0
  72. data/lib/lutaml/lml/models/mapping_rule.rb +16 -0
  73. data/lib/lutaml/lml/models/member_field.rb +16 -0
  74. data/lib/lutaml/lml/models/namespace.rb +18 -0
  75. data/lib/lutaml/lml/models/operation.rb +28 -0
  76. data/lib/lutaml/lml/models/operation_parameter.rb +12 -0
  77. data/lib/lutaml/lml/models/package.rb +28 -0
  78. data/lib/lutaml/lml/models/primitive_type.rb +35 -0
  79. data/lib/lutaml/lml/models/reference.rb +23 -0
  80. data/lib/lutaml/lml/models/serialization_mapping.rb +21 -0
  81. data/lib/lutaml/lml/models/string_format.rb +16 -0
  82. data/lib/lutaml/lml/models/top_element_attribute.rb +118 -0
  83. data/lib/lutaml/lml/models/uml_class.rb +87 -0
  84. data/lib/lutaml/lml/models/value.rb +17 -0
  85. data/lib/lutaml/lml/models/view_filter.rb +11 -0
  86. data/lib/lutaml/lml/models/view_import.rb +11 -0
  87. data/lib/lutaml/lml/parser.rb +19 -0
  88. data/lib/lutaml/lml/pipeline.rb +73 -0
  89. data/lib/lutaml/lml/positioned.rb +13 -0
  90. data/lib/lutaml/lml/preprocessor.rb +132 -0
  91. data/lib/lutaml/lml/quoting.rb +60 -0
  92. data/lib/lutaml/lml/source.rb +49 -0
  93. data/lib/lutaml/lml/source_position.rb +20 -0
  94. data/lib/lutaml/lml/symbol_index.rb +202 -0
  95. data/lib/lutaml/lml/transform.rb +119 -0
  96. data/lib/lutaml/lml/types/text_type.rb +28 -0
  97. data/lib/lutaml/lml/types.rb +10 -0
  98. data/lib/lutaml/lml/validator.rb +460 -0
  99. data/lib/lutaml/lml/view_resolution.rb +32 -0
  100. data/lib/lutaml/lml/view_resolver.rb +48 -0
  101. data/lib/lutaml/lml/yaml_parser.rb +17 -0
  102. data/lib/lutaml/lml.rb +130 -0
  103. data/lib/lutaml/model/adapter_resolver.rb +21 -2
  104. data/lib/lutaml/model/config.rb +22 -0
  105. data/lib/lutaml/model/serialize/format_conversion.rb +8 -6
  106. data/lib/lutaml/model/version.rb +1 -1
  107. data/lib/lutaml/xml/adapter/base_adapter.rb +26 -0
  108. data/lib/lutaml/xml/adapter/moxml_adapter.rb +49 -0
  109. data/lib/lutaml/xml/adapter/xml_parser.rb +4 -4
  110. data/lib/lutaml/xml/adapter/xml_serializer.rb +1 -1
  111. data/lib/lutaml/xml/adapter.rb +5 -0
  112. data/lib/lutaml/xml/adapter_loader.rb +5 -0
  113. data/lib/lutaml/xml/format.rb +23 -2
  114. data/lib/lutaml/xml/leptris/native_emission.rb +6 -1
  115. data/lib/lutaml/xml/leptris/plan_serializer.rb +5 -1
  116. data/lib/lutaml/xml/parse_session.rb +8 -1
  117. data/lib/lutaml/xml/schema/builder/moxml.rb +1 -1
  118. data/lib/lutaml/xml/schema/builder.rb +1 -1
  119. data/lib/lutaml/xml/schema/relaxng_schema.rb +1 -1
  120. data/lib/lutaml/xml/schema/vc_namespace.rb +24 -0
  121. data/lib/lutaml/xml/schema/xsd/any.rb +4 -0
  122. data/lib/lutaml/xml/schema/xsd/any_attribute.rb +4 -0
  123. data/lib/lutaml/xml/schema/xsd/base.rb +7 -0
  124. data/lib/lutaml/xml/schema/xsd/open_content.rb +2 -0
  125. data/lib/lutaml/xml/schema/xsd/restriction_simple_type.rb +3 -0
  126. data/lib/lutaml/xml/schema/xsd/schema.rb +38 -0
  127. data/lib/lutaml/xml/schema/xsd/schema_validator.rb +1 -1
  128. data/lib/lutaml/xml/schema/xsd.rb +1 -0
  129. data/lib/lutaml/xml/schema/xsd_schema.rb +1 -1
  130. data/lib/lutaml/xml/serialization/format_conversion.rb +6 -0
  131. data/lib/lutaml/xml/xsd_validator.rb +1 -1
  132. data/lutaml-model.gemspec +2 -0
  133. data/spec/lml/fixtures/dsl/broken_diagram.lutaml +34 -0
  134. data/spec/lml/fixtures/dsl/diagram.lutaml +4 -0
  135. data/spec/lml/fixtures/dsl/diagram_attributes.lutaml +6 -0
  136. data/spec/lml/fixtures/dsl/diagram_blank_definion.lutaml +6 -0
  137. data/spec/lml/fixtures/dsl/diagram_blank_entities.lutaml +8 -0
  138. data/spec/lml/fixtures/dsl/diagram_class_assocation.lutaml +29 -0
  139. data/spec/lml/fixtures/dsl/diagram_class_fields.lutaml +25 -0
  140. data/spec/lml/fixtures/dsl/diagram_commented_includes.lutaml +5 -0
  141. data/spec/lml/fixtures/dsl/diagram_comments.lutaml +28 -0
  142. data/spec/lml/fixtures/dsl/diagram_concept_model.lutaml +132 -0
  143. data/spec/lml/fixtures/dsl/diagram_data_types.lutaml +44 -0
  144. data/spec/lml/fixtures/dsl/diagram_definitions.lutaml +25 -0
  145. data/spec/lml/fixtures/dsl/diagram_includes.lutaml +6 -0
  146. data/spec/lml/fixtures/dsl/diagram_multiply_classes.lutaml +7 -0
  147. data/spec/lml/fixtures/dsl/diagram_non_existing_include.lutaml +6 -0
  148. data/spec/lml/fixtures/dsl/shared.lutaml +5 -0
  149. data/spec/lml/fixtures/dsl/shared1.lutaml +4 -0
  150. data/spec/lml/fixtures/generated_dot/AddressClassProfile.dot +170 -0
  151. data/spec/lml/fixtures/generated_dot/AddressProfile.dot +34 -0
  152. data/spec/lml/fixtures/generated_dot/address_class_profile_with_associations.dot +127 -0
  153. data/spec/lml/fixtures/generated_dot/address_profile_with_associations.dot +28 -0
  154. data/spec/lml/fixtures/generated_dot/document.dot +28 -0
  155. data/spec/lml/fixtures/generated_dot/document.dot.backup +33 -0
  156. data/spec/lml/fixtures/generated_dot/document_with_fidelity.dot +27 -0
  157. data/spec/lml/fixtures/lml/data_s102_check.lml +79 -0
  158. data/spec/lml/fixtures/lml/data_s158_metadata.lml +28 -0
  159. data/spec/lml/fixtures/lml/iho_data_models.lml +59 -0
  160. data/spec/lml/fixtures/lml/iho_s102_check.lml +101 -0
  161. data/spec/lml/fixtures/mixed_lml/diagram.lml +26 -0
  162. data/spec/lml/fixtures/mixed_lml/instances.lml +72 -0
  163. data/spec/lml/fixtures/mixed_lml/model.lml +30 -0
  164. data/spec/lml/fixtures/real_world/basicdoc-models/AdmonitionType.lutaml +32 -0
  165. data/spec/lml/fixtures/real_world/basicdoc-models/BasicBlock.lutaml +11 -0
  166. data/spec/lml/fixtures/real_world/basicdoc-models/BasicDocument.lutaml +41 -0
  167. data/spec/lml/fixtures/real_world/basicdoc-models/BasicSection.lutaml +38 -0
  168. data/spec/lml/fixtures/real_world/basicdoc-models/BibliographicItem.lutaml +6 -0
  169. data/spec/lml/fixtures/real_world/basicdoc-models/FigureBlock.lutaml +65 -0
  170. data/spec/lml/fixtures/real_world/basicdoc-models/FormattedString.lutaml +12 -0
  171. data/spec/lml/fixtures/real_world/basicdoc-models/List.lutaml +12 -0
  172. data/spec/lml/fixtures/real_world/basicdoc-models/OrderedListType.lutaml +32 -0
  173. data/spec/lml/fixtures/real_world/basicdoc-models/Signature.lutaml +22 -0
  174. data/spec/lml/fixtures/real_world/basicdoc-models/String.lutaml +2 -0
  175. data/spec/lml/fixtures/real_world/basicdoc-models/TableBlock.lutaml +60 -0
  176. data/spec/lml/fixtures/real_world/basicdoc-models/TextElement.lutaml +13 -0
  177. data/spec/lml/fixtures/real_world/basicdoc-models/Uri.lutaml +7 -0
  178. data/spec/lml/fixtures/real_world/metanorma-model-iso/BibliographicItem.lutaml +4 -0
  179. data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoAdmonitionType.lutaml +31 -0
  180. data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoBibDataExtensionType.lutaml +40 -0
  181. data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoSections.lutaml +30 -0
  182. data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoStandardDocument.lutaml +46 -0
  183. data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoTerm.lutaml +20 -0
  184. data/spec/lml/fixtures/real_world/metanorma-model-iso/StandardBibDataExtensionType.lutaml +2 -0
  185. data/spec/lml/fixtures/real_world/metanorma-model-iso/StandardDocument.lutaml +2 -0
  186. data/spec/lml/fixtures/rs3001/01_class_tail_comment.lml +5 -0
  187. data/spec/lml/fixtures/rs3001/02_definition_block.lml +9 -0
  188. data/spec/lml/fixtures/rs3001/03_package_ceramics.lml +20 -0
  189. data/spec/lml/fixtures/rs3001/04_attribute_definition_form.lml +10 -0
  190. data/spec/lml/fixtures/rs3001/05_attribute_cardinality_unbounded.lml +10 -0
  191. data/spec/lml/fixtures/rs3001/06_attribute_values_set.lml +10 -0
  192. data/spec/lml/fixtures/rs3001/07_attribute_pattern.lml +10 -0
  193. data/spec/lml/fixtures/rs3001/08_attribute_default_colon.lml +15 -0
  194. data/spec/lml/fixtures/rs3001/09_value_porcelain.lml +9 -0
  195. data/spec/lml/fixtures/rs3001/10_enum_glaze_technique.lml +19 -0
  196. data/spec/lml/fixtures/rs3001/11_enum_values_as_instances.lml +29 -0
  197. data/spec/lml/fixtures/rs3001/12_instance_named.lml +13 -0
  198. data/spec/lml/fixtures/rs3001/13_instances_collection_refs.lml +11 -0
  199. data/spec/lml/fixtures/rs3001/14_require_models.lml +7 -0
  200. data/spec/lml/fixtures/rs3001/15_comment_line.lml +1 -0
  201. data/spec/lml/fixtures/rs3001/16_comment_tail.lml +5 -0
  202. data/spec/lml/fixtures/rs3001/17_comment_documented_class.lml +5 -0
  203. data/spec/lml/fixtures/rs3001/18_comment_block.lml +4 -0
  204. data/spec/lml/fixtures/rs3001/19_top_level_instance_definition.lml +21 -0
  205. data/spec/lml/fixtures/rs3001/20_instance_typed_definition.lml +22 -0
  206. data/spec/lml/fixtures/rs3001/21_instance_collection_studios.lml +19 -0
  207. data/spec/lml/fixtures/rs3001/22_instance_collection_tiles.lml +15 -0
  208. data/spec/lml/fixtures/rs3001/23_reference_cross_collection.lml +11 -0
  209. data/spec/lml/fixtures/rs3001/24_null_and_empty.lml +15 -0
  210. data/spec/lml/fixtures/rs3001/25_string_escapes.lml +23 -0
  211. data/spec/lml/fixtures/rs3001/26_quoted_keys.lml +7 -0
  212. data/spec/lml/fixtures/test.lutaml +20 -0
  213. data/spec/lml/fixtures/test_data/components.csv +4 -0
  214. data/spec/lml/fixtures/test_data/products.xml +18 -0
  215. data/spec/lml/fixtures/uml/address_class_profile_with_associations.yml +58 -0
  216. data/spec/lml/fixtures/uml/address_profile_with_associations.yml +31 -0
  217. data/spec/lml/fixtures/uml/association.yml +11 -0
  218. data/spec/lml/fixtures/uml/class.yml +28 -0
  219. data/spec/lml/fixtures/uml/data_type.yml +30 -0
  220. data/spec/lml/fixtures/uml/diagram.yml +7 -0
  221. data/spec/lml/fixtures/uml/document.yml +44 -0
  222. data/spec/lml/fixtures/uml/document_with_fidelity.yml +47 -0
  223. data/spec/lml/fixtures/uml/enum.yml +14 -0
  224. data/spec/lml/fixtures/uml/operation.yml +8 -0
  225. data/spec/lml/fixtures/uml/package.yml +10 -0
  226. data/spec/lml/fixtures/uml/top_element.yml +11 -0
  227. data/spec/lml/fixtures/uml/top_element_attribute.yml +10 -0
  228. data/spec/lml/fixtures/uml/trigger.yml +12 -0
  229. data/spec/lml/fixtures/uml/value.yml +8 -0
  230. data/spec/lml/fixtures/view/cycle_a.lutaml +3 -0
  231. data/spec/lml/fixtures/view/cycle_b.lutaml +3 -0
  232. data/spec/lml/fixtures/view/import_model.lutaml +3 -0
  233. data/spec/lml/fixtures/view/import_view.lutaml +3 -0
  234. data/spec/lml/fixtures/view/import_with_hide.lutaml +4 -0
  235. data/spec/lml/fixtures/view/import_with_show.lutaml +4 -0
  236. data/spec/lml/fixtures/view/models/bar.lutaml +3 -0
  237. data/spec/lml/fixtures/view/models/baz.lutaml +3 -0
  238. data/spec/lml/fixtures/view/models/foo.lutaml +4 -0
  239. data/spec/lml/integration/instance_import_export_spec.rb +102 -0
  240. data/spec/lml/lml_spec_setup.rb +25 -0
  241. data/spec/lml/lutaml/lml/association_label_resolver_spec.rb +139 -0
  242. data/spec/lml/lutaml/lml/data_processor_spec.rb +274 -0
  243. data/spec/lml/lutaml/lml/declarations_spec.rb +337 -0
  244. data/spec/lml/lutaml/lml/document_builder_registry_spec.rb +52 -0
  245. data/spec/lml/lutaml/lml/document_builder_spec.rb +99 -0
  246. data/spec/lml/lutaml/lml/element_visibility_spec.rb +128 -0
  247. data/spec/lml/lutaml/lml/entity_types_spec.rb +56 -0
  248. data/spec/lml/lutaml/lml/enum_spec.rb +77 -0
  249. data/spec/lml/lutaml/lml/executor/adapter_helpers_spec.rb +96 -0
  250. data/spec/lml/lutaml/lml/executor/condition_evaluator_spec.rb +393 -0
  251. data/spec/lml/lutaml/lml/executor/csv_adapter_spec.rb +151 -0
  252. data/spec/lml/lutaml/lml/executor/format_adapter_spec.rb +31 -0
  253. data/spec/lml/lutaml/lml/executor/xml_adapter_spec.rb +201 -0
  254. data/spec/lml/lutaml/lml/executor_spec.rb +71 -0
  255. data/spec/lml/lutaml/lml/format_adapter_spec.rb +272 -0
  256. data/spec/lml/lutaml/lml/format_autoload_spec.rb +31 -0
  257. data/spec/lml/lutaml/lml/grammar_spec.rb +581 -0
  258. data/spec/lml/lutaml/lml/has_attributes_spec.rb +54 -0
  259. data/spec/lml/lutaml/lml/import_resolver_spec.rb +116 -0
  260. data/spec/lml/lutaml/lml/instance_hydration_spec.rb +178 -0
  261. data/spec/lml/lutaml/lml/lsp/server_spec.rb +285 -0
  262. data/spec/lml/lutaml/lml/model_compiler_spec.rb +406 -0
  263. data/spec/lml/lutaml/lml/models/association_spec.rb +40 -0
  264. data/spec/lml/lutaml/lml/models/collection_spec.rb +27 -0
  265. data/spec/lml/lutaml/lml/models/data_type_spec.rb +34 -0
  266. data/spec/lml/lutaml/lml/models/diagram_spec.rb +18 -0
  267. data/spec/lml/lutaml/lml/models/document_spec.rb +64 -0
  268. data/spec/lml/lutaml/lml/models/enum_spec.rb +42 -0
  269. data/spec/lml/lutaml/lml/models/inheritance_spec.rb +77 -0
  270. data/spec/lml/lutaml/lml/models/instance_collection_spec.rb +62 -0
  271. data/spec/lml/lutaml/lml/models/instance_spec.rb +81 -0
  272. data/spec/lml/lutaml/lml/models/instances_export_spec.rb +23 -0
  273. data/spec/lml/lutaml/lml/models/instances_import_spec.rb +28 -0
  274. data/spec/lml/lutaml/lml/models/package_spec.rb +26 -0
  275. data/spec/lml/lutaml/lml/models/primitive_type_spec.rb +34 -0
  276. data/spec/lml/lutaml/lml/models/top_element_attribute_spec.rb +153 -0
  277. data/spec/lml/lutaml/lml/models/uml_class_spec.rb +70 -0
  278. data/spec/lml/lutaml/lml/models_version_spec.rb +27 -0
  279. data/spec/lml/lutaml/lml/operations_spec.rb +59 -0
  280. data/spec/lml/lutaml/lml/parser_spec.rb +348 -0
  281. data/spec/lml/lutaml/lml/pipeline_spec.rb +93 -0
  282. data/spec/lml/lutaml/lml/preprocessor_spec.rb +174 -0
  283. data/spec/lml/lutaml/lml/property_laws_spec.rb +344 -0
  284. data/spec/lml/lutaml/lml/real_world_spec.rb +191 -0
  285. data/spec/lml/lutaml/lml/reference_spec.rb +64 -0
  286. data/spec/lml/lutaml/lml/round_trip_spec.rb +457 -0
  287. data/spec/lml/lutaml/lml/rs3001_corpus_spec.rb +83 -0
  288. data/spec/lml/lutaml/lml/rs3001_syntax_spec.rb +77 -0
  289. data/spec/lml/lutaml/lml/serialization_mapping_spec.rb +127 -0
  290. data/spec/lml/lutaml/lml/source_spec.rb +62 -0
  291. data/spec/lml/lutaml/lml/transform_spec.rb +37 -0
  292. data/spec/lml/lutaml/lml/types/text_type_spec.rb +43 -0
  293. data/spec/lml/lutaml/lml/validator_spec.rb +238 -0
  294. data/spec/lml/lutaml/lml/view_resolver_spec.rb +78 -0
  295. data/spec/lml/lutaml/lml/view_spec.rb +112 -0
  296. data/spec/lml/lutaml/parsers/dsl_spec.rb +275 -0
  297. data/spec/lml/lutaml/parsers/yaml_spec.rb +52 -0
  298. data/spec/lml/lutaml/qualified_type_spec.rb +33 -0
  299. data/spec/lutaml/model/adapter_type_unset_restore_spec.rb +61 -0
  300. data/spec/lutaml/model/custom_bibtex_adapter_spec.rb +4 -1
  301. data/spec/lutaml/xml/adapter/moxml_lane_spec.rb +112 -0
  302. data/spec/lutaml/xml/adapter_metadata_default_spec.rb +21 -2
  303. data/spec/lutaml/xml/adapter_moxml_engine_spec.rb +57 -0
  304. data/spec/lutaml/xml/leptris/native_emission_plain_model_spec.rb +50 -0
  305. data/spec/lutaml/xml/plain_model_mapping_resolution_spec.rb +88 -0
  306. data/spec/lutaml/xml/schema/xsd/vc_versioning_spec.rb +49 -0
  307. data/spec/lutaml/xml/schema/xsd/xsd_11_constructs_spec.rb +83 -0
  308. metadata +286 -2
@@ -0,0 +1,348 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+ require_relative "../../lml_spec_setup"
5
+
6
+ RSpec.describe Lutaml::Lml::Parser do
7
+ describe "LML and LUTAML file parsing and mapping" do
8
+ def parse_lml(fname)
9
+ File.open(fname) { |f| Lutaml::Lml.parse(f) }
10
+ end
11
+
12
+ describe "parsing test.lutaml for diagram/classes/definitions/attributes" do
13
+ let(:doc) { parse_lml("spec/lml/fixtures/test.lutaml") }
14
+
15
+ it "returns a Lutaml::Lml::Document with correct title" do
16
+ expect(doc).to be_a(Lutaml::Lml::Document)
17
+ expect(doc.title).to eq("my diagram").or be_nil
18
+ end
19
+
20
+ context "AddressClassProfile class" do
21
+ let(:klass) { doc.classes.find { |c| c.name == "AddressClassProfile" } }
22
+
23
+ it "exists and has correct definition" do
24
+ expect(klass).not_to be_nil, "Expected AddressClassProfile class to exist"
25
+ expect(klass.definition).to include("this is multiline")
26
+ end
27
+
28
+ it "has an attribute 'addressClassProfile' with correct type and cardinality" do
29
+ attr = klass.attributes.find { |a| a.name == "addressClassProfile" }
30
+ expect(attr).not_to be_nil, "Expected attribute 'addressClassProfile' to exist"
31
+ expect(attr.type).to eq("CharacterString")
32
+ expect(attr.cardinality.min).to eq("0")
33
+ expect(attr.cardinality.max).to eq("1")
34
+ end
35
+ end
36
+
37
+ context "AttributeProfile class" do
38
+ let(:klass2) { doc.classes.find { |c| c.name == "AttributeProfile" } }
39
+
40
+ it "exists" do
41
+ expect(klass2).not_to be_nil, "Expected AttributeProfile class to exist"
42
+ end
43
+
44
+ it "has an attribute 'imlicistAttributeProfile' with correct type, cardinality, and definition" do
45
+ attr2 = klass2.attributes.find { |a| a.name == "imlicistAttributeProfile" }
46
+ expect(attr2).not_to be_nil, "Expected attribute 'imlicistAttributeProfile' to exist"
47
+ expect(attr2.type).to eq("CharacterString")
48
+ expect(attr2.cardinality.min).to eq("0")
49
+ expect(attr2.cardinality.max).to eq("1")
50
+ expect(attr2.definition).to include("this is attribute definition")
51
+ end
52
+ end
53
+ end
54
+
55
+ describe "parsing data_s102_check.lml for instances and requires" do
56
+ let(:doc) { parse_lml("spec/lml/fixtures/lml/data_s102_check.lml") }
57
+
58
+ it "returns a Lutaml::Lml::Document and includes required file" do
59
+ expect(doc).to be_a(Lutaml::Lml::Document)
60
+ expect(doc.requires).to include("iho_s102_check.lml")
61
+ end
62
+
63
+ context "S158Checks instance" do
64
+ let(:inst) { doc.instance }
65
+
66
+ it "exists and has correct type" do
67
+ expect(inst).not_to be_nil, "Expected S158Checks instance to exist"
68
+ expect(inst.type).to eq("S158Checks")
69
+ end
70
+
71
+ it "has a 'checks' attribute with correct structure and values" do
72
+ checks = inst.attributes.find { |a| a.name == "checks" }
73
+ expect(checks).not_to be_nil, "Expected 'checks' attribute to exist"
74
+ expect(checks.instances).to be_a(Array)
75
+ first_check = checks.instances.first
76
+ expect(first_check.type).to eq("IhoS102Check::ValidationCheck")
77
+ dev_id_check = first_check.attributes.find { |a| a.name == "dev_id" }
78
+ expect(dev_id_check).not_to be_nil, "Expected 'dev_id' attribute to exist in first check"
79
+ expect(dev_id_check.value).to eq("S102_Dev1001")
80
+ end
81
+ end
82
+ end
83
+
84
+ describe "parsing data_s158_metadata.lml for nested instances and lists" do
85
+ let(:doc) { parse_lml("spec/lml/fixtures/lml/data_s158_metadata.lml") }
86
+
87
+ it "returns a Lutaml::Lml::Document and has a top-level instance" do
88
+ expect(doc).to be_a(Lutaml::Lml::Document)
89
+ expect(doc.instance).not_to be_nil
90
+ end
91
+
92
+ context "top-level instance (meta)" do
93
+ let(:meta) { doc.instance }
94
+
95
+ it "has a nested instance (iho) with correct attributes and lists" do
96
+ iho = meta.instance
97
+ expect(iho).not_to be_nil, "Expected nested instance 'iho' to exist"
98
+ doc_number_attr = iho.attributes.find { |a| a.name == "document_number" }
99
+ expect(doc_number_attr).not_to be_nil, "Expected 'document_number' attribute to exist"
100
+ expect(doc_number_attr.value).to eq("S-158:102")
101
+
102
+ compliant_standards = iho.attributes.find { |a| a.name == "compliant_standards" }
103
+ expect(compliant_standards).not_to be_nil, "Expected 'compliant_standards' attribute to exist"
104
+ expect(compliant_standards.instances).to be_a(Array)
105
+ first_standard = compliant_standards.instances.first
106
+ expect(first_standard.type).to eq("CompliantStandard")
107
+ title_attr = first_standard.attributes.find { |a| a.name == "title" }
108
+ expect(title_attr).not_to be_nil, "Expected 'title' attribute to exist in first compliant standard"
109
+ expect(title_attr.value).to eq("S-102 PS")
110
+ end
111
+ end
112
+ end
113
+
114
+ it "parses iho_data_models.lml and maps models/classes/attributes" do
115
+ doc = parse_lml("spec/lml/fixtures/lml/iho_data_models.lml")
116
+ expect(doc).to be_a(Lutaml::Lml::Document)
117
+ expect(doc.name).to eq("IhoDataModels")
118
+ klass = doc.classes.find { |c| c.name == "IhoMetadata" }
119
+ expect(klass).not_to be_nil
120
+ expect(klass.attributes.map(&:name)).to include("document_number", "title", "document_type", "edition", "issued_date", "committee", "wg_pt", "compliant_standards")
121
+ attr = klass.attributes.find { |a| a.name == "document_number" }
122
+ expect(attr.type).to eq("String")
123
+ expect(attr.cardinality.min).to eq("1")
124
+ end
125
+
126
+ describe "parsing iho_s102_check.lml for models/classes/attributes" do
127
+ let(:doc) { parse_lml("spec/lml/fixtures/lml/iho_s102_check.lml") }
128
+
129
+ it "returns a Lutaml::Lml::Document with correct name" do
130
+ expect(doc).to be_a(Lutaml::Lml::Document)
131
+ expect(doc.name).to eql("IhoS102Check")
132
+ end
133
+
134
+ context "ValidationCheck class" do
135
+ let(:klass) { doc.classes.find { |c| c.name == "ValidationCheck" } }
136
+
137
+ it "exists and has correct attributes" do
138
+ expect(klass).not_to be_nil, "Expected ValidationCheck class to exist"
139
+ expect(klass.attributes.map(&:name)).to include(
140
+ "dev_id", "check_id", "classification", "check_message", "check_description", "check_solution"
141
+ )
142
+ end
143
+
144
+ it "has 'dev_id' attribute with correct type, cardinality, and properties" do
145
+ attr = klass.attributes.find { |a| a.name == "dev_id" }
146
+ expect(attr).not_to be_nil, "Expected attribute 'dev_id' to exist"
147
+ expect(attr.type).to eq("String")
148
+ expect(attr.cardinality.min).to eq("1")
149
+ expect(attr.properties.find { |p| p.name == "description" }.value).to eq("Dev ID: Development identifier for the check")
150
+ end
151
+ end
152
+ end
153
+
154
+ describe "parsing mixed diagram lml" do
155
+ let(:doc) { parse_lml("spec/lml/fixtures/mixed_lml/diagram.lml") }
156
+
157
+ it "returns a Lutaml::Lml::Document with correct title" do
158
+ expect(doc).to be_a(Lutaml::Lml::Document)
159
+ expect(doc.title).to eq("my diagram").or be_nil
160
+ end
161
+
162
+ context "AddressClassProfile class" do
163
+ let(:klass) { doc.classes.find { |c| c.name == "AddressClassProfile" } }
164
+
165
+ it "exists and has correct definition" do
166
+ expect(klass).not_to be_nil, "Expected AddressClassProfile class to exist"
167
+ expect(klass.definition).to include("this is multiline")
168
+ end
169
+
170
+ it "has attributes with correct types and cardinalities" do
171
+ attr = klass.attributes.find { |a| a.name == "addressClassProfile" }
172
+ expect(attr).not_to be_nil, "Expected attribute 'addressClassProfile' to exist"
173
+ expect(attr.type).to eq("CharacterString")
174
+ expect(attr.cardinality.max).to eq("1")
175
+
176
+ attr2 = klass.attributes.find { |a| a.name == "address" }
177
+ expect(attr2).not_to be_nil, "Expected attribute 'address' to exist"
178
+ expect(attr2.type).to eq("String")
179
+ expect(attr2.cardinality.min).to eq("1")
180
+ end
181
+ end
182
+
183
+ context "AttributeProfile class" do
184
+ let(:klass2) { doc.classes.find { |c| c.name == "AttributeProfile" } }
185
+
186
+ it "exists" do
187
+ expect(klass2).not_to be_nil, "Expected AttributeProfile class to exist"
188
+ end
189
+
190
+ it "has an attribute 'imlicistAttributeProfile' with correct type, cardinality, and definition" do
191
+ attr2 = klass2.attributes.find { |a| a.name == "imlicistAttributeProfile" }
192
+ expect(attr2).not_to be_nil, "Expected attribute 'imlicistAttributeProfile' to exist"
193
+ expect(attr2.type).to eq("CharacterString")
194
+ expect(attr2.cardinality.min).to eq("0")
195
+ expect(attr2.cardinality.max).to eq("1")
196
+ expect(attr2.definition).to include("this is attribute definition")
197
+ end
198
+ end
199
+ end
200
+
201
+ describe "parsing mixed model lml" do
202
+ let(:doc) { parse_lml("spec/lml/fixtures/mixed_lml/model.lml") }
203
+
204
+ it "returns a Lutaml::Lml::Document with correct name" do
205
+ expect(doc).to be_a(Lutaml::Lml::Document)
206
+ expect(doc.name).to eql("IhoS102Check")
207
+ end
208
+
209
+ context "ValidationCheck class" do
210
+ let(:klass) { doc.classes.find { |c| c.name == "ValidationCheck" } }
211
+
212
+ it "exists and has correct attributes" do
213
+ expect(klass).not_to be_nil, "Expected ValidationCheck class to exist"
214
+ expect(klass.attributes.map(&:name)).to include("dev_id", "classification", "check_message")
215
+ end
216
+
217
+ it "has 'dev_id' and 'classification' attributes with correct types and cardinalities" do
218
+ attr = klass.attributes.find { |a| a.name == "dev_id" }
219
+ expect(attr).not_to be_nil, "Expected attribute 'dev_id' to exist"
220
+ expect(attr.type).to eq("String")
221
+ expect(attr.cardinality.min).to eq("1")
222
+
223
+ attr2 = klass.attributes.find { |a| a.name == "classification" }
224
+ expect(attr2).not_to be_nil, "Expected attribute 'classification' to exist"
225
+ expect(attr2.type).to eq("Classification")
226
+ expect(attr2.cardinality.min).to eq("1")
227
+ end
228
+ end
229
+ end
230
+
231
+ context "when parsing mixed_lml/instances.lml" do
232
+ let(:doc) { parse_lml("spec/lml/fixtures/mixed_lml/instances.lml") }
233
+
234
+ it "parses the document and instance collection" do
235
+ expect(doc).to be_a(Lutaml::Lml::Document)
236
+ expect(doc.instances).to be_a(Lutaml::Lml::InstanceCollection)
237
+ end
238
+
239
+ it "maps every collection block, in order" do
240
+ collections = doc.instances.collections
241
+ expect(collections.map(&:name)).to eq(%w[test_suite_1 test_suite_2])
242
+ suite = collections.first
243
+ expect(suite.includes).to eq(%w[laptop_123 desktop_1 desktop_2])
244
+ expect(suite.validations).to eq(["count >= 3", "all? { |i| i.components.count > 0 }"])
245
+ expect(collections.last.includes).to eq(["gaming_pc"])
246
+ end
247
+
248
+ it "maps imports correctly" do
249
+ imports = doc.instances.imports
250
+ expect(imports.size).to eq(2)
251
+ xml_import = imports.find { |imp| imp.format_type == "xml" }
252
+ expect(xml_import.file).to eq("test_data/products.xml")
253
+ expect(xml_import.attributes.map(&:name)).to include("map_to", "where")
254
+ expect(xml_import.attributes.find { |a| a.name == "map_to" }.value).to eq("Product")
255
+ expect(xml_import.attributes.find { |a| a.name == "where" }.value).to eq("/product")
256
+ csv_import = imports.find { |imp| imp.format_type == "csv" }
257
+ expect(csv_import.file).to eq("test_data/components.csv")
258
+ expect(csv_import.attributes.map(&:name)).to include("map_to", "columns")
259
+ end
260
+
261
+ it "preserves a map-valued attribute without dropping keys" do
262
+ csv_import = doc.instances.imports.find { |imp| imp.format_type == "csv" }
263
+ columns = csv_import.attributes.find { |a| a.name == "columns" }
264
+ expect(columns.value.value).to eq(
265
+ id: "component_id", type: "component_type", quantity: "count",
266
+ )
267
+ end
268
+
269
+ # JSON has no symbol type, so the keys come back as strings.
270
+ it "reloads a map-valued attribute through Document.from_json" do
271
+ reloaded = Lutaml::Lml::Document.from_json(doc.to_json)
272
+
273
+ csv_import = reloaded.instances.imports.find { |imp| imp.format_type == "csv" }
274
+ columns = csv_import.attributes.find { |a| a.name == "columns" }
275
+ expect(columns.value.value).to eq(
276
+ "id" => "component_id", "type" => "component_type", "quantity" => "count",
277
+ )
278
+ end
279
+
280
+ it "serializes a map-valued attribute to YAML without a ruby object tag" do
281
+ expect(doc.to_yaml).not_to include("!ruby/object")
282
+ end
283
+
284
+ it "reloads a map-valued attribute through Document.from_yaml" do
285
+ reloaded = Lutaml::Lml::Document.from_yaml(doc.to_yaml)
286
+
287
+ csv_import = reloaded.instances.imports.find { |imp| imp.format_type == "csv" }
288
+ columns = csv_import.attributes.find { |a| a.name == "columns" }
289
+ expect(columns.value.value).to eq(
290
+ id: "component_id", type: "component_type", quantity: "count",
291
+ )
292
+ end
293
+
294
+ it "maps exports correctly" do
295
+ exports = doc.instances.exports
296
+ expect(exports.size).to eq(2)
297
+ xml_export = exports.find { |exp| exp.format_type == "xml" }
298
+ expect(xml_export.attributes.map(&:name)).to include("file", "indent", "encoding")
299
+ expect(xml_export.attributes.find { |a| a.name == "file" }.value).to eq("output/products.xml")
300
+ expect(xml_export.attributes.find { |a| a.name == "indent" }.value).to be(true)
301
+ expect(xml_export.attributes.find { |a| a.name == "encoding" }.value).to eq("UTF-8")
302
+ step_export = exports.find { |exp| exp.format_type == "step" }
303
+ expect(step_export.attributes.map(&:name)).to include("file", "reference_format")
304
+ expect(step_export.attributes.find { |a| a.name == "file" }.value).to eq("output/products.stp")
305
+ expect(step_export.attributes.find { |a| a.name == "reference_format" }.value).to eq("#%{id}") # rubocop:disable Style/FormatStringToken -- literal reference template
306
+ end
307
+
308
+ it "maps product inheritance and template correctly" do
309
+ products = doc.instances.instances.filter { |i| i.type == "Product" }
310
+ base_computer = products.first
311
+ expect(base_computer).not_to be_nil
312
+ components_attr = base_computer.template.find { |a| a.name == "components" }
313
+ expect(components_attr.instances).to be_a(Array)
314
+ expect(components_attr.instances.first.type).to eq("Component")
315
+ expect(products.last.parent).to eq("base_computer")
316
+ end
317
+ end
318
+ end
319
+
320
+ describe "XML namespace and node kind (issue #49)" do
321
+ let(:car) do
322
+ source = <<~LML
323
+ class Car {
324
+ namespace "xyz" prefix "x"
325
+ wheels Wheel[4] as :element
326
+ vin: String as :attribute
327
+ plain Wheel
328
+ }
329
+ class Wheel {
330
+ tire
331
+ }
332
+ LML
333
+ Lutaml::Lml.parse_document(source).classes.first
334
+ end
335
+
336
+ it "records the class namespace instead of an attribute" do
337
+ expect([car.xml_namespace.uri, car.xml_namespace.prefix]).to eq(%w[xyz x])
338
+ expect(car.attributes.map(&:name)).to eq(%w[wheels vin plain])
339
+ end
340
+
341
+ it "records the node kind on the attribute and keeps type and cardinality" do
342
+ wheels, vin, plain = car.attributes
343
+ expect([wheels.type, wheels.cardinality.min, wheels.xml_role]).to eq(%w[Wheel 4 element])
344
+ expect([vin.type, vin.xml_role]).to eq(%w[String attribute])
345
+ expect([plain.type, plain.xml_role]).to eq(["Wheel", nil])
346
+ end
347
+ end
348
+ end
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+ require_relative "../../lml_spec_setup"
5
+ require "tmpdir"
6
+ require "fileutils"
7
+
8
+ RSpec.describe "LML pipeline and entry points" do
9
+ describe Lutaml::Lml::Pipeline, ".call" do
10
+ it "parses a minimal diagram into a document" do
11
+ file = Tempfile.new(%w[test .lutaml])
12
+ file.write("diagram Test { class Foo {} }")
13
+ file.rewind
14
+
15
+ doc = described_class.call(file)
16
+ expect(doc).to be_a(Lutaml::Lml::Document)
17
+ expect(doc.classes.first.name).to eq("Foo")
18
+ ensure
19
+ file.close!
20
+ end
21
+
22
+ it "raises ParsingError on invalid input" do
23
+ file = Tempfile.new(%w[test .lutaml])
24
+ file.write("!!! invalid !!!")
25
+ file.rewind
26
+
27
+ expect { described_class.call(file) }.to raise_error(Lutaml::Lml::ParsingError)
28
+ ensure
29
+ file.close!
30
+ end
31
+
32
+ it "parses instances with collection" do
33
+ file = Tempfile.new(%w[test .lml])
34
+ file.write <<~LML
35
+ instances {
36
+ collection "test_suite" {
37
+ includes [ "a", "b" ]
38
+ }
39
+ }
40
+ LML
41
+ file.rewind
42
+
43
+ doc = described_class.call(file)
44
+ expect(doc.instances).to be_a(Lutaml::Lml::InstanceCollection)
45
+ ensure
46
+ file.close!
47
+ end
48
+
49
+ it "does not resolve view imports (parsing only)" do
50
+ dir = Dir.mktmpdir
51
+ File.write(File.join(dir, "model.lutaml"), "class External {}")
52
+ view_file = File.join(dir, "view.lutaml")
53
+ File.write(view_file, "view V { import \"model.lutaml\" }")
54
+
55
+ doc = described_class.call(File.new(view_file))
56
+ expect(doc.view_imports.map(&:path)).to eq(["model.lutaml"])
57
+ expect(doc.classes).to be_empty
58
+ ensure
59
+ FileUtils.rm_rf(dir)
60
+ end
61
+ end
62
+
63
+ describe Lutaml::Lml do
64
+ describe ".parse" do
65
+ it "resolves view imports and enriches labels" do
66
+ dir = Dir.mktmpdir
67
+ File.write(File.join(dir, "model.lutaml"), "class External {}")
68
+ view_file = File.join(dir, "view.lutaml")
69
+ File.write(view_file, "view V { import \"model.lutaml\" }")
70
+
71
+ doc = described_class.parse(File.new(view_file))
72
+ expect(doc.classes.map(&:name)).to include("External")
73
+ ensure
74
+ FileUtils.rm_rf(dir)
75
+ end
76
+ end
77
+
78
+ describe ".parse_document" do
79
+ it "parses without resolving imports" do
80
+ dir = Dir.mktmpdir
81
+ File.write(File.join(dir, "model.lutaml"), "class External {}")
82
+ view_file = File.join(dir, "view.lutaml")
83
+ File.write(view_file, "view V { import \"model.lutaml\" }")
84
+
85
+ doc = described_class.parse_document(File.new(view_file))
86
+ expect(doc.view_imports.map(&:path)).to eq(["model.lutaml"])
87
+ expect(doc.classes).to be_empty
88
+ ensure
89
+ FileUtils.rm_rf(dir)
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,174 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+ require_relative "../../lml_spec_setup"
5
+ require "tempfile"
6
+ require "fileutils"
7
+
8
+ RSpec.describe Lutaml::Lml::Preprocessor do
9
+ def make_file(content, name = "test.lutaml")
10
+ file = Tempfile.new([name.gsub(/\..*/, ""), File.extname(name)])
11
+ file.write(content)
12
+ file.rewind
13
+ file
14
+ end
15
+
16
+ describe ".call" do
17
+ it "returns file content unchanged for simple files" do
18
+ file = make_file("diagram TestDiagram\nend")
19
+ result = described_class.call(file)
20
+ expect(result).to eq("diagram TestDiagram\nend")
21
+ file.close!
22
+ end
23
+
24
+ it "preserves // comments for grammar-level trivia" do
25
+ file = make_file("diagram Test // this is a comment\nend")
26
+ result = described_class.call(file)
27
+ expect(result).to eq("diagram Test // this is a comment\nend")
28
+ file.close!
29
+ end
30
+
31
+ it "preserves inline comments and raises on unterminated block comments" do
32
+ file = make_file("class MyClass // inline comment\ntitle \"Test\" // another\nend")
33
+ result = described_class.call(file)
34
+ expect(result).to include("// inline comment")
35
+ file.close!
36
+
37
+ bad = make_file("class MyClass {\n/* never closed\n")
38
+ expect { described_class.call(bad) }
39
+ .to raise_error(Lutaml::Lml::Error, /unterminated block comment/)
40
+ bad.close!
41
+ end
42
+ end
43
+
44
+ describe "include directives" do
45
+ it "includes referenced files" do
46
+ shared_content = "class SharedClass\nend"
47
+ shared_file = make_file(shared_content, "shared.lutaml")
48
+
49
+ main_content = "diagram Test\ninclude #{File.basename(shared_file.path)}\nend"
50
+ main_file = Tempfile.new(["main", ".lutaml"])
51
+ main_file.write(main_content)
52
+ main_file.rewind
53
+
54
+ result = described_class.call(main_file)
55
+ expect(result).to include("SharedClass")
56
+ expect(result).not_to include("include")
57
+ main_file.close!
58
+ shared_file.close!
59
+ end
60
+
61
+ it "raises on missing include files" do
62
+ file = make_file("diagram Test\ninclude nonexistent.lutaml\nend")
63
+ expect { described_class.call(file) }
64
+ .to raise_error(Lutaml::Lml::Error, /cannot read include/)
65
+ file.close!
66
+ end
67
+
68
+ it "expands includes nested inside included files" do
69
+ dir = Dir.mktmpdir
70
+ inner = File.join(dir, "inner.lutaml")
71
+ middle = File.join(dir, "middle.lutaml")
72
+ File.write(inner, "class Inner\nend")
73
+ File.write(middle, "class Middle\ninclude inner.lutaml\nend")
74
+
75
+ main = Tempfile.new(%w[main .lutaml])
76
+ main.write("diagram Test\ninclude #{middle}\nend")
77
+ main.rewind
78
+
79
+ result = described_class.call(main)
80
+ expect(result).to include("Middle")
81
+ expect(result).to include("Inner")
82
+ expect(result).not_to include("include")
83
+ main.close!
84
+ FileUtils.rm_rf(dir)
85
+ end
86
+
87
+ it "resolves nested includes relative to the including file" do
88
+ dir = Dir.mktmpdir
89
+ subdir = File.join(dir, "sub")
90
+ FileUtils.mkdir(subdir)
91
+ File.write(File.join(subdir, "inner.lutaml"), "class Inner\nend")
92
+ File.write(File.join(dir, "middle.lutaml"), "class Middle\ninclude sub/inner.lutaml\nend")
93
+
94
+ main = Tempfile.new(%w[main .lutaml])
95
+ main.write("diagram Test\ninclude #{File.join(dir, 'middle.lutaml')}\nend")
96
+ main.rewind
97
+
98
+ result = described_class.call(main)
99
+ expect(result).to include("Inner")
100
+ main.close!
101
+ FileUtils.rm_rf(dir)
102
+ end
103
+
104
+ it "raises on circular includes" do
105
+ dir = Dir.mktmpdir
106
+ a = File.join(dir, "a.lutaml")
107
+ b = File.join(dir, "b.lutaml")
108
+ File.write(a, "class A\ninclude #{b}\nend")
109
+ File.write(b, "class B\ninclude #{a}\nend")
110
+
111
+ main = Tempfile.new(%w[main .lutaml])
112
+ main.write("diagram Test\ninclude #{a}\nend")
113
+ main.rewind
114
+
115
+ expect { described_class.call(main) }
116
+ .to raise_error(Lutaml::Lml::Error, /circular include/)
117
+ main.close!
118
+ FileUtils.rm_rf(dir)
119
+ end
120
+
121
+ it "allows the same file included twice (non-circular)" do
122
+ dir = Dir.mktmpdir
123
+ shared = File.join(dir, "shared.lutaml")
124
+ File.write(shared, "class Shared\nend")
125
+
126
+ main = Tempfile.new(%w[main .lutaml])
127
+ main.write("diagram Test\ninclude #{shared}\ninclude #{shared}\nend")
128
+ main.rewind
129
+
130
+ result = described_class.call(main)
131
+ expect(result.scan("Shared").length).to eq(2)
132
+ main.close!
133
+ FileUtils.rm_rf(dir)
134
+ end
135
+
136
+ it "strips carriage returns from CRLF files" do
137
+ file = make_file("diagram Test\r\ntitle \"x\"\r\n")
138
+ result = described_class.call(file)
139
+ expect(result).not_to include("\r")
140
+ file.close!
141
+ end
142
+
143
+ it "raises on unreadable include files" do
144
+ skip "Unix file modes not enforced on Windows" if Gem.win_platform?
145
+ dir = Dir.mktmpdir
146
+ unreadable = File.join(dir, "unreadable.lutaml")
147
+ File.write(unreadable, "class Unreadable\nend")
148
+ FileUtils.chmod(0o000, unreadable)
149
+ main = Tempfile.new(%w[main .lutaml])
150
+ main.write("diagram Test\ninclude #{unreadable}\nend")
151
+ main.rewind
152
+
153
+ expect { described_class.call(main) }
154
+ .to raise_error(Lutaml::Lml::Error, /cannot read include/)
155
+ ensure
156
+ begin
157
+ FileUtils.chmod(0o644, unreadable)
158
+ rescue StandardError
159
+ nil
160
+ end
161
+ main&.close!
162
+ FileUtils.rm_rf(dir)
163
+ end
164
+ end
165
+
166
+ describe "idempotency" do
167
+ it "produces the same output when called twice on the same StringIO" do
168
+ io = StringIO.new("diagram Test // comment\nend")
169
+ first = described_class.call(io)
170
+ second = described_class.call(io)
171
+ expect(second).to eq(first)
172
+ end
173
+ end
174
+ end