diff options
-rwxr-xr-x | cmd2.py | 6 | ||||
-rw-r--r-- | tests/test_transcript.py | 10 |
2 files changed, 11 insertions, 5 deletions
@@ -2341,8 +2341,10 @@ class Cmd2TestCase(unittest.TestCase): # turn through the loop start = second_slash_pos + 1 else: - # no closing slash, treat it all as plain text - regex += re.escape(s[start:]) + # No closing slash, we have to add the first slash, + # and the rest of the text + regex += re.escape(s[start-1:]) + break return regex def _escaped_find(self, regex, s, start, in_regex): diff --git a/tests/test_transcript.py b/tests/test_transcript.py index 9928be15..5092a2cd 100644 --- a/tests/test_transcript.py +++ b/tests/test_transcript.py @@ -310,14 +310,18 @@ def test_transcript(request, capsys, filename, feedback_to_output): @pytest.mark.parametrize('expected, transformed', [ ( 'text with no slashes', 'text\ with\ no\ slashes' ), + # stuff with just one slash + ( 'use 2/3 cup', 'use\ 2\/3\ cup' ), + ( '/tmp is nice', '\/tmp\ is\ nice'), + ( 'slash at end/', 'slash\ at\ end\/'), + # regexes ( 'specials .*', 'specials\ \.\*' ), ( '/.*/', '.*' ), - ( 'use 2\/3 cup', 'use\ 2\/3\ cup' ), ( 'specials ^ and + /[0-9]+/', 'specials\ \^\ and\ \+\ [0-9]+' ), - ( '/a{6}/ but not a{6} with /.*?/ more', 'a{6}\ but\ not\ a\{6\}\ with\ .*?\ more' ), + ( '/a{6}/ but not \/a{6} with /.*?/ more', 'a{6}\ but\ not\ \/a\{6\}\ with\ .*?\ more' ), ( 'not this slash\/ or this one\/', 'not\ this\ slash\\/\ or\ this\ one\\/' ), ( 'not \/, use /\|?/, not \/', 'not\ \\/\,\ use\ \|?\,\ not\ \\/' ), - # inception: we have a slashes in our regex: backslashed on input, bare on output + # inception: slashes in our regex. backslashed on input, bare on output ( 'not \/, use /\/?/, not \/', 'not\ \\/\,\ use\ /?\,\ not\ \\/' ), ( 'the /\/?/ more /.*/ stuff', 'the\ /?\ more\ .*\ stuff' ), ]) |