69 lines
2.9 KiB
Lua
69 lines
2.9 KiB
Lua
-- 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
|