@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.
- package/LICENSE +176 -0
- package/README.md +50 -1
- package/app.zon +30 -0
- package/assets/icon.icns +0 -0
- package/assets/icon.ico +0 -0
- package/assets/icon.png +0 -0
- package/assets/icon.svg +15 -0
- package/assets/native-sdk.entitlements +10 -0
- package/assets/native-sdk.manifest +12 -0
- package/bin/native.js +156 -0
- package/build/app.zig +716 -0
- package/build.zig +2593 -0
- package/build.zig.zon +24 -0
- package/native-sdk.d.ts +615 -0
- package/package.json +45 -8
- package/skill-data/automation/SKILL.md +248 -0
- package/skill-data/core/SKILL.md +249 -0
- package/skill-data/core/references/app-model-runtime.md +141 -0
- package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
- package/skill-data/core/references/frontend-assets.md +124 -0
- package/skill-data/core/references/project-anatomy.md +108 -0
- package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
- package/skill-data/native-ui/SKILL.md +1080 -0
- package/skills/native-sdk/SKILL.md +33 -0
- package/src/app_runner/root.zig +740 -0
- package/src/assets/root.zig +20 -0
- package/src/automation/protocol.zig +285 -0
- package/src/automation/root.zig +13 -0
- package/src/automation/server.zig +506 -0
- package/src/automation/snapshot.zig +1202 -0
- package/src/automation/watcher.zig +165 -0
- package/src/bridge/root.zig +507 -0
- package/src/debug/root.zig +246 -0
- package/src/embed/app_exports.zig +11 -0
- package/src/embed/c_api.zig +793 -0
- package/src/embed/c_exports.zig +10 -0
- package/src/embed/chrome.zig +168 -0
- package/src/embed/conversions.zig +359 -0
- package/src/embed/host.zig +960 -0
- package/src/embed/root.zig +81 -0
- package/src/embed/tests.zig +2552 -0
- package/src/embed/types.zig +382 -0
- package/src/embed/ui_host.zig +289 -0
- package/src/extensions/root.zig +197 -0
- package/src/frontend/root.zig +48 -0
- package/src/js/root.zig +65 -0
- package/src/platform/android/NativeSdkActivity.java +1370 -0
- package/src/platform/android/android_host.c +696 -0
- package/src/platform/android/files.zig +9 -0
- package/src/platform/android/native_sdk_app.h +237 -0
- package/src/platform/ios/files.zig +8 -0
- package/src/platform/ios/native_sdk_app.h +289 -0
- package/src/platform/ios/uikit_host.m +2739 -0
- package/src/platform/linux/cef_host.cpp +599 -0
- package/src/platform/linux/gtk_host.c +5362 -0
- package/src/platform/linux/gtk_host.h +265 -0
- package/src/platform/linux/root.zig +1519 -0
- package/src/platform/macos/appkit_host.h +604 -0
- package/src/platform/macos/appkit_host.m +10392 -0
- package/src/platform/macos/automation_host.h +14 -0
- package/src/platform/macos/automation_host.m +12 -0
- package/src/platform/macos/cef_host.mm +3028 -0
- package/src/platform/macos/root.zig +2260 -0
- package/src/platform/null_platform.zig +2232 -0
- package/src/platform/null_platform_tests.zig +670 -0
- package/src/platform/policy_values.zig +14 -0
- package/src/platform/root.zig +181 -0
- package/src/platform/types.zig +2681 -0
- package/src/platform/windows/cef_host.cpp +3 -0
- package/src/platform/windows/root.zig +1521 -0
- package/src/platform/windows/webview2_host.cpp +6230 -0
- package/src/primitives/app_dirs/root.zig +440 -0
- package/src/primitives/app_manifest/root.zig +109 -0
- package/src/primitives/app_manifest/tests.zig +758 -0
- package/src/primitives/app_manifest/types.zig +587 -0
- package/src/primitives/app_manifest/validation.zig +828 -0
- package/src/primitives/assets/root.zig +520 -0
- package/src/primitives/canvas/a11y_audit.zig +390 -0
- package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
- package/src/primitives/canvas/app_icon.zig +1590 -0
- package/src/primitives/canvas/chart.zig +392 -0
- package/src/primitives/canvas/chart_tests.zig +751 -0
- package/src/primitives/canvas/commands.zig +446 -0
- package/src/primitives/canvas/drawing.zig +309 -0
- package/src/primitives/canvas/equality.zig +316 -0
- package/src/primitives/canvas/events.zig +696 -0
- package/src/primitives/canvas/font_coverage.zig +118 -0
- package/src/primitives/canvas/font_ttf.zig +510 -0
- package/src/primitives/canvas/font_ttf_tests.zig +280 -0
- package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
- package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
- package/src/primitives/canvas/frame.zig +679 -0
- package/src/primitives/canvas/frame_metrics.zig +462 -0
- package/src/primitives/canvas/gpu.zig +639 -0
- package/src/primitives/canvas/hash.zig +112 -0
- package/src/primitives/canvas/icons/alert.svg +1 -0
- package/src/primitives/canvas/icons/archive.svg +1 -0
- package/src/primitives/canvas/icons/arrow-down.svg +1 -0
- package/src/primitives/canvas/icons/arrow-right.svg +1 -0
- package/src/primitives/canvas/icons/arrow-up.svg +1 -0
- package/src/primitives/canvas/icons/check-circle.svg +1 -0
- package/src/primitives/canvas/icons/check.svg +1 -0
- package/src/primitives/canvas/icons/chevron-down.svg +1 -0
- package/src/primitives/canvas/icons/chevron-left.svg +1 -0
- package/src/primitives/canvas/icons/chevron-right.svg +1 -0
- package/src/primitives/canvas/icons/chevron-up.svg +1 -0
- package/src/primitives/canvas/icons/circle-dot.svg +1 -0
- package/src/primitives/canvas/icons/clock.svg +1 -0
- package/src/primitives/canvas/icons/copy.svg +1 -0
- package/src/primitives/canvas/icons/download.svg +1 -0
- package/src/primitives/canvas/icons/edit.svg +1 -0
- package/src/primitives/canvas/icons/ellipsis.svg +1 -0
- package/src/primitives/canvas/icons/external-link.svg +1 -0
- package/src/primitives/canvas/icons/eye.svg +1 -0
- package/src/primitives/canvas/icons/file-text.svg +1 -0
- package/src/primitives/canvas/icons/folder-open.svg +1 -0
- package/src/primitives/canvas/icons/folder.svg +1 -0
- package/src/primitives/canvas/icons/git-branch.svg +1 -0
- package/src/primitives/canvas/icons/git-merge.svg +1 -0
- package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
- package/src/primitives/canvas/icons/info.svg +1 -0
- package/src/primitives/canvas/icons/menu.svg +1 -0
- package/src/primitives/canvas/icons/missing.svg +1 -0
- package/src/primitives/canvas/icons/moon.svg +1 -0
- package/src/primitives/canvas/icons/music.svg +1 -0
- package/src/primitives/canvas/icons/panel-left.svg +1 -0
- package/src/primitives/canvas/icons/panel-right.svg +1 -0
- package/src/primitives/canvas/icons/pause.svg +1 -0
- package/src/primitives/canvas/icons/play.svg +1 -0
- package/src/primitives/canvas/icons/plus.svg +1 -0
- package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
- package/src/primitives/canvas/icons/repeat.svg +1 -0
- package/src/primitives/canvas/icons/save.svg +1 -0
- package/src/primitives/canvas/icons/search.svg +1 -0
- package/src/primitives/canvas/icons/send.svg +1 -0
- package/src/primitives/canvas/icons/settings.svg +1 -0
- package/src/primitives/canvas/icons/shuffle.svg +1 -0
- package/src/primitives/canvas/icons/skip-back.svg +1 -0
- package/src/primitives/canvas/icons/skip-forward.svg +1 -0
- package/src/primitives/canvas/icons/sun.svg +1 -0
- package/src/primitives/canvas/icons/terminal.svg +1 -0
- package/src/primitives/canvas/icons/trash.svg +1 -0
- package/src/primitives/canvas/icons/volume.svg +1 -0
- package/src/primitives/canvas/icons/wrench.svg +1 -0
- package/src/primitives/canvas/icons/x-circle.svg +1 -0
- package/src/primitives/canvas/icons/x.svg +1 -0
- package/src/primitives/canvas/icons.zig +249 -0
- package/src/primitives/canvas/layout_audit.zig +744 -0
- package/src/primitives/canvas/layout_audit_tests.zig +426 -0
- package/src/primitives/canvas/markdown.zig +1031 -0
- package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
- package/src/primitives/canvas/markdown_tests.zig +538 -0
- package/src/primitives/canvas/plan_key_index.zig +120 -0
- package/src/primitives/canvas/png.zig +355 -0
- package/src/primitives/canvas/reference.zig +1457 -0
- package/src/primitives/canvas/reference_blur.zig +104 -0
- package/src/primitives/canvas/reference_memo.zig +322 -0
- package/src/primitives/canvas/reference_paths.zig +184 -0
- package/src/primitives/canvas/reference_tests.zig +1650 -0
- package/src/primitives/canvas/render.zig +747 -0
- package/src/primitives/canvas/render_effects.zig +255 -0
- package/src/primitives/canvas/render_fingerprints.zig +256 -0
- package/src/primitives/canvas/render_generic_resources.zig +376 -0
- package/src/primitives/canvas/render_images.zig +247 -0
- package/src/primitives/canvas/render_layers.zig +260 -0
- package/src/primitives/canvas/render_paths.zig +347 -0
- package/src/primitives/canvas/render_resources.zig +51 -0
- package/src/primitives/canvas/render_tests.zig +3186 -0
- package/src/primitives/canvas/root.zig +744 -0
- package/src/primitives/canvas/serialization.zig +1528 -0
- package/src/primitives/canvas/svg_icon.zig +636 -0
- package/src/primitives/canvas/svg_icon_tests.zig +312 -0
- package/src/primitives/canvas/test_support.zig +422 -0
- package/src/primitives/canvas/testdata/markdown_document.md +83 -0
- package/src/primitives/canvas/tests.zig +30 -0
- package/src/primitives/canvas/text.zig +82 -0
- package/src/primitives/canvas/text_atlas.zig +408 -0
- package/src/primitives/canvas/text_batch_tests.zig +431 -0
- package/src/primitives/canvas/text_interaction.zig +615 -0
- package/src/primitives/canvas/text_layout.zig +1069 -0
- package/src/primitives/canvas/text_layout_cache.zig +281 -0
- package/src/primitives/canvas/text_layout_hash.zig +113 -0
- package/src/primitives/canvas/text_layout_types.zig +128 -0
- package/src/primitives/canvas/text_measure_cache.zig +279 -0
- package/src/primitives/canvas/text_metrics.zig +309 -0
- package/src/primitives/canvas/text_metrics_tests.zig +262 -0
- package/src/primitives/canvas/text_span_tests.zig +608 -0
- package/src/primitives/canvas/text_spans.zig +1010 -0
- package/src/primitives/canvas/text_tests.zig +1949 -0
- package/src/primitives/canvas/themes/geist.zig +470 -0
- package/src/primitives/canvas/tokens.zig +1522 -0
- package/src/primitives/canvas/ui.zig +2686 -0
- package/src/primitives/canvas/ui_markup.zig +3791 -0
- package/src/primitives/canvas/ui_markup_binary.zig +522 -0
- package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
- package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
- package/src/primitives/canvas/ui_markup_edit.zig +416 -0
- package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
- package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
- package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
- package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
- package/src/primitives/canvas/ui_markup_view.zig +2352 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
- package/src/primitives/canvas/ui_provenance.zig +96 -0
- package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
- package/src/primitives/canvas/ui_schema.zig +825 -0
- package/src/primitives/canvas/ui_schema_tests.zig +128 -0
- package/src/primitives/canvas/ui_tests.zig +1432 -0
- package/src/primitives/canvas/vector.zig +919 -0
- package/src/primitives/canvas/vector_tests.zig +547 -0
- package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
- package/src/primitives/canvas/virtual_extents.zig +540 -0
- package/src/primitives/canvas/widget_access.zig +208 -0
- package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
- package/src/primitives/canvas/widget_invalidation.zig +748 -0
- package/src/primitives/canvas/widget_layout.zig +2055 -0
- package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
- package/src/primitives/canvas/widget_metrics.zig +228 -0
- package/src/primitives/canvas/widget_render.zig +2534 -0
- package/src/primitives/canvas/widget_render_controls.zig +1563 -0
- package/src/primitives/canvas/widget_render_scroll.zig +136 -0
- package/src/primitives/canvas/widget_render_style.zig +626 -0
- package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
- package/src/primitives/canvas/widget_routing.zig +475 -0
- package/src/primitives/canvas/widget_runtime.zig +307 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
- package/src/primitives/canvas/widget_semantics.zig +480 -0
- package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
- package/src/primitives/canvas/widget_tests.zig +8 -0
- package/src/primitives/canvas/widget_text_input.zig +351 -0
- package/src/primitives/canvas/widget_text_select.zig +147 -0
- package/src/primitives/canvas/widget_tree.zig +232 -0
- package/src/primitives/canvas/widgets.zig +1319 -0
- package/src/primitives/diagnostics/root.zig +445 -0
- package/src/primitives/geometry/root.zig +889 -0
- package/src/primitives/json/root.zig +272 -0
- package/src/primitives/platform_info/root.zig +450 -0
- package/src/primitives/trace/root.zig +569 -0
- package/src/root.zig +165 -0
- package/src/runtime/api.zig +431 -0
- package/src/runtime/async_bridge.zig +49 -0
- package/src/runtime/automation_commands.zig +686 -0
- package/src/runtime/automation_liveness_tests.zig +140 -0
- package/src/runtime/automation_snapshot.zig +246 -0
- package/src/runtime/automation_widget_dispatch.zig +617 -0
- package/src/runtime/bridge_dispatch_tests.zig +202 -0
- package/src/runtime/bridge_payload.zig +194 -0
- package/src/runtime/bridge_permission_tests.zig +551 -0
- package/src/runtime/bridge_responses.zig +414 -0
- package/src/runtime/builtin_bridge.zig +554 -0
- package/src/runtime/canvas_budget_edge_tests.zig +415 -0
- package/src/runtime/canvas_font_tests.zig +410 -0
- package/src/runtime/canvas_fonts.zig +229 -0
- package/src/runtime/canvas_frame.zig +1734 -0
- package/src/runtime/canvas_frame_animation_tests.zig +609 -0
- package/src/runtime/canvas_frame_cache_tests.zig +333 -0
- package/src/runtime/canvas_frame_helpers.zig +414 -0
- package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
- package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
- package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
- package/src/runtime/canvas_frame_retained_tests.zig +753 -0
- package/src/runtime/canvas_frame_tests.zig +9 -0
- package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
- package/src/runtime/canvas_image_tests.zig +362 -0
- package/src/runtime/canvas_images.zig +224 -0
- package/src/runtime/canvas_limits.zig +317 -0
- package/src/runtime/canvas_screenshot_tests.zig +289 -0
- package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
- package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
- package/src/runtime/canvas_widget_chart_tests.zig +249 -0
- package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
- package/src/runtime/canvas_widget_context_menu.zig +318 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
- package/src/runtime/canvas_widget_control_tests.zig +2164 -0
- package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
- package/src/runtime/canvas_widget_display.zig +677 -0
- package/src/runtime/canvas_widget_event_tests.zig +1779 -0
- package/src/runtime/canvas_widget_events.zig +1098 -0
- package/src/runtime/canvas_widget_floating_tests.zig +695 -0
- package/src/runtime/canvas_widget_layout_tests.zig +26 -0
- package/src/runtime/canvas_widget_runtime.zig +1335 -0
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
- package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
- package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
- package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
- package/src/runtime/canvas_widget_state.zig +798 -0
- package/src/runtime/canvas_widget_text_tests.zig +2104 -0
- package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
- package/src/runtime/clock.zig +231 -0
- package/src/runtime/core.zig +927 -0
- package/src/runtime/effects.zig +4197 -0
- package/src/runtime/effects_audio_tests.zig +690 -0
- package/src/runtime/effects_clipboard_tests.zig +317 -0
- package/src/runtime/effects_fetch_tests.zig +1031 -0
- package/src/runtime/effects_file_tests.zig +407 -0
- package/src/runtime/effects_tests.zig +1251 -0
- package/src/runtime/flow.zig +1175 -0
- package/src/runtime/frame_profile.zig +221 -0
- package/src/runtime/gpu_surface_events.zig +639 -0
- package/src/runtime/launch_timing.zig +59 -0
- package/src/runtime/markdown_app_tests.zig +224 -0
- package/src/runtime/native_command_event_tests.zig +431 -0
- package/src/runtime/platform_bridge_tests.zig +8 -0
- package/src/runtime/platform_config_tests.zig +392 -0
- package/src/runtime/root.zig +150 -0
- package/src/runtime/runtime_event_tests.zig +1079 -0
- package/src/runtime/session_journal.zig +1522 -0
- package/src/runtime/session_record.zig +332 -0
- package/src/runtime/session_replay.zig +274 -0
- package/src/runtime/session_state.zig +30 -0
- package/src/runtime/session_tests.zig +399 -0
- package/src/runtime/shell_layout.zig +472 -0
- package/src/runtime/shell_layout_tests.zig +1246 -0
- package/src/runtime/shell_view_tests.zig +604 -0
- package/src/runtime/state.zig +110 -0
- package/src/runtime/system_services.zig +392 -0
- package/src/runtime/test_support.zig +79 -0
- package/src/runtime/tests.zig +30 -0
- package/src/runtime/ui_app.zig +3290 -0
- package/src/runtime/ui_app_huge_model_tests.zig +351 -0
- package/src/runtime/ui_app_provenance.zig +370 -0
- package/src/runtime/ui_app_tests.zig +3254 -0
- package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
- package/src/runtime/ui_app_window_tests.zig +442 -0
- package/src/runtime/validation.zig +206 -0
- package/src/runtime/view.zig +908 -0
- package/src/runtime/view_canvas.zig +850 -0
- package/src/runtime/view_widget_control.zig +433 -0
- package/src/runtime/view_widget_scroll.zig +360 -0
- package/src/runtime/view_widget_text.zig +275 -0
- package/src/runtime/view_widget_tree.zig +843 -0
- package/src/runtime/webview_view_bridge_tests.zig +664 -0
- package/src/runtime/widget_bridge.zig +231 -0
- package/src/runtime/window_command_bridge_tests.zig +403 -0
- package/src/runtime/window_storage.zig +255 -0
- package/src/runtime/window_view_runtime.zig +727 -0
- package/src/runtime/window_views.zig +334 -0
- package/src/security/root.zig +118 -0
- package/src/tooling/android.zig +1172 -0
- package/src/tooling/assets.zig +128 -0
- package/src/tooling/buildgraph.zig +379 -0
- package/src/tooling/cef.zig +671 -0
- package/src/tooling/codesign.zig +172 -0
- package/src/tooling/components/identity_tests.zig +185 -0
- package/src/tooling/components/stepper.zig +113 -0
- package/src/tooling/components/timeline.native +27 -0
- package/src/tooling/components/timeline_item.zig +131 -0
- package/src/tooling/default_icon.icns +0 -0
- package/src/tooling/default_icon.png +0 -0
- package/src/tooling/dev.zig +172 -0
- package/src/tooling/doctor.zig +349 -0
- package/src/tooling/eject_components.zig +170 -0
- package/src/tooling/embedlib.zig +290 -0
- package/src/tooling/ios.zig +528 -0
- package/src/tooling/manifest.zig +1939 -0
- package/src/tooling/package.zig +2388 -0
- package/src/tooling/process_tree.zig +114 -0
- package/src/tooling/raw_manifest.zig +193 -0
- package/src/tooling/root.zig +22 -0
- package/src/tooling/templates.zig +3191 -0
- package/src/tooling/toolchain.zig +371 -0
- package/src/tooling/verbs.zig +204 -0
- package/src/tooling/web_engine.zig +135 -0
- package/src/tooling/xcodeproj.zig +462 -0
- package/src/window_state/root.zig +507 -0
- package/index.js +0 -2
|
@@ -0,0 +1,1669 @@
|
|
|
1
|
+
//! Parity tests for the comptime-compiled markup path: for the same model,
|
|
2
|
+
//! `CompiledMarkupView(...).build` must produce exactly what the runtime
|
|
3
|
+
//! interpreter produces — identical structural ids node for node, identical
|
|
4
|
+
//! handler tables, identical dispatch results, identical interpolated text.
|
|
5
|
+
//!
|
|
6
|
+
//! Compile-error coverage: Zig cannot unit-test `@compileError`, so the
|
|
7
|
+
//! rejecting side is guaranteed structurally — every invalid construct the
|
|
8
|
+
//! interpreter reports at runtime (see "markup build failures carry position
|
|
9
|
+
//! and message" in ui_markup_view_tests.zig) is resolved during the comptime
|
|
10
|
+
//! walk and fails compilation with the same message plus line/column. These
|
|
11
|
+
//! tests pin down the accepting side: everything valid builds identically.
|
|
12
|
+
|
|
13
|
+
const std = @import("std");
|
|
14
|
+
const canvas = @import("root.zig");
|
|
15
|
+
const markup_view = @import("ui_markup_view.zig");
|
|
16
|
+
const fixture = @import("ui_markup_view_tests.zig");
|
|
17
|
+
|
|
18
|
+
const testing = std.testing;
|
|
19
|
+
|
|
20
|
+
// ------------------------------------------------------ shared assertions
|
|
21
|
+
|
|
22
|
+
/// Identical trees: same structural ids node for node and the same handler
|
|
23
|
+
/// table entry for entry (messages by value, input/value constructors by
|
|
24
|
+
/// function identity — both engines instantiate `Ui.inputMsg` on the same
|
|
25
|
+
/// comptime tag, so parity implies pointer equality).
|
|
26
|
+
fn expectSameTree(comptime MsgT: type, expected: canvas.Ui(MsgT).Tree, actual: canvas.Ui(MsgT).Tree) !void {
|
|
27
|
+
var expected_ids: std.ArrayListUnmanaged(canvas.ObjectId) = .empty;
|
|
28
|
+
defer expected_ids.deinit(testing.allocator);
|
|
29
|
+
var actual_ids: std.ArrayListUnmanaged(canvas.ObjectId) = .empty;
|
|
30
|
+
defer actual_ids.deinit(testing.allocator);
|
|
31
|
+
try fixture.collectIds(expected.root, &expected_ids, testing.allocator);
|
|
32
|
+
try fixture.collectIds(actual.root, &actual_ids, testing.allocator);
|
|
33
|
+
try testing.expectEqualSlices(canvas.ObjectId, expected_ids.items, actual_ids.items);
|
|
34
|
+
|
|
35
|
+
try testing.expectEqual(expected.handlers.len, actual.handlers.len);
|
|
36
|
+
for (expected.handlers, actual.handlers) |expected_handler, actual_handler| {
|
|
37
|
+
try testing.expectEqual(expected_handler.id, actual_handler.id);
|
|
38
|
+
try testing.expectEqual(expected_handler.event, actual_handler.event);
|
|
39
|
+
try testing.expectEqual(std.meta.activeTag(expected_handler.action), std.meta.activeTag(actual_handler.action));
|
|
40
|
+
switch (expected_handler.action) {
|
|
41
|
+
.message => |msg| try expectSameMsg(MsgT, msg, actual_handler.action.message),
|
|
42
|
+
.input => |make| try testing.expectEqual(make, actual_handler.action.input),
|
|
43
|
+
.value => |make| try testing.expectEqual(make, actual_handler.action.value),
|
|
44
|
+
.scroll => |make| try testing.expectEqual(make, actual_handler.action.scroll),
|
|
45
|
+
// Context-menu handler entries carry one ?Msg per declared
|
|
46
|
+
// item (separators are null slots); markup `<context-menu>`
|
|
47
|
+
// and the Zig builder both produce them.
|
|
48
|
+
.context_menu => |msgs| {
|
|
49
|
+
const actual_msgs = actual_handler.action.context_menu;
|
|
50
|
+
try testing.expectEqual(msgs.len, actual_msgs.len);
|
|
51
|
+
for (msgs, actual_msgs) |expected_msg, actual_msg| {
|
|
52
|
+
try testing.expectEqual(expected_msg == null, actual_msg == null);
|
|
53
|
+
if (expected_msg) |msg| try expectSameMsg(MsgT, msg, actual_msg.?);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/// Messages are equal when their tag and payload agree; string payloads
|
|
61
|
+
/// compare by bytes (each engine formats arena-computed payloads into its
|
|
62
|
+
/// own arena, so pointer identity is not part of the contract).
|
|
63
|
+
fn expectSameMsg(comptime MsgT: type, expected: MsgT, actual: MsgT) !void {
|
|
64
|
+
try testing.expectEqual(std.meta.activeTag(expected), std.meta.activeTag(actual));
|
|
65
|
+
switch (expected) {
|
|
66
|
+
inline else => |payload, tag| {
|
|
67
|
+
const actual_payload = @field(actual, @tagName(tag));
|
|
68
|
+
if (@TypeOf(payload) == []const u8) {
|
|
69
|
+
try testing.expectEqualStrings(payload, actual_payload);
|
|
70
|
+
} else {
|
|
71
|
+
try testing.expect(std.meta.eql(payload, actual_payload));
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
fn expectSameTexts(expected: canvas.Widget, actual: canvas.Widget) !void {
|
|
78
|
+
try testing.expectEqual(expected.kind, actual.kind);
|
|
79
|
+
try testing.expectEqualStrings(expected.text, actual.text);
|
|
80
|
+
try testing.expectEqual(expected.state.selected, actual.state.selected);
|
|
81
|
+
try testing.expectEqual(expected.children.len, actual.children.len);
|
|
82
|
+
for (expected.children, actual.children) |expected_child, actual_child| {
|
|
83
|
+
try expectSameTexts(expected_child, actual_child);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// --------------------------------------------------- inbox fixture parity
|
|
88
|
+
|
|
89
|
+
const InboxUi = canvas.Ui(fixture.Msg);
|
|
90
|
+
const InboxInterpreter = markup_view.MarkupView(fixture.Model, fixture.Msg);
|
|
91
|
+
const InboxCompiled = canvas.CompiledMarkupView(fixture.Model, fixture.Msg, fixture.inbox_markup_source);
|
|
92
|
+
|
|
93
|
+
fn interpretInbox(arena: std.mem.Allocator, model: *const fixture.Model) !InboxUi.Tree {
|
|
94
|
+
var view = try InboxInterpreter.init(arena, fixture.inbox_markup_source);
|
|
95
|
+
var ui = InboxUi.init(arena);
|
|
96
|
+
return ui.finalize(try view.build(&ui, model));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
fn compileInbox(arena: std.mem.Allocator, model: *const fixture.Model) !InboxUi.Tree {
|
|
100
|
+
var ui = InboxUi.init(arena);
|
|
101
|
+
return ui.finalize(InboxCompiled.build(&ui, model));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const ContextMenuCompiled = canvas.CompiledMarkupView(fixture.Model, fixture.Msg, fixture.context_menu_markup_source);
|
|
105
|
+
|
|
106
|
+
test "compiled context-menus build the interpreter's declared items and handler entries exactly" {
|
|
107
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
108
|
+
defer arena_state.deinit();
|
|
109
|
+
const arena = arena_state.allocator();
|
|
110
|
+
const model = fixture.testModel();
|
|
111
|
+
|
|
112
|
+
var interpreter_view = try InboxInterpreter.init(arena, fixture.context_menu_markup_source);
|
|
113
|
+
var interpreter_ui = InboxUi.init(arena);
|
|
114
|
+
const interpreted = try interpreter_ui.finalize(try interpreter_view.build(&interpreter_ui, &model));
|
|
115
|
+
var compiled_ui = InboxUi.init(arena);
|
|
116
|
+
const compiled = try compiled_ui.finalize(ContextMenuCompiled.build(&compiled_ui, &model));
|
|
117
|
+
|
|
118
|
+
// Same ids, same handler table (context_menu entries msg for msg),
|
|
119
|
+
// same texts — and the declared items agree slot for slot.
|
|
120
|
+
try expectSameTree(fixture.Msg, interpreted, compiled);
|
|
121
|
+
try expectSameTexts(interpreted.root, compiled.root);
|
|
122
|
+
try testing.expectEqual(@as(usize, 3), interpreted.root.children.len);
|
|
123
|
+
for (interpreted.root.children, compiled.root.children) |expected_row, actual_row| {
|
|
124
|
+
try testing.expectEqual(expected_row.context_menu.len, actual_row.context_menu.len);
|
|
125
|
+
for (expected_row.context_menu, actual_row.context_menu) |expected_item, actual_item| {
|
|
126
|
+
try testing.expectEqualStrings(expected_item.label, actual_item.label);
|
|
127
|
+
try testing.expectEqual(expected_item.enabled, actual_item.enabled);
|
|
128
|
+
try testing.expectEqual(expected_item.separator, actual_item.separator);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// Selection dispatch parity through the shared handler entry.
|
|
132
|
+
const row = compiled.root.children[1];
|
|
133
|
+
try testing.expectEqual(fixture.Msg{ .toggle = 2 }, compiled.msgForContextMenu(row.id, 0).?);
|
|
134
|
+
try testing.expectEqual(
|
|
135
|
+
interpreted.msgForContextMenu(interpreted.root.children[1].id, 0).?,
|
|
136
|
+
compiled.msgForContextMenu(row.id, 0).?,
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
test "compiled inbox view builds the interpreter's and the hand-written tree exactly" {
|
|
141
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
142
|
+
defer arena_state.deinit();
|
|
143
|
+
const arena = arena_state.allocator();
|
|
144
|
+
|
|
145
|
+
const model = fixture.testModel();
|
|
146
|
+
|
|
147
|
+
const interpreted = try interpretInbox(arena, &model);
|
|
148
|
+
const compiled = try compileInbox(arena, &model);
|
|
149
|
+
var hand_ui = InboxUi.init(arena);
|
|
150
|
+
const hand = try hand_ui.finalize(fixture.handView(&hand_ui, &model));
|
|
151
|
+
|
|
152
|
+
// The three engines agree node for node and handler for handler: the
|
|
153
|
+
// compiled path covers `for` over a pub const array (filters) and an
|
|
154
|
+
// arena fn (visible), `{a == b}` equality, on-input/on-submit/on-press/
|
|
155
|
+
// on-toggle messages, and interpolation.
|
|
156
|
+
try expectSameTree(fixture.Msg, hand, interpreted);
|
|
157
|
+
try expectSameTree(fixture.Msg, hand, compiled);
|
|
158
|
+
try expectSameTexts(interpreted.root, compiled.root);
|
|
159
|
+
|
|
160
|
+
// Pointer dispatch parity.
|
|
161
|
+
const add_button = fixture.findByKind(compiled.root, .button).?;
|
|
162
|
+
try testing.expectEqual(fixture.Msg.add, compiled.msgForPointer(add_button.id, .up).?);
|
|
163
|
+
const interpreted_checkbox = fixture.findByKind(interpreted.root, .checkbox).?;
|
|
164
|
+
const compiled_checkbox = fixture.findByKind(compiled.root, .checkbox).?;
|
|
165
|
+
try testing.expectEqual(interpreted_checkbox.id, compiled_checkbox.id);
|
|
166
|
+
try testing.expectEqual(
|
|
167
|
+
interpreted.msgForPointer(interpreted_checkbox.id, .up).?,
|
|
168
|
+
compiled.msgForPointer(compiled_checkbox.id, .up).?,
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
// Keyboard dispatch parity, including the on-input constructor.
|
|
172
|
+
const text_field = fixture.findByKind(compiled.root, .text_field).?;
|
|
173
|
+
const typed = canvas.WidgetKeyboardEvent{ .phase = .text_input, .text = "x" };
|
|
174
|
+
try testing.expectEqualStrings("x", compiled.msgForKeyboard(text_field.id, typed).?.draft.insert_text);
|
|
175
|
+
const submit = canvas.WidgetKeyboardEvent{ .phase = .key_down, .key = "enter" };
|
|
176
|
+
try testing.expectEqual(
|
|
177
|
+
interpreted.msgForKeyboard(text_field.id, submit).?,
|
|
178
|
+
compiled.msgForKeyboard(text_field.id, submit).?,
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
// Interpolated text parity down to the byte.
|
|
182
|
+
try testing.expectEqualStrings("2 open", fixture.findByKind(compiled.root, .status_bar).?.text);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
test "compiled keyed rows keep ids across model changes and filters dispatch" {
|
|
186
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
187
|
+
defer arena_state.deinit();
|
|
188
|
+
const arena = arena_state.allocator();
|
|
189
|
+
|
|
190
|
+
var model = fixture.testModel();
|
|
191
|
+
|
|
192
|
+
const first = try compileInbox(arena, &model);
|
|
193
|
+
const first_checkbox = fixture.findByKind(first.root, .checkbox).?;
|
|
194
|
+
|
|
195
|
+
// Dispatch the done filter through a compiled-view button.
|
|
196
|
+
var done_msg: ?fixture.Msg = null;
|
|
197
|
+
for (first.handlers) |handler| {
|
|
198
|
+
if (handler.action == .message and handler.action.message == .set_filter) {
|
|
199
|
+
if (handler.action.message.set_filter == .done) done_msg = handler.action.message;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
try testing.expectEqual(fixture.Filter.done, done_msg.?.set_filter);
|
|
203
|
+
model.filter = done_msg.?.set_filter;
|
|
204
|
+
|
|
205
|
+
const second = try compileInbox(arena, &model);
|
|
206
|
+
const second_checkbox = fixture.findByKind(second.root, .checkbox).?;
|
|
207
|
+
try testing.expect(first_checkbox.id != second_checkbox.id);
|
|
208
|
+
try testing.expectEqual(@as(u32, 2), second.msgForPointer(second_checkbox.id, .up).?.toggle);
|
|
209
|
+
|
|
210
|
+
// Back to all: the original first row returns with its original id, and
|
|
211
|
+
// the interpreter agrees at every step.
|
|
212
|
+
model.filter = .all;
|
|
213
|
+
const third = try compileInbox(arena, &model);
|
|
214
|
+
try testing.expectEqual(first_checkbox.id, fixture.findByKind(third.root, .checkbox).?.id);
|
|
215
|
+
try expectSameTree(fixture.Msg, try interpretInbox(arena, &model), third);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// ------------------------- field-slice for, if/else, global-key fixture
|
|
219
|
+
|
|
220
|
+
const EntryStatus = enum { open, closed };
|
|
221
|
+
|
|
222
|
+
const Entry = struct {
|
|
223
|
+
id: u32,
|
|
224
|
+
label: []const u8,
|
|
225
|
+
status: EntryStatus = .open,
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
const EntriesMsg = union(enum) {
|
|
229
|
+
open_entry: u32,
|
|
230
|
+
refresh,
|
|
231
|
+
feed_scrolled: canvas.ScrollState,
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const EntriesModel = struct {
|
|
235
|
+
/// A plain slice field: the third `for` source kind (the inbox fixture
|
|
236
|
+
/// covers pub const arrays and arena fns).
|
|
237
|
+
entries: []const Entry = &.{},
|
|
238
|
+
/// Optional binding: truthiness is only runtime-known.
|
|
239
|
+
banner: ?[]const u8 = null,
|
|
240
|
+
closed_status: EntryStatus = .closed,
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const entries_markup =
|
|
244
|
+
\\<column gap="4">
|
|
245
|
+
\\ <if test="{banner}">
|
|
246
|
+
\\ <text>bannered</text>
|
|
247
|
+
\\ </if>
|
|
248
|
+
\\ <else>
|
|
249
|
+
\\ <text>plain</text>
|
|
250
|
+
\\ </else>
|
|
251
|
+
\\ <for each="entries" as="e" key="id">
|
|
252
|
+
\\ <row global-key="{e.id}" gap="2" cross="center">
|
|
253
|
+
\\ <if test="{e.status == closed_status}">
|
|
254
|
+
\\ <badge>closed</badge>
|
|
255
|
+
\\ </if>
|
|
256
|
+
\\ <else>
|
|
257
|
+
\\ <badge>open</badge>
|
|
258
|
+
\\ </else>
|
|
259
|
+
\\ <text grow="1">{e.label} #{e.id}</text>
|
|
260
|
+
\\ <button size="sm" on-press="open_entry:{e.id}">Open</button>
|
|
261
|
+
\\ </row>
|
|
262
|
+
\\ </for>
|
|
263
|
+
\\ <if test="{banner}">
|
|
264
|
+
\\ <status-bar>{banner}</status-bar>
|
|
265
|
+
\\ </if>
|
|
266
|
+
\\</column>
|
|
267
|
+
;
|
|
268
|
+
|
|
269
|
+
const EntriesUi = canvas.Ui(EntriesMsg);
|
|
270
|
+
const EntriesInterpreter = markup_view.MarkupView(EntriesModel, EntriesMsg);
|
|
271
|
+
const EntriesCompiled = canvas.CompiledMarkupView(EntriesModel, EntriesMsg, entries_markup);
|
|
272
|
+
|
|
273
|
+
fn interpretEntries(arena: std.mem.Allocator, model: *const EntriesModel) !EntriesUi.Tree {
|
|
274
|
+
var view = try EntriesInterpreter.init(arena, entries_markup);
|
|
275
|
+
var ui = EntriesUi.init(arena);
|
|
276
|
+
return ui.finalize(try view.build(&ui, model));
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
fn compileEntries(arena: std.mem.Allocator, model: *const EntriesModel) !EntriesUi.Tree {
|
|
280
|
+
var ui = EntriesUi.init(arena);
|
|
281
|
+
return ui.finalize(EntriesCompiled.build(&ui, model));
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
fn findText(widget: canvas.Widget, text: []const u8) ?canvas.Widget {
|
|
285
|
+
if (std.mem.eql(u8, widget.text, text)) return widget;
|
|
286
|
+
for (widget.children) |child| {
|
|
287
|
+
if (findText(child, text)) |found| return found;
|
|
288
|
+
}
|
|
289
|
+
return null;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
test "compiled field-slice for, if/else, and optional bindings match the interpreter" {
|
|
293
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
294
|
+
defer arena_state.deinit();
|
|
295
|
+
const arena = arena_state.allocator();
|
|
296
|
+
|
|
297
|
+
const entries = [_]Entry{
|
|
298
|
+
.{ .id = 11, .label = "first" },
|
|
299
|
+
.{ .id = 22, .label = "second", .status = .closed },
|
|
300
|
+
.{ .id = 33, .label = "third" },
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
// Optional none: the else branch renders, the trailing if disappears.
|
|
304
|
+
var model = EntriesModel{ .entries = &entries };
|
|
305
|
+
const plain_interpreted = try interpretEntries(arena, &model);
|
|
306
|
+
const plain_compiled = try compileEntries(arena, &model);
|
|
307
|
+
try expectSameTree(EntriesMsg, plain_interpreted, plain_compiled);
|
|
308
|
+
try expectSameTexts(plain_interpreted.root, plain_compiled.root);
|
|
309
|
+
try testing.expect(findText(plain_compiled.root, "plain") != null);
|
|
310
|
+
try testing.expect(findText(plain_compiled.root, "bannered") == null);
|
|
311
|
+
try testing.expect(findText(plain_compiled.root, "second #22") != null);
|
|
312
|
+
try testing.expect(findText(plain_compiled.root, "closed") != null);
|
|
313
|
+
try testing.expect(findText(plain_compiled.root, "open") != null);
|
|
314
|
+
|
|
315
|
+
// Optional some: both ifs flip, and the status bar interpolates the
|
|
316
|
+
// optional's payload.
|
|
317
|
+
model.banner = "hello";
|
|
318
|
+
const bannered_interpreted = try interpretEntries(arena, &model);
|
|
319
|
+
const bannered_compiled = try compileEntries(arena, &model);
|
|
320
|
+
try expectSameTree(EntriesMsg, bannered_interpreted, bannered_compiled);
|
|
321
|
+
try expectSameTexts(bannered_interpreted.root, bannered_compiled.root);
|
|
322
|
+
try testing.expect(findText(bannered_compiled.root, "bannered") != null);
|
|
323
|
+
try testing.expect(findText(bannered_compiled.root, "plain") == null);
|
|
324
|
+
try testing.expectEqualStrings("hello", fixture.findByKind(bannered_compiled.root, .status_bar).?.text);
|
|
325
|
+
|
|
326
|
+
// Message payloads built from loop items dispatch identically.
|
|
327
|
+
const open_button = fixture.findByKind(plain_compiled.root, .button).?;
|
|
328
|
+
try testing.expectEqual(
|
|
329
|
+
plain_interpreted.msgForPointer(open_button.id, .up).?,
|
|
330
|
+
plain_compiled.msgForPointer(open_button.id, .up).?,
|
|
331
|
+
);
|
|
332
|
+
try testing.expectEqual(@as(u32, 11), plain_compiled.msgForPointer(open_button.id, .up).?.open_entry);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
test "compiled global-key rows keep their ids across reorders" {
|
|
336
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
337
|
+
defer arena_state.deinit();
|
|
338
|
+
const arena = arena_state.allocator();
|
|
339
|
+
|
|
340
|
+
const forward = [_]Entry{
|
|
341
|
+
.{ .id = 11, .label = "first" },
|
|
342
|
+
.{ .id = 22, .label = "second" },
|
|
343
|
+
};
|
|
344
|
+
const reversed = [_]Entry{
|
|
345
|
+
.{ .id = 22, .label = "second" },
|
|
346
|
+
.{ .id = 11, .label = "first" },
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
var model = EntriesModel{ .entries = &forward };
|
|
350
|
+
const before = try compileEntries(arena, &model);
|
|
351
|
+
const first_before = findText(before.root, "first #11").?;
|
|
352
|
+
|
|
353
|
+
model.entries = &reversed;
|
|
354
|
+
const after = try compileEntries(arena, &model);
|
|
355
|
+
const first_after = findText(after.root, "first #11").?;
|
|
356
|
+
|
|
357
|
+
// global-key (declared in markup, resolved at comptime) pins identity
|
|
358
|
+
// independent of position — and the interpreter agrees.
|
|
359
|
+
try testing.expectEqual(first_before.id, first_after.id);
|
|
360
|
+
try expectSameTree(EntriesMsg, try interpretEntries(arena, &model), after);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// ------------------------------------------------ on-scroll parity
|
|
364
|
+
|
|
365
|
+
const scroll_feed_markup =
|
|
366
|
+
\\<scroll on-scroll="feed_scrolled" on-reach-end="refresh">
|
|
367
|
+
\\ <column gap="4">
|
|
368
|
+
\\ <for each="entries" as="e" key="id">
|
|
369
|
+
\\ <text>{e.label}</text>
|
|
370
|
+
\\ </for>
|
|
371
|
+
\\ </column>
|
|
372
|
+
\\</scroll>
|
|
373
|
+
;
|
|
374
|
+
|
|
375
|
+
const ScrollFeedCompiled = canvas.CompiledMarkupView(EntriesModel, EntriesMsg, scroll_feed_markup);
|
|
376
|
+
|
|
377
|
+
test "compiled on-scroll binds the ScrollState constructor identically to the interpreter" {
|
|
378
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
379
|
+
defer arena_state.deinit();
|
|
380
|
+
const arena = arena_state.allocator();
|
|
381
|
+
|
|
382
|
+
const entries = [_]Entry{.{ .id = 11, .label = "first" }};
|
|
383
|
+
const model = EntriesModel{ .entries = &entries };
|
|
384
|
+
|
|
385
|
+
var view = try markup_view.MarkupView(EntriesModel, EntriesMsg).init(arena, scroll_feed_markup);
|
|
386
|
+
var interpreter_ui = EntriesUi.init(arena);
|
|
387
|
+
const interpreted = try interpreter_ui.finalize(try view.build(&interpreter_ui, &model));
|
|
388
|
+
var compiled_ui = EntriesUi.init(arena);
|
|
389
|
+
const compiled = try compiled_ui.finalize(ScrollFeedCompiled.build(&compiled_ui, &model));
|
|
390
|
+
try expectSameTree(EntriesMsg, interpreted, compiled);
|
|
391
|
+
|
|
392
|
+
// Both engines dispatch the same typed scroll Msg for the container.
|
|
393
|
+
const feed = fixture.findByKind(compiled.root, .scroll_view).?;
|
|
394
|
+
const state = canvas.ScrollState{ .offset = 40, .viewport_extent = 80, .content_extent = 200 };
|
|
395
|
+
try testing.expectEqual(@as(f32, 40), compiled.msgForScroll(feed.id, state).?.feed_scrolled.offset);
|
|
396
|
+
try testing.expectEqual(
|
|
397
|
+
interpreted.msgForScroll(feed.id, state).?.feed_scrolled.offset,
|
|
398
|
+
compiled.msgForScroll(feed.id, state).?.feed_scrolled.offset,
|
|
399
|
+
);
|
|
400
|
+
|
|
401
|
+
// And the same approach-end Msg (`on-reach-end`, the infinite-scroll
|
|
402
|
+
// fetch signal) through both handler tables.
|
|
403
|
+
try testing.expectEqual(EntriesMsg.refresh, compiled.msgForReachEnd(feed.id).?);
|
|
404
|
+
try testing.expectEqual(interpreted.msgForReachEnd(feed.id).?, compiled.msgForReachEnd(feed.id).?);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// ------------------------------------------------ overscroll parity
|
|
408
|
+
|
|
409
|
+
const overscroll_feed_markup =
|
|
410
|
+
\\<scroll overscroll="rubber_band">
|
|
411
|
+
\\ <column gap="4">
|
|
412
|
+
\\ <for each="entries" as="e" key="id">
|
|
413
|
+
\\ <text>{e.label}</text>
|
|
414
|
+
\\ </for>
|
|
415
|
+
\\ </column>
|
|
416
|
+
\\</scroll>
|
|
417
|
+
;
|
|
418
|
+
|
|
419
|
+
const OverscrollFeedCompiled = canvas.CompiledMarkupView(EntriesModel, EntriesMsg, overscroll_feed_markup);
|
|
420
|
+
|
|
421
|
+
test "compiled overscroll stamps the region edge behavior identically to the interpreter" {
|
|
422
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
423
|
+
defer arena_state.deinit();
|
|
424
|
+
const arena = arena_state.allocator();
|
|
425
|
+
|
|
426
|
+
const entries = [_]Entry{.{ .id = 11, .label = "first" }};
|
|
427
|
+
const model = EntriesModel{ .entries = &entries };
|
|
428
|
+
|
|
429
|
+
var view = try markup_view.MarkupView(EntriesModel, EntriesMsg).init(arena, overscroll_feed_markup);
|
|
430
|
+
var interpreter_ui = EntriesUi.init(arena);
|
|
431
|
+
const interpreted = try interpreter_ui.finalize(try view.build(&interpreter_ui, &model));
|
|
432
|
+
var compiled_ui = EntriesUi.init(arena);
|
|
433
|
+
const compiled = try compiled_ui.finalize(OverscrollFeedCompiled.build(&compiled_ui, &model));
|
|
434
|
+
try expectSameTree(EntriesMsg, interpreted, compiled);
|
|
435
|
+
|
|
436
|
+
// Both engines stamp the per-region opt-in on the scroll widget.
|
|
437
|
+
const compiled_feed = fixture.findByKind(compiled.root, .scroll_view).?;
|
|
438
|
+
const interpreted_feed = fixture.findByKind(interpreted.root, .scroll_view).?;
|
|
439
|
+
try testing.expectEqual(canvas.WidgetOverscroll.rubber_band, compiled_feed.overscroll);
|
|
440
|
+
try testing.expectEqual(canvas.WidgetOverscroll.rubber_band, interpreted_feed.overscroll);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// ------------------------------------------- split layout-tween parity
|
|
444
|
+
|
|
445
|
+
const split_tween_markup =
|
|
446
|
+
\\<split value="0.3" resize-duration="180" resize-easing="spring" grow="1">
|
|
447
|
+
\\ <panel><text>sidebar</text></panel>
|
|
448
|
+
\\ <panel><text>content</text></panel>
|
|
449
|
+
\\</split>
|
|
450
|
+
;
|
|
451
|
+
|
|
452
|
+
const SplitTweenCompiled = canvas.CompiledMarkupView(EntriesModel, EntriesMsg, split_tween_markup);
|
|
453
|
+
|
|
454
|
+
test "compiled split tween pair lowers into the layout-tween declaration identically to the interpreter" {
|
|
455
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
456
|
+
defer arena_state.deinit();
|
|
457
|
+
const arena = arena_state.allocator();
|
|
458
|
+
|
|
459
|
+
const entries = [_]Entry{.{ .id = 11, .label = "first" }};
|
|
460
|
+
const model = EntriesModel{ .entries = &entries };
|
|
461
|
+
|
|
462
|
+
var view = try markup_view.MarkupView(EntriesModel, EntriesMsg).init(arena, split_tween_markup);
|
|
463
|
+
var interpreter_ui = EntriesUi.init(arena);
|
|
464
|
+
const interpreted = try interpreter_ui.finalize(try view.build(&interpreter_ui, &model));
|
|
465
|
+
var compiled_ui = EntriesUi.init(arena);
|
|
466
|
+
const compiled = try compiled_ui.finalize(SplitTweenCompiled.build(&compiled_ui, &model));
|
|
467
|
+
try expectSameTree(EntriesMsg, interpreted, compiled);
|
|
468
|
+
|
|
469
|
+
// Both engines stamp the same declaration the runtime lowers into a
|
|
470
|
+
// layout tween: value is the target, duration arms it, easing shapes
|
|
471
|
+
// it. Bare splits keep the zero (snap) defaults, so existing
|
|
472
|
+
// documents lower byte-identically.
|
|
473
|
+
const compiled_split = fixture.findByKind(compiled.root, .split).?;
|
|
474
|
+
const interpreted_split = fixture.findByKind(interpreted.root, .split).?;
|
|
475
|
+
try testing.expectEqual(@as(u32, 180), compiled_split.resize_duration_ms);
|
|
476
|
+
try testing.expectEqual(@as(u32, 180), interpreted_split.resize_duration_ms);
|
|
477
|
+
try testing.expectEqual(canvas.Easing.spring, compiled_split.resize_easing);
|
|
478
|
+
try testing.expectEqual(canvas.Easing.spring, interpreted_split.resize_easing);
|
|
479
|
+
try testing.expectEqual(interpreted_split.value, compiled_split.value);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// --------------------- multi-child for bodies and the for-empty else
|
|
483
|
+
|
|
484
|
+
const multi_entries_markup =
|
|
485
|
+
\\<column gap="4">
|
|
486
|
+
\\ <for each="entries" as="e" key="id">
|
|
487
|
+
\\ <if test="{e.status == closed_status}">
|
|
488
|
+
\\ <badge>closed</badge>
|
|
489
|
+
\\ </if>
|
|
490
|
+
\\ <else>
|
|
491
|
+
\\ <badge>open</badge>
|
|
492
|
+
\\ </else>
|
|
493
|
+
\\ <text>{e.label}</text>
|
|
494
|
+
\\ <text>#{e.id}</text>
|
|
495
|
+
\\ </for>
|
|
496
|
+
\\ <else>
|
|
497
|
+
\\ <text>Nothing yet</text>
|
|
498
|
+
\\ </else>
|
|
499
|
+
\\</column>
|
|
500
|
+
;
|
|
501
|
+
|
|
502
|
+
const MultiEntriesCompiled = canvas.CompiledMarkupView(EntriesModel, EntriesMsg, multi_entries_markup);
|
|
503
|
+
|
|
504
|
+
fn interpretMultiEntries(arena: std.mem.Allocator, model: *const EntriesModel) !EntriesUi.Tree {
|
|
505
|
+
var view = try EntriesInterpreter.init(arena, multi_entries_markup);
|
|
506
|
+
var ui = EntriesUi.init(arena);
|
|
507
|
+
return ui.finalize(try view.build(&ui, model));
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
fn compileMultiEntries(arena: std.mem.Allocator, model: *const EntriesModel) !EntriesUi.Tree {
|
|
511
|
+
var ui = EntriesUi.init(arena);
|
|
512
|
+
return ui.finalize(MultiEntriesCompiled.build(&ui, model));
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
test "compiled multi-child for bodies and the for-empty else match the interpreter" {
|
|
516
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
517
|
+
defer arena_state.deinit();
|
|
518
|
+
const arena = arena_state.allocator();
|
|
519
|
+
|
|
520
|
+
const entries = [_]Entry{
|
|
521
|
+
.{ .id = 11, .label = "first" },
|
|
522
|
+
.{ .id = 22, .label = "second", .status = .closed },
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
// Non-empty: each item emits an if/else badge arm plus two same-kind
|
|
526
|
+
// texts as siblings (no wrapper node), and the trailing else stays out.
|
|
527
|
+
var model = EntriesModel{ .entries = &entries };
|
|
528
|
+
const interpreted = try interpretMultiEntries(arena, &model);
|
|
529
|
+
const compiled = try compileMultiEntries(arena, &model);
|
|
530
|
+
try expectSameTree(EntriesMsg, interpreted, compiled);
|
|
531
|
+
try expectSameTexts(interpreted.root, compiled.root);
|
|
532
|
+
try testing.expect(findText(compiled.root, "Nothing yet") == null);
|
|
533
|
+
try testing.expect(findText(compiled.root, "first") != null);
|
|
534
|
+
try testing.expect(findText(compiled.root, "#22") != null);
|
|
535
|
+
try testing.expect(findText(compiled.root, "closed") != null);
|
|
536
|
+
try testing.expect(findText(compiled.root, "open") != null);
|
|
537
|
+
|
|
538
|
+
// Same-kind siblings from one keyed item stay distinct: the item key
|
|
539
|
+
// slot-suffix keeps every structural id in the tree unique.
|
|
540
|
+
var ids: std.ArrayListUnmanaged(canvas.ObjectId) = .empty;
|
|
541
|
+
defer ids.deinit(testing.allocator);
|
|
542
|
+
try fixture.collectIds(compiled.root, &ids, testing.allocator);
|
|
543
|
+
for (ids.items, 0..) |id, index| {
|
|
544
|
+
for (ids.items[index + 1 ..]) |other| try testing.expect(id != other);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// Keyed identity survives reorders for every node an item emits.
|
|
548
|
+
const label_before = findText(compiled.root, "first").?;
|
|
549
|
+
const number_before = findText(compiled.root, "#11").?;
|
|
550
|
+
const reversed = [_]Entry{
|
|
551
|
+
.{ .id = 22, .label = "second", .status = .closed },
|
|
552
|
+
.{ .id = 11, .label = "first" },
|
|
553
|
+
};
|
|
554
|
+
model.entries = &reversed;
|
|
555
|
+
const reordered = try compileMultiEntries(arena, &model);
|
|
556
|
+
try expectSameTree(EntriesMsg, try interpretMultiEntries(arena, &model), reordered);
|
|
557
|
+
try testing.expectEqual(label_before.id, findText(reordered.root, "first").?.id);
|
|
558
|
+
try testing.expectEqual(number_before.id, findText(reordered.root, "#11").?.id);
|
|
559
|
+
|
|
560
|
+
// Empty: the trailing else renders the empty state in both engines.
|
|
561
|
+
model.entries = &.{};
|
|
562
|
+
const empty_interpreted = try interpretMultiEntries(arena, &model);
|
|
563
|
+
const empty_compiled = try compileMultiEntries(arena, &model);
|
|
564
|
+
try expectSameTree(EntriesMsg, empty_interpreted, empty_compiled);
|
|
565
|
+
try expectSameTexts(empty_interpreted.root, empty_compiled.root);
|
|
566
|
+
try testing.expect(findText(empty_compiled.root, "Nothing yet") != null);
|
|
567
|
+
try testing.expect(findText(empty_interpreted.root, "Nothing yet") != null);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
test "the compiled path accepts every element the validator knows" {
|
|
571
|
+
for (canvas.ui_markup.known_element_names) |name| {
|
|
572
|
+
try testing.expect(markup_view.elementKind(name) != null);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
const icon_markup_source =
|
|
577
|
+
"<row gap=\"8\">\n" ++
|
|
578
|
+
" <icon name=\"search\" width=\"16\" height=\"16\" foreground=\"accent\" />\n" ++
|
|
579
|
+
" <text>Search</text>\n" ++
|
|
580
|
+
"</row>";
|
|
581
|
+
|
|
582
|
+
test "compiled icons match the interpreter and carry the validated name" {
|
|
583
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
584
|
+
defer arena_state.deinit();
|
|
585
|
+
const arena = arena_state.allocator();
|
|
586
|
+
const model = fixture.Model{};
|
|
587
|
+
|
|
588
|
+
var interpreter_view = try InboxInterpreter.init(arena, icon_markup_source);
|
|
589
|
+
var interpreter_ui = InboxUi.init(arena);
|
|
590
|
+
const interpreted = try interpreter_ui.finalize(try interpreter_view.build(&interpreter_ui, &model));
|
|
591
|
+
|
|
592
|
+
const Compiled = canvas.CompiledMarkupView(fixture.Model, fixture.Msg, icon_markup_source);
|
|
593
|
+
var compiled_ui = InboxUi.init(arena);
|
|
594
|
+
const compiled = try compiled_ui.finalize(Compiled.build(&compiled_ui, &model));
|
|
595
|
+
|
|
596
|
+
try expectSameTree(fixture.Msg, interpreted, compiled);
|
|
597
|
+
const icon = compiled.root.children[0];
|
|
598
|
+
try testing.expectEqual(canvas.WidgetKind.icon, icon.kind);
|
|
599
|
+
try testing.expectEqualStrings("search", icon.text);
|
|
600
|
+
try testing.expectEqual(canvas.WidgetKind.icon, interpreted.root.children[0].kind);
|
|
601
|
+
try testing.expectEqualStrings("search", interpreted.root.children[0].text);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
const button_icon_markup_source =
|
|
605
|
+
"<row gap=\"8\">\n" ++
|
|
606
|
+
" <button icon=\"save\" on-press=\"add\">Save</button>\n" ++
|
|
607
|
+
" <button icon=\"refresh-cw\" on-press=\"add\" label=\"Refresh\"></button>\n" ++
|
|
608
|
+
" <toggle-button icon=\"arrow-up\" on-toggle=\"add\">Newest</toggle-button>\n" ++
|
|
609
|
+
" <list-item icon=\"folder\" on-press=\"add\">Projects</list-item>\n" ++
|
|
610
|
+
" <menu-item icon=\"trash\" on-press=\"add\">Delete</menu-item>\n" ++
|
|
611
|
+
"</row>";
|
|
612
|
+
|
|
613
|
+
test "compiled button icons match the interpreter and carry the validated name" {
|
|
614
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
615
|
+
defer arena_state.deinit();
|
|
616
|
+
const arena = arena_state.allocator();
|
|
617
|
+
const model = fixture.Model{};
|
|
618
|
+
|
|
619
|
+
var interpreter_view = try InboxInterpreter.init(arena, button_icon_markup_source);
|
|
620
|
+
var interpreter_ui = InboxUi.init(arena);
|
|
621
|
+
const interpreted = try interpreter_ui.finalize(try interpreter_view.build(&interpreter_ui, &model));
|
|
622
|
+
|
|
623
|
+
const Compiled = canvas.CompiledMarkupView(fixture.Model, fixture.Msg, button_icon_markup_source);
|
|
624
|
+
var compiled_ui = InboxUi.init(arena);
|
|
625
|
+
const compiled = try compiled_ui.finalize(Compiled.build(&compiled_ui, &model));
|
|
626
|
+
|
|
627
|
+
try expectSameTree(fixture.Msg, interpreted, compiled);
|
|
628
|
+
for ([_]InboxUi.Tree{ interpreted, compiled }) |tree| {
|
|
629
|
+
const labeled = tree.root.children[0];
|
|
630
|
+
try testing.expectEqual(canvas.WidgetKind.button, labeled.kind);
|
|
631
|
+
try testing.expectEqualStrings("save", labeled.icon);
|
|
632
|
+
try testing.expectEqualStrings("Save", labeled.text);
|
|
633
|
+
// Icon + label are ONE hit target: the icon has no child node and
|
|
634
|
+
// the button's own press handler dispatches.
|
|
635
|
+
try testing.expectEqual(@as(usize, 0), labeled.children.len);
|
|
636
|
+
try testing.expect(tree.msgFor(labeled.id, .press) != null);
|
|
637
|
+
const icon_only = tree.root.children[1];
|
|
638
|
+
try testing.expectEqualStrings("refresh-cw", icon_only.icon);
|
|
639
|
+
try testing.expectEqualStrings("", icon_only.text);
|
|
640
|
+
try testing.expectEqualStrings("Refresh", icon_only.semantics.label);
|
|
641
|
+
// The wider labeled interactive set compiles to the same
|
|
642
|
+
// widgets in both engines.
|
|
643
|
+
const chip = tree.root.children[2];
|
|
644
|
+
try testing.expectEqual(canvas.WidgetKind.toggle_button, chip.kind);
|
|
645
|
+
try testing.expectEqualStrings("arrow-up", chip.icon);
|
|
646
|
+
const row_item = tree.root.children[3];
|
|
647
|
+
try testing.expectEqual(canvas.WidgetKind.list_item, row_item.kind);
|
|
648
|
+
try testing.expectEqualStrings("folder", row_item.icon);
|
|
649
|
+
const menu_row = tree.root.children[4];
|
|
650
|
+
try testing.expectEqual(canvas.WidgetKind.menu_item, menu_row.kind);
|
|
651
|
+
try testing.expectEqualStrings("trash", menu_row.icon);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
const open_icon_markup_source =
|
|
656
|
+
"<row gap=\"8\">\n" ++
|
|
657
|
+
" <icon name=\"app:wave\" width=\"16\" height=\"16\" />\n" ++
|
|
658
|
+
" <icon name=\"{filter}\" width=\"16\" height=\"16\" />\n" ++
|
|
659
|
+
" <button icon=\"app:wave\" on-press=\"add\">Wave</button>\n" ++
|
|
660
|
+
" <button icon=\"{filter}\" on-press=\"add\">Filter</button>\n" ++
|
|
661
|
+
"</row>";
|
|
662
|
+
|
|
663
|
+
test "compiled app: and bound icons match the interpreter and ride the explicit icon channel" {
|
|
664
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
665
|
+
defer arena_state.deinit();
|
|
666
|
+
const arena = arena_state.allocator();
|
|
667
|
+
const model = fixture.Model{};
|
|
668
|
+
|
|
669
|
+
var interpreter_view = try InboxInterpreter.init(arena, open_icon_markup_source);
|
|
670
|
+
var interpreter_ui = InboxUi.init(arena);
|
|
671
|
+
const interpreted = try interpreter_ui.finalize(try interpreter_view.build(&interpreter_ui, &model));
|
|
672
|
+
|
|
673
|
+
const Compiled = canvas.CompiledMarkupView(fixture.Model, fixture.Msg, open_icon_markup_source);
|
|
674
|
+
var compiled_ui = InboxUi.init(arena);
|
|
675
|
+
const compiled = try compiled_ui.finalize(Compiled.build(&compiled_ui, &model));
|
|
676
|
+
|
|
677
|
+
try expectSameTree(fixture.Msg, interpreted, compiled);
|
|
678
|
+
for ([_]InboxUi.Tree{ interpreted, compiled }) |tree| {
|
|
679
|
+
// Both open forms carry the name on `Widget.icon` (the explicit
|
|
680
|
+
// channel the draw path resolves, with the missing-icon fallback
|
|
681
|
+
// for names that resolve nowhere): the app: reference verbatim,
|
|
682
|
+
// the binding as whatever the model produced.
|
|
683
|
+
try testing.expectEqualStrings("app:wave", tree.root.children[0].icon);
|
|
684
|
+
try testing.expectEqualStrings("all", tree.root.children[1].icon);
|
|
685
|
+
try testing.expectEqualStrings("app:wave", tree.root.children[2].icon);
|
|
686
|
+
try testing.expectEqualStrings("all", tree.root.children[3].icon);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
const list_row_markup_source =
|
|
691
|
+
"<column>\n" ++
|
|
692
|
+
" <list-item on-press=\"add\" label=\"Groceries row\" padding=\"8\" gap=\"8\">\n" ++
|
|
693
|
+
" <text grow=\"1\">Groceries</text>\n" ++
|
|
694
|
+
" <badge variant=\"secondary\">3</badge>\n" ++
|
|
695
|
+
" </list-item>\n" ++
|
|
696
|
+
" <list-item on-press=\"add\">Piranesi</list-item>\n" ++
|
|
697
|
+
"</column>";
|
|
698
|
+
|
|
699
|
+
test "compiled list-row composites match the interpreter" {
|
|
700
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
701
|
+
defer arena_state.deinit();
|
|
702
|
+
const arena = arena_state.allocator();
|
|
703
|
+
const model = fixture.Model{};
|
|
704
|
+
|
|
705
|
+
var interpreter_view = try InboxInterpreter.init(arena, list_row_markup_source);
|
|
706
|
+
var interpreter_ui = InboxUi.init(arena);
|
|
707
|
+
const interpreted = try interpreter_ui.finalize(try interpreter_view.build(&interpreter_ui, &model));
|
|
708
|
+
|
|
709
|
+
const Compiled = canvas.CompiledMarkupView(fixture.Model, fixture.Msg, list_row_markup_source);
|
|
710
|
+
var compiled_ui = InboxUi.init(arena);
|
|
711
|
+
const compiled = try compiled_ui.finalize(Compiled.build(&compiled_ui, &model));
|
|
712
|
+
|
|
713
|
+
try expectSameTree(fixture.Msg, interpreted, compiled);
|
|
714
|
+
for ([_]InboxUi.Tree{ interpreted, compiled }) |tree| {
|
|
715
|
+
// Element children in place of the text run: the row keeps the
|
|
716
|
+
// flat list-item kind and flows the children inside it.
|
|
717
|
+
const composite = tree.root.children[0];
|
|
718
|
+
try testing.expectEqual(canvas.WidgetKind.list_item, composite.kind);
|
|
719
|
+
try testing.expectEqual(@as(usize, 2), composite.children.len);
|
|
720
|
+
try testing.expectEqual(@as(usize, 0), composite.text.len);
|
|
721
|
+
try testing.expectEqualStrings("Groceries row", composite.semantics.label);
|
|
722
|
+
try testing.expect(tree.msgFor(composite.id, .press) != null);
|
|
723
|
+
// The classic text leaf keeps working next to it.
|
|
724
|
+
const leaf = tree.root.children[1];
|
|
725
|
+
try testing.expectEqual(canvas.WidgetKind.list_item, leaf.kind);
|
|
726
|
+
try testing.expectEqualStrings("Piranesi", leaf.text);
|
|
727
|
+
try testing.expectEqual(@as(usize, 0), leaf.children.len);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
// --------------------------------------------- component catalog parity
|
|
732
|
+
|
|
733
|
+
const CatalogUi = fixture.CatalogUi;
|
|
734
|
+
const CatalogInterpreter = markup_view.MarkupView(fixture.CatalogModel, fixture.CatalogMsg);
|
|
735
|
+
const CatalogCompiled = canvas.CompiledMarkupView(fixture.CatalogModel, fixture.CatalogMsg, fixture.catalog_markup_source);
|
|
736
|
+
|
|
737
|
+
fn interpretCatalog(arena: std.mem.Allocator, model: *const fixture.CatalogModel) !CatalogUi.Tree {
|
|
738
|
+
var view = try CatalogInterpreter.init(arena, fixture.catalog_markup_source);
|
|
739
|
+
var ui = CatalogUi.init(arena);
|
|
740
|
+
return ui.finalize(try view.build(&ui, model));
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
fn compileCatalog(arena: std.mem.Allocator, model: *const fixture.CatalogModel) !CatalogUi.Tree {
|
|
744
|
+
var ui = CatalogUi.init(arena);
|
|
745
|
+
return ui.finalize(CatalogCompiled.build(&ui, model));
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
test "compiled catalog elements match the interpreter and the hand-written view" {
|
|
749
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
750
|
+
defer arena_state.deinit();
|
|
751
|
+
const arena = arena_state.allocator();
|
|
752
|
+
|
|
753
|
+
const model = fixture.catalogTestModel();
|
|
754
|
+
|
|
755
|
+
const interpreted = try interpretCatalog(arena, &model);
|
|
756
|
+
const compiled = try compileCatalog(arena, &model);
|
|
757
|
+
var hand_ui = CatalogUi.init(arena);
|
|
758
|
+
const hand = try hand_ui.finalize(fixture.handCatalogView(&hand_ui, &model));
|
|
759
|
+
|
|
760
|
+
// All three engines agree on every new element: ids, handlers, texts.
|
|
761
|
+
try expectSameTree(fixture.CatalogMsg, hand, interpreted);
|
|
762
|
+
try expectSameTree(fixture.CatalogMsg, hand, compiled);
|
|
763
|
+
try expectSameTexts(interpreted.root, compiled.root);
|
|
764
|
+
|
|
765
|
+
// Dispatch parity across the new control kinds.
|
|
766
|
+
const select = fixture.findByKind(compiled.root, .select).?;
|
|
767
|
+
try testing.expectEqual(
|
|
768
|
+
interpreted.msgForPointer(select.id, .up).?,
|
|
769
|
+
compiled.msgForPointer(select.id, .up).?,
|
|
770
|
+
);
|
|
771
|
+
const switch_control = fixture.findByKind(compiled.root, .switch_control).?;
|
|
772
|
+
try testing.expectEqual(fixture.CatalogMsg.toggle_bold, compiled.msgForPointer(switch_control.id, .up).?);
|
|
773
|
+
const pears_cell = fixture.findByText(compiled.root, .data_cell, "Pears").?;
|
|
774
|
+
try testing.expectEqual(
|
|
775
|
+
interpreted.msgForPointer(pears_cell.id, .up).?,
|
|
776
|
+
compiled.msgForPointer(pears_cell.id, .up).?,
|
|
777
|
+
);
|
|
778
|
+
try testing.expectEqual(@as(u32, 2), compiled.msgForPointer(pears_cell.id, .up).?.pick_row);
|
|
779
|
+
|
|
780
|
+
// Text entry parity on the input element, including on-input.
|
|
781
|
+
const input = fixture.findByKind(compiled.root, .input).?;
|
|
782
|
+
const typed = canvas.WidgetKeyboardEvent{ .phase = .text_input, .text = "q" };
|
|
783
|
+
try testing.expectEqualStrings("q", compiled.msgForKeyboard(input.id, typed).?.query_edit.insert_text);
|
|
784
|
+
const submit = canvas.WidgetKeyboardEvent{ .phase = .key_down, .key = "enter" };
|
|
785
|
+
try testing.expectEqual(
|
|
786
|
+
interpreted.msgForKeyboard(input.id, submit).?,
|
|
787
|
+
compiled.msgForKeyboard(input.id, submit).?,
|
|
788
|
+
);
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
test "compiled catalog stays in parity when conditional surfaces flip" {
|
|
792
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
793
|
+
defer arena_state.deinit();
|
|
794
|
+
const arena = arena_state.allocator();
|
|
795
|
+
|
|
796
|
+
var model = fixture.catalogTestModel();
|
|
797
|
+
model.loading = false;
|
|
798
|
+
model.dialog_open = true;
|
|
799
|
+
model.tab = 1;
|
|
800
|
+
model.bold = true;
|
|
801
|
+
model.page = 3;
|
|
802
|
+
|
|
803
|
+
const interpreted = try interpretCatalog(arena, &model);
|
|
804
|
+
const compiled = try compileCatalog(arena, &model);
|
|
805
|
+
try expectSameTree(fixture.CatalogMsg, interpreted, compiled);
|
|
806
|
+
try expectSameTexts(interpreted.root, compiled.root);
|
|
807
|
+
|
|
808
|
+
// The dialog branch renders with its title and dispatching child.
|
|
809
|
+
const dialog = fixture.findByKind(compiled.root, .dialog).?;
|
|
810
|
+
try testing.expectEqualStrings("Confirm", dialog.text);
|
|
811
|
+
try testing.expect(fixture.findByKind(compiled.root, .spinner) == null);
|
|
812
|
+
const yes_button = fixture.findByText(compiled.root, .button, "Yes").?;
|
|
813
|
+
try testing.expectEqual(fixture.CatalogMsg.submit_query, compiled.msgForPointer(yes_button.id, .up).?);
|
|
814
|
+
try testing.expectEqual(@as(u32, 2), compiled.msgForPointer(fixture.findByText(compiled.root, .button, "Prev").?.id, .up).?.set_page);
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
// ---------------------------------------------- arena-scalar binding parity
|
|
818
|
+
|
|
819
|
+
const ExpensesUi = fixture.ExpensesUi;
|
|
820
|
+
const ExpensesInterpreter = markup_view.MarkupView(fixture.ExpensesModel, fixture.ExpensesMsg);
|
|
821
|
+
const ExpensesCompiled = canvas.CompiledMarkupView(fixture.ExpensesModel, fixture.ExpensesMsg, fixture.expenses_markup_source);
|
|
822
|
+
|
|
823
|
+
fn interpretExpenses(arena: std.mem.Allocator, model: *const fixture.ExpensesModel) !ExpensesUi.Tree {
|
|
824
|
+
var view = try ExpensesInterpreter.init(arena, fixture.expenses_markup_source);
|
|
825
|
+
var ui = ExpensesUi.init(arena);
|
|
826
|
+
return ui.finalize(try view.build(&ui, model));
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
fn compileExpenses(arena: std.mem.Allocator, model: *const fixture.ExpensesModel) !ExpensesUi.Tree {
|
|
830
|
+
var ui = ExpensesUi.init(arena);
|
|
831
|
+
return ui.finalize(ExpensesCompiled.build(&ui, model));
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
test "compiled arena-scalar bindings match the interpreter and the hand-written view" {
|
|
835
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
836
|
+
defer arena_state.deinit();
|
|
837
|
+
const arena = arena_state.allocator();
|
|
838
|
+
|
|
839
|
+
const model = fixture.expensesTestModel();
|
|
840
|
+
|
|
841
|
+
const interpreted = try interpretExpenses(arena, &model);
|
|
842
|
+
const compiled = try compileExpenses(arena, &model);
|
|
843
|
+
var hand_ui = ExpensesUi.init(arena);
|
|
844
|
+
const hand = try hand_ui.finalize(fixture.handExpensesView(&hand_ui, &model));
|
|
845
|
+
|
|
846
|
+
// All three engines agree: the arena scalar flows through text
|
|
847
|
+
// content, interpolation, an attribute value (label), a message
|
|
848
|
+
// payload, an if test, and an item-level arena method.
|
|
849
|
+
try expectSameTree(fixture.ExpensesMsg, hand, interpreted);
|
|
850
|
+
try expectSameTree(fixture.ExpensesMsg, hand, compiled);
|
|
851
|
+
try expectSameTexts(interpreted.root, compiled.root);
|
|
852
|
+
|
|
853
|
+
try testing.expectEqualStrings("2 expenses · $12.94", fixture.findByKind(compiled.root, .status_bar).?.text);
|
|
854
|
+
const labeled = fixture.findByText(compiled.root, .text, "all: 2 expenses · $12.94").?;
|
|
855
|
+
try testing.expectEqualStrings("2 expenses · $12.94", labeled.semantics.label);
|
|
856
|
+
try testing.expect(fixture.findByText(compiled.root, .badge, "summarized") != null);
|
|
857
|
+
|
|
858
|
+
// Payload dispatch parity: the arena string rides the typed message.
|
|
859
|
+
const pick_button = fixture.findByKind(compiled.root, .button).?;
|
|
860
|
+
try testing.expectEqualStrings("$12.34", compiled.msgForPointer(pick_button.id, .up).?.pick);
|
|
861
|
+
try testing.expectEqualStrings(
|
|
862
|
+
interpreted.msgForPointer(pick_button.id, .up).?.pick,
|
|
863
|
+
compiled.msgForPointer(pick_button.id, .up).?.pick,
|
|
864
|
+
);
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
test "compiled string bindings pass to templates as value args" {
|
|
868
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
869
|
+
defer arena_state.deinit();
|
|
870
|
+
const arena = arena_state.allocator();
|
|
871
|
+
|
|
872
|
+
const model = fixture.expensesTestModel();
|
|
873
|
+
const source =
|
|
874
|
+
"<template name=\"line\" args=\"title\"><text>{title}</text></template>\n" ++
|
|
875
|
+
"<column>\n" ++
|
|
876
|
+
" <use template=\"line\" title=\"{filter}\" />\n" ++
|
|
877
|
+
" <use template=\"line\" title=\"{summary}\" />\n" ++
|
|
878
|
+
"</column>";
|
|
879
|
+
const Compiled = canvas.CompiledMarkupView(fixture.ExpensesModel, fixture.ExpensesMsg, source);
|
|
880
|
+
|
|
881
|
+
var compiled_ui = ExpensesUi.init(arena);
|
|
882
|
+
const compiled = try compiled_ui.finalize(Compiled.build(&compiled_ui, &model));
|
|
883
|
+
|
|
884
|
+
var view = try ExpensesInterpreter.init(arena, source);
|
|
885
|
+
var interpreted_ui = ExpensesUi.init(arena);
|
|
886
|
+
const interpreted = try interpreted_ui.finalize(try view.build(&interpreted_ui, &model));
|
|
887
|
+
|
|
888
|
+
try expectSameTree(fixture.ExpensesMsg, interpreted, compiled);
|
|
889
|
+
try expectSameTexts(interpreted.root, compiled.root);
|
|
890
|
+
try testing.expect(findText(compiled.root, "all") != null);
|
|
891
|
+
try testing.expect(findText(compiled.root, "2 expenses · $12.94") != null);
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
// -------------------------------------------------- markdown element parity
|
|
895
|
+
|
|
896
|
+
const DocUi = fixture.DocUi;
|
|
897
|
+
const DocInterpreter = markup_view.MarkupView(fixture.DocModel, fixture.DocMsg);
|
|
898
|
+
const DocCompiled = canvas.CompiledMarkupView(fixture.DocModel, fixture.DocMsg, fixture.doc_markup_source);
|
|
899
|
+
|
|
900
|
+
fn interpretDoc(arena: std.mem.Allocator, model: *const fixture.DocModel) !DocUi.Tree {
|
|
901
|
+
var view = try DocInterpreter.init(arena, fixture.doc_markup_source);
|
|
902
|
+
var ui = DocUi.init(arena);
|
|
903
|
+
return ui.finalize(try view.build(&ui, model));
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
fn compileDoc(arena: std.mem.Allocator, model: *const fixture.DocModel) !DocUi.Tree {
|
|
907
|
+
var ui = DocUi.init(arena);
|
|
908
|
+
return ui.finalize(DocCompiled.build(&ui, model));
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
test "compiled markdown element matches the interpreter and the hand-written Md.view" {
|
|
912
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
913
|
+
defer arena_state.deinit();
|
|
914
|
+
const arena = arena_state.allocator();
|
|
915
|
+
|
|
916
|
+
var model = fixture.DocModel{};
|
|
917
|
+
|
|
918
|
+
const interpreted = try interpretDoc(arena, &model);
|
|
919
|
+
const compiled = try compileDoc(arena, &model);
|
|
920
|
+
var hand_ui = DocUi.init(arena);
|
|
921
|
+
const hand = try hand_ui.finalize(fixture.handDocView(&hand_ui, &model));
|
|
922
|
+
|
|
923
|
+
try expectSameTree(fixture.DocMsg, hand, interpreted);
|
|
924
|
+
try expectSameTree(fixture.DocMsg, hand, compiled);
|
|
925
|
+
try expectSameTexts(interpreted.root, compiled.root);
|
|
926
|
+
|
|
927
|
+
// Link dispatch parity, including the payload URL.
|
|
928
|
+
const link = fixture.findByRole(compiled.root, .link).?;
|
|
929
|
+
try testing.expectEqualStrings("https://example.com/guide", compiled.msgForPointer(link.id, .up).?.open_url);
|
|
930
|
+
try testing.expectEqualStrings(
|
|
931
|
+
interpreted.msgForPointer(link.id, .up).?.open_url,
|
|
932
|
+
compiled.msgForPointer(link.id, .up).?.open_url,
|
|
933
|
+
);
|
|
934
|
+
|
|
935
|
+
// Autolink parity: issue refs through the issue-link-base binding and
|
|
936
|
+
// bare URLs resolve to the same targets in both engines.
|
|
937
|
+
try testing.expectEqualStrings("ghissue://12", fixture.findSpanLink(compiled.root, "#12").?);
|
|
938
|
+
try testing.expectEqualStrings(
|
|
939
|
+
fixture.findSpanLink(interpreted.root, "#12").?,
|
|
940
|
+
fixture.findSpanLink(compiled.root, "#12").?,
|
|
941
|
+
);
|
|
942
|
+
try testing.expectEqualStrings(
|
|
943
|
+
fixture.findSpanLink(interpreted.root, "https://status.example.com").?,
|
|
944
|
+
fixture.findSpanLink(compiled.root, "https://status.example.com").?,
|
|
945
|
+
);
|
|
946
|
+
|
|
947
|
+
// Details dispatch parity: the summary press carries the block index.
|
|
948
|
+
const summary_item = fixture.findByKind(compiled.root, .list_item).?;
|
|
949
|
+
try testing.expectEqual(@as(usize, 0), compiled.msgForPointer(summary_item.id, .up).?.toggle_details);
|
|
950
|
+
try testing.expect(findText(compiled.root, "Enable for 5% of traffic.") == null);
|
|
951
|
+
|
|
952
|
+
// Expanding through the caller-owned flag keeps the engines in step.
|
|
953
|
+
model.details_expanded[0] = true;
|
|
954
|
+
const expanded_interpreted = try interpretDoc(arena, &model);
|
|
955
|
+
const expanded_compiled = try compileDoc(arena, &model);
|
|
956
|
+
try expectSameTree(fixture.DocMsg, expanded_interpreted, expanded_compiled);
|
|
957
|
+
try expectSameTexts(expanded_interpreted.root, expanded_compiled.root);
|
|
958
|
+
try testing.expect(findText(expanded_compiled.root, "Enable for 5% of traffic.") != null);
|
|
959
|
+
|
|
960
|
+
// The summary keeps its id across the expand (keyed by details index).
|
|
961
|
+
try testing.expectEqual(summary_item.id, fixture.findByKind(expanded_compiled.root, .list_item).?.id);
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
// ------------------------------------------- template/use + style parity
|
|
965
|
+
|
|
966
|
+
fn expectSameStyles(expected: canvas.Widget, actual: canvas.Widget) !void {
|
|
967
|
+
try testing.expect(std.meta.eql(expected.style, actual.style));
|
|
968
|
+
try testing.expectEqual(expected.children.len, actual.children.len);
|
|
969
|
+
for (expected.children, actual.children) |expected_child, actual_child| {
|
|
970
|
+
try expectSameStyles(expected_child, actual_child);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
const TemplateUi = fixture.TemplateUi;
|
|
975
|
+
const TemplateInterpreter = markup_view.MarkupView(fixture.TemplateModel, fixture.TemplateMsg);
|
|
976
|
+
const TemplateCompiled = canvas.CompiledMarkupView(fixture.TemplateModel, fixture.TemplateMsg, fixture.template_markup_source);
|
|
977
|
+
|
|
978
|
+
fn interpretTemplates(arena: std.mem.Allocator, model: *const fixture.TemplateModel, tokens: canvas.DesignTokens) !TemplateUi.Tree {
|
|
979
|
+
var view = try TemplateInterpreter.init(arena, fixture.template_markup_source);
|
|
980
|
+
var ui = TemplateUi.init(arena);
|
|
981
|
+
return ui.finalizeWithTokens(try view.build(&ui, model), tokens);
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
fn compileTemplates(arena: std.mem.Allocator, model: *const fixture.TemplateModel, tokens: canvas.DesignTokens) !TemplateUi.Tree {
|
|
985
|
+
var ui = TemplateUi.init(arena);
|
|
986
|
+
return ui.finalizeWithTokens(TemplateCompiled.build(&ui, model), tokens);
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
test "compiled templates with slice and value args match the interpreter and the hand-written view" {
|
|
990
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
991
|
+
defer arena_state.deinit();
|
|
992
|
+
const arena = arena_state.allocator();
|
|
993
|
+
|
|
994
|
+
const model = fixture.templateTestModel();
|
|
995
|
+
const tokens = canvas.DesignTokens{};
|
|
996
|
+
|
|
997
|
+
const interpreted = try interpretTemplates(arena, &model, tokens);
|
|
998
|
+
const compiled = try compileTemplates(arena, &model, tokens);
|
|
999
|
+
var hand_ui = TemplateUi.init(arena);
|
|
1000
|
+
const hand = try hand_ui.finalizeWithTokens(fixture.handTemplateView(&hand_ui, &model), tokens);
|
|
1001
|
+
|
|
1002
|
+
// All three engines agree: ids, handlers, texts, and resolved styles.
|
|
1003
|
+
// The fixture covers a value arg (title), a slice arg iterated by a
|
|
1004
|
+
// for inside the template, a nested use whose arg binds a loop item
|
|
1005
|
+
// field, and style token attributes.
|
|
1006
|
+
try expectSameTree(fixture.TemplateMsg, hand, interpreted);
|
|
1007
|
+
try expectSameTree(fixture.TemplateMsg, hand, compiled);
|
|
1008
|
+
try expectSameTexts(interpreted.root, compiled.root);
|
|
1009
|
+
try expectSameStyles(hand.root, interpreted.root);
|
|
1010
|
+
try expectSameStyles(hand.root, compiled.root);
|
|
1011
|
+
|
|
1012
|
+
// Dispatch parity for a handler declared inside a template body.
|
|
1013
|
+
const pear_button = fixture.findByText(compiled.root, .button, "pear").?;
|
|
1014
|
+
try testing.expectEqual(
|
|
1015
|
+
interpreted.msgForPointer(pear_button.id, .up).?,
|
|
1016
|
+
compiled.msgForPointer(pear_button.id, .up).?,
|
|
1017
|
+
);
|
|
1018
|
+
try testing.expectEqual(@as(u32, 2), compiled.msgForPointer(pear_button.id, .up).?.pick);
|
|
1019
|
+
|
|
1020
|
+
// Style token references resolved to the same concrete values.
|
|
1021
|
+
const badge = fixture.findByText(compiled.root, .badge, "apple").?;
|
|
1022
|
+
try testing.expectEqualDeep(tokens.colors.surface, badge.style.background.?);
|
|
1023
|
+
try testing.expectEqual(tokens.radius.md, badge.style.radius.?);
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
test "compiled template expansion keeps ids per use site and re-resolves tokens" {
|
|
1027
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1028
|
+
defer arena_state.deinit();
|
|
1029
|
+
const arena = arena_state.allocator();
|
|
1030
|
+
|
|
1031
|
+
const model = fixture.templateTestModel();
|
|
1032
|
+
|
|
1033
|
+
const light = try compileTemplates(arena, &model, canvas.DesignTokens{});
|
|
1034
|
+
const top_text = fixture.findByText(light.root, .text, "Top").?;
|
|
1035
|
+
const bottom_text = fixture.findByText(light.root, .text, "Bottom").?;
|
|
1036
|
+
try testing.expect(top_text.id != bottom_text.id);
|
|
1037
|
+
|
|
1038
|
+
// Retheme rebuild: same ids, new resolved colors — and the
|
|
1039
|
+
// interpreter agrees on both.
|
|
1040
|
+
const dark_tokens = canvas.DesignTokens.theme(.{ .color_scheme = .dark });
|
|
1041
|
+
const dark = try compileTemplates(arena, &model, dark_tokens);
|
|
1042
|
+
const dark_top_text = fixture.findByText(dark.root, .text, "Top").?;
|
|
1043
|
+
try testing.expectEqual(top_text.id, dark_top_text.id);
|
|
1044
|
+
try testing.expectEqualDeep(dark_tokens.colors.text_muted, dark_top_text.style.foreground.?);
|
|
1045
|
+
try testing.expect(!std.meta.eql(top_text.style.foreground.?, dark_top_text.style.foreground.?));
|
|
1046
|
+
|
|
1047
|
+
const dark_interpreted = try interpretTemplates(arena, &model, dark_tokens);
|
|
1048
|
+
try expectSameTree(fixture.TemplateMsg, dark_interpreted, dark);
|
|
1049
|
+
try expectSameStyles(dark_interpreted.root, dark.root);
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
// ------------------------------------------- avatar image binding parity
|
|
1053
|
+
|
|
1054
|
+
const AvatarUi = fixture.AvatarUi;
|
|
1055
|
+
const AvatarInterpreter = markup_view.MarkupView(fixture.AvatarModel, fixture.AvatarMsg);
|
|
1056
|
+
const AvatarCompiled = canvas.CompiledMarkupView(fixture.AvatarModel, fixture.AvatarMsg, fixture.avatar_markup_source);
|
|
1057
|
+
|
|
1058
|
+
test "compiled avatar image binding matches the interpreter and the hand-written view" {
|
|
1059
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1060
|
+
defer arena_state.deinit();
|
|
1061
|
+
const arena = arena_state.allocator();
|
|
1062
|
+
|
|
1063
|
+
const model = fixture.AvatarModel{ .user_image = 7 };
|
|
1064
|
+
|
|
1065
|
+
var view = try AvatarInterpreter.init(arena, fixture.avatar_markup_source);
|
|
1066
|
+
var interpreted_ui = AvatarUi.init(arena);
|
|
1067
|
+
const interpreted = try interpreted_ui.finalize(try view.build(&interpreted_ui, &model));
|
|
1068
|
+
|
|
1069
|
+
var compiled_ui = AvatarUi.init(arena);
|
|
1070
|
+
const compiled = try compiled_ui.finalize(AvatarCompiled.build(&compiled_ui, &model));
|
|
1071
|
+
|
|
1072
|
+
var hand_ui = AvatarUi.init(arena);
|
|
1073
|
+
const hand = try hand_ui.finalize(fixture.handAvatarView(&hand_ui, &model));
|
|
1074
|
+
|
|
1075
|
+
try expectSameTree(fixture.AvatarMsg, hand, interpreted);
|
|
1076
|
+
try expectSameTree(fixture.AvatarMsg, hand, compiled);
|
|
1077
|
+
try expectSameTexts(interpreted.root, compiled.root);
|
|
1078
|
+
|
|
1079
|
+
// The field binding and the fn binding both resolve to the widget's
|
|
1080
|
+
// image id at comptime-unrolled access, with the Ui.avatar cover fit.
|
|
1081
|
+
const field_avatar = fixture.findByText(compiled.root, .avatar, "CT").?;
|
|
1082
|
+
try testing.expectEqual(@as(canvas.ImageId, 7), field_avatar.image_id);
|
|
1083
|
+
try testing.expectEqual(canvas.ImageFit.cover, field_avatar.image_fit);
|
|
1084
|
+
try testing.expectEqual(@as(canvas.ImageId, 8), fixture.findByText(compiled.root, .avatar, "NS").?.image_id);
|
|
1085
|
+
|
|
1086
|
+
// 0 keeps the initials fallback in both engines.
|
|
1087
|
+
const empty_model = fixture.AvatarModel{};
|
|
1088
|
+
var empty_ui = AvatarUi.init(arena);
|
|
1089
|
+
const empty = try empty_ui.finalize(AvatarCompiled.build(&empty_ui, &empty_model));
|
|
1090
|
+
try testing.expectEqual(@as(canvas.ImageId, 0), fixture.findByText(empty.root, .avatar, "CT").?.image_id);
|
|
1091
|
+
try testing.expectEqualStrings("CT", fixture.findByText(empty.root, .avatar, "CT").?.text);
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
// ------------------------------------------------------ text wrap parity
|
|
1095
|
+
|
|
1096
|
+
const WrapUi = fixture.WrapUi;
|
|
1097
|
+
const WrapInterpreter = markup_view.MarkupView(fixture.WrapModel, fixture.WrapMsg);
|
|
1098
|
+
const WrapCompiled = canvas.CompiledMarkupView(fixture.WrapModel, fixture.WrapMsg, fixture.wrap_markup_source);
|
|
1099
|
+
|
|
1100
|
+
test "compiled wrap attribute matches the interpreter and the hand-written view" {
|
|
1101
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1102
|
+
defer arena_state.deinit();
|
|
1103
|
+
const arena = arena_state.allocator();
|
|
1104
|
+
|
|
1105
|
+
const model = fixture.WrapModel{};
|
|
1106
|
+
|
|
1107
|
+
var view = try WrapInterpreter.init(arena, fixture.wrap_markup_source);
|
|
1108
|
+
var interpreted_ui = WrapUi.init(arena);
|
|
1109
|
+
const interpreted = try interpreted_ui.finalize(try view.build(&interpreted_ui, &model));
|
|
1110
|
+
|
|
1111
|
+
var compiled_ui = WrapUi.init(arena);
|
|
1112
|
+
const compiled = try compiled_ui.finalize(WrapCompiled.build(&compiled_ui, &model));
|
|
1113
|
+
|
|
1114
|
+
var hand_ui = WrapUi.init(arena);
|
|
1115
|
+
const hand = try hand_ui.finalize(fixture.handWrapView(&hand_ui, &model));
|
|
1116
|
+
|
|
1117
|
+
try expectSameTree(fixture.WrapMsg, hand, interpreted);
|
|
1118
|
+
try expectSameTree(fixture.WrapMsg, hand, compiled);
|
|
1119
|
+
try expectSameTexts(interpreted.root, compiled.root);
|
|
1120
|
+
|
|
1121
|
+
// Both engines produce the single-span paragraph conversion.
|
|
1122
|
+
const compiled_wrapped = compiled.root.children[0];
|
|
1123
|
+
try testing.expectEqual(@as(usize, 1), compiled_wrapped.spans.len);
|
|
1124
|
+
try testing.expectEqualStrings(model.message, compiled_wrapped.text);
|
|
1125
|
+
try testing.expectEqual(@as(usize, 0), compiled.root.children[1].spans.len);
|
|
1126
|
+
try testing.expect(!compiled.root.children[1].text_no_wrap);
|
|
1127
|
+
// And both stamp wrap="false" as the honest single-line mode.
|
|
1128
|
+
const compiled_no_wrap = compiled.root.children[2];
|
|
1129
|
+
try testing.expectEqual(@as(usize, 0), compiled_no_wrap.spans.len);
|
|
1130
|
+
try testing.expect(compiled_no_wrap.text_no_wrap);
|
|
1131
|
+
try testing.expect(interpreted.root.children[2].text_no_wrap);
|
|
1132
|
+
// Both engines land overflow="clip" on the widget; unmarked leaves
|
|
1133
|
+
// keep the ellipsis default.
|
|
1134
|
+
try testing.expectEqual(canvas.TextOverflow.clip, compiled.root.children[3].text_overflow);
|
|
1135
|
+
try testing.expectEqual(canvas.TextOverflow.clip, interpreted.root.children[3].text_overflow);
|
|
1136
|
+
try testing.expectEqual(canvas.TextOverflow.ellipsis, compiled.root.children[1].text_overflow);
|
|
1137
|
+
try testing.expectEqual(canvas.TextOverflow.ellipsis, interpreted.root.children[1].text_overflow);
|
|
1138
|
+
// The definite width lands in both bounds.
|
|
1139
|
+
try testing.expectEqual(@as(f32, 360), compiled.root.layout.min_size.width);
|
|
1140
|
+
try testing.expectEqual(@as(f32, 360), compiled.root.layout.max_size.width);
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
// ------------------------------------------------ text size rung parity
|
|
1144
|
+
|
|
1145
|
+
const TypeScaleUi = fixture.TypeScaleUi;
|
|
1146
|
+
const TypeScaleInterpreter = markup_view.MarkupView(fixture.TypeScaleModel, fixture.TypeScaleMsg);
|
|
1147
|
+
const TypeScaleCompiled = canvas.CompiledMarkupView(fixture.TypeScaleModel, fixture.TypeScaleMsg, fixture.type_scale_markup_source);
|
|
1148
|
+
|
|
1149
|
+
test "compiled text size rungs match the interpreter and the hand-written view" {
|
|
1150
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1151
|
+
defer arena_state.deinit();
|
|
1152
|
+
const arena = arena_state.allocator();
|
|
1153
|
+
|
|
1154
|
+
const model = fixture.TypeScaleModel{};
|
|
1155
|
+
|
|
1156
|
+
var view = try TypeScaleInterpreter.init(arena, fixture.type_scale_markup_source);
|
|
1157
|
+
var interpreted_ui = TypeScaleUi.init(arena);
|
|
1158
|
+
const interpreted = try interpreted_ui.finalize(try view.build(&interpreted_ui, &model));
|
|
1159
|
+
|
|
1160
|
+
var compiled_ui = TypeScaleUi.init(arena);
|
|
1161
|
+
const compiled = try compiled_ui.finalize(TypeScaleCompiled.build(&compiled_ui, &model));
|
|
1162
|
+
|
|
1163
|
+
var hand_ui = TypeScaleUi.init(arena);
|
|
1164
|
+
const hand = try hand_ui.finalize(fixture.handTypeScaleView(&hand_ui, &model));
|
|
1165
|
+
|
|
1166
|
+
try expectSameTree(fixture.TypeScaleMsg, hand, interpreted);
|
|
1167
|
+
try expectSameTree(fixture.TypeScaleMsg, hand, compiled);
|
|
1168
|
+
try expectSameTexts(interpreted.root, compiled.root);
|
|
1169
|
+
|
|
1170
|
+
// Both engines stamp the typography rungs onto the text widgets, and
|
|
1171
|
+
// the wrapped display line keeps the single-span paragraph conversion.
|
|
1172
|
+
try testing.expectEqual(canvas.WidgetSize.heading, compiled.root.children[0].size);
|
|
1173
|
+
try testing.expectEqual(canvas.WidgetSize.display, compiled.root.children[1].size);
|
|
1174
|
+
try testing.expectEqual(canvas.WidgetSize.display, interpreted.root.children[1].size);
|
|
1175
|
+
const compiled_wrapped = compiled.root.children[2];
|
|
1176
|
+
try testing.expectEqual(canvas.WidgetSize.display, compiled_wrapped.size);
|
|
1177
|
+
try testing.expectEqual(@as(usize, 1), compiled_wrapped.spans.len);
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
// -------------------------------- text alignment and grid columns parity
|
|
1181
|
+
|
|
1182
|
+
const AlignUi = fixture.AlignUi;
|
|
1183
|
+
const AlignInterpreter = markup_view.MarkupView(fixture.AlignModel, fixture.AlignMsg);
|
|
1184
|
+
const AlignCompiled = canvas.CompiledMarkupView(fixture.AlignModel, fixture.AlignMsg, fixture.align_markup_source);
|
|
1185
|
+
|
|
1186
|
+
test "compiled text-alignment and grid columns match the interpreter and the hand-written view" {
|
|
1187
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1188
|
+
defer arena_state.deinit();
|
|
1189
|
+
const arena = arena_state.allocator();
|
|
1190
|
+
|
|
1191
|
+
const model = fixture.AlignModel{};
|
|
1192
|
+
|
|
1193
|
+
var view = try AlignInterpreter.init(arena, fixture.align_markup_source);
|
|
1194
|
+
var interpreted_ui = AlignUi.init(arena);
|
|
1195
|
+
const interpreted = try interpreted_ui.finalize(try view.build(&interpreted_ui, &model));
|
|
1196
|
+
|
|
1197
|
+
var compiled_ui = AlignUi.init(arena);
|
|
1198
|
+
const compiled = try compiled_ui.finalize(AlignCompiled.build(&compiled_ui, &model));
|
|
1199
|
+
|
|
1200
|
+
var hand_ui = AlignUi.init(arena);
|
|
1201
|
+
const hand = try hand_ui.finalize(fixture.handAlignView(&hand_ui, &model));
|
|
1202
|
+
|
|
1203
|
+
try expectSameTree(fixture.AlignMsg, hand, interpreted);
|
|
1204
|
+
try expectSameTree(fixture.AlignMsg, hand, compiled);
|
|
1205
|
+
try expectSameTexts(interpreted.root, compiled.root);
|
|
1206
|
+
|
|
1207
|
+
// Both engines land the alignment and the column counts.
|
|
1208
|
+
try testing.expectEqual(canvas.TextAlign.center, compiled.root.children[0].text_alignment);
|
|
1209
|
+
try testing.expectEqualDeep((canvas.DesignTokens{}).colors.info, compiled.root.children[0].style.foreground.?);
|
|
1210
|
+
try testing.expectEqual(@as(usize, 4), compiled.root.children[1].layout.columns);
|
|
1211
|
+
try testing.expectEqual(@as(usize, 3), compiled.root.children[2].layout.columns);
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
// --------------------------------- pressable rows (press fall-through)
|
|
1215
|
+
|
|
1216
|
+
const pressable_rows_markup =
|
|
1217
|
+
\\<column gap="4">
|
|
1218
|
+
\\ <for each="entries" as="e" key="id">
|
|
1219
|
+
\\ <panel on-press="open_entry:{e.id}" padding="8" role="listitem" label="{e.label}">
|
|
1220
|
+
\\ <row gap="8" cross="center">
|
|
1221
|
+
\\ <text grow="1">{e.label}</text>
|
|
1222
|
+
\\ <badge>#{e.id}</badge>
|
|
1223
|
+
\\ </row>
|
|
1224
|
+
\\ </panel>
|
|
1225
|
+
\\ </for>
|
|
1226
|
+
\\ <row on-press="refresh" gap="8">
|
|
1227
|
+
\\ <text>Refresh feed</text>
|
|
1228
|
+
\\ </row>
|
|
1229
|
+
\\</column>
|
|
1230
|
+
;
|
|
1231
|
+
|
|
1232
|
+
const PressableRowsCompiled = canvas.CompiledMarkupView(EntriesModel, EntriesMsg, pressable_rows_markup);
|
|
1233
|
+
|
|
1234
|
+
test "compiled pressable rows (panel and layout containers) match the interpreter" {
|
|
1235
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1236
|
+
defer arena_state.deinit();
|
|
1237
|
+
const arena = arena_state.allocator();
|
|
1238
|
+
|
|
1239
|
+
const entries = [_]Entry{
|
|
1240
|
+
.{ .id = 7, .label = "Ship the IR" },
|
|
1241
|
+
.{ .id = 9, .label = "Write decisions" },
|
|
1242
|
+
};
|
|
1243
|
+
const model = EntriesModel{ .entries = &entries };
|
|
1244
|
+
|
|
1245
|
+
var view = try EntriesInterpreter.init(arena, pressable_rows_markup);
|
|
1246
|
+
var interpreter_ui = EntriesUi.init(arena);
|
|
1247
|
+
const interpreted = try interpreter_ui.finalize(try view.build(&interpreter_ui, &model));
|
|
1248
|
+
var compiled_ui = EntriesUi.init(arena);
|
|
1249
|
+
const compiled = try compiled_ui.finalize(PressableRowsCompiled.build(&compiled_ui, &model));
|
|
1250
|
+
try expectSameTree(EntriesMsg, interpreted, compiled);
|
|
1251
|
+
|
|
1252
|
+
// Both engines make the pressable panel row a press claimer that
|
|
1253
|
+
// dispatches the payload-carrying Msg, with its text falling through.
|
|
1254
|
+
const first_row = fixture.findByKind(compiled.root, .panel).?;
|
|
1255
|
+
try testing.expectEqualStrings("Ship the IR", first_row.semantics.label);
|
|
1256
|
+
try testing.expect(canvas.widgetClaimsPress(first_row));
|
|
1257
|
+
try testing.expectEqual(@as(u32, 7), compiled.msgForPointer(first_row.id, .up).?.open_entry);
|
|
1258
|
+
try testing.expect(!canvas.widgetClaimsPress(first_row.children[0].children[0]));
|
|
1259
|
+
|
|
1260
|
+
// A LAYOUT container with on-press is a widget-level hit target in
|
|
1261
|
+
// both engines — the handler stamps the press action.
|
|
1262
|
+
var pressable_row: ?canvas.Widget = null;
|
|
1263
|
+
for (compiled.root.children) |child| {
|
|
1264
|
+
if (child.kind == .row and child.semantics.actions.press) pressable_row = child;
|
|
1265
|
+
}
|
|
1266
|
+
try testing.expect(pressable_row != null);
|
|
1267
|
+
try testing.expect(canvas.widgetIsHitTarget(pressable_row.?));
|
|
1268
|
+
try testing.expectEqual(EntriesMsg.refresh, compiled.msgForPointer(pressable_row.?.id, .up).?);
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
// -------------------------------------------------- anchored picker parity
|
|
1272
|
+
|
|
1273
|
+
const PickerCompiled = canvas.CompiledMarkupView(fixture.Model, fixture.Msg, fixture.picker_markup_source);
|
|
1274
|
+
|
|
1275
|
+
test "compiled anchored picker (anchor, on-dismiss, on-hold) matches the interpreter" {
|
|
1276
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1277
|
+
defer arena_state.deinit();
|
|
1278
|
+
const arena = arena_state.allocator();
|
|
1279
|
+
|
|
1280
|
+
const model = fixture.Model{};
|
|
1281
|
+
|
|
1282
|
+
var view = try InboxInterpreter.init(arena, fixture.picker_markup_source);
|
|
1283
|
+
var interpreter_ui = InboxUi.init(arena);
|
|
1284
|
+
const interpreted = try interpreter_ui.finalize(try view.build(&interpreter_ui, &model));
|
|
1285
|
+
var compiled_ui = InboxUi.init(arena);
|
|
1286
|
+
const compiled = try compiled_ui.finalize(PickerCompiled.build(&compiled_ui, &model));
|
|
1287
|
+
try expectSameTree(fixture.Msg, interpreted, compiled);
|
|
1288
|
+
|
|
1289
|
+
// Both engines resolve the anchor attributes into the same layout
|
|
1290
|
+
// channel and bind the dismiss/hold handlers identically.
|
|
1291
|
+
const dropdown = fixture.findByKind(compiled.root, .dropdown_menu).?;
|
|
1292
|
+
const anchor = dropdown.layout.anchor orelse return error.TestUnexpectedResult;
|
|
1293
|
+
try testing.expectEqual(canvas.WidgetAnchorPlacement.below, anchor.placement);
|
|
1294
|
+
try testing.expectEqual(canvas.WidgetAnchorAlignment.stretch, anchor.alignment);
|
|
1295
|
+
try testing.expectEqual(@as(f32, 6), anchor.offset);
|
|
1296
|
+
try testing.expect(compiled.msgFor(dropdown.id, .dismiss) != null);
|
|
1297
|
+
const crumb = fixture.findByKind(compiled.root, .button).?;
|
|
1298
|
+
try testing.expect(compiled.msgFor(crumb.id, .hold) != null);
|
|
1299
|
+
try testing.expect(crumb.semantics.actions.press);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
// -------------------------------------------------- split panes and trees
|
|
1303
|
+
|
|
1304
|
+
const PaneCompiled = canvas.CompiledMarkupView(fixture.PaneModel, fixture.PaneMsg, fixture.pane_markup_source);
|
|
1305
|
+
|
|
1306
|
+
test "compiled split and tree match the interpreter and the hand-written view" {
|
|
1307
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1308
|
+
defer arena_state.deinit();
|
|
1309
|
+
const arena = arena_state.allocator();
|
|
1310
|
+
|
|
1311
|
+
const model = fixture.PaneModel{};
|
|
1312
|
+
|
|
1313
|
+
var view = try markup_view.MarkupView(fixture.PaneModel, fixture.PaneMsg).init(arena, fixture.pane_markup_source);
|
|
1314
|
+
var interpreter_ui = fixture.PaneUi.init(arena);
|
|
1315
|
+
const interpreted = try interpreter_ui.finalize(try view.build(&interpreter_ui, &model));
|
|
1316
|
+
var compiled_ui = fixture.PaneUi.init(arena);
|
|
1317
|
+
const compiled = try compiled_ui.finalize(PaneCompiled.build(&compiled_ui, &model));
|
|
1318
|
+
try expectSameTree(fixture.PaneMsg, interpreted, compiled);
|
|
1319
|
+
|
|
1320
|
+
var hand_ui = fixture.PaneUi.init(arena);
|
|
1321
|
+
const hand = try hand_ui.finalize(fixture.handPaneView(&hand_ui, &model));
|
|
1322
|
+
try expectSameTree(fixture.PaneMsg, hand, compiled);
|
|
1323
|
+
|
|
1324
|
+
// The synthesized divider and the resize dispatch agree across engines.
|
|
1325
|
+
try testing.expectEqual(canvas.WidgetKind.split_divider, compiled.root.children[1].kind);
|
|
1326
|
+
try testing.expectEqual(@as(f32, 0.7), compiled.msgForResize(compiled.root.id, 0.7).?.sidebar_resized);
|
|
1327
|
+
try testing.expectEqual(
|
|
1328
|
+
interpreted.msgForResize(interpreted.root.id, 0.7).?.sidebar_resized,
|
|
1329
|
+
compiled.msgForResize(compiled.root.id, 0.7).?.sidebar_resized,
|
|
1330
|
+
);
|
|
1331
|
+
|
|
1332
|
+
// Tree rows: role, expanded state, and both dispatch channels.
|
|
1333
|
+
const row = fixture.findByKind(compiled.root, .panel).?;
|
|
1334
|
+
try testing.expectEqual(canvas.WidgetRole.treeitem, row.semantics.role);
|
|
1335
|
+
try testing.expectEqual(@as(?bool, true), row.state.expanded);
|
|
1336
|
+
try testing.expectEqual(@as(u32, 1), compiled.msgForPointer(row.id, .up).?.select_folder);
|
|
1337
|
+
try testing.expectEqual(@as(u32, 1), compiled.msgFor(row.id, .toggle).?.toggle_folder);
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
// --------------------------------- imports, slots, and defaults parity
|
|
1341
|
+
|
|
1342
|
+
const ImportCompiled = canvas.CompiledMarkupImports(
|
|
1343
|
+
fixture.TemplateModel,
|
|
1344
|
+
fixture.TemplateMsg,
|
|
1345
|
+
"view.native",
|
|
1346
|
+
&fixture.import_view_sources,
|
|
1347
|
+
);
|
|
1348
|
+
|
|
1349
|
+
fn interpretImports(arena: std.mem.Allocator, model: *const fixture.TemplateModel) !TemplateUi.Tree {
|
|
1350
|
+
const document = try fixture.resolveImportSet(arena, &fixture.import_view_sources, "view.native");
|
|
1351
|
+
var view = TemplateInterpreter.fromDocument(document);
|
|
1352
|
+
var ui = TemplateUi.init(arena);
|
|
1353
|
+
return ui.finalize(try view.build(&ui, model));
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
fn compileImports(arena: std.mem.Allocator, model: *const fixture.TemplateModel) !TemplateUi.Tree {
|
|
1357
|
+
var ui = TemplateUi.init(arena);
|
|
1358
|
+
return ui.finalize(ImportCompiled.build(&ui, model));
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
test "compiled imports with slots and defaults match the interpreter and the hand-written view" {
|
|
1362
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1363
|
+
defer arena_state.deinit();
|
|
1364
|
+
const arena = arena_state.allocator();
|
|
1365
|
+
|
|
1366
|
+
const model = fixture.templateTestModel();
|
|
1367
|
+
|
|
1368
|
+
const interpreted = try interpretImports(arena, &model);
|
|
1369
|
+
const compiled = try compileImports(arena, &model);
|
|
1370
|
+
var hand_ui = TemplateUi.init(arena);
|
|
1371
|
+
const hand = try hand_ui.finalize(fixture.handImportView(&hand_ui, &model));
|
|
1372
|
+
|
|
1373
|
+
// Three engines, one tree: the comptime source-set resolution and the
|
|
1374
|
+
// runtime set resolution produce the same merged document, and slot
|
|
1375
|
+
// content (built in the consumer's scope, spliced at the slot) hashes
|
|
1376
|
+
// the same structural ids as hand-written inlining. The fixture
|
|
1377
|
+
// covers a transitive import chain, an imported template using
|
|
1378
|
+
// another imported template, a defaulted arg omitted inside slot
|
|
1379
|
+
// content, and an empty slot.
|
|
1380
|
+
try expectSameTree(fixture.TemplateMsg, hand, interpreted);
|
|
1381
|
+
try expectSameTree(fixture.TemplateMsg, hand, compiled);
|
|
1382
|
+
try expectSameTexts(interpreted.root, compiled.root);
|
|
1383
|
+
|
|
1384
|
+
// Defaulted arg parity down to the interpolated byte.
|
|
1385
|
+
try testing.expect(fixture.findByText(compiled.root, .badge, "Top header") != null);
|
|
1386
|
+
try testing.expect(fixture.findByText(compiled.root, .badge, "apple muted") != null);
|
|
1387
|
+
try testing.expect(fixture.findByText(compiled.root, .badge, "Bottom header") != null);
|
|
1388
|
+
|
|
1389
|
+
// Dispatch parity for a handler declared in slot content: it captured
|
|
1390
|
+
// the consumer's loop variable.
|
|
1391
|
+
const pear_button = fixture.findByText(compiled.root, .button, "pear").?;
|
|
1392
|
+
try testing.expectEqual(
|
|
1393
|
+
interpreted.msgForPointer(pear_button.id, .up).?,
|
|
1394
|
+
compiled.msgForPointer(pear_button.id, .up).?,
|
|
1395
|
+
);
|
|
1396
|
+
try testing.expectEqual(@as(u32, 2), compiled.msgForPointer(pear_button.id, .up).?.pick);
|
|
1397
|
+
|
|
1398
|
+
// Rebuild stability: same ids on a second build.
|
|
1399
|
+
const rebuilt = try compileImports(arena, &model);
|
|
1400
|
+
try testing.expectEqual(pear_button.id, fixture.findByText(rebuilt.root, .button, "pear").?.id);
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
test "compiled slot content follows model changes like the interpreter" {
|
|
1404
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1405
|
+
defer arena_state.deinit();
|
|
1406
|
+
const arena = arena_state.allocator();
|
|
1407
|
+
|
|
1408
|
+
// Slot content iterates model.top at the use site: growing the list
|
|
1409
|
+
// grows both engines' trees identically.
|
|
1410
|
+
var model = fixture.templateTestModel();
|
|
1411
|
+
model.top = &[_]fixture.Fruit{
|
|
1412
|
+
.{ .id = 1, .name = "apple" },
|
|
1413
|
+
.{ .id = 2, .name = "pear" },
|
|
1414
|
+
.{ .id = 9, .name = "quince" },
|
|
1415
|
+
};
|
|
1416
|
+
const interpreted = try interpretImports(arena, &model);
|
|
1417
|
+
const compiled = try compileImports(arena, &model);
|
|
1418
|
+
try expectSameTree(fixture.TemplateMsg, interpreted, compiled);
|
|
1419
|
+
try expectSameTexts(interpreted.root, compiled.root);
|
|
1420
|
+
const quince_button = fixture.findByText(compiled.root, .button, "quince").?;
|
|
1421
|
+
try testing.expectEqual(@as(u32, 9), compiled.msgForPointer(quince_button.id, .up).?.pick);
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
// ---------------------------------------------------- chart fixture parity
|
|
1425
|
+
|
|
1426
|
+
const ChartUi = fixture.ChartUi;
|
|
1427
|
+
const ChartInterpreter = markup_view.MarkupView(fixture.ChartModel, fixture.ChartMsg);
|
|
1428
|
+
const ChartCompiled = canvas.CompiledMarkupView(fixture.ChartModel, fixture.ChartMsg, fixture.chart_markup_source);
|
|
1429
|
+
|
|
1430
|
+
fn interpretChart(arena: std.mem.Allocator, model: *const fixture.ChartModel) !ChartUi.Tree {
|
|
1431
|
+
var view = try ChartInterpreter.init(arena, fixture.chart_markup_source);
|
|
1432
|
+
var ui = ChartUi.init(arena);
|
|
1433
|
+
return ui.finalize(try view.build(&ui, model));
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
fn compileChart(arena: std.mem.Allocator, model: *const fixture.ChartModel) !ChartUi.Tree {
|
|
1437
|
+
var ui = ChartUi.init(arena);
|
|
1438
|
+
return ui.finalize(ChartCompiled.build(&ui, model));
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
fn expectSameChartData(expected: canvas.ChartData, actual: canvas.ChartData) !void {
|
|
1442
|
+
try testing.expectEqual(expected.y_min, actual.y_min);
|
|
1443
|
+
try testing.expectEqual(expected.y_max, actual.y_max);
|
|
1444
|
+
try testing.expectEqual(expected.grid_lines, actual.grid_lines);
|
|
1445
|
+
try testing.expectEqual(expected.baseline, actual.baseline);
|
|
1446
|
+
try testing.expectEqual(expected.y_labels, actual.y_labels);
|
|
1447
|
+
try testing.expectEqual(expected.hover_details, actual.hover_details);
|
|
1448
|
+
try testing.expectEqual(expected.x_labels.len, actual.x_labels.len);
|
|
1449
|
+
for (expected.x_labels, actual.x_labels) |expected_label, actual_label| {
|
|
1450
|
+
try testing.expectEqualStrings(expected_label, actual_label);
|
|
1451
|
+
}
|
|
1452
|
+
try testing.expectEqual(expected.series.len, actual.series.len);
|
|
1453
|
+
for (expected.series, actual.series) |expected_series, actual_series| {
|
|
1454
|
+
try testing.expectEqual(expected_series.kind, actual_series.kind);
|
|
1455
|
+
try testing.expectEqual(expected_series.fill, actual_series.fill);
|
|
1456
|
+
try testing.expectEqual(expected_series.color, actual_series.color);
|
|
1457
|
+
try testing.expectEqualStrings(expected_series.label, actual_series.label);
|
|
1458
|
+
try testing.expectEqual(expected_series.values.len, actual_series.values.len);
|
|
1459
|
+
for (expected_series.values, actual_series.values) |expected_value, actual_value| {
|
|
1460
|
+
// NaN gaps compare as gaps: both engines pass them through.
|
|
1461
|
+
if (std.math.isNan(expected_value)) {
|
|
1462
|
+
try testing.expect(std.math.isNan(actual_value));
|
|
1463
|
+
} else {
|
|
1464
|
+
try testing.expectEqual(expected_value, actual_value);
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
fn firstChartWidget(widget: canvas.Widget) ?canvas.Widget {
|
|
1471
|
+
return fixture.findByKind(widget, .chart);
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
test "compiled charts match the interpreter and the hand-written Ui.chart tree" {
|
|
1475
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1476
|
+
defer arena_state.deinit();
|
|
1477
|
+
const arena = arena_state.allocator();
|
|
1478
|
+
|
|
1479
|
+
const model = fixture.ChartModel{};
|
|
1480
|
+
|
|
1481
|
+
const interpreted = try interpretChart(arena, &model);
|
|
1482
|
+
const compiled = try compileChart(arena, &model);
|
|
1483
|
+
var hand_ui = ChartUi.init(arena);
|
|
1484
|
+
const hand = try hand_ui.finalize(fixture.handChartView(&hand_ui, &model));
|
|
1485
|
+
|
|
1486
|
+
try expectSameTree(fixture.ChartMsg, hand, interpreted);
|
|
1487
|
+
try expectSameTree(fixture.ChartMsg, hand, compiled);
|
|
1488
|
+
|
|
1489
|
+
// Chart payload parity: options, series kinds/colors/labels, and the
|
|
1490
|
+
// bound data (NaN gaps included) agree across all three engines.
|
|
1491
|
+
const interpreted_chart = firstChartWidget(interpreted.root).?;
|
|
1492
|
+
const compiled_chart = firstChartWidget(compiled.root).?;
|
|
1493
|
+
const hand_chart = firstChartWidget(hand.root).?;
|
|
1494
|
+
try expectSameChartData(hand_chart.chart, interpreted_chart.chart);
|
|
1495
|
+
try expectSameChartData(hand_chart.chart, compiled_chart.chart);
|
|
1496
|
+
try testing.expectEqualStrings(hand_chart.semantics.label, compiled_chart.semantics.label);
|
|
1497
|
+
// The chart role derives from the widget KIND at semantics
|
|
1498
|
+
// publication (widget_semantics maps .chart kind -> .chart role), so
|
|
1499
|
+
// the markup path carries the same accessibility surface as the
|
|
1500
|
+
// builder: same kind, same label, same derived role.
|
|
1501
|
+
try testing.expectEqual(hand_chart.semantics.role, compiled_chart.semantics.role);
|
|
1502
|
+
try testing.expectEqual(canvas.WidgetKind.chart, compiled_chart.kind);
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
// ---------------------------------------------- input-group fixture parity
|
|
1506
|
+
|
|
1507
|
+
const ComposerUi = fixture.ComposerUi;
|
|
1508
|
+
const ComposerInterpreter = markup_view.MarkupView(fixture.ComposerModel, fixture.ComposerMsg);
|
|
1509
|
+
const ComposerCompiled = canvas.CompiledMarkupView(fixture.ComposerModel, fixture.ComposerMsg, fixture.composer_markup_source);
|
|
1510
|
+
|
|
1511
|
+
test "compiled input-groups match the interpreter and the hand-written Ui.inputGroup tree" {
|
|
1512
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1513
|
+
defer arena_state.deinit();
|
|
1514
|
+
const arena = arena_state.allocator();
|
|
1515
|
+
|
|
1516
|
+
var model = fixture.ComposerModel{};
|
|
1517
|
+
model.draft_buffer.set("hello");
|
|
1518
|
+
|
|
1519
|
+
var view = try ComposerInterpreter.init(arena, fixture.composer_markup_source);
|
|
1520
|
+
var interpreted_ui = ComposerUi.init(arena);
|
|
1521
|
+
const interpreted = try interpreted_ui.finalize(try view.build(&interpreted_ui, &model));
|
|
1522
|
+
|
|
1523
|
+
var compiled_ui = ComposerUi.init(arena);
|
|
1524
|
+
const compiled = try compiled_ui.finalize(ComposerCompiled.build(&compiled_ui, &model));
|
|
1525
|
+
|
|
1526
|
+
var hand_ui = ComposerUi.init(arena);
|
|
1527
|
+
const hand = try hand_ui.finalize(fixture.handComposerView(&hand_ui, &model));
|
|
1528
|
+
|
|
1529
|
+
try expectSameTree(fixture.ComposerMsg, hand, interpreted);
|
|
1530
|
+
try expectSameTree(fixture.ComposerMsg, hand, compiled);
|
|
1531
|
+
|
|
1532
|
+
// Group payload parity: the field chrome treatment (dissolved entry
|
|
1533
|
+
// chrome, grow-stretched entry, group semantics) agrees across all
|
|
1534
|
+
// three engines.
|
|
1535
|
+
const compiled_group = fixture.findByKind(compiled.root, .input_group).?;
|
|
1536
|
+
const hand_group = fixture.findByKind(hand.root, .input_group).?;
|
|
1537
|
+
try testing.expectEqual(canvas.WidgetKind.input_group, compiled_group.kind);
|
|
1538
|
+
try testing.expectEqualStrings(hand_group.semantics.label, compiled_group.semantics.label);
|
|
1539
|
+
try testing.expectEqual(hand_group.semantics.role, compiled_group.semantics.role);
|
|
1540
|
+
try testing.expectEqual(@as(usize, 2), compiled_group.children.len);
|
|
1541
|
+
try testing.expectEqual(@as(f32, 1), compiled_group.children[0].layout.grow);
|
|
1542
|
+
try testing.expectEqual(@as(u8, 0), compiled_group.children[0].style.background.?.a);
|
|
1543
|
+
try testing.expectEqual(@as(u8, 0), compiled_group.children[0].style.border.?.a);
|
|
1544
|
+
try testing.expectEqual(@as(u8, 0), compiled_group.children[0].style.focus_ring.?.a);
|
|
1545
|
+
try testing.expectEqualStrings("hello", compiled_group.children[0].text);
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
const chart_template_markup =
|
|
1549
|
+
\\<template name="spark" args="data"><chart height="32"><series kind="area" values="{data}" /></chart></template>
|
|
1550
|
+
\\<column>
|
|
1551
|
+
\\ <use template="spark" data="{latency}" />
|
|
1552
|
+
\\</column>
|
|
1553
|
+
;
|
|
1554
|
+
|
|
1555
|
+
const ChartTemplateCompiled = canvas.CompiledMarkupView(fixture.ChartModel, fixture.ChartMsg, chart_template_markup);
|
|
1556
|
+
|
|
1557
|
+
test "compiled chart series resolve through slice-valued template args like the interpreter" {
|
|
1558
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1559
|
+
defer arena_state.deinit();
|
|
1560
|
+
const arena = arena_state.allocator();
|
|
1561
|
+
|
|
1562
|
+
const model = fixture.ChartModel{};
|
|
1563
|
+
|
|
1564
|
+
var view = try ChartInterpreter.init(arena, chart_template_markup);
|
|
1565
|
+
var interpreted_ui = ChartUi.init(arena);
|
|
1566
|
+
const interpreted = try interpreted_ui.finalize(try view.build(&interpreted_ui, &model));
|
|
1567
|
+
|
|
1568
|
+
var compiled_ui = ChartUi.init(arena);
|
|
1569
|
+
const compiled = try compiled_ui.finalize(ChartTemplateCompiled.build(&compiled_ui, &model));
|
|
1570
|
+
|
|
1571
|
+
try expectSameTree(fixture.ChartMsg, interpreted, compiled);
|
|
1572
|
+
const compiled_chart = firstChartWidget(compiled.root).?;
|
|
1573
|
+
try expectSameChartData(firstChartWidget(interpreted.root).?.chart, compiled_chart.chart);
|
|
1574
|
+
try testing.expectEqual(@as(f32, 12), compiled_chart.chart.series[0].values[0]);
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1577
|
+
// ------------------------------------------------- span paragraph parity
|
|
1578
|
+
|
|
1579
|
+
const SpanUi = canvas.Ui(fixture.SpanMsg);
|
|
1580
|
+
const SpanInterpreter = markup_view.MarkupView(fixture.SpanModel, fixture.SpanMsg);
|
|
1581
|
+
const SpanCompiled = canvas.CompiledMarkupView(fixture.SpanModel, fixture.SpanMsg, fixture.span_markup_source);
|
|
1582
|
+
|
|
1583
|
+
test "compiled span paragraphs build the interpreter's and the hand-written paragraphs exactly" {
|
|
1584
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1585
|
+
defer arena_state.deinit();
|
|
1586
|
+
const arena = arena_state.allocator();
|
|
1587
|
+
|
|
1588
|
+
const model = fixture.SpanModel{};
|
|
1589
|
+
|
|
1590
|
+
var view = try SpanInterpreter.init(arena, fixture.span_markup_source);
|
|
1591
|
+
var interpreted_ui = SpanUi.init(arena);
|
|
1592
|
+
const interpreted = try interpreted_ui.finalize(try view.build(&interpreted_ui, &model));
|
|
1593
|
+
|
|
1594
|
+
var compiled_ui = SpanUi.init(arena);
|
|
1595
|
+
const compiled = try compiled_ui.finalize(SpanCompiled.build(&compiled_ui, &model));
|
|
1596
|
+
|
|
1597
|
+
var hand_ui = SpanUi.init(arena);
|
|
1598
|
+
const hand = try hand_ui.finalize(fixture.handSpanView(&hand_ui, &model));
|
|
1599
|
+
|
|
1600
|
+
// The three engines agree node for node: mixed weight/mono/italic/
|
|
1601
|
+
// color runs, bindings inside spans, a bound weight, single-space
|
|
1602
|
+
// collapsing, the abutting punctuation run, and the later span
|
|
1603
|
+
// additions — scaled (literal and bound) and underlined runs.
|
|
1604
|
+
try expectSameTree(fixture.SpanMsg, hand, interpreted);
|
|
1605
|
+
try expectSameTree(fixture.SpanMsg, hand, compiled);
|
|
1606
|
+
try expectSameTexts(interpreted.root, compiled.root);
|
|
1607
|
+
|
|
1608
|
+
// Span lists agree style for style and byte for byte.
|
|
1609
|
+
for (interpreted.root.children, compiled.root.children) |interpreted_child, compiled_child| {
|
|
1610
|
+
try testing.expect(canvas.text_spans.textSpansEqual(interpreted_child.spans, compiled_child.spans));
|
|
1611
|
+
}
|
|
1612
|
+
const compiled_disk = compiled.root.children[0];
|
|
1613
|
+
try testing.expectEqualStrings("Disk 182 GB of 512 GB used; run native doctor!", compiled_disk.text);
|
|
1614
|
+
try testing.expectEqual(@as(usize, 12), compiled_disk.spans.len);
|
|
1615
|
+
try testing.expectEqual(canvas.TextSpanWeight.bold, compiled_disk.spans[2].weight);
|
|
1616
|
+
try testing.expect(compiled_disk.spans[10].monospace);
|
|
1617
|
+
|
|
1618
|
+
// The later span additions: the compiled engine lowers the
|
|
1619
|
+
// comptime-literal scale, the runtime-bound scale, and the underline
|
|
1620
|
+
// decoration to the same channels the interpreter and the
|
|
1621
|
+
// hand-written paragraph carry (textSpansEqual above already held
|
|
1622
|
+
// the full lists equal — these pins state the interesting values).
|
|
1623
|
+
const compiled_title = compiled.root.children[2];
|
|
1624
|
+
try testing.expectEqualStrings("182 GB free on 512 GB at native doctor", compiled_title.text);
|
|
1625
|
+
try testing.expectEqual(@as(f32, 1.5), compiled_title.spans[0].scale);
|
|
1626
|
+
try testing.expect(compiled_title.spans[4].underline);
|
|
1627
|
+
try testing.expectEqual(@as(f32, 1.3), compiled_title.spans[8].scale);
|
|
1628
|
+
|
|
1629
|
+
// Accessibility parity pin: one text run, no semantic children —
|
|
1630
|
+
// scaled and underlined runs change nothing.
|
|
1631
|
+
try testing.expectEqual(@as(usize, 0), compiled_disk.children.len);
|
|
1632
|
+
try testing.expectEqual(@as(usize, 0), compiled_title.children.len);
|
|
1633
|
+
try testing.expectEqualStrings("Total line", compiled.root.children[1].semantics.label);
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
// ------------------------------------------------ bubble reaction parity
|
|
1637
|
+
|
|
1638
|
+
const ReactionsCompiled = canvas.CompiledMarkupView(fixture.SpanModel, fixture.SpanMsg, fixture.reactions_markup_source);
|
|
1639
|
+
|
|
1640
|
+
test "compiled reactions lower onto the bubble's chrome-text channel exactly like the interpreter" {
|
|
1641
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1642
|
+
defer arena_state.deinit();
|
|
1643
|
+
const arena = arena_state.allocator();
|
|
1644
|
+
|
|
1645
|
+
const model = fixture.SpanModel{};
|
|
1646
|
+
|
|
1647
|
+
var view = try SpanInterpreter.init(arena, fixture.reactions_markup_source);
|
|
1648
|
+
var interpreted_ui = SpanUi.init(arena);
|
|
1649
|
+
const interpreted = try interpreted_ui.finalize(try view.build(&interpreted_ui, &model));
|
|
1650
|
+
|
|
1651
|
+
var compiled_ui = SpanUi.init(arena);
|
|
1652
|
+
const compiled = try compiled_ui.finalize(ReactionsCompiled.build(&compiled_ui, &model));
|
|
1653
|
+
|
|
1654
|
+
try expectSameTree(fixture.SpanMsg, interpreted, compiled);
|
|
1655
|
+
try expectSameTexts(interpreted.root, compiled.root);
|
|
1656
|
+
|
|
1657
|
+
// The pill run lands on widget.text, the reactions child is
|
|
1658
|
+
// consumed, and the dock literal resolves at comptime: end without
|
|
1659
|
+
// an attribute, start when declared. Interpolation in the run
|
|
1660
|
+
// resolves at runtime like any text.
|
|
1661
|
+
const received = compiled.root.children[0];
|
|
1662
|
+
try testing.expectEqualStrings("+2", received.text);
|
|
1663
|
+
try testing.expectEqual(canvas.TextAlign.end, received.text_alignment);
|
|
1664
|
+
try testing.expectEqual(@as(usize, 1), received.children.len);
|
|
1665
|
+
const sent = compiled.root.children[1];
|
|
1666
|
+
try testing.expectEqualStrings("182 GB +1", sent.text);
|
|
1667
|
+
try testing.expectEqual(canvas.TextAlign.start, sent.text_alignment);
|
|
1668
|
+
try testing.expectEqual(@as(usize, 0), compiled.root.children[2].text.len);
|
|
1669
|
+
}
|