From ef8b2efd135c79ddabcb707b06dabc1af08b7bed Mon Sep 17 00:00:00 2001 From: David Wood Date: Sat, 23 Dec 2017 01:32:55 +0000 Subject: [PATCH] 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. --- src/expr.rs | 6 +++--- tests/source/macros.rs | 1 + tests/target/macros.rs | 6 ++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index 43e153bbe64f..45dabaf7f88a 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -2081,7 +2081,7 @@ where { let one_line_before = all_simple_before && definitive_tactic( - &item_vec[..num_args_before - 1], + &item_vec[..num_args_before], ListTactic::HorizontalVertical, Separator::Comma, nested_shape.width, @@ -2140,8 +2140,8 @@ fn maybe_get_args_offset(callee_str: &str, args: &[&T]) -> Option<(bo .iter() .find(|&&(s, _)| s == callee_str) { - let all_simple_before = num_args_before >= 1 && args.len() >= num_args_before - && is_every_args_simple(&args[..num_args_before]); + let all_simple_before = + args.len() >= num_args_before && is_every_args_simple(&args[..num_args_before]); let all_simple_after = args.len() >= num_args_before + 1 && is_every_args_simple(&args[num_args_before + 1..]); diff --git a/tests/source/macros.rs b/tests/source/macros.rs index 8d02eb67fcbd..4862c4f107d5 100644 --- a/tests/source/macros.rs +++ b/tests/source/macros.rs @@ -272,6 +272,7 @@ fn special_case_macros() { 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!(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, 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); diff --git a/tests/target/macros.rs b/tests/target/macros.rs index 3a9d200bde77..933fe000c9fb 100644 --- a/tests/target/macros.rs +++ b/tests/target/macros.rs @@ -734,6 +734,12 @@ fn special_case_macros() { "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,