diff options
Diffstat (limited to 'tests/unit/style/parsing/mod.rs')
-rw-r--r-- | tests/unit/style/parsing/mod.rs | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/tests/unit/style/parsing/mod.rs b/tests/unit/style/parsing/mod.rs index 8e12018a7a3..369e0b66bf0 100644 --- a/tests/unit/style/parsing/mod.rs +++ b/tests/unit/style/parsing/mod.rs @@ -5,32 +5,19 @@ //! Tests for parsing and serialization of values/properties use cssparser::Parser; +use media_queries::CSSErrorReporterTest; +use style::parser::ParserContext; +use style::stylesheets::Origin; -fn parse<T, F: Fn(&mut Parser) -> Result<T, ()>>(f: F, s: &str) -> Result<T, ()> { +fn parse<T, F: Fn(&ParserContext, &mut Parser) -> Result<T, ()>>(f: F, s: &str) -> Result<T, ()> { + let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); + let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest)); let mut parser = Parser::new(s); - f(&mut parser) + f(&context, &mut parser) } - // This is a macro so that the file/line information // is preserved in the panic -macro_rules! assert_roundtrip { - ($fun:expr, $string:expr) => { - assert_roundtrip!($fun, $string, $string); - }; - ($fun:expr, $input:expr, $output:expr) => { - let parsed = $crate::parsing::parse($fun, $input) - .expect(&format!("Failed to parse {}", $input)); - let serialized = ToCss::to_css_string(&parsed); - assert_eq!(serialized, $output); - - let re_parsed = $crate::parsing::parse($fun, &serialized) - .expect(&format!("Failed to parse serialization {}", $input)); - let re_serialized = ToCss::to_css_string(&re_parsed); - assert_eq!(serialized, re_serialized); - } -} - macro_rules! assert_roundtrip_with_context { ($fun:expr, $string:expr) => { assert_roundtrip_with_context!($fun, $string, $string); @@ -46,13 +33,12 @@ macro_rules! assert_roundtrip_with_context { let mut parser = Parser::new(&serialized); let re_parsed = $fun(&context, &mut parser) - .expect(&format!("Failed to parse {}", $input)); + .expect(&format!("Failed to parse serialization {}", $input)); let re_serialized = ToCss::to_css_string(&re_parsed); assert_eq!(serialized, re_serialized); } } - macro_rules! parse_longhand { ($name:ident, $s:expr) => {{ let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); |