use std::path::PathBuf;
use crate::index;
use crate::search::{self, ActiveFiles};
use crate::store::Store;
fn indexed_src() -> Store {
let src = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("src");
let mut store = Store::open_in_memory().unwrap();
index::index_path(&mut store, &src).unwrap();
store
}
fn top(store: &Store, query: &str) -> search::Hit {
let hits = search::search(store, query, None, None, &ActiveFiles::default(), 10).unwrap();
assert!(!hits.is_empty(), "no hits for {query:?}");
hits.into_iter().next().unwrap()
}
#[test]
fn obvious_queries_land_their_definition_first() {
let store = indexed_src();
let symbol = top(&store, "Symbol");
assert_eq!(symbol.name, "Symbol");
assert_eq!(symbol.kind, "struct");
assert_eq!(top(&store, "LanguagePlugin").kind, "trait");
assert_eq!(top(&store, "index_budgeted").name, "index_budgeted");
let fs = top(&store, "FileSymbols");
assert_eq!(fs.name, "FileSymbols");
assert_eq!(fs.kind, "struct");
}
#[test]
fn fuzzy_abbreviations_resolve_to_their_definition() {
let store = indexed_src();
assert_eq!(top(&store, "idxbudg").name, "index_budgeted"); assert_eq!(top(&store, "filesym").name, "FileSymbols"); assert_eq!(top(&store, "langplug").name, "LanguagePlugin"); }