const RUST: &str = "fn alpha() {}\nstruct Beta;\nfn gamma(x: u32) -> u32 { x }\n";
fn classes(src: &str, path: &str) -> Vec<(String, String)> {
let eco = escriba_ts::build_ecosystem();
let hl = eco.highlighter_for_path(path);
hl.highlight(src)
.into_iter()
.filter_map(|sp| {
let t = src.get(sp.span.range())?.trim().to_string();
(!t.is_empty()).then_some((format!("{:?}", sp.class), t))
})
.collect()
}
#[test]
fn keywords_are_classified_as_keywords() {
let got = classes(RUST, "probe.rs");
assert!(
got.iter().any(|(c, t)| t == "fn" && c == "Keyword"),
"`fn` must be a Keyword: {got:?}",
);
}
#[test]
fn function_and_type_are_still_indistinguishable_through_semantic() {
let got = classes(RUST, "probe.rs");
let class_of = |name: &str| {
got.iter()
.find(|(_, t)| t == name)
.map(|(c, _)| c.clone())
.unwrap_or_default()
};
assert_ne!(
class_of("alpha"),
"Punctuation",
"a function NAME must not be punctuation — this regressed to the \
pre-hikari-0.1.10 behaviour",
);
assert_eq!(
class_of("alpha"),
"Special",
"functions currently fold through Semantic::Accent",
);
assert_eq!(
class_of("Beta"),
"Special",
"…and so do types, indistinguishably"
);
}