Files
tuimble/tests/test_history.py
Username 7c57e03e6d test: add InputHistory unit tests
Covers empty history, push/up/down navigation, draft preservation,
boundary clamping, and full navigation cycle.
2026-02-24 16:37:59 +01:00

95 lines
2.2 KiB
Python

"""Tests for InputHistory."""
from tuimble.app import InputHistory
def test_empty_history_up_returns_none():
h = InputHistory()
assert h.up("current") is None
def test_empty_history_down_returns_none():
h = InputHistory()
assert h.down() is None
def test_push_then_up_returns_last():
h = InputHistory()
h.push("hello")
assert h.up("draft") == "hello"
def test_up_twice_with_single_entry_stays():
h = InputHistory()
h.push("one")
assert h.up("draft") == "one"
assert h.up("draft") == "one" # no older entry, stays put
def test_up_navigates_backwards():
h = InputHistory()
h.push("first")
h.push("second")
h.push("third")
assert h.up("draft") == "third"
assert h.up("draft") == "second"
assert h.up("draft") == "first"
assert h.up("draft") == "first" # clamped at oldest
def test_down_navigates_forward():
h = InputHistory()
h.push("first")
h.push("second")
h.push("third")
h.up("draft") # -> third
h.up("draft") # -> second
assert h.down() == "third"
def test_down_past_end_restores_draft():
h = InputHistory()
h.push("one")
h.up("my draft") # -> one
result = h.down() # -> back to draft
assert result == "my draft"
def test_down_without_prior_up_returns_none():
h = InputHistory()
h.push("one")
assert h.down() is None
def test_push_resets_navigation():
h = InputHistory()
h.push("first")
h.up("draft") # -> first
h.push("second")
# After push, navigation resets -- up should go to newest
assert h.up("new draft") == "second"
def test_up_preserves_current_as_draft():
"""First up() saves current input; down past end restores it."""
h = InputHistory()
h.push("old")
h.up("typing in progress")
assert h.down() == "typing in progress"
def test_full_cycle():
"""Push several, navigate to oldest, then back to draft."""
h = InputHistory()
h.push("a")
h.push("b")
h.push("c")
assert h.up("draft") == "c"
assert h.up("draft") == "b"
assert h.up("draft") == "a"
assert h.down() == "b"
assert h.down() == "c"
assert h.down() == "draft"
assert h.down() is None # already at draft