Add some tests for match blocks

This commit is contained in:
Marcus Klaas 2015-09-09 23:14:09 +02:00
parent abe8e7de99
commit 8e471ece31
4 changed files with 36 additions and 15 deletions

View File

@ -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;

View File

@ -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<T>
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]

View File

@ -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)

View File

@ -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);