2020-03-01 14:53:52 -05:00
|
|
|
#[macro_export]
|
2020-02-01 23:09:22 -05:00
|
|
|
macro_rules! test {
|
2020-03-22 18:13:19 -04:00
|
|
|
($( #[$attr:meta] ),*$func:ident, $input:expr) => {
|
|
|
|
$(#[$attr])*
|
2020-02-01 23:09:22 -05:00
|
|
|
#[test]
|
2020-03-18 10:08:40 -04:00
|
|
|
#[allow(non_snake_case)]
|
2020-02-01 23:09:22 -05:00
|
|
|
fn $func() {
|
2020-07-15 12:37:19 +01:00
|
|
|
let sass = grass::from_string($input.to_string(), &grass::Options::default())
|
2020-04-18 19:08:35 -04:00
|
|
|
.expect(concat!("failed to parse on ", $input));
|
2020-02-01 23:09:22 -05:00
|
|
|
assert_eq!(
|
|
|
|
String::from($input),
|
2020-04-21 05:25:08 -04:00
|
|
|
sass
|
2020-02-01 23:09:22 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
2020-03-22 18:13:19 -04:00
|
|
|
($( #[$attr:meta] ),*$func:ident, $input:expr, $output:expr) => {
|
|
|
|
$(#[$attr])*
|
2020-02-01 23:09:22 -05:00
|
|
|
#[test]
|
2020-03-18 10:08:40 -04:00
|
|
|
#[allow(non_snake_case)]
|
2020-02-01 23:09:22 -05:00
|
|
|
fn $func() {
|
2020-07-15 12:37:19 +01:00
|
|
|
let sass = grass::from_string($input.to_string(), &grass::Options::default())
|
2020-04-18 19:08:35 -04:00
|
|
|
.expect(concat!("failed to parse on ", $input));
|
2020-02-01 23:09:22 -05:00
|
|
|
assert_eq!(
|
|
|
|
String::from($output),
|
2020-04-21 05:25:08 -04:00
|
|
|
sass
|
2020-02-01 23:09:22 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
2020-02-02 10:27:08 -05:00
|
|
|
}
|
2020-03-21 14:39:16 -04:00
|
|
|
|
2020-04-12 14:22:52 -04:00
|
|
|
/// Verify the error *message*
|
|
|
|
/// Span and scope information are not yet tested
|
2020-03-21 14:39:16 -04:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! error {
|
2020-03-22 18:13:19 -04:00
|
|
|
($( #[$attr:meta] ),*$func:ident, $input:expr, $err:expr) => {
|
|
|
|
$(#[$attr])*
|
2020-03-21 14:39:16 -04:00
|
|
|
#[test]
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
fn $func() {
|
2020-07-15 12:37:19 +01:00
|
|
|
match grass::from_string($input.to_string(), &grass::Options::default()) {
|
2020-03-21 14:39:16 -04:00
|
|
|
Ok(..) => panic!("did not fail"),
|
2020-04-17 13:06:54 -04:00
|
|
|
Err(e) => assert_eq!($err, e.to_string()
|
|
|
|
.chars()
|
|
|
|
.take_while(|c| *c != '\n')
|
|
|
|
.collect::<String>()
|
|
|
|
.as_str()
|
|
|
|
),
|
2020-03-21 14:39:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2020-07-30 17:21:32 -04:00
|
|
|
|
|
|
|
/// Create a temporary file with the given name
|
|
|
|
/// and contents.
|
|
|
|
///
|
|
|
|
/// This must be a macro rather than a function
|
|
|
|
/// because the tempfile will be deleted when it
|
|
|
|
/// exits scope
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! tempfile {
|
|
|
|
($name:literal, $content:literal) => {
|
|
|
|
let mut f = tempfile::Builder::new()
|
|
|
|
.rand_bytes(0)
|
|
|
|
.prefix("")
|
|
|
|
.suffix($name)
|
|
|
|
.tempfile_in("")
|
|
|
|
.unwrap();
|
|
|
|
write!(f, "{}", $content).unwrap();
|
|
|
|
};
|
|
|
|
($name:literal, $content:literal, dir=$dir:literal) => {
|
|
|
|
let _d = tempfile::Builder::new()
|
|
|
|
.rand_bytes(0)
|
|
|
|
.prefix("")
|
|
|
|
.suffix($dir)
|
|
|
|
.tempdir_in("")
|
|
|
|
.unwrap();
|
|
|
|
let mut f = tempfile::Builder::new()
|
|
|
|
.rand_bytes(0)
|
|
|
|
.prefix("")
|
|
|
|
.suffix($name)
|
|
|
|
.tempfile_in($dir)
|
|
|
|
.unwrap();
|
|
|
|
write!(f, "{}", $content).unwrap();
|
|
|
|
};
|
|
|
|
}
|
2020-08-02 04:20:08 -04:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! assert_err {
|
|
|
|
($err:literal, $input:expr) => {
|
|
|
|
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()
|
|
|
|
),
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|