aboutsummaryrefslogtreecommitdiff
path: root/libeditor/tests
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-09 10:47:34 +0100
committerAleksey Kladov <[email protected]>2018-08-09 10:47:34 +0100
commite847a1b7a6b53d5663aae7396ea0f65485f1283e (patch)
treeb501e3330b77368c28533fcccfbcb64bb785b107 /libeditor/tests
parent34bf0a0b180a4c56cf43c34080a074e6e7537e18 (diff)
hihglihgitng tests
Diffstat (limited to 'libeditor/tests')
-rw-r--r--libeditor/tests/test.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/libeditor/tests/test.rs b/libeditor/tests/test.rs
new file mode 100644
index 000000000..e1c8aee4b
--- /dev/null
+++ b/libeditor/tests/test.rs
@@ -0,0 +1,47 @@
1extern crate libeditor;
2extern crate itertools;
3
4use std::fmt;
5use itertools::Itertools;
6use libeditor::{File, TextRange};
7
8#[test]
9fn 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 = file.extend_selection(range).unwrap();
16 assert_eq!(range, TextRange::from_to(17.into(), 18.into()));
17 let range = file.extend_selection(range).unwrap();
18 assert_eq!(range, TextRange::from_to(15.into(), 20.into()));
19}
20
21#[test]
22fn test_highlighting() {
23 let file = file(r#"
24// comment
25fn main() {}
26 println!("Hello, {}!", 92);
27"#);
28 let hls = file.highlight();
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
40fn file(text: &str) -> File {
41 File::new(text)
42}
43
44fn dbg_eq(actual: &impl fmt::Debug, expected: &str) {
45 let expected = expected.lines().map(|l| l.trim()).join(" ");
46 assert_eq!(actual, expected);
47}