mod fixture;
use theme::HighlightKind;
const PAGE: &str = r#"<!DOCTYPE html>
<html>
<style>
.banner { color: #ff0000; }
</style>
<script>
const total = 41 + 1;
</script>
</html>
"#;
fn kind_at(needle: &str) -> Option<HighlightKind> {
let at = PAGE.find(needle).expect("needle is in the source");
syntax::highlight(PAGE, "html")?
.into_iter()
.find(|(range, _)| range.start <= at && at < range.end)
.map(|(_, kind)| kind)
}
#[test]
fn the_host_language_still_paints() {
fixture::install();
let spans = syntax::highlight(PAGE, "html").expect("html was registered");
assert!(!spans.is_empty(), "the html query compiled to nothing");
assert_eq!(kind_at("DOCTYPE"), Some(HighlightKind::Keyword));
}
#[test]
fn a_style_body_is_painted_as_css() {
fixture::install();
assert_eq!(kind_at("color"), Some(HighlightKind::Property));
assert_eq!(kind_at("#ff0000"), Some(HighlightKind::Constant));
}
#[test]
fn an_injection_to_an_unregistered_language_paints_nothing() {
fixture::install();
assert_eq!(kind_at("const"), None);
assert_eq!(kind_at("41"), None);
}
#[test]
fn injection_captures_do_not_paint() {
fixture::install();
let spans = syntax::highlight(PAGE, "html").expect("html was registered");
let start = PAGE.find(".banner").expect("the rule is in the source");
let end = PAGE.find('}').expect("the rule closes") + 1;
assert!(
!spans
.iter()
.any(|(range, _)| range.start <= start && range.end >= end),
"a span blankets the whole css rule; an injection capture is painting"
);
}
#[test]
fn css_is_a_language_in_its_own_right() {
fixture::install();
let spans = syntax::highlight(".a { color: red; }", "css").expect("css was registered");
assert!(!spans.is_empty(), "the css query compiled to nothing");
}