Add assert_format_rewrite() test macro
All previous format tests checked that the output matched the input, but sometimes the formatter output is deliberately different, which can now be tested.
Use this new macro to add 2 tests for the previously added list prepend syntax change ([x | y] to [x, ..y])
@@ -2247,3 +2247,46 @@ fn main() {
"
);
}
+
+#[test]
+fn module_rewrites_test() {
+ macro_rules! assert_format_rewrite {
+ ($src:expr, $output:expr $(,)?) => {
+ assert_eq!(pretty($src).unwrap(), $output);
+ };
+ }
+
+ // Formatter rewrites old [x | y] list prepend syntax to [x, ..y]
+ assert_format_rewrite!(
+ "fn main() {
+ [1, 2, 3 | x]
+}
+",
+ "fn main() {
+ [1, 2, 3, ..x]
+}
+",
+ );
+
+ // Formatter rewrites old [x | y] list prepend syntax to [x, ..y] with line breaks
+ assert_format_rewrite!(
+ "fn main() {
+ [
+ really_long_variable_name,
+ really_long_variable_name,
+ really_long_variable_name
+ | tail
+ ]
+}
+",
+ "fn main() {
+ [
+ really_long_variable_name,
+ really_long_variable_name,
+ really_long_variable_name,
+ ..tail
+ ]
+}
+",
+ );
+}
