From 654ed59f5eb3b89d159be00f4ff078b232d2b33c Mon Sep 17 00:00:00 2001 From: FarnaHerry Date: Tue, 24 Nov 2026 22:00:31 +0800 Subject: [PATCH] feat(huxerui): add huxerui.interaction 0.2.0, huxerui.markdown 0.3.1, and huxerui.qrcode 0.1.0 --- .../docs/2026-11-24-add-huxerui-libs-plan.md | 57 +++++++++++ mcpp.toml | 3 + pkgs/h/huxerui.interaction.lua | 43 ++++++++ pkgs/h/huxerui.markdown.lua | 43 ++++++++ pkgs/h/huxerui.qrcode.lua | 43 ++++++++ tests/examples/huxerui-interaction/mcpp.toml | 10 ++ .../huxerui-interaction/tests/runtime.cpp | 87 +++++++++++++++++ tests/examples/huxerui-markdown/mcpp.toml | 10 ++ .../huxerui-markdown/tests/runtime.cpp | 87 +++++++++++++++++ tests/examples/huxerui-qrcode/mcpp.toml | 10 ++ .../examples/huxerui-qrcode/tests/runtime.cpp | 97 +++++++++++++++++++ 11 files changed, 490 insertions(+) create mode 100644 .agents/docs/2026-11-24-add-huxerui-libs-plan.md create mode 100644 pkgs/h/huxerui.interaction.lua create mode 100644 pkgs/h/huxerui.markdown.lua create mode 100644 pkgs/h/huxerui.qrcode.lua create mode 100644 tests/examples/huxerui-interaction/mcpp.toml create mode 100644 tests/examples/huxerui-interaction/tests/runtime.cpp create mode 100644 tests/examples/huxerui-markdown/mcpp.toml create mode 100644 tests/examples/huxerui-markdown/tests/runtime.cpp create mode 100644 tests/examples/huxerui-qrcode/mcpp.toml create mode 100644 tests/examples/huxerui-qrcode/tests/runtime.cpp diff --git a/.agents/docs/2026-11-24-add-huxerui-libs-plan.md b/.agents/docs/2026-11-24-add-huxerui-libs-plan.md new file mode 100644 index 00000000..67f62112 --- /dev/null +++ b/.agents/docs/2026-11-24-add-huxerui-libs-plan.md @@ -0,0 +1,57 @@ +# Add `huxerui.interaction`, `huxerui.markdown`, and `huxerui.qrcode` + +## Summary + +Add three Form A native C++23 module libraries from the `HuxerUI` ecosystem targeting `huxerui.huxerui` `0.5.5`: + +| Package | Version | Upstream Tag | Module Interface | Descriptor | +| :--- | :--- | :--- | :--- | :--- | +| `huxerui.interaction` | `0.2.0` | `HuxerUI/Lib-Interaction@v0.2.0` (`ff37a8a6`) | `import huxerui.interaction;` | `pkgs/h/huxerui.interaction.lua` | +| `huxerui.markdown` | `0.3.1` | `HuxerUI/Lib-Markdown@v0.3.1` (`3a875ae0`) | `import huxerui.markdown;` | `pkgs/h/huxerui.markdown.lua` | +| `huxerui.qrcode` | `0.1.0` | `HuxerUI/Lib-QRCode@v0.1.0` (`696ff56b`) | `import huxerui.qrcode;` | `pkgs/h/huxerui.qrcode.lua` | + +## Package Architecture + +- **Form A (External Native Module Repositories)**: + - Each upstream tag archive ships its own `mcpp.toml`, `build.mcpp` (`huxerui.rules`), and `modules/*.cppm`, so none of the three descriptors carries an inline `mcpp` build table: + - `huxerui.interaction` (`0.2.0`): `modules/interaction.cppm` and `modules/operators.cppm` (gesture/press/hover/scroll/overlay/accessibility primitives and pipe/mask operators). + - `huxerui.markdown` (`0.3.1`): `modules/markdown.cppm` and `modules/macros.cppm`, with vendored `md4c` (`c99`) parser sources and CommonMark/GFM declarative view components. + - `huxerui.qrcode` (`0.1.0`): `modules/qrcode.cppm`, with `build.mcpp` generating `zxing/Version.h` and compiling vendored ZXing 3.1.1 (C++ and `c99` `libzueci`) encoder/decoder sources. + - Each package declares `licenses = {"MIT"}`, matching `LICENSE` and `mcpp.toml` in its upstream tag archive. + - All three upstream `mcpp.toml` manifests declare `[dependencies] huxerui.huxerui = "0.5.5"` (`standard = "c++23"`), so no extra `xpm..deps` closures need to be duplicated in these descriptors; transitive Linux GTK4 `xim` dependencies come from `pkgs/h/huxerui.huxerui.lua`. +- **Upstream Archives & CN Mirror Status**: + - Plain upstream GitHub tag archive URLs are declared across `linux`, `macosx`, and `windows` (local `gitcode.com/mcpp-res` credentials are unavailable; maintainers can populate `CN` mirrors later without altering versions): + - `Lib-Interaction` `v0.2.0` (`196,811` bytes): `https://github.com/HuxerUI/Lib-Interaction/archive/refs/tags/v0.2.0.tar.gz` — SHA256 verified twice: `9ffff3fa6e8bee09a97a766f84af5b4c7dd61f1db6d321d2256ddcc2b32d968d` + - `Lib-Markdown` `v0.3.1` (`171,647` bytes): `https://github.com/HuxerUI/Lib-Markdown/archive/refs/tags/v0.3.1.tar.gz` — SHA256 verified twice: `0e8be37f40b0377bec57e5354dc3dd1114544db92724eadbb027adf53e1a6f2a` + - `Lib-QRCode` `v0.1.0` (`870,446` bytes): `https://github.com/HuxerUI/Lib-QRCode/archive/refs/tags/v0.1.0.tar.gz` — SHA256 verified twice: `8cee876321cdcaa44362342d1990036faf2bd57cea069d9e725f3563907f2d40` +- **Feature Evaluation**: + - None of the three upstream manifests defines optional `[features]` or `[feature-deps.*]`. Each exposes its single default library/module target cleanly. +- **Automatic Updates**: + - All three descriptors declare `extensions.autoupdate` with `tag = "v${version}"` and `url = "https://github.com/HuxerUI//archive/refs/tags/${tag}.tar.gz"`. + +## Workspace Test Members + +All three members use `[indices] huxerui = { path = "../../.." }` and `standard = "c++23"`, matching `tests/examples/huxerui-module` (`huxerui.huxerui = "0.5.5"`), and run headless C++23 module tests without opening a GUI window: + +1. `tests/examples/huxerui-interaction` (`huxerui.interaction = "0.2.0"`): + - Verifies unbound controllers, pipeable `ViewAdaptor`s (`operator|`, `operator&` via `huxerui.interaction.operators`), and out-of-line `std::invalid_argument` validation across subgroups. +2. `tests/examples/huxerui-markdown` (`huxerui.markdown = "0.3.1"`): + - Verifies `macros::HUXERUI_MARKDOWN_SOURCE_MAPPING == 1` (`modules/macros.cppm`), GitHub-flavored AST + source range resolution, incremental parse sessions, streaming output, link policy, and `Markdown(doc)` view construction. +3. `tests/examples/huxerui-qrcode` (`huxerui.qrcode = "0.1.0"`): + - Verifies `Encode`/`ToSvg`/`Rasterize`/`Decode`/`DecodeAll` round-trips across QR Code, Code128, DataMatrix, Aztec, and PDF417, declarative `QRCode`/`Barcode` views, and out-of-line `std::invalid_argument` exception paths. + +## Local Verification (`mcpp 2026.11.23.1`, `gcc@16.2.0`) + +- **Descriptor Lints & Parser**: + - Passed `lua5.4` syntax checks (with a temporary `lua5.4 -> /usr/bin/lua` 5.4.8 symlink on `PATH`), `check_mirror_urls.lua`, `check_package_name.lua`, `check_reserved_namespace.lua`, `check_mplugin_layout.lua`, `check_capability_providers.lua`, `check_cross_package_refs.lua`, `check_platform_version_parity.lua`, `check_duplicate_versions.lua`, `check_quill_install.lua`, `tools/platform_rows.py check`, `test_check_mplugin.py` (12/12), `test_check_capability_providers.py` (8/8), `tests/openkal/compat.py selftest` (32/32), `tests/red_members.py selftest` (6/6), and `mcpp xpkg parse` across all `pkgs/*/*.lua` (all three new descriptors report `form A`, `parse OK`). +- **Selective Member Selection**: + - `python3 tests/select_members.py --base upstream/main pkgs/h/huxerui.interaction.lua pkgs/h/huxerui.markdown.lua pkgs/h/huxerui.qrcode.lua` selected `huxerui-interaction huxerui-markdown huxerui-qrcode`. +- **Consumer Member Runs (`tests/run_members.sh`)**: + - `huxerui-interaction`: `runtime ... ok (0.01s)`, `1 passed; 0 failed` (`42.85s` total; downloaded directly from `github.com` with `XLINGS_MIRROR_FALLBACK=off`, `XLINGS_ADAPTIVE_MIRROR=off`, `XLINGS_DOWNLOAD_CONNECT_TIMEOUT=5` to bypass stalled CN ghproxy/kkgithub endpoints). + - `huxerui-markdown`: `module_smoke: ok`, `runtime ... ok (0.01s)`, `1 passed; 0 failed` (`33.27s` total). + - `huxerui-qrcode`: `qrcode module_smoke: ok`, `runtime ... ok (0.06s)`, `1 passed; 0 failed` (`133.38s` total). + - Workspace lockfile verified resolution of `huxerui.huxerui@0.5.5`, `huxerui.interaction@0.2.0`, `huxerui.markdown@0.3.1`, and `huxerui.qrcode@0.1.0`. +- **Autoupdate Verification (`openxlings/xpkgindex-update` @ `6c0bee29`)**: + - `tests/autoupdate` unit tests (26/26 OK) and `test_mwrap_tag_selection.py` (4/4 OK). + - `tests/autoupdate/ci.py audit --base upstream/main`: `115` updateable GitHub-direct descriptors declared, all existing versions preserved. + - `xpkgindex_update inspect` and authenticated `check` verified `up-to-date` (`0.2.0`, `0.3.1`, `0.1.0`). diff --git a/mcpp.toml b/mcpp.toml index 8d393029..7dac2d2c 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -126,6 +126,9 @@ members = [ "tests/examples/gmp", "tests/examples/gzip-hpp", "tests/examples/huxerui-module", + "tests/examples/huxerui-interaction", + "tests/examples/huxerui-markdown", + "tests/examples/huxerui-qrcode", "tests/examples/gmp-gmpxx", "tests/examples/gsl", "tests/examples/godot-cpp", diff --git a/pkgs/h/huxerui.interaction.lua b/pkgs/h/huxerui.interaction.lua new file mode 100644 index 00000000..eb961b33 --- /dev/null +++ b/pkgs/h/huxerui.interaction.lua @@ -0,0 +1,43 @@ +local versions = { + ["0.2.0"] = { + url = "https://github.com/HuxerUI/Lib-Interaction/archive/refs/tags/v0.2.0.tar.gz", + sha256 = "9ffff3fa6e8bee09a97a766f84af5b4c7dd61f1db6d321d2256ddcc2b32d968d", + }, +} + +-- huxerui.interaction — HuxerUI interactive primitives as a native mcpp module package. +-- +-- Form A: upstream carries its own `mcpp.toml` (`Lib-Interaction-0.2.0/mcpp.toml`) +-- and exports `import huxerui.interaction;` (`modules/interaction.cppm` and +-- `modules/operators.cppm`), depending on `huxerui.huxerui = "0.5.5"` which +-- provides the transitive SDK and platform dependencies. +-- +-- 0.2.0 uses plain upstream GitHub URLs (no CN mcpp-res mirror yet). +package = { + spec = "1", + namespace = "huxerui", + name = "interaction", + description = "Interactive primitives, controllers, feedback modifiers, and visual motion effects for HuxerUI", + licenses = {"MIT"}, + repo = "https://github.com/HuxerUI/Lib-Interaction", + type = "package", + + extensions = { + autoupdate = { + tag = "v${version}", + url = "https://github.com/HuxerUI/Lib-Interaction/archive/refs/tags/${tag}.tar.gz", + }, + }, + + xpm = { + linux = { + ["0.2.0"] = versions["0.2.0"], + }, + macosx = { + ["0.2.0"] = versions["0.2.0"], + }, + windows = { + ["0.2.0"] = versions["0.2.0"], + }, + }, +} diff --git a/pkgs/h/huxerui.markdown.lua b/pkgs/h/huxerui.markdown.lua new file mode 100644 index 00000000..bfbf16e1 --- /dev/null +++ b/pkgs/h/huxerui.markdown.lua @@ -0,0 +1,43 @@ +local versions = { + ["0.3.1"] = { + url = "https://github.com/HuxerUI/Lib-Markdown/archive/refs/tags/v0.3.1.tar.gz", + sha256 = "0e8be37f40b0377bec57e5354dc3dd1114544db92724eadbb027adf53e1a6f2a", + }, +} + +-- huxerui.markdown — HuxerUI Markdown parser and declarative view component as a native mcpp module package. +-- +-- Form A: upstream carries its own `mcpp.toml` (`Lib-Markdown-0.3.1/mcpp.toml`) +-- with vendored `md4c` (C99) and exports `import huxerui.markdown;` +-- (`modules/markdown.cppm` and `modules/macros.cppm`), depending on +-- `huxerui.huxerui = "0.5.5"` for transitive SDK and platform dependencies. +-- +-- 0.3.1 uses plain upstream GitHub URLs (no CN mcpp-res mirror yet). +package = { + spec = "1", + namespace = "huxerui", + name = "markdown", + description = "Native CommonMark and GFM Markdown parser and declarative view component for HuxerUI", + licenses = {"MIT"}, + repo = "https://github.com/HuxerUI/Lib-Markdown", + type = "package", + + extensions = { + autoupdate = { + tag = "v${version}", + url = "https://github.com/HuxerUI/Lib-Markdown/archive/refs/tags/${tag}.tar.gz", + }, + }, + + xpm = { + linux = { + ["0.3.1"] = versions["0.3.1"], + }, + macosx = { + ["0.3.1"] = versions["0.3.1"], + }, + windows = { + ["0.3.1"] = versions["0.3.1"], + }, + }, +} diff --git a/pkgs/h/huxerui.qrcode.lua b/pkgs/h/huxerui.qrcode.lua new file mode 100644 index 00000000..809fd67b --- /dev/null +++ b/pkgs/h/huxerui.qrcode.lua @@ -0,0 +1,43 @@ +local versions = { + ["0.1.0"] = { + url = "https://github.com/HuxerUI/Lib-QRCode/archive/refs/tags/v0.1.0.tar.gz", + sha256 = "8cee876321cdcaa44362342d1990036faf2bd57cea069d9e725f3563907f2d40", + }, +} + +-- huxerui.qrcode — HuxerUI QR code and barcode package as a native mcpp module package. +-- +-- Form A: upstream carries its own `mcpp.toml` (`Lib-QRCode-0.1.0/mcpp.toml`) +-- and `build.mcpp` (vendored ZXing 3.1.1 sources + Version.h generation) and +-- exports `import huxerui.qrcode;` (`modules/qrcode.cppm`), depending on +-- `huxerui.huxerui = "0.5.5"` for transitive SDK and platform dependencies. +-- +-- 0.1.0 uses plain upstream GitHub URLs (no CN mcpp-res mirror yet). +package = { + spec = "1", + namespace = "huxerui", + name = "qrcode", + description = "QR code and barcode generation, declarative HuxerUI views, and multi-format image decoding", + licenses = {"MIT"}, + repo = "https://github.com/HuxerUI/Lib-QRCode", + type = "package", + + extensions = { + autoupdate = { + tag = "v${version}", + url = "https://github.com/HuxerUI/Lib-QRCode/archive/refs/tags/${tag}.tar.gz", + }, + }, + + xpm = { + linux = { + ["0.1.0"] = versions["0.1.0"], + }, + macosx = { + ["0.1.0"] = versions["0.1.0"], + }, + windows = { + ["0.1.0"] = versions["0.1.0"], + }, + }, +} diff --git a/tests/examples/huxerui-interaction/mcpp.toml b/tests/examples/huxerui-interaction/mcpp.toml new file mode 100644 index 00000000..e4205796 --- /dev/null +++ b/tests/examples/huxerui-interaction/mcpp.toml @@ -0,0 +1,10 @@ +[indices] +huxerui = { path = "../../.." } + +[package] +name = "huxerui-interaction-tests" +version = "0.1.0" +standard = "c++23" + +[dependencies.huxerui] +interaction = "0.2.0" diff --git a/tests/examples/huxerui-interaction/tests/runtime.cpp b/tests/examples/huxerui-interaction/tests/runtime.cpp new file mode 100644 index 00000000..f972479c --- /dev/null +++ b/tests/examples/huxerui-interaction/tests/runtime.cpp @@ -0,0 +1,87 @@ +// Headless C++23 module consumer test for huxerui.interaction. +// Verifies package resolution, transitive huxerui.huxerui linking, pipe/mask +// operators exported via huxerui.interaction.operators, and out-of-line +// std::invalid_argument validation across the module boundary. +import std; +import huxerui.interaction; + +using namespace huxerui; +using namespace huxerui::interaction; + +namespace { + +template +bool ThrowsInvalidArgument(Fn&& fn) { + try { + fn(); + } catch (const std::invalid_argument&) { + return true; + } + return false; +} + +} // namespace + +int main() { + bool ok = true; + + // 1. Default-constructed unbound controllers across gesture/overlay/scroll/accessibility subgroups + ok = ok && (SwipeController{} == SwipeController{}) && !static_cast(SwipeController{}); + ok = ok && (PanZoomController{} == PanZoomController{}); + ok = ok && (HoverCardController{} == HoverCardController{}); + ok = ok && (PopoverController{} == PopoverController{}) && !static_cast(PopoverController{}); + ok = ok && (RovingFocusController{} == RovingFocusController{}) && !static_cast(RovingFocusController{}); + ok = ok && !RovingFocusController{}.FocusIndex(0); + ok = ok && !RovingFocusController{}.FocusNext(); + ok = ok && (ScrollToTopController{} == ScrollToTopController{}) && !static_cast(ScrollToTopController{}); + ok = ok && (CompareSliderController{} == CompareSliderController{}) && !static_cast(CompareSliderController{}); + ok = ok && (RadialDialController{} == RadialDialController{}) && !static_cast(RadialDialController{}); + ok = ok && (PredictiveBackController{} == PredictiveBackController{}) && !static_cast(PredictiveBackController{}); + + // 2. Construct valid Views and pipeable ViewAdaptors across press, hover, gesture, reorder, + // dragdrop, overlay, scroll, accessibility, and visual subgroups (no #include of library headers) + View composed = Text("interaction-smoke") + .With(Ripple{}, Spotlight{}, HoverHighlight{}, Shimmer{}) + | Pressable([] {}) + | HoverLift() + | DoubleClickable([](const MultiTapEvent&) {}) + | ContextMenuArea([](Point) {}) + | KeyboardShortcut({.key = Key::K}, [] {}) + | BackHandler([] {}) + | RovingFocusItem(0) + | RovingFocusGroup() + | Copyable("hello") + | Popover([](PopupContext) { return Text("popover"); }) + | Expandable(true) + | Appear() + | DropZone([](int v) { return v > 0; }); + ok = ok && static_cast(composed); + + ok = ok && static_cast(InteractiveSurface([](const InteractionSnapshot&) { return Text("surface"); })); + ok = ok && static_cast(Hoverable([](bool) { return Text("hoverable"); })); + ok = ok && static_cast(CompareSlider(Text("before"), Text("after"))); + ok = ok && static_cast(RadialDial()); + ok = ok && static_cast(SwipeActions(Text("row"), [](SwipeActionContext) { return Text("act"); })); + ok = ok && static_cast(Reorderable({Text("a"), Text("b")})); + ok = ok && static_cast(RollingNumber(42)); + ok = ok && static_cast(HoverCard(Text("anchor"), [](PopupContext) { return Text("card"); })); + ok = ok && static_cast(Text("scroll").With(ScrollProgress(ScrollController{}), ScrollEdgeFade(ScrollController{}))); + const SwipeDirectionMask dir_mask = SwipeDirectionMask::Left | SwipeDirectionMask::Right; + ok = ok && ((dir_mask & SwipeDirectionMask::Left) == SwipeDirectionMask::Left); + ok = ok && HasDirection(dir_mask, SwipeDirectionMask::Right); + + // 3. Call out-of-line validation paths across subgroups (must throw std::invalid_argument) + ok = ok && ThrowsInvalidArgument([] { (void)InteractiveSurface({}); }); + ok = ok && ThrowsInvalidArgument([] { (void)Pressable(Text("x"), {.hovered_scale = 0.0F}); }); + ok = ok && ThrowsInvalidArgument([] { (void)HoverLift(Text("x"), {.hovered_scale = -1.0F}); }); + ok = ok && ThrowsInvalidArgument([] { (void)Text("x").With(Ripple{RippleStyle{.duration = 0.0}}); }); + ok = ok && ThrowsInvalidArgument([] { (void)Copyable(std::function{}, "text"); }); + ok = ok && ThrowsInvalidArgument([] { (void)Popover(Text("x"), std::function{}); }); + ok = ok && ThrowsInvalidArgument([] { (void)HoverCard(Text("x"), std::function{}); }); + ok = ok && ThrowsInvalidArgument([] { (void)RollingNumber(0, {.minimum_digits = -1}); }); + ok = ok && ThrowsInvalidArgument([] { + (void)SwipeActions(Text("row"), [](SwipeActionContext) { return Text("act"); }, {.action_extent = 0.0F}); + }); + + return ok ? 0 : 1; +} diff --git a/tests/examples/huxerui-markdown/mcpp.toml b/tests/examples/huxerui-markdown/mcpp.toml new file mode 100644 index 00000000..e7c61248 --- /dev/null +++ b/tests/examples/huxerui-markdown/mcpp.toml @@ -0,0 +1,10 @@ +[indices] +huxerui = { path = "../../.." } + +[package] +name = "huxerui-markdown-tests" +version = "0.1.0" +standard = "c++23" + +[dependencies.huxerui] +markdown = "0.3.1" diff --git a/tests/examples/huxerui-markdown/tests/runtime.cpp b/tests/examples/huxerui-markdown/tests/runtime.cpp new file mode 100644 index 00000000..63bb1cba --- /dev/null +++ b/tests/examples/huxerui-markdown/tests/runtime.cpp @@ -0,0 +1,87 @@ +// Headless C++23 module consumer test for huxerui.markdown. +// Verifies mapped macros (modules/macros.cppm), md4c C99 compilation, CommonMark/GFM +// AST + incremental parsing, source range mapping, and HuxerUI declarative Markdown views. +import std; +import huxerui.markdown; + +int main() { + using namespace huxerui::markdown; + + int failures = 0; + const auto check = [&](bool cond, std::string_view label) { + if (!cond) { + std::cerr << "FAILED: " << label << '\n'; + ++failures; + } + }; + + // Mapped public macro from modules/macros.cppm (re-exported by huxerui.markdown). + check(macros::HUXERUI_MARKDOWN_SOURCE_MAPPING == 1, "macro HUXERUI_MARKDOWN_SOURCE_MAPPING == 1"); + + // Out-of-line ParseMarkdown + ParseOptions::GitHub + AST / source mapping verification. + auto opts = ParseOptions::GitHub(); + opts.track_source_positions = true; + opts.highlight = true; + + const std::string_view source = + "# Title\n\n" + "Hello **world** ==mark== [link](https://example.com).\n\n" + "- [x] Done\n" + "- [ ] Todo\n\n" + "| A | B |\n" + "|---|---|\n" + "| 1 | 2 |\n"; + + const MarkdownDocument doc = ParseMarkdown(source, opts); + const MarkdownNode& root = doc.Root(); + check(root.kind == NodeKind::Document, "root is Document"); + check(root.children.size() == 4, "4 top-level blocks"); + check(root.children[0].kind == NodeKind::Heading, "block 0 is Heading"); + check(root.children[0].heading_level == 1, "heading_level == 1"); + check(PlainText(root.children[0]) == "Title", "heading PlainText"); + check(root.children[1].kind == NodeKind::Paragraph, "block 1 is Paragraph"); + check(root.children[2].kind == NodeKind::UnorderedList, "block 2 is UnorderedList"); + check(root.children[2].children.size() == 2, "2 list items"); + check(root.children[2].children[0].task_checked == true, "task 0 checked"); + check(root.children[2].children[1].task_checked == false, "task 1 unchecked"); + check(root.children[3].kind == NodeKind::Table, "block 3 is Table"); + + const std::string plain = doc.PlainText(); + check(plain.find("Title") != std::string::npos, "PlainText contains Title"); + check(plain.find("world") != std::string::npos, "PlainText contains world"); + + const MarkdownMappedText mapped = PlainTextWithSource(root.children[0]); + check(mapped.text == "Title", "PlainTextWithSource heading"); + const auto ranges = ResolveMarkdownSourceRanges(mapped.text, mapped.source_segments, 0, mapped.text.size()); + check(ranges.has_value() && !ranges->empty(), "ResolveMarkdownSourceRanges non-empty"); + + // Out-of-line incremental parse session & streaming APIs. + std::string large; + for (int i = 0; i < 60; ++i) + large += "## Section " + std::to_string(i) + "\n\nParagraph **bold**.\n\n"; + MarkdownParseSession session(ParseOptions::CommonMark()); + (void)session.Update(large); + check(session.LastParseStats().mode == MarkdownParseMode::Full, "initial session update is Full"); + (void)session.Append("New tail text\n"); + check(session.LastParseStats().mode == MarkdownParseMode::Incremental, "append on large doc is Incremental"); + check(session.Document().PlainText().ends_with("New tail text"), "session tail text matches"); + + MarkdownStream stream; + (void)stream.Append("Stream "); + const MarkdownDocument finished = stream.Finish(); + check(stream.IsFinished(), "stream finished"); + check(finished.PlainText() == "Stream", "stream PlainText matches"); + + // Out-of-line link policy & HuxerUI theme/view integration (also verifies export import huxerui). + check(IsDefaultLinkAllowed("https://example.com"), "https link allowed"); + check(!IsDefaultLinkAllowed("javascript:alert(1)"), "javascript link rejected"); + + const MarkdownStyle style = MarkdownStyle::FromTheme(huxerui::MaterialDarkThemeSpec()); + check(style.body.foreground == huxerui::MaterialDarkThemeSpec().colors.on_surface, "FromTheme matches surface"); + + const huxerui::View rendered = Markdown(doc); + check(static_cast(rendered), "Markdown(doc) valid view"); + + std::cout << "module_smoke: " << (failures == 0 ? "ok" : "FAILED") << '\n'; + return failures == 0 ? 0 : 1; +} diff --git a/tests/examples/huxerui-qrcode/mcpp.toml b/tests/examples/huxerui-qrcode/mcpp.toml new file mode 100644 index 00000000..92247d50 --- /dev/null +++ b/tests/examples/huxerui-qrcode/mcpp.toml @@ -0,0 +1,10 @@ +[indices] +huxerui = { path = "../../.." } + +[package] +name = "huxerui-qrcode-tests" +version = "0.1.0" +standard = "c++23" + +[dependencies.huxerui] +qrcode = "0.1.0" diff --git a/tests/examples/huxerui-qrcode/tests/runtime.cpp b/tests/examples/huxerui-qrcode/tests/runtime.cpp new file mode 100644 index 00000000..b0309702 --- /dev/null +++ b/tests/examples/huxerui-qrcode/tests/runtime.cpp @@ -0,0 +1,97 @@ +// Headless C++23 module consumer test for huxerui.qrcode. +// Verifies vendored ZXing 3.1.1 + generated Version.h compilation, QR/1D/2D +// encode-SVG-rasterize-decode round-trips, HuxerUI view construction, and +// std::invalid_argument exceptions across the module boundary. +import std; +import huxerui.qrcode; + +int main() { + using namespace huxerui::qrcode; + + bool ok = true; + const auto check = [&](bool cond, std::string_view label) { + if (!cond) { + std::cerr << "FAILED: " << label << '\n'; + ok = false; + } + }; + + // 1. Format queries (out-of-line in src/codec.cpp) + check(FormatName(BarcodeFormat::QRCode) == "QR Code", "FormatName(QRCode)"); + check(CanEncode(BarcodeFormat::QRCode), "CanEncode(QRCode)"); + check(CanDecode(BarcodeFormat::QRCode), "CanDecode(QRCode)"); + check(!CanEncode(BarcodeFormat::MicroQRCode), "!CanEncode(MicroQRCode)"); + check(CanDecode(BarcodeFormat::MicroQRCode), "CanDecode(MicroQRCode)"); + + // 2. Encode QR Code -> SVG -> Rasterize -> Decode round-trip (out-of-line in src/codec.cpp) + const std::string_view payload = "https://github.com/HuxerUI/Lib-QRCode"; + const Symbol symbol = Encode(payload, { + .format = BarcodeFormat::QRCode, + .qr_error_correction = ErrorCorrection::High, + .quiet_zone = 4, + }); + check(symbol.Format() == BarcodeFormat::QRCode, "symbol.Format() == QRCode"); + check(symbol.Width() > 0 && symbol.Width() == symbol.Height(), "square QR dimensions"); + check(symbol.Modules().size() == static_cast(symbol.Width()) * symbol.Height(), + "symbol.Modules().size()"); + check(!symbol.IsDark(0, 0), "quiet zone corner is light"); + + const std::string svg = symbol.ToSvg({.scale = 4, .foreground = 0x112233, .background = 0xFFFFFF}); + check(svg.starts_with(""), "SVG footer"); + check(svg.find("#112233") != std::string::npos, "SVG foreground color"); + + const GrayImage raster = symbol.Rasterize(4); + check(raster.width == symbol.Width() * 4 && raster.height == symbol.Height() * 4, "raster dimensions"); + + const std::optional decoded = Decode(raster.View(), {.formats = {BarcodeFormat::QRCode}}); + check(decoded.has_value(), "Decode() returned result"); + if (decoded) { + check(decoded->format == BarcodeFormat::QRCode, "decoded format == QRCode"); + check(decoded->text == payload, "decoded text matches payload"); + check(decoded->error_correction == "H", "decoded ECC == H"); + check(!decoded->bytes.empty(), "decoded bytes non-empty"); + } + + const std::vector all = DecodeAll(raster.View()); + check(all.size() == 1 && all[0].text == payload, "DecodeAll() matches single QR"); + + // 3. Linear & 2D symbologies compiled from ZXing OLD writers + readers + for (auto fmt : {BarcodeFormat::Code128, BarcodeFormat::DataMatrix, BarcodeFormat::Aztec, BarcodeFormat::PDF417}) { + const Symbol sym = Encode("HUXERUI-2026", {.format = fmt}); + const GrayImage img = sym.Rasterize(3); + const auto res = Decode(img.View(), {.formats = {fmt}}); + check(res.has_value() && res->format == fmt && res->text == "HUXERUI-2026", FormatName(fmt)); + } + + // 4. Out-of-line HuxerUI View constructors (src/qrcode.cpp + exported huxerui::View) + const huxerui::View qr_view = QRCode(symbol, { + .foreground = huxerui::Color::Black(), + .background = huxerui::Color::White(), + }).With(huxerui::Frame{.width = 200.0F, .height = 200.0F}); + check(static_cast(qr_view), "QRCode(Symbol) produced valid View"); + + const huxerui::View bar_view = Barcode("HUXERUI-2026", {.format = BarcodeFormat::Code128}) + .With(huxerui::Frame{.width = 320.0F, .height = 100.0F}); + check(static_cast(bar_view), "Barcode(text) produced valid View"); + + // 5. Exception paths across module boundary + bool threw_empty = false; + try { + static_cast(Encode("")); + } catch (const std::invalid_argument&) { + threw_empty = true; + } + check(threw_empty, "Encode(\"\") throws std::invalid_argument"); + + bool threw_wrong_fmt = false; + try { + static_cast(QRCode(Encode("123456", {.format = BarcodeFormat::Code128}))); + } catch (const std::invalid_argument&) { + threw_wrong_fmt = true; + } + check(threw_wrong_fmt, "QRCode(Code128 symbol) throws std::invalid_argument"); + + std::cout << "qrcode module_smoke: " << (ok ? "ok" : "FAILED") << '\n'; + return ok ? 0 : 1; +}