| 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 ©</p>' |
| 25 |
) |
| 26 |
|
| 27 |
def test_trademark(self): |
| 28 |
"""Test trademark.""" |
| 29 |
|
| 30 |
self.check_markdown( |
| 31 |
'Trademark(tm)', |
| 32 |
'<p>Trademark™</p>' |
| 33 |
) |
| 34 |
|
| 35 |
def test_registered(self): |
| 36 |
"""Test registered.""" |
| 37 |
|
| 38 |
self.check_markdown( |
| 39 |
'Registered(r)', |
| 40 |
'<p>Registered®</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 ± 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 ≠ 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 →</p>' |
| 65 |
) |
| 66 |
|
| 67 |
def test_left(self): |
| 68 |
"""Test left arrow.""" |
| 69 |
|
| 70 |
self.check_markdown( |
| 71 |
'left arrow <--', |
| 72 |
'<p>left arrow ←</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 ↔</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 ½ |
| 122 |
Fraction ¼ |
| 123 |
Fraction ¾ |
| 124 |
Fraction ⅓ |
| 125 |
Fraction ⅔ |
| 126 |
Fraction ⅕ |
| 127 |
Fraction ⅖ |
| 128 |
Fraction ⅗ |
| 129 |
Fraction ⅘ |
| 130 |
Fraction ⅙ |
| 131 |
Fraction ⅚ |
| 132 |
Fraction ⅛ |
| 133 |
Fraction ⅜ |
| 134 |
Fraction ⅝ |
| 135 |
Fraction ⅞</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> ≠ <code>bar</code>', |
| 152 |
'id': 'foo-bar', |
| 153 |
'level': 1, |
| 154 |
'name': 'Foo ≠ bar' |
| 155 |
} |
| 156 |
] if PYMD_3_6 else [ |
| 157 |
{ |
| 158 |
'level': 1, |
| 159 |
'id': 'foo-bar', |
| 160 |
'name': 'Foo ≠ bar', |
| 161 |
'children': [] |
| 162 |
} |
| 163 |
] |
| 164 |
) |