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