| 1 |
"""Test caret.""" |
| 2 |
from .. import util |
| 3 |
|
| 4 |
|
| 5 |
class TestCaretSmart(util.MdCase): |
| 6 |
"""Test escaping cases for Caret with smart enabled.""" |
| 7 |
|
| 8 |
extension = [ |
| 9 |
'pymdownx.caret' |
| 10 |
] |
| 11 |
extension_configs = { |
| 12 |
"pymdownx.caret": { |
| 13 |
"smart_insert": True |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
def test_case_1(self): |
| 18 |
"""Test case 1.""" |
| 19 |
|
| 20 |
self.check_markdown( |
| 21 |
R"x^2^ + y^2^ = 4", |
| 22 |
"<p>x<sup>2</sup> + y<sup>2</sup> = 4</p>", |
| 23 |
True |
| 24 |
) |
| 25 |
|
| 26 |
def test_case_2(self): |
| 27 |
"""Test case 2.""" |
| 28 |
|
| 29 |
self.check_markdown( |
| 30 |
R"Text^superscript^", |
| 31 |
"<p>Text<sup>superscript</sup></p>", |
| 32 |
True |
| 33 |
) |
| 34 |
|
| 35 |
def test_case_3(self): |
| 36 |
"""Test case 3.""" |
| 37 |
|
| 38 |
self.check_markdown( |
| 39 |
R"Text^superscript failed^", |
| 40 |
"<p>Text^superscript failed^</p>", |
| 41 |
True |
| 42 |
) |
| 43 |
|
| 44 |
def test_case_4(self): |
| 45 |
"""Test case 4.""" |
| 46 |
|
| 47 |
self.check_markdown( |
| 48 |
R"Text^superscript\ success^", |
| 49 |
"<p>Text<sup>superscript success</sup></p>", |
| 50 |
True |
| 51 |
) |
| 52 |
|
| 53 |
def test_case_5(self): |
| 54 |
"""Test case 5.""" |
| 55 |
|
| 56 |
self.check_markdown( |
| 57 |
R"Test: ^^ Won't insert ^^", |
| 58 |
"<p>Test: ^^ Won't insert ^^</p>", |
| 59 |
True |
| 60 |
) |
| 61 |
|
| 62 |
def test_case_6(self): |
| 63 |
"""Test case 6.""" |
| 64 |
|
| 65 |
self.check_markdown( |
| 66 |
R"Test: ^^Will insert^^", |
| 67 |
"<p>Test: <ins>Will insert</ins></p>", |
| 68 |
True |
| 69 |
) |
| 70 |
|
| 71 |
def test_case_7(self): |
| 72 |
"""Test case 7.""" |
| 73 |
|
| 74 |
self.check_markdown( |
| 75 |
R"Test: \^\^Escaped\^\^", |
| 76 |
"<p>Test: ^^Escaped^^</p>", |
| 77 |
True |
| 78 |
) |
| 79 |
|
| 80 |
def test_case_8(self): |
| 81 |
"""Test case 8.""" |
| 82 |
|
| 83 |
self.check_markdown( |
| 84 |
R"Test: ^^This will all be inserted ^^because of the placement of the center carets.^^", |
| 85 |
"<p>Test: <ins>This will all be inserted ^^because of the placement of the center carets.</ins></p>", |
| 86 |
True |
| 87 |
) |
| 88 |
|
| 89 |
def test_case_9(self): |
| 90 |
"""Test case 9.""" |
| 91 |
|
| 92 |
self.check_markdown( |
| 93 |
R"Test: ^^This will all be inserted ^^ because of the placement of the center carets.^^", |
| 94 |
"<p>Test: <ins>This will all be inserted ^^ because of the placement of the center carets.</ins></p>", |
| 95 |
True |
| 96 |
) |
| 97 |
|
| 98 |
def test_case_10(self): |
| 99 |
"""Test case 10.""" |
| 100 |
|
| 101 |
self.check_markdown( |
| 102 |
R"Test: ^^This will NOT all be inserted^^ because of the placement of the center caret.^^", |
| 103 |
"<p>Test: <ins>This will NOT all be inserted</ins> because of the placement of the center caret.^^</p>", |
| 104 |
True |
| 105 |
) |
| 106 |
|
| 107 |
def test_case_11(self): |
| 108 |
"""Test case 11.""" |
| 109 |
|
| 110 |
self.check_markdown( |
| 111 |
R"Test: ^^This will all be inserted^ because of the token is less than that of the caret.^^", |
| 112 |
"<p>Test: <ins>This will all be inserted^ because of the token is less than that of the caret.</ins></p>", |
| 113 |
True |
| 114 |
) |
| 115 |
|
| 116 |
def test_complex_cases(self): |
| 117 |
"""Test some complex cases.""" |
| 118 |
|
| 119 |
self.check_markdown( |
| 120 |
R''' |
| 121 |
^^^I'm\ insert\ and\ sup^ I am just insert.^^ |
| 122 |
|
| 123 |
^^^I'm\ insert\ and\ sup!^^\ I\ am\ just\ sup.^ |
| 124 |
|
| 125 |
^sup\ and\ ^^sup\ insert^^^ and ^sup^ |
| 126 |
|
| 127 |
^^insert and ^sup\ insert^^^ and ^sup^ |
| 128 |
|
| 129 |
^^^I'm\ sup\ and\ insert^ I am just insert.^^ ^sup^ |
| 130 |
|
| 131 |
^^^I'm\ insert\ and\ sup!^^\ I\ am\ just\ sup.^ ^sup^ |
| 132 |
|
| 133 |
^sup\ and\ ^^sup\ insert^^^ and not sup^ |
| 134 |
|
| 135 |
^^insert and ^sup\ insert^^^ and not sup^ |
| 136 |
|
| 137 |
^sup\ and\ ^^sup\ insert^^^ |
| 138 |
|
| 139 |
^^insert and ^sup\ insert^^^ |
| 140 |
|
| 141 |
^sup\ ^^sup\ insert^^\ sup^ |
| 142 |
|
| 143 |
^^^sup\ and\ insert^ insert^^: foo bar ^^insert^^ |
| 144 |
|
| 145 |
^^^sup\ and\ insert^^\ sup^ foo bar ^^insert^^ |
| 146 |
|
| 147 |
^sup\ and\ ^^sup\ insert^^^ ^^insert^^ |
| 148 |
|
| 149 |
^^insert and ^sup\ insert^^^ ^^insert^^ |
| 150 |
''', |
| 151 |
''' |
| 152 |
<p><ins><sup>I'm insert and sup</sup> I am just insert.</ins></p> |
| 153 |
<p><sup><ins>I'm insert and sup!</ins> I am just sup.</sup></p> |
| 154 |
<p><sup>sup and <ins>sup insert</ins></sup> and <sup>sup</sup></p> |
| 155 |
<p><ins>insert and <sup>sup insert</sup></ins> and <sup>sup</sup></p> |
| 156 |
<p><ins><sup>I'm sup and insert</sup> I am just insert.</ins> <sup>sup</sup></p> |
| 157 |
<p><sup><ins>I'm insert and sup!</ins> I am just sup.</sup> <sup>sup</sup></p> |
| 158 |
<p><sup>sup and <ins>sup insert</ins></sup> and not sup^</p> |
| 159 |
<p><ins>insert and <sup>sup insert</sup></ins> and not sup^</p> |
| 160 |
<p><sup>sup and <ins>sup insert</ins></sup></p> |
| 161 |
<p><ins>insert and <sup>sup insert</sup></ins></p> |
| 162 |
<p><sup>sup <ins>sup insert</ins> sup</sup></p> |
| 163 |
<p><ins><sup>sup and insert</sup> insert</ins>: foo bar <ins>insert</ins></p> |
| 164 |
<p><sup><ins>sup and insert</ins> sup</sup> foo bar <ins>insert</ins></p> |
| 165 |
<p><sup>sup and <ins>sup insert</ins></sup> <ins>insert</ins></p> |
| 166 |
<p><ins>insert and <sup>sup insert</sup></ins> <ins>insert</ins></p> |
| 167 |
''', |
| 168 |
True |
| 169 |
) |
| 170 |
|
| 171 |
|
| 172 |
class TestCaretNoSmart(util.MdCase): |
| 173 |
"""Test escaping cases for Caret without smart enabled.""" |
| 174 |
|
| 175 |
extension = [ |
| 176 |
'pymdownx.caret' |
| 177 |
] |
| 178 |
extension_configs = { |
| 179 |
"pymdownx.caret": { |
| 180 |
"smart_insert": False |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
def test_case_1(self): |
| 185 |
"""Test case 1.""" |
| 186 |
|
| 187 |
self.check_markdown( |
| 188 |
R"x^2^ + y^2^ = 4", |
| 189 |
"<p>x<sup>2</sup> + y<sup>2</sup> = 4</p>", |
| 190 |
True |
| 191 |
) |
| 192 |
|
| 193 |
def test_case_2(self): |
| 194 |
"""Test case 2.""" |
| 195 |
|
| 196 |
self.check_markdown( |
| 197 |
R"Text^superscript^", |
| 198 |
"<p>Text<sup>superscript</sup></p>", |
| 199 |
True |
| 200 |
) |
| 201 |
|
| 202 |
def test_case_3(self): |
| 203 |
"""Test case 3.""" |
| 204 |
|
| 205 |
self.check_markdown( |
| 206 |
R"Text^superscript failed^", |
| 207 |
"<p>Text^superscript failed^</p>", |
| 208 |
True |
| 209 |
) |
| 210 |
|
| 211 |
def test_case_4(self): |
| 212 |
"""Test case 4.""" |
| 213 |
|
| 214 |
self.check_markdown( |
| 215 |
R"Text^superscript\ success^", |
| 216 |
"<p>Text<sup>superscript success</sup></p>", |
| 217 |
True |
| 218 |
) |
| 219 |
|
| 220 |
def test_case_5(self): |
| 221 |
"""Test case 5.""" |
| 222 |
|
| 223 |
self.check_markdown( |
| 224 |
R"Test: ^^ Won't insert ^^", |
| 225 |
"<p>Test: ^^ Won't insert ^^</p>", |
| 226 |
True |
| 227 |
) |
| 228 |
|
| 229 |
def test_case_6(self): |
| 230 |
"""Test case 6.""" |
| 231 |
|
| 232 |
self.check_markdown( |
| 233 |
R"Test: ^^Will insert^^", |
| 234 |
"<p>Test: <ins>Will insert</ins></p>", |
| 235 |
True |
| 236 |
) |
| 237 |
|
| 238 |
def test_case_7(self): |
| 239 |
"""Test case 7.""" |
| 240 |
|
| 241 |
self.check_markdown( |
| 242 |
R"Test: \^\^Escaped\^\^", |
| 243 |
"<p>Test: ^^Escaped^^</p>", |
| 244 |
True |
| 245 |
) |
| 246 |
|
| 247 |
def test_case_8(self): |
| 248 |
"""Test case 8.""" |
| 249 |
|
| 250 |
self.check_markdown( |
| 251 |
R"Test: ^^All will ^ be insert^^", |
| 252 |
"<p>Test: <ins>All will ^ be insert</ins></p>", |
| 253 |
True |
| 254 |
) |
| 255 |
|
| 256 |
def test_case_9(self): |
| 257 |
"""Test case 9.""" |
| 258 |
|
| 259 |
self.check_markdown( |
| 260 |
R"Test: ^^All will^\^^ be insert with superscript in middle^^", |
| 261 |
"<p>Test: <ins>All will<sup>^</sup> be insert with superscript in middle</ins></p>", |
| 262 |
True |
| 263 |
) |
| 264 |
|
| 265 |
def test_case_10(self): |
| 266 |
"""Test case 10.""" |
| 267 |
|
| 268 |
self.check_markdown( |
| 269 |
R"Test: ^^All will ^\^^ be insert with superscript in middle^^", |
| 270 |
"<p>Test: <ins>All will <sup>^</sup> be insert with superscript in middle</ins></p>", |
| 271 |
True |
| 272 |
) |
| 273 |
|
| 274 |
def test_complex_cases(self): |
| 275 |
"""Test some complex cases.""" |
| 276 |
|
| 277 |
self.check_markdown( |
| 278 |
R''' |
| 279 |
^^^I'm\ insert\ and\ sup^ I am just insert.^^ |
| 280 |
|
| 281 |
^^^I'm\ insert\ and\ sup!^^\ I\ am\ just\ sup.^ |
| 282 |
|
| 283 |
^sup\ and\ ^^sup\ insert^^^ and ^sup^ |
| 284 |
|
| 285 |
^^insert and ^sup\ insert^^^ and ^sup^ |
| 286 |
|
| 287 |
^^^I'm\ sup\ and\ insert^ I am just insert.^^ ^sup^ |
| 288 |
|
| 289 |
^^^I'm\ insert\ and\ sup!^^\ I\ am\ just\ sup.^ ^sup^ |
| 290 |
|
| 291 |
^sup\ and\ ^^sup\ insert^^^ and not sup^ |
| 292 |
|
| 293 |
^^insert and ^sup\ insert^^^ and not sup^ |
| 294 |
|
| 295 |
^sup\ and\ ^^sup\ insert^^^ |
| 296 |
|
| 297 |
^^insert and ^sup\ insert^^^ |
| 298 |
|
| 299 |
^sup\ ^^sup\ insert^^\ sup^ |
| 300 |
|
| 301 |
^^^sup\ and\ insert^ insert^^: foo bar ^^insert^^ |
| 302 |
|
| 303 |
^^^sup\ and\ insert^^\ sup^ foo bar ^^insert^^ |
| 304 |
|
| 305 |
^sup\ and\ ^^sup\ insert^^^ ^^insert^^ |
| 306 |
|
| 307 |
^^insert and ^sup\ insert^^^ ^^insert^^ |
| 308 |
''', |
| 309 |
''' |
| 310 |
<p><ins><sup>I'm insert and sup</sup> I am just insert.</ins></p> |
| 311 |
<p><sup><ins>I'm insert and sup!</ins> I am just sup.</sup></p> |
| 312 |
<p><sup>sup and <ins>sup insert</ins></sup> and <sup>sup</sup></p> |
| 313 |
<p><ins>insert and <sup>sup insert</sup></ins> and <sup>sup</sup></p> |
| 314 |
<p><ins><sup>I'm sup and insert</sup> I am just insert.</ins> <sup>sup</sup></p> |
| 315 |
<p><sup><ins>I'm insert and sup!</ins> I am just sup.</sup> <sup>sup</sup></p> |
| 316 |
<p><sup>sup and <ins>sup insert</ins></sup> and not sup^</p> |
| 317 |
<p><ins>insert and <sup>sup insert</sup></ins> and not sup^</p> |
| 318 |
<p><sup>sup and <ins>sup insert</ins></sup></p> |
| 319 |
<p><ins>insert and <sup>sup insert</sup></ins></p> |
| 320 |
<p><sup>sup <ins>sup insert</ins> sup</sup></p> |
| 321 |
<p><ins><sup>sup and insert</sup> insert</ins>: foo bar <ins>insert</ins></p> |
| 322 |
<p><sup><ins>sup and insert</ins> sup</sup> foo bar <ins>insert</ins></p> |
| 323 |
<p><sup>sup and <ins>sup insert</ins></sup> <ins>insert</ins></p> |
| 324 |
<p><ins>insert and <sup>sup insert</sup></ins> <ins>insert</ins></p> |
| 325 |
''', |
| 326 |
True |
| 327 |
) |