diff options
Diffstat (limited to 'libeditor/tests/test.rs')
-rw-r--r-- | libeditor/tests/test.rs | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/libeditor/tests/test.rs b/libeditor/tests/test.rs deleted file mode 100644 index 2a84c5080..000000000 --- a/libeditor/tests/test.rs +++ /dev/null | |||
@@ -1,69 +0,0 @@ | |||
1 | extern crate libeditor; | ||
2 | extern crate itertools; | ||
3 | |||
4 | use std::fmt; | ||
5 | use itertools::Itertools; | ||
6 | use libeditor::{ast, highlight, runnables, extend_selection, TextRange}; | ||
7 | |||
8 | #[test] | ||
9 | fn test_extend_selection() { | ||
10 | let file = file(r#"fn foo() { | ||
11 | 1 + 1 | ||
12 | } | ||
13 | "#); | ||
14 | let range = TextRange::offset_len(18.into(), 0.into()); | ||
15 | let range = extend_selection(&file, range).unwrap(); | ||
16 | assert_eq!(range, TextRange::from_to(17.into(), 18.into())); | ||
17 | let range = extend_selection(&file, range).unwrap(); | ||
18 | assert_eq!(range, TextRange::from_to(15.into(), 20.into())); | ||
19 | } | ||
20 | |||
21 | #[test] | ||
22 | fn test_highlighting() { | ||
23 | let file = file(r#" | ||
24 | // comment | ||
25 | fn main() {} | ||
26 | println!("Hello, {}!", 92); | ||
27 | "#); | ||
28 | let hls = highlight(&file); | ||
29 | dbg_eq( | ||
30 | &hls, | ||
31 | r#"[HighlightedRange { range: [1; 11), tag: "comment" }, | ||
32 | HighlightedRange { range: [12; 14), tag: "keyword" }, | ||
33 | HighlightedRange { range: [15; 19), tag: "function" }, | ||
34 | HighlightedRange { range: [29; 36), tag: "text" }, | ||
35 | HighlightedRange { range: [38; 50), tag: "string" }, | ||
36 | HighlightedRange { range: [52; 54), tag: "literal" }]"# | ||
37 | ); | ||
38 | } | ||
39 | |||
40 | #[test] | ||
41 | fn test_runnables() { | ||
42 | let file = file(r#" | ||
43 | fn main() {} | ||
44 | |||
45 | #[test] | ||
46 | fn test_foo() {} | ||
47 | |||
48 | #[test] | ||
49 | #[ignore] | ||
50 | fn test_foo() {} | ||
51 | "#); | ||
52 | let runnables = runnables(&file); | ||
53 | dbg_eq( | ||
54 | &runnables, | ||
55 | r#"[Runnable { range: [1; 13), kind: Bin }, | ||
56 | Runnable { range: [15; 39), kind: Test { name: "test_foo" } }, | ||
57 | Runnable { range: [41; 75), kind: Test { name: "test_foo" } }]"#, | ||
58 | ) | ||
59 | } | ||
60 | |||
61 | fn file(text: &str) -> ast::File { | ||
62 | ast::File::parse(text) | ||
63 | } | ||
64 | |||
65 | fn dbg_eq(actual: &impl fmt::Debug, expected: &str) { | ||
66 | let actual = format!("{:?}", actual); | ||
67 | let expected = expected.lines().map(|l| l.trim()).join(" "); | ||
68 | assert_eq!(actual, expected); | ||
69 | } | ||