Skip to content

Commit 39e2f43

Browse files
committed
Split assert_eq! if any arguments are not simple
1 parent 212a8a3 commit 39e2f43

File tree

4 files changed

+36
-51
lines changed

4 files changed

+36
-51
lines changed

src/expr.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,30 +2082,26 @@ where
20822082
tactic = default_tactic();
20832083

20842084
if tactic == DefinitiveListTactic::Vertical {
2085-
if let Some((all_simple_before, all_simple_after, num_args_before)) =
2085+
if let Some((all_simple, num_args_before)) =
20862086
maybe_get_args_offset(callee_str, args)
20872087
{
2088-
let one_line_before = all_simple_before
2088+
let one_line = all_simple
20892089
&& definitive_tactic(
20902090
&item_vec[..num_args_before],
20912091
ListTactic::HorizontalVertical,
20922092
Separator::Comma,
20932093
nested_shape.width,
2094-
) == DefinitiveListTactic::Horizontal;
2095-
2096-
let one_line_after = all_simple_after
2094+
) == DefinitiveListTactic::Horizontal
20972095
&& definitive_tactic(
20982096
&item_vec[num_args_before + 1..],
20992097
ListTactic::HorizontalVertical,
21002098
Separator::Comma,
21012099
nested_shape.width,
21022100
) == DefinitiveListTactic::Horizontal;
21032101

2104-
tactic = DefinitiveListTactic::SpecialMacro(
2105-
one_line_before,
2106-
one_line_after,
2107-
num_args_before,
2108-
);
2102+
if one_line {
2103+
tactic = DefinitiveListTactic::SpecialMacro(num_args_before);
2104+
};
21092105
}
21102106
}
21112107
}
@@ -2141,18 +2137,14 @@ fn is_every_args_simple<T: ToExpr>(lists: &[&T]) -> bool {
21412137
}
21422138

