grass/tests/macros.rs
2020-07-15 12:37:19 +01:00

54 lines
1.6 KiB
Rust

#![cfg(test)]
#[macro_export]
macro_rules! test {
($( #[$attr:meta] ),*$func:ident, $input:expr) => {
$(#[$attr])*
#[test]
#[allow(non_snake_case)]
fn $func() {
let sass = grass::from_string($input.to_string(), &grass::Options::default())
.expect(concat!("failed to parse on ", $input));
assert_eq!(
String::from($input),
sass
);
}
};
($( #[$attr:meta] ),*$func:ident, $input:expr, $output:expr) => {
$(#[$attr])*
#[test]
#[allow(non_snake_case)]
fn $func() {
let sass = grass::from_string($input.to_string(), &grass::Options::default())
.expect(concat!("failed to parse on ", $input));
assert_eq!(
String::from($output),
sass
);
}
};
}
/// Verify the error *message*
/// Span and scope information are not yet tested
#[macro_export]
macro_rules! error {
($( #[$attr:meta] ),*$func:ident, $input:expr, $err:expr) => {
$(#[$attr])*
#[test]
#[allow(non_snake_case)]
fn $func() {
match grass::from_string($input.to_string(), &grass::Options::default()) {
Ok(..) => panic!("did not fail"),
Err(e) => assert_eq!($err, e.to_string()
.chars()
.take_while(|c| *c != '\n')
.collect::<String>()
.as_str()
),
}
}
};
}