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,344 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+ require_relative "../../lml_spec_setup"
5
+
6
+ ENV["RANTLY_VERBOSE"] ||= "0"
7
+ require "rantly"
8
+ require "rantly/rspec_extensions"
9
+ require "rantly/shrinks"
10
+ require "lutaml/lml/format"
11
+
12
+ # Constants shared by the generative laws (TODO.next/sota/properties.md).
13
+ # Seeded and reproducible: the seed is printed before every property run,
14
+ # and Rantly shrinks the generated tuple on failure. PR runs use a
15
+ # reduced count and depth; the nightly workflow raises both through
16
+ # LML_PROPERTY_COUNT / LML_PROPERTY_DEPTH and supplies a fresh seed.
17
+ module PropertyLawsSupport
18
+ SEED = Integer(ENV.fetch("LML_PROPERTY_SEED", "20261020"))
19
+ COUNT = Integer(ENV.fetch("LML_PROPERTY_COUNT", "40"))
20
+ DEPTH = Integer(ENV.fetch("LML_PROPERTY_DEPTH", "2"))
21
+
22
+ TYPES = {
23
+ string: :string, integer: :integer, float: :float, boolean: :boolean
24
+ }.freeze
25
+
26
+ # Values that a bare-word emission would read back as something other
27
+ # than a string (or not read at all).
28
+ EDGE_STRINGS = [
29
+ "", "null", "true", "false", "01", "1.50", "2dCi9o", "0x10",
30
+ "with space", "a-b", 'quote"x', "back\\slash", " padded ",
31
+ "line\nbreak", "tab\there", "üñï", "🎨", "12", "-3"
32
+ ].freeze
33
+
34
+ STRING_GEN = proc do
35
+ case choose(:print, :ascii, :edge)
36
+ when :print then string(:print)
37
+ when :ascii then string(:ascii)
38
+ else choose(*EDGE_STRINGS)
39
+ end
40
+ end
41
+
42
+ # The document-model comparison defined with TODO.canon/5.
43
+ DEFAULT_VALUES = {
44
+ "visibility" => "public", "literal" => false, "is_derived" => false,
45
+ "is_static" => false, "is_read_only" => false, "is_abstract" => false,
46
+ "direction" => "in"
47
+ }.freeze
48
+ end
49
+
50
+ RSpec.describe "LML round-trip properties" do
51
+ def report_seed
52
+ warn "LML property seed: #{PropertyLawsSupport::SEED}"
53
+ end
54
+
55
+ def model_class(type)
56
+ Class.new(Lutaml::Model::Serializable) do
57
+ attribute :value, type
58
+ lml { map :value, to: :value }
59
+ end
60
+ end
61
+
62
+ def parse(source)
63
+ Lutaml::Lml.parse_document(source)
64
+ end
65
+
66
+ def canonical(source)
67
+ Lutaml::Formatter::Canonical.new(parse(source)).render
68
+ rescue Lutaml::Lml::Error => e
69
+ raise "#{e.message}\n--- generated source ---\n#{source}"
70
+ end
71
+
72
+ def normalize(node)
73
+ case node
74
+ when Hash
75
+ node.each_with_object({}) do |(key, value), result|
76
+ next if PropertyLawsSupport::DEFAULT_VALUES[key] == value
77
+
78
+ if key.to_s.include?("cardinality") && value.is_a?(Hash)
79
+ next if value["min"] == "0" && value["max"] == "1"
80
+
81
+ result[key] = value.merge("max" => unbounded(value["max"]))
82
+ next
83
+ end
84
+
85
+ result[key] = normalize(value)
86
+ end
87
+ when Array
88
+ node.map { |item| normalize(item) }
89
+ else
90
+ node
91
+ end
92
+ end
93
+
94
+ def unbounded(max)
95
+ max == "*" ? "n" : max
96
+ end
97
+
98
+ def model(source)
99
+ normalize(parse(source).to_hash)
100
+ end
101
+
102
+ describe "L1 value fidelity" do
103
+ it "round-trips generated typed values through to_lml/from_lml" do
104
+ report_seed
105
+
106
+ property = property_of do
107
+ kind = choose(:string, :string, :string, :integer, :float, :boolean)
108
+ value = case kind
109
+ when :string then call(PropertyLawsSupport::STRING_GEN)
110
+ when :integer then choose(integer, -618_435_539_813_391_527, 0)
111
+ when :float then choose(float, 1.0e-10, 1.0e20, -1.0e-10)
112
+ else boolean
113
+ end
114
+ Tuple.new([kind, value])
115
+ end
116
+
117
+ property.check(PropertyLawsSupport::COUNT) do |pair|
118
+ kind = pair[0]
119
+ value = pair[1]
120
+ klass = model_class(PropertyLawsSupport::TYPES.fetch(kind))
121
+ reloaded = klass.from_lml(klass.new(value: value).to_lml).value
122
+
123
+ expect(reloaded).to eq(value), "kind=#{kind} value=#{value.inspect}"
124
+ end
125
+ end
126
+ end
127
+
128
+ describe "L2 key fidelity" do
129
+ it "round-trips generated keys and values through the LML adapter" do
130
+ report_seed
131
+
132
+ property = property_of do
133
+ Tuple.new([call(PropertyLawsSupport::STRING_GEN),
134
+ call(PropertyLawsSupport::STRING_GEN)])
135
+ end
136
+
137
+ property.check(PropertyLawsSupport::COUNT) do |pair|
138
+ key = pair[0]
139
+ value = pair[1]
140
+ adapter = Lutaml::Lml::Format::Adapter::StandardAdapter
141
+ lml = adapter.new({ "__type__" => "Data", key => value }).to_lml
142
+ hash = adapter.instance_to_hash(parse(lml).instance)
143
+
144
+ expect(hash).to include(key => value)
145
+ end
146
+ end
147
+ end
148
+
149
+ describe "regressions found by the laws" do
150
+ it "quotes string values that would re-parse as other literals" do
151
+ klass = model_class(:string)
152
+
153
+ ["null", "01", "2dCi9o", "0x10", "1.50"].each do |value|
154
+ reloaded = klass.from_lml(klass.new(value: value).to_lml).value
155
+
156
+ expect(reloaded).to eq(value), "value=#{value.inspect}"
157
+ end
158
+ end
159
+
160
+ it "expands exponent-notation floats into plain decimals" do
161
+ klass = model_class(:float)
162
+
163
+ [1.0e-10, 1.0e20, -1.0e-10].each do |value|
164
+ expect(klass.from_lml(klass.new(value: value).to_lml).value).to eq(value)
165
+ end
166
+ end
167
+
168
+ it "reads a signed number as a number" do
169
+ reloaded = model_class(:integer)
170
+ .from_lml("instance Data {\n value = -618435539813391527\n}").value
171
+
172
+ expect(reloaded).to eq(-618_435_539_813_391_527)
173
+ end
174
+
175
+ it "keeps a trailing colon on a quoted key" do
176
+ adapter = Lutaml::Lml::Format::Adapter::StandardAdapter
177
+ lml = adapter.new({ "__type__" => "Data", "key:" => "v" }).to_lml
178
+ hash = adapter.instance_to_hash(parse(lml).instance)
179
+
180
+ expect(hash).to include("key:" => "v")
181
+ end
182
+
183
+ it "renders an exponent float without exponent notation" do
184
+ source = "instance X { a = 0.0000000001 }"
185
+ output = canonical(source)
186
+
187
+ expect(output).to include("a = 0.0000000001")
188
+ expect(model(output)).to eq(model(source))
189
+ end
190
+ end
191
+
192
+ # ---- grammar-directed document generation ----
193
+
194
+ def generated_document(params)
195
+ numbers = params.array
196
+ counts = Array.new(7) { |i| numbers[i] % (PropertyLawsSupport::DEPTH + 1) }
197
+ seed = numbers[7]
198
+
199
+ model = []
200
+ model.concat(generated_classes(seed, counts[0]))
201
+ model.concat(generated_enums(seed, counts[1], counts[2]))
202
+ model.concat(generated_packages(seed, counts[3]))
203
+ model.concat(generated_mappings(counts[4]))
204
+
205
+ source = +""
206
+ source << "lml \"1.0\"\n\n" if numbers[9].even?
207
+ source << "require \"gen.lml\"\n\n" if numbers[8].even?
208
+ source << wrap_models(seed, model) unless model.empty?
209
+ source << generated_instances(counts[5], counts[6])
210
+ source
211
+ end
212
+
213
+ def wrap_models(seed, members)
214
+ "models Gen#{seed % 10} {\n#{indent(members.join("\n\n"))}\n}\n\n"
215
+ end
216
+
217
+ def generated_classes(seed, count)
218
+ Array.new(count) do |i|
219
+ attrs = Array.new((seed + i) % (PropertyLawsSupport::DEPTH + 2)) do |j|
220
+ generated_attribute(seed + i + j, j)
221
+ end
222
+ body = attrs.map { |line| indent(line) }
223
+ body << indent("definition \"generated class #{i}\"") if seed.even?
224
+ body << indent("op#{i}(in x: String) : Boolean") if (seed + i) % 4 == 1
225
+ body << indent("** class comment #{i}") if (seed + i) % 4 == 2
226
+
227
+ header = "class C#{i}"
228
+ header += " < Base" if (seed + i) % 5 == 3
229
+ "#{header} {\n#{body.join("\n\n")}\n}"
230
+ end
231
+ end
232
+
233
+ def generated_attribute(seed, index)
234
+ name = "a#{index}"
235
+ type = PropertyLawsSupport::TYPES.keys.map { |k| k.to_s.capitalize }[seed % 4]
236
+ case seed % 6
237
+ when 0 then "attribute #{name}, #{type}"
238
+ when 1 then "attribute #{name}, #{type} { cardinality 0..n }"
239
+ when 2 then "attribute #{name}, #{type} { values { \"x\", \"y\" } }"
240
+ when 3 then "attribute #{name}, #{type} { pattern /a[0-9]+/ }"
241
+ when 4 then "-a#{index}: #{type} [1..2]"
242
+ else "attribute #{name}, #{type} { default: \"d#{index}\" }"
243
+ end
244
+ end
245
+
246
+ def generated_enums(seed, count, members)
247
+ Array.new(count) do |i|
248
+ body = ["definition \"generated enum #{i}\""]
249
+ Array.new(members) do |m|
250
+ body << generated_enum_member(seed + m, m)
251
+ end
252
+ "enum E#{i} {\n#{indent(body.join("\n\n"))}\n}"
253
+ end
254
+ end
255
+
256
+ def generated_enum_member(seed, index)
257
+ case seed % 4
258
+ when 0 then "value \"v#{index}\" {\n definition \"member #{index}\"\n}"
259
+ when 1 then "value v#{index}"
260
+ when 2 then "m#{index}: String"
261
+ else "value \"p#{index}\" {\n payload = \"x\"\n instance Payload {\n a = \"b\"\n }\n}"
262
+ end
263
+ end
264
+
265
+ def generated_packages(seed, count)
266
+ Array.new(count) do
267
+ "package P#{seed % 10} {\n" \
268
+ "#{indent('class PClass { attribute x, String }')}\n\n" \
269
+ "#{indent('enum PEnum { value "p" }')}\n}"
270
+ end
271
+ end
272
+
273
+ def generated_mappings(count)
274
+ return [] if count.zero?
275
+
276
+ ["mapping xml Thing {\n" \
277
+ "#{indent('element "thing"')}\n\n" \
278
+ "#{indent('map_element "wire" a0')}\n}"]
279
+ end
280
+
281
+ def generated_instances(collections, instances)
282
+ lines = []
283
+ instances.times do |i|
284
+ lines << "instance \"t#{i}\" Thing {"
285
+ lines << indent("a0 = \"value #{i}\"")
286
+ lines << indent("a1 = 1")
287
+ lines << indent("a2 = true")
288
+ lines << indent("a3 = null")
289
+ lines << indent("a4 = [\"x\", \"null\", \"é\"]")
290
+ lines << "}"
291
+ end
292
+
293
+ if collections.positive?
294
+ lines << "instances GenInstances {"
295
+ Array.new(collections) do |i|
296
+ lines << indent("collection \"col#{i}\" {")
297
+ lines << indent(indent("includes [\"t#{i}\"]"))
298
+ lines << indent(indent('validation { condition "count >= 0" }'))
299
+ lines << indent("}")
300
+ end
301
+ lines << "}"
302
+ end
303
+ return "" if lines.empty?
304
+
305
+ "#{lines.join("\n\n")}\n"
306
+ end
307
+
308
+ def indent(text)
309
+ text.lines.map { |line| " #{line}" }.join
310
+ end
311
+
312
+ describe "L3 document semantics" do
313
+ it "preserves generated documents through parse/emit/parse" do
314
+ report_seed
315
+
316
+ property = property_of do
317
+ Tuple.new(Array.new(10) { range(0, 24) })
318
+ end
319
+
320
+ property.check(PropertyLawsSupport::COUNT) do |params|
321
+ source = generated_document(params)
322
+
323
+ expect(model(canonical(source))).to eq(model(source)), "source:\n#{source}"
324
+ end
325
+ end
326
+ end
327
+
328
+ describe "L4 idempotence" do
329
+ it "renders generated documents to a fixed point" do
330
+ report_seed
331
+
332
+ property = property_of do
333
+ Tuple.new(Array.new(10) { range(0, 24) })
334
+ end
335
+
336
+ property.check(PropertyLawsSupport::COUNT) do |params|
337
+ source = generated_document(params)
338
+ once = canonical(source)
339
+
340
+ expect(canonical(once)).to eq(once), "source:\n#{source}"
341
+ end
342
+ end
343
+ end
344
+ end
@@ -0,0 +1,191 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+ require_relative "../../lml_spec_setup"
5
+ require "tempfile"
6
+
7
+ RSpec.describe "Real-world fixture parsing" do
8
+ def wrap_in_diagram(content)
9
+ "diagram Test {\n#{content}\n}"
10
+ end
11
+
12
+ def parse_fixture(path)
13
+ content = File.read(path)
14
+ content = wrap_in_diagram(content) unless content.strip.start_with?("diagram")
15
+ file = Tempfile.new(%w[test .lutaml])
16
+ file.write(content)
17
+ file.rewind
18
+ doc = Lutaml::Lml.parse(file)
19
+ file.close!
20
+ doc
21
+ end
22
+
23
+ def fixture_path(repo, name)
24
+ File.expand_path("../../fixtures/real_world/#{repo}/#{name}", __dir__)
25
+ end
26
+
27
+ describe "basicdoc-models fixtures" do
28
+ it "parses BasicDocument.lutaml" do
29
+ doc = parse_fixture(fixture_path("basicdoc-models", "BasicDocument.lutaml"))
30
+ expect(doc.classes.length).to eq(1)
31
+ c = doc.classes.first
32
+ expect(c.name).to eq("BasicDocument")
33
+ expect(c.attributes.length).to be >= 3
34
+ attr_names = c.attributes.map(&:name)
35
+ expect(attr_names).to include("identifier", "bibdata", "sections")
36
+ end
37
+
38
+ it "parses BasicBlock.lutaml" do
39
+ doc = parse_fixture(fixture_path("basicdoc-models", "BasicBlock.lutaml"))
40
+ c = doc.classes.first
41
+ expect(c.name).to eq("BasicBlock")
42
+ expect(c.attributes.map(&:name)).to include("notes")
43
+ end
44
+
45
+ it "parses BasicSection.lutaml with cardinality" do
46
+ doc = parse_fixture(fixture_path("basicdoc-models", "BasicSection.lutaml"))
47
+ c = doc.classes.first
48
+ expect(c.name).to eq("BasicSection")
49
+ title_attr = c.attributes.find { |a| a.name == "title" }
50
+ expect(title_attr).not_to be_nil
51
+ expect(title_attr.type).to eq("TextElement")
52
+ expect(title_attr.cardinality.min).to eq("0")
53
+ expect(title_attr.cardinality.max).to eq("*")
54
+ end
55
+
56
+ it "parses TableBlock.lutaml with mixed cardinalities" do
57
+ doc = parse_fixture(fixture_path("basicdoc-models", "TableBlock.lutaml"))
58
+ c = doc.classes.first
59
+ expect(c.name).to eq("TableBlock")
60
+ head_attr = c.attributes.find { |a| a.name == "head" }
61
+ body_attr = c.attributes.find { |a| a.name == "body" }
62
+ expect(head_attr.cardinality.max).to eq("1")
63
+ expect(body_attr.cardinality.max).to eq("*")
64
+ end
65
+
66
+ it "parses OrderedListType.lutaml as enum" do
67
+ doc = parse_fixture(fixture_path("basicdoc-models", "OrderedListType.lutaml"))
68
+ expect(doc.enums.length).to eq(1)
69
+ expect(doc.enums.first.name).to eq("OrderedListType")
70
+ end
71
+
72
+ it "parses Uri.lutaml as data_type" do
73
+ doc = parse_fixture(fixture_path("basicdoc-models", "Uri.lutaml"))
74
+ expect(doc.data_types.length).to eq(1)
75
+ expect(doc.data_types.first.name).to eq("Uri")
76
+ end
77
+
78
+ it "parses String.lutaml as primitive" do
79
+ doc = parse_fixture(fixture_path("basicdoc-models", "String.lutaml"))
80
+ expect(doc.classes.length).to eq(0)
81
+ expect(doc.enums.length).to eq(0)
82
+ expect(doc.data_types.length).to eq(0)
83
+ end
84
+
85
+ it "parses BibliographicItem.lutaml with stereotype" do
86
+ doc = parse_fixture(fixture_path("basicdoc-models", "BibliographicItem.lutaml"))
87
+ expect(doc.classes.length).to eq(1)
88
+ expect(doc.classes.first.name).to eq("BibliographicItem")
89
+ end
90
+
91
+ it "parses AdmonitionType.lutaml as enum with values" do
92
+ doc = parse_fixture(fixture_path("basicdoc-models", "AdmonitionType.lutaml"))
93
+ expect(doc.enums.length).to eq(1)
94
+ e = doc.enums.first
95
+ expect(e.name).to eq("AdmonitionType")
96
+ expect(e.attributes.length).to be >= 3
97
+ end
98
+
99
+ it "parses FigureBlock.lutaml" do
100
+ doc = parse_fixture(fixture_path("basicdoc-models", "FigureBlock.lutaml"))
101
+ expect(doc.classes.length).to eq(1)
102
+ expect(doc.classes.first.name).to eq("FigureBlock")
103
+ end
104
+ end
105
+
106
+ describe "metanorma-model-iso fixtures" do
107
+ it "parses IsoStandardDocument.lutaml with stereotype attribute types" do
108
+ doc = parse_fixture(fixture_path("metanorma-model-iso", "IsoStandardDocument.lutaml"))
109
+ c = doc.classes.first
110
+ expect(c.name).to eq("IsoStandardDocument")
111
+ term_attr = c.attributes.find { |a| a.name == "termSources" }
112
+ expect(term_attr).not_to be_nil
113
+ expect(term_attr.type).to eq("Citation")
114
+ expect(term_attr.cardinality.max).to eq("*")
115
+ end
116
+
117
+ it "parses IsoBibDataExtensionType.lutaml" do
118
+ doc = parse_fixture(fixture_path("metanorma-model-iso", "IsoBibDataExtensionType.lutaml"))
119
+ c = doc.classes.first
120
+ expect(c.name).to eq("IsoBibDataExtensionType")
121
+ expect(c.attributes.length).to be >= 5
122
+ ft_attr = c.attributes.find { |a| a.name == "fast-track" }
123
+ expect(ft_attr).not_to be_nil
124
+ end
125
+
126
+ it "parses IsoAdmonitionType.lutaml as enum" do
127
+ doc = parse_fixture(fixture_path("metanorma-model-iso", "IsoAdmonitionType.lutaml"))
128
+ expect(doc.enums.length).to eq(1)
129
+ expect(doc.enums.first.name).to eq("IsoAdmonitionType")
130
+ end
131
+
132
+ it "parses IsoSections.lutaml" do
133
+ doc = parse_fixture(fixture_path("metanorma-model-iso", "IsoSections.lutaml"))
134
+ expect(doc.classes.length).to eq(1)
135
+ expect(doc.classes.first.name).to eq("IsoSections")
136
+ end
137
+
138
+ it "parses IsoTerm.lutaml" do
139
+ doc = parse_fixture(fixture_path("metanorma-model-iso", "IsoTerm.lutaml"))
140
+ expect(doc.classes.length).to eq(1)
141
+ expect(doc.classes.first.name).to eq("IsoTerm")
142
+ end
143
+
144
+ it "parses StandardDocument.lutaml with stereotype" do
145
+ doc = parse_fixture(fixture_path("metanorma-model-iso", "StandardDocument.lutaml"))
146
+ expect(doc.classes.length).to eq(1)
147
+ expect(doc.classes.first.name).to eq("StandardDocument")
148
+ end
149
+
150
+ it "parses StandardBibDataExtensionType.lutaml" do
151
+ doc = parse_fixture(fixture_path("metanorma-model-iso", "StandardBibDataExtensionType.lutaml"))
152
+ c = doc.classes.first
153
+ expect(c.name).to eq("StandardBibDataExtensionType")
154
+ end
155
+ end
156
+
157
+ describe "batch smoke test" do
158
+ it "parses all basicdoc-models real-world fixtures" do
159
+ dir = File.expand_path("../../fixtures/real_world/basicdoc-models", __dir__)
160
+ Dir.glob("#{dir}/*.lutaml").each do |path|
161
+ expect { parse_fixture(path) }.not_to raise_error,
162
+ "Failed to parse #{File.basename(path)}"
163
+ end
164
+ end
165
+
166
+ it "parses all metanorma-model-iso real-world fixtures" do
167
+ dir = File.expand_path("../../fixtures/real_world/metanorma-model-iso", __dir__)
168
+ Dir.glob("#{dir}/*.lutaml").each do |path|
169
+ expect { parse_fixture(path) }.not_to raise_error,
170
+ "Failed to parse #{File.basename(path)}"
171
+ end
172
+ end
173
+ end
174
+
175
+ describe "ModelCompiler with real-world fixtures" do
176
+ it "compiles BasicDocument into instantiable classes" do
177
+ nil
178
+ file = Tempfile.new(%w[test .lutaml])
179
+ content = File.read(fixture_path("basicdoc-models", "BasicSection.lutaml"))
180
+ file.write(wrap_in_diagram(content))
181
+ file.rewind
182
+ result = Lutaml::Lml.compile(file)
183
+
184
+ expect(result).to have_key("BasicSection")
185
+ section = result["BasicSection"]
186
+ obj = section.new("title" => "Test Section", "id" => "sec-1")
187
+ expect(obj.id).to eq("sec-1")
188
+ file.close!
189
+ end
190
+ end
191
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe "RS 3001 typed references (par. Value type)" do
6
+ def parse(src)
7
+ Lutaml::Lml.parse_document(StringIO.new(src))
8
+ end
9
+
10
+ let(:doc) do
11
+ parse(<<~LML)
12
+ instances {
13
+ Product "a" {
14
+ id = "A"
15
+ }
16
+ Product "b" {
17
+ id = "B"
18
+ same = ref:(a.id)
19
+ full = reference:(a)
20
+ }
21
+ Item "listy" {
22
+ refs = [reference:(a.id), ref:(b.id)]
23
+ }
24
+ }
25
+ LML
26
+ end
27
+
28
+ it "exposes a typed Reference per attribute" do
29
+ b = doc.instances.instances.find { |i| i.name == "b" }
30
+ same = b.attributes.find { |a| a.name == "same" }
31
+ full = b.attributes.find { |a| a.name == "full" }
32
+ expect(same.reference).to be_a(Lutaml::Lml::Reference)
33
+ expect(same.reference.path).to eq("a.id")
34
+ expect(same.reference.segments).to eq(%w[a id])
35
+ expect(full.reference.path).to eq("a")
36
+ end
37
+
38
+ it "returns nil for non-reference values" do
39
+ a = doc.instances.instances.find { |i| i.name == "a" }
40
+ id = a.attributes.find { |attr| attr.name == "id" }
41
+ expect(id.reference).to be_nil
42
+ end
43
+
44
+ it "sees references inside list values" do
45
+ item = doc.instances.instances.find { |i| i.name == "listy" }
46
+ refs = item.attributes.find { |attr| attr.name == "refs" }
47
+ expect(refs.reference.path).to eq("a.id")
48
+ end
49
+
50
+ it "round trips references through LML emission" do
51
+ emitted = Lutaml::Lml::Format::Adapter::StandardAdapter.new(
52
+ {
53
+ "same" => { reference: "a.id" },
54
+ "refs" => [{ reference: "a.id" }, { reference: "b.id" }],
55
+ },
56
+ )
57
+ lml = emitted.to_lml
58
+ expect(lml).to include("same = ref:(a.id)")
59
+ expect(lml).to include("ref:(a.id)")
60
+ expect(lml).to include("ref:(b.id)")
61
+ reparsed = parse("instances {\n#{lml}\n}\n")
62
+ expect(reparsed).to be_a(Lutaml::Lml::Document)
63
+ end
64
+ end