use super::util::*;
#[test]
fn box_shadow() {
let shadow: Option<Arc<[BoxShadow]>> = Some(Arc::new([BoxShadow {
offset_x: Length::Px(5.0),
offset_y: Length::Px(10.0),
blur: Length::Px(15.0),
spread: Length::Px(20.0),
color: Some(color::palette::css::BLUE),
inset: false,
}]));
let shadow_current_color: Option<Arc<[BoxShadow]>> = Some(Arc::new([BoxShadow {
offset_x: Length::Px(5.0),
offset_y: Length::Px(10.0),
blur: Length::Px(15.0),
spread: Length::Px(20.0),
color: None,
inset: true,
}]));
let styles = apply_css_to_tree(".root { box-shadow: none; }", single_node_tree);
assert_eq!(styles[0].box_shadow, Style::default().box_shadow);
let styles = apply_css_to_tree(".root { box-shadow: 5px 10px 15px 20px #00F; }", single_node_tree);
assert_eq!(styles[0].box_shadow, shadow);
let styles = apply_css_to_tree(".child { box-shadow: 5px 10px 15px 20px rgb(0, 0, 255); } .right { box-shadow: initial; }", two_child_tree);
assert_eq!(styles[1].box_shadow, shadow);
assert_eq!(styles[2].box_shadow, Style::default().box_shadow);
let styles = apply_css_to_tree(".parent { box-shadow: 5px 10px 15px 20px blue; } .child { box-shadow: inherit; }", one_child_tree);
assert_eq!(styles[0].box_shadow, shadow);
assert_eq!(styles[1].box_shadow, shadow);
let styles = apply_css_to_tree(".parent { box-shadow: 5px 10px 15px 20px blue; }", one_child_tree);
assert_eq!(styles[0].box_shadow, shadow);
assert_eq!(styles[1].box_shadow, Style::default().box_shadow);
let styles = apply_css_to_tree(".root { box-shadow: 5px 10px 15px 20px currentcolor inset; }", single_node_tree);
assert_eq!(styles[0].box_shadow, shadow_current_color);
}
#[test]
fn box_shadow_reject() {
fn reject(value: &str) {
let css = format!(".root {{ box-shadow: {}; }}", value);
let styles = apply_css_to_tree(&css, single_node_tree);
assert_eq!(styles[0].box_shadow, Style::default().box_shadow, "expected parser to reject box-shadow: {}", value);
}
for value in [
"", "()", "auto", "foo", "#fff", "5px", "5px 10px 15px 20px blue extra", "inset", "inset extra", "5px 10px 15px 20px blue,", ",5px 10px 15px 20px blue", "5px 10px 15px 20px blue,,", "5px 10px 15px 20px blue, , 1px 2px 3px 4px red", "5px 10px 15px 20px blue 1px 2px 3px 4px red", "5 10px 15px 20px blue", "5px 10 15px 20px blue", "5px 10px 15 20px blue", "5px 10px 15px 20 blue", "5 px 10px 15px 20px blue", "5px 10 px 15px 20px blue", "5px 10px 15 px 20px blue", "5px 10px 15px 20 px blue", "5% 10px 15px 20px blue", "5px 10% 15px 20px blue", "5px 10px 15% 20px blue", "5px 10px 15px 20% blue", "5s 10px 15px 20px blue", "5px 10s 15px 20px blue", "5px 10px 15s 20px blue", "5px 10px 15px 20s blue", "5px 10px -1px 20px blue", "5px, 10px, 15px, 20px, blue", "5px 10px 15px 20px / blue", "5px 10px 15px 20px blue / 1", "5px 10px 15px 20px #12", "5px 10px 15px 20px #GGG", "5px 10px 15px 20px rgb(255,0)", "5px 10px 15px 20px rgb()", "5px 10px 15px 20px url(x)", "5px 10px 15px 20px linear-gradient(#fff,#000)", "5px 10px 15px 20px 123", "5px 10px 15px 20px blue,", "5px 10px 15px 20px blue inset inset", "5px 10px 15px 20px blue insett", "5px (10px) 15px 20px blue", "5px 10px (15px 20px blue)", "5px 10px 15px 20px (blue", "5px 10px 15px 20px blue)", "5px 10px 15px 20px (currentcolor) inset", "5px 10px 15px 20px blue !important", ] {
reject(value);
}
}
#[test]
fn text_shadow() {
let shadow: Option<Arc<[TextShadow]>> = Some(Arc::new([TextShadow {
offset_x: Length::Px(5.0),
offset_y: Length::Px(10.0),
blur: Length::Px(15.0),
color: Some(color::palette::css::BLUE),
}]));
let shadow_current_color: Option<Arc<[TextShadow]>> = Some(Arc::new([TextShadow {
offset_x: Length::Px(5.0),
offset_y: Length::Px(10.0),
blur: Length::Px(15.0),
color: None,
}]));
let styles = apply_css_to_tree(".root { text-shadow: none; }", single_node_tree);
assert_eq!(styles[0].text_shadow, Style::default().text_shadow);
let styles = apply_css_to_tree(".root { text-shadow: 5px 10px 15px #00F; }", single_node_tree);
assert_eq!(styles[0].text_shadow, shadow);
let styles = apply_css_to_tree(".child { text-shadow: 5px 10px 15px rgb(0, 0, 255); } .right { text-shadow: initial; }", two_child_tree);
assert_eq!(styles[1].text_shadow, shadow);
assert_eq!(styles[2].text_shadow, Style::default().text_shadow);
let styles = apply_css_to_tree(".parent { text-shadow: 5px 10px 15px blue; } .child { text-shadow: inherit; }", one_child_tree);
assert_eq!(styles[0].text_shadow, shadow);
assert_eq!(styles[1].text_shadow, shadow);
let styles = apply_css_to_tree(".parent { text-shadow: 5px 10px 15px blue; }", one_child_tree);
assert_eq!(styles[0].text_shadow, shadow);
assert_eq!(styles[1].text_shadow, shadow);
let styles = apply_css_to_tree(".root { text-shadow: 5px 10px 15px currentcolor; }", single_node_tree);
assert_eq!(styles[0].text_shadow, shadow_current_color);
}
#[test]
fn text_shadow_reject() {
fn reject(value: &str) {
let css = format!(".root {{ text-shadow: {}; }}", value);
let styles = apply_css_to_tree(&css, single_node_tree);
assert_eq!(styles[0].text_shadow, Style::default().text_shadow, "expected parser to reject text-shadow: {}", value);
}
for value in [
"", "()", "auto", "foo", "#fff", "5px", "5px 10px blue extra", "5 10px 15px blue", "5px 10 15px blue", "5px 10px 15 blue", "5px 10px -1px blue", "5 px 10px 15px blue", "5px 10 px 15px blue", "5px 10px 15 px blue", "5% 10px 15px blue", "5px 10% 15px blue", "5px 10px 15% blue", "5s 10px 15px blue", "5px 10s 15px blue", "5px 10px 15s blue", "5px, 10px, 15px, blue", "5px 10px 15px / blue", "5px 10px 15px blue / 1", "5px 10px 15px #12", "5px 10px 15px #GGG", "5px 10px 15px rgb(255,0)", "5px 10px 15px url(x)", "5px 10px 15px linear-gradient(#fff,#000)", "5px 10px 15px 123", "5px 10px 15px blue,", "5px 10px 15px blue,", ",5px 10px 15px blue", "5px 10px 15px blue,,", "5px 10px 15px blue, , 1px 2px 3px red", "5px 10px 15px blue 1px 2px 3px red", "5px 10px 15px blue !important", "5px (10px) 15px blue", "5px 10px (15px blue)", "5px 10px 15px (blue", "5px 10px 15px blue)", ] {
reject(value);
}
}