Skip to content

Commit 67d8811

Browse files
committed
Added unit tests for folded argument classes.
1 parent 154f4fa commit 67d8811

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

smartdispatch/argument.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22

33

4-
class Argument(object):
4+
class FoldedArgument(object):
55
def __init__(self):
66
self.name = ""
77
self.regex = ""
@@ -10,7 +10,7 @@ def unfold(self, match):
1010
raise NotImplementedError("Subclass must implement this method!")
1111

1212

13-
class EnumerationArgument(object):
13+
class EnumerationFoldedArgument(FoldedArgument):
1414
def __init__(self):
1515
self.name = "enumeration"
1616
self.regex = "\[[^]]*\]"
@@ -19,14 +19,14 @@ def unfold(self, match):
1919
return match[1:-1].split(' ')
2020

2121

22-
class RangeArgument(object):
22+
class RangeFoldedArgument(FoldedArgument):
2323
def __init__(self):
2424
self.name = "range"
25-
self.regex = "\[\d+:\d+(:\d+)?\]"
25+
self.regex = "\[(\d+):(\d+)(?::(\d+))?\]"
2626

2727
def unfold(self, match):
2828
groups = re.search(self.regex, match).groups()
2929
start = int(groups[0])
3030
end = int(groups[1])
3131
step = 1 if groups[2] is None else int(groups[2])
32-
return range(start, end, step)
32+
return map(str, range(start, end, step))

smartdispatch/smartdispatch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import smartdispatch
99
from smartdispatch import utils
10-
from smartdispatch.argument import EnumerationArgument, RangeArgument
10+
from smartdispatch.argument import EnumerationFoldedArgument, RangeFoldedArgument
1111

1212
UID_TAG = "{UID}"
1313

@@ -138,7 +138,7 @@ def unfold_arguments(arguments):
138138
text = utils.escape(" ".join(arguments))
139139

140140
# Order matter, if some regex is more greedy than another, the it should go after
141-
arguments = [RangeArgument(), EnumerationArgument()]
141+
arguments = [RangeFoldedArgument(), EnumerationFoldedArgument()]
142142

143143
# Build the master regex with all argument's regex
144144
regex = "(" + "|".join(["(?P<{0}>{1})".format(arg.name, arg.regex) for arg in arguments]) + ")"

0 commit comments

Comments
 (0)