From a224f1990331fea5506455d3706468788412ea12 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Thu, 7 Dec 2023 19:52:14 -0500 Subject: [PATCH] ruff_python_formatter: add test for extraneous info string text (#9050) @ofek asked [about this][ref]. I did specifically add support for it, but neglected to add a test. This PR adds a test. [ref]: https://github.com/astral-sh/ruff/pull/9030#issuecomment-1846054764 --- .../fixtures/ruff/docstring_code_examples.py | 14 ++ .../format@docstring_code_examples.py.snap | 126 ++++++++++++++++++ 2 files changed, 140 insertions(+) diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/docstring_code_examples.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/docstring_code_examples.py index 68c7a528a6..381f04b757 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/ruff/docstring_code_examples.py +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/docstring_code_examples.py @@ -1195,6 +1195,20 @@ def markdown_over_indented(): pass +# This tests that we can have additional text after the language specifier. +def markdown_additional_info_string(): + """ + Do cool stuff. + + ```python tab="plugin.py" + cool_stuff( 1 ) + ``` + + Done. + """ + pass + + # Tests that an unclosed block gobbles up everything remaining in the # docstring, even if it isn't valid Python. Since it isn't valid Python, # reformatting fails and the entire thing is skipped. diff --git a/crates/ruff_python_formatter/tests/snapshots/format@docstring_code_examples.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@docstring_code_examples.py.snap index 7dc1badfe2..ce33622b63 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@docstring_code_examples.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@docstring_code_examples.py.snap @@ -1201,6 +1201,20 @@ def markdown_over_indented(): pass +# This tests that we can have additional text after the language specifier. +def markdown_additional_info_string(): + """ + Do cool stuff. + + ```python tab="plugin.py" + cool_stuff( 1 ) + ``` + + Done. + """ + pass + + # Tests that an unclosed block gobbles up everything remaining in the # docstring, even if it isn't valid Python. Since it isn't valid Python, # reformatting fails and the entire thing is skipped. @@ -2556,6 +2570,20 @@ def markdown_over_indented(): pass +# This tests that we can have additional text after the language specifier. +def markdown_additional_info_string(): + """ + Do cool stuff. + + ```python tab="plugin.py" + cool_stuff( 1 ) + ``` + + Done. + """ + pass + + # Tests that an unclosed block gobbles up everything remaining in the # docstring, even if it isn't valid Python. Since it isn't valid Python, # reformatting fails and the entire thing is skipped. @@ -3911,6 +3939,20 @@ def markdown_over_indented(): pass +# This tests that we can have additional text after the language specifier. +def markdown_additional_info_string(): + """ + Do cool stuff. + + ```python tab="plugin.py" + cool_stuff( 1 ) + ``` + + Done. + """ + pass + + # Tests that an unclosed block gobbles up everything remaining in the # docstring, even if it isn't valid Python. Since it isn't valid Python, # reformatting fails and the entire thing is skipped. @@ -5266,6 +5308,20 @@ def markdown_over_indented(): pass +# This tests that we can have additional text after the language specifier. +def markdown_additional_info_string(): + """ + Do cool stuff. + + ```python tab="plugin.py" + cool_stuff( 1 ) + ``` + + Done. + """ + pass + + # Tests that an unclosed block gobbles up everything remaining in the # docstring, even if it isn't valid Python. Since it isn't valid Python, # reformatting fails and the entire thing is skipped. @@ -6621,6 +6677,20 @@ def markdown_over_indented(): pass +# This tests that we can have additional text after the language specifier. +def markdown_additional_info_string(): + """ + Do cool stuff. + + ```python tab="plugin.py" + cool_stuff( 1 ) + ``` + + Done. + """ + pass + + # Tests that an unclosed block gobbles up everything remaining in the # docstring, even if it isn't valid Python. Since it isn't valid Python, # reformatting fails and the entire thing is skipped. @@ -7971,6 +8041,20 @@ def markdown_over_indented(): pass +# This tests that we can have additional text after the language specifier. +def markdown_additional_info_string(): + """ + Do cool stuff. + + ```python tab="plugin.py" + cool_stuff(1) + ``` + + Done. + """ + pass + + # Tests that an unclosed block gobbles up everything remaining in the # docstring, even if it isn't valid Python. Since it isn't valid Python, # reformatting fails and the entire thing is skipped. @@ -9321,6 +9405,20 @@ def markdown_over_indented(): pass +# This tests that we can have additional text after the language specifier. +def markdown_additional_info_string(): + """ + Do cool stuff. + + ```python tab="plugin.py" + cool_stuff(1) + ``` + + Done. + """ + pass + + # Tests that an unclosed block gobbles up everything remaining in the # docstring, even if it isn't valid Python. Since it isn't valid Python, # reformatting fails and the entire thing is skipped. @@ -10671,6 +10769,20 @@ def markdown_over_indented(): pass +# This tests that we can have additional text after the language specifier. +def markdown_additional_info_string(): + """ + Do cool stuff. + + ```python tab="plugin.py" + cool_stuff(1) + ``` + + Done. + """ + pass + + # Tests that an unclosed block gobbles up everything remaining in the # docstring, even if it isn't valid Python. Since it isn't valid Python, # reformatting fails and the entire thing is skipped. @@ -12021,6 +12133,20 @@ def markdown_over_indented(): pass +# This tests that we can have additional text after the language specifier. +def markdown_additional_info_string(): + """ + Do cool stuff. + + ```python tab="plugin.py" + cool_stuff(1) + ``` + + Done. + """ + pass + + # Tests that an unclosed block gobbles up everything remaining in the # docstring, even if it isn't valid Python. Since it isn't valid Python, # reformatting fails and the entire thing is skipped.