From 5b2427d52257402de0ed8d2f0203aac48a790623 Mon Sep 17 00:00:00 2001 From: Axel Meyer Date: Thu, 14 May 2026 15:08:45 +0200 Subject: [PATCH] =?UTF-8?q?feat(P.3.6):=20lib-core.selection-test=20v0.1.0?= =?UTF-8?q?=20=E2=80=94=2019=20state=20assertions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- init.lua | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ manifest.core | 6 +++++ manifest.module | 12 +++++++++ 3 files changed, 86 insertions(+) create mode 100644 init.lua create mode 100644 manifest.core create mode 100644 manifest.module diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..1787d3d --- /dev/null +++ b/init.lua @@ -0,0 +1,68 @@ +-- lib-core.selection-test — 19 pure-state assertions for v0.1.0. +-- See meta/docs/superpowers/specs/2026-05-14-p3-6-lib-selection-design.md §5. + +local selection = require("lib-core.selection") +local T = engine.test + +function init(ctx) + -- Register / Unregister (3) + local h1 = selection.register(function() return {x=0, y=0, w=10, h=10} end) + T.assert(h1 ~= nil and h1 >= 1, "register returns positive handle") + T.equals(selection.count_registered(), 1, "count_registered after register") + selection.unregister(h1) + T.equals(selection.count_registered(), 0, "count_registered after unregister") + + -- Re-register for set-tests + local h2 = selection.register(function() return {x=0, y=0, w=10, h=10} end) + local h3 = selection.register(function() return {x=20, y=0, w=10, h=10} end) + local h4 = selection.register(function() return {x=40, y=0, w=10, h=10} end) + + -- Set-Query: initial empty (2) + T.assert(selection.is_empty(), "is_empty after registers (no selection yet)") + T.equals(selection.count(), 0, "count = 0 initially") + + -- Set-Mutation (5) + selection.add(h2) + T.assert(selection.contains(h2), "add → contains") + T.equals(selection.count(), 1, "count = 1 after add") + selection.remove(h2) + T.assert(not selection.contains(h2), "remove → !contains") + selection.toggle(h3); T.assert(selection.contains(h3), "toggle adds when absent") + selection.toggle(h3); T.assert(not selection.contains(h3), "toggle removes when present") + selection.add(h2); selection.add(h4); selection.clear() + T.assert(selection.is_empty(), "clear → empty") + + -- Unregister cleans up selection (1) + selection.add(h2) + selection.unregister(h2) + T.assert(not selection.contains(h2), "unregister removes from selection") + + -- Drag-Threshold (2) + T.equals(selection.drag_threshold(), 4, "default threshold = 4") + selection.set_drag_threshold(8) + T.equals(selection.drag_threshold(), 8, "set_drag_threshold writes") + + -- Drag-State + box_rect (2) + T.equals(selection.drag_state(), "idle", "initial drag_state = idle") + T.assert(selection.box_rect() == nil, "box_rect nil while idle") + + -- Enabled-Flag (2) + T.assert(selection.enabled(), "enabled default true") + selection.set_enabled(false) + T.assert(not selection.enabled(), "set_enabled(false) writes") + selection.set_enabled(true) + + -- Visual-Setters (2) + selection.set_drag_box_color(10, 20, 30, 40) + local c = selection.drag_box_color() + T.assert(c[1]==10 and c[2]==20 and c[3]==30 and c[4]==40, + "set_drag_box_color writes correctly") + selection.set_highlight_color(50, 60, 70, 80) + local hc = selection.highlight_color() + T.assert(hc[1]==50 and hc[2]==60 and hc[3]==70 and hc[4]==80, + "set_highlight_color writes correctly") + + -- Error-Handling (1) + local ok = pcall(function() selection.set_drag_threshold(-1) end) + T.assert(not ok, "set_drag_threshold(-1) errors") +end diff --git a/manifest.core b/manifest.core new file mode 100644 index 0000000..a810e5e --- /dev/null +++ b/manifest.core @@ -0,0 +1,6 @@ +{ + "id": "lib-core.selection-test.core", + "kind": "lib", + "version": "0.1.0", + "license": "Proprietary" +} diff --git a/manifest.module b/manifest.module new file mode 100644 index 0000000..965da8d --- /dev/null +++ b/manifest.module @@ -0,0 +1,12 @@ +{ + "id": "lib-core.selection-test", + "version": "0.1.0", + "kind": "test-module", + "api": "^0.1", + "entry_point": "init.lua", + "deps": [ + { "id": "lib-core.selection", "version": "0.1.0" }, + { "id": "lib-core.input", "version": "0.3.0" }, + { "id": "lib-core.camera", "version": "0.3.0" } + ] +}