mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Centralize ParserContext for tests
To simplify adding additional data to `ParserContext`, this moves test usages to a few shared locations, instead of being spread across many tests. MozReview-Commit-ID: 1OahV797eq
This commit is contained in:
parent
f7896fd80b
commit
0936dd24d0
27 changed files with 248 additions and 513 deletions
|
@ -23,29 +23,30 @@ macro_rules! assert_roundtrip_with_context {
|
|||
($fun:expr, $string:expr) => {
|
||||
assert_roundtrip_with_context!($fun, $string, $string);
|
||||
};
|
||||
($fun:expr,$input:expr, $output:expr) => {
|
||||
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style));
|
||||
let mut parser = Parser::new($input);
|
||||
let parsed = $fun(&context, &mut parser)
|
||||
.expect(&format!("Failed to parse {}", $input));
|
||||
let serialized = ToCss::to_css_string(&parsed);
|
||||
assert_eq!(serialized, $output);
|
||||
($fun:expr, $input:expr, $output:expr) => {{
|
||||
let serialized = parse(|context, i| {
|
||||
let parsed = $fun(context, i)
|
||||
.expect(&format!("Failed to parse {}", $input));
|
||||
let serialized = ToCss::to_css_string(&parsed);
|
||||
assert_eq!(serialized, $output);
|
||||
Ok(serialized)
|
||||
}, $input).unwrap();
|
||||
|
||||
let mut parser = Parser::new(&serialized);
|
||||
let re_parsed = $fun(&context, &mut parser)
|
||||
.expect(&format!("Failed to parse serialization {}", $input));
|
||||
let re_serialized = ToCss::to_css_string(&re_parsed);
|
||||
assert_eq!(serialized, re_serialized);
|
||||
}
|
||||
parse(|context, i| {
|
||||
let re_parsed = $fun(context, i)
|
||||
.expect(&format!("Failed to parse serialization {}", $input));
|
||||
let re_serialized = ToCss::to_css_string(&re_parsed);
|
||||
assert_eq!(serialized, re_serialized);
|
||||
Ok(())
|
||||
}, &serialized).unwrap()
|
||||
}}
|
||||
}
|
||||
|
||||
macro_rules! assert_roundtrip {
|
||||
($fun:expr, $string:expr) => {
|
||||
assert_roundtrip!($fun, $string, $string);
|
||||
};
|
||||
($fun:expr,$input:expr, $output:expr) => {
|
||||
($fun:expr, $input:expr, $output:expr) => {
|
||||
let mut parser = Parser::new($input);
|
||||
let parsed = $fun(&mut parser)
|
||||
.expect(&format!("Failed to parse {}", $input));
|
||||
|
@ -56,29 +57,25 @@ macro_rules! assert_roundtrip {
|
|||
let re_parsed = $fun(&mut parser)
|
||||
.expect(&format!("Failed to parse serialization {}", $input));
|
||||
let re_serialized = ToCss::to_css_string(&re_parsed);
|
||||
assert_eq!(serialized, re_serialized);
|
||||
assert_eq!(serialized, re_serialized)
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! assert_parser_exhausted {
|
||||
($name:ident, $string:expr, $should_exhausted:expr) => {{
|
||||
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style));
|
||||
let mut parser = Parser::new($string);
|
||||
let parsed = $name::parse(&context, &mut parser);
|
||||
assert_eq!(parsed.is_ok(), true);
|
||||
assert_eq!(parser.is_exhausted(), $should_exhausted);
|
||||
($fun:expr, $string:expr, $should_exhausted:expr) => {{
|
||||
parse(|context, input| {
|
||||
let parsed = $fun(context, input);
|
||||
assert_eq!(parsed.is_ok(), true);
|
||||
assert_eq!(input.is_exhausted(), $should_exhausted);
|
||||
Ok(())
|
||||
}, $string).unwrap()
|
||||
}}
|
||||
}
|
||||
|
||||
macro_rules! parse_longhand {
|
||||
($name:ident, $s:expr) => {{
|
||||
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style));
|
||||
$name::parse(&context, &mut Parser::new($s)).unwrap()
|
||||
}};
|
||||
($name:ident, $s:expr) => {
|
||||
parse($name::parse, $s).unwrap()
|
||||
};
|
||||
}
|
||||
|
||||
mod animation;
|
||||
|
@ -103,3 +100,4 @@ mod text;
|
|||
mod text_overflow;
|
||||
mod transition_timing_function;
|
||||
mod ui;
|
||||
mod value;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue