mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-21 12:05:10 +00:00
Use new formatter infrastructure in CLI and test (#4767)
* Use dummy verbatim formatter for all nodes * Use new formatter infrastructure in CLI and test * Expose the new formatter in the CLI * Merge import blocks
This commit is contained in:
parent
9bf168c0a4
commit
d4027d8b65
6 changed files with 64 additions and 41 deletions
|
@ -16,7 +16,6 @@ use ruff_python_ast::source_code::{CommentRanges, CommentRangesBuilder, Locator}
|
|||
|
||||
use crate::comments::Comments;
|
||||
use crate::context::PyFormatContext;
|
||||
use crate::module::FormatModule;
|
||||
|
||||
pub mod cli;
|
||||
mod comments;
|
||||
|
@ -130,9 +129,9 @@ pub fn format_node<'a>(
|
|||
line_width: 88.try_into().unwrap(),
|
||||
},
|
||||
locator.contents(),
|
||||
comments
|
||||
comments,
|
||||
),
|
||||
[FormatModule::new(root)]
|
||||
[root.format()]
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -165,13 +164,33 @@ mod tests {
|
|||
use insta::assert_snapshot;
|
||||
use rustpython_parser::lexer::lex;
|
||||
use rustpython_parser::{parse_tokens, Mode};
|
||||
use similar::TextDiff;
|
||||
|
||||
use ruff_python_ast::source_code::CommentRangesBuilder;
|
||||
use ruff_testing_macros::fixture;
|
||||
use similar::TextDiff;
|
||||
|
||||
use crate::{format_module, format_node};
|
||||
|
||||
/// Very basic test intentionally kept very similar to the CLI
|
||||
#[test]
|
||||
fn basic() -> Result<()> {
|
||||
let input = r#"
|
||||
# preceding
|
||||
if True:
|
||||
print( "hi" )
|
||||
# trailing
|
||||
"#;
|
||||
let expected = r#"
|
||||
# preceding
|
||||
if True:
|
||||
print( "hi" )
|
||||
# trailing
|
||||
"#;
|
||||
let actual = format_module(input)?.as_code().to_string();
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[fixture(pattern = "resources/test/fixtures/black/**/*.py")]
|
||||
#[test]
|
||||
fn black_test(input_path: &Path) -> Result<()> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue