-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrust_match_literals.rs
59 lines (56 loc) · 1.87 KB
/
rust_match_literals.rs
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use codesort::*;
#[test]
fn test_match_literals() {
static INPUT: &str = r#"
pub fn analyze(aliment: &str) -> Kind {
match aliment {
"pepper" => Kind::Fruit, // I guess
"apple" => Kind::Fruit,
// well...
"tomato" => if rand::random() {
Kind::Vegetable
} else {
Kind::Fruit
},
"carrot" => Kind::Vegetable,
"avocado" => Kind::Both,
// There should probably be another kind for this one
"samphire" => Kind::Unknown,
_ => Kind::Unknown,
}
}
"#;
static OUTPUT: &str = r#"
pub fn analyze(aliment: &str) -> Kind {
match aliment {
"apple" => Kind::Fruit,
"avocado" => Kind::Both,
"carrot" => Kind::Vegetable,
"pepper" => Kind::Fruit, // I guess
// There should probably be another kind for this one
"samphire" => Kind::Unknown,
// well...
"tomato" => if rand::random() {
Kind::Vegetable
} else {
Kind::Fruit
},
_ => Kind::Unknown,
}
}
"#;
let list = LocList::read_str(INPUT, Language::Rust).unwrap();
let focused = list.focus_around_line_index(6).unwrap();
focused.print_debug();
{
let blocks = focused.clone().focus.into_blocks();
for (i, block) in blocks.iter().enumerate() {
block.print_debug(&format!(" BLOCK {i}"));
}
assert!(blocks[1] < blocks[0]);
assert!(blocks[3] < blocks[0]);
}
let sorted_list = focused.sort();
sorted_list.print_debug(" SORTED ");
assert_eq!(sorted_list.to_string(), OUTPUT);
}