2018-08-09 04:47:34 -05:00
|
|
|
extern crate libeditor;
|
|
|
|
extern crate itertools;
|
|
|
|
|
|
|
|
use std::fmt;
|
|
|
|
use itertools::Itertools;
|
2018-08-11 00:56:13 -05:00
|
|
|
use libeditor::{File, highlight, runnables, extend_selection, TextRange};
|
2018-08-09 04:47:34 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_extend_selection() {
|
|
|
|
let file = file(r#"fn foo() {
|
|
|
|
1 + 1
|
|
|
|
}
|
|
|
|
"#);
|
|
|
|
let range = TextRange::offset_len(18.into(), 0.into());
|
2018-08-10 09:49:45 -05:00
|
|
|
let range = extend_selection(&file, range).unwrap();
|
2018-08-09 04:47:34 -05:00
|
|
|
assert_eq!(range, TextRange::from_to(17.into(), 18.into()));
|
2018-08-10 09:49:45 -05:00
|
|
|
let range = extend_selection(&file, range).unwrap();
|
2018-08-09 04:47:34 -05:00
|
|
|
assert_eq!(range, TextRange::from_to(15.into(), 20.into()));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_highlighting() {
|
|
|
|
let file = file(r#"
|
|
|
|
// comment
|
|
|
|
fn main() {}
|
|
|
|
println!("Hello, {}!", 92);
|
|
|
|
"#);
|
2018-08-10 09:49:45 -05:00
|
|
|
let hls = highlight(&file);
|
2018-08-09 04:47:34 -05:00
|
|
|
dbg_eq(
|
|
|
|
&hls,
|
|
|
|
r#"[HighlightedRange { range: [1; 11), tag: "comment" },
|
|
|
|
HighlightedRange { range: [12; 14), tag: "keyword" },
|
|
|
|
HighlightedRange { range: [15; 19), tag: "function" },
|
|
|
|
HighlightedRange { range: [29; 36), tag: "text" },
|
|
|
|
HighlightedRange { range: [38; 50), tag: "string" },
|
|
|
|
HighlightedRange { range: [52; 54), tag: "literal" }]"#
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-08-09 08:03:21 -05:00
|
|
|
#[test]
|
|
|
|
fn test_runnables() {
|
|
|
|
let file = file(r#"
|
|
|
|
fn main() {}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_foo() {}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn test_foo() {}
|
|
|
|
"#);
|
2018-08-10 09:49:45 -05:00
|
|
|
let runnables = runnables(&file);
|
2018-08-09 08:03:21 -05:00
|
|
|
dbg_eq(
|
|
|
|
&runnables,
|
|
|
|
r#"[Runnable { range: [1; 13), kind: Bin },
|
|
|
|
Runnable { range: [15; 39), kind: Test { name: "test_foo" } },
|
|
|
|
Runnable { range: [41; 75), kind: Test { name: "test_foo" } }]"#,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-08-11 00:56:13 -05:00
|
|
|
fn file(text: &str) -> File {
|
|
|
|
File::parse(text)
|
2018-08-09 04:47:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn dbg_eq(actual: &impl fmt::Debug, expected: &str) {
|
2018-08-09 08:03:21 -05:00
|
|
|
let actual = format!("{:?}", actual);
|
2018-08-09 04:47:34 -05:00
|
|
|
let expected = expected.lines().map(|l| l.trim()).join(" ");
|
|
|
|
assert_eq!(actual, expected);
|
|
|
|
}
|