///| 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 }