Improve auto tests by handling nested structures

This commit is contained in:
Adrien Ufferte
2025-08-13 15:07:06 +02:00
parent 9a557d0aad
commit 01f7c2b9c7
2 changed files with 18 additions and 14 deletions
+9 -7
View File
@@ -4,16 +4,18 @@ import sys
def split_params(param_string: str):
"""Split a function parameter string on commas while ignoring brackets."""
"""Split parameters on commas while ignoring nested structures."""
params = []
current = ""
depth = 0
stack = []
pairs = {')': '(', ']': '[', '}': '{'}
for char in param_string:
if char == '[':
depth += 1
elif char == ']':
depth = max(0, depth - 1)
if char == ',' and depth == 0:
if char in '([{':
stack.append(char)
elif char in ')]}':
if stack and stack[-1] == pairs.get(char):
stack.pop()
if char == ',' and not stack:
params.append(current.strip())
current = ""
continue