Skip to content

Commit 99a52eb

Browse files
committed
update snapshot tests
1 parent 7efede9 commit 99a52eb

8 files changed

Lines changed: 74 additions & 32 deletions

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ruff_linter/resources/test/fixtures/pyupgrade/UP032_0.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,6 @@ async def c():
276276
number = 0
277277
string = "{}".format(number := number + 1)
278278
print(string)
279+
280+
# Unicode escape
281+
"\N{angle}AOB = {angle}°".format(angle=180)

crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP032_0.py.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,3 +1368,19 @@ help: Convert to f-string
13681368
- string = "{}".format(number := number + 1)
13691369
277 + string = f"{(number := number + 1)}"
13701370
278 | print(string)
1371+
279 |
1372+
280 | # Unicode escape
1373+
1374+
UP032 [*] Use f-string instead of `format` call
1375+
--> UP032_0.py:281:1
1376+
|
1377+
280 | # Unicode escape
1378+
281 | "\N{angle}AOB = {angle}°".format(angle=180)
1379+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1380+
|
1381+
help: Convert to f-string
1382+
278 | print(string)
1383+
279 |
1384+
280 | # Unicode escape
1385+
- "\N{angle}AOB = {angle}°".format(angle=180)
1386+
281 + f"\N{angle}AOB = {180}°"

crates/ruff_python_literal/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ itertools = { workspace = true }
2222
unic-ucd-category = { workspace = true }
2323

2424
[dev-dependencies]
25+
insta = { workspace = true }
2526

2627
[lints]
2728
workspace = true

crates/ruff_python_literal/src/format.rs

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ impl<'a> FromTemplate<'a> for FormatString {
729729
#[cfg(test)]
730730
mod tests {
731731
use super::*;
732+
use insta::assert_debug_snapshot;
732733

733734
#[test]
734735
fn test_fill_and_align() {
@@ -1042,45 +1043,16 @@ mod tests {
10421043

10431044
#[test]
10441045
fn test_format_unicode_escape() {
1045-
let expected = Ok(FormatString {
1046-
format_parts: vec![FormatPart::Literal("I am a \\N{snowman}".to_owned())],
1047-
});
1048-
1049-
assert_eq!(FormatString::from_str("I am a \\N{snowman}"), expected);
1046+
assert_debug_snapshot!(FormatString::from_str("I am a \\N{snowman}"));
10501047
}
10511048

10521049
#[test]
10531050
fn test_format_unicode_escape_with_field() {
1054-
let expected = Ok(FormatString {
1055-
format_parts: vec![
1056-
FormatPart::Literal("I am a \\N{snowman}".to_owned()),
1057-
FormatPart::Field {
1058-
field_name: "snowman".to_owned(),
1059-
conversion_spec: None,
1060-
format_spec: String::new(),
1061-
},
1062-
],
1063-
});
1064-
1065-
assert_eq!(
1066-
FormatString::from_str("I am a \\N{snowman}{snowman}"),
1067-
expected
1068-
);
1051+
assert_debug_snapshot!(FormatString::from_str("I am a \\N{snowman}{snowman}"))
10691052
}
10701053

10711054
#[test]
10721055
fn test_format_multiple_escape_with_field() {
1073-
let expected = Ok(FormatString {
1074-
format_parts: vec![
1075-
FormatPart::Literal("I am a \\\\N".to_owned()),
1076-
FormatPart::Field {
1077-
field_name: "snowman".to_owned(),
1078-
conversion_spec: None,
1079-
format_spec: String::new(),
1080-
},
1081-
],
1082-
});
1083-
1084-
assert_eq!(FormatString::from_str("I am a \\\\N{snowman}"), expected);
1056+
assert_debug_snapshot!(FormatString::from_str("I am a \\\\N{snowman}"));
10851057
}
10861058
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
source: crates/ruff_python_literal/src/format.rs
3+
expression: "FormatString::from_str(\"I am a \\\\\\\\N{snowman}\")"
4+
---
5+
Ok(
6+
FormatString {
7+
format_parts: [
8+
Literal(
9+
"I am a \\\\N",
10+
),
11+
Field {
12+
field_name: "snowman",
13+
conversion_spec: None,
14+
format_spec: "",
15+
},
16+
],
17+
},
18+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
source: crates/ruff_python_literal/src/format.rs
3+
expression: "FormatString::from_str(\"I am a \\\\N{snowman}\")"
4+
---
5+
Ok(
6+
FormatString {
7+
format_parts: [
8+
Literal(
9+
"I am a \\N{snowman}",
10+
),
11+
],
12+
},
13+
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
source: crates/ruff_python_literal/src/format.rs
3+
expression: "FormatString::from_str(\"I am a \\\\N{snowman}{snowman}\")"
4+
---
5+
Ok(
6+
FormatString {
7+
format_parts: [
8+
Literal(
9+
"I am a \\N{snowman}",
10+
),
11+
Field {
12+
field_name: "snowman",
13+
conversion_spec: None,
14+
format_spec: "",
15+
},
16+
],
17+
},
18+
)

0 commit comments

Comments
 (0)