-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[internal]
ComparableExpr
(f)strings and bytes made invariant under…
… concatenation (#13301)
- Loading branch information
Showing
3 changed files
with
174 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
crates/ruff_python_ast_integration_tests/tests/comparable.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use ruff_python_ast::comparable::ComparableExpr; | ||
use ruff_python_parser::{parse_expression, ParseError}; | ||
|
||
#[test] | ||
fn concatenated_strings_compare_equal() -> Result<(), ParseError> { | ||
let split_contents = r#"'a' 'b' r'\n raw'"#; | ||
let value_contents = r#"'ab\\n raw'"#; | ||
|
||
let split_parsed = parse_expression(split_contents)?; | ||
let value_parsed = parse_expression(value_contents)?; | ||
|
||
let split_compr = ComparableExpr::from(split_parsed.expr()); | ||
let value_compr = ComparableExpr::from(value_parsed.expr()); | ||
|
||
assert_eq!(split_compr, value_compr); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn concatenated_bytes_compare_equal() -> Result<(), ParseError> { | ||
let split_contents = r#"b'a' b'b'"#; | ||
let value_contents = r#"b'ab'"#; | ||
|
||
let split_parsed = parse_expression(split_contents)?; | ||
let value_parsed = parse_expression(value_contents)?; | ||
|
||
let split_compr = ComparableExpr::from(split_parsed.expr()); | ||
let value_compr = ComparableExpr::from(value_parsed.expr()); | ||
|
||
assert_eq!(split_compr, value_compr); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn concatenated_fstrings_compare_equal() -> Result<(), ParseError> { | ||
let split_contents = r#"f"{foo!r} this" r"\n raw" f" and {bar!s} that""#; | ||
let value_contents = r#"f"{foo!r} this\\n raw and {bar!s} that""#; | ||
|
||
let split_parsed = parse_expression(split_contents)?; | ||
let value_parsed = parse_expression(value_contents)?; | ||
|
||
let split_compr = ComparableExpr::from(split_parsed.expr()); | ||
let value_compr = ComparableExpr::from(value_parsed.expr()); | ||
|
||
assert_eq!(split_compr, value_compr); | ||
Ok(()) | ||
} |