Skip to content

Commit b92cc73

Browse files
committed
tests/test_options.py(feat): Add inherited array marker preservation tests
why: Ensure explode_arrays correctly preserves the "*" marker for inherited array options (e.g., "status-format[0]*" → "status-format*"), consistent with scalar inherited options. what: - Add ExplodeArraysInheritedCase NamedTuple for parametrized tests - Add 3 test cases: inherited arrays, non-inherited arrays, mixed indices - Import explode_arrays function for direct unit testing
1 parent 39d20cc commit b92cc73

File tree

1 file changed

+77
-1
lines changed

1 file changed

+77
-1
lines changed

tests/test_options.py

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from libtmux.common import has_gte_version
2020
from libtmux.constants import OptionScope
2121
from libtmux.exc import OptionError
22-
from libtmux.options import TerminalOverrides, convert_values
22+
from libtmux.options import TerminalOverrides, convert_values, explode_arrays
2323
from libtmux.pane import Pane
2424

2525
if t.TYPE_CHECKING:
@@ -1418,3 +1418,79 @@ def test_show_option_indexed_array(
14181418
assert not isinstance(result, SparseArray), (
14191419
f"Expected single value for '{test_case.option}', got SparseArray"
14201420
)
1421+
1422+
1423+
# =============================================================================
1424+
# explode_arrays Inherited Marker Tests
1425+
# =============================================================================
1426+
1427+
1428+
class ExplodeArraysInheritedCase(t.NamedTuple):
1429+
"""Test case for explode_arrays with inherited marker preservation."""
1430+
1431+
test_id: str
1432+
raw_input: dict[str, str | None]
1433+
expected_key: str
1434+
expected_indices: dict[int, str]
1435+
1436+
1437+
EXPLODE_ARRAYS_INHERITED_CASES: list[ExplodeArraysInheritedCase] = [
1438+
ExplodeArraysInheritedCase(
1439+
test_id="inherited_array_marker_preserved",
1440+
raw_input={"status-format[0]*": "fmt0", "status-format[1]*": "fmt1"},
1441+
expected_key="status-format*",
1442+
expected_indices={0: "fmt0", 1: "fmt1"},
1443+
),
1444+
ExplodeArraysInheritedCase(
1445+
test_id="non_inherited_array_no_marker",
1446+
raw_input={"status-format[0]": "fmt0", "status-format[1]": "fmt1"},
1447+
expected_key="status-format",
1448+
expected_indices={0: "fmt0", 1: "fmt1"},
1449+
),
1450+
ExplodeArraysInheritedCase(
1451+
test_id="mixed_inherited_indices",
1452+
raw_input={"opt[0]*": "v0", "opt[5]*": "v5", "opt[10]*": "v10"},
1453+
expected_key="opt*",
1454+
expected_indices={0: "v0", 5: "v5", 10: "v10"},
1455+
),
1456+
]
1457+
1458+
1459+
@pytest.mark.parametrize(
1460+
"test_case",
1461+
[pytest.param(tc, id=tc.test_id) for tc in EXPLODE_ARRAYS_INHERITED_CASES],
1462+
)
1463+
def test_explode_arrays_preserves_inherited_marker(
1464+
test_case: ExplodeArraysInheritedCase,
1465+
) -> None:
1466+
"""Test that explode_arrays preserves the inherited marker (*) for array options.
1467+
1468+
When tmux returns inherited array options with the -A flag, each index includes
1469+
a trailing asterisk (e.g., "status-format[0]*"). The explode_arrays function
1470+
should preserve this marker in the resulting key, producing "status-format*"
1471+
instead of stripping it to just "status-format".
1472+
1473+
This ensures consistency with scalar inherited options, which already preserve
1474+
the "*" marker (e.g., "visual-activity*" stays as "visual-activity*").
1475+
"""
1476+
result = explode_arrays(test_case.raw_input)
1477+
1478+
assert test_case.expected_key in result, (
1479+
f"Expected key '{test_case.expected_key}' not found in result. "
1480+
f"Got keys: {list(result.keys())}"
1481+
)
1482+
1483+
array_value = result[test_case.expected_key]
1484+
# explode_arrays returns SparseArray for most options (dict-like with int keys)
1485+
assert isinstance(array_value, SparseArray), (
1486+
f"Expected SparseArray for array option, got {type(array_value).__name__}"
1487+
)
1488+
1489+
for idx, expected_val in test_case.expected_indices.items():
1490+
assert idx in array_value, (
1491+
f"Expected index {idx} not found in array. "
1492+
f"Got indices: {list(array_value.keys())}"
1493+
)
1494+
assert array_value[idx] == expected_val, (
1495+
f"Value at index {idx}: expected '{expected_val}', got '{array_value[idx]}'"
1496+
)

0 commit comments

Comments
 (0)