@@ -77,32 +77,71 @@ def test_get_commands_from_file():
7777 assert_array_equal (smartdispatch .get_commands_from_file (fileobj ), commands )
7878
7979
80- def test_get_commands_from_arguments ():
81- # Test single unfolded arguments
82- args = [["arg" ]]
83- assert_equal (smartdispatch .get_commands_from_arguments (args ), ["arg" ])
84-
85- args = [["args1_a" , "args1_b" ]]
86- assert_equal (smartdispatch .get_commands_from_arguments (args ), ["args1_a" , "args1_b" ])
87-
88- # Test multiple unfolded arguments
89- args = [["args1" ], ["args2" ]]
90- assert_equal (smartdispatch .get_commands_from_arguments (args ), ["args1 args2" ])
91-
92- args = [["args1_a" , "args1_b" , "args1_c" ], ["args2_a" , "args2_b" ]]
93- assert_equal (smartdispatch .get_commands_from_arguments (args ), ["args1_a args2_a" , "args1_a args2_b" ,
94- "args1_b args2_a" , "args1_b args2_b" ,
95- "args1_c args2_a" , "args1_c args2_b" ])
96-
97-
98- def test_unfold_argument ():
99- # Test simple argument
100- for arg in ["arg1" , "[arg1" ]:
101- assert_array_equal (smartdispatch .unfold_argument (arg ), [arg ])
102-
103- # Test list (space)
104- for arg in ["arg1 arg2" , "arg1 " , " arg1" ]:
105- assert_array_equal (smartdispatch .unfold_argument (arg ), arg .split (" " ))
80+ def test_unfold_command ():
81+ # Test with one argument
82+ cmd = "ls"
83+ assert_equal (smartdispatch .unfold_command (cmd ), ["ls" ])
84+
85+ cmd = "echo 1"
86+ assert_equal (smartdispatch .unfold_command (cmd ), ["echo 1" ])
87+
88+ # Test two arguments
89+ cmd = "echo [1 2]"
90+ assert_equal (smartdispatch .unfold_command (cmd ), ["echo 1" , "echo 2" ])
91+
92+ cmd = "echo test [1 2] yay"
93+ assert_equal (smartdispatch .unfold_command (cmd ), ["echo test 1 yay" , "echo test 2 yay" ])
94+
95+ cmd = "echo test[1 2]"
96+ assert_equal (smartdispatch .unfold_command (cmd ), ["echo test1" , "echo test2" ])
97+
98+ cmd = "echo test[1 2]yay"
99+ assert_equal (smartdispatch .unfold_command (cmd ), ["echo test1yay" , "echo test2yay" ])
100+
101+ # Test multiple folded arguments
102+ cmd = "python my_command.py [0.01 0.000001 0.00000000001] -1 [omicron mu]"
103+ assert_equal (smartdispatch .unfold_command (cmd ), ["python my_command.py 0.01 -1 omicron" ,
104+ "python my_command.py 0.01 -1 mu" ,
105+ "python my_command.py 0.000001 -1 omicron" ,
106+ "python my_command.py 0.000001 -1 mu" ,
107+ "python my_command.py 0.00000000001 -1 omicron" ,
108+ "python my_command.py 0.00000000001 -1 mu" ])
109+
110+ # Test multiple folded arguments and not unfoldable brackets
111+ cmd = "python my_command.py [0.01 0.000001 0.00000000001] -1 \[[42 133,666]\] slow [omicron mu]"
112+ assert_equal (smartdispatch .unfold_command (cmd ), ["python my_command.py 0.01 -1 [42] slow omicron" ,
113+ "python my_command.py 0.01 -1 [42] slow mu" ,
114+ "python my_command.py 0.01 -1 [133,666] slow omicron" ,
115+ "python my_command.py 0.01 -1 [133,666] slow mu" ,
116+ "python my_command.py 0.000001 -1 [42] slow omicron" ,
117+ "python my_command.py 0.000001 -1 [42] slow mu" ,
118+ "python my_command.py 0.000001 -1 [133,666] slow omicron" ,
119+ "python my_command.py 0.000001 -1 [133,666] slow mu" ,
120+ "python my_command.py 0.00000000001 -1 [42] slow omicron" ,
121+ "python my_command.py 0.00000000001 -1 [42] slow mu" ,
122+ "python my_command.py 0.00000000001 -1 [133,666] slow omicron" ,
123+ "python my_command.py 0.00000000001 -1 [133,666] slow mu" ])
124+
125+ # Test multiple different folded arguments
126+ cmd = "python my_command.py [0.01 0.001] -[1:5] slow"
127+ assert_equal (smartdispatch .unfold_command (cmd ), ["python my_command.py 0.01 -1 slow" ,
128+ "python my_command.py 0.01 -2 slow" ,
129+ "python my_command.py 0.01 -3 slow" ,
130+ "python my_command.py 0.01 -4 slow" ,
131+ "python my_command.py 0.001 -1 slow" ,
132+ "python my_command.py 0.001 -2 slow" ,
133+ "python my_command.py 0.001 -3 slow" ,
134+ "python my_command.py 0.001 -4 slow" ])
135+
136+ cmd = "python my_command.py -[1:5] slow [0.01 0.001]"
137+ assert_equal (smartdispatch .unfold_command (cmd ), ["python my_command.py -1 slow 0.01" ,
138+ "python my_command.py -1 slow 0.001" ,
139+ "python my_command.py -2 slow 0.01" ,
140+ "python my_command.py -2 slow 0.001" ,
141+ "python my_command.py -3 slow 0.01" ,
142+ "python my_command.py -3 slow 0.001" ,
143+ "python my_command.py -4 slow 0.01" ,
144+ "python my_command.py -4 slow 0.001" ])
106145
107146
108147def test_replace_uid_tag ():
0 commit comments