Add optional charset restriction to InputField
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -94,3 +94,30 @@ def test_init_colors_survives_init_pair_rejecting_every_pair():
|
||||
side_effect=_curses.error("init_pair() returned ERR")), \
|
||||
patch.object(_curses, "COLORS", 256, create=True):
|
||||
init_colors() # must not raise
|
||||
|
||||
|
||||
def test_allowed_charset_accepts_listed_characters():
|
||||
f = InputField(MagicMock(), 0, 0, 10, initial="", allowed="0123456789")
|
||||
for ch in "90":
|
||||
f.handle_key(ord(ch))
|
||||
assert f.value == "90"
|
||||
|
||||
|
||||
def test_allowed_charset_drops_other_characters():
|
||||
f = InputField(MagicMock(), 0, 0, 10, initial="", allowed="0123456789")
|
||||
for ch in "9a0-!":
|
||||
f.handle_key(ord(ch))
|
||||
assert f.value == "90"
|
||||
|
||||
|
||||
def test_allowed_none_accepts_everything():
|
||||
f = InputField(MagicMock(), 0, 0, 10, initial="")
|
||||
for ch in "a-1!":
|
||||
f.handle_key(ord(ch))
|
||||
assert f.value == "a-1!"
|
||||
|
||||
|
||||
def test_allowed_charset_still_supports_editing_keys():
|
||||
f = InputField(MagicMock(), 0, 0, 10, initial="90", allowed="0123456789")
|
||||
f.handle_key(_curses.KEY_BACKSPACE)
|
||||
assert f.value == "9"
|
||||
|
||||
Reference in New Issue
Block a user