diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /servo/tests/unit/style/properties/mod.rs | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'servo/tests/unit/style/properties/mod.rs')
-rw-r--r-- | servo/tests/unit/style/properties/mod.rs | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/servo/tests/unit/style/properties/mod.rs b/servo/tests/unit/style/properties/mod.rs new file mode 100644 index 0000000000..bfb6402692 --- /dev/null +++ b/servo/tests/unit/style/properties/mod.rs @@ -0,0 +1,66 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +use cssparser::{Parser, ParserInput}; +use style::context::QuirksMode; +use style::parser::ParserContext; +use style::stylesheets::{CssRuleType, Origin}; +use style_traits::{ParsingMode, ParseError}; + +fn parse<T, F>(f: F, s: &'static str) -> Result<T, ParseError<'static>> +where + F: for<'t> Fn( + &ParserContext, + &mut Parser<'static, 't>, + ) -> Result<T, ParseError<'static>> +{ + let mut input = ParserInput::new(s); + parse_input(f, &mut input) +} + +fn parse_input<'i: 't, 't, T, F>(f: F, input: &'t mut ParserInput<'i>) -> Result<T, ParseError<'i>> +where + F: Fn(&ParserContext, &mut Parser<'i, 't>) -> Result<T, ParseError<'i>>, +{ + let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); + let context = ParserContext::new( + Origin::Author, + &url, + Some(CssRuleType::Style), + ParsingMode::DEFAULT, + QuirksMode::NoQuirks, + None, + None, + ); + let mut parser = Parser::new(input); + f(&context, &mut parser) +} + +macro_rules! assert_roundtrip_with_context { + ($fun:expr, $string:expr) => { + assert_roundtrip_with_context!($fun, $string, $string); + }; + ($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 input = ::cssparser::ParserInput::new(&serialized); + let unwrapped = parse_input(|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(()) + }, &mut input).unwrap(); + unwrapped + }} +} + +mod scaffolding; +mod serialization; |