Debian Codegraph @

tests/test_extensions/test_smartsymbols.py

raw
1 """Test cases for SmartSymbols."""
2 from .. import util
3 import markdown
4 from pymdownx.__meta__ import parse_version
5
6 PYMD_3_6 = parse_version(markdown.__version__) >= (3, 6, 0)
7
8
9 class TestSmartSymbols(util.MdCase):
10 """Test smart symbols works in various scenarios."""
11
12 extension = [
13 'toc',
14 'smarty',
15 'pymdownx.smartsymbols'
16 ]
17 extension_configs = {}
18
19 def test_copyright(self):
20 """Test copyright."""
21
22 self.check_markdown(
23 'Copyright (c)',
24 '<p>Copyright &copy;</p>'
25 )
26
27 def test_trademark(self):
28 """Test trademark."""
29
30 self.check_markdown(
31 'Trademark(tm)',
32 '<p>Trademark&trade;</p>'
33 )
34
35 def test_registered(self):
36 """Test registered."""
37
38 self.check_markdown(
39 'Registered(r)',
40 '<p>Registered&reg;</p>'
41 )
42
43 def test_plus_minus(self):
44 """Test plus/minus."""
45
46 self.check_markdown(
47 '230 +/- 10% V',
48 '<p>230 &plusmn; 10% V</p>'
49 )
50
51 def test_neq(self):
52 """Test not equal."""
53
54 self.check_markdown(
55 'A =/= B',
56 '<p>A &ne; B</p>'
57 )
58
59 def test_right(self):
60 """Test right arrow."""
61
62 self.check_markdown(
63 'right arrow -->',
64 '<p>right arrow &rarr;</p>'
65 )
66
67 def test_left(self):
68 """Test left arrow."""
69
70 self.check_markdown(
71 'left arrow <--',
72 '<p>left arrow &larr;</p>'
73 )
74
75 def test_double_arrow(self):
76 """Test double arrow."""
77
78 self.check_markdown(
79 'double arrow <-->',
80 '<p>double arrow &harr;</p>'
81 )
82
83 def test_ordinals(self):
84 """Test ordinals."""
85
86 self.check_markdown(
87 """
88 Good: 1st 2nd 3rd 11th 12th 13th 15th 32nd 103rd
89
90 Bad: 1th 2th 3th 2rd 1nd 22th 33th 41nd 53nd
91 """,
92 """
93 <p>Good: 1<sup>st</sup> 2<sup>nd</sup> 3<sup>rd</sup> 11<sup>th</sup> 12<sup>th</sup> 13<sup>th</sup> 15<sup>th</sup> 32<sup>nd</sup> 103<sup>rd</sup></p>
94 <p>Bad: 1th 2th 3th 2rd 1nd 22th 33th 41nd 53nd</p>
95 """, # noqa: E501
96 True
97 )
98
99 def test_fractions(self):
100 """Test fractions."""
101
102 self.check_markdown(
103 """
104 Fraction 1/2
105 Fraction 1/4
106 Fraction 3/4
107 Fraction 1/3
108 Fraction 2/3
109 Fraction 1/5
110 Fraction 2/5
111 Fraction 3/5
112 Fraction 4/5
113 Fraction 1/6
114 Fraction 5/6
115 Fraction 1/8
116 Fraction 3/8
117 Fraction 5/8
118 Fraction 7/8
119 """,
120 """
121 <p>Fraction &frac12;
122 Fraction &frac14;
123 Fraction &frac34;
124 Fraction &#8531;
125 Fraction &#8532;
126 Fraction &#8533;
127 Fraction &#8534;
128 Fraction &#8535;
129 Fraction &#8536;
130 Fraction &#8537;
131 Fraction &#8538;
132 Fraction &#8539;
133 Fraction &#8540;
134 Fraction &#8541;
135 Fraction &#8542;</p>
136 """,
137 True
138 )
139
140 def test_toc_tokens(self):
141 """Ensure smart symbols end up correctly in table of content tokens."""
142
143 md = markdown.Markdown(extensions=['toc', 'pymdownx.smartsymbols'])
144 md.convert('# *Foo* =/= `bar`')
145 self.assertEqual(
146 md.toc_tokens,
147 [
148 {
149 'children': [],
150 'data-toc-label': '',
151 'html': '<em>Foo</em> &ne; <code>bar</code>',
152 'id': 'foo-bar',
153 'level': 1,
154 'name': 'Foo &ne; bar'
155 }
156 ] if PYMD_3_6 else [
157 {
158 'level': 1,
159 'id': 'foo-bar',
160 'name': 'Foo &ne; bar',
161 'children': []
162 }
163 ]
164 )