Skip to content

Commit b462582

Browse files
committed
Run rustfmt
1 parent cf8fa5c commit b462582

File tree

1 file changed

+42
-23
lines changed

1 file changed

+42
-23
lines changed

src/search.rs

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -678,14 +678,17 @@ pub(crate) fn highlight_line_matches(
678678
// into the stripped string at the point where it is being checked.
679679
let mut inserted_escs_len = 0;
680680
for esc in &escapes {
681-
let match_count: usize = matches.iter()
681+
let match_count: usize = matches
682+
.iter()
682683
.take_while(|(s, _)| *s <= esc.0)
683-
.map(|(_, e)| if *e <= esc.0 {
684-
// if the end of the match is at the same point as the escape, the NORMAL should be
685-
// inserted before the escape so that the escape isn't immediately negated
686-
2
687-
} else {
688-
1
684+
.map(|(_, e)| {
685+
if *e <= esc.0 {
686+
// if the end of the match is at the same point as the escape, the NORMAL should be
687+
// inserted before the escape so that the escape isn't immediately negated
688+
2
689+
} else {
690+
1
691+
}
689692
})
690693
.sum();
691694
// Find how many invert|normal markers appear before this escape
@@ -728,7 +731,8 @@ pub(crate) fn highlight_line_matches(
728731

729732
// then we need to find all of the escapes which would be placed before it in the final
730733
// string
731-
let escapes: usize = escapes.iter()
734+
let escapes: usize = escapes
735+
.iter()
732736
// we take them while their start position in the stripped string is before the end
733737
// position of this match in the final string. We use `<` instead of `<=` b/c we insert
734738
// the escapes back into the inverted string after the NORMAL
@@ -1150,7 +1154,8 @@ eros.",
11501154
#[test]
11511155
fn single_match_no_esc() {
11521156
let res =
1153-
highlight_line_matches("this is a test", &Regex::new(" a ").unwrap(), false).unwrap();
1157+
highlight_line_matches("this is a test", &Regex::new(" a ").unwrap(), false)
1158+
.unwrap();
11541159
assert_eq!(res, format!("this is{} a {}test", *INVERT, *NORMAL));
11551160
}
11561161

@@ -1160,7 +1165,8 @@ eros.",
11601165
"test another test",
11611166
&Regex::new("test").unwrap(),
11621167
false,
1163-
).unwrap();
1168+
)
1169+
.unwrap();
11641170
assert_eq!(
11651171
res,
11661172
format!("{i}test{n} another {i}test{n}", i = *INVERT, n = *NORMAL)
@@ -1175,7 +1181,8 @@ eros.",
11751181
&format!("{ESC}color{NONE} and test"),
11761182
&Regex::new("test").unwrap(),
11771183
false,
1178-
).unwrap();
1184+
)
1185+
.unwrap();
11791186
assert_eq!(
11801187
res,
11811188
format!("{}color{} and {}test{}", ESC, NONE, *INVERT, *NORMAL)
@@ -1185,7 +1192,8 @@ eros.",
11851192
#[test]
11861193
fn esc_pair_end_in_match() {
11871194
let orig = format!("this {ESC}is a te{NONE}st");
1188-
let res = highlight_line_matches(&orig, &Regex::new("test").unwrap(), false).unwrap();
1195+
let res =
1196+
highlight_line_matches(&orig, &Regex::new("test").unwrap(), false).unwrap();
11891197
assert_eq!(
11901198
res,
11911199
format!("this {}is a {}test{}{}", ESC, *INVERT, *NORMAL, NONE)
@@ -1195,7 +1203,8 @@ eros.",
11951203
#[test]
11961204
fn esc_pair_start_in_match() {
11971205
let orig = format!("this is a te{ESC}st again{NONE}");
1198-
let res = highlight_line_matches(&orig, &Regex::new("test").unwrap(), false).unwrap();
1206+
let res =
1207+
highlight_line_matches(&orig, &Regex::new("test").unwrap(), false).unwrap();
11991208
assert_eq!(
12001209
res,
12011210
format!("this is a {}test{}{ESC} again{}", *INVERT, *NORMAL, NONE)
@@ -1205,7 +1214,8 @@ eros.",
12051214
#[test]
12061215
fn esc_pair_around_match() {
12071216
let orig = format!("this is {ESC}a test again{NONE}");
1208-
let res = highlight_line_matches(&orig, &Regex::new("test").unwrap(), false).unwrap();
1217+
let res =
1218+
highlight_line_matches(&orig, &Regex::new("test").unwrap(), false).unwrap();
12091219
assert_eq!(
12101220
res,
12111221
format!("this is {}a {}test{} again{}", ESC, *INVERT, *NORMAL, NONE)
@@ -1215,7 +1225,8 @@ eros.",
12151225
#[test]
12161226
fn esc_pair_within_match() {
12171227
let orig = format!("this is a t{ESC}es{NONE}t again");
1218-
let res = highlight_line_matches(&orig, &Regex::new("test").unwrap(), false).unwrap();
1228+
let res =
1229+
highlight_line_matches(&orig, &Regex::new("test").unwrap(), false).unwrap();
12191230
assert_eq!(
12201231
res,
12211232
format!("this is a {}test{}{ESC}{NONE} again", *INVERT, *NORMAL)
@@ -1225,7 +1236,8 @@ eros.",
12251236
#[test]
12261237
fn multi_escape_match() {
12271238
let orig = format!("this {ESC}is a te{NONE}st again {ESC}yeah{NONE} test",);
1228-
let res = highlight_line_matches(&orig, &Regex::new("test").unwrap(), false).unwrap();
1239+
let res =
1240+
highlight_line_matches(&orig, &Regex::new("test").unwrap(), false).unwrap();
12291241
assert_eq!(
12301242
res,
12311243
format!(
@@ -1246,7 +1258,8 @@ eros.",
12461258
"{ESC}test{NONE} this {ESC}is a te{NONE}st again {ESC}yeah{NONE} test",
12471259
);
12481260

1249-
let res = highlight_line_matches(&orig, &Regex::new("test").unwrap(), true).unwrap();
1261+
let res =
1262+
highlight_line_matches(&orig, &Regex::new("test").unwrap(), true).unwrap();
12501263
assert_eq!(
12511264
res,
12521265
format!(
@@ -1266,7 +1279,8 @@ eros.",
12661279
&format!("{ESC}color{NONE} and test"),
12671280
&Regex::new("test").unwrap(),
12681281
true,
1269-
).unwrap();
1282+
)
1283+
.unwrap();
12701284
assert_eq!(
12711285
res,
12721286
format!("{}color{} and {}test{}", ESC, NONE, *INVERT, *NORMAL)
@@ -1276,7 +1290,8 @@ eros.",
12761290
#[test]
12771291
fn esc_pair_end_in_match() {
12781292
let orig = format!("this {ESC}is a te{NONE}st");
1279-
let res = highlight_line_matches(&orig, &Regex::new("test").unwrap(), true).unwrap();
1293+
let res =
1294+
highlight_line_matches(&orig, &Regex::new("test").unwrap(), true).unwrap();
12801295
assert_eq!(
12811296
res,
12821297
format!("this {ESC}is a {}te{NONE}st{}", *INVERT, *NORMAL)
@@ -1286,7 +1301,8 @@ eros.",
12861301
#[test]
12871302
fn esc_pair_start_in_match() {
12881303
let orig = format!("this is a te{ESC}st again{NONE}");
1289-
let res = highlight_line_matches(&orig, &Regex::new("test").unwrap(), true).unwrap();
1304+
let res =
1305+
highlight_line_matches(&orig, &Regex::new("test").unwrap(), true).unwrap();
12901306
assert_eq!(
12911307
res,
12921308
format!("this is a {}te{ESC}st{} again{NONE}", *INVERT, *NORMAL)
@@ -1296,7 +1312,8 @@ eros.",
12961312
#[test]
12971313
fn esc_pair_around_match() {
12981314
let orig = format!("this is {ESC}a test again{NONE}");
1299-
let res = highlight_line_matches(&orig, &Regex::new("test").unwrap(), true).unwrap();
1315+
let res =
1316+
highlight_line_matches(&orig, &Regex::new("test").unwrap(), true).unwrap();
13001317
assert_eq!(
13011318
res,
13021319
format!("this is {ESC}a {}test{} again{NONE}", *INVERT, *NORMAL)
@@ -1306,7 +1323,8 @@ eros.",
13061323
#[test]
13071324
fn esc_pair_within_match() {
13081325
let orig = format!("this is a t{ESC}es{NONE}t again");
1309-
let res = highlight_line_matches(&orig, &Regex::new("test").unwrap(), true).unwrap();
1326+
let res =
1327+
highlight_line_matches(&orig, &Regex::new("test").unwrap(), true).unwrap();
13101328
assert_eq!(
13111329
res,
13121330
format!("this is a {}t{ESC}es{NONE}t{} again", *INVERT, *NORMAL)
@@ -1316,7 +1334,8 @@ eros.",
13161334
#[test]
13171335
fn multi_escape_match() {
13181336
let orig = format!("this {ESC}is a te{NONE}st again {ESC}yeah{NONE} test",);
1319-
let res = highlight_line_matches(&orig, &Regex::new("test").unwrap(), true).unwrap();
1337+
let res =
1338+
highlight_line_matches(&orig, &Regex::new("test").unwrap(), true).unwrap();
13201339
assert_eq!(
13211340
res,
13221341
format!(

0 commit comments

Comments
 (0)