Update theme check tests

This commit is contained in:
Guillaume Gomez 2022-09-14 17:39:32 +02:00
parent fb42dae987
commit 0b037c17b8

View file

@ -44,11 +44,7 @@ rule j end {}
"#;
let mut ret = Vec::new();
get_differences(
&load_css_paths(against.as_bytes()),
&load_css_paths(text.as_bytes()),
&mut ret,
);
get_differences(&load_css_paths(against).unwrap(), &load_css_paths(text).unwrap(), &mut ret);
assert!(ret.is_empty());
}
@ -61,46 +57,45 @@ a
c // sdf
d {}
"#;
let paths = load_css_paths(text.as_bytes());
assert!(paths.children.contains(&CssPath::new("a b c d".to_owned())));
let paths = load_css_paths(text).unwrap();
assert!(paths.contains_key(&"a b c d".to_owned()));
}
#[test]
fn test_comparison() {
let x = r#"
a {
b {
c {}
}
}
"#;
let y = r#"
a {
@a {
b {}
}
"#;
let against = load_css_paths(y.as_bytes());
let other = load_css_paths(x.as_bytes());
let y = r#"
@a {
b {}
c {}
}
"#;
let against = load_css_paths(y).unwrap();
let other = load_css_paths(x).unwrap();
let mut ret = Vec::new();
get_differences(&against, &other, &mut ret);
assert!(ret.is_empty());
get_differences(&other, &against, &mut ret);
assert_eq!(ret, vec![" Missing \"c\" rule".to_owned()]);
assert_eq!(ret, vec![" Missing rule `c`".to_owned()]);
}
#[test]
fn check_empty_css() {
let events = load_css_events(&[]);
assert_eq!(events.len(), 0);
let paths = load_css_paths("").unwrap();
assert_eq!(paths.len(), 0);
}
#[test]
fn check_invalid_css() {
let events = load_css_events(b"*");
assert_eq!(events.len(), 0);
let paths = load_css_paths("*").unwrap();
assert_eq!(paths.len(), 0);
}
#[test]
@ -108,10 +103,33 @@ fn test_with_minification() {
let text = include_str!("../html/static/css/themes/dark.css");
let minified = minifier::css::minify(&text).expect("CSS minification failed").to_string();
let against = load_css_paths(text.as_bytes());
let other = load_css_paths(minified.as_bytes());
let against = load_css_paths(text).unwrap();
let other = load_css_paths(&minified).unwrap();
let mut ret = Vec::new();
get_differences(&against, &other, &mut ret);
assert!(ret.is_empty());
}
#[test]
fn test_media() {
let text = r#"
@media (min-width: 701px) {
a:hover {
color: #fff;
}
b {
x: y;
}
}
"#;
let paths = load_css_paths(text).unwrap();
eprintln!("{:?}", paths);
let p = paths.get("@media (min-width:701px)");
assert!(p.is_some());
let p = p.unwrap();
assert!(p.children.get("a:hover").is_some());
assert!(p.children.get("b").is_some());
}