Skip to content

Commit a97dbfc

Browse files
committed
Fix argument validation logic
1 parent 865d7f4 commit a97dbfc

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/robotide/validators/__init__.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def _set_window_value(self, value):
7171

7272

7373
class ArgumentTypes(object):
74-
POSITIONAL, NAMED = range(1, 3)
74+
SCALAR, DEFAULT, LIST, DICT = range(1, 5)
7575

7676

7777
class ArgumentsValidator(_AbstractValidator):
@@ -85,19 +85,22 @@ def _validate(self, args_str):
8585
return self._validate_argument_order(types)
8686

8787
def _get_type(self, arg):
88-
if robotapi.is_scalar_var(arg) or robotapi.is_list_var(arg):
89-
return ArgumentTypes.POSITIONAL
90-
elif robotapi.is_scalar_var(arg.split("=")[0]) or \
91-
robotapi.is_dict_var(arg):
92-
return ArgumentTypes.NAMED
88+
if robotapi.is_scalar_var(arg):
89+
return ArgumentTypes.SCALAR
90+
elif robotapi.is_scalar_var(arg.split("=")[0]):
91+
return ArgumentTypes.DEFAULT
92+
elif robotapi.is_list_var(arg):
93+
return ArgumentTypes.LIST
94+
elif robotapi.is_dict_var(arg):
95+
return ArgumentTypes.DICT
9396
else:
9497
raise ValueError
9598

9699
def _validate_argument_order(self, types):
97-
prev = ArgumentTypes.POSITIONAL
100+
prev = ArgumentTypes.SCALAR
98101
for t in types:
99102
if t < prev:
100-
return ('List and scalar arguments must be before'
103+
return ('List and scalar arguments must be before '
101104
'named and dictionary arguments')
102105
prev = t
103106
return None

utest/validators/test_arguments_validation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class Test(unittest.TestCase):
99
validate = ArgumentsValidator()._validate
1010
validation_error = \
11-
'List and scalar arguments must be beforenamed and dictionary arguments'
11+
'List and scalar arguments must be before named and dictionary arguments'
1212

1313
def test_valid_arguments_validation(self):
1414
for arg in [
@@ -18,12 +18,12 @@ def test_valid_arguments_validation(self):
1818
"${arg}=def val",
1919
"${a} | ${b}=d | ${c}=\\| | ${d}=",
2020
"@{list}",
21-
"@{list} | ${arg}",
2221
"${a} | ${b} | @{f}",
2322
"&{dict}",
2423
"${arg} | &{dict}",
2524
"@{list} | &{dict}",
2625
"${a} | ${b} | @{f} | &{dict}",
26+
"${arg}=foo | @{list}"
2727
]:
2828
assert_equals(self.validate(arg), None, arg)
2929

@@ -35,10 +35,10 @@ def test_invalid_arguments_validation(self):
3535
assert_equals(self.validate(arg),
3636
"Invalid argument syntax '%s'" % err)
3737

38-
def test_list_arg_in_incorrect_poition(self):
39-
for arg in ["${arg}=foo | @{list}",
38+
def test_list_arg_in_incorrect_position(self):
39+
for arg in ["@{list} | ${foo}",
4040
"&{dict} | @{list}"]:
41-
assert_equals(self.validate(arg), self.validation_error)
41+
assert_equals(self.validate(arg), self.validation_error, arg)
4242

4343
def test_req_arg_after_defaults(self):
4444
for arg in ["${a}=default | ${a2}",

0 commit comments

Comments
 (0)