File: test_caret.py

package info (click to toggle)
pymdown-extensions 10.13-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,104 kB
  • sloc: python: 60,117; javascript: 846; sh: 8; makefile: 5
file content (327 lines) | stat: -rw-r--r-- 9,821 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
"""Test caret."""
from .. import util


class TestCaretSmart(util.MdCase):
    """Test escaping cases for Caret with smart enabled."""

    extension = [
        'pymdownx.caret'
    ]
    extension_configs = {
        "pymdownx.caret": {
            "smart_insert": True
        }
    }

    def test_case_1(self):
        """Test case 1."""

        self.check_markdown(
            R"x^2^ + y^2^ = 4",
            "<p>x<sup>2</sup> + y<sup>2</sup> = 4</p>",
            True
        )

    def test_case_2(self):
        """Test case 2."""

        self.check_markdown(
            R"Text^superscript^",
            "<p>Text<sup>superscript</sup></p>",
            True
        )

    def test_case_3(self):
        """Test case 3."""

        self.check_markdown(
            R"Text^superscript failed^",
            "<p>Text^superscript failed^</p>",
            True
        )

    def test_case_4(self):
        """Test case 4."""

        self.check_markdown(
            R"Text^superscript\ success^",
            "<p>Text<sup>superscript success</sup></p>",
            True
        )

    def test_case_5(self):
        """Test case 5."""

        self.check_markdown(
            R"Test: ^^ Won't insert ^^",
            "<p>Test: ^^ Won't insert ^^</p>",
            True
        )

    def test_case_6(self):
        """Test case 6."""

        self.check_markdown(
            R"Test: ^^Will insert^^",
            "<p>Test: <ins>Will insert</ins></p>",
            True
        )

    def test_case_7(self):
        """Test case 7."""

        self.check_markdown(
            R"Test: \^\^Escaped\^\^",
            "<p>Test: ^^Escaped^^</p>",
            True
        )

    def test_case_8(self):
        """Test case 8."""

        self.check_markdown(
            R"Test: ^^This will all be inserted ^^because of the placement of the center carets.^^",
            "<p>Test: <ins>This will all be inserted ^^because of the placement of the center carets.</ins></p>",
            True
        )

    def test_case_9(self):
        """Test case 9."""

        self.check_markdown(
            R"Test: ^^This will all be inserted ^^ because of the placement of the center carets.^^",
            "<p>Test: <ins>This will all be inserted ^^ because of the placement of the center carets.</ins></p>",
            True
        )

    def test_case_10(self):
        """Test case 10."""

        self.check_markdown(
            R"Test: ^^This will NOT all be inserted^^ because of the placement of the center caret.^^",
            "<p>Test: <ins>This will NOT all be inserted</ins> because of the placement of the center caret.^^</p>",
            True
        )

    def test_case_11(self):
        """Test case 11."""

        self.check_markdown(
            R"Test: ^^This will all be inserted^ because of the token is less than that of the caret.^^",
            "<p>Test: <ins>This will all be inserted^ because of the token is less than that of the caret.</ins></p>",
            True
        )

    def test_complex_cases(self):
        """Test some complex cases."""

        self.check_markdown(
            R'''
            ^^^I'm\ insert\ and\ sup^ I am just insert.^^

            ^^^I'm\ insert\ and\ sup!^^\ I\ am\ just\ sup.^

            ^sup\ and\ ^^sup\ insert^^^ and ^sup^

            ^^insert and ^sup\ insert^^^ and ^sup^

            ^^^I'm\ sup\ and\ insert^ I am just insert.^^ ^sup^

            ^^^I'm\ insert\ and\ sup!^^\ I\ am\ just\ sup.^ ^sup^

            ^sup\ and\ ^^sup\ insert^^^ and not sup^

            ^^insert and ^sup\ insert^^^ and not sup^

            ^sup\ and\ ^^sup\ insert^^^

            ^^insert and ^sup\ insert^^^

            ^sup\ ^^sup\ insert^^\ sup^

            ^^^sup\ and\ insert^ insert^^: foo bar ^^insert^^

            ^^^sup\ and\ insert^^\ sup^ foo bar ^^insert^^

            ^sup\ and\ ^^sup\ insert^^^ ^^insert^^

            ^^insert and ^sup\ insert^^^ ^^insert^^
            ''',
            '''
            <p><ins><sup>I'm insert and sup</sup> I am just insert.</ins></p>
            <p><sup><ins>I'm insert and sup!</ins> I am just sup.</sup></p>
            <p><sup>sup and <ins>sup insert</ins></sup> and <sup>sup</sup></p>
            <p><ins>insert and <sup>sup insert</sup></ins> and <sup>sup</sup></p>
            <p><ins><sup>I'm sup and insert</sup> I am just insert.</ins> <sup>sup</sup></p>
            <p><sup><ins>I'm insert and sup!</ins> I am just sup.</sup> <sup>sup</sup></p>
            <p><sup>sup and <ins>sup insert</ins></sup> and not sup^</p>
            <p><ins>insert and <sup>sup insert</sup></ins> and not sup^</p>
            <p><sup>sup and <ins>sup insert</ins></sup></p>
            <p><ins>insert and <sup>sup insert</sup></ins></p>
            <p><sup>sup <ins>sup insert</ins> sup</sup></p>
            <p><ins><sup>sup and insert</sup> insert</ins>: foo bar <ins>insert</ins></p>
            <p><sup><ins>sup and insert</ins> sup</sup> foo bar <ins>insert</ins></p>
            <p><sup>sup and <ins>sup insert</ins></sup> <ins>insert</ins></p>
            <p><ins>insert and <sup>sup insert</sup></ins> <ins>insert</ins></p>
            ''',
            True
        )


