From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- servo/tests/unit/style/properties/mod.rs | 70 ++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 servo/tests/unit/style/properties/mod.rs (limited to 'servo/tests/unit/style/properties/mod.rs') diff --git a/servo/tests/unit/style/properties/mod.rs b/servo/tests/unit/style/properties/mod.rs new file mode 100644 index 0000000000..06a5c2086f --- /dev/null +++ b/servo/tests/unit/style/properties/mod.rs @@ -0,0 +1,70 @@ +/* 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::{ParseError, ParsingMode}; + +fn parse(f: F, s: &'static str) -> Result> +where + F: for<'t> Fn(&ParserContext, &mut Parser<'static, 't>) -> Result>, +{ + 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> +where + F: Fn(&ParserContext, &mut Parser<'i, 't>) -> Result>, +{ + 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; -- cgit v1.2.3