use reference_query::core::{Kind, RepoIdentity, Symbol};
use reference_query::store::Store;
fn sym(name: &str) -> Symbol {
Symbol {
name: name.into(),
kind: Kind::Function,
language: "rust".into(),
file: "a.rs".into(),
line: 1,
parent: None,
}
}
#[test]
fn exact_match_survives_a_flooded_first_char_bucket() {
let mut store = Store::open_in_memory().unwrap();
let repo = store
.upsert_repository(&RepoIdentity::local("/tmp/x"), None)
.unwrap();
let mut syms: Vec<Symbol> = (1..=50).map(|i| sym(&format!("manaa{i:03}"))).collect();
syms.push(sym("mango"));
store
.replace_file_symbols(repo, "a.rs", "rust", None, "h", &syms)
.unwrap();
let cands = store.search_candidates("mango", 5, false).unwrap();
assert!(
cands.iter().any(|c| c.name == "mango"),
"exact match dropped by the cap; got {:?}",
cands.iter().map(|c| &c.name).collect::<Vec<_>>()
);
}
#[test]
fn a_strong_match_short_circuits_the_broad_fuzzy_layers() {
let mut store = Store::open_in_memory().unwrap();
let repo = store
.upsert_repository(&RepoIdentity::local("/tmp/x"), None)
.unwrap();
store
.replace_file_symbols(
repo,
"a.rs",
"rust",
None,
"h",
&[sym("User"), sym("Peruser")],
)
.unwrap();
let strong_only = store.search_candidates("user", 50, false).unwrap();
assert!(strong_only.iter().any(|c| c.name == "User"), "prefix kept");
assert!(
!strong_only.iter().any(|c| c.name == "Peruser"),
"fuzzy-only candidate skipped when a strong match exists"
);
let forced = store.search_candidates("user", 50, true).unwrap();
assert!(
forced.iter().any(|c| c.name == "Peruser"),
"force_fuzzy still recalls the fuzzy candidate"
);
}