From 86a5375e04b296ca3b6e1717ee07009cf5977930 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Wed, 24 Jan 2024 12:10:29 +0530 Subject: [PATCH] Test cases --- ..._line_after_nested_stub_class.options.json | 6 + .../blank_line_after_nested_stub_class.pyi | 174 ++++++++++++++++++ ...e_after_nested_stub_class_eof.options.json | 6 + ...blank_line_after_nested_stub_class_eof.pyi | 17 ++ .../format@stub_files__suite.pyi.snap | 23 +++ 5 files changed, 226 insertions(+) create mode 100644 crates/ruff_python_formatter/resources/test/fixtures/ruff/stub_files/blank_line_after_nested_stub_class.options.json create mode 100644 crates/ruff_python_formatter/resources/test/fixtures/ruff/stub_files/blank_line_after_nested_stub_class.pyi create mode 100644 crates/ruff_python_formatter/resources/test/fixtures/ruff/stub_files/blank_line_after_nested_stub_class_eof.options.json create mode 100644 crates/ruff_python_formatter/resources/test/fixtures/ruff/stub_files/blank_line_after_nested_stub_class_eof.pyi diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/stub_files/blank_line_after_nested_stub_class.options.json b/crates/ruff_python_formatter/resources/test/fixtures/ruff/stub_files/blank_line_after_nested_stub_class.options.json new file mode 100644 index 0000000000000..e8f35d9827789 --- /dev/null +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/stub_files/blank_line_after_nested_stub_class.options.json @@ -0,0 +1,6 @@ +[ + { + "source_type": "Stub", + "preview": "enabled" + } +] diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/stub_files/blank_line_after_nested_stub_class.pyi b/crates/ruff_python_formatter/resources/test/fixtures/ruff/stub_files/blank_line_after_nested_stub_class.pyi new file mode 100644 index 0000000000000..fbb11e68a4202 --- /dev/null +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/stub_files/blank_line_after_nested_stub_class.pyi @@ -0,0 +1,174 @@ +class Top1: + pass +class Top2: + pass + +class Top: + class Ellipsis: ... + class Ellipsis: ... + +class Top: + class Ellipsis: ... + class Pass: + pass + +class Top: + class Ellipsis: ... + class_variable = 1 + +class Top: + class TrailingComment: + pass + # comment + class Other: + pass + +class Top: + class CommentWithEllipsis: ... + # comment + class Other: ... + +class Top: + class TrailingCommentWithMultipleBlankLines: + pass + + + # comment + class Other: + pass + +class Top: + class Nested: + pass + + # comment + class LeadingComment: + pass + +class Top: + @decorator + class Ellipsis: ... + @decorator + class Ellipsis: ... + +class Top: + @decorator + class Ellipsis: ... + @decorator + class Pass: + pass + +class Top: + class Foo: + pass + + + + + class AfterMultipleEmptyLines: + pass + +class Top: + class Nested11: + class Nested12: + pass + class Nested21: + pass + +class Top: + class Nested11: + class Nested12: + pass + # comment + class Nested21: + pass + +class Top: + class Nested11: + class Nested12: + pass + # comment + class Nested21: + pass + # comment + +class Top1: + class Nested: + pass +class Top2: + pass + +class Top1: + class Nested: + pass + # comment +class Top2: + pass + +class Top1: + class Nested: + pass +# comment +class Top2: + pass + +if foo: + class Nested1: + pass + class Nested2: + pass +else: + pass + +if foo: + class Nested1: + pass + class Nested2: + pass + # comment +else: + pass + +if top1: + class Nested: + pass +if top2: + pass + +if top1: + class Nested: + pass + # comment +if top2: + pass + +if top1: + class Nested: + pass +# comment +if top2: + pass + +try: + class Try: + pass +except: + class Except: + pass +foo = 1 + +match foo: + case 1: + class Nested: + pass + case 2: + class Nested: + pass + case _: + class Nested: + pass +foo = 1 + +class Eof: + class Nested: + pass diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/stub_files/blank_line_after_nested_stub_class_eof.options.json b/crates/ruff_python_formatter/resources/test/fixtures/ruff/stub_files/blank_line_after_nested_stub_class_eof.options.json new file mode 100644 index 0000000000000..e8f35d9827789 --- /dev/null +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/stub_files/blank_line_after_nested_stub_class_eof.options.json @@ -0,0 +1,6 @@ +[ + { + "source_type": "Stub", + "preview": "enabled" + } +] diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/stub_files/blank_line_after_nested_stub_class_eof.pyi b/crates/ruff_python_formatter/resources/test/fixtures/ruff/stub_files/blank_line_after_nested_stub_class_eof.pyi new file mode 100644 index 0000000000000..50007377e19e1 --- /dev/null +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/stub_files/blank_line_after_nested_stub_class_eof.pyi @@ -0,0 +1,17 @@ +# A separate file to test out the behavior when there are a mix of blank lines +# and comments at EOF just after a nested stub class. + +class Top: + class Nested1: + class Nested12: + pass + # comment + class Nested2: + pass + + + +# comment + + + diff --git a/crates/ruff_python_formatter/tests/snapshots/format@stub_files__suite.pyi.snap b/crates/ruff_python_formatter/tests/snapshots/format@stub_files__suite.pyi.snap index 9edc789b5fabd..cea732f045fe3 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@stub_files__suite.pyi.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@stub_files__suite.pyi.snap @@ -309,4 +309,27 @@ class ComplexStatements: ``` +## Preview changes +```diff +--- Stable ++++ Preview +@@ -110,6 +110,7 @@ + + class InnerClass5: + def a(self): ... ++ + field1 = 1 + + class InnerClass6: +@@ -119,6 +120,7 @@ + + class InnerClass7: + def a(self): ... ++ + print("hi") + + class InnerClass8: +``` + +