Skip to content

Commit abde4c2

Browse files
authored
Merge pull request chubin#318 from chubin/space-tests
Document unit tests and replace + and space handling logic with regexpx
2 parents 0ff765a + 908bc52 commit abde4c2

File tree

4 files changed

+18
-20
lines changed

4 files changed

+18
-20
lines changed

lib/cheat_wrapper.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,10 @@ def _add_section_name(query):
2626
if '/' in query:
2727
return query
2828
if ' ' in query:
29-
delim = " "
30-
elif '+' in query:
31-
delim = "+"
32-
33-
index = 0
34-
length = len(query)
35-
while index != length:
36-
37-
index = query.index(delim, index) + 1
38-
39-
try:
40-
comparison = query.index(delim, index)
41-
except ValueError:
42-
comparison = -1
43-
44-
if (index != comparison and index != length):
45-
return "%s/%s" % (query[:index-1], query[index:])
46-
47-
return query
29+
return re.sub(r' +', '/', query, count=1)
30+
if '+' in query:
31+
# replace only single + to avoid catching g++ and friends
32+
return re.sub(r'([^\+])\+([^\+])', r'\1/\2', query, count=1)
4833

4934
def cheat_wrapper(query, request_options=None, output_format='ansi'):
5035
"""
@@ -53,7 +38,6 @@ def cheat_wrapper(query, request_options=None, output_format='ansi'):
5338
Additional request options specified in `request_options`.
5439
"""
5540

56-
5741
def _rewrite_aliases(word):
5842
if word == ':bash.completion':
5943
return ':bash_completion'

lib/cheat_wrapper_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,19 @@
1313
python/copy+file
1414
python/rosetta/:list
1515
emacs:go-mode/:list
16+
g++g++
1617
"""
1718

1819
split = """
1920
python copy file
2021
python/copy file
2122
23+
python file
24+
python/file
25+
26+
python+file
27+
python/file
28+
2229
g++ -O1
2330
g++/-O1
2431
"""

tests/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
To run unit tests.
2+
3+
python3 -m pytest -v ../lib/
4+
5+
To run input/output tests.
6+
7+
./run-tests.sh

tests/run-tests.sh

100644100755
File mode changed.

0 commit comments

Comments
 (0)