t = Token("hello", 0)
assert t.text == "hello"
assert t.index == 0
assert t.metadata is None
t_meta = Token("world", 1, metadata={"confidence": 0.95})
assert t_meta.metadata["confidence"] == 0.95
print("Token tests passed!")Token tests passed!
A single token in the token grid.
Context passed to per-token styling callbacks.
Mutable runtime state for a token selector instance.
s = TokenSelectorState()
assert s.anchor == 0
assert s.focus == 0
assert s.word_count == 0
assert s.active is False
# Mutable
s.anchor = 5
s.focus = 8
s.word_count = 20
assert s.anchor == 5
assert s.focus == 8
# Span selection state
s_span = TokenSelectorState(anchor=3, focus=7, word_count=20)
assert s_span.anchor != s_span.focus
print("TokenSelectorState tests passed!")TokenSelectorState tests passed!