mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 11:48:30 +00:00
Add some tests for match blocks
This commit is contained in:
parent
abe8e7de99
commit
8e471ece31
@ -8,6 +8,17 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// 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 rewrite::{Rewrite, RewriteContext};
|
||||||
use utils::{make_indent, extra_offset};
|
use utils::{make_indent, extra_offset};
|
||||||
use expr::rewrite_call;
|
use expr::rewrite_call;
|
||||||
|
@ -150,17 +150,6 @@ pub fn contains_comment(text: &str) -> bool {
|
|||||||
CharClasses::new(text.chars()).any(|(kind, _)| kind == CodeCharKind::Comment)
|
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>
|
struct CharClasses<T>
|
||||||
where T: Iterator,
|
where T: Iterator,
|
||||||
T::Item: RichChar
|
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
|
// 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.
|
// keeping it around unless it helps us test stuff.
|
||||||
fn uncommented(text: &str) -> String {
|
fn uncommented(text: &str) -> String {
|
||||||
CharClasses::new(text.chars()).filter_map(|(s, c)| match s {
|
CharClasses::new(text.chars())
|
||||||
CodeCharKind::Normal => Some(c),
|
.filter_map(|(s, c)| {
|
||||||
CodeCharKind::Comment => None
|
match s {
|
||||||
}).collect()
|
CodeCharKind::Normal => Some(c),
|
||||||
|
CodeCharKind::Comment => None,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -21,6 +21,15 @@ fn main() {
|
|||||||
2
|
2
|
||||||
});
|
});
|
||||||
|
|
||||||
|
fffffffffffffffffffffffffffffffffff(a,
|
||||||
|
{
|
||||||
|
SCRIPT_TASK_ROOT
|
||||||
|
.with(|root| {
|
||||||
|
// Another case of write_list failing us.
|
||||||
|
*root.borrow_mut() = Some(&script_task);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum = xxxxxxx
|
let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum = xxxxxxx
|
||||||
.map(|x| x + 5)
|
.map(|x| x + 5)
|
||||||
.map(|x| x / 2)
|
.map(|x| x / 2)
|
||||||
|
@ -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)
|
let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum = xxxxxxx.map(|x| x + 5)
|
||||||
.map(|x| x / 2)
|
.map(|x| x / 2)
|
||||||
.fold(0, |acc, x| acc + x);
|
.fold(0, |acc, x| acc + x);
|
||||||
|
Loading…
Reference in New Issue
Block a user