-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.py
30 lines (23 loc) · 1.02 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import re
regex = '!!([^\s]+) ([^!]+)!!'
def replace_all_occurence(text):
return re.sub(regex, r'<div data-method="\1" data-path="\2">\1 \2</div>', text)
def test_one_occurence():
text = '!!GET /foo/bar!!'
m = replace_all_occurence(text)
assert m == '<div data-method="GET" data-path="/foo/bar">GET /foo/bar</div>'
def test_three_occurence():
text = '!!GET /foo/bar!! \n !!POST /foo/bar!! \n !!GET /foo/bar/baz!!'
m = replace_all_occurence(text)
assert m == '<div data-method="GET" data-path="/foo/bar">GET /foo/bar</div> \n <div data-method="POST" data-path="/foo/bar">POST /foo/bar</div> \n <div data-method="GET" data-path="/foo/bar/baz">GET /foo/bar/baz</div>'
def test_real():
text = '''# Welcome to MkDocs
!!GET /foo/bar!!
'''
m = replace_all_occurence(text)
assert m == '# Welcome to MkDocs\n\n <div data-method="GET" data-path="/foo/bar">GET /foo/bar</div>\n'
if __name__ == "__main__":
test_one_occurence()
test_three_occurence()
test_real()
print("Everything passed")