Fix removing empty elements to avoid trailing commas
This commit is contained in:
+2
-1
@@ -60,7 +60,8 @@ def parse_options(raw: str) -> list[str]:
|
||||
|
||||
# Generate cartesian product
|
||||
for combo in product(*current_block):
|
||||
result.append(", ".join(combo))
|
||||
parts = [p for p in combo if p.strip()]
|
||||
result.append(", ".join(parts) if parts else "")
|
||||
|
||||
elif stripped == "---":
|
||||
if in_combine:
|
||||
|
||||
@@ -43,8 +43,10 @@ def test_combine_three_lists():
|
||||
def test_combine_empty_line_in_list():
|
||||
raw = "@combine\na\n\n---\nb\n@end"
|
||||
result = parse_options(raw)
|
||||
assert ", b" in result # empty + b
|
||||
assert "b" in result
|
||||
assert "a, b" in result
|
||||
# Empty element combined with b gives just "b"
|
||||
assert ", b" not in result
|
||||
|
||||
|
||||
def test_multiple_combine_blocks():
|
||||
|
||||
@@ -75,7 +75,8 @@ const parseOptions = (raw) => {
|
||||
const next = [];
|
||||
for (const a of acc) {
|
||||
for (const b of list) {
|
||||
next.push(a ? `${a}, ${b}` : b);
|
||||
const parts = [a, b].filter((p) => p.trim() !== "");
|
||||
next.push(parts.join(", "));
|
||||
}
|
||||
}
|
||||
return next;
|
||||
|
||||
Reference in New Issue
Block a user