-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_markdownanchormaker.py
executable file
·110 lines (91 loc) · 3.87 KB
/
test_markdownanchormaker.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env python3
import unittest
from markdownanchormaker import get_pretty_title
from markdownanchormaker import anchor_maker
from markdownanchormaker import replace_spaces_with_dashes
from markdownanchormaker import drop_unwanted_chars
from markdownanchormaker import prepend_octothorpe
from markdownanchormaker import parenthesis_surround
from markdownanchormaker import remove_leading_dashes
from markdownanchormaker import make_lowercase
from markdownanchormaker import output_title_and_link
class TestGetPrettyTitle(unittest.TestCase):
def test_result_not_startswith_octothorpe(self):
"""
Test that result doesn't start with a #; ie the # is removed
"""
data = "# Test Title"
result = get_pretty_title(data)
self.assertRegex(result, r"^[^#]")
def test_handles_multiple_spaces_after_octothorpe(self):
"""
Test that string returned by get_pretty_title() doesn't start with
a space(s). (ie, it can handle multiple spaces after # in a
title, and that those extra spaces are stripped off)
"""
data = "# Title With Extra Whitespace"
result = get_pretty_title(data)
self.assertRegex(result, r"^(?:[^\s]+)")
def test_passed_an_integer(self):
"""
Assert that a TypeError is raised if passed an integer
"""
self.assertRaises(TypeError, get_pretty_title, 2)
class TestAnchorMaker(unittest.TestCase):
def test_replace_spaces_with_dashes(self):
"""
Test that spaces are replaced with dashes
"""
data = "foo bar baz"
result = replace_spaces_with_dashes(data)
# Test that there are no spaces
self.assertNotRegex(result, r"(?= )")
def test_drop_unwanted_chars(self):
data = "- ^Foo* ?baR <baz "
result = drop_unwanted_chars(data)
# Test that there are no "special" characters
self.assertNotRegex(result, r"(?=[!@$%^&*<>\[\]\{\};:\"'])")
def test_prepend_octothorpe(self):
data = "Foo ?baR <baz "
result = prepend_octothorpe(data)
# Test that the string starts with #
self.assertRegex(result, r"^#")
def test_parenthesis_surround(self):
data = "# Test Title"
result = parenthesis_surround(data)
# Test that result starts with ( and ends with )
self.assertRegex(result, r"^\(.*?\)$")
def test_remove_leading_dashes(self):
data = "(#-Foo ?baR <baz "
result = remove_leading_dashes(data)
# Test that the string doesn't contain dashes between (# and first letter
self.assertNotRegex(result, r"^\(#[-]+")
def test_make_lowercase(self):
data = "UPPERCASE"
result = make_lowercase(data)
# Test that the string is all lowercase
self.assertNotRegex(result, r"(?=[A-Z])")
def test_passed_an_integer(self):
"""
Assert that a TypeError is raised if passed an integer
"""
self.assertRaises(TypeError, anchor_maker, 8)
class TestOutputTitleAndLink(unittest.TestCase):
def test_startswith_bracket(self):
data_pretty_part = "[Three Octothorpe Title]"
data_anchor_link = "(#three-octothorpe-title)"
result = output_title_and_link(data_pretty_part, data_anchor_link)
self.assertRegex(result, r"^\[")
def test_endswith_parenthesis_and_two_spaces(self):
# output_title_and_link() adds two spaces at end for Markdown newlines
data_pretty_part = "[Three Octothorpe Title]"
data_anchor_link = "(#three-octothorpe-title)"
result = output_title_and_link(data_pretty_part, data_anchor_link)
self.assertRegex(result, r"\) $")
def test_passed_an_integer(self):
"""
Assert that a TypeError is raised if passed an integer
"""
self.assertRaises(TypeError, anchor_maker, 273, 53)
if __name__ == "__main__":
unittest.main()