diff options
author | Aleksey Kladov <[email protected]> | 2018-08-10 20:33:29 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-10 20:33:29 +0100 |
commit | 7c67612b8a894187fa3b64725531a5459f9211bf (patch) | |
tree | 9e2a536efa0c880d921fd8d4d74423afc9451fd4 /crates/libeditor/tests | |
parent | 26262aaf05983c5b7f41cc438e287523268fe1eb (diff) |
organizize
Diffstat (limited to 'crates/libeditor/tests')
-rw-r--r-- | crates/libeditor/tests/test.rs | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/crates/libeditor/tests/test.rs b/crates/libeditor/tests/test.rs new file mode 100644 index 000000000..2a84c5080 --- /dev/null +++ b/crates/libeditor/tests/test.rs | |||
@@ -0,0 +1,69 @@ | |||
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 | } | ||