Debian Codegraph @

tests/test_extensions/test_slugs.py

raw
1 """Test slugs."""
2 from .. import util
3 from pymdownx import slugs
4
5
6 class TestUslugify(util.MdCase):
7 """Test Unicode slugs."""
8
9 extension = ['markdown.extensions.toc']
10 extension_configs = {
11 'markdown.extensions.toc': {
12 "slugify": slugs.slugify(case="lower")
13 }
14 }
15
16 def test_slug(self):
17 """Test the slug output."""
18
19 self.check_markdown(
20 r'# Testing unicode-slugs_headers ±♠Ωℑ',
21 r'<h1 id="testing-unicode-slugs_headers-ωℑ">Testing unicode-slugs_headers ±♠Ωℑ</h1>'
22 )
23
24
25 class TestUslugifyEncoded(util.MdCase):
26 """Test Unicode encoded slugs."""
27
28 extension = ['markdown.extensions.toc']
29 extension_configs = {
30 'markdown.extensions.toc': {
31 "slugify": slugs.slugify(case="lower", percent_encode=True)
32 }
33 }
34
35 def test_slug(self):
36 """Test the slug output."""
37
38 self.check_markdown(
39 r'# Testing unicode-slugs_headers ±♠Ωℑ with encoding',
40 r'<h1 id="testing-unicode-slugs_headers-%CF%89%E2%84%91-with-encoding">'
41 'Testing unicode-slugs_headers ±♠Ωℑ with encoding</h1>'
42 )
43
44
45 class TestUslugifyCased(util.MdCase):
46 """Test Unicode cased slugs."""
47
48 extension = ['markdown.extensions.toc']
49 extension_configs = {
50 'markdown.extensions.toc': {
51 "slugify": slugs.slugify()
52 }
53 }
54
55 def test_slug(self):
56 """Test the slug output."""
57
58 self.check_markdown(
59 r'# Testing cased unicode-slugs_headers ±♠Ωℑ',
60 r'<h1 id="Testing-cased-unicode-slugs_headers-Ωℑ">Testing cased unicode-slugs_headers ±♠Ωℑ</h1>'
61 )
62
63
64 class TestUslugifyCasedEncoded(util.MdCase):
65 """Test Unicode cased, encoded slugs."""
66
67 extension = ['markdown.extensions.toc']
68 extension_configs = {
69 'markdown.extensions.toc': {
70 "slugify": slugs.slugify(percent_encode=True)
71 }
72 }
73
74 def test_slug(self):
75 """Test the slug output."""
76
77 self.check_markdown(
78 r'# Testing cased unicode-slugs_headers ±♠Ωℑ with encoding',
79 r'<h1 id="Testing-cased-unicode-slugs_headers-%CE%A9%E2%84%91-with-encoding">'
80 'Testing cased unicode-slugs_headers ±♠Ωℑ with encoding</h1>'
81 )
82
83
84 class TestGFM(util.MdCase):
85 """Test GitHub Flavored Markdown style slugs."""
86
87 extension = ['markdown.extensions.toc']
88 extension_configs = {
89 'markdown.extensions.toc': {
90 "slugify": slugs.slugify(case="lower-ascii")
91 }
92 }
93
94 def test_slug(self):
95 """Test the slug output."""
96
97 self.check_markdown(
98 r'# Testing GFM unicode-slugs_headers ±♠Ωℑ',
99 r'<h1 id="testing-gfm-unicode-slugs_headers-Ωℑ">Testing GFM unicode-slugs_headers ±♠Ωℑ</h1>'
100 )
101
102
103 class TestGFMEncoded(util.MdCase):
104 """Test encoded GitHub Flavored Markdown style slugs."""
105
106 extension = ['markdown.extensions.toc']
107 extension_configs = {
108 'markdown.extensions.toc': {
109 "slugify": slugs.slugify(case="lower-ascii", percent_encode=True)
110 }
111 }
112
113 def test_slug(self):
114 """Test the slug output."""
115
116 self.check_markdown(
117 r'# Testing GFM unicode-slugs_headers ±♠Ωℑ with encoding',
118 r'<h1 id="testing-gfm-unicode-slugs_headers-%CE%A9%E2%84%91-with-encoding">'
119 r'Testing GFM unicode-slugs_headers ±♠Ωℑ with encoding</h1>'
120 )
121
122
123 class TestNormalize(util.MdCase):
124 """Test different normalization methods."""
125
126 extension = ['markdown.extensions.toc']
127 extension_configs = {
128 'markdown.extensions.toc': {
129 "slugify": slugs.slugify(normalize='NFD')
130 }
131 }
132
133 def test_slug(self):
134 """Test the slug output."""
135
136 self.check_markdown(
137 r'# Théâtre',
138 r'<h1 id="Theatre">Théâtre</h1>'
139 )
140
141
142 class TestFold(util.MdCase):
143 """Test different normalization methods."""
144
145 extension = ['markdown.extensions.toc']
146 extension_configs = {
147 'markdown.extensions.toc': {
148 "slugify": slugs.slugify(case='fold')
149 }
150 }
151
152 def test_slug(self):
153 """Test the slug output."""
154
155 self.check_markdown(
156 r'# ß',
157 r'<h1 id="ss">ß</h1>'
158 )