From aa4cacec78be39c169f6e59fd13d38c1a4b7c3ab Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sun, 5 Jan 2020 20:26:34 -0500 Subject: [PATCH] Add css tests --- src/main.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/main.rs b/src/main.rs index 78a262f..85dfd6e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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