Skip to content

Commit

Permalink
unit tests to validate the behavior with non-string items
Browse files Browse the repository at this point in the history
  • Loading branch information
celina touati authored and celina touati committed Jan 27, 2025
1 parent 39032d3 commit 3e08646
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/prompts/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,38 @@ def test_prompt_show_description():
]
assert ic.pointed_at == 1
assert ic._get_choice_tokens() == expected_tokens


def test_non_string_choices_handling():
"""Test selecting a choice from a list containing non-string items."""
ic = InquirerControl([1, 2.5, True, "String"])

expected_tokens = [
("class:pointer", " » "),
("[SetCursorPosition]", ""),
("class:text", "○ "),
("class:highlighted", "1"),
("", "\n"),
("class:text", " "),
("class:text", "○ "),
("class:text", "2.5"),
("", "\n"),
("class:text", " "),
("class:text", "○ "),
("class:text", "True"),
("", "\n"),
("class:text", " "),
("class:text", "○ "),
("class:text", "String"),
]
assert ic.pointed_at == 0
assert ic._get_choice_tokens() == expected_tokens

ic.select_next()
assert ic.get_pointed_at().value == 2.5

ic.select_next()
assert ic.get_pointed_at().value is True

ic.select_next()
assert ic.get_pointed_at().value == "String"

0 comments on commit 3e08646

Please sign in to comment.