Add css tests
@@ -429,3 +429,41 @@ fn main() -> io::Result<()> {
// drop(input);
Ok(())
}
+
+#[cfg(test)]
+mod test_css {
+ use super::StyleSheet;
+ macro_rules! test {
+ ($func:ident, $input:literal) => {
+ #[test]
+ fn $func() {
+ let mut buf = Vec::new();
+ StyleSheet::new($input)
+ .print_as_css(&mut buf)
+ .expect(concat!("failed to pretty print on ", $input));
+ assert_eq!(
+ String::from($input),
+ String::from_utf8(buf).expect("produced invalid utf8")
+ );
+ }
+ };
+ ($func:ident, $input:literal, $output:literal) => {
+ #[test]
+ fn $func() {
+ let mut buf = Vec::new();
+ StyleSheet::new($input)
+ .print_as_css(&mut buf)
+ .expect(concat!("failed to pretty print on ", $input));
+ assert_eq!(
+ String::from($output),
+ String::from_utf8(buf).expect("produced invalid utf8")
+ );
+ }
+ };
+ }
+
+ test!(nesting_el_mul_el, "a, b {\n a, b {\n color: red\n}\n}\n", "a a, b a, a b, b b {\n color: red;\n}\n");
+ test!(basic_style, "a {\n color: red;\n}\n");
+ test!(two_styles, "a {\n color: red;\n color: blue;\n}\n");
+ test!(selector_mul, "a, b {\n color: red;\n}\n");
+}
\ No newline at end of file
