From 41570f60bf268c97223a864b8aa11a339929f55a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 17 Aug 2018 16:04:34 +0300 Subject: extend module resolve to mod.rs --- crates/libanalysis/tests/tests.rs | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 crates/libanalysis/tests/tests.rs (limited to 'crates/libanalysis/tests') 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 @@ +extern crate libanalysis; +extern crate assert_eq_text; + +use std::path::PathBuf; + +use libanalysis::{WorldState, FileId}; +use assert_eq_text::assert_eq_dbg; + + +#[test] +fn test_resolve_module() { + let mut world = WorldState::new(); + world.change_file(FileId(1), Some("mod foo;".to_string())); + world.change_file(FileId(2), Some("".to_string())); + + let snap = world.snapshot(|id, path| { + assert_eq!(id, FileId(1)); + if path == PathBuf::from("../foo/mod.rs") { + return None; + } + assert_eq!(path, PathBuf::from("../foo.rs")); + Some(FileId(2)) + }); + let symbols = snap.approximately_resolve_symbol(FileId(1), 4.into()) + .unwrap(); + assert_eq_dbg( + r#"[(FileId(2), FileSymbol { name: "foo", node_range: [0; 0), kind: MODULE })]"#, + &symbols, + ); + + let snap = world.snapshot(|id, path| { + assert_eq!(id, FileId(1)); + if path == PathBuf::from("../foo.rs") { + return None; + } + assert_eq!(path, PathBuf::from("../foo/mod.rs")); + Some(FileId(2)) + }); + let symbols = snap.approximately_resolve_symbol(FileId(1), 4.into()) + .unwrap(); + assert_eq_dbg( + r#"[(FileId(2), FileSymbol { name: "foo", node_range: [0; 0), kind: MODULE })]"#, + &symbols, + ); +} -- cgit v1.2.3