aboutsummaryrefslogtreecommitdiff
path: root/libeditor/tests/test.rs
diff options
context:
space:
mode:
Diffstat (limited to 'libeditor/tests/test.rs')
-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}