Add the pure MoonBit core: grid, gestures, updater, vdom, app
grid: packing, pinning, resize steps (port of Layout.js and app.py's grid logic). gesture: pointer state machine (tap, long press, drag, release, swipe). updater: release/version parsing and the update decision. vdom: pure virtual DOM with an HTML-text renderer for tests. app: Elm-style Model/Msg/update/view with effects as data, persistence (JSON layout, import of the old WebView build's localStorage), drawer/search, menus, drag and resize. 60 headless tests drive it through pointer input. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
66e8e90da1
commit
28e0284d9b
28 files changed
+4278
No files matched your search
@@ -0,0 +1,66 @@
|
||||
///|
|
||||
test "a tap: down then up without moving" {
|
||||
let g = State::new()
|
||||
assert_eq(
|
||||
g.step(Down(x=10.0, y=10.0, chain=[3, 1])),
|
||||
[Began(chain=[3, 1], x=10.0, y=10.0), Schedule(500, 1)],
|
||||
)
|
||||
assert_eq(g.step(Up(x=11.0, y=10.0)), [Tap(chain=[3, 1]), Release(moved=false, held=false)])
|
||||
}
|
||||
|
||||
///|
|
||||
test "a long press: the timer fires, then the release is not a tap" {
|
||||
let g = State::new()
|
||||
ignore(g.step(Down(x=0.0, y=0.0, chain=[7])))
|
||||
assert_eq(g.step(Hold(1)), [Press(chain=[7])])
|
||||
assert_eq(g.step(Up(x=0.0, y=0.0)), [Release(moved=false, held=true)])
|
||||
}
|
||||
|
||||
///|
|
||||
test "moving past the slop cancels the hold and starts a drag" {
|
||||
let g = State::new()
|
||||
ignore(g.step(Down(x=0.0, y=0.0, chain=[7])))
|
||||
assert_eq(g.step(Move(x=5.0, y=0.0)), [])
|
||||
assert_eq(g.step(Move(x=20.0, y=0.0)), [Drag(x=20.0, y=0.0, x0=0.0, y0=0.0)])
|
||||
assert_eq(g.step(Hold(1)), []) // the stale timer does nothing
|
||||
assert_eq(g.step(Move(x=30.0, y=2.0)), [Drag(x=30.0, y=2.0, x0=0.0, y0=0.0)])
|
||||
assert_eq(g.step(Up(x=30.0, y=2.0)), [Release(moved=true, held=false)])
|
||||
}
|
||||
|
||||
///|
|
||||
test "a press then a drag, then release" {
|
||||
let g = State::new()
|
||||
ignore(g.step(Down(x=0.0, y=0.0, chain=[7])))
|
||||
ignore(g.step(Hold(1)))
|
||||
assert_eq(g.step(Move(x=40.0, y=0.0)), [Drag(x=40.0, y=0.0, x0=0.0, y0=0.0)])
|
||||
assert_eq(g.step(Up(x=40.0, y=0.0)), [Release(moved=true, held=true)])
|
||||
}
|
||||
|
||||
///|
|
||||
test "cancel releases without a tap; stray input is ignored" {
|
||||
let g = State::new()
|
||||
assert_eq(g.step(Up(x=0.0, y=0.0)), [])
|
||||
assert_eq(g.step(Move(x=0.0, y=0.0)), [])
|
||||
ignore(g.step(Down(x=0.0, y=0.0, chain=[1])))
|
||||
assert_eq(g.step(Cancel), [Release(moved=false, held=false)])
|
||||
assert_eq(g.step(Hold(1)), [])
|
||||
}
|
||||
|
||||
///|
|
||||
test "a stale timer from an earlier press is ignored" {
|
||||
let g = State::new()
|
||||
ignore(g.step(Down(x=0.0, y=0.0, chain=[1])))
|
||||
ignore(g.step(Up(x=0.0, y=0.0)))
|
||||
ignore(g.step(Down(x=0.0, y=0.0, chain=[2])))
|
||||
assert_eq(g.step(Hold(1)), [])
|
||||
assert_eq(g.step(Hold(3)), [Press(chain=[2])])
|
||||
}
|
||||
|
||||
///|
|
||||
test "swipes" {
|
||||
assert_eq(classify_swipe(5.0, 100.0, 300), Some(Down))
|
||||
assert_eq(classify_swipe(5.0, -100.0, 300), Some(Up))
|
||||
assert_eq(classify_swipe(5.0, 50.0, 300), None) // too short
|
||||
assert_eq(classify_swipe(120.0, 100.0, 300), None) // more sideways than down
|
||||
assert_eq(classify_swipe(5.0, 100.0, 900), None) // too slow
|
||||
}
|
||||
Reference in new issue
Block a user