From 8e471ece31abb7e329bffef977e1bd0c7d876b8c Mon Sep 17 00:00:00 2001 From: Marcus Klaas Date: Wed, 9 Sep 2015 23:14:09 +0200 Subject: [PATCH] Add some tests for match blocks --- src/chains.rs | 11 +++++++++++ src/comment.rs | 23 ++++++++--------------- tests/source/chains.rs | 9 +++++++++ tests/target/chains.rs | 8 ++++++++ 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/chains.rs b/src/chains.rs index e5d2a43840b..4eaf0f5acb5 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -8,6 +8,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// Formatting of chained expressions, i.e. expressions which are chained by +// dots: struct and enum field access and method calls. +// +// Instead of walking these subexpressions one-by-one, as is our usual strategy +// for expression formatting, we collect maximal sequences of these expressions +// and handle them simultaneously. +// +// Whenever possible, the entire chain is put on a single line. If that fails, +// we put each subexpression on a separate, much like the (default) function +// argument function argument strategy. + use rewrite::{Rewrite, RewriteContext}; use utils::{make_indent, extra_offset}; use expr::rewrite_call; diff --git a/src/comment.rs b/src/comment.rs index 290fc62e15a..d0eeba9a7c1 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -150,17 +150,6 @@ pub fn contains_comment(text: &str) -> bool { CharClasses::new(text.chars()).any(|(kind, _)| kind == CodeCharKind::Comment) } -pub fn uncommented(text: &str) -> String { - CharClasses::new(text.chars()) - .filter_map(|(s, c)| { - match s { - CodeCharKind::Normal => Some(c), - CodeCharKind::Comment => None, - } - }) - .collect() -} - struct CharClasses where T: Iterator, T::Item: RichChar @@ -321,10 +310,14 @@ mod test { // This is probably intended to be a non-test fn, but it is not used. I'm // keeping it around unless it helps us test stuff. fn uncommented(text: &str) -> String { - CharClasses::new(text.chars()).filter_map(|(s, c)| match s { - CodeCharKind::Normal => Some(c), - CodeCharKind::Comment => None - }).collect() + CharClasses::new(text.chars()) + .filter_map(|(s, c)| { + match s { + CodeCharKind::Normal => Some(c), + CodeCharKind::Comment => None, + } + }) + .collect() } #[test] diff --git a/tests/source/chains.rs b/tests/source/chains.rs index 7e4bda0671e..8282c3baa6b 100644 --- a/tests/source/chains.rs +++ b/tests/source/chains.rs @@ -21,6 +21,15 @@ fn main() { 2 }); + fffffffffffffffffffffffffffffffffff(a, + { + SCRIPT_TASK_ROOT + .with(|root| { + // Another case of write_list failing us. + *root.borrow_mut() = Some(&script_task); + }); + }); + let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum = xxxxxxx .map(|x| x + 5) .map(|x| x / 2) diff --git a/tests/target/chains.rs b/tests/target/chains.rs index 2ed91a2eb8e..daa60d09855 100644 --- a/tests/target/chains.rs +++ b/tests/target/chains.rs @@ -25,6 +25,14 @@ fn main() { } }); + fffffffffffffffffffffffffffffffffff(a, + { + SCRIPT_TASK_ROOT.with(|root| { + // Another case of write_list failing us. + *root.borrow_mut() = Some(&script_task); + }); + }); + let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum = xxxxxxx.map(|x| x + 5) .map(|x| x / 2) .fold(0, |acc, x| acc + x);