Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin committed Aug 25, 2023
1 parent 5b211e4 commit b2235f9
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 27 deletions.
48 changes: 32 additions & 16 deletions crates/ruff_formatter/src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ use Tag::*;
///
/// Soft line breaks are emitted if the enclosing `Group` doesn't fit on a single line
/// ```
/// use ruff_formatter::{format, format_args, LineLength, SimpleFormatOptions};
/// use ruff_python_trivia::LineLength;
/// use ruff_formatter::{format, format_args, SimpleFormatOptions};
/// use ruff_formatter::prelude::*;
///
/// # fn main() -> FormatResult<()> {
Expand Down Expand Up @@ -161,7 +162,8 @@ pub const fn empty_line() -> Line {
///
/// The printer breaks the lines if the enclosing `Group` doesn't fit on a single line:
/// ```
/// use ruff_formatter::{format_args, format, LineLength, SimpleFormatOptions};
/// use ruff_python_trivia::LineLength;
/// use ruff_formatter::{format_args, format, SimpleFormatOptions};
/// use ruff_formatter::prelude::*;
///
/// # fn main() -> FormatResult<()> {
Expand Down Expand Up @@ -537,8 +539,9 @@ impl<Context> Format<Context> for LineSuffixBoundary {
/// ## Examples
///
/// ```rust
/// use ruff_python_trivia::LineLength;
/// use ruff_formatter::prelude::*;
/// use ruff_formatter::{format, write, LineLength};
/// use ruff_formatter::{format, write};
///
/// #[derive(Debug, Copy, Clone)]
/// enum MyLabels {
Expand Down Expand Up @@ -1038,7 +1041,8 @@ pub fn block_indent<Context>(content: &impl Format<Context>) -> BlockIndent<Cont
/// Indents the content by one level and puts in new lines if the enclosing `Group` doesn't fit on a single line
///
/// ```
/// use ruff_formatter::{format, format_args, LineLength, SimpleFormatOptions};
/// use ruff_python_trivia::LineLength;
/// use ruff_formatter::{format, format_args, SimpleFormatOptions};
/// use ruff_formatter::prelude::*;
///
/// # fn main() -> FormatResult<()> {
Expand Down Expand Up @@ -1112,7 +1116,8 @@ pub fn soft_block_indent<Context>(content: &impl Format<Context>) -> BlockIndent
/// fit on a single line. Otherwise, just inserts a space.
///
/// ```
/// use ruff_formatter::{format, format_args, LineLength, SimpleFormatOptions};
/// use ruff_python_trivia::LineLength;
/// use ruff_formatter::{format, format_args, SimpleFormatOptions};
/// use ruff_formatter::prelude::*;
///
/// # fn main() -> FormatResult<()> {
Expand Down Expand Up @@ -1244,7 +1249,8 @@ impl<Context> std::fmt::Debug for BlockIndent<'_, Context> {
/// Adds line breaks and indents the content if the enclosing group doesn't fit on the line.
///
/// ```
/// use ruff_formatter::{format, format_args, LineLength, SimpleFormatOptions};
/// use ruff_python_trivia::LineLength;
/// use ruff_formatter::{format, format_args, SimpleFormatOptions};
/// use ruff_formatter::prelude::*;
///
/// # fn main() -> FormatResult<()> {
Expand Down Expand Up @@ -1349,7 +1355,8 @@ pub fn soft_space_or_block_indent<Context>(content: &impl Format<Context>) -> Bl
///
/// The printer breaks the `Group` over multiple lines if its content doesn't fit on a single line
/// ```
/// use ruff_formatter::{format, format_args, LineLength, SimpleFormatOptions};
/// use ruff_python_trivia::LineLength;
/// use ruff_formatter::{format, format_args, SimpleFormatOptions};
/// use ruff_formatter::prelude::*;
///
/// # fn main() -> FormatResult<()> {
Expand Down Expand Up @@ -1454,7 +1461,8 @@ impl<Context> std::fmt::Debug for Group<'_, Context> {
///
/// ```
/// # use ruff_formatter::prelude::*;
/// # use ruff_formatter::{format, format_args, LineLength, SimpleFormatOptions};
/// use ruff_python_trivia::LineLength;
/// # use ruff_formatter::{format, format_args, SimpleFormatOptions};
///
/// # fn main() -> FormatResult<()> {
/// use ruff_formatter::Formatted;
Expand Down Expand Up @@ -1583,7 +1591,8 @@ impl<Context> std::fmt::Debug for ConditionalGroup<'_, Context> {
/// ## Examples
///
/// ```
/// use ruff_formatter::{format, format_args, LineLength};
/// use ruff_python_trivia::LineLength;
/// use ruff_formatter::{format, format_args};
/// use ruff_formatter::prelude::*;
///
/// # fn main() -> FormatResult<()> {
Expand Down Expand Up @@ -1668,7 +1677,8 @@ impl<Context> Format<Context> for ExpandParent {
///
/// Prints the trailing comma for the last array element if the `Group` doesn't fit on a single line
/// ```
/// use ruff_formatter::{format_args, format, LineLength, SimpleFormatOptions};
/// use ruff_python_trivia::LineLength;
/// use ruff_formatter::{format_args, format, SimpleFormatOptions};
/// use ruff_formatter::prelude::*;
/// use ruff_formatter::printer::PrintWidth;
///
Expand Down Expand Up @@ -1750,7 +1760,8 @@ where
///
/// Omits the trailing comma for the last array element if the `Group` doesn't fit on a single line
/// ```
/// use ruff_formatter::{format, format_args, LineLength, SimpleFormatOptions};
/// use ruff_python_trivia::LineLength;
/// use ruff_formatter::{format, format_args, SimpleFormatOptions};
/// use ruff_formatter::prelude::*;
///
/// # fn main() -> FormatResult<()> {
Expand Down Expand Up @@ -1812,7 +1823,8 @@ impl<Context> IfGroupBreaks<'_, Context> {
/// The item `[4]` in this example fits on a single line but the trailing comma should still be printed
///
/// ```
/// use ruff_formatter::{format, format_args, write, LineLength, SimpleFormatOptions};
/// use ruff_python_trivia::LineLength;
/// use ruff_formatter::{format, format_args, write, SimpleFormatOptions};
/// use ruff_formatter::prelude::*;
///
/// # fn main() -> FormatResult<()> {
Expand Down Expand Up @@ -1915,7 +1927,8 @@ impl<Context> std::fmt::Debug for IfGroupBreaks<'_, Context> {
///
/// Indent the body of an arrow function if the group wrapping the signature breaks:
/// ```
/// use ruff_formatter::{format, format_args, LineLength, SimpleFormatOptions, write};
/// use ruff_python_trivia::LineLength;
/// use ruff_formatter::{format, format_args, SimpleFormatOptions, write};
/// use ruff_formatter::prelude::*;
///
/// # fn main() -> FormatResult<()> {
Expand Down Expand Up @@ -1945,7 +1958,8 @@ impl<Context> std::fmt::Debug for IfGroupBreaks<'_, Context> {
///
/// It doesn't add an indent if the group wrapping the signature doesn't break:
/// ```
/// use ruff_formatter::{format, format_args, LineLength, SimpleFormatOptions, write};
/// use ruff_python_trivia::LineLength;
/// use ruff_formatter::{format, format_args, SimpleFormatOptions, write};
/// use ruff_formatter::prelude::*;
///
/// # fn main() -> FormatResult<()> {
Expand Down Expand Up @@ -2017,7 +2031,8 @@ impl<Context> std::fmt::Debug for IndentIfGroupBreaks<'_, Context> {
/// that spans multiple lines.
///
/// ```
/// # use ruff_formatter::{format, format_args, LineLength, SimpleFormatOptions, write};
/// use ruff_python_trivia::LineLength;
/// # use ruff_formatter::{format, format_args, SimpleFormatOptions, write};
/// # use ruff_formatter::prelude::*;
///
/// # fn main() -> FormatResult<()> {
Expand Down Expand Up @@ -2432,7 +2447,8 @@ impl<'a, Context> BestFitting<'a, Context> {
/// ### All Lines
///
/// ```
/// use ruff_formatter::{Formatted, LineLength, format, format_args, SimpleFormatOptions};
/// use ruff_python_trivia::LineLength;
/// use ruff_formatter::{Formatted, format, format_args, SimpleFormatOptions};
/// use ruff_formatter::prelude::*;
///
/// # fn main() -> FormatResult<()> {
Expand Down
10 changes: 5 additions & 5 deletions crates/ruff_formatter/src/format_element/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ mod tests {
soft_block_indent(&format_args![
text("Some longer content"),
space(),
text("That should ultimately break"),
text("That should ultimately break for its length"),
])
])]
)
Expand All @@ -811,7 +811,7 @@ mod tests {
"(",
indent([
soft_line_break,
"Some longer content That should ultimately break"
"Some longer content That should ultimately break for its length"
]),
soft_line_break
])
Expand All @@ -837,7 +837,7 @@ mod tests {

#[test]
fn display_elements_with_source_text_slice() {
let source_code = "Some longer content\nThat should ultimately break";
let source_code = "Some longer content\nThat should ultimately break for its length";
let formatted = format!(
SimpleFormatContext::default().with_source_code(source_code),
[format_with(|f| {
Expand All @@ -852,7 +852,7 @@ mod tests {
),
space(),
source_text_slice(
TextRange::at(TextSize::new(20), TextSize::new(28)),
TextRange::at(TextSize::new(20), TextSize::new(43)),
ContainsNewlines::No
),
])
Expand All @@ -871,7 +871,7 @@ mod tests {
"(",
indent([
soft_line_break,
"Some longer content That should ultimately break"
"Some longer content That should ultimately break for its length"
]),
soft_line_break
])
Expand Down
3 changes: 2 additions & 1 deletion crates/ruff_formatter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ pub type FormatResult<F> = Result<F, FormatError>;
/// Implementing `Format` for a custom struct
///
/// ```
/// use ruff_formatter::{format, write, IndentStyle, LineLength};
/// use ruff_python_trivia::LineLength;
/// use ruff_formatter::{format, write, IndentStyle};
/// use ruff_formatter::prelude::*;
/// use ruff_text_size::TextSize;
///
Expand Down
6 changes: 4 additions & 2 deletions crates/ruff_formatter/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ macro_rules! format {
/// ## Examples
///
/// ```
/// use ruff_formatter::{Formatted, LineLength, format, format_args, SimpleFormatOptions};
/// use ruff_python_trivia::LineLength;
/// use ruff_formatter::{Formatted, format, format_args, SimpleFormatOptions};
/// use ruff_formatter::prelude::*;
///
/// # fn main() -> FormatResult<()> {
Expand Down Expand Up @@ -241,7 +242,8 @@ macro_rules! format {
/// ### Enclosing group with `should_expand: true`
///
/// ```
/// use ruff_formatter::{Formatted, LineLength, format, format_args, SimpleFormatOptions};
/// use ruff_python_trivia::LineLength;
/// use ruff_formatter::{Formatted, format, format_args, SimpleFormatOptions};
/// use ruff_formatter::prelude::*;
///
/// # fn main() -> FormatResult<()> {
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_python_trivia/src/line_width.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::hash::Hasher;
use std::num::ParseIntError;
use std::str::FromStr;

/// Validated value for the `line-length` option
/// The length of a line of text that is considered too long.
///
/// The allowed range of values is 1..=320
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
Expand Down
4 changes: 2 additions & 2 deletions ruff.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b2235f9

Please sign in to comment.