diff options
Diffstat (limited to 'crates/libanalysis/tests')
-rw-r--r-- | crates/libanalysis/tests/tests.rs | 45 |
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 @@ | |||
1 | extern crate libanalysis; | ||
2 | extern crate assert_eq_text; | ||
3 | |||
4 | use std::path::PathBuf; | ||
5 | |||
6 | use libanalysis::{WorldState, FileId}; | ||
7 | use assert_eq_text::assert_eq_dbg; | ||
8 | |||
9 | |||
10 | #[test] | ||
11 | fn 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 | } | ||