Skip to content

Commit ec97859

Browse files
committed
tests/test_options.py(test): Add test for indexed array option lookup
why: Verify show_option correctly handles bracketed array indices like 'status-format[0]'. Currently returns None instead of the value. what: - Add ShowOptionIndexedTestCase NamedTuple with test_id pattern - Add parametrized test_show_option_indexed_array test - Test verifies indexed query returns value, base name returns SparseArray - Test follows TDD RED phase (currently failing as expected)
1 parent 7c316bf commit ec97859

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

tests/test_options.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,3 +1286,63 @@ def test_show_option_g_parameter_emits_deprecation_warning(
12861286
server = session.server
12871287
with pytest.warns(DeprecationWarning, match=r"g argument is deprecated"):
12881288
server.show_option("buffer-limit", g=True)
1289+
1290+
1291+
# =============================================================================
1292+
# show_option with Indexed Array Tests
1293+
# =============================================================================
1294+
1295+
1296+
class ShowOptionIndexedTestCase(t.NamedTuple):
1297+
"""Test case for show_option with bracketed array index."""
1298+
1299+
test_id: str
1300+
option: str
1301+
expect_sparse_array: bool # True for base name, False for indexed
1302+
1303+
1304+
SHOW_OPTION_INDEXED_TEST_CASES: list[ShowOptionIndexedTestCase] = [
1305+
ShowOptionIndexedTestCase(
1306+
test_id="indexed_returns_value",
1307+
option="status-format[0]",
1308+
expect_sparse_array=False,
1309+
),
1310+
ShowOptionIndexedTestCase(
1311+
test_id="base_name_returns_sparse_array",
1312+
option="status-format",
1313+
expect_sparse_array=True,
1314+
),
1315+
]
1316+
1317+
1318+
@pytest.mark.parametrize(
1319+
"test_case",
1320+
[pytest.param(tc, id=tc.test_id) for tc in SHOW_OPTION_INDEXED_TEST_CASES],
1321+
)
1322+
def test_show_option_indexed_array(
1323+
session: Session,
1324+
test_case: ShowOptionIndexedTestCase,
1325+
) -> None:
1326+
"""Test show_option handles bracketed array indices correctly.
1327+
1328+
When querying an option with a bracketed index (e.g., 'status-format[0]'),
1329+
tmux returns only that specific index's value. When querying the base name
1330+
(e.g., 'status-format'), tmux returns all indexed values.
1331+
1332+
This test verifies libtmux correctly:
1333+
- Returns a single value for indexed queries
1334+
- Returns a SparseArray for base name queries on array options
1335+
"""
1336+
result = session.show_option(test_case.option, global_=True)
1337+
if test_case.expect_sparse_array:
1338+
assert isinstance(result, SparseArray), (
1339+
f"Expected SparseArray for '{test_case.option}', "
1340+
f"got {type(result).__name__}"
1341+
)
1342+
else:
1343+
assert result is not None, (
1344+
f"Expected a value for '{test_case.option}', got None"
1345+
)
1346+
assert not isinstance(result, SparseArray), (
1347+
f"Expected single value for '{test_case.option}', got SparseArray"
1348+
)

0 commit comments

Comments
 (0)