aboutsummaryrefslogtreecommitdiff
path: root/crates/libanalysis/tests
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libanalysis/tests')
-rw-r--r--crates/libanalysis/tests/tests.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/crates/libanalysis/tests/tests.rs b/crates/libanalysis/tests/tests.rs
new file mode 100644
index 000000000..9ef5200af
--- /dev/null
+++ b/crates/libanalysis/tests/tests.rs
@@ -0,0 +1,45 @@
1extern crate libanalysis;
2extern crate assert_eq_text;
3
4use std::path::PathBuf;
5
6use libanalysis::{WorldState, FileId};
7use assert_eq_text::assert_eq_dbg;
8
9
10#[test]
11fn test_resolve_module() {
12 let mut world = WorldState::new();
13 world.change_file(FileId(1), Some("mod foo;".to_string()));
14 world.change_file(FileId(2), Some("".to_string()));
15
16 let snap = world.snapshot(|id, path| {
17 assert_eq!(id, FileId(1));
18 if path == PathBuf::from("../foo/mod.rs") {
19 return None;
20 }
21 assert_eq!(path, PathBuf::from("../foo.rs"));
22 Some(FileId(2))
23 });
24 let symbols = snap.approximately_resolve_symbol(FileId(1), 4.into())
25 .unwrap();
26 assert_eq_dbg(
27 r#"[(FileId(2), FileSymbol { name: "foo", node_range: [0; 0), kind: MODULE })]"#,
28 &symbols,
29 );
30
31 let snap = world.snapshot(|id, path| {
32 assert_eq!(id, FileId(1));
33 if path == PathBuf::from("../foo.rs") {
34 return None;
35 }
36 assert_eq!(path, PathBuf::from("../foo/mod.rs"));
37 Some(FileId(2))
38 });
39 let symbols = snap.approximately_resolve_symbol(FileId(1), 4.into())
40 .unwrap();
41 assert_eq_dbg(
42 r#"[(FileId(2), FileSymbol { name: "foo", node_range: [0; 0), kind: MODULE })]"#,
43 &symbols,
44 );
45}