summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2018-09-27 11:38:53 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2018-09-27 11:38:53 -0400
commit98a763c2e4d75bfb2d59738826f992d56a0d03c7 (patch)
tree0610d46f9256a4a3b9725a9d6ada1ea907cc6f5b /tests
parent1148a1227d98e7b461783a009013ba3829eb8f9b (diff)
downloadcmd2-git-98a763c2e4d75bfb2d59738826f992d56a0d03c7.tar.gz
Added unit tests for MacroArg regular expressions
Diffstat (limited to 'tests')
-rw-r--r--tests/test_parsing.py93
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/test_parsing.py b/tests/test_parsing.py
index 9cf9429a..15da9b7a 100644
--- a/tests/test_parsing.py
+++ b/tests/test_parsing.py
@@ -754,3 +754,96 @@ def test_statement_is_immutable():
statement.args = 'bar'
with pytest.raises(attr.exceptions.FrozenInstanceError):
statement.raw = 'baz'
+
+
+def test_macro_normal_arg_pattern():
+ # This pattern matches digits surrounded by exactly 1 brace on a side and 1 or more braces on the opposite side
+ from cmd2.parsing import MacroArg
+ pattern = MacroArg.macro_normal_arg_pattern
+
+ # Valid strings
+ matches = pattern.findall('{5}')
+ assert matches == ['{5}']
+
+ matches = pattern.findall('{233}')
+ assert matches == ['{233}']
+
+ matches = pattern.findall('{{{{{4}')
+ assert matches == ['{4}']
+
+ matches = pattern.findall('{2}}}}}')
+ assert matches == ['{2}']
+
+ matches = pattern.findall('{3}{4}{5}')
+ assert matches == ['{3}', '{4}', '{5}']
+
+ matches = pattern.findall('{3} {4} {5}')
+ assert matches == ['{3}', '{4}', '{5}']
+
+ matches = pattern.findall('{3} {{{4} {5}}}}')
+ assert matches == ['{3}', '{4}', '{5}']
+
+ matches = pattern.findall('{3} text {4} stuff {5}}}}')
+ assert matches == ['{3}', '{4}', '{5}']
+
+ # Invalid strings
+ matches = pattern.findall('5')
+ assert not matches
+
+ matches = pattern.findall('{5')
+ assert not matches
+
+ matches = pattern.findall('5}')
+ assert not matches
+
+ matches = pattern.findall('{{5}}')
+ assert not matches
+
+ matches = pattern.findall('{5text}')
+ assert not matches
+
+def test_macro_escaped_arg_pattern():
+ # This pattern matches digits surrounded by 2 or more braces on both sides
+ from cmd2.parsing import MacroArg
+ pattern = MacroArg.macro_escaped_arg_pattern
+
+ # Valid strings
+ matches = pattern.findall('{{5}}')
+ assert matches == ['{{5}}']
+
+ matches = pattern.findall('{{233}}')
+ assert matches == ['{{233}}']
+
+ matches = pattern.findall('{{{{{4}}')
+ assert matches == ['{{4}}']
+
+ matches = pattern.findall('{{2}}}}}')
+ assert matches == ['{{2}}']
+
+ matches = pattern.findall('{{3}}{{4}}{{5}}')
+ assert matches == ['{{3}}', '{{4}}', '{{5}}']
+
+ matches = pattern.findall('{{3}} {{4}} {{5}}')
+ assert matches == ['{{3}}', '{{4}}', '{{5}}']
+
+ matches = pattern.findall('{{3}} {{{4}} {{5}}}}')
+ assert matches == ['{{3}}', '{{4}}', '{{5}}']
+
+ matches = pattern.findall('{{3}} text {{4}} stuff {{5}}}}')
+ assert matches == ['{{3}}', '{{4}}', '{{5}}']
+
+ # Invalid strings
+ matches = pattern.findall('5')
+ assert not matches
+
+ matches = pattern.findall('{{5')
+ assert not matches
+
+ matches = pattern.findall('5}}')
+ assert not matches
+
+ matches = pattern.findall('{5}')
+ assert not matches
+
+ matches = pattern.findall('{{5text}}')
+ assert not matches