Debian Codegraph @

tests/test_extensions/test_arithmatex.py

raw
1 """Test cases for Arithmatex."""
2 from .. import util
3
4
5 class TestArithmatexLimit(util.MdCase):
6 """Test limiting Arithmatex inline and block inputs."""
7
8 extension = [
9 'pymdownx.arithmatex'
10 ]
11 extension_configs = {'pymdownx.arithmatex': {'inline_syntax': ['round'], 'block_syntax': ['square']}}
12
13 def test_round_only(self):
14 """Test round only."""
15
16 self.check_markdown(
17 "\\(1 + 2 + 3\\)",
18 """<p><span class="arithmatex"><span class="MathJax_Preview">1 + 2 + 3</span><script type="math/tex">1 + 2 + 3</script></span></p>""" # noqa: E501
19 )
20
21 def test_square_only(self):
22 """Test square only."""
23
24 self.check_markdown(
25 r"""
26 \[
27 1 + 2 + 3
28 \]
29 """,
30 r"""
31 <div class="arithmatex">
32 <div class="MathJax_Preview">
33 1 + 2 + 3
34 </div>
35 <script type="math/tex; mode=display">
36 1 + 2 + 3
37 </script>
38 </div>
39 """,
40 True
41 )
42
43
44 class TestArithmatexBlockEscapes(util.MdCase):
45 """Test escaping cases for Arithmatex blocks."""
46
47 extension = [
48 'pymdownx.arithmatex'
49 ]
50 extension_configs = {}
51
52 def test_escaped_dollar_block(self):
53 """Test escaping a dollar."""
54
55 self.check_markdown(
56 r'''
57 $$3+2\$$
58 ''',
59 r'''
60 <p>$<span class="arithmatex"><span class="MathJax_Preview">3+2\$</span><script type="math/tex">3+2\$</script></span></p>
61 ''', # noqa: E501
62 True
63 )
64
65 def test_escaped_dollar_dollar_block(self):
66 """Test escaping both dollars."""
67
68 self.check_markdown(
69 r'''
70 $$3+2\$\$
71 ''',
72 r'''
73 <p>$$3+2$$</p>
74 ''',
75 True
76 )
77
78 def test_double_escaped_dollar_block(self):
79 """Test double escaping a dollar."""
80
81 self.check_markdown(
82 r'''
83 $$3+2\\$$
84 ''',
85 r'''
86 <div class="arithmatex">
87 <div class="MathJax_Preview">3+2\\</div>
88 <script type="math/tex; mode=display">3+2\\</script>
89 </div>
90 ''',
91 True
92 )
93
94 def test_escaped_end_block(self):
95 """Test escaping an end."""
96
97 self.check_markdown(
98 r'''
99 \begin{align}3+2\\end{align}
100 ''',
101 r'''
102 <p>\begin{align}3+2\end{align}</p>
103 ''',
104 True
105 )
106
107 def test_double_escaped_end_block(self):
108 """Test double escaping an end."""
109
110 self.check_markdown(
111 r'''
112 \begin{align}3+2\\\end{align}
113 ''',
114 r'''
115 <div class="arithmatex">
116 <div class="MathJax_Preview">\begin{align}3+2\\\end{align}</div>
117 <script type="math/tex; mode=display">\begin{align}3+2\\\end{align}</script>
118 </div>
119 ''',
120 True
121 )
122
123 def test_escaped_bracket_block(self):
124 """Test escaping a bracket."""
125
126 self.check_markdown(
127 r'''
128 \[3+2\\]
129 ''',
130 r'''
131 <p>[3+2\]</p>
132 ''',
133 True
134 )
135
136 def test_double_escaped_bracket_block(self):
137 """Test double escaping a bracket."""
138
139 self.check_markdown(
140 r'''
141 \[3+2\\\]
142 ''',
143 r'''
144 <div class="arithmatex">
145 <div class="MathJax_Preview">3+2\\</div>
146 <script type="math/tex; mode=display">3+2\\</script>
147 </div>
148 ''',
149 True
150 )
151
152 def test_nested_inline_dollar(self):
153 """Test nested inline dollar."""
154
155 self.check_markdown(
156 R'''
157 a $$x$$ b
158 ''',
159 R'''
160 <p>a $<span class="arithmatex"><span class="MathJax_Preview">x</span><script type="math/tex">x</script></span>$ b</p>
161 ''', # noqa: E501
162 True
163 )
164
165 def test_hang_dollar(self):
166 """
167 We are just making sure this works.
168
169 Previously this pattern would hang. It isn't supposed to match due to the space before the last dollar,
170 but it definitely shouldn't hang the process.
171 """
172
173 self.check_markdown(
174 r'''
175 $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} $
176 ''', # noqa: E501
177 r'''
178 <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>
179 ''', # noqa: E501
180 True
181 )