21432139
/// In case special-case style is required, returns an offset from which we start horizontal layout.
2144-
fn maybe_get_args_offset<T: ToExpr>(callee_str: &str, args: &[&T]) -> Option<(bool, bool, usize)> {
2140+
fn maybe_get_args_offset<T: ToExpr>(callee_str: &str, args: &[&T]) -> Option<(bool, usize)> {
21452141
if let Some(&(_, num_args_before)) = SPECIAL_MACRO_WHITELIST
21462142
.iter()
21472143
.find(|&&(s, _)| s == callee_str)
21482144
{
2149-
let all_simple_before =
2150-
args.len() >= num_args_before && is_every_args_simple(&args[..num_args_before]);
2151-
2152-
let all_simple_after =
2153-
args.len() >= num_args_before + 1 && is_every_args_simple(&args[num_args_before + 1..]);
2145+
let all_simple = args.len() >= num_args_before && is_every_args_simple(args);
21542146

2155-
Some((all_simple_before, all_simple_after, num_args_before))
2147+
Some((all_simple, num_args_before))
21562148
} else {
21572149
None
21582150
}

src/lists.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub enum DefinitiveListTactic {
161161
Horizontal,
162162
Mixed,
163163
/// Special case tactic for `format!()`, `write!()` style macros.
164-
SpecialMacro(bool, bool, usize),
164+
SpecialMacro(usize),
165165
}
166166

167167
impl DefinitiveListTactic {
@@ -311,30 +311,16 @@ where
311311
DefinitiveListTactic::Horizontal if !first => {
312312
result.push(' ');
313313
}
314-
DefinitiveListTactic::SpecialMacro(
315-
one_line_before,
316-
one_line_after,
317-
num_args_before,
318-
) => {
314+
DefinitiveListTactic::SpecialMacro(num_args_before) => {
319315
if i == 0 {
320316
// Nothing
321317
} else if i < num_args_before {
322-
if one_line_before {
323-
result.push(' ');
324-
} else {
325-
result.push('\n');
326-
result.push_str(indent_str);
327-
}
318+
result.push(' ');
328319
} else if i <= num_args_before + 1 {
329320
result.push('\n');
330321
result.push_str(indent_str);
331322
} else {
332-
if one_line_after {
333-
result.push(' ');
334-
} else {
335-
result.push('\n');
336-
result.push_str(indent_str);
337-
}
323+
result.push(' ');
338324
}
339325
}
340326
DefinitiveListTactic::Vertical if !first => {

tests/source/macros.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,21 +267,21 @@ fn special_case_macros() {
267267
warn!("{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26);
268268

269269
assert!(result == 42, "Ahoy there, {}!", target);
270-
assert!(result == 42, "Arr! Batten down the hatches, we got '{}' but not '{}' (we expected '{}')", result, input, expected);
270+
assert!(result == 42, "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')", result, input, expected);
271271
assert!(result == 42, "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26);
272272

273273
assert_eq!(left, right, "Ahoy there, {}!", target);
274-
assert_eq!(left, right, "Arr! Batten down the hatches, we got '{}' but not '{}' (we expected '{}')", result, input, expected);
275-
assert_eq!(first_realllllllllllly_long_variable_that_doesnt_fit_one_one_line, second_reallllllllllly_long_variable_that_doesnt_fit_one_one_line, "Arr! Batten down the hatches, we got '{}' but not '{}' (we expected '{}')", result, input, expected);
276-
assert_eq!(left + 42, right, "Arr! Batten down the hatches, we got '{}' but not '{}' (we expected '{}')", result, input, expected);
274+
assert_eq!(left, right, "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')", result, input, expected);
275+
assert_eq!(first_realllllllllllly_long_variable_that_doesnt_fit_one_one_line, second_reallllllllllly_long_variable_that_doesnt_fit_one_one_line, "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')", result, input, expected);
276+
assert_eq!(left + 42, right, "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')", result, input, expected);
277277
assert_eq!(left, right, "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26);
278278

279279
write!(&mut s, "Ahoy there, {}!", target);
280-
write!(&mut s, "Arr! Batten down the hatches, we got '{}' but not '{}' (we expected '{}')", result, input, expected);
280+
write!(&mut s, "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')", result, input, expected);
281281
write!(&mut s, "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26);
282282

283283
writeln!(&mut s, "Ahoy there, {}!", target);
284-
writeln!(&mut s, "Arr! Batten down the hatches, we got '{}' but not '{}' (we expected '{}')", result, input, expected);
284+
writeln!(&mut s, "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')", result, input, expected);
285285
writeln!(&mut s, "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26);
286286
}
287287

tests/target/macros.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -694,8 +694,10 @@ fn special_case_macros() {
694694
assert!(result == 42, "Ahoy there, {}!", target);
695695
assert!(
696696
result == 42,
697-
"Arr! Batten down the hatches, we got '{}' but not '{}' (we expected '{}')",
698-
result, input, expected
697+
"Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
698+
result,
699+
input,
700+
expected
699701
);
700702
assert!(
701703
result == 42,
@@ -731,23 +733,28 @@ fn special_case_macros() {
731733
assert_eq!(left, right, "Ahoy there, {}!", target);
732734
assert_eq!(
733735
left, right,
734-
"Arr! Batten down the hatches, we got '{}' but not '{}' (we expected '{}')",
736+
"Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
735737
result, input, expected
736738
);
737739
assert_eq!(
738740
first_realllllllllllly_long_variable_that_doesnt_fit_one_one_line,
739741
second_reallllllllllly_long_variable_that_doesnt_fit_one_one_line,
740-
"Arr! Batten down the hatches, we got '{}' but not '{}' (we expected '{}')",
741-
result, input, expected
742+
"Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
743+
result,
744+
input,
745+
expected
742746
);
743747
assert_eq!(
744748
left + 42,
745749
right,
746-
"Arr! Batten down the hatches, we got '{}' but not '{}' (we expected '{}')",
747-
result, input, expected
750+
"Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
751+
result,
752+
input,
753+
expected
748754
);
749755
assert_eq!(
750-
left, right,
756+
left,
757+
right,
751758
"{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
752759
1,
753760
2,
@@ -780,7 +787,7 @@ fn special_case_macros() {
780787
write!(&mut s, "Ahoy there, {}!", target);
781788
write!(
782789
&mut s,
783-
"Arr! Batten down the hatches, we got '{}' but not '{}' (we expected '{}')",
790+
"Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
784791
result, input, expected
785792
);
786793
write!(
@@ -817,7 +824,7 @@ fn special_case_macros() {
817824
writeln!(&mut s, "Ahoy there, {}!", target);
818825
writeln!(
819826
&mut s,
820-
"Arr! Batten down the hatches, we got '{}' but not '{}' (we expected '{}')",
827+
"Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
821828
result, input, expected
822829
);
823830
writeln!(

0 commit comments

Comments
 (0)