From f2772e29aeda5e35c282f3b023ce9d470f3fb441 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Aug 2018 19:14:08 +0300 Subject: add crate graph --- crates/libanalysis/tests/tests.rs | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'crates/libanalysis/tests') diff --git a/crates/libanalysis/tests/tests.rs b/crates/libanalysis/tests/tests.rs index 887e13fa3..c098c8e8c 100644 --- a/crates/libanalysis/tests/tests.rs +++ b/crates/libanalysis/tests/tests.rs @@ -2,10 +2,13 @@ extern crate libanalysis; extern crate relative_path; extern crate test_utils; -use std::path::{Path}; +use std::{ + collections::HashMap, + path::{Path}, +}; use relative_path::RelativePath; -use libanalysis::{AnalysisHost, FileId, FileResolver, JobHandle}; +use libanalysis::{AnalysisHost, FileId, FileResolver, JobHandle, CrateGraph, CrateId}; use test_utils::assert_eq_dbg; struct FileMap(&'static [(u32, &'static str)]); @@ -112,3 +115,34 @@ fn test_resolve_parent_module() { &symbols, ); } + +#[test] +fn test_resolve_crate_root() { + let mut world = AnalysisHost::new(); + world.change_file(FileId(1), Some("mod foo;".to_string())); + world.change_file(FileId(2), Some("".to_string())); + + let snap = world.analysis(FileMap(&[ + (1, "/lib.rs"), + (2, "/foo.rs"), + ])); + assert!(snap.crate_root(FileId(2)).is_empty()); + + let crate_graph = CrateGraph { + crate_roots: { + let mut m = HashMap::new(); + m.insert(CrateId(1), FileId(1)); + m + }, + }; + world.set_crate_graph(crate_graph); + + let snap = world.analysis(FileMap(&[ + (1, "/lib.rs"), + (2, "/foo.rs"), + ])); + assert_eq!( + snap.crate_root(FileId(2)), + vec![CrateId(1)], + ); +} -- cgit v1.2.3