mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 11:59:35 +00:00
Remove lexing from flake8-pytest-style (#6795)
## Summary Another drive-by change to remove unnecessary custom lexing. We just need to know the parenthesized range, so we can use... `parenthesized_range`. I've also updated `parenthesized_range` to support nested parentheses. ## Test Plan `cargo test`
This commit is contained in:
parent
417a1d0717
commit
26e63ab137
3 changed files with 68 additions and 65 deletions
|
@ -1,5 +1,6 @@
|
|||
use ruff_python_ast::parenthesize::parenthesized_range;
|
||||
use ruff_python_parser::parse_expression;
|
||||
use ruff_text_size::TextRange;
|
||||
|
||||
#[test]
|
||||
fn test_parenthesized_name() {
|
||||
|
@ -10,7 +11,7 @@ fn test_parenthesized_name() {
|
|||
let name = bin_op.left.as_ref();
|
||||
|
||||
let parenthesized = parenthesized_range(name.into(), bin_op.into(), source_code);
|
||||
assert!(parenthesized.is_some());
|
||||
assert_eq!(parenthesized, Some(TextRange::new(0.into(), 3.into())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -22,7 +23,7 @@ fn test_non_parenthesized_name() {
|
|||
let name = bin_op.left.as_ref();
|
||||
|
||||
let parenthesized = parenthesized_range(name.into(), bin_op.into(), source_code);
|
||||
assert!(parenthesized.is_none());
|
||||
assert_eq!(parenthesized, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -35,7 +36,7 @@ fn test_parenthesized_argument() {
|
|||
let argument = arguments.args.first().unwrap();
|
||||
|
||||
let parenthesized = parenthesized_range(argument.into(), arguments.into(), source_code);
|
||||
assert!(parenthesized.is_some());
|
||||
assert_eq!(parenthesized, Some(TextRange::new(2.into(), 5.into())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -48,7 +49,7 @@ fn test_non_parenthesized_argument() {
|
|||
let argument = arguments.args.first().unwrap();
|
||||
|
||||
let parenthesized = parenthesized_range(argument.into(), arguments.into(), source_code);
|
||||
assert!(parenthesized.is_none());
|
||||
assert_eq!(parenthesized, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -60,7 +61,7 @@ fn test_parenthesized_tuple_member() {
|
|||
let member = tuple.elts.last().unwrap();
|
||||
|
||||
let parenthesized = parenthesized_range(member.into(), tuple.into(), source_code);
|
||||
assert!(parenthesized.is_some());
|
||||
assert_eq!(parenthesized, Some(TextRange::new(4.into(), 7.into())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -72,5 +73,30 @@ fn test_non_parenthesized_tuple_member() {
|
|||
let member = tuple.elts.last().unwrap();
|
||||
|
||||
let parenthesized = parenthesized_range(member.into(), tuple.into(), source_code);
|
||||
assert!(parenthesized.is_none());
|
||||
assert_eq!(parenthesized, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_twice_parenthesized_name() {
|
||||
let source_code = r#"((x)) + 1"#;
|
||||
let expr = parse_expression(source_code, "<filename>").unwrap();
|
||||
|
||||
let bin_op = expr.as_bin_op_expr().unwrap();
|
||||
let name = bin_op.left.as_ref();
|
||||
|
||||
let parenthesized = parenthesized_range(name.into(), bin_op.into(), source_code);
|
||||
assert_eq!(parenthesized, Some(TextRange::new(0.into(), 5.into())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_twice_parenthesized_argument() {
|
||||
let source_code = r#"f(((a + 1)))"#;
|
||||
let expr = parse_expression(source_code, "<filename>").unwrap();
|
||||
|
||||
let call = expr.as_call_expr().unwrap();
|
||||
let arguments = &call.arguments;
|
||||
let argument = arguments.args.first().unwrap();
|
||||
|
||||
let parenthesized = parenthesized_range(argument.into(), arguments.into(), source_code);
|
||||
assert_eq!(parenthesized, Some(TextRange::new(2.into(), 11.into())));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue