@native-sdk/cli 0.0.0 → 0.4.1

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 (373) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +50 -1
  3. package/app.zon +30 -0
  4. package/assets/icon.icns +0 -0
  5. package/assets/icon.ico +0 -0
  6. package/assets/icon.png +0 -0
  7. package/assets/icon.svg +15 -0
  8. package/assets/native-sdk.entitlements +10 -0
  9. package/assets/native-sdk.manifest +12 -0
  10. package/bin/native.js +156 -0
  11. package/build/app.zig +716 -0
  12. package/build.zig +2593 -0
  13. package/build.zig.zon +24 -0
  14. package/native-sdk.d.ts +615 -0
  15. package/package.json +45 -8
  16. package/skill-data/automation/SKILL.md +248 -0
  17. package/skill-data/core/SKILL.md +249 -0
  18. package/skill-data/core/references/app-model-runtime.md +141 -0
  19. package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
  20. package/skill-data/core/references/frontend-assets.md +124 -0
  21. package/skill-data/core/references/project-anatomy.md +108 -0
  22. package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
  23. package/skill-data/native-ui/SKILL.md +1080 -0
  24. package/skills/native-sdk/SKILL.md +33 -0
  25. package/src/app_runner/root.zig +740 -0
  26. package/src/assets/root.zig +20 -0
  27. package/src/automation/protocol.zig +285 -0
  28. package/src/automation/root.zig +13 -0
  29. package/src/automation/server.zig +506 -0
  30. package/src/automation/snapshot.zig +1202 -0
  31. package/src/automation/watcher.zig +165 -0
  32. package/src/bridge/root.zig +507 -0
  33. package/src/debug/root.zig +246 -0
  34. package/src/embed/app_exports.zig +11 -0
  35. package/src/embed/c_api.zig +793 -0
  36. package/src/embed/c_exports.zig +10 -0
  37. package/src/embed/chrome.zig +168 -0
  38. package/src/embed/conversions.zig +359 -0
  39. package/src/embed/host.zig +960 -0
  40. package/src/embed/root.zig +81 -0
  41. package/src/embed/tests.zig +2552 -0
  42. package/src/embed/types.zig +382 -0
  43. package/src/embed/ui_host.zig +289 -0
  44. package/src/extensions/root.zig +197 -0
  45. package/src/frontend/root.zig +48 -0
  46. package/src/js/root.zig +65 -0
  47. package/src/platform/android/NativeSdkActivity.java +1370 -0
  48. package/src/platform/android/android_host.c +696 -0
  49. package/src/platform/android/files.zig +9 -0
  50. package/src/platform/android/native_sdk_app.h +237 -0
  51. package/src/platform/ios/files.zig +8 -0
  52. package/src/platform/ios/native_sdk_app.h +289 -0
  53. package/src/platform/ios/uikit_host.m +2739 -0
  54. package/src/platform/linux/cef_host.cpp +599 -0
  55. package/src/platform/linux/gtk_host.c +5362 -0
  56. package/src/platform/linux/gtk_host.h +265 -0
  57. package/src/platform/linux/root.zig +1519 -0
  58. package/src/platform/macos/appkit_host.h +604 -0
  59. package/src/platform/macos/appkit_host.m +10392 -0
  60. package/src/platform/macos/automation_host.h +14 -0
  61. package/src/platform/macos/automation_host.m +12 -0
  62. package/src/platform/macos/cef_host.mm +3028 -0
  63. package/src/platform/macos/root.zig +2260 -0
  64. package/src/platform/null_platform.zig +2232 -0
  65. package/src/platform/null_platform_tests.zig +670 -0
  66. package/src/platform/policy_values.zig +14 -0
  67. package/src/platform/root.zig +181 -0
  68. package/src/platform/types.zig +2681 -0
  69. package/src/platform/windows/cef_host.cpp +3 -0
  70. package/src/platform/windows/root.zig +1521 -0
  71. package/src/platform/windows/webview2_host.cpp +6230 -0
  72. package/src/primitives/app_dirs/root.zig +440 -0
  73. package/src/primitives/app_manifest/root.zig +109 -0
  74. package/src/primitives/app_manifest/tests.zig +758 -0
  75. package/src/primitives/app_manifest/types.zig +587 -0
  76. package/src/primitives/app_manifest/validation.zig +828 -0
  77. package/src/primitives/assets/root.zig +520 -0
  78. package/src/primitives/canvas/a11y_audit.zig +390 -0
  79. package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
  80. package/src/primitives/canvas/app_icon.zig +1590 -0
  81. package/src/primitives/canvas/chart.zig +392 -0
  82. package/src/primitives/canvas/chart_tests.zig +751 -0
  83. package/src/primitives/canvas/commands.zig +446 -0
  84. package/src/primitives/canvas/drawing.zig +309 -0
  85. package/src/primitives/canvas/equality.zig +316 -0
  86. package/src/primitives/canvas/events.zig +696 -0
  87. package/src/primitives/canvas/font_coverage.zig +118 -0
  88. package/src/primitives/canvas/font_ttf.zig +510 -0
  89. package/src/primitives/canvas/font_ttf_tests.zig +280 -0
  90. package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
  91. package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
  92. package/src/primitives/canvas/frame.zig +679 -0
  93. package/src/primitives/canvas/frame_metrics.zig +462 -0
  94. package/src/primitives/canvas/gpu.zig +639 -0
  95. package/src/primitives/canvas/hash.zig +112 -0
  96. package/src/primitives/canvas/icons/alert.svg +1 -0
  97. package/src/primitives/canvas/icons/archive.svg +1 -0
  98. package/src/primitives/canvas/icons/arrow-down.svg +1 -0
  99. package/src/primitives/canvas/icons/arrow-right.svg +1 -0
  100. package/src/primitives/canvas/icons/arrow-up.svg +1 -0
  101. package/src/primitives/canvas/icons/check-circle.svg +1 -0
  102. package/src/primitives/canvas/icons/check.svg +1 -0
  103. package/src/primitives/canvas/icons/chevron-down.svg +1 -0
  104. package/src/primitives/canvas/icons/chevron-left.svg +1 -0
  105. package/src/primitives/canvas/icons/chevron-right.svg +1 -0
  106. package/src/primitives/canvas/icons/chevron-up.svg +1 -0
  107. package/src/primitives/canvas/icons/circle-dot.svg +1 -0
  108. package/src/primitives/canvas/icons/clock.svg +1 -0
  109. package/src/primitives/canvas/icons/copy.svg +1 -0
  110. package/src/primitives/canvas/icons/download.svg +1 -0
  111. package/src/primitives/canvas/icons/edit.svg +1 -0
  112. package/src/primitives/canvas/icons/ellipsis.svg +1 -0
  113. package/src/primitives/canvas/icons/external-link.svg +1 -0
  114. package/src/primitives/canvas/icons/eye.svg +1 -0
  115. package/src/primitives/canvas/icons/file-text.svg +1 -0
  116. package/src/primitives/canvas/icons/folder-open.svg +1 -0
  117. package/src/primitives/canvas/icons/folder.svg +1 -0
  118. package/src/primitives/canvas/icons/git-branch.svg +1 -0
  119. package/src/primitives/canvas/icons/git-merge.svg +1 -0
  120. package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
  121. package/src/primitives/canvas/icons/info.svg +1 -0
  122. package/src/primitives/canvas/icons/menu.svg +1 -0
  123. package/src/primitives/canvas/icons/missing.svg +1 -0
  124. package/src/primitives/canvas/icons/moon.svg +1 -0
  125. package/src/primitives/canvas/icons/music.svg +1 -0
  126. package/src/primitives/canvas/icons/panel-left.svg +1 -0
  127. package/src/primitives/canvas/icons/panel-right.svg +1 -0
  128. package/src/primitives/canvas/icons/pause.svg +1 -0
  129. package/src/primitives/canvas/icons/play.svg +1 -0
  130. package/src/primitives/canvas/icons/plus.svg +1 -0
  131. package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
  132. package/src/primitives/canvas/icons/repeat.svg +1 -0
  133. package/src/primitives/canvas/icons/save.svg +1 -0
  134. package/src/primitives/canvas/icons/search.svg +1 -0
  135. package/src/primitives/canvas/icons/send.svg +1 -0
  136. package/src/primitives/canvas/icons/settings.svg +1 -0
  137. package/src/primitives/canvas/icons/shuffle.svg +1 -0
  138. package/src/primitives/canvas/icons/skip-back.svg +1 -0
  139. package/src/primitives/canvas/icons/skip-forward.svg +1 -0
  140. package/src/primitives/canvas/icons/sun.svg +1 -0
  141. package/src/primitives/canvas/icons/terminal.svg +1 -0
  142. package/src/primitives/canvas/icons/trash.svg +1 -0
  143. package/src/primitives/canvas/icons/volume.svg +1 -0
  144. package/src/primitives/canvas/icons/wrench.svg +1 -0
  145. package/src/primitives/canvas/icons/x-circle.svg +1 -0
  146. package/src/primitives/canvas/icons/x.svg +1 -0
  147. package/src/primitives/canvas/icons.zig +249 -0
  148. package/src/primitives/canvas/layout_audit.zig +744 -0
  149. package/src/primitives/canvas/layout_audit_tests.zig +426 -0
  150. package/src/primitives/canvas/markdown.zig +1031 -0
  151. package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
  152. package/src/primitives/canvas/markdown_tests.zig +538 -0
  153. package/src/primitives/canvas/plan_key_index.zig +120 -0
  154. package/src/primitives/canvas/png.zig +355 -0
  155. package/src/primitives/canvas/reference.zig +1457 -0
  156. package/src/primitives/canvas/reference_blur.zig +104 -0
  157. package/src/primitives/canvas/reference_memo.zig +322 -0
  158. package/src/primitives/canvas/reference_paths.zig +184 -0
  159. package/src/primitives/canvas/reference_tests.zig +1650 -0
  160. package/src/primitives/canvas/render.zig +747 -0
  161. package/src/primitives/canvas/render_effects.zig +255 -0
  162. package/src/primitives/canvas/render_fingerprints.zig +256 -0
  163. package/src/primitives/canvas/render_generic_resources.zig +376 -0
  164. package/src/primitives/canvas/render_images.zig +247 -0
  165. package/src/primitives/canvas/render_layers.zig +260 -0
  166. package/src/primitives/canvas/render_paths.zig +347 -0
  167. package/src/primitives/canvas/render_resources.zig +51 -0
  168. package/src/primitives/canvas/render_tests.zig +3186 -0
  169. package/src/primitives/canvas/root.zig +744 -0
  170. package/src/primitives/canvas/serialization.zig +1528 -0
  171. package/src/primitives/canvas/svg_icon.zig +636 -0
  172. package/src/primitives/canvas/svg_icon_tests.zig +312 -0
  173. package/src/primitives/canvas/test_support.zig +422 -0
  174. package/src/primitives/canvas/testdata/markdown_document.md +83 -0
  175. package/src/primitives/canvas/tests.zig +30 -0
  176. package/src/primitives/canvas/text.zig +82 -0
  177. package/src/primitives/canvas/text_atlas.zig +408 -0
  178. package/src/primitives/canvas/text_batch_tests.zig +431 -0
  179. package/src/primitives/canvas/text_interaction.zig +615 -0
  180. package/src/primitives/canvas/text_layout.zig +1069 -0
  181. package/src/primitives/canvas/text_layout_cache.zig +281 -0
  182. package/src/primitives/canvas/text_layout_hash.zig +113 -0
  183. package/src/primitives/canvas/text_layout_types.zig +128 -0
  184. package/src/primitives/canvas/text_measure_cache.zig +279 -0
  185. package/src/primitives/canvas/text_metrics.zig +309 -0
  186. package/src/primitives/canvas/text_metrics_tests.zig +262 -0
  187. package/src/primitives/canvas/text_span_tests.zig +608 -0
  188. package/src/primitives/canvas/text_spans.zig +1010 -0
  189. package/src/primitives/canvas/text_tests.zig +1949 -0
  190. package/src/primitives/canvas/themes/geist.zig +470 -0
  191. package/src/primitives/canvas/tokens.zig +1522 -0
  192. package/src/primitives/canvas/ui.zig +2686 -0
  193. package/src/primitives/canvas/ui_markup.zig +3791 -0
  194. package/src/primitives/canvas/ui_markup_binary.zig +522 -0
  195. package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
  196. package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
  197. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
  198. package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
  199. package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
  200. package/src/primitives/canvas/ui_markup_edit.zig +416 -0
  201. package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
  202. package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
  203. package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
  204. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
  205. package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
  206. package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
  207. package/src/primitives/canvas/ui_markup_view.zig +2352 -0
  208. package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
  209. package/src/primitives/canvas/ui_provenance.zig +96 -0
  210. package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
  211. package/src/primitives/canvas/ui_schema.zig +825 -0
  212. package/src/primitives/canvas/ui_schema_tests.zig +128 -0
  213. package/src/primitives/canvas/ui_tests.zig +1432 -0
  214. package/src/primitives/canvas/vector.zig +919 -0
  215. package/src/primitives/canvas/vector_tests.zig +547 -0
  216. package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
  217. package/src/primitives/canvas/virtual_extents.zig +540 -0
  218. package/src/primitives/canvas/widget_access.zig +208 -0
  219. package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
  220. package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
  221. package/src/primitives/canvas/widget_invalidation.zig +748 -0
  222. package/src/primitives/canvas/widget_layout.zig +2055 -0
  223. package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
  224. package/src/primitives/canvas/widget_metrics.zig +228 -0
  225. package/src/primitives/canvas/widget_render.zig +2534 -0
  226. package/src/primitives/canvas/widget_render_controls.zig +1563 -0
  227. package/src/primitives/canvas/widget_render_scroll.zig +136 -0
  228. package/src/primitives/canvas/widget_render_style.zig +626 -0
  229. package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
  230. package/src/primitives/canvas/widget_routing.zig +475 -0
  231. package/src/primitives/canvas/widget_runtime.zig +307 -0
  232. package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
  233. package/src/primitives/canvas/widget_semantics.zig +480 -0
  234. package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
  235. package/src/primitives/canvas/widget_tests.zig +8 -0
  236. package/src/primitives/canvas/widget_text_input.zig +351 -0
  237. package/src/primitives/canvas/widget_text_select.zig +147 -0
  238. package/src/primitives/canvas/widget_tree.zig +232 -0
  239. package/src/primitives/canvas/widgets.zig +1319 -0
  240. package/src/primitives/diagnostics/root.zig +445 -0
  241. package/src/primitives/geometry/root.zig +889 -0
  242. package/src/primitives/json/root.zig +272 -0
  243. package/src/primitives/platform_info/root.zig +450 -0
  244. package/src/primitives/trace/root.zig +569 -0
  245. package/src/root.zig +165 -0
  246. package/src/runtime/api.zig +431 -0
  247. package/src/runtime/async_bridge.zig +49 -0
  248. package/src/runtime/automation_commands.zig +686 -0
  249. package/src/runtime/automation_liveness_tests.zig +140 -0
  250. package/src/runtime/automation_snapshot.zig +246 -0
  251. package/src/runtime/automation_widget_dispatch.zig +617 -0
  252. package/src/runtime/bridge_dispatch_tests.zig +202 -0
  253. package/src/runtime/bridge_payload.zig +194 -0
  254. package/src/runtime/bridge_permission_tests.zig +551 -0
  255. package/src/runtime/bridge_responses.zig +414 -0
  256. package/src/runtime/builtin_bridge.zig +554 -0
  257. package/src/runtime/canvas_budget_edge_tests.zig +415 -0
  258. package/src/runtime/canvas_font_tests.zig +410 -0
  259. package/src/runtime/canvas_fonts.zig +229 -0
  260. package/src/runtime/canvas_frame.zig +1734 -0
  261. package/src/runtime/canvas_frame_animation_tests.zig +609 -0
  262. package/src/runtime/canvas_frame_cache_tests.zig +333 -0
  263. package/src/runtime/canvas_frame_helpers.zig +414 -0
  264. package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
  265. package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
  266. package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
  267. package/src/runtime/canvas_frame_retained_tests.zig +753 -0
  268. package/src/runtime/canvas_frame_tests.zig +9 -0
  269. package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
  270. package/src/runtime/canvas_image_tests.zig +362 -0
  271. package/src/runtime/canvas_images.zig +224 -0
  272. package/src/runtime/canvas_limits.zig +317 -0
  273. package/src/runtime/canvas_screenshot_tests.zig +289 -0
  274. package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
  275. package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
  276. package/src/runtime/canvas_widget_chart_tests.zig +249 -0
  277. package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
  278. package/src/runtime/canvas_widget_context_menu.zig +318 -0
  279. package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
  280. package/src/runtime/canvas_widget_control_tests.zig +2164 -0
  281. package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
  282. package/src/runtime/canvas_widget_display.zig +677 -0
  283. package/src/runtime/canvas_widget_event_tests.zig +1779 -0
  284. package/src/runtime/canvas_widget_events.zig +1098 -0
  285. package/src/runtime/canvas_widget_floating_tests.zig +695 -0
  286. package/src/runtime/canvas_widget_layout_tests.zig +26 -0
  287. package/src/runtime/canvas_widget_runtime.zig +1335 -0
  288. package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
  289. package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
  290. package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
  291. package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
  292. package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
  293. package/src/runtime/canvas_widget_state.zig +798 -0
  294. package/src/runtime/canvas_widget_text_tests.zig +2104 -0
  295. package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
  296. package/src/runtime/clock.zig +231 -0
  297. package/src/runtime/core.zig +927 -0
  298. package/src/runtime/effects.zig +4197 -0
  299. package/src/runtime/effects_audio_tests.zig +690 -0
  300. package/src/runtime/effects_clipboard_tests.zig +317 -0
  301. package/src/runtime/effects_fetch_tests.zig +1031 -0
  302. package/src/runtime/effects_file_tests.zig +407 -0
  303. package/src/runtime/effects_tests.zig +1251 -0
  304. package/src/runtime/flow.zig +1175 -0
  305. package/src/runtime/frame_profile.zig +221 -0
  306. package/src/runtime/gpu_surface_events.zig +639 -0
  307. package/src/runtime/launch_timing.zig +59 -0
  308. package/src/runtime/markdown_app_tests.zig +224 -0
  309. package/src/runtime/native_command_event_tests.zig +431 -0
  310. package/src/runtime/platform_bridge_tests.zig +8 -0
  311. package/src/runtime/platform_config_tests.zig +392 -0
  312. package/src/runtime/root.zig +150 -0
  313. package/src/runtime/runtime_event_tests.zig +1079 -0
  314. package/src/runtime/session_journal.zig +1522 -0
  315. package/src/runtime/session_record.zig +332 -0
  316. package/src/runtime/session_replay.zig +274 -0
  317. package/src/runtime/session_state.zig +30 -0
  318. package/src/runtime/session_tests.zig +399 -0
  319. package/src/runtime/shell_layout.zig +472 -0
  320. package/src/runtime/shell_layout_tests.zig +1246 -0
  321. package/src/runtime/shell_view_tests.zig +604 -0
  322. package/src/runtime/state.zig +110 -0
  323. package/src/runtime/system_services.zig +392 -0
  324. package/src/runtime/test_support.zig +79 -0
  325. package/src/runtime/tests.zig +30 -0
  326. package/src/runtime/ui_app.zig +3290 -0
  327. package/src/runtime/ui_app_huge_model_tests.zig +351 -0
  328. package/src/runtime/ui_app_provenance.zig +370 -0
  329. package/src/runtime/ui_app_tests.zig +3254 -0
  330. package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
  331. package/src/runtime/ui_app_window_tests.zig +442 -0
  332. package/src/runtime/validation.zig +206 -0
  333. package/src/runtime/view.zig +908 -0
  334. package/src/runtime/view_canvas.zig +850 -0
  335. package/src/runtime/view_widget_control.zig +433 -0
  336. package/src/runtime/view_widget_scroll.zig +360 -0
  337. package/src/runtime/view_widget_text.zig +275 -0
  338. package/src/runtime/view_widget_tree.zig +843 -0
  339. package/src/runtime/webview_view_bridge_tests.zig +664 -0
  340. package/src/runtime/widget_bridge.zig +231 -0
  341. package/src/runtime/window_command_bridge_tests.zig +403 -0
  342. package/src/runtime/window_storage.zig +255 -0
  343. package/src/runtime/window_view_runtime.zig +727 -0
  344. package/src/runtime/window_views.zig +334 -0
  345. package/src/security/root.zig +118 -0
  346. package/src/tooling/android.zig +1172 -0
  347. package/src/tooling/assets.zig +128 -0
  348. package/src/tooling/buildgraph.zig +379 -0
  349. package/src/tooling/cef.zig +671 -0
  350. package/src/tooling/codesign.zig +172 -0
  351. package/src/tooling/components/identity_tests.zig +185 -0
  352. package/src/tooling/components/stepper.zig +113 -0
  353. package/src/tooling/components/timeline.native +27 -0
  354. package/src/tooling/components/timeline_item.zig +131 -0
  355. package/src/tooling/default_icon.icns +0 -0
  356. package/src/tooling/default_icon.png +0 -0
  357. package/src/tooling/dev.zig +172 -0
  358. package/src/tooling/doctor.zig +349 -0
  359. package/src/tooling/eject_components.zig +170 -0
  360. package/src/tooling/embedlib.zig +290 -0
  361. package/src/tooling/ios.zig +528 -0
  362. package/src/tooling/manifest.zig +1939 -0
  363. package/src/tooling/package.zig +2388 -0
  364. package/src/tooling/process_tree.zig +114 -0
  365. package/src/tooling/raw_manifest.zig +193 -0
  366. package/src/tooling/root.zig +22 -0
  367. package/src/tooling/templates.zig +3191 -0
  368. package/src/tooling/toolchain.zig +371 -0
  369. package/src/tooling/verbs.zig +204 -0
  370. package/src/tooling/web_engine.zig +135 -0
  371. package/src/tooling/xcodeproj.zig +462 -0
  372. package/src/window_state/root.zig +507 -0
  373. package/index.js +0 -2