class TestCaretNoSmart(util.MdCase):
    """Test escaping cases for Caret without smart enabled."""

    extension = [
        'pymdownx.caret'
    ]
    extension_configs = {
        "pymdownx.caret": {
            "smart_insert": False
        }
    }

    def test_case_1(self):
        """Test case 1."""

        self.check_markdown(
            R"x^2^ + y^2^ = 4",
            "<p>x<sup>2</sup> + y<sup>2</sup> = 4</p>",
            True
        )

    def test_case_2(self):
        """Test case 2."""

        self.check_markdown(
            R"Text^superscript^",
            "<p>Text<sup>superscript</sup></p>",
            True
        )

    def test_case_3(self):
        """Test case 3."""

        self.check_markdown(
            R"Text^superscript failed^",
            "<p>Text^superscript failed^</p>",
            True
        )

    def test_case_4(self):
        """Test case 4."""

        self.check_markdown(
            R"Text^superscript\ success^",
            "<p>Text<sup>superscript success</sup></p>",
            True
        )

    def test_case_5(self):
        """Test case 5."""

        self.check_markdown(
            R"Test: ^^ Won't insert ^^",
            "<p>Test: ^^ Won't insert ^^</p>",
            True
        )

    def test_case_6(self):
        """Test case 6."""

        self.check_markdown(
            R"Test: ^^Will insert^^",
            "<p>Test: <ins>Will insert</ins></p>",
            True
        )

    def test_case_7(self):
        """Test case 7."""

        self.check_markdown(
            R"Test: \^\^Escaped\^\^",
            "<p>Test: ^^Escaped^^</p>",
            True
        )

    def test_case_8(self):
        """Test case 8."""

        self.check_markdown(
            R"Test: ^^All will ^ be insert^^",
            "<p>Test: <ins>All will ^ be insert</ins></p>",
            True
        )

    def test_case_9(self):
        """Test case 9."""

        self.check_markdown(
            R"Test: ^^All will^\^^ be insert with superscript in middle^^",
            "<p>Test: <ins>All will<sup>^</sup> be insert with superscript in middle</ins></p>",
            True
        )

    def test_case_10(self):
        """Test case 10."""

        self.check_markdown(
            R"Test: ^^All will ^\^^ be insert with superscript in middle^^",
            "<p>Test: <ins>All will <sup>^</sup> be insert with superscript in middle</ins></p>",
            True
        )

    def test_complex_cases(self):
        """Test some complex cases."""

        self.check_markdown(
            R'''
            ^^^I'm\ insert\ and\ sup^ I am just insert.^^

            ^^^I'm\ insert\ and\ sup!^^\ I\ am\ just\ sup.^

            ^sup\ and\ ^^sup\ insert^^^ and ^sup^

            ^^insert and ^sup\ insert^^^ and ^sup^

            ^^^I'm\ sup\ and\ insert^ I am just insert.^^ ^sup^

            ^^^I'm\ insert\ and\ sup!^^\ I\ am\ just\ sup.^ ^sup^

            ^sup\ and\ ^^sup\ insert^^^ and not sup^

            ^^insert and ^sup\ insert^^^ and not sup^

            ^sup\ and\ ^^sup\ insert^^^

            ^^insert and ^sup\ insert^^^

            ^sup\ ^^sup\ insert^^\ sup^

            ^^^sup\ and\ insert^ insert^^: foo bar ^^insert^^

            ^^^sup\ and\ insert^^\ sup^ foo bar ^^insert^^

            ^sup\ and\ ^^sup\ insert^^^ ^^insert^^

            ^^insert and ^sup\ insert^^^ ^^insert^^
            ''',
            '''
            <p><ins><sup>I'm insert and sup</sup> I am just insert.</ins></p>
            <p><sup><ins>I'm insert and sup!</ins> I am just sup.</sup></p>
            <p><sup>sup and <ins>sup insert</ins></sup> and <sup>sup</sup></p>
            <p><ins>insert and <sup>sup insert</sup></ins> and <sup>sup</sup></p>
            <p><ins><sup>I'm sup and insert</sup> I am just insert.</ins> <sup>sup</sup></p>
            <p><sup><ins>I'm insert and sup!</ins> I am just sup.</sup> <sup>sup</sup></p>
            <p><sup>sup and <ins>sup insert</ins></sup> and not sup^</p>
            <p><ins>insert and <sup>sup insert</sup></ins> and not sup^</p>
            <p><sup>sup and <ins>sup insert</ins></sup></p>
            <p><ins>insert and <sup>sup insert</sup></ins></p>
            <p><sup>sup <ins>sup insert</ins> sup</sup></p>
            <p><ins><sup>sup and insert</sup> insert</ins>: foo bar <ins>insert</ins></p>
            <p><sup><ins>sup and insert</ins> sup</sup> foo bar <ins>insert</ins></p>
            <p><sup>sup and <ins>sup insert</ins></sup> <ins>insert</ins></p>
            <p><ins>insert and <sup>sup insert</sup></ins> <ins>insert</ins></p>
            ''',
            True
        )