From 779413d8c1a08c86fc2ea41a72dd92c842da3ab0 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Tue, 19 Dec 2023 00:11:11 -0600 Subject: [PATCH] Add test case for docstring with comments --- ...k_line_before_class_docstring.options.json | 5 + .../ruff/blank_line_before_class_docstring.py | 38 ++++++++ ...@blank_line_before_class_docstring.py.snap | 95 +++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 crates/ruff_python_formatter/resources/test/fixtures/ruff/blank_line_before_class_docstring.options.json create mode 100644 crates/ruff_python_formatter/resources/test/fixtures/ruff/blank_line_before_class_docstring.py create mode 100644 crates/ruff_python_formatter/tests/snapshots/format@blank_line_before_class_docstring.py.snap diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/blank_line_before_class_docstring.options.json b/crates/ruff_python_formatter/resources/test/fixtures/ruff/blank_line_before_class_docstring.options.json new file mode 100644 index 00000000000000..8925dd0a8280f7 --- /dev/null +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/blank_line_before_class_docstring.options.json @@ -0,0 +1,5 @@ +[ + { + "preview": "enabled" + } +] diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/blank_line_before_class_docstring.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/blank_line_before_class_docstring.py new file mode 100644 index 00000000000000..a8dbbafebbfd13 --- /dev/null +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/blank_line_before_class_docstring.py @@ -0,0 +1,38 @@ +class NormalDocstring: + + """This is a docstring.""" + + +class DocstringWithComment0: + # This is a comment + """This is a docstring.""" + + +class DocstringWithComment1: + # This is a comment + + """This is a docstring.""" + + +class DocstringWithComment2: + + # This is a comment + """This is a docstring.""" + + +class DocstringWithComment3: + + # This is a comment + + """This is a docstring.""" + + +class DocstringWithComment4: + + + # This is a comment + + + """This is a docstring.""" + + diff --git a/crates/ruff_python_formatter/tests/snapshots/format@blank_line_before_class_docstring.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@blank_line_before_class_docstring.py.snap new file mode 100644 index 00000000000000..b3986d0395ff1a --- /dev/null +++ b/crates/ruff_python_formatter/tests/snapshots/format@blank_line_before_class_docstring.py.snap @@ -0,0 +1,95 @@ +--- +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/blank_line_before_class_docstring.py +--- +## Input +```python +class NormalDocstring: + + """This is a docstring.""" + + +class DocstringWithComment0: + # This is a comment + """This is a docstring.""" + + +class DocstringWithComment1: + # This is a comment + + """This is a docstring.""" + + +class DocstringWithComment2: + + # This is a comment + """This is a docstring.""" + + +class DocstringWithComment3: + + # This is a comment + + """This is a docstring.""" + + +class DocstringWithComment4: + + + # This is a comment + + + """This is a docstring.""" + + +``` + +## Outputs +### Output 1 +``` +indent-style = space +line-width = 88 +indent-width = 4 +quote-style = Double +line-ending = LineFeed +magic-trailing-comma = Respect +docstring-code = Disabled +docstring-code-line-width = "dynamic" +preview = Enabled +``` + +```python +class NormalDocstring: + """This is a docstring.""" + + +class DocstringWithComment0: + # This is a comment + """This is a docstring.""" + + +class DocstringWithComment1: + # This is a comment + + """This is a docstring.""" + + +class DocstringWithComment2: + # This is a comment + """This is a docstring.""" + + +class DocstringWithComment3: + # This is a comment + + """This is a docstring.""" + + +class DocstringWithComment4: + # This is a comment + + """This is a docstring.""" +``` + + +