@@ -0,0 +1,1545 @@
1
+ const std = @import("std");
2
+ const markup = @import("ui_markup.zig");
3
+
4
+ const testing = std.testing;
5
+
6
+ const inbox_source =
7
+ \\<!-- The inbox mockup, adjusted to the shipped v1 grammar. -->
8
+ \\<column gap="12" padding="16">
9
+ \\ <row gap="8" cross="center">
10
+ \\ <text-field placeholder="New task…" on-input="draft" on-submit="add" grow="1" />
11
+ \\ <button variant="primary" on-press="add">Add</button>
12
+ \\ </row>
13
+ \\ <row gap="8">
14
+ \\ <for each="filters" as="f">
15
+ \\ <button selected="{f == filter}" on-press="set_filter:{f}">{f}</button>
16
+ \\ </for>
17
+ \\ </row>
18
+ \\ <scroll grow="1">
19
+ \\ <column gap="2">
20
+ \\ <for each="visible" key="id" as="t">
21
+ \\ <row gap="8" padding="6" cross="center" global-key="{t.id}">
22
+ \\ <checkbox checked="{t.done}" on-toggle="toggle:{t.id}" label="Done" />
23
+ \\ <text grow="1">{t.title}</text>
24
+ \\ </row>
25
+ \\ </for>
26
+ \\ </column>
27
+ \\ </scroll>
28
+ \\ <status-bar>{open_count} open · {done_count} done</status-bar>
29
+ \\</column>
30
+ ;
31
+
32
+ fn parseSource(arena: std.mem.Allocator, source: []const u8) !markup.MarkupDocument {
33
+ var parser = markup.Parser.init(arena, source);
34
+ return parser.parse();
35
+ }
36
+
37
+ test "parses the inbox mockup into the expected tree shape" {
38
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
39
+ defer arena_state.deinit();
40
+
41
+ const document = try parseSource(arena_state.allocator(), inbox_source);
42
+ const root = document.root.?;
43
+
44
+ try testing.expectEqual(markup.MarkupNodeKind.element, root.kind);
45
+ try testing.expectEqualStrings("column", root.name);
46
+ try testing.expectEqualStrings("12", root.attr("gap").?);
47
+ try testing.expectEqual(@as(usize, 4), root.children.len);
48
+
49
+ const toolbar = root.children[0];
50
+ try testing.expectEqualStrings("row", toolbar.name);
51
+ try testing.expectEqualStrings("text-field", toolbar.children[0].name);
52
+ try testing.expectEqualStrings("draft", toolbar.children[0].attr("on-input").?);
53
+
54
+ const add_button = toolbar.children[1];
55
+ try testing.expectEqualStrings("button", add_button.name);
56
+ try testing.expectEqual(@as(usize, 1), add_button.children.len);
57
+ try testing.expectEqual(markup.MarkupNodeKind.text, add_button.children[0].kind);
58
+ try testing.expectEqualStrings("Add", add_button.children[0].text);
59
+
60
+ const filters_row = root.children[1];
61
+ const filters_for = filters_row.children[0];
62
+ try testing.expectEqual(markup.MarkupNodeKind.for_block, filters_for.kind);
63
+ try testing.expectEqualStrings("filters", filters_for.attr("each").?);
64
+ try testing.expectEqualStrings("f", filters_for.attr("as").?);
65
+
66
+ const tasks_for = root.children[2].children[0].children[0];
67
+ try testing.expectEqual(markup.MarkupNodeKind.for_block, tasks_for.kind);
68
+ try testing.expectEqualStrings("id", tasks_for.attr("key").?);
69
+ const task_row = tasks_for.children[0];
70
+ try testing.expectEqualStrings("{t.id}", task_row.attr("global-key").?);
71
+
72
+ const status = root.children[3];
73
+ try testing.expectEqualStrings("status-bar", status.name);
74
+ try testing.expectEqualStrings("{open_count} open · {done_count} done", status.children[0].text);
75
+ }
76
+
77
+ test "reports syntax errors with line and column" {
78
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
79
+ defer arena_state.deinit();
80
+
81
+ const cases = [_]struct { source: []const u8, line: usize }{
82
+ .{ .source = "<row>\n <button>Add</row>\n</row>", .line = 2 },
83
+ .{ .source = "<row gap=12></row>", .line = 1 },
84
+ .{ .source = "<row><button>Add</button>", .line = 1 },
85
+ .{ .source = "<row></row><row></row>", .line = 1 },
86
+ .{ .source = "<row gap=\"8></row>", .line = 1 },
87
+ };
88
+ for (cases) |case| {
89
+ var parser = markup.Parser.init(arena_state.allocator(), case.source);
90
+ try testing.expectError(error.MarkupSyntax, parser.parse());
91
+ try testing.expect(parser.diagnostic.message.len > 0);
92
+ try testing.expectEqual(case.line, parser.diagnostic.line);
93
+ }
94
+ }
95
+
96
+ test "attribute expressions classify into the sanctioned forms" {
97
+ const literal = markup.parseAttrExpression("primary").?;
98
+ try testing.expectEqualStrings("primary", literal.literal);
99
+
100
+ const binding = markup.parseAttrExpression("{t.done}").?;
101
+ try testing.expectEqualStrings("t.done", binding.binding);
102
+
103
+ const equals = markup.parseAttrExpression("{f == filter}").?;
104
+ try testing.expectEqualStrings("f", equals.equals.left);
105
+ try testing.expectEqualStrings("filter", equals.equals.right);
106
+
107
+ // Everything else brace-wrapped classifies as a full expression: the
108
+ // grammar (and its teaching errors) live in the expression core, which
109
+ // `attrExpressionError` and the engines run.
110
+ const arithmetic = markup.parseAttrExpression("{a + b}").?;
111
+ try testing.expectEqualStrings("a + b", arithmetic.expression);
112
+ try testing.expect(markup.attrExpressionError("{a + b}", "fallback") == null);
113
+ try testing.expect(markup.attrExpressionError("{count > 0 and not busy}", "fallback") == null);
114
+ try testing.expect(markup.attrExpressionError("{plural(n, 'item', 'items')}", "fallback") == null);
115
+
116
+ // Invalid expressions surface the core's specific messages.
117
+ try testing.expectEqualStrings(
118
+ markup.expr.unknown_function_message,
119
+ markup.attrExpressionError("{call(a)}", "fallback").?,
120
+ );
121
+ try testing.expectEqualStrings(
122
+ markup.expr.comparison_chain_message,
123
+ markup.attrExpressionError("{a == b == c}", "fallback").?,
124
+ );
125
+ try testing.expectEqualStrings(
126
+ markup.expr.clock_function_message,
127
+ markup.attrExpressionError("{now()}", "fallback").?,
128
+ );
129
+ try testing.expectEqualStrings(
130
+ markup.expr.arithmetic_type_message,
131
+ markup.attrExpressionError("{'a' - 1}", "fallback").?,
132
+ );
133
+
134
+ // Values that do not even classify keep the caller's message.
135
+ try testing.expectEqual(@as(?markup.Expression, null), markup.parseAttrExpression("{}"));
136
+ try testing.expectEqual(@as(?markup.Expression, null), markup.parseAttrExpression("{unclosed"));
137
+ try testing.expectEqualStrings("fallback", markup.attrExpressionError("{}", "fallback").?);
138
+ }
139
+
140
+ test "message expressions parse tag and optional payload binding" {
141
+ const plain = markup.parseMessageExpression("add").?;
142
+ try testing.expectEqualStrings("add", plain.tag);
143
+ try testing.expectEqualStrings("", plain.payload);
144
+
145
+ const with_payload = markup.parseMessageExpression("toggle:{t.id}").?;
146
+ try testing.expectEqualStrings("toggle", with_payload.tag);
147
+ try testing.expectEqualStrings("t.id", with_payload.payload);
148
+
149
+ try testing.expectEqual(@as(?markup.MessageExpression, null), markup.parseMessageExpression("toggle:t.id"));
150
+ try testing.expectEqual(@as(?markup.MessageExpression, null), markup.parseMessageExpression("toggle:{}"));
151
+ try testing.expectEqual(@as(?markup.MessageExpression, null), markup.parseMessageExpression("1add"));
152
+ }
153
+
154
+ test "templates parse before the root and expose name and args" {
155
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
156
+ defer arena_state.deinit();
157
+
158
+ const source =
159
+ \\<template name="pill" args="label">
160
+ \\ <badge>{label}</badge>
161
+ \\</template>
162
+ \\<template name="pill-row" args="a b">
163
+ \\ <row gap="4">
164
+ \\ <use template="pill" label="{a}" />
165
+ \\ <use template="pill" label="{b}" />
166
+ \\ </row>
167
+ \\</template>
168
+ \\<row>
169
+ \\ <use template="pill-row" a="one" b="two" />
170
+ \\</row>
171
+ ;
172
+ const document = try parseSource(arena_state.allocator(), source);
173
+ try testing.expectEqual(@as(usize, 2), document.templates.len);
174
+ try testing.expectEqualStrings("pill", document.templates[0].attr("name").?);
175
+ try testing.expectEqual(@as(?usize, 1), document.templateIndex("pill-row"));
176
+ try testing.expectEqual(@as(?usize, null), document.templateIndex("missing"));
177
+
178
+ var args = markup.templateArgs(document.templates[1]);
179
+ try testing.expectEqualStrings("a", args.next().?);
180
+ try testing.expectEqualStrings("b", args.next().?);
181
+ try testing.expectEqual(@as(?[]const u8, null), args.next());
182
+ try testing.expect(markup.templateDeclaresArg(document.templates[0], "label"));
183
+ try testing.expect(!markup.templateDeclaresArg(document.templates[0], "cards"));
184
+
185
+ try testing.expectEqualStrings("row", document.root.?.name);
186
+ try testing.expectEqual(markup.MarkupNodeKind.use_block, document.root.?.children[0].kind);
187
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(document));
188
+ }
189
+
190
+ test "a template file without a view root parses as a component file" {
191
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
192
+ defer arena_state.deinit();
193
+
194
+ // Valid as an import target: all templates, no view root. The engines
195
+ // reject building it as a view with their own teaching error.
196
+ var parser = markup.Parser.init(arena_state.allocator(), "<template name=\"only\"><text>x</text></template>");
197
+ const document = try parser.parse();
198
+ try testing.expectEqual(@as(?markup.MarkupNode, null), document.root);
199
+ try testing.expectEqual(@as(usize, 1), document.templates.len);
200
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(document));
201
+
202
+ // A file with nothing at all stays an error.
203
+ var empty_parser = markup.Parser.init(arena_state.allocator(), " <!-- just a comment -->\n");
204
+ try testing.expectError(error.MarkupSyntax, empty_parser.parse());
205
+ try testing.expectEqualStrings(markup.empty_document_message, empty_parser.diagnostic.message);
206
+ }
207
+
208
+ test "template and use misuse is validated with positions and teaching messages" {
209
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
210
+ defer arena_state.deinit();
211
+
212
+ const cases = [_]struct { source: []const u8, message: []const u8 }{
213
+ // Templates must be top-level, named, unique, and single-bodied.
214
+ .{ .source = "<column>\n <template name=\"t\"><text>x</text></template>\n</column>", .message = markup.template_top_level_message },
215
+ .{ .source = "<template args=\"a\"><text>x</text></template>\n<row />", .message = markup.template_name_message },
216
+ .{ .source = "<template name=\"t\"><text>x</text></template>\n<template name=\"t\"><text>y</text></template>\n<row />", .message = markup.template_unique_name_message },
217
+ .{ .source = "<template name=\"t\" args=\"a.b\"><text>x</text></template>\n<row />", .message = markup.template_args_message },
218
+ .{ .source = "<template name=\"t\" bogus=\"1\"><text>x</text></template>\n<row />", .message = markup.template_attrs_message },
219
+ .{ .source = "<template name=\"t\"><text>x</text><text>y</text></template>\n<row />", .message = markup.template_one_child_message },
220
+ // Use sites must name a defined, earlier template and match its args.
221
+ .{ .source = "<row>\n <use />\n</row>", .message = markup.use_template_attr_message },
222
+ .{ .source = "<row>\n <use template=\"missing\" />\n</row>", .message = markup.use_undefined_template_message },
223
+ .{ .source = "<template name=\"a\"><column><use template=\"b\" /></column></template>\n<template name=\"b\"><text>x</text></template>\n<row />", .message = markup.use_earlier_template_message },
224
+ .{ .source = "<template name=\"t\" args=\"title\"><text>{title}</text></template>\n<row>\n <use template=\"t\" />\n</row>", .message = markup.use_missing_arg_message },
225
+ .{ .source = "<template name=\"t\"><text>x</text></template>\n<row>\n <use template=\"t\" extra=\"1\" />\n</row>", .message = markup.use_extra_arg_message },
226
+ .{ .source = "<template name=\"t\"><text>x</text></template>\n<row>\n <use template=\"t\"><text>y</text></use>\n</row>", .message = markup.use_children_without_slot_message },
227
+ .{ .source = "<template name=\"t\" args=\"title\"><text>{title}</text></template>\n<row>\n <use template=\"t\" title=\"{a ++}\" />\n</row>", .message = markup.expr.expected_operand_message },
228
+ // A template using itself is a later-reference error (recursion).
229
+ .{ .source = "<template name=\"loop\"><column><use template=\"loop\" /></column></template>\n<row />", .message = markup.use_earlier_template_message },
230
+ };
231
+ for (cases) |case| {
232
+ var parser = markup.Parser.init(arena_state.allocator(), case.source);
233
+ const info = markup.validate(try parser.parse()) orelse return error.TestUnexpectedResult;
234
+ try testing.expectEqualStrings(case.message, info.message);
235
+ try testing.expect(info.line > 0);
236
+ try testing.expect(info.column > 0);
237
+ }
238
+ }
239
+
240
+ test "style token attributes validate against the token name lists" {
241
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
242
+ defer arena_state.deinit();
243
+
244
+ // Every color style attribute accepts every known color token name,
245
+ // and radius accepts every radius token name.
246
+ for (markup.known_color_style_attrs) |attr| {
247
+ for (markup.known_color_token_names) |token| {
248
+ const source = try std.fmt.allocPrint(arena_state.allocator(), "<row {s}=\"{s}\" />", .{ attr, token });
249
+ var parser = markup.Parser.init(arena_state.allocator(), source);
250
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try parser.parse()));
251
+ }
252
+ }
253
+ for (markup.known_radius_token_names) |token| {
254
+ const source = try std.fmt.allocPrint(arena_state.allocator(), "<row radius=\"{s}\" />", .{token});
255
+ var parser = markup.Parser.init(arena_state.allocator(), source);
256
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try parser.parse()));
257
+ }
258
+
259
+ const cases = [_]struct { source: []const u8, message: []const u8 }{
260
+ .{ .source = "<row background=\"chartreuse\" />", .message = markup.unknown_color_token_message },
261
+ .{ .source = "<row foreground=\"#ff0000\" />", .message = markup.unknown_color_token_message },
262
+ .{ .source = "<row radius=\"tiny\" />", .message = markup.unknown_radius_token_message },
263
+ .{ .source = "<row background=\"{accentColor}\" />", .message = markup.style_token_literal_message },
264
+ .{ .source = "<row radius=\"{r}\" />", .message = markup.style_token_literal_message },
265
+ };
266
+ for (cases) |case| {
267
+ var parser = markup.Parser.init(arena_state.allocator(), case.source);
268
+ const info = markup.validate(try parser.parse()) orelse return error.TestUnexpectedResult;
269
+ try testing.expectEqualStrings(case.message, info.message);
270
+ try testing.expect(info.line > 0);
271
+ }
272
+ }
273
+
274
+ test "structural validation reports positions for grammar misuse" {
275
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
276
+ defer arena_state.deinit();
277
+
278
+ // The inbox fixture is fully valid.
279
+ var parser = markup.Parser.init(arena_state.allocator(), inbox_source);
280
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try parser.parse()));
281
+
282
+ // on-scroll validates on the scroll element itself.
283
+ const scrollable = "<scroll on-scroll=\"scrolled\">\n <column><text>x</text></column>\n</scroll>";
284
+ var scrollable_parser = markup.Parser.init(arena_state.allocator(), scrollable);
285
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try scrollable_parser.parse()));
286
+
287
+ // on-reach-end (the infinite-scroll fetch signal) validates on the
288
+ // scroll element too, with or without a payload.
289
+ const reachable = "<scroll on-reach-end=\"load_more\" on-scroll=\"scrolled\">\n <column><text>x</text></column>\n</scroll>";
290
+ var reachable_parser = markup.Parser.init(arena_state.allocator(), reachable);
291
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try reachable_parser.parse()));
292
+
293
+ // A built-in vector icon with a literal name and token tint is valid.
294
+ const icon_source = "<row gap=\"8\">\n <icon name=\"search\" width=\"16\" height=\"16\" foreground=\"accent\" />\n <text>Search</text>\n</row>";
295
+ var icon_parser = markup.Parser.init(arena_state.allocator(), icon_source);
296
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try icon_parser.parse()));
297
+
298
+ // The other two icon grammar forms are structurally valid: an
299
+ // app:<name> reference (its registration is `native check`'s job,
300
+ // through the model contract) and one {binding} producing the name.
301
+ const open_icon_source = "<row gap=\"8\">\n <icon name=\"app:wave-pulse\" />\n <icon name=\"{status_icon}\" />\n <button icon=\"app:wave\" on-press=\"play\">Wave</button>\n <button icon=\"{status_icon}\" on-press=\"play\">Status</button>\n</row>";
302
+ var open_icon_parser = markup.Parser.init(arena_state.allocator(), open_icon_source);
303
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try open_icon_parser.parse()));
304
+
305
+ // The labeled interactive elements take an inline icon (with or
306
+ // without a label): one hit target, one tint. Toggle-buttons cover
307
+ // chips and tab strips; list/menu items get a leading slot.
308
+ const button_icon_source = "<row gap=\"8\">\n <button icon=\"save\" on-press=\"save\">Save</button>\n <button icon=\"refresh-cw\" on-press=\"refresh\" label=\"Refresh\"></button>\n <toggle-button icon=\"arrow-up\" on-toggle=\"sort\">Newest</toggle-button>\n <list-item icon=\"folder\" on-press=\"open\">Projects</list-item>\n <menu-item icon=\"trash\" on-press=\"remove\">Delete</menu-item>\n <badge icon=\"check\">3</badge>\n</row>";
309
+ var button_icon_parser = markup.Parser.init(arena_state.allocator(), button_icon_source);
310
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try button_icon_parser.parse()));
311
+
312
+ // Autofocus on focusable controls: literal or bound.
313
+ const autofocus_source = "<column gap=\"8\">\n <text-field autofocus=\"true\" label=\"Title\" on-input=\"edit\" />\n <textarea autofocus=\"{editing}\" label=\"Body\" on-input=\"edit\" />\n</column>";
314
+ var autofocus_parser = markup.Parser.init(arena_state.allocator(), autofocus_source);
315
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try autofocus_parser.parse()));
316
+
317
+ const cases = [_]struct { source: []const u8, message: []const u8 }{
318
+ .{ .source = "<column>\n <weird />\n</column>", .message = "unknown element" },
319
+ .{ .source = "<column bogus=\"1\" />", .message = "unknown attribute" },
320
+ .{ .source = "<row>\n <button on-press=\"a + b\">X</button>\n</row>", .message = "invalid message expression: on-* takes a Msg tag (\"add\") or tag with one binding payload (\"toggle:{item.id}\")" },
321
+ .{ .source = "<row>\n <button on-hover=\"x\">X</button>\n</row>", .message = "unknown event attribute" },
322
+ .{ .source = "<column>\n <row on-change=\"select\">\n <text>press me</text>\n </row>\n</column>", .message = markup.non_hit_target_handler_message },
323
+ .{ .source = "<column on-input=\"draft\">\n <text>x</text>\n</column>", .message = markup.non_hit_target_handler_message },
324
+ .{ .source = "<table>\n <table-row on-submit=\"pick\">\n <table-cell>x</table-cell>\n </table-row>\n</table>", .message = markup.non_hit_target_handler_message },
325
+ .{ .source = "<row>\n <badge on-change=\"x\">3</badge>\n</row>", .message = markup.non_hit_target_handler_message },
326
+ // Full expressions are valid attribute values now; broken ones
327
+ // surface the expression core's specific teaching message.
328
+ .{ .source = "<row gap=\"{a +}\" />", .message = markup.expr.expected_operand_message },
329
+ .{ .source = "<row gap=\"{count(a)}\" />", .message = markup.expr.unknown_function_message },
330
+ .{ .source = "<row gap=\"{now()}\" />", .message = markup.expr.clock_function_message },
331
+ .{ .source = "<row gap=\"{'a' - 1}\" />", .message = markup.expr.arithmetic_type_message },
332
+ .{ .source = "<column>\n <for as=\"t\"><text>x</text></for>\n</column>", .message = "for requires an each attribute" },
333
+ .{ .source = "<column>\n <if><text>x</text></if>\n</column>", .message = "if requires a test attribute" },
334
+ .{ .source = "<column>\n <else><text>x</text></else>\n</column>", .message = markup.else_placement_message },
335
+ .{ .source = "<row>\n <button on-scroll=\"scrolled\">X</button>\n</row>", .message = markup.on_scroll_element_message },
336
+ .{ .source = "<column>\n <list on-scroll=\"scrolled\"><list-item>x</list-item></list>\n</column>", .message = markup.on_scroll_element_message },
337
+ .{ .source = "<row>\n <button on-reach-end=\"load_more\">X</button>\n</row>", .message = markup.on_reach_end_element_message },
338
+ .{ .source = "<column>\n <list on-reach-end=\"load_more\"><list-item>x</list-item></list>\n</column>", .message = markup.on_reach_end_element_message },
339
+ .{ .source = "<column>\n <text>x</text>\n <else><text>y</text></else>\n</column>", .message = markup.else_placement_message },
340
+ .{ .source = "<column>\n <for each=\"items\" as=\"t\"></for>\n</column>", .message = markup.for_children_message },
341
+ .{ .source = "<column>\n <for each=\"items\" as=\"t\">stray text</for>\n</column>", .message = markup.for_children_message },
342
+ // Icon: bare names are the closed built-in vocabulary; app: is
343
+ // the one namespace (well-shaped names only); bindings pass
344
+ // structurally. Leaf, icon-scoped attr.
345
+ .{ .source = "<row>\n <icon />\n</row>", .message = markup.icon_missing_name_message },
346
+ .{ .source = "<row>\n <icon name=\"sparkle-pony\" />\n</row>", .message = markup.icon_name_message },
347
+ .{ .source = "<row>\n <icon name=\"lib:search\" />\n</row>", .message = markup.icon_namespace_message },
348
+ .{ .source = "<row>\n <icon name=\"app:\" />\n</row>", .message = markup.app_icon_shape_message },
349
+ .{ .source = "<row>\n <icon name=\"app:Wave Pulse\" />\n</row>", .message = markup.app_icon_shape_message },
350
+ .{ .source = "<row>\n <icon name=\"app:wave--pulse\" />\n</row>", .message = markup.app_icon_shape_message },
351
+ .{ .source = "<row>\n <badge name=\"search\">3</badge>\n</row>", .message = markup.icon_name_element_message },
352
+ .{ .source = "<row>\n <icon name=\"search\"><text>x</text></icon>\n</row>", .message = markup.icon_children_message },
353
+ .{ .source = "<row>\n <icon name=\"search\" on-change=\"go\" />\n</row>", .message = markup.non_hit_target_handler_message },
354
+ // Button icon attr: the same grammar, button-scoped.
355
+ .{ .source = "<row>\n <button icon=\"sparkle-pony\">Save</button>\n</row>", .message = markup.button_icon_message },
356
+ .{ .source = "<row>\n <button icon=\"lib:save\">Save</button>\n</row>", .message = markup.icon_namespace_message },
357
+ .{ .source = "<row>\n <button icon=\"app:-wave\">Save</button>\n</row>", .message = markup.app_icon_shape_message },
358
+ .{ .source = "<row>\n <badge icon=\"sparkle-pony\">3</badge>\n</row>", .message = markup.button_icon_message },
359
+ .{ .source = "<row>\n <toggle-button icon=\"sparkle-pony\">Bold</toggle-button>\n</row>", .message = markup.button_icon_message },
360
+ .{ .source = "<column>\n <checkbox icon=\"check\">Done</checkbox>\n</column>", .message = markup.button_icon_element_message },
361
+ // Autofocus needs a focusable control; layout and decoration
362
+ // elements can never take the keyboard.
363
+ .{ .source = "<column>\n <row autofocus=\"true\">\n <text>x</text>\n </row>\n</column>", .message = markup.autofocus_element_message },
364
+ .{ .source = "<column>\n <badge autofocus=\"true\">3</badge>\n</column>", .message = markup.autofocus_element_message },
365
+ };
366
+ for (cases) |case| {
367
+ var case_parser = markup.Parser.init(arena_state.allocator(), case.source);
368
+ const info = markup.validate(try case_parser.parse()) orelse return error.TestUnexpectedResult;
369
+ try testing.expectEqualStrings(case.message, info.message);
370
+ try testing.expect(info.line > 0);
371
+ }
372
+ }
373
+
374
+ test "the tofu guard flags markup literals outside the bundled font's coverage" {
375
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
376
+ defer arena_state.deinit();
377
+
378
+ // Everything the showcase apps ship passes: typographic punctuation,
379
+ // accents, arrows are in the bundled face.
380
+ const covered_source = "<column gap=\"8\">\n <text>Cafe\xc3\xa9 \xe2\x80\xa6 \xc2\xb7 \xe2\x86\x92</text>\n <text-field placeholder=\"Search albums\xe2\x80\xa6\" on-input=\"edit\" />\n</column>";
381
+ var covered_parser = markup.Parser.init(arena_state.allocator(), covered_source);
382
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try covered_parser.parse()));
383
+
384
+ // Binding spans are skipped: dynamic values are the runtime Debug
385
+ // warning's job, not the static guard's.
386
+ const binding_source = "<column>\n <text>{shortcutHint} to send</text>\n</column>";
387
+ var binding_parser = markup.Parser.init(arena_state.allocator(), binding_source);
388
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try binding_parser.parse()));
389
+
390
+ // A ⌘ in text content errors AT the character's position.
391
+ const text_source = "<column>\n <text>Press \xe2\x8c\x98K to search</text>\n</column>";
392
+ var text_parser = markup.Parser.init(arena_state.allocator(), text_source);
393
+ const text_info = markup.validate(try text_parser.parse()) orelse return error.TestUnexpectedResult;
394
+ try testing.expectEqualStrings(markup.font_coverage_message, text_info.message);
395
+ try testing.expectEqual(@as(usize, 2), text_info.line);
396
+ try testing.expectEqual(@as(usize, 15), text_info.column);
397
+
398
+ // Text-bearing attribute literals ride the same guard.
399
+ const attr_cases = [_][]const u8{
400
+ "<row>\n <button label=\"\xe2\x8c\x98K\" on-press=\"go\">Go</button>\n</row>",
401
+ "<column>\n <text-field placeholder=\"\xe2\x8c\x98 to focus\" on-input=\"edit\" />\n</column>",
402
+ "<timeline>\n <timeline-item title=\"Done\" indicator=\"\xe2\x9c\x93\" />\n</timeline>",
403
+ "<column>\n <stepper active=\"{page}\">\n <step>Work \xe2\x8c\x98</step>\n </stepper>\n</column>",
404
+ };
405
+ for (attr_cases) |source| {
406
+ var case_parser = markup.Parser.init(arena_state.allocator(), source);
407
+ const info = markup.validate(try case_parser.parse()) orelse return error.TestUnexpectedResult;
408
+ try testing.expectEqualStrings(markup.font_coverage_message, info.message);
409
+ try testing.expect(info.line > 0);
410
+ }
411
+ }
412
+
413
+ test "the coverage scanner finds the first uncovered codepoint and skips bindings" {
414
+ try testing.expectEqual(@as(?markup.UncoveredCodepoint, null), markup.firstUncoveredCodepoint("plain words"));
415
+ try testing.expectEqual(@as(?markup.UncoveredCodepoint, null), markup.firstUncoveredCodepoint("caf\xc3\xa9 \xe2\x80\xa6 \xc2\xb7"));
416
+ try testing.expectEqual(@as(?markup.UncoveredCodepoint, null), markup.firstUncoveredCodepoint("{anything \xe2\x8c\x98 inside} stays dynamic"));
417
+
418
+ const found = markup.firstUncoveredCodepoint("Press \xe2\x8c\x98K").?;
419
+ try testing.expectEqual(@as(usize, 6), found.offset);
420
+ try testing.expectEqual(@as(u21, 0x2318), found.codepoint);
421
+ try testing.expectEqualStrings("\xe2\x8c\x98", found.bytes);
422
+
423
+ // Invalid UTF-8 reports as U+FFFD at the offending byte.
424
+ const invalid = markup.firstUncoveredCodepoint("ok \xff bytes").?;
425
+ try testing.expectEqual(@as(u21, 0xFFFD), invalid.codepoint);
426
+ try testing.expectEqual(@as(usize, 3), invalid.offset);
427
+ }
428
+ test "for accepts multiple element children and a trailing else for the empty case" {
429
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
430
+ defer arena_state.deinit();
431
+ const arena = arena_state.allocator();
432
+
433
+ // Multi-child for bodies: elements, if/else arms, and nested fors are
434
+ // all valid without a wrapper node.
435
+ const valid_sources = [_][]const u8{
436
+ "<column>\n <for each=\"items\" as=\"t\">\n <text>{t.title}</text>\n <separator />\n </for>\n</column>",
437
+ "<column>\n <for each=\"items\" as=\"t\">\n <if test=\"{t.done}\"><text>done</text></if>\n <else><text>{t.title}</text></else>\n </for>\n</column>",
438
+ "<column>\n <for each=\"items\" as=\"t\">\n <for each=\"t.tags\" as=\"tag\"><badge>{tag.name}</badge></for>\n </for>\n</column>",
439
+ "<column>\n <for each=\"items\" as=\"t\">\n <text>{t.title}</text>\n </for>\n <else>\n <text>Nothing yet</text>\n </else>\n</column>",
440
+ "<column>\n <for each=\"items\" as=\"t\">\n <text>{t.title}</text>\n </for>\n <else>\n <text>empty</text>\n </else>\n <text>after</text>\n</column>",
441
+ };
442
+ for (valid_sources) |source| {
443
+ var parser = markup.Parser.init(arena, source);
444
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try parser.parse()));
445
+ }
446
+
447
+ // An else after the for's else (or anywhere else) still teaches.
448
+ const stray = "<column>\n <for each=\"items\" as=\"t\"><text>{t.title}</text></for>\n <else><text>empty</text></else>\n <else><text>again</text></else>\n</column>";
449
+ var stray_parser = markup.Parser.init(arena, stray);
450
+ const info = markup.validate(try stray_parser.parse()) orelse return error.TestUnexpectedResult;
451
+ try testing.expectEqualStrings(markup.else_placement_message, info.message);
452
+ }
453
+
454
+ test "a dead handler on a non-hit-target element reports the attribute position" {
455
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
456
+ defer arena_state.deinit();
457
+
458
+ const source = "<column>\n <row gap=\"8\" on-change=\"select\">\n <text>press me</text>\n </row>\n</column>";
459
+ var parser = markup.Parser.init(arena_state.allocator(), source);
460
+ const info = markup.validate(try parser.parse()) orelse return error.TestUnexpectedResult;
461
+ try testing.expectEqualStrings(markup.non_hit_target_handler_message, info.message);
462
+ try testing.expectEqual(@as(usize, 2), info.line);
463
+ // The diagnostic points at the on-change attribute, not the element.
464
+ try testing.expectEqual(@as(usize, 16), info.column);
465
+
466
+ // The same handler on a control inside the row validates clean.
467
+ const fixed = "<column>\n <row gap=\"8\">\n <checkbox on-change=\"select\">press me</checkbox>\n </row>\n</column>";
468
+ var fixed_parser = markup.Parser.init(arena_state.allocator(), fixed);
469
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try fixed_parser.parse()));
470
+ }
471
+
472
+ test "the a11y lint: unnamed controls, icon-only controls, and unnamed text entry are errors" {
473
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
474
+ defer arena_state.deinit();
475
+ const arena = arena_state.allocator();
476
+
477
+ const cases = [_]struct { source: []const u8, message: []const u8 }{
478
+ // A control with no name anywhere is announced as an unnamed
479
+ // control - unusable blind.
480
+ .{ .source = "<row>\n <checkbox on-toggle=\"select\" />\n</row>", .message = markup.a11y_unlabeled_control_message },
481
+ .{ .source = "<row>\n <slider value=\"0.5\" on-change=\"scale\" />\n</row>", .message = markup.a11y_unlabeled_control_message },
482
+ // The icon name is a drawing instruction, not a label.
483
+ .{ .source = "<row>\n <button icon=\"trash\" on-press=\"remove\"></button>\n</row>", .message = markup.a11y_icon_only_message },
484
+ // Text entry needs a label or a placeholder; a bound VALUE is
485
+ // not a name (hearing the content does not say what to type).
486
+ .{ .source = "<row>\n <text-field on-input=\"draft\" />\n</row>", .message = markup.a11y_unlabeled_editable_message },
487
+ .{ .source = "<row>\n <input text=\"{query}\" on-input=\"draft\" />\n</row>", .message = markup.a11y_unlabeled_editable_message },
488
+ // A blank label is not a name on a control (unlike an image,
489
+ // where the empty label is the decorative opt-out).
490
+ .{ .source = "<row>\n <checkbox label=\" \" on-toggle=\"select\" />\n</row>", .message = markup.a11y_unlabeled_control_message },
491
+ };
492
+ for (cases) |case| {
493
+ var parser = markup.Parser.init(arena, case.source);
494
+ const info = markup.validate(try parser.parse()) orelse return error.TestUnexpectedResult;
495
+ try testing.expectEqualStrings(case.message, info.message);
496
+ }
497
+
498
+ // Every sanctioned name source validates clean: text content, the
499
+ // text attribute, a label (literal or binding), a placeholder, and
500
+ // select's face content.
501
+ const clean = [_][]const u8{
502
+ "<row>\n <checkbox on-toggle=\"select\">Done</checkbox>\n</row>",
503
+ "<row>\n <checkbox text=\"Done\" on-toggle=\"select\" />\n</row>",
504
+ "<row>\n <checkbox label=\"Done\" on-toggle=\"select\" />\n</row>",
505
+ "<row>\n <button icon=\"trash\" label=\"Delete\" on-press=\"remove\"></button>\n</row>",
506
+ "<row>\n <button icon=\"save\" on-press=\"save\">Save</button>\n</row>",
507
+ "<row>\n <checkbox label=\"{item.title}\" on-toggle=\"select\" />\n</row>",
508
+ "<row>\n <text-field placeholder=\"New task\" on-input=\"draft\" />\n</row>",
509
+ "<row>\n <textarea label=\"Body\" on-input=\"draft\" />\n</row>",
510
+ "<row>\n <select on-press=\"open\">Newest first</select>\n</row>",
511
+ "<row>\n <select text=\"{choice}\" on-press=\"open\"/>\n</row>",
512
+ };
513
+ for (clean) |source| {
514
+ var parser = markup.Parser.init(arena, source);
515
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try parser.parse()));
516
+ }
517
+ }
518
+
519
+ test "the a11y lint: unknown literal roles and container roles on childless elements are errors" {
520
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
521
+ defer arena_state.deinit();
522
+ const arena = arena_state.allocator();
523
+
524
+ const unknown = "<row>\n <button role=\"pushbutton\" on-press=\"add\">Add</button>\n</row>";
525
+ var unknown_parser = markup.Parser.init(arena, unknown);
526
+ const unknown_info = markup.validate(try unknown_parser.parse()) orelse return error.TestUnexpectedResult;
527
+ try testing.expectEqualStrings(markup.a11y_unknown_role_message, unknown_info.message);
528
+ // The diagnostic points at the role attribute.
529
+ try testing.expectEqual(@as(usize, 2), unknown_info.line);
530
+
531
+ // role="tree" promises rows a text leaf can never hold.
532
+ const misuse = "<row>\n <button role=\"tree\" on-press=\"add\">Add</button>\n</row>";
533
+ var misuse_parser = markup.Parser.init(arena, misuse);
534
+ const misuse_info = markup.validate(try misuse_parser.parse()) orelse return error.TestUnexpectedResult;
535
+ try testing.expectEqualStrings(markup.a11y_container_role_message, misuse_info.message);
536
+
537
+ // The same container roles are fine on containers, treeitem is fine
538
+ // on a pressable row, and a dynamic role resolves at runtime.
539
+ const clean = [_][]const u8{
540
+ "<column role=\"tree\">\n <row role=\"treeitem\" on-press=\"pick\"><text>Docs</text></row>\n</column>",
541
+ "<row>\n <button role=\"{item.role}\" on-press=\"add\">Add</button>\n</row>",
542
+ };
543
+ for (clean) |source| {
544
+ var parser = markup.Parser.init(arena, source);
545
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try parser.parse()));
546
+ }
547
+ }
548
+
549
+ test "the a11y lint: unnamed images and redundant labels are warnings, not errors" {
550
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
551
+ defer arena_state.deinit();
552
+ const arena = arena_state.allocator();
553
+ var storage: [markup.max_a11y_warnings]markup.MarkupErrorInfo = undefined;
554
+
555
+ // An unnamed avatar validates (degraded, not blocked) and warns.
556
+ const unnamed = "<row>\n <avatar image=\"{photo}\"></avatar>\n</row>";
557
+ var unnamed_parser = markup.Parser.init(arena, unnamed);
558
+ const unnamed_doc = try unnamed_parser.parse();
559
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(unnamed_doc));
560
+ const unnamed_warnings = markup.collectA11yWarnings(unnamed_doc, &storage);
561
+ try testing.expectEqual(@as(usize, 1), unnamed_warnings.len);
562
+ try testing.expectEqualStrings(markup.a11y_unlabeled_image_message, unnamed_warnings[0].message);
563
+ try testing.expectEqual(@as(usize, 2), unnamed_warnings[0].line);
564
+
565
+ // label="" is the explicit decorative opt-out; initials or a real
566
+ // label also clear it.
567
+ const clean = [_][]const u8{
568
+ "<row>\n <avatar image=\"{photo}\" label=\"\"></avatar>\n</row>",
569
+ "<row>\n <avatar image=\"{photo}\" label=\"Octocat\"></avatar>\n</row>",
570
+ "<row>\n <avatar>CT</avatar>\n</row>",
571
+ };
572
+ for (clean) |source| {
573
+ var parser = markup.Parser.init(arena, source);
574
+ const document = try parser.parse();
575
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(document));
576
+ try testing.expectEqual(@as(usize, 0), markup.collectA11yWarnings(document, &storage).len);
577
+ }
578
+
579
+ // A label duplicating the text it shadows warns at the label.
580
+ const redundant = "<row>\n <button label=\"Save\" on-press=\"save\">Save</button>\n</row>";
581
+ var redundant_parser = markup.Parser.init(arena, redundant);
582
+ const redundant_doc = try redundant_parser.parse();
583
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(redundant_doc));
584
+ const redundant_warnings = markup.collectA11yWarnings(redundant_doc, &storage);
585
+ try testing.expectEqual(@as(usize, 1), redundant_warnings.len);
586
+ try testing.expectEqualStrings(markup.a11y_redundant_label_message, redundant_warnings[0].message);
587
+
588
+ // A label that ADDS information (differs from the text) is the
589
+ // sanctioned shape and stays quiet.
590
+ const adds = "<row>\n <button label=\"Save the draft\" on-press=\"save\">Save</button>\n</row>";
591
+ var adds_parser = markup.Parser.init(arena, adds);
592
+ const adds_doc = try adds_parser.parse();
593
+ try testing.expectEqual(@as(usize, 0), markup.collectA11yWarnings(adds_doc, &storage).len);
594
+ }
595
+
596
+ test "collectA11yErrors reports every a11y error in one pass with validate's positions" {
597
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
598
+ defer arena_state.deinit();
599
+ const arena = arena_state.allocator();
600
+ var storage: [markup.max_a11y_warnings]markup.MarkupErrorInfo = undefined;
601
+
602
+ // validate stops at the first offender; the collector reports both.
603
+ const two_unlabeled = "<column>\n <button on-press=\"add\"></button>\n <button on-press=\"remove\"></button>\n</column>";
604
+ var parser = markup.Parser.init(arena, two_unlabeled);
605
+ const document = try parser.parse();
606
+ const first = markup.validate(document) orelse return error.TestUnexpectedResult;
607
+ try testing.expectEqualStrings(markup.a11y_unlabeled_control_message, first.message);
608
+ const findings = markup.collectA11yErrors(document, &storage);
609
+ try testing.expectEqual(@as(usize, 2), findings.len);
610
+ try testing.expectEqualStrings(markup.a11y_unlabeled_control_message, findings[0].message);
611
+ try testing.expectEqual(first.line, findings[0].line);
612
+ try testing.expectEqual(first.column, findings[0].column);
613
+ try testing.expectEqualStrings(markup.a11y_unlabeled_control_message, findings[1].message);
614
+ try testing.expect(findings[1].line > findings[0].line);
615
+
616
+ // Mixed classes collect together: an unnamed control and a role
617
+ // misuse (positioned at the role attribute, like validate).
618
+ const mixed = "<column>\n <slider value=\"0.5\" on-change=\"scale\" />\n <button role=\"tree\" on-press=\"add\">Add</button>\n</column>";
619
+ var mixed_parser = markup.Parser.init(arena, mixed);
620
+ const mixed_findings = markup.collectA11yErrors(try mixed_parser.parse(), &storage);
621
+ try testing.expectEqual(@as(usize, 2), mixed_findings.len);
622
+ try testing.expectEqualStrings(markup.a11y_unlabeled_control_message, mixed_findings[0].message);
623
+ try testing.expectEqualStrings(markup.a11y_container_role_message, mixed_findings[1].message);
624
+
625
+ // A clean document collects nothing.
626
+ var clean_parser = markup.Parser.init(arena, "<column>\n <button on-press=\"add\">Add</button>\n</column>");
627
+ try testing.expectEqual(@as(usize, 0), markup.collectA11yErrors(try clean_parser.parse(), &storage).len);
628
+ }
629
+
630
+ test "press and toggle handlers are legal on layout elements (press fall-through makes them pressable)" {
631
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
632
+ defer arena_state.deinit();
633
+
634
+ // A pressable row with plain text children is THE shape the press
635
+ // fall-through exists for: the handler makes the row a hit target and
636
+ // clicks on the text land on it — no empty-text overlay, no
637
+ // duplicated handlers.
638
+ const sources = [_][]const u8{
639
+ "<column>\n <row on-press=\"select\" gap=\"8\">\n <text>press me</text>\n </row>\n</column>",
640
+ "<column on-press=\"add\">\n <text>x</text>\n</column>",
641
+ "<column>\n <stack on-toggle=\"flip\">\n <text>x</text>\n </stack>\n</column>",
642
+ "<row>\n <icon name=\"search\" on-press=\"go\" />\n</row>",
643
+ "<row>\n <badge on-press=\"open\">3</badge>\n</row>",
644
+ };
645
+ for (sources) |source| {
646
+ var parser = markup.Parser.init(arena_state.allocator(), source);
647
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try parser.parse()));
648
+ }
649
+ }
650
+
651
+ test "gap on stacking containers is rejected with the teaching error" {
652
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
653
+ defer arena_state.deinit();
654
+ const arena = arena_state.allocator();
655
+
656
+ // Every stack-container element rejects gap at the attribute position.
657
+ for (markup.known_stack_container_element_names) |name| {
658
+ const source = try std.fmt.allocPrint(arena, "<column>\n <{s} gap=\"8\" />\n</column>", .{name});
659
+ var parser = markup.Parser.init(arena, source);
660
+ const info = markup.validate(try parser.parse()) orelse return error.TestUnexpectedResult;
661
+ try testing.expectEqualStrings(markup.stack_container_gap_message, info.message);
662
+ try testing.expectEqual(@as(usize, 2), info.line);
663
+ }
664
+
665
+ // Flow containers keep gap; a column inside a panel is the fix.
666
+ const valid_sources = [_][]const u8{
667
+ "<row gap=\"8\">\n <text>x</text>\n</row>",
668
+ "<panel>\n <column gap=\"8\">\n <text>a</text>\n <text>b</text>\n </column>\n</panel>",
669
+ };
670
+ for (valid_sources) |source| {
671
+ var parser = markup.Parser.init(arena, source);
672
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try parser.parse()));
673
+ }
674
+ }
675
+
676
+ test "the avatar image attribute validates as one binding, avatar-only" {
677
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
678
+ defer arena_state.deinit();
679
+ const arena = arena_state.allocator();
680
+
681
+ // One {binding} on avatar is the whole grammar.
682
+ var parser = markup.Parser.init(arena, "<row>\n <avatar image=\"{user_image}\">CT</avatar>\n</row>");
683
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try parser.parse()));
684
+
685
+ const cases = [_]struct { source: []const u8, message: []const u8 }{
686
+ // Runtime image ids are model data, never markup literals.
687
+ .{ .source = "<row>\n <avatar image=\"7\">CT</avatar>\n</row>", .message = markup.avatar_image_message },
688
+ .{ .source = "<row>\n <avatar image=\"{a == b}\">CT</avatar>\n</row>", .message = markup.avatar_image_message },
689
+ // Scoped to avatar: the other image elements stay Zig views.
690
+ .{ .source = "<row>\n <badge image=\"{user_image}\">3</badge>\n</row>", .message = markup.avatar_image_element_message },
691
+ .{ .source = "<column>\n <panel image=\"{user_image}\" />\n</column>", .message = markup.avatar_image_element_message },
692
+ };
693
+ for (cases) |case| {
694
+ var case_parser = markup.Parser.init(arena, case.source);
695
+ const info = markup.validate(try case_parser.parse()) orelse return error.TestUnexpectedResult;
696
+ try testing.expectEqualStrings(case.message, info.message);
697
+ try testing.expectEqual(@as(usize, 2), info.line);
698
+ }
699
+ }
700
+
701
+ test "wrap and issue-link-base validate as vocabulary with teaching errors" {
702
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
703
+ defer arena_state.deinit();
704
+ const arena = arena_state.allocator();
705
+
706
+ // Valid: wrap on a text leaf, issue-link-base as a literal prefix or
707
+ // one binding.
708
+ const valid_sources = [_][]const u8{
709
+ "<column>\n <text wrap=\"true\">long message</text>\n</column>",
710
+ "<column>\n <text wrap=\"false\">one-line row title</text>\n</column>",
711
+ "<column>\n <markdown source=\"{body}\" issue-link-base=\"ghissue://\" />\n</column>",
712
+ "<column>\n <markdown source=\"{body}\" issue-link-base=\"{issue_base}\" />\n</column>",
713
+ };
714
+ for (valid_sources) |source| {
715
+ var parser = markup.Parser.init(arena, source);
716
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try parser.parse()));
717
+ }
718
+
719
+ // issue-link-base rejects equality expressions with the teaching
720
+ // message; the closed markdown attr set names it.
721
+ const cases = [_]struct { source: []const u8, message: []const u8 }{
722
+ .{
723
+ .source = "<column>\n <markdown source=\"{body}\" issue-link-base=\"{a == b}\" />\n</column>",
724
+ .message = markup.markdown_issue_link_base_message,
725
+ },
726
+ .{
727
+ .source = "<column>\n <markdown source=\"{body}\" wrap=\"true\" />\n</column>",
728
+ .message = markup.markdown_attr_message,
729
+ },
730
+ // wrap on anything but a text leaf is silently inert (rows never
731
+ // flow-wrap their children) — rejected with the teaching message,
732
+ // same policy as gap on stacking containers.
733
+ .{
734
+ .source = "<column>\n <row wrap=\"true\">\n <text>a</text>\n </row>\n</column>",
735
+ .message = markup.wrap_element_message,
736
+ },
737
+ .{
738
+ .source = "<column>\n <badge wrap=\"true\">new</badge>\n</column>",
739
+ .message = markup.wrap_element_message,
740
+ },
741
+ .{
742
+ .source = "<column>\n <row wrap=\"false\">\n <text>a</text>\n </row>\n</column>",
743
+ .message = markup.wrap_element_message,
744
+ },
745
+ };
746
+ for (cases) |case| {
747
+ var parser = markup.Parser.init(arena, case.source);
748
+ const info = markup.validate(try parser.parse()) orelse return error.TestUnexpectedResult;
749
+ try testing.expectEqualStrings(case.message, info.message);
750
+ try testing.expect(info.line > 0);
751
+ }
752
+ }
753
+
754
+ test "overscroll validates as scroll-scoped with a closed value vocabulary" {
755
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
756
+ defer arena_state.deinit();
757
+ const arena = arena_state.allocator();
758
+
759
+ // Valid: every vocabulary value on scroll, and a binding (resolved
760
+ // by the engines at build).
761
+ const valid_sources = [_][]const u8{
762
+ "<column>\n <scroll overscroll=\"none\">\n <column><text>a</text></column>\n </scroll>\n</column>",
763
+ "<column>\n <scroll overscroll=\"rubber_band\">\n <column><text>a</text></column>\n </scroll>\n</column>",
764
+ "<column>\n <scroll overscroll=\"default\">\n <column><text>a</text></column>\n </scroll>\n</column>",
765
+ "<column>\n <scroll overscroll=\"{edge_mode}\">\n <column><text>a</text></column>\n </scroll>\n</column>",
766
+ };
767
+ for (valid_sources) |source| {
768
+ var parser = markup.Parser.init(arena, source);
769
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try parser.parse()));
770
+ }
771
+
772
+ const cases = [_]struct { source: []const u8, message: []const u8 }{
773
+ // Edge behavior exists only where the runtime scrolls; anywhere
774
+ // else the option is silently inert (same policy as columns off
775
+ // grid).
776
+ .{
777
+ .source = "<column>\n <row overscroll=\"rubber_band\">\n <text>a</text>\n </row>\n</column>",
778
+ .message = markup.overscroll_element_message,
779
+ },
780
+ .{
781
+ .source = "<column>\n <list overscroll=\"none\">\n <list-item>a</list-item>\n </list>\n</column>",
782
+ .message = markup.overscroll_element_message,
783
+ },
784
+ // Literal values outside the closed vocabulary teach the set.
785
+ .{
786
+ .source = "<column>\n <scroll overscroll=\"bouncy\">\n <column><text>a</text></column>\n </scroll>\n</column>",
787
+ .message = markup.overscroll_value_message,
788
+ },
789
+ };
790
+ for (cases) |case| {
791
+ var parser = markup.Parser.init(arena, case.source);
792
+ const info = markup.validate(try parser.parse()) orelse return error.TestUnexpectedResult;
793
+ try testing.expectEqualStrings(case.message, info.message);
794
+ try testing.expect(info.line > 0);
795
+ }
796
+ }
797
+
798
+ test "overflow validates as text-scoped with a closed value vocabulary" {
799
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
800
+ defer arena_state.deinit();
801
+ const arena = arena_state.allocator();
802
+
803
+ // Valid: every vocabulary value on text, and a binding (resolved by
804
+ // the engines at build).
805
+ const valid_sources = [_][]const u8{
806
+ "<column>\n <text overflow=\"ellipsis\">a long row title</text>\n</column>",
807
+ "<column>\n <text overflow=\"clip\">1:22</text>\n</column>",
808
+ "<column>\n <text wrap=\"false\" overflow=\"clip\">1:22</text>\n</column>",
809
+ "<column>\n <text overflow=\"{policy}\">a</text>\n</column>",
810
+ };
811
+ for (valid_sources) |source| {
812
+ var parser = markup.Parser.init(arena, source);
813
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try parser.parse()));
814
+ }
815
+
816
+ const cases = [_]struct { source: []const u8, message: []const u8 }{
817
+ // Overflow policy exists only where a single line can overflow:
818
+ // a plain text leaf (same policy as wrap).
819
+ .{
820
+ .source = "<column>\n <row overflow=\"clip\">\n <text>a</text>\n </row>\n</column>",
821
+ .message = markup.overflow_element_message,
822
+ },
823
+ .{
824
+ .source = "<column>\n <button overflow=\"ellipsis\">Save</button>\n</column>",
825
+ .message = markup.overflow_element_message,
826
+ },
827
+ // Literal values outside the closed vocabulary teach the set —
828
+ // including the deliberate absence of overflow-visible.
829
+ .{
830
+ .source = "<column>\n <text overflow=\"visible\">a</text>\n</column>",
831
+ .message = markup.overflow_value_message,
832
+ },
833
+ .{
834
+ .source = "<column>\n <text overflow=\"middle\">a</text>\n</column>",
835
+ .message = markup.overflow_value_message,
836
+ },
837
+ };
838
+ for (cases) |case| {
839
+ var parser = markup.Parser.init(arena, case.source);
840
+ const info = markup.validate(try parser.parse()) orelse return error.TestUnexpectedResult;
841
+ try testing.expectEqualStrings(case.message, info.message);
842
+ try testing.expect(info.line > 0);
843
+ }
844
+ }
845
+
846
+ test "resize-duration and resize-easing validate as split-scoped with a closed easing vocabulary" {
847
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
848
+ defer arena_state.deinit();
849
+ const arena = arena_state.allocator();
850
+
851
+ // Valid: a duration alone (with and without easing), every easing
852
+ // vocabulary value beside a nonzero duration, bindings for both
853
+ // (resolved by the engines at build), and an explicit 0 duration
854
+ // WITHOUT easing (a declared snap is legal; easing beside it is not).
855
+ const valid_sources = [_][]const u8{
856
+ "<column>\n <split value=\"{fraction}\" resize-duration=\"180\">\n <panel><text>a</text></panel>\n <panel><text>b</text></panel>\n </split>\n</column>",
857
+ "<column>\n <split value=\"{fraction}\" resize-duration=\"180\" resize-easing=\"linear\">\n <panel><text>a</text></panel>\n <panel><text>b</text></panel>\n </split>\n</column>",
858
+ "<column>\n <split value=\"{fraction}\" resize-duration=\"180\" resize-easing=\"standard\">\n <panel><text>a</text></panel>\n <panel><text>b</text></panel>\n </split>\n</column>",
859
+ "<column>\n <split value=\"{fraction}\" resize-duration=\"180\" resize-easing=\"emphasized\">\n <panel><text>a</text></panel>\n <panel><text>b</text></panel>\n </split>\n</column>",
860
+ "<column>\n <split value=\"{fraction}\" resize-duration=\"180\" resize-easing=\"spring\">\n <panel><text>a</text></panel>\n <panel><text>b</text></panel>\n </split>\n</column>",
861
+ "<column>\n <split value=\"{fraction}\" resize-duration=\"{speed}\" resize-easing=\"{curve}\">\n <panel><text>a</text></panel>\n <panel><text>b</text></panel>\n </split>\n</column>",
862
+ "<column>\n <split value=\"{fraction}\" resize-duration=\"0\">\n <panel><text>a</text></panel>\n <panel><text>b</text></panel>\n </split>\n</column>",
863
+ };
864
+ for (valid_sources) |source| {
865
+ var parser = markup.Parser.init(arena, source);
866
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try parser.parse()));
867
+ }
868
+
869
+ const cases = [_]struct { source: []const u8, message: []const u8 }{
870
+ // The layout tween exists only where a fraction can move: a
871
+ // split. Anywhere else the pair is silently inert (same policy
872
+ // as overscroll off scroll).
873
+ .{
874
+ .source = "<column>\n <row resize-duration=\"180\">\n <text>a</text>\n </row>\n</column>",
875
+ .message = markup.resize_duration_element_message,
876
+ },
877
+ .{
878
+ .source = "<column>\n <scroll resize-easing=\"standard\">\n <column><text>a</text></column>\n </scroll>\n</column>",
879
+ .message = markup.resize_easing_element_message,
880
+ },
881
+ // Easing shapes a ramp only a nonzero duration declares: alone,
882
+ // or beside a literal 0, it is silently inert data (same policy
883
+ // as anchor-alignment without anchor).
884
+ .{
885
+ .source = "<column>\n <split value=\"{fraction}\" resize-easing=\"standard\">\n <panel><text>a</text></panel>\n <panel><text>b</text></panel>\n </split>\n</column>",
886
+ .message = markup.resize_easing_dependent_attr_message,
887
+ },
888
+ .{
889
+ .source = "<column>\n <split value=\"{fraction}\" resize-duration=\"0\" resize-easing=\"standard\">\n <panel><text>a</text></panel>\n <panel><text>b</text></panel>\n </split>\n</column>",
890
+ .message = markup.resize_easing_dependent_attr_message,
891
+ },
892
+ // Literal easing values outside the closed vocabulary teach the
893
+ // set (the names mirror canvas.Easing member for member).
894
+ .{
895
+ .source = "<column>\n <split value=\"{fraction}\" resize-duration=\"180\" resize-easing=\"bouncy\">\n <panel><text>a</text></panel>\n <panel><text>b</text></panel>\n </split>\n</column>",
896
+ .message = markup.resize_easing_value_message,
897
+ },
898
+ };
899
+ for (cases) |case| {
900
+ var parser = markup.Parser.init(arena, case.source);
901
+ const info = markup.validate(try parser.parse()) orelse return error.TestUnexpectedResult;
902
+ try testing.expectEqualStrings(case.message, info.message);
903
+ try testing.expect(info.line > 0);
904
+ }
905
+ }
906
+
907
+ test "size validates as the two-axis closed vocabulary with teaching errors" {
908
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
909
+ defer arena_state.deinit();
910
+ const arena = arena_state.allocator();
911
+
912
+ // Valid: the control scale on controls, the typography rungs on
913
+ // text, and bindings (resolved by the engines at build).
914
+ const valid_sources = [_][]const u8{
915
+ "<column>\n <button size=\"sm\" on-press=\"go\">Go</button>\n</column>",
916
+ "<column>\n <text size=\"heading\">Section</text>\n</column>",
917
+ "<column>\n <text size=\"display\">42.7</text>\n</column>",
918
+ "<column>\n <text size=\"display\" wrap=\"true\">A hero line that may wrap</text>\n</column>",
919
+ "<column>\n <text size=\"{stat_size}\">42</text>\n</column>",
920
+ };
921
+ for (valid_sources) |source| {
922
+ var parser = markup.Parser.init(arena, source);
923
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try parser.parse()));
924
+ }
925
+
926
+ const cases = [_]struct { source: []const u8, message: []const u8 }{
927
+ // The typography rungs are text-only: on a control the size
928
+ // register is the control scale, a different axis.
929
+ .{
930
+ .source = "<column>\n <button size=\"display\" on-press=\"go\">Go</button>\n</column>",
931
+ .message = markup.text_size_element_message,
932
+ },
933
+ .{
934
+ .source = "<column>\n <badge size=\"heading\">3</badge>\n</column>",
935
+ .message = markup.text_size_element_message,
936
+ },
937
+ // Unknown values teach the whole vocabulary; numeric sizes are
938
+ // refused by design (type sizes are themable token steps).
939
+ .{
940
+ .source = "<column>\n <text size=\"title\">Section</text>\n</column>",
941
+ .message = markup.size_value_message,
942
+ },
943
+ .{
944
+ .source = "<column>\n <text size=\"48\">42.7</text>\n</column>",
945
+ .message = markup.size_value_message,
946
+ },
947
+ .{
948
+ .source = "<column>\n <button size=\"tiny\" on-press=\"go\">Go</button>\n</column>",
949
+ .message = markup.size_value_message,
950
+ },
951
+ };
952
+ for (cases) |case| {
953
+ var parser = markup.Parser.init(arena, case.source);
954
+ const info = markup.validate(try parser.parse()) orelse return error.TestUnexpectedResult;
955
+ try testing.expectEqualStrings(case.message, info.message);
956
+ try testing.expectEqual(@as(usize, 2), info.line);
957
+ }
958
+ }
959
+
960
+ test "stepper and timeline validate structure with teaching messages" {
961
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
962
+ defer arena_state.deinit();
963
+ const arena = arena_state.allocator();
964
+
965
+ const valid_sources = [_][]const u8{
966
+ "<column>\n <stepper active=\"{stage}\">\n <step>Work</step>\n <step>Ready</step>\n </stepper>\n</column>",
967
+ "<column>\n <timeline gap=\"4\">\n <timeline-item title=\"Done\" description=\"ok\" meta=\"1m\" variant=\"primary\" on-press=\"pick:{id}\" />\n <if test=\"{ready}\">\n <timeline-item title=\"Ready\" connector=\"false\" />\n </if>\n </timeline>\n</column>",
968
+ };
969
+ for (valid_sources) |source| {
970
+ var parser = markup.Parser.init(arena, source);
971
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try parser.parse()));
972
+ }
973
+
974
+ const cases = [_]struct { source: []const u8, message: []const u8 }{
975
+ .{ .source = "<column>\n <stepper>\n <step>Work</step>\n </stepper>\n</column>", .message = markup.stepper_active_message },
976
+ .{ .source = "<column>\n <stepper active=\"1\" gap=\"4\" />\n</column>", .message = markup.stepper_attr_message },
977
+ .{ .source = "<column>\n <stepper active=\"1\">\n <text>Work</text>\n </stepper>\n</column>", .message = markup.stepper_children_message },
978
+ .{ .source = "<column>\n <stepper active=\"1\">\n <step variant=\"primary\">Work</step>\n </stepper>\n</column>", .message = markup.step_attr_message },
979
+ .{ .source = "<column>\n <step>Work</step>\n</column>", .message = markup.step_parent_message },
980
+ .{ .source = "<column>\n <timeline padding=\"8\" />\n</column>", .message = markup.timeline_attr_message },
981
+ .{ .source = "<column>\n <timeline-item title=\"Done\" />\n</column>", .message = markup.timeline_item_parent_message },
982
+ .{ .source = "<column>\n <timeline>\n <timeline-item description=\"x\" />\n </timeline>\n</column>", .message = markup.timeline_item_title_message },
983
+ .{ .source = "<column>\n <timeline>\n <timeline-item title=\"Done\" width=\"20\" />\n </timeline>\n</column>", .message = markup.timeline_item_attr_message },
984
+ .{ .source = "<column>\n <timeline>\n <timeline-item title=\"Done\" on-toggle=\"pick\" />\n </timeline>\n</column>", .message = markup.timeline_item_press_only_message },
985
+ .{ .source = "<column>\n <timeline>\n <timeline-item title=\"Done\">\n <text>x</text>\n </timeline-item>\n </timeline>\n</column>", .message = markup.timeline_item_children_message },
986
+ };
987
+ for (cases) |case| {
988
+ var parser = markup.Parser.init(arena, case.source);
989
+ const info = markup.validate(try parser.parse()) orelse return error.TestUnexpectedResult;
990
+ try testing.expectEqualStrings(case.message, info.message);
991
+ try testing.expect(info.line > 0);
992
+ }
993
+ }
994
+
995
+ test "chart and series validate structure with teaching messages" {
996
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
997
+ defer arena_state.deinit();
998
+ const arena = arena_state.allocator();
999
+
1000
+ const valid_sources = [_][]const u8{
1001
+ "<column>\n <chart y-min=\"0\" y-max=\"1\" grid-lines=\"4\" baseline=\"true\" width=\"239\" height=\"32\" label=\"CPU history\">\n <series kind=\"bar\" values=\"{cpu_history}\" color=\"accent\" label=\"cpu\" />\n <series kind=\"area\" values=\"{latency}\" />\n </chart>\n</column>",
1002
+ "<column>\n <chart grow=\"1\" stroke-width=\"2\">\n <series values=\"{levels}\" />\n </chart>\n</column>",
1003
+ // Axis labels and hover details: x-labels bind a string
1004
+ // iterable, the flags are ordinary truthy attributes.
1005
+ "<column>\n <chart x-labels=\"{months}\" y-labels=\"true\" hover-details=\"true\">\n <series values=\"{levels}\" />\n </chart>\n</column>",
1006
+ };
1007
+ for (valid_sources) |source| {
1008
+ var parser = markup.Parser.init(arena, source);
1009
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try parser.parse()));
1010
+ }
1011
+
1012
+ const cases = [_]struct { source: []const u8, message: []const u8 }{
1013
+ .{ .source = "<column>\n <chart gap=\"4\">\n <series values=\"{levels}\" />\n </chart>\n</column>", .message = markup.chart_attr_message },
1014
+ // The label data channel is a binding, never a literal.
1015
+ .{ .source = "<column>\n <chart x-labels=\"jan\">\n <series values=\"{levels}\" />\n </chart>\n</column>", .message = markup.chart_x_labels_message },
1016
+ .{ .source = "<column>\n <chart on-press=\"pick\">\n <series values=\"{levels}\" />\n </chart>\n</column>", .message = markup.chart_display_only_message },
1017
+ .{ .source = "<column>\n <chart />\n</column>", .message = markup.chart_series_required_message },
1018
+ .{ .source = "<column>\n <chart>\n <text>x</text>\n </chart>\n</column>", .message = markup.chart_children_message },
1019
+ // The series set is static: dynamic composition stays with the
1020
+ // Zig builder, so structure tags inside a chart teach that.
1021
+ .{ .source = "<column>\n <chart>\n <for each=\"rows\" as=\"row\">\n <series values=\"{row.levels}\" />\n </for>\n </chart>\n</column>", .message = markup.chart_children_message },
1022
+ .{ .source = "<column>\n <series values=\"{levels}\" />\n</column>", .message = markup.series_parent_message },
1023
+ .{ .source = "<column>\n <chart>\n <series />\n </chart>\n</column>", .message = markup.series_values_message },
1024
+ .{ .source = "<column>\n <chart>\n <series values=\"7\" />\n </chart>\n</column>", .message = markup.series_values_message },
1025
+ // Band envelopes need a paired lower edge; the teaching error
1026
+ // names the Zig builder as the home.
1027
+ .{ .source = "<column>\n <chart>\n <series kind=\"band\" values=\"{levels}\" />\n </chart>\n</column>", .message = markup.series_kind_message },
1028
+ .{ .source = "<column>\n <chart>\n <series kind=\"{kind}\" values=\"{levels}\" />\n </chart>\n</column>", .message = markup.series_kind_message },
1029
+ .{ .source = "<column>\n <chart>\n <series values=\"{levels}\" color=\"magenta\" />\n </chart>\n</column>", .message = markup.series_color_message },
1030
+ .{ .source = "<column>\n <chart>\n <series values=\"{levels}\" fill=\"true\" />\n </chart>\n</column>", .message = markup.series_attr_message },
1031
+ .{ .source = "<column>\n <chart>\n <series values=\"{levels}\">\n <text>x</text>\n </series>\n </chart>\n</column>", .message = markup.series_children_message },
1032
+ };
1033
+ for (cases) |case| {
1034
+ var parser = markup.Parser.init(arena, case.source);
1035
+ const info = markup.validate(try parser.parse()) orelse return error.TestUnexpectedResult;
1036
+ try testing.expectEqualStrings(case.message, info.message);
1037
+ try testing.expect(info.line > 0);
1038
+ }
1039
+ }
1040
+
1041
+ // ----------------------------------------------------------- imports
1042
+
1043
+ fn resolveSet(arena: std.mem.Allocator, set: []const markup.SourceFile, root_name: []const u8, diagnostic: *markup.MarkupErrorInfo) markup.ResolveError!markup.MarkupDocument {
1044
+ var loader = markup.SourceSetLoader{ .set = set };
1045
+ const root_source = for (set) |file| {
1046
+ if (std.mem.eql(u8, file.path, root_name)) break file.source;
1047
+ } else return error.MarkupImport;
1048
+ return markup.resolveImports(arena, root_name, root_source, loader.loader(), diagnostic);
1049
+ }
1050
+
1051
+ test "import resolution merges imported templates before the importer's own" {
1052
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1053
+ defer arena_state.deinit();
1054
+ const arena = arena_state.allocator();
1055
+
1056
+ // view.native imports components/pills.native, which imports base.native from
1057
+ // its own directory (transitive, subdirectory, relative-to-importer).
1058
+ const set = [_]markup.SourceFile{
1059
+ .{ .path = "view.native", .source = "<import src=\"components/pills.native\"/>\n<template name=\"local\"><text>l</text></template>\n<row>\n <use template=\"pill-stack\" title=\"T\" />\n</row>" },
1060
+ .{ .path = "components/pills.native", .source = "<import src=\"base.native\"/>\n<template name=\"pill-stack\" args=\"title\"><column><use template=\"pill\" label=\"{title}\" /></column></template>" },
1061
+ .{ .path = "components/base.native", .source = "<template name=\"pill\" args=\"label\"><badge>{label}</badge></template>" },
1062
+ };
1063
+ var diagnostic: markup.MarkupErrorInfo = .{};
1064
+ const document = try resolveSet(arena, &set, "view.native", &diagnostic);
1065
+
1066
+ // Depth-first splice order: transitive imports first, then the
1067
+ // importer's templates, then the root's own.
1068
+ try testing.expectEqual(@as(usize, 3), document.templates.len);
1069
+ try testing.expectEqualStrings("pill", document.templates[0].attr("name").?);
1070
+ try testing.expectEqualStrings("pill-stack", document.templates[1].attr("name").?);
1071
+ try testing.expectEqualStrings("local", document.templates[2].attr("name").?);
1072
+ try testing.expectEqual(@as(usize, 0), document.imports.len);
1073
+
1074
+ // Every node is stamped with its source file for diagnostics.
1075
+ try testing.expectEqualStrings("components/base.native", document.templates[0].src_path);
1076
+ try testing.expectEqualStrings("components/pills.native", document.templates[1].src_path);
1077
+ try testing.expectEqualStrings("view.native", document.templates[2].src_path);
1078
+ try testing.expectEqualStrings("view.native", document.root.?.src_path);
1079
+ try testing.expectEqualStrings("components/base.native", document.templates[0].children[0].src_path);
1080
+
1081
+ // The merged document passes the strict (resolved) validation pass.
1082
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(document));
1083
+ }
1084
+
1085
+ test "import cycles are reported with the cycle path spelled out" {
1086
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1087
+ defer arena_state.deinit();
1088
+ const arena = arena_state.allocator();
1089
+
1090
+ const set = [_]markup.SourceFile{
1091
+ .{ .path = "a.native", .source = "<import src=\"b.native\"/>\n<row />" },
1092
+ .{ .path = "b.native", .source = "<import src=\"a.native\"/>\n<template name=\"t\"><text>x</text></template>" },
1093
+ };
1094
+ var diagnostic: markup.MarkupErrorInfo = .{};
1095
+ try testing.expectError(error.MarkupImport, resolveSet(arena, &set, "a.native", &diagnostic));
1096
+ try testing.expectEqualStrings("import cycle: a.native -> b.native -> a.native", diagnostic.message);
1097
+ try testing.expectEqualStrings("b.native", diagnostic.path);
1098
+
1099
+ // Self-import is the shortest cycle.
1100
+ const self_set = [_]markup.SourceFile{
1101
+ .{ .path = "a.native", .source = "<import src=\"a.native\"/>\n<row />" },
1102
+ };
1103
+ try testing.expectError(error.MarkupImport, resolveSet(arena, &self_set, "a.native", &diagnostic));
1104
+ try testing.expectEqualStrings("import cycle: a.native -> a.native", diagnostic.message);
1105
+ }
1106
+
1107
+ test "duplicate template names across files name both definition sites" {
1108
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1109
+ defer arena_state.deinit();
1110
+ const arena = arena_state.allocator();
1111
+
1112
+ const set = [_]markup.SourceFile{
1113
+ .{ .path = "view.native", .source = "<import src=\"one.native\"/>\n<import src=\"two.native\"/>\n<row />" },
1114
+ .{ .path = "one.native", .source = "<template name=\"card\"><text>1</text></template>" },
1115
+ .{ .path = "two.native", .source = "<template name=\"card\"><text>2</text></template>" },
1116
+ };
1117
+ var diagnostic: markup.MarkupErrorInfo = .{};
1118
+ try testing.expectError(error.MarkupImport, resolveSet(arena, &set, "view.native", &diagnostic));
1119
+ try testing.expect(std.mem.indexOf(u8, diagnostic.message, "duplicate template name \"card\"") != null);
1120
+ try testing.expect(std.mem.indexOf(u8, diagnostic.message, "one.native:1:1") != null);
1121
+ try testing.expectEqualStrings("two.native", diagnostic.path);
1122
+
1123
+ // Import vs local: the local definition collides with the imported one.
1124
+ const local_set = [_]markup.SourceFile{
1125
+ .{ .path = "view.native", .source = "<import src=\"one.native\"/>\n<template name=\"card\"><text>l</text></template>\n<row />" },
1126
+ .{ .path = "one.native", .source = "<template name=\"card\"><text>1</text></template>" },
1127
+ };
1128
+ try testing.expectError(error.MarkupImport, resolveSet(arena, &local_set, "view.native", &diagnostic));
1129
+ try testing.expect(std.mem.indexOf(u8, diagnostic.message, "duplicate template name \"card\"") != null);
1130
+ try testing.expectEqualStrings("view.native", diagnostic.path);
1131
+ }
1132
+
1133
+ test "import path escapes, absolute paths, and bad extensions are teaching errors" {
1134
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1135
+ defer arena_state.deinit();
1136
+ const arena = arena_state.allocator();
1137
+
1138
+ const cases = [_]struct { src: []const u8, message: []const u8 }{
1139
+ .{ .src = "../secrets.native", .message = markup.import_src_escape_message },
1140
+ .{ .src = "/etc/passwd.native", .message = markup.import_src_absolute_message },
1141
+ .{ .src = "c:\\parts.native", .message = markup.import_src_absolute_message },
1142
+ .{ .src = "parts.txt", .message = markup.import_src_extension_message },
1143
+ .{ .src = "", .message = markup.import_src_message },
1144
+ };
1145
+ for (cases) |case| {
1146
+ const source = try std.fmt.allocPrint(arena, "<import src=\"{s}\"/>\n<row />", .{case.src});
1147
+ const set = [_]markup.SourceFile{.{ .path = "src/view.native", .source = source }};
1148
+ var diagnostic: markup.MarkupErrorInfo = .{};
1149
+ try testing.expectError(error.MarkupImport, resolveSet(arena, &set, "src/view.native", &diagnostic));
1150
+ try testing.expectEqualStrings(case.message, diagnostic.message);
1151
+ try testing.expectEqual(@as(usize, 1), diagnostic.line);
1152
+ }
1153
+
1154
+ // Within-root ".." stays legal: components can reach a sibling folder
1155
+ // under the markup root.
1156
+ var buffer: [markup.max_import_path_len]u8 = undefined;
1157
+ const resolved = markup.resolveImportPath("src", "src/components/pills.native", "../shared/base.native", &buffer);
1158
+ try testing.expectEqualStrings("src/shared/base.native", resolved.path);
1159
+ const escaped = markup.resolveImportPath("src", "src/view.native", "../../other.native", &buffer);
1160
+ try testing.expectEqualStrings(markup.import_src_escape_message, escaped.message);
1161
+ }
1162
+
1163
+ test "an absolute root path resolves imports the same as a relative one" {
1164
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1165
+ defer arena_state.deinit();
1166
+ const arena = arena_state.allocator();
1167
+
1168
+ // Checking a view by absolute path (as `native markup check /abs/view.native`
1169
+ // does) must behave exactly like the relative form: joined import paths
1170
+ // keep the leading "/", so they stay under the absolute markup root and
1171
+ // load from the right place. Regression: the join used to drop the "/",
1172
+ // making every import of an absolutely-addressed view "escape" the root.
1173
+ var buffer: [markup.max_import_path_len]u8 = undefined;
1174
+ const resolved = markup.resolveImportPath("/app/src", "/app/src/view.native", "components/card.native", &buffer);
1175
+ try testing.expectEqualStrings("/app/src/components/card.native", resolved.path);
1176
+
1177
+ // The full resolver, rooted at an absolute path, resolves the closure.
1178
+ const set = [_]markup.SourceFile{
1179
+ .{ .path = "/app/src/view.native", .source = "<import src=\"components/card.native\"/>\n<column><card/></column>" },
1180
+ .{ .path = "/app/src/components/card.native", .source = "<template name=\"card\"><text>hi</text></template>" },
1181
+ };
1182
+ var diagnostic: markup.MarkupErrorInfo = .{};
1183
+ const document = try resolveSet(arena, &set, "/app/src/view.native", &diagnostic);
1184
+ try testing.expectEqual(@as(usize, 1), document.templates.len);
1185
+
1186
+ // An import that genuinely climbs out of the absolute root still fails.
1187
+ const escaped = markup.resolveImportPath("/app/src", "/app/src/view.native", "../other.native", &buffer);
1188
+ try testing.expectEqualStrings(markup.import_src_escape_message, escaped.message);
1189
+ }
1190
+
1191
+ test ".native is the one markup extension" {
1192
+ try testing.expect(markup.hasMarkupExtension("view.native"));
1193
+ try testing.expect(!markup.hasMarkupExtension("view.html"));
1194
+ try testing.expect(!markup.hasMarkupExtension("view.xml"));
1195
+ try testing.expect(!markup.hasMarkupExtension("view.native.txt"));
1196
+ }
1197
+
1198
+ test "an imported file with a view root is rejected with the teaching error" {
1199
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1200
+ defer arena_state.deinit();
1201
+ const arena = arena_state.allocator();
1202
+
1203
+ const set = [_]markup.SourceFile{
1204
+ .{ .path = "view.native", .source = "<import src=\"other.native\"/>\n<row />" },
1205
+ .{ .path = "other.native", .source = "<template name=\"t\"><text>x</text></template>\n<column />" },
1206
+ };
1207
+ var diagnostic: markup.MarkupErrorInfo = .{};
1208
+ try testing.expectError(error.MarkupImport, resolveSet(arena, &set, "view.native", &diagnostic));
1209
+ try testing.expectEqualStrings(markup.import_view_root_message, diagnostic.message);
1210
+ try testing.expectEqualStrings("other.native", diagnostic.path);
1211
+ }
1212
+
1213
+ test "a missing imported file reports at the importing file's position" {
1214
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1215
+ defer arena_state.deinit();
1216
+ const arena = arena_state.allocator();
1217
+
1218
+ const set = [_]markup.SourceFile{
1219
+ .{ .path = "view.native", .source = "<row />\n" },
1220
+ .{ .path = "importer.native", .source = "<import src=\"nope.native\"/>\n<row />" },
1221
+ };
1222
+ var diagnostic: markup.MarkupErrorInfo = .{};
1223
+ try testing.expectError(error.MarkupImport, resolveSet(arena, &set, "importer.native", &diagnostic));
1224
+ try testing.expect(std.mem.indexOf(u8, diagnostic.message, "unable to read imported file \"nope.native\"") != null);
1225
+ try testing.expectEqualStrings("importer.native", diagnostic.path);
1226
+ try testing.expectEqual(@as(usize, 1), diagnostic.line);
1227
+ }
1228
+
1229
+ test "hostile import chains and template counts get bounded errors" {
1230
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1231
+ defer arena_state.deinit();
1232
+ const arena = arena_state.allocator();
1233
+
1234
+ // A chain one past max_import_depth errors instead of recursing on.
1235
+ var files: std.ArrayListUnmanaged(markup.SourceFile) = .empty;
1236
+ for (0..markup.max_import_depth + 1) |index| {
1237
+ const path = try std.fmt.allocPrint(arena, "c{d}.native", .{index});
1238
+ const source = if (index == markup.max_import_depth)
1239
+ try std.fmt.allocPrint(arena, "<template name=\"leaf\"><text>x</text></template>", .{})
1240
+ else
1241
+ try std.fmt.allocPrint(arena, "<import src=\"c{d}.native\"/>\n<template name=\"t{d}\"><text>x</text></template>", .{ index + 1, index });
1242
+ try files.append(arena, .{ .path = path, .source = source });
1243
+ }
1244
+ var diagnostic: markup.MarkupErrorInfo = .{};
1245
+ try testing.expectError(error.MarkupImport, resolveSet(arena, files.items, "c0.native", &diagnostic));
1246
+ try testing.expectEqualStrings(markup.import_depth_message, diagnostic.message);
1247
+
1248
+ // A single file with too many templates fails the parse cap.
1249
+ var huge: std.ArrayListUnmanaged(u8) = .empty;
1250
+ for (0..markup.max_document_templates + 1) |index| {
1251
+ try huge.appendSlice(arena, try std.fmt.allocPrint(arena, "<template name=\"t{d}\"><text>x</text></template>\n", .{index}));
1252
+ }
1253
+ try huge.appendSlice(arena, "<row />");
1254
+ var parser = markup.Parser.init(arena, huge.items);
1255
+ try testing.expectError(error.MarkupSyntax, parser.parse());
1256
+ try testing.expectEqualStrings(markup.max_templates_message, parser.diagnostic.message);
1257
+ }
1258
+
1259
+ test "imports parse at the top only and validate their shape" {
1260
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1261
+ defer arena_state.deinit();
1262
+ const arena = arena_state.allocator();
1263
+
1264
+ // An import after a template is a parse error (position is structure).
1265
+ var parser = markup.Parser.init(arena, "<template name=\"t\"><text>x</text></template>\n<import src=\"a.native\"/>\n<row />");
1266
+ try testing.expectError(error.MarkupSyntax, parser.parse());
1267
+ try testing.expectEqualStrings(markup.import_top_level_message, parser.diagnostic.message);
1268
+
1269
+ const shape_cases = [_]struct { source: []const u8, message: []const u8 }{
1270
+ .{ .source = "<import/>\n<row />", .message = markup.import_src_message },
1271
+ .{ .source = "<import src=\"a.native\" extra=\"1\"/>\n<row />", .message = markup.import_attrs_message },
1272
+ .{ .source = "<import src=\"a.native\"><text>x</text></import>\n<row />", .message = markup.import_children_message },
1273
+ .{ .source = "<column>\n <import src=\"a.native\"/>\n</column>", .message = markup.import_top_level_message },
1274
+ };
1275
+ for (shape_cases) |case| {
1276
+ var case_parser = markup.Parser.init(arena, case.source);
1277
+ const info = markup.validate(try case_parser.parse()) orelse return error.TestUnexpectedResult;
1278
+ try testing.expectEqualStrings(case.message, info.message);
1279
+ }
1280
+
1281
+ // A view with unresolved imports skips use-reference checks (the
1282
+ // template may come from the import); everything else still validates.
1283
+ var lenient_parser = markup.Parser.init(arena, "<import src=\"a.native\"/>\n<row>\n <use template=\"from-import\" whatever=\"1\" />\n</row>");
1284
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try lenient_parser.parse()));
1285
+ }
1286
+
1287
+ // -------------------------------------------------- defaults and slots
1288
+
1289
+ test "template arg defaults parse and validate as literals only" {
1290
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1291
+ defer arena_state.deinit();
1292
+ const arena = arena_state.allocator();
1293
+
1294
+ const arg = markup.parseTemplateArg("trend=flat");
1295
+ try testing.expectEqualStrings("trend", arg.name);
1296
+ try testing.expectEqualStrings("flat", arg.default.?);
1297
+ try testing.expectEqual(@as(?[]const u8, null), markup.parseTemplateArg("trend").default);
1298
+ try testing.expectEqualStrings("", markup.parseTemplateArg("trend=").default.?);
1299
+
1300
+ // Omitting a defaulted arg is fine; omitting a required one is not.
1301
+ var ok_parser = markup.Parser.init(arena, "<template name=\"t\" args=\"title trend=flat\"><text>{title} {trend}</text></template>\n<row>\n <use template=\"t\" title=\"T\" />\n</row>");
1302
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try ok_parser.parse()));
1303
+
1304
+ const cases = [_]struct { source: []const u8, message: []const u8 }{
1305
+ .{ .source = "<template name=\"t\" args=\"title trend=flat\"><text>{title}</text></template>\n<row>\n <use template=\"t\" trend=\"up\" />\n</row>", .message = markup.use_missing_arg_message },
1306
+ .{ .source = "<template name=\"t\" args=\"trend={title}\"><text>{trend}</text></template>\n<row />", .message = markup.template_default_literal_message },
1307
+ // Quote characters in a default are literal text, not string
1308
+ // delimiters - rejected with the bare-form teaching instead of
1309
+ // silently rendering the quotes.
1310
+ .{ .source = "<template name=\"t\" args=\"trend='flat'\"><text>{trend}</text></template>\n<row />", .message = markup.template_default_quoted_message },
1311
+ };
1312
+ for (cases) |case| {
1313
+ var parser = markup.Parser.init(arena, case.source);
1314
+ const info = markup.validate(try parser.parse()) orelse return error.TestUnexpectedResult;
1315
+ try testing.expectEqualStrings(case.message, info.message);
1316
+ }
1317
+ }
1318
+
1319
+ test "slot placement rules validate with teaching messages" {
1320
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1321
+ defer arena_state.deinit();
1322
+ const arena = arena_state.allocator();
1323
+
1324
+ // A template with one slot accepts use-site children (built in the
1325
+ // consumer's scope); a slotless template rejects them.
1326
+ var ok_parser = markup.Parser.init(arena, "<template name=\"t\" args=\"title\"><column><text>{title}</text><slot/></column></template>\n<row>\n <use template=\"t\" title=\"T\"><text>body</text></use>\n</row>");
1327
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try ok_parser.parse()));
1328
+
1329
+ const cases = [_]struct { source: []const u8, message: []const u8 }{
1330
+ .{ .source = "<template name=\"t\"><column><slot/><slot/></column></template>\n<row />", .message = markup.template_one_slot_message },
1331
+ .{ .source = "<row>\n <slot/>\n</row>", .message = markup.slot_outside_template_message },
1332
+ .{ .source = "<template name=\"t\"><column><slot gap=\"2\"/></column></template>\n<row />", .message = markup.slot_attrs_message },
1333
+ .{ .source = "<template name=\"t\"><column><slot><text>x</text></slot></column></template>\n<row />", .message = markup.slot_children_message },
1334
+ .{ .source = "<template name=\"a\"><column><slot/></column></template>\n<template name=\"b\"><column><use template=\"a\"><slot/></use></column></template>\n<row />", .message = markup.slot_in_use_children_message },
1335
+ };
1336
+ for (cases) |case| {
1337
+ var parser = markup.Parser.init(arena, case.source);
1338
+ const info = markup.validate(try parser.parse()) orelse return error.TestUnexpectedResult;
1339
+ try testing.expectEqualStrings(case.message, info.message);
1340
+ }
1341
+ }
1342
+
1343
+ // ------------------------------------------------------------------ spans
1344
+
1345
+ fn expectSpansCover(source: []const u8, node: markup.MarkupNode) !void {
1346
+ switch (node.kind) {
1347
+ .text => {
1348
+ if (std.mem.eql(u8, node.text, " ") and !std.mem.eql(u8, source[node.span.start..node.span.end], " ")) {
1349
+ // The parser-spliced inline separator (span paragraphs):
1350
+ // its text is the canonical single space while its span
1351
+ // covers the whitespace gap it collapsed, so write-back
1352
+ // still owns the exact source bytes.
1353
+ try testing.expect(node.span.end > node.span.start);
1354
+ } else {
1355
+ // A text run's span is exactly its trimmed visible bytes.
1356
+ try testing.expectEqualStrings(node.text, source[node.span.start..node.span.end]);
1357
+ }
1358
+ },
1359
+ else => {
1360
+ // An element/structure node spans `<` through its closing `>`.
1361
+ try testing.expectEqual(@as(u8, '<'), source[node.span.start]);
1362
+ try testing.expectEqual(@as(u8, '>'), source[node.span.end - 1]);
1363
+ },
1364
+ }
1365
+ // The classic line/column IS the span start, in display form.
1366
+ const node_position = markup.positionAt(source, node.span.start);
1367
+ try testing.expectEqual(node.line, node_position.line);
1368
+ try testing.expectEqual(node.column, node_position.column);
1369
+ for (node.attrs) |attribute| {
1370
+ try testing.expectEqualStrings(attribute.name, source[attribute.name_span.start..attribute.name_span.end]);
1371
+ if (attribute.value.len > 0) {
1372
+ try testing.expectEqualStrings(attribute.value, source[attribute.value_span.start..attribute.value_span.end]);
1373
+ } else {
1374
+ try testing.expectEqual(attribute.value_span.start, attribute.value_span.end);
1375
+ }
1376
+ const attr_position = markup.positionAt(source, attribute.name_span.start);
1377
+ try testing.expectEqual(attribute.line, attr_position.line);
1378
+ try testing.expectEqual(attribute.column, attr_position.column);
1379
+ }
1380
+ for (node.children) |child| {
1381
+ try expectSpansCover(source, child);
1382
+ }
1383
+ }
1384
+
1385
+ test "nodes and attributes carry byte-range spans; line/column derive from them" {
1386
+ // Spans are the write-back prerequisite: every node, attribute name,
1387
+ // attribute value, and text run must map to the exact source bytes,
1388
+ // and the parser's line/column must be re-derivable from the span
1389
+ // start (diagnostics keep their line:column shape; spans carry the
1390
+ // authority).
1391
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1392
+ defer arena_state.deinit();
1393
+ var parser = markup.Parser.init(arena_state.allocator(), inbox_source);
1394
+ const document = try parser.parse();
1395
+ try expectSpansCover(inbox_source, document.root.?);
1396
+
1397
+ // The comptime parser stamps identical spans (both engines see one
1398
+ // document geometry).
1399
+ const comptime_document = comptime markup.parseComptime(inbox_source);
1400
+ try expectSpansCover(inbox_source, comptime_document.root.?);
1401
+ try testing.expectEqual(document.root.?.span, comptime_document.root.?.span);
1402
+
1403
+ // Spot-pin the root: the document's exact extent.
1404
+ try testing.expectEqual(std.mem.indexOf(u8, inbox_source, "<column").?, document.root.?.span.start);
1405
+ try testing.expectEqual(inbox_source.len, document.root.?.span.end);
1406
+ }
1407
+
1408
+ test "self-closing elements and value-less attributes span correctly" {
1409
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1410
+ defer arena_state.deinit();
1411
+ const source = "<column><separator/><text wrap=\"true\">hi</text></column>";
1412
+ var parser = markup.Parser.init(arena_state.allocator(), source);
1413
+ const document = try parser.parse();
1414
+ const root = document.root.?;
1415
+ const separator = root.children[0];
1416
+ try testing.expectEqualStrings("<separator/>", source[separator.span.start..separator.span.end]);
1417
+ const text = root.children[1];
1418
+ try testing.expectEqualStrings("<text wrap=\"true\">hi</text>", source[text.span.start..text.span.end]);
1419
+ const wrap = text.attrs[0];
1420
+ try testing.expectEqualStrings("wrap", source[wrap.name_span.start..wrap.name_span.end]);
1421
+ try testing.expectEqualStrings("true", source[wrap.value_span.start..wrap.value_span.end]);
1422
+ const run = text.children[0];
1423
+ try testing.expectEqualStrings("hi", source[run.span.start..run.span.end]);
1424
+ }
1425
+
1426
+ // ---------------------------------------------------------- typed pass
1427
+
1428
+ fn expectTypedMatchesClassification(node: markup.MarkupNode) !void {
1429
+ for (node.attrs) |attribute| {
1430
+ // Canonicalization stamped every attribute...
1431
+ const typed = attribute.typed orelse return error.TestUnexpectedResult;
1432
+ // ...with exactly the classification the engines' fallback
1433
+ // computes — the pass changes cost, never meaning.
1434
+ const fallback = markup.classifyAttrValue(attribute.name, attribute.value);
1435
+ try testing.expectEqual(std.meta.activeTag(fallback), std.meta.activeTag(typed.*));
1436
+ if (typed.* == .expression) {
1437
+ // The tree parsed once, at document level.
1438
+ try testing.expect(typed.expression.tree != null);
1439
+ try testing.expectEqualStrings(fallback.expression.inner, typed.expression.inner);
1440
+ }
1441
+ }
1442
+ if (node.kind == .text and std.mem.indexOfScalar(u8, node.text, '{') != null) {
1443
+ try testing.expect(node.typed_text != null);
1444
+ }
1445
+ for (node.children) |child| {
1446
+ try expectTypedMatchesClassification(child);
1447
+ }
1448
+ }
1449
+
1450
+ test "canonicalization stamps typed values that match on-the-fly classification" {
1451
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1452
+ defer arena_state.deinit();
1453
+ const arena = arena_state.allocator();
1454
+ const source =
1455
+ \\<column gap="8" background="surface">
1456
+ \\ <text label="{count} items">{count} of {total(count, 2)}</text>
1457
+ \\ <button selected="{mode == active_mode}" on-press="set:{mode}">Go</button>
1458
+ \\ <if test="{count > 0 and not busy}">
1459
+ \\ <badge>{count}</badge>
1460
+ \\ </if>
1461
+ \\</column>
1462
+ ;
1463
+ var parser = markup.Parser.init(arena, source);
1464
+ const document = try parser.parse();
1465
+ const canonical = try markup.canonicalize(arena, document);
1466
+ try expectTypedMatchesClassification(canonical.root.?);
1467
+
1468
+ // The if test is a full expression whose tree parsed once.
1469
+ const if_block = canonical.root.?.children[2];
1470
+ const test_attr = if_block.attrEntry("test").?;
1471
+ try testing.expect(test_attr.typed.?.* == .expression);
1472
+ try testing.expect(test_attr.typed.?.expression.tree != null);
1473
+
1474
+ // on-* attributes classify as messages, payload path included.
1475
+ const button = canonical.root.?.children[1];
1476
+ const press = button.attrEntry("on-press").?;
1477
+ try testing.expectEqualStrings("set", press.typed.?.message.tag);
1478
+ try testing.expectEqualStrings("mode", press.typed.?.message.payload);
1479
+
1480
+ // The comptime pass stamps the same shapes for the compiled engine.
1481
+ const comptime_canonical = comptime markup.canonicalizeComptime(markup.parseComptime(
1482
+ \\<row><text>{a} + {b}</text></row>
1483
+ ));
1484
+ const run = comptime_canonical.root.?.children[0].children[0];
1485
+ try testing.expect(run.typed_text != null);
1486
+ try testing.expectEqual(@as(usize, 3), run.typed_text.?.len);
1487
+ try testing.expectEqualStrings("a", run.typed_text.?[0].binding);
1488
+ try testing.expectEqualStrings(" + ", run.typed_text.?[1].literal);
1489
+ try testing.expectEqualStrings("b", run.typed_text.?[2].binding);
1490
+ }
1491
+
1492
+ // ------------------------------------------------- inline span separators
1493
+
1494
+ test "whitespace between a span paragraph's runs collapses to one spliced space" {
1495
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1496
+ defer arena_state.deinit();
1497
+ const arena = arena_state.allocator();
1498
+
1499
+ // Whitespace between inline children is STRUCTURE inside a span
1500
+ // paragraph: the parser materializes it as a single-space text node,
1501
+ // so spacing serializes, hashes, and round-trips as ordinary content.
1502
+ const source = "<column><text>value <span weight=\"bold\">42</span>\n of <span mono=\"true\">60</span>.</text></column>";
1503
+ var parser = markup.Parser.init(arena, source);
1504
+ const document = try parser.parse();
1505
+ try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(document));
1506
+ const text_node = document.root.?.children[0];
1507
+
1508
+ // [value][ ][span 42][ ][of][ ][span 60][.] — the multi-byte
1509
+ // "\n " gap collapses to one space, and the "." run abuts its
1510
+ // span (no gap, no separator).
1511
+ try testing.expectEqual(@as(usize, 8), text_node.children.len);
1512
+ try testing.expectEqualStrings("value", text_node.children[0].text);
1513
+ try testing.expectEqualStrings(" ", text_node.children[1].text);
1514
+ try testing.expect(markup.nodeIsSpan(text_node.children[2]));
1515
+ try testing.expectEqualStrings(" ", text_node.children[3].text);
1516
+ try testing.expectEqualStrings("of", text_node.children[4].text);
1517
+ try testing.expectEqualStrings(" ", text_node.children[5].text);
1518
+ try testing.expect(markup.nodeIsSpan(text_node.children[6]));
1519
+ try testing.expectEqualStrings(".", text_node.children[7].text);
1520
+
1521
+ // Separator spans cover the exact whitespace gap (write-back bytes),
1522
+ // and their positions derive from the gap start like every node.
1523
+ const separator = text_node.children[3];
1524
+ try testing.expectEqualStrings("\n ", source[separator.span.start..separator.span.end]);
1525
+ try expectSpansCover(source, document.root.?);
1526
+
1527
+ // The comptime parser splices identical separators.
1528
+ const comptime_document = comptime markup.parseComptime("<column><text>value <span weight=\"bold\">42</span>\n of <span mono=\"true\">60</span>.</text></column>");
1529
+ const comptime_text = comptime_document.root.?.children[0];
1530
+ try testing.expectEqual(@as(usize, 8), comptime_text.children.len);
1531
+ try testing.expectEqualStrings(" ", comptime_text.children[1].text);
1532
+ try testing.expectEqualStrings(".", comptime_text.children[7].text);
1533
+
1534
+ // Span-less text keeps the classic trim: no separators appear.
1535
+ var plain_parser = markup.Parser.init(arena, "<column><text> hi there </text></column>");
1536
+ const plain = try plain_parser.parse();
1537
+ try testing.expectEqual(@as(usize, 1), plain.root.?.children[0].children.len);
1538
+ try testing.expectEqualStrings("hi there", plain.root.?.children[0].children[0].text);
1539
+
1540
+ // Comments between runs are transparent: their bytes never count as
1541
+ // author whitespace, so commented-but-abutting runs stay abutting.
1542
+ var comment_parser = markup.Parser.init(arena, "<column><text><span>a</span><!-- glue --><span>b</span></text></column>");
1543
+ const commented = try comment_parser.parse();
1544
+ try testing.expectEqual(@as(usize, 2), commented.root.?.children[0].children.len);
1545
+ }