Fix off-by-one error in assert_eq! line wrapping

If two really long conditions are checked for equality, they wouldn't be split
into multiple lines if the last condition is the one to push the line past the
width limit.

Fix the off-by-one error that caused this, and add a test-case for it.
This commit is contained in:
David Wood 2017-12-23 01:32:55 +00:00
parent e343521276
commit ef8b2efd13
3 changed files with 10 additions and 3 deletions

View file

@ -2081,7 +2081,7 @@ where
{ {
let one_line_before = all_simple_before let one_line_before = all_simple_before
&& definitive_tactic( && definitive_tactic(
&item_vec[..num_args_before - 1], &item_vec[..num_args_before],
ListTactic::HorizontalVertical, ListTactic::HorizontalVertical,
Separator::Comma, Separator::Comma,
nested_shape.width, nested_shape.width,
@ -2140,8 +2140,8 @@ fn maybe_get_args_offset<T: ToExpr>(callee_str: &str, args: &[&T]) -> Option<(bo
.iter() .iter()
.find(|&&(s, _)| s == callee_str) .find(|&&(s, _)| s == callee_str)
{ {
let all_simple_before = num_args_before >= 1 && args.len() >= num_args_before let all_simple_before =
&& is_every_args_simple(&args[..num_args_before]); args.len() >= num_args_before && is_every_args_simple(&args[..num_args_before]);
let all_simple_after = let all_simple_after =
args.len() >= num_args_before + 1 && is_every_args_simple(&args[num_args_before + 1..]); args.len() >= num_args_before + 1 && is_every_args_simple(&args[num_args_before + 1..]);

View file

@ -272,6 +272,7 @@ fn special_case_macros() {
assert_eq!(left, right, "Ahoy there, {}!", target); assert_eq!(left, right, "Ahoy there, {}!", target);
assert_eq!(left, right, "Arr! Batten down the hatches, we got '{}' but not '{}' (we expected '{}')", result, input, expected); assert_eq!(left, right, "Arr! Batten down the hatches, we got '{}' but not '{}' (we expected '{}')", result, input, expected);
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);
assert_eq!(left + 42, right, "Arr! Batten down the hatches, we got '{}' but not '{}' (we expected '{}')", result, input, expected); assert_eq!(left + 42, right, "Arr! Batten down the hatches, we got '{}' but not '{}' (we expected '{}')", result, input, expected);
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); 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);

View file

@ -734,6 +734,12 @@ fn special_case_macros() {
"Arr! Batten down the hatches, we got '{}' but not '{}' (we expected '{}')", "Arr! Batten down the hatches, we got '{}' but not '{}' (we expected '{}')",
result, input, expected result, input, expected
); );
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
);
assert_eq!( assert_eq!(
left + 42, left + 42,
right, right,