refactor test macros to handle new errors

This commit is contained in:
ConnorSkees 2020-04-12 14:22:52 -04:00
parent 1d2f645f35
commit e833650af0
2 changed files with 7 additions and 5 deletions

View File

@ -12,7 +12,7 @@ macro_rules! test_import {
write!(f, $content).unwrap();
)*
let mut buf = Vec::new();
StyleSheet::new($input)
StyleSheet::new($input.to_string())
.expect(concat!("failed to parse in "))
.print_as_css(&mut buf)
.expect(concat!("failed to pretty print on ", $input));

View File

@ -8,7 +8,7 @@ macro_rules! test {
#[allow(non_snake_case)]
fn $func() {
let mut buf = Vec::new();
grass::StyleSheet::new($input)
grass::StyleSheet::new($input.to_string())
.expect(concat!("failed to parse on ", $input))
.print_as_css(&mut buf)
.expect(concat!("failed to pretty print on ", $input));
@ -24,7 +24,7 @@ macro_rules! test {
#[allow(non_snake_case)]
fn $func() {
let mut buf = Vec::new();
grass::StyleSheet::new($input)
grass::StyleSheet::new($input.to_string())
.expect(concat!("failed to parse on ", $input))
.print_as_css(&mut buf)
.expect(concat!("failed to pretty print on ", $input));
@ -36,6 +36,8 @@ macro_rules! test {
};
}
/// 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) => {
@ -43,9 +45,9 @@ macro_rules! error {
#[test]
#[allow(non_snake_case)]
fn $func() {
match grass::StyleSheet::new($input) {
match grass::StyleSheet::new($input.to_string()) {
Ok(..) => panic!("did not fail"),
Err(e) => assert_eq!($err, e.to_string().as_str()),
Err(e) => assert_eq!($err, e.to_string().chars().take_while(|c| *c != '\n').collect::<String>().as_str()),
}
}
};