summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJeremy Maitin-Shepard <jbms@google.com>2022-03-10 19:33:56 -0800
committerJeremy Maitin-Shepard <jbms@google.com>2022-03-19 20:37:49 -0700
commit099b54cb87db3ca210f6edd67dfdbde3ec83c9a4 (patch)
tree9dad6cce1d15dab01960a2780bfa5b3068c76383 /tests
parentb3812f72a98b01bae4b1158761082edc46cfa87f (diff)
downloadsphinx-git-099b54cb87db3ca210f6edd67dfdbde3ec83c9a4.tar.gz
Make code role highlighting consistent with code-block directive
Fixes https://github.com/sphinx-doc/sphinx/issues/5157 This is factored out of the sphinx-immaterial theme: https://github.com/jbms/sphinx-immaterial/blob/1ef121a612d4f5afc2a9ca9c4e3f20fca89065e8/sphinx_immaterial/inlinesyntaxhighlight.py#L1 See also: https://github.com/sphinx-doc/sphinx/pull/6916
Diffstat (limited to 'tests')
-rw-r--r--tests/roots/test-reST-code-role/conf.py0
-rw-r--r--tests/roots/test-reST-code-role/index.rst9
-rw-r--r--tests/test_build_html.py24
-rw-r--r--tests/test_build_latex.py27
4 files changed, 60 insertions, 0 deletions
diff --git a/tests/roots/test-reST-code-role/conf.py b/tests/roots/test-reST-code-role/conf.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/roots/test-reST-code-role/conf.py
diff --git a/tests/roots/test-reST-code-role/index.rst b/tests/roots/test-reST-code-role/index.rst
new file mode 100644
index 000000000..5be6bfc57
--- /dev/null
+++ b/tests/roots/test-reST-code-role/index.rst
@@ -0,0 +1,9 @@
+.. role:: python(code)
+ :language: python
+ :class: highlight
+
+Inline :python:`def foo(1 + 2 + None + "abc"): pass` code block
+
+.. code-block:: python
+
+ def foo(1 + 2 + None + "abc"): pass
diff --git a/tests/test_build_html.py b/tests/test_build_html.py
index 7688f76b3..39c6be783 100644
--- a/tests/test_build_html.py
+++ b/tests/test_build_html.py
@@ -1718,3 +1718,27 @@ def test_html_signaturereturn_icon(app):
content = (app.outdir / 'index.html').read_text()
assert ('<span class="sig-return-icon">&#x2192;</span>' in content)
+
+
+@pytest.mark.sphinx('html', testroot='reST-code-role')
+def test_html_code_role(app):
+ app.build()
+ content = (app.outdir / 'index.html').read_text()
+
+ common_content = (
+ '<span class="k">def</span> <span class="nf">foo</span>'
+ '<span class="p">(</span>'
+ '<span class="mi">1</span> '
+ '<span class="o">+</span> '
+ '<span class="mi">2</span> '
+ '<span class="o">+</span> '
+ '<span class="kc">None</span> '
+ '<span class="o">+</span> '
+ '<span class="s2">&quot;abc&quot;</span>'
+ '<span class="p">):</span> '
+ '<span class="k">pass</span>')
+ assert ('<p>Inline <code class="code highlight python docutils literal highlight-python">' +
+ common_content + '</code> code block</p>') in content
+ assert ('<div class="highlight-python notranslate">' +
+ '<div class="highlight"><pre><span></span>' +
+ common_content) in content
diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py
index b0ae85423..fa7847d44 100644
--- a/tests/test_build_latex.py
+++ b/tests/test_build_latex.py
@@ -1628,3 +1628,30 @@ def test_latex_container(app, status, warning):
result = (app.outdir / 'python.tex').read_text()
assert r'\begin{sphinxuseclass}{classname}' in result
assert r'\end{sphinxuseclass}' in result
+
+
+@pytest.mark.sphinx('latex', testroot='reST-code-role')
+def test_latex_code_role(app):
+ app.build()
+ content = (app.outdir / 'python.tex').read_text()
+
+ common_content = (
+ r'\PYG{k}{def} '
+ r'\PYG{n+nf}{foo}'
+ r'\PYG{p}{(}'
+ r'\PYG{l+m+mi}{1} '
+ r'\PYG{o}{+} '
+ r'\PYG{l+m+mi}{2} '
+ r'\PYG{o}{+} '
+ r'\PYG{k+kc}{None} '
+ r'\PYG{o}{+} '
+ r'\PYG{l+s+s2}{\PYGZdq{}}'
+ r'\PYG{l+s+s2}{abc}'
+ r'\PYG{l+s+s2}{\PYGZdq{}}'
+ r'\PYG{p}{)}'
+ r'\PYG{p}{:} '
+ r'\PYG{k}{pass}')
+ assert (r'Inline \sphinxcode{\sphinxupquote{' + '\n' +
+ common_content + '\n}} code block') in content
+ assert (r'\begin{sphinxVerbatim}[commandchars=\\\{\}]' +
+ '\n' + common_content + '\n' + r'\end{sphinxVerbatim}') in content