File: test_arithmatex.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 (172 lines) | stat: -rw-r--r-- 4,989 bytes parent folder | download | duplicates (3)
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
"""Test cases for Arithmatex."""
from .. import util


class TestArithmatexLimit(util.MdCase):
    """Test limiting Arithmatex inline and block inputs."""

    extension = [
        'pymdownx.arithmatex'
    ]
    extension_configs = {'pymdownx.arithmatex': {'inline_syntax': ['round'], 'block_syntax': ['square']}}

    def test_round_only(self):
        """Test round only."""

        self.check_markdown(
            "\\(1 + 2 + 3\\)",
            """<p><span class="arithmatex"><span class="MathJax_Preview">1 + 2 + 3</span><script type="math/tex">1 + 2 + 3</script></span></p>"""  # noqa: E501
        )

    def test_square_only(self):
        """Test square only."""

        self.check_markdown(
            r"""
            \[
            1 + 2 + 3
            \]
            """,
            r"""
            <div class="arithmatex">
            <div class="MathJax_Preview">
            1 + 2 + 3
            </div>
            <script type="math/tex; mode=display">
            1 + 2 + 3
            </script>
            </div>
            """,
            True
        )


class TestArithmatexBlockEscapes(util.MdCase):
    """Test escaping cases for Arithmatex blocks."""

    extension = [
        'pymdownx.arithmatex'
    ]
    extension_configs = {}

    def test_escaped_dollar_block(self):
        """Test escaping a dollar."""

        self.check_markdown(
            r'''
            $$3+2\$$
            ''',
            r'''
            <p>$<span class="arithmatex"><span class="MathJax_Preview">3+2\$</span><script type="math/tex">3+2\$</script></span></p>
            ''',  # noqa: E501
            True
        )

    def test_escaped_dollar_dollar_block(self):
        """Test escaping both dollars."""

        self.check_markdown(
            r'''
            $$3+2\$\$
            ''',
            r'''
            <p>$$3+2$$</p>
            ''',
            True
        )

    def test_double_escaped_dollar_block(self):
        """Test double escaping a dollar."""

        self.check_markdown(
            r'''
            $$3+2\\$$
            ''',
            r'''
            <div class="arithmatex">
            <div class="MathJax_Preview">3+2\\</div>
            <script type="math/tex; mode=display">3+2\\</script>
            </div>
            ''',
            True
        )

    def test_escaped_end_block(self):
        """Test escaping an end."""

        self.check_markdown(
            r'''
            \begin{align}3+2\\end{align}
            ''',
            r'''
            <p>\begin{align}3+2\end{align}</p>
            ''',
            True
        )

    def test_double_escaped_end_block(self):
        """Test double escaping an end."""

        self.check_markdown(
            r'''
            \begin{align}3+2\\\end{align}
            ''',
            r'''
            <div class="arithmatex">
            <div class="MathJax_Preview">\begin{align}3+2\\\end{align}</div>
            <script type="math/tex; mode=display">\begin{align}3+2\\\end{align}</script>
            </div>
            ''',
            True
        )

    def test_escaped_bracket_block(self):
        """Test escaping a bracket."""

        self.check_markdown(
            r'''
            \[3+2\\]
            ''',
            r'''
            <p>[3+2\]</p>
            ''',
            True
        )

    def test_double_escaped_bracket_block(self):
        """Test double escaping a bracket."""

        self.check_markdown(
            r'''
            \[3+2\\\]
            ''',
            r'''
            <div class="arithmatex">
            <div class="MathJax_Preview">3+2\\</div>
            <script type="math/tex; mode=display">3+2\\</script>
            </div>
            ''',
            True
        )


class TestArithmatexHang(util.MdCase):
    """Test hang cases."""

    def test_hang_dollar(self):
        """
        We are just making sure this works.

        Previously this pattern would hang. It isn't supposed to match due to the space before the last dollar,
        but it definitely shouldn't hang the process.
        """

        self.check_markdown(
            r'''
            $z^{[1]} = \begin{bmatrix}w^{[1]T}_1 \\ w^{[1]T}_2 \\ w^{[1]T}_3 \\ w^{[1]T}_4 \end{bmatrix} \begin{bmatrix}x_1 \\ x_2 \\ x_3 \end{bmatrix} + \begin{bmatrix}b^{[1]}_1 \\ b^{[1]}_2 \\ b^{[1]}_3 \\ b^{[1]}_4 \end{bmatrix}= \begin{bmatrix}w^{[1]T}_1 x + b^{[1]}_1 \\ w^{[1]T}_2 x + b^{[1]}_2\\ w^{[1]T}_3 x + b^{[1]}_3 \\ w^{[1]T}_4 x + b^{[1]}_4 \end{bmatrix} $
            ''',  # noqa: E501
            r'''
            <p>$z^{[1]} = \begin{bmatrix}w^{[1]T}_1 \ w^{[1]T}_2 \ w^{[1]T}_3 \ w^{[1]T}_4 \end{bmatrix} \begin{bmatrix}x_1 \ x_2 \ x_3 \end{bmatrix} + \begin{bmatrix}b^{[1]}_1 \ b^{[1]}_2 \ b^{[1]}_3 \ b^{[1]}_4 \end{bmatrix}= \begin{bmatrix}w^{[1]T}_1 x + b^{[1]}_1 \ w^{[1]T}_2 x + b^{[1]}_2\ w^{[1]T}_3 x + b^{[1]}_3 \ w^{[1]T}_4 x + b^{[1]}_4 \end{bmatrix} $</p>
            ''',  # noqa: E501
            True
        )