ruff/crates/ruff_python_formatter/src/snapshots
Micha Reiser 3973836420
Correctly handle left/right breaking of binary expression
<!--
Thank you for contributing to Ruff! To help us out with reviewing, please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary
Black supports for layouts when it comes to breaking binary expressions:

```rust
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
enum BinaryLayout {
    /// Put each operand on their own line if either side expands
    Default,

    /// Try to expand the left to make it fit. Add parentheses if the left or right don't fit.
    ///
    ///```python
    /// [
    ///     a,
    ///     b
    /// ] & c
    ///```
    ExpandLeft,

    /// Try to expand the right to make it fix. Add parentheses if the left or right don't fit.
    ///
    /// ```python
    /// a & [
    ///     b,
    ///     c
    /// ]
    /// ```
    ExpandRight,

    /// Both the left and right side can be expanded. Try in the following order:
    /// * expand the right side
    /// * expand the left side
    /// * expand both sides
    ///
    /// to make the expression fit
    ///
    /// ```python
    /// [
    ///     a,
    ///     b
    /// ] & [
    ///     c,
    ///     d
    /// ]
    /// ```
    ExpandRightThenLeft,
}
```

Our current implementation only handles `ExpandRight` and `Default` correctly. This PR adds support for `ExpandRightThenLeft` and `ExpandLeft`. 

## Test Plan

I added tests that play through all 4 binary expression layouts.
2023-06-21 09:40:05 +02:00
..
ruff_python_formatter__tests__black_test__attribute_access_on_number_literals_py.snap Format if statements (#4961) 2023-06-09 10:55:14 +02:00
ruff_python_formatter__tests__black_test__beginning_backslash_py.snap A basic StmtAssign formatter and better dummies for expressions (#4938) 2023-06-08 12:20:25 +02:00
ruff_python_formatter__tests__black_test__bracketmatch_py.snap A basic StmtAssign formatter and better dummies for expressions (#4938) 2023-06-08 12:20:25 +02:00
ruff_python_formatter__tests__black_test__class_blank_parentheses_py.snap Format Function definitions (#4951) 2023-06-08 16:07:33 +00:00
ruff_python_formatter__tests__black_test__class_methods_new_line_py.snap Replace verbatim text with NOT_YET_IMPLEMENTED (#4904) 2023-06-07 14:57:25 +02:00
ruff_python_formatter__tests__black_test__collections_py.snap basic formatting for ExprDict (#5167) 2023-06-20 09:25:08 +00:00
ruff_python_formatter__tests__black_test__comment_after_escaped_newline_py.snap Format Function definitions (#4951) 2023-06-08 16:07:33 +00:00
ruff_python_formatter__tests__black_test__comments2_py.snap Format continue statement (#5165) 2023-06-18 11:25:59 +00:00
ruff_python_formatter__tests__black_test__comments3_py.snap Format if statements (#4961) 2023-06-09 10:55:14 +02:00
ruff_python_formatter__tests__black_test__comments4_py.snap Format Function definitions (#4951) 2023-06-08 16:07:33 +00:00
ruff_python_formatter__tests__black_test__comments5_py.snap Format if statements (#4961) 2023-06-09 10:55:14 +02:00
ruff_python_formatter__tests__black_test__comments6_py.snap Format ExprTuple (#4963) 2023-06-12 12:55:47 +00:00
ruff_python_formatter__tests__black_test__comments9_py.snap Format if statements (#4961) 2023-06-09 10:55:14 +02:00
ruff_python_formatter__tests__black_test__comments_non_breaking_space_py.snap Format ExprTuple (#4963) 2023-06-12 12:55:47 +00:00
ruff_python_formatter__tests__black_test__comments_py.snap basic formatting for ExprDict (#5167) 2023-06-20 09:25:08 +00:00
ruff_python_formatter__tests__black_test__composition_no_trailing_comma_py.snap Replace verbatim text with NOT_YET_IMPLEMENTED (#4904) 2023-06-07 14:57:25 +02:00
ruff_python_formatter__tests__black_test__composition_py.snap Replace verbatim text with NOT_YET_IMPLEMENTED (#4904) 2023-06-07 14:57:25 +02:00
ruff_python_formatter__tests__black_test__docstring_no_extra_empty_line_before_eof_py.snap Replace verbatim text with NOT_YET_IMPLEMENTED (#4904) 2023-06-07 14:57:25 +02:00
ruff_python_formatter__tests__black_test__docstring_preview_py.snap Format Function definitions (#4951) 2023-06-08 16:07:33 +00:00
ruff_python_formatter__tests__black_test__docstring_py.snap Format Function definitions (#4951) 2023-06-08 16:07:33 +00:00
ruff_python_formatter__tests__black_test__empty_lines_py.snap Format if statements (#4961) 2023-06-09 10:55:14 +02:00
ruff_python_formatter__tests__black_test__expression_py.snap basic formatting for ExprDict (#5167) 2023-06-20 09:25:08 +00:00
ruff_python_formatter__tests__black_test__fmtonoff2_py.snap Format ExprTuple (#4963) 2023-06-12 12:55:47 +00:00
ruff_python_formatter__tests__black_test__fmtonoff3_py.snap Add basic Constant formatting (#4954) 2023-06-08 11:42:44 +00:00
ruff_python_formatter__tests__black_test__fmtonoff4_py.snap Format Function definitions (#4951) 2023-06-08 16:07:33 +00:00
ruff_python_formatter__tests__black_test__fmtonoff5_py.snap Format if statements (#4961) 2023-06-09 10:55:14 +02:00
ruff_python_formatter__tests__black_test__fmtonoff_py.snap basic formatting for ExprDict (#5167) 2023-06-20 09:25:08 +00:00
ruff_python_formatter__tests__black_test__fmtskip2_py.snap Add basic Constant formatting (#4954) 2023-06-08 11:42:44 +00:00
ruff_python_formatter__tests__black_test__fmtskip3_py.snap Format ExprTuple (#4963) 2023-06-12 12:55:47 +00:00
ruff_python_formatter__tests__black_test__fmtskip4_py.snap Add basic Constant formatting (#4954) 2023-06-08 11:42:44 +00:00
ruff_python_formatter__tests__black_test__fmtskip5_py.snap Format ExprTuple (#4963) 2023-06-12 12:55:47 +00:00
ruff_python_formatter__tests__black_test__fmtskip6_py.snap Replace verbatim text with NOT_YET_IMPLEMENTED (#4904) 2023-06-07 14:57:25 +02:00
ruff_python_formatter__tests__black_test__fmtskip7_py.snap Add basic Constant formatting (#4954) 2023-06-08 11:42:44 +00:00
ruff_python_formatter__tests__black_test__fmtskip8_py.snap Format if statements (#4961) 2023-06-09 10:55:14 +02:00
ruff_python_formatter__tests__black_test__fmtskip_py.snap Format ExprTuple (#4963) 2023-06-12 12:55:47 +00:00
ruff_python_formatter__tests__black_test__fstring_py.snap Replace verbatim text with NOT_YET_IMPLEMENTED (#4904) 2023-06-07 14:57:25 +02:00
ruff_python_formatter__tests__black_test__function2_py.snap Format if statements (#4961) 2023-06-09 10:55:14 +02:00
ruff_python_formatter__tests__black_test__function_py.snap basic formatting for ExprDict (#5167) 2023-06-20 09:25:08 +00:00
ruff_python_formatter__tests__black_test__function_trailing_comma_py.snap basic formatting for ExprDict (#5167) 2023-06-20 09:25:08 +00:00
ruff_python_formatter__tests__black_test__import_spacing_py.snap Add basic Constant formatting (#4954) 2023-06-08 11:42:44 +00:00
ruff_python_formatter__tests__black_test__one_element_subscript_py.snap Add basic Constant formatting (#4954) 2023-06-08 11:42:44 +00:00
ruff_python_formatter__tests__black_test__power_op_spacing_py.snap basic formatting for ExprDict (#5167) 2023-06-20 09:25:08 +00:00
ruff_python_formatter__tests__black_test__prefer_rhs_split_reformatted_py.snap Format ExprTuple (#4963) 2023-06-12 12:55:47 +00:00
ruff_python_formatter__tests__black_test__remove_await_parens_py.snap Format Function definitions (#4951) 2023-06-08 16:07:33 +00:00
ruff_python_formatter__tests__black_test__remove_except_parens_py.snap Replace verbatim text with NOT_YET_IMPLEMENTED (#4904) 2023-06-07 14:57:25 +02:00
ruff_python_formatter__tests__black_test__remove_for_brackets_py.snap Replace verbatim text with NOT_YET_IMPLEMENTED (#4904) 2023-06-07 14:57:25 +02:00
ruff_python_formatter__tests__black_test__remove_newline_after_code_block_open_py.snap Format if statements (#4961) 2023-06-09 10:55:14 +02:00
ruff_python_formatter__tests__black_test__remove_parens_py.snap Format ExprTuple (#4963) 2023-06-12 12:55:47 +00:00
ruff_python_formatter__tests__black_test__return_annotation_brackets_py.snap Format Function definitions (#4951) 2023-06-08 16:07:33 +00:00
ruff_python_formatter__tests__black_test__skip_magic_trailing_comma_py.snap Format ExprTuple (#4963) 2023-06-12 12:55:47 +00:00
ruff_python_formatter__tests__black_test__slices_py.snap Format ExprTuple (#4963) 2023-06-12 12:55:47 +00:00
ruff_python_formatter__tests__black_test__string_prefixes_py.snap Format ExprTuple (#4963) 2023-06-12 12:55:47 +00:00
ruff_python_formatter__tests__black_test__torture_py.snap Format ExprTuple (#4963) 2023-06-12 12:55:47 +00:00
ruff_python_formatter__tests__black_test__trailing_comma_optional_parens1_py.snap Format if statements (#4961) 2023-06-09 10:55:14 +02:00
ruff_python_formatter__tests__black_test__trailing_comma_optional_parens2_py.snap Format if statements (#4961) 2023-06-09 10:55:14 +02:00
ruff_python_formatter__tests__black_test__trailing_comma_optional_parens3_py.snap basic formatting for ExprDict (#5167) 2023-06-20 09:25:08 +00:00
ruff_python_formatter__tests__black_test__trailing_commas_in_leading_parts_py.snap Format ExprTuple (#4963) 2023-06-12 12:55:47 +00:00
ruff_python_formatter__tests__black_test__tupleassign_py.snap Format ExprTuple (#4963) 2023-06-12 12:55:47 +00:00
ruff_python_formatter__tests__ruff_test__expression__binary_py.snap Correctly handle left/right breaking of binary expression 2023-06-21 09:40:05 +02:00
ruff_python_formatter__tests__ruff_test__expression__dict_py.snap basic formatting for ExprDict (#5167) 2023-06-20 09:25:08 +00:00
ruff_python_formatter__tests__ruff_test__expression__list_py.snap Fix a number of formatter errors from the cpython repository (#5089) 2023-06-15 11:24:14 +00:00
ruff_python_formatter__tests__ruff_test__expression__tuple_py.snap Fix a number of formatter errors from the cpython repository (#5089) 2023-06-15 11:24:14 +00:00
ruff_python_formatter__tests__ruff_test__statement__assign_py.snap Fix a number of formatter errors from the cpython repository (#5089) 2023-06-15 11:24:14 +00:00
ruff_python_formatter__tests__ruff_test__statement__break_py.snap format StmtBreak (#5158) 2023-06-17 10:31:29 +02:00
ruff_python_formatter__tests__ruff_test__statement__function_py.snap Fix ArgWithDefault comments handling (#5204) 2023-06-20 20:48:07 +00:00
ruff_python_formatter__tests__ruff_test__statement__if_py.snap Fix a number of formatter errors from the cpython repository (#5089) 2023-06-15 11:24:14 +00:00
ruff_python_formatter__tests__ruff_test__statement__while_py.snap Implement StmtPass (#4959) 2023-06-08 16:29:27 +02:00
ruff_python_formatter__tests__ruff_test__trivia_py.snap Add basic Constant formatting (#4954) 2023-06-08 11:42:44 +00:00
ruff_python_formatter__tests__string_processing.snap Prototype Black's string joining/splitting (#4449) 2023-05-16 18:42:40 +01:00
ruff_python_formatter__trivia__tests__Reverse.snap Simple lexer for formatter (#4922) 2023-06-08 17:37:39 +02:00
ruff_python_formatter__trivia__tests__tokenize_bogus.snap Simple lexer for formatter (#4922) 2023-06-08 17:37:39 +02:00
ruff_python_formatter__trivia__tests__tokenize_comma.snap Fix a number of formatter errors from the cpython repository (#5089) 2023-06-15 11:24:14 +00:00
ruff_python_formatter__trivia__tests__tokenize_continuation.snap Fix a number of formatter errors from the cpython repository (#5089) 2023-06-15 11:24:14 +00:00
ruff_python_formatter__trivia__tests__tokenize_parentheses.snap Fix a number of formatter errors from the cpython repository (#5089) 2023-06-15 11:24:14 +00:00
ruff_python_formatter__trivia__tests__tokenize_slash.snap Simple lexer for formatter (#4922) 2023-06-08 17:37:39 +02:00
ruff_python_formatter__trivia__tests__tokenize_substring.snap Fix a number of formatter errors from the cpython repository (#5089) 2023-06-15 11:24:14 +00:00
ruff_python_formatter__trivia__tests__tokenize_trivia.snap Fix a number of formatter errors from the cpython repository (#5089) 2023-06-15 11:24:14 +00:00