Skip to main content

rspack_lightningcss/
lib.rs

1//! Lightning CSS is a CSS parser, transformer, and minifier based on the
2//! [cssparser](https://github.com/servo/rust-cssparser) crate used in Firefox.
3//! It supports fully parsing all CSS rules, properties, and values into normalized
4//! structures exactly how a browser would. Once parsed, the CSS can be transformed
5//! to add or remove vendor prefixes, or lower syntax for older browsers as appropriate.
6//! The style sheet can also be minified to merge longhand properties into shorthands,
7//! merge adjacent rules, reduce `calc()` expressions, and more. Finally, the style sheet
8//! can be printed back to CSS syntax, either minified to remove whitespace and compress
9//! the output as much as possible, or pretty printed.
10//!
11//! The [StyleSheet](stylesheet::StyleSheet) struct is the main entrypoint for Lightning CSS,
12//! and supports parsing and transforming entire CSS files. You can also parse and manipulate
13//! individual CSS [rules](rules), [properties](properties), or [values](values). The [bundler](bundler)
14//! module also can be used to combine a CSS file and all of its dependencies together into a single
15//! style sheet. See the individual module documentation for more details and examples.
16
17#![deny(missing_docs)]
18#![cfg_attr(docsrs, feature(doc_cfg))]
19
20#[cfg(feature = "bundler")]
21#[cfg_attr(docsrs, doc(cfg(feature = "bundler")))]
22pub mod bundler;
23mod compat;
24mod context;
25pub mod css_modules;
26pub mod declaration;
27pub mod dependencies;
28pub mod error;
29mod logical;
30mod macros;
31pub mod media_query;
32mod parser;
33mod prefixes;
34pub mod printer;
35pub mod properties;
36pub mod rules;
37pub mod selector;
38pub mod stylesheet;
39pub mod targets;
40pub mod traits;
41pub mod values;
42pub mod vendor_prefix;
43#[cfg(feature = "visitor")]
44#[cfg_attr(docsrs, doc(cfg(feature = "visitor")))]
45pub mod visitor;
46
47#[cfg(feature = "serde")]
48mod serialization;
49
50#[cfg(test)]
51mod test_helpers;
52
53#[cfg(test)]
54mod tests {
55  use crate::css_modules::{CssModuleExport, CssModuleExports, CssModuleReference, CssModuleReferences};
56  use crate::dependencies::Dependency;
57  use crate::error::{Error, ErrorLocation, MinifyErrorKind, ParserError, PrinterErrorKind, SelectorError};
58  use crate::parser::ParserFlags;
59  use crate::printer::{OriginalLocation, SourceMap};
60  use crate::properties::custom::Token;
61  use crate::properties::Property;
62  use crate::rules::CssRule;
63  use crate::rules::Location;
64  use crate::stylesheet::*;
65  use crate::targets::{Browsers, Features, Targets};
66  use crate::test_helpers::panic_with_test_error;
67  use crate::traits::{Parse, ToCss};
68  use crate::values::color::CssColor;
69  use crate::vendor_prefix::VendorPrefix;
70  use cssparser::SourceLocation;
71  use indexmap::IndexMap;
72  use indoc::indoc;
73  use pretty_assertions::assert_eq;
74  use std::collections::HashMap;
75  use std::sync::{Arc, RwLock};
76
77  #[track_caller]
78  fn test(source: &str, expected: &str) {
79    test_with_options(source, expected, ParserOptions::default())
80  }
81
82  #[track_caller]
83  fn non_negative_test<'i, T: crate::traits::ParseNumeric<'i> + ToCss>(source: &'i str, expected: Option<&str>) {
84    use crate::values::number::NonNegative;
85
86    let result = NonNegative::<T>::parse_string(source);
87    match expected {
88      Some(expected) => {
89        let value = result.unwrap();
90        assert_eq!(
91          value.to_css_string(PrinterOptions::default()).unwrap(),
92          expected,
93          "{}",
94          source
95        );
96      }
97      None => assert!(result.is_err(), "expected {} to be invalid", source),
98    }
99  }
100
101  // Invalid known properties are preserved as unparsed declarations for browser validation.
102  #[track_caller]
103  fn property_range_test(names: &[&str], cases: &[(&str, Option<&str>)]) {
104    for name in names {
105      for (source, expected) in cases {
106        let value = Property::parse_string((*name).into(), source, ParserOptions::default()).unwrap();
107        if let Some(expected) = expected {
108          assert!(
109            !matches!(value, Property::Unparsed(_) | Property::Custom(_)),
110            "{name}: {source}"
111          );
112          assert_eq!(
113            value
114              .value_to_css_string(PrinterOptions {
115                minify: true,
116                ..PrinterOptions::default()
117              })
118              .unwrap(),
119            *expected,
120            "{name}: {source}"
121          );
122        } else {
123          assert!(
124            matches!(value, Property::Unparsed(_)),
125            "expected {name}: {source} to be invalid, got {value:?}"
126          );
127        }
128      }
129    }
130  }
131
132  #[track_caller]
133  fn test_with_options<'i>(source: &'i str, expected: &'i str, options: ParserOptions<'i>) {
134    let mut stylesheet = match StyleSheet::parse(&source, options) {
135      Ok(stylesheet) => stylesheet,
136      Err(e) => panic_with_test_error("test_with_options", "parse", source, e),
137    };
138    if let Err(e) = stylesheet.minify(MinifyOptions::default()) {
139      panic_with_test_error("test_with_options", "minify", source, e);
140    }
141    let res = match stylesheet.to_css(PrinterOptions::default(), None::<&mut ()>) {
142      Ok(res) => res,
143      Err(e) => panic_with_test_error("test_with_options", "print", source, e),
144    };
145    assert_eq!(res.code, expected);
146  }
147
148  #[track_caller]
149  fn test_with_printer_options<'i>(source: &'i str, expected: &'i str, options: PrinterOptions<'i>) {
150    let mut stylesheet = match StyleSheet::parse(&source, ParserOptions::default()) {
151      Ok(stylesheet) => stylesheet,
152      Err(e) => panic_with_test_error("test_with_printer_options", "parse", source, e),
153    };
154    if let Err(e) = stylesheet.minify(MinifyOptions::default()) {
155      panic_with_test_error("test_with_printer_options", "minify", source, e);
156    }
157    let res = match stylesheet.to_css(options, None::<&mut ()>) {
158      Ok(res) => res,
159      Err(e) => panic_with_test_error("test_with_printer_options", "print", source, e),
160    };
161    assert_eq!(res.code, expected);
162  }
163
164  #[track_caller]
165  fn minify_test(source: &str, expected: &str) {
166    minify_test_with_options(source, expected, ParserOptions::default())
167  }
168
169  #[track_caller]
170  fn minify_test_with_options<'i>(source: &'i str, expected: &'i str, options: ParserOptions<'i>) {
171    minify_test_with_options_and_browsers(source, expected, options, None)
172  }
173
174  #[track_caller]
175  fn minify_test_with_options_and_browsers<'i>(
176    source: &'i str,
177    expected: &'i str,
178    options: ParserOptions<'i>,
179    browsers: Option<Browsers>,
180  ) {
181    let targets = browsers.into();
182    let mut stylesheet = match StyleSheet::parse(&source, options) {
183      Ok(stylesheet) => stylesheet,
184      Err(e) => panic_with_test_error("minify_test_with_options", "parse", source, e),
185    };
186    if let Err(e) = stylesheet.minify(MinifyOptions {
187      targets,
188      ..MinifyOptions::default()
189    }) {
190      panic_with_test_error("minify_test_with_options", "minify", source, e);
191    }
192    let res = match stylesheet.to_css(
193      PrinterOptions {
194        minify: true,
195        targets,
196        ..PrinterOptions::default()
197      },
198      None::<&mut ()>,
199    ) {
200      Ok(res) => res,
201      Err(e) => panic_with_test_error("minify_test_with_options", "print", source, e),
202    };
203    assert_eq!(res.code, expected);
204  }
205
206  #[track_caller]
207  fn minify_error_test_with_options<'i>(source: &'i str, error: MinifyErrorKind, options: ParserOptions<'i>) {
208    let mut stylesheet = match StyleSheet::parse(&source, options) {
209      Ok(stylesheet) => stylesheet,
210      Err(e) => panic_with_test_error("minify_error_test_with_options", "parse", source, e),
211    };
212    match stylesheet.minify(MinifyOptions::default()) {
213      Err(e) => assert_eq!(e.kind, error),
214      Ok(()) => panic!(
215        "minify_error_test_with_options: expected minify error {:?}, but minification succeeded.\nsource:\n{source}",
216        error
217      ),
218    }
219  }
220
221  #[track_caller]
222  fn prefix_test(source: &str, expected: &str, targets: Browsers) {
223    let mut stylesheet = match StyleSheet::parse(&source, ParserOptions::default()) {
224      Ok(stylesheet) => stylesheet,
225      Err(e) => panic_with_test_error("prefix_test", "parse", source, e),
226    };
227    if let Err(e) = stylesheet.minify(MinifyOptions {
228      targets: targets.into(),
229      ..MinifyOptions::default()
230    }) {
231      panic_with_test_error("prefix_test", "minify", source, e);
232    }
233    let res = match stylesheet.to_css(
234      PrinterOptions {
235        targets: targets.into(),
236        ..PrinterOptions::default()
237      },
238      None::<&mut ()>,
239    ) {
240      Ok(res) => res,
241      Err(e) => panic_with_test_error("prefix_test", "print", source, e),
242    };
243    assert_eq!(res.code, expected);
244  }
245
246  #[track_caller]
247  fn attr_test(source: &str, expected: &str, minify: bool, targets: Option<Browsers>) {
248    let mut attr = match StyleAttribute::parse(source, ParserOptions::default()) {
249      Ok(attr) => attr,
250      Err(e) => panic_with_test_error("attr_test", "parse", source, e),
251    };
252    attr.minify(MinifyOptions {
253      targets: targets.into(),
254      ..MinifyOptions::default()
255    });
256    let res = match attr.to_css(PrinterOptions {
257      targets: targets.into(),
258      minify,
259      ..PrinterOptions::default()
260    }) {
261      Ok(res) => res,
262      Err(e) => panic_with_test_error("attr_test", "print", source, e),
263    };
264    assert_eq!(res.code, expected);
265  }
266
267  #[track_caller]
268  fn nesting_test(source: &str, expected: &str) {
269    nesting_test_with_targets(
270      source,
271      expected,
272      Browsers {
273        chrome: Some(95 << 16),
274        ..Browsers::default()
275      }
276      .into(),
277    );
278  }
279
280  #[track_caller]
281  fn nesting_test_with_targets(source: &str, expected: &str, targets: Targets) {
282    let mut stylesheet = match StyleSheet::parse(&source, ParserOptions::default()) {
283      Ok(stylesheet) => stylesheet,
284      Err(e) => panic_with_test_error("nesting_test_with_targets", "parse", source, e),
285    };
286    if let Err(e) = stylesheet.minify(MinifyOptions {
287      targets,
288      ..MinifyOptions::default()
289    }) {
290      panic_with_test_error("nesting_test_with_targets", "minify", source, e);
291    }
292    let res = match stylesheet.to_css(
293      PrinterOptions {
294        targets,
295        ..PrinterOptions::default()
296      },
297      None::<&mut ()>,
298    ) {
299      Ok(res) => res,
300      Err(e) => panic_with_test_error("nesting_test_with_targets", "print", source, e),
301    };
302    assert_eq!(res.code, expected);
303  }
304
305  #[track_caller]
306  fn nesting_test_no_targets(source: &str, expected: &str) {
307    let mut stylesheet = match StyleSheet::parse(&source, ParserOptions::default()) {
308      Ok(stylesheet) => stylesheet,
309      Err(e) => panic_with_test_error("nesting_test_no_targets", "parse", source, e),
310    };
311    if let Err(e) = stylesheet.minify(MinifyOptions::default()) {
312      panic_with_test_error("nesting_test_no_targets", "minify", source, e);
313    }
314    let res = match stylesheet.to_css(PrinterOptions::default(), None::<&mut ()>) {
315      Ok(res) => res,
316      Err(e) => panic_with_test_error("nesting_test_no_targets", "print", source, e),
317    };
318    assert_eq!(res.code, expected);
319  }
320
321  #[test]
322  fn test_css_module_order() {
323    // Exports and references are in source order, which determines e.g. dependency order.
324    let mut stylesheet = StyleSheet::parse(
325      r#"
326      .zebra { color: var(--z from "./z.css"); }
327      .apple { color: var(--a from "./a.css"); }
328      .mango { composes: m from "./m.css"; }
329    "#,
330      ParserOptions {
331        filename: "test.css".into(),
332        css_modules: Some(crate::css_modules::Config {
333          dashed_idents: true,
334          ..Default::default()
335        }),
336        ..ParserOptions::default()
337      },
338    )
339    .unwrap();
340    stylesheet.minify(MinifyOptions::default()).unwrap();
341    let res = stylesheet.to_css(PrinterOptions::default(), None::<&mut ()>).unwrap();
342    let exports: Vec<String> = res.exports.unwrap().into_keys().collect();
343    assert_eq!(exports, ["zebra", "apple", "mango"]);
344    let references: Vec<String> = res
345      .references
346      .unwrap()
347      .into_values()
348      .map(|reference| match reference {
349        CssModuleReference::Dependency { specifier, .. } => specifier,
350        _ => unreachable!(),
351      })
352      .collect();
353    assert_eq!(references, ["./z.css", "./a.css"]);
354  }
355
356  #[track_caller]
357  fn css_modules_test<'i>(
358    source: &'i str,
359    expected: &str,
360    expected_exports: CssModuleExports,
361    expected_references: CssModuleReferences,
362    config: crate::css_modules::Config,
363    minify: bool,
364  ) {
365    let mut stylesheet = match StyleSheet::parse(
366      &source,
367      ParserOptions {
368        filename: "test.css".into(),
369        css_modules: Some(config),
370        ..ParserOptions::default()
371      },
372    ) {
373      Ok(stylesheet) => stylesheet,
374      Err(e) => panic_with_test_error("css_modules_test", "parse", source, e),
375    };
376    if let Err(e) = stylesheet.minify(MinifyOptions::default()) {
377      panic_with_test_error("css_modules_test", "minify", source, e);
378    }
379    let res = match stylesheet.to_css(
380      PrinterOptions {
381        minify,
382        ..Default::default()
383      },
384      None::<&mut ()>,
385    ) {
386      Ok(res) => res,
387      Err(e) => panic_with_test_error("css_modules_test", "print", source, e),
388    };
389    assert_eq!(res.code, expected);
390    match res.exports {
391      Some(exports) => assert_eq!(exports, expected_exports),
392      None => panic!("css_modules_test: expected CSS module exports, but got None.\nsource:\n{source}"),
393    }
394    match res.references {
395      Some(references) => assert_eq!(references, expected_references),
396      None => panic!("css_modules_test: expected CSS module references, but got None.\nsource:\n{source}"),
397    }
398  }
399
400  #[track_caller]
401  fn custom_media_test(source: &str, expected: &str) {
402    let mut stylesheet = match StyleSheet::parse(
403      &source,
404      ParserOptions {
405        flags: ParserFlags::CUSTOM_MEDIA,
406        ..ParserOptions::default()
407      },
408    ) {
409      Ok(stylesheet) => stylesheet,
410      Err(e) => panic_with_test_error("custom_media_test", "parse", source, e),
411    };
412    if let Err(e) = stylesheet.minify(MinifyOptions {
413      targets: Browsers {
414        chrome: Some(95 << 16),
415        ..Browsers::default()
416      }
417      .into(),
418      ..MinifyOptions::default()
419    }) {
420      panic_with_test_error("custom_media_test", "minify", source, e);
421    }
422    let res = match stylesheet.to_css(PrinterOptions::default(), None::<&mut ()>) {
423      Ok(res) => res,
424      Err(e) => panic_with_test_error("custom_media_test", "print", source, e),
425    };
426    assert_eq!(res.code, expected);
427  }
428
429  fn error_test(source: &str, error: ParserError) {
430    let res = StyleSheet::parse(&source, ParserOptions::default());
431    match res {
432      Ok(_) => unreachable!(),
433      Err(e) => assert_eq!(e.kind, error),
434    }
435  }
436
437  fn error_test_with_options<'i>(source: &'i str, error: ParserError<'i>, options: ParserOptions<'i>) {
438    let res = StyleSheet::parse(&source, options);
439    match res {
440      Ok(_) => unreachable!(),
441      Err(e) => assert_eq!(e.kind, error),
442    }
443  }
444
445  fn error_recovery_test(source: &str) -> Vec<Error<ParserError<'_>>> {
446    let warnings = Arc::new(RwLock::default());
447    {
448      let res = StyleSheet::parse(
449        &source,
450        ParserOptions {
451          error_recovery: true,
452          warnings: Some(warnings.clone()),
453          ..Default::default()
454        },
455      );
456      match res {
457        Ok(..) => {}
458        Err(e) => unreachable!("parser error should be recovered, but got {e:?}"),
459      }
460    }
461    let warnings = match Arc::into_inner(warnings) {
462      Some(warnings) => warnings,
463      None => panic!("error_recovery_test: expected a single Arc owner for warnings"),
464    };
465    match warnings.into_inner() {
466      Ok(warnings) => warnings,
467      Err(e) => panic!("error_recovery_test: warnings lock is poisoned: {e}"),
468    }
469  }
470
471  fn css_modules_error_test(source: &str, error: ParserError) {
472    let res = StyleSheet::parse(
473      &source,
474      ParserOptions {
475        css_modules: Some(Default::default()),
476        ..Default::default()
477      },
478    );
479    match res {
480      Ok(_) => unreachable!(),
481      Err(e) => assert_eq!(e.kind, error),
482    }
483  }
484
485  macro_rules! map(
486    { $($key:expr => $name:literal $(referenced: $referenced: literal)? $($value:literal $(global: $global: literal)? $(from $from:literal)?)*),* } => {
487      {
488        #[allow(unused_mut)]
489        let mut m = IndexMap::new();
490        $(
491          #[allow(unused_mut)]
492          let mut v = Vec::new();
493          #[allow(unused_macros)]
494          macro_rules! insert {
495            ($local:literal from $specifier:literal) => {
496              v.push(CssModuleReference::Dependency {
497                name: $local.into(),
498                specifier: $specifier.into()
499              });
500            };
501            ($local:literal global: $is_global: literal) => {
502              v.push(CssModuleReference::Global {
503                name: $local.into()
504              });
505            };
506            ($local:literal) => {
507              v.push(CssModuleReference::Local {
508                name: $local.into()
509              });
510            };
511          }
512          $(
513            insert!($value $(global: $global)? $(from $from)?);
514          )*
515
516          macro_rules! is_referenced {
517            ($ref: literal) => {
518              $ref
519            };
520            () => {
521              false
522            };
523          }
524
525          m.insert($key.into(), CssModuleExport {
526            name: $name.into(),
527            composes: v,
528            is_referenced: is_referenced!($($referenced)?)
529          });
530        )*
531        m
532      }
533    };
534  );
535
536  #[test]
537  pub fn test_border_spacing() {
538    property_range_test(
539      &["border-spacing"],
540      &[
541        ("-1px", None),
542        ("calc(1px - 2px)", Some("0")),
543        ("calc(-1px + 2px)", Some("1px")),
544        ("1px -1px", None),
545      ],
546    );
547    minify_test(
548      r#"
549      .foo {
550        border-spacing: 0px;
551      }
552    "#,
553      indoc! {".foo{border-spacing:0}"
554      },
555    );
556    minify_test(
557      r#"
558      .foo {
559        border-spacing: 0px 0px;
560      }
561    "#,
562      indoc! {".foo{border-spacing:0}"
563      },
564    );
565
566    minify_test(
567      r#"
568      .foo {
569        border-spacing: 12px   0px;
570      }
571    "#,
572      indoc! {".foo{border-spacing:12px 0}"
573      },
574    );
575
576    minify_test(
577      r#"
578      .foo {
579        border-spacing: calc(3px * 2) calc(5px * 0);
580      }
581    "#,
582      indoc! {".foo{border-spacing:6px 0}"
583      },
584    );
585
586    minify_test(
587      r#"
588      .foo {
589        border-spacing: calc(3px * 2) max(0px, 8px);
590      }
591    "#,
592      indoc! {".foo{border-spacing:6px 8px}"
593      },
594    );
595
596    // TODO: The `<length>` in border-spacing cannot have a negative value,
597    // we may need to implement NonNegativeLength like Servo does.
598    // Servo Code: https://github.com/servo/servo/blob/08bc2d53579c9ab85415d4363888881b91df073b/components/style/values/specified/length.rs#L875
599    // CSSWG issue: https://lists.w3.org/Archives/Public/www-style/2008Sep/0161.html
600    // `border-spacing = <length> <length>?`
601    minify_test(
602      r#"
603      .foo {
604        border-spacing: -20px;
605      }
606    "#,
607      indoc! {".foo{border-spacing:-20px}"
608      },
609    );
610  }
611
612  #[test]
613  pub fn test_math_fn() {
614    use crate::values::angle::Angle;
615    use crate::values::length::Length;
616    use crate::values::number::{CSSInteger, CSSNumber};
617    use crate::values::percentage::{NumberOrPercentage, Percentage};
618
619    for source in ["-1", "-0.5"] {
620      non_negative_test::<CSSNumber>(source, None);
621      assert!(CSSNumber::parse_string(source).is_ok());
622    }
623    for (source, expected) in [
624      ("0", "0"),
625      ("-0", "0"),
626      ("calc(-5)", "0"),
627      ("calc(-5 + 10)", "5"),
628      ("calc(-5 * -2)", "10"),
629      ("min(-5, 10)", "0"),
630      ("max(-5, -10)", "0"),
631      ("clamp(-10, -5, -1)", "0"),
632      ("calc(min(-5, -10) + 20)", "10"),
633    ] {
634      non_negative_test::<CSSNumber>(source, Some(expected));
635      non_negative_test::<NumberOrPercentage>(source, Some(expected));
636    }
637    non_negative_test::<CSSInteger>("-1", None);
638    non_negative_test::<CSSInteger>("0", Some("0"));
639    non_negative_test::<CSSInteger>("2147483647", Some("2147483647"));
640    non_negative_test::<CSSInteger>("1.5", None);
641    for (source, expected) in [
642      ("-5%", None),
643      ("-0%", Some("-0%")),
644      ("calc(-5%)", Some("0%")),
645      ("calc(-5% + 10%)", Some("5%")),
646      ("min(-5%, 10%)", Some("0%")),
647      ("calc(min(-5%, -10%) + 20%)", Some("10%")),
648    ] {
649      non_negative_test::<Percentage>(source, expected);
650      non_negative_test::<NumberOrPercentage>(source, expected);
651    }
652    non_negative_test::<Percentage>("calc(1)", None);
653    non_negative_test::<Percentage>("calc(1px)", None);
654    assert_eq!(Percentage::parse_string("calc(-5%)").unwrap().0, -0.05);
655    for (source, expected) in [
656      ("-5deg", None),
657      ("calc(-5deg)", Some("0deg")),
658      ("calc(-5deg + 10deg)", Some("5deg")),
659      ("min(-5deg, 10deg)", Some("0deg")),
660      ("calc(1)", None),
661    ] {
662      non_negative_test::<Angle>(source, expected);
663    }
664    for (source, expected) in [
665      ("min(-5px, 10px)", "0"),
666      ("max(-5px, -10px)", "0"),
667      ("clamp(-10px, -5px, -1px)", "0"),
668      ("calc(min(-5px, -10px) + 20px)", "10px"),
669    ] {
670      non_negative_test::<Length>(source, Some(expected));
671    }
672
673    // max()
674    minify_test(
675      r#"
676      .foo {
677        color: rgb(max(255, 100), 0, 0);
678      }
679    "#,
680      indoc! {".foo{color:red}"
681      },
682    );
683    // min()
684    minify_test(
685      r#"
686      .foo {
687        color: rgb(min(255, 500), 0, 0);
688      }
689    "#,
690      indoc! {".foo{color:red}"
691      },
692    );
693    // abs()
694    minify_test(
695      r#"
696      .foo {
697        color: rgb(abs(-255), 0, 0);
698      }
699    "#,
700      indoc! {".foo{color:red}"
701      },
702    );
703    // clamp()
704    minify_test(
705      r#"
706      .foo {
707        flex: clamp(1, 5.20, 20);
708        color: rgb(clamp(0, 255, 300), 0, 0);
709      }
710    "#,
711      indoc! {".foo{color:red;flex:5.2}"
712      },
713    );
714    // round()
715    minify_test(
716      r#"
717      .round-color {
718        color: rgb(round(down, 255.6, 1), 0, 0);
719      }
720    "#,
721      indoc! {".round-color{color:red}"
722      },
723    );
724    // hypot()
725    minify_test(
726      r#"
727      .hypot-color {
728        color: rgb(hypot(255, 0), 0, 0);
729      }
730    "#,
731      indoc! {".hypot-color{color:red}"
732      },
733    );
734    // sign(), sign(50) = 1
735    minify_test(
736      r#"
737      .sign-color {
738        color: rgb(sign(50), 0, 0);
739      }
740    "#,
741      indoc! {".sign-color{color:#010000}"
742      },
743    );
744    // rem(), rem(21, 2) = 1
745    minify_test(
746      r#"
747      .rem-color {
748        color: rgb(rem(21, 2), 0, 0);
749      }
750    "#,
751      indoc! {".rem-color{color:#010000}"
752      },
753    );
754    // max() in width
755    minify_test(
756      r#"
757      .foo {
758        width: max(200px,   5px);
759      }
760    "#,
761      indoc! {".foo{width:200px}"
762      },
763    );
764    // max() in opacity
765    minify_test(
766      r#"
767      .foo {
768        opacity: max(1, 0.2);
769        filter: invert(min(1, 0.5));
770      }
771    "#,
772      indoc! {".foo{opacity:1;filter:invert(.5)}"
773      },
774    );
775    // TODO: support calc in Integer
776    // minify_test(
777    //   r#"
778    //   .foo {
779    //     z-index: max(100,    20);
780    //   }
781    // "#,
782    //   indoc! {".foo{z-index:100}"
783    //   },
784    // );
785  }
786
787  #[test]
788  pub fn test_border() {
789    property_range_test(
790      &["border-width", "border-left-width", "outline-width"],
791      &[
792        ("-1px", None),
793        ("calc(1px - 2px)", Some("0")),
794        ("calc(-1px + 2px)", Some("1px")),
795      ],
796    );
797    test(
798      r#"
799      .foo {
800        border-left: 2px solid red;
801        border-right: 2px solid red;
802        border-bottom: 2px solid red;
803        border-top: 2px solid red;
804      }
805    "#,
806      indoc! {r#"
807      .foo {
808        border: 2px solid red;
809      }
810    "#
811      },
812    );
813
814    test(
815      r#"
816      .foo {
817        border-left-color: red;
818        border-right-color: red;
819        border-bottom-color: red;
820        border-top-color: red;
821      }
822    "#,
823      indoc! {r#"
824      .foo {
825        border-color: red;
826      }
827    "#
828      },
829    );
830
831    test(
832      r#"
833      .foo {
834        border-left-width: thin;
835        border-right-width: thin;
836        border-bottom-width: thin;
837        border-top-width: thin;
838      }
839    "#,
840      indoc! {r#"
841      .foo {
842        border-width: thin;
843      }
844    "#
845      },
846    );
847
848    test(
849      r#"
850      .foo {
851        border-left-style: dotted;
852        border-right-style: dotted;
853        border-bottom-style: dotted;
854        border-top-style: dotted;
855      }
856    "#,
857      indoc! {r#"
858      .foo {
859        border-style: dotted;
860      }
861    "#
862      },
863    );
864
865    test(
866      r#"
867      .foo {
868        border-left-width: thin;
869        border-left-style: dotted;
870        border-left-color: red;
871      }
872    "#,
873      indoc! {r#"
874      .foo {
875        border-left: thin dotted red;
876      }
877    "#
878      },
879    );
880
881    test(
882      r#"
883      .foo {
884        border-left-width: thick;
885        border-left: thin dotted red;
886      }
887    "#,
888      indoc! {r#"
889      .foo {
890        border-left: thin dotted red;
891      }
892    "#
893      },
894    );
895
896    test(
897      r#"
898      .foo {
899        border-left-width: thick;
900        border: thin dotted red;
901      }
902    "#,
903      indoc! {r#"
904      .foo {
905        border: thin dotted red;
906      }
907    "#
908      },
909    );
910
911    test(
912      r#"
913      .foo {
914        border: thin dotted red;
915        border-right-width: thick;
916      }
917    "#,
918      indoc! {r#"
919      .foo {
920        border: thin dotted red;
921        border-right-width: thick;
922      }
923    "#
924      },
925    );
926
927    test(
928      r#"
929      .foo {
930        border: thin dotted red;
931        border-right: thick dotted red;
932      }
933    "#,
934      indoc! {r#"
935      .foo {
936        border: thin dotted red;
937        border-right-width: thick;
938      }
939    "#
940      },
941    );
942
943    test(
944      r#"
945      .foo {
946        border: thin dotted red;
947        border-right-width: thick;
948        border-right-style: solid;
949      }
950    "#,
951      indoc! {r#"
952      .foo {
953        border: thin dotted red;
954        border-right: thick solid red;
955      }
956    "#
957      },
958    );
959
960    test(
961      r#"
962      .foo {
963        border-top: thin dotted red;
964        border-block-start: thick solid green;
965      }
966    "#,
967      indoc! {r#"
968      .foo {
969        border-top: thin dotted red;
970        border-block-start: thick solid green;
971      }
972    "#
973      },
974    );
975
976    test(
977      r#"
978      .foo {
979        border: thin dotted red;
980        border-block-start-width: thick;
981        border-left-width: medium;
982      }
983    "#,
984      indoc! {r#"
985      .foo {
986        border: thin dotted red;
987        border-block-start-width: thick;
988        border-left-width: medium;
989      }
990    "#
991      },
992    );
993
994    test(
995      r#"
996      .foo {
997        border-block-start: thin dotted red;
998        border-inline-end: thin dotted red;
999      }
1000    "#,
1001      indoc! {r#"
1002      .foo {
1003        border-block-start: thin dotted red;
1004        border-inline-end: thin dotted red;
1005      }
1006    "#
1007      },
1008    );
1009
1010    test(
1011      r#"
1012      .foo {
1013        border-block-start-width: thin;
1014        border-block-start-style: dotted;
1015        border-block-start-color: red;
1016        border-inline-end: thin dotted red;
1017      }
1018    "#,
1019      indoc! {r#"
1020      .foo {
1021        border-block-start: thin dotted red;
1022        border-inline-end: thin dotted red;
1023      }
1024    "#
1025      },
1026    );
1027
1028    test(
1029      r#"
1030      .foo {
1031        border-block-start: thin dotted red;
1032        border-block-end: thin dotted red;
1033      }
1034    "#,
1035      indoc! {r#"
1036      .foo {
1037        border-block: thin dotted red;
1038      }
1039    "#
1040      },
1041    );
1042
1043    minify_test(
1044      r#"
1045      .foo {
1046        border: none;
1047      }
1048    "#,
1049      indoc! {".foo{border:none}"
1050      },
1051    );
1052
1053    minify_test(".foo { border-width: 0 0 1px; }", ".foo{border-width:0 0 1px}");
1054    test(
1055      r#"
1056      .foo {
1057        border-block-width: 1px;
1058        border-inline-width: 1px;
1059      }
1060    "#,
1061      indoc! {r#"
1062      .foo {
1063        border-width: 1px;
1064      }
1065    "#
1066      },
1067    );
1068    test(
1069      r#"
1070      .foo {
1071        border-block-start-width: 1px;
1072        border-block-end-width: 1px;
1073        border-inline-start-width: 1px;
1074        border-inline-end-width: 1px;
1075      }
1076    "#,
1077      indoc! {r#"
1078      .foo {
1079        border-width: 1px;
1080      }
1081    "#
1082      },
1083    );
1084    test(
1085      r#"
1086      .foo {
1087        border-block-start-width: 1px;
1088        border-block-end-width: 1px;
1089        border-inline-start-width: 2px;
1090        border-inline-end-width: 2px;
1091      }
1092    "#,
1093      indoc! {r#"
1094      .foo {
1095        border-block-width: 1px;
1096        border-inline-width: 2px;
1097      }
1098    "#
1099      },
1100    );
1101    test(
1102      r#"
1103      .foo {
1104        border-block-start-width: 1px;
1105        border-block-end-width: 1px;
1106        border-inline-start-width: 2px;
1107        border-inline-end-width: 3px;
1108      }
1109    "#,
1110      indoc! {r#"
1111      .foo {
1112        border-block-width: 1px;
1113        border-inline-width: 2px 3px;
1114      }
1115    "#
1116      },
1117    );
1118
1119    minify_test(
1120      ".foo { border-bottom: 1px solid var(--spectrum-global-color-gray-200)}",
1121      ".foo{border-bottom:1px solid var(--spectrum-global-color-gray-200)}",
1122    );
1123    test(
1124      r#"
1125      .foo {
1126        border-width: 0;
1127        border-bottom: var(--test, 1px) solid;
1128      }
1129    "#,
1130      indoc! {r#"
1131      .foo {
1132        border-width: 0;
1133        border-bottom: var(--test, 1px) solid;
1134      }
1135    "#
1136      },
1137    );
1138
1139    test(
1140      r#"
1141      .foo {
1142        border: 1px solid black;
1143        border-width: 1px 1px 0 0;
1144      }
1145    "#,
1146      indoc! {r#"
1147      .foo {
1148        border: 1px solid #000;
1149        border-width: 1px 1px 0 0;
1150      }
1151    "#},
1152    );
1153
1154    test(
1155      r#"
1156      .foo {
1157        border-top: 1px solid black;
1158        border-bottom: 1px solid black;
1159        border-left: 2px solid black;
1160        border-right: 2px solid black;
1161      }
1162    "#,
1163      indoc! {r#"
1164      .foo {
1165        border: 1px solid #000;
1166        border-width: 1px 2px;
1167      }
1168    "#},
1169    );
1170
1171    test(
1172      r#"
1173      .foo {
1174        border-top: 1px solid black;
1175        border-bottom: 1px solid black;
1176        border-left: 2px solid black;
1177        border-right: 1px solid black;
1178      }
1179    "#,
1180      indoc! {r#"
1181      .foo {
1182        border: 1px solid #000;
1183        border-left-width: 2px;
1184      }
1185    "#},
1186    );
1187
1188    test(
1189      r#"
1190      .foo {
1191        border-top: 1px solid black;
1192        border-bottom: 1px solid black;
1193        border-left: 1px solid red;
1194        border-right: 1px solid red;
1195      }
1196    "#,
1197      indoc! {r#"
1198      .foo {
1199        border: 1px solid #000;
1200        border-color: #000 red;
1201      }
1202    "#},
1203    );
1204
1205    test(
1206      r#"
1207      .foo {
1208        border-block-start: 1px solid black;
1209        border-block-end: 1px solid black;
1210        border-inline-start: 1px solid red;
1211        border-inline-end: 1px solid red;
1212      }
1213    "#,
1214      indoc! {r#"
1215      .foo {
1216        border: 1px solid #000;
1217        border-inline-color: red;
1218      }
1219    "#},
1220    );
1221
1222    test(
1223      r#"
1224      .foo {
1225        border-block-start: 1px solid black;
1226        border-block-end: 1px solid black;
1227        border-inline-start: 2px solid black;
1228        border-inline-end: 2px solid black;
1229      }
1230    "#,
1231      indoc! {r#"
1232      .foo {
1233        border: 1px solid #000;
1234        border-inline-width: 2px;
1235      }
1236    "#},
1237    );
1238
1239    test(
1240      r#"
1241      .foo {
1242        border-block-start: 1px solid black;
1243        border-block-end: 1px solid black;
1244        border-inline-start: 2px solid red;
1245        border-inline-end: 2px solid red;
1246      }
1247    "#,
1248      indoc! {r#"
1249      .foo {
1250        border: 1px solid #000;
1251        border-inline: 2px solid red;
1252      }
1253    "#},
1254    );
1255
1256    test(
1257      r#"
1258      .foo {
1259        border-block-start: 1px solid black;
1260        border-block-end: 1px solid black;
1261        border-inline-start: 2px solid red;
1262        border-inline-end: 3px solid red;
1263      }
1264    "#,
1265      indoc! {r#"
1266      .foo {
1267        border: 1px solid #000;
1268        border-inline-start: 2px solid red;
1269        border-inline-end: 3px solid red;
1270      }
1271    "#},
1272    );
1273
1274    test(
1275      r#"
1276      .foo {
1277        border-block-start: 2px solid black;
1278        border-block-end: 1px solid black;
1279        border-inline-start: 2px solid red;
1280        border-inline-end: 2px solid red;
1281      }
1282    "#,
1283      indoc! {r#"
1284      .foo {
1285        border: 2px solid red;
1286        border-block-start-color: #000;
1287        border-block-end: 1px solid #000;
1288      }
1289    "#},
1290    );
1291
1292    test(
1293      r#"
1294      .foo {
1295        border-block-start: 2px solid red;
1296        border-block-end: 1px solid red;
1297        border-inline-start: 2px solid red;
1298        border-inline-end: 2px solid red;
1299      }
1300    "#,
1301      indoc! {r#"
1302      .foo {
1303        border: 2px solid red;
1304        border-block-end-width: 1px;
1305      }
1306    "#},
1307    );
1308
1309    test(
1310      r#"
1311      .foo {
1312        border-block-start: 2px solid red;
1313        border-block-end: 2px solid red;
1314        border-inline-start: 2px solid red;
1315        border-inline-end: 1px solid red;
1316      }
1317    "#,
1318      indoc! {r#"
1319      .foo {
1320        border: 2px solid red;
1321        border-inline-end-width: 1px;
1322      }
1323    "#},
1324    );
1325
1326    test(
1327      r#"
1328      .foo {
1329        border: 1px solid currentColor;
1330      }
1331    "#,
1332      indoc! {r#"
1333      .foo {
1334        border: 1px solid;
1335      }
1336    "#
1337      },
1338    );
1339
1340    minify_test(
1341      r#"
1342      .foo {
1343        border: 1px solid currentColor;
1344      }
1345    "#,
1346      ".foo{border:1px solid}",
1347    );
1348
1349    prefix_test(
1350      r#"
1351      .foo {
1352        border-block: 2px solid red;
1353      }
1354    "#,
1355      indoc! {r#"
1356      .foo {
1357        border-top: 2px solid red;
1358        border-bottom: 2px solid red;
1359      }
1360    "#
1361      },
1362      Browsers {
1363        safari: Some(8 << 16),
1364        ..Browsers::default()
1365      },
1366    );
1367
1368    prefix_test(
1369      r#"
1370      .foo {
1371        border-block-start: 2px solid red;
1372      }
1373    "#,
1374      indoc! {r#"
1375      .foo {
1376        border-top: 2px solid red;
1377      }
1378    "#
1379      },
1380      Browsers {
1381        safari: Some(8 << 16),
1382        ..Browsers::default()
1383      },
1384    );
1385
1386    prefix_test(
1387      r#"
1388      .foo {
1389        border-block-end: 2px solid red;
1390      }
1391    "#,
1392      indoc! {r#"
1393      .foo {
1394        border-bottom: 2px solid red;
1395      }
1396    "#
1397      },
1398      Browsers {
1399        safari: Some(8 << 16),
1400        ..Browsers::default()
1401      },
1402    );
1403
1404    prefix_test(
1405      r#"
1406      .foo {
1407        border-inline: 2px solid red;
1408      }
1409    "#,
1410      indoc! {r#"
1411      .foo {
1412        border-left: 2px solid red;
1413        border-right: 2px solid red;
1414      }
1415    "#
1416      },
1417      Browsers {
1418        safari: Some(8 << 16),
1419        ..Browsers::default()
1420      },
1421    );
1422
1423    prefix_test(
1424      r#"
1425      .foo {
1426        border-block-width: 2px;
1427      }
1428    "#,
1429      indoc! {r#"
1430      .foo {
1431        border-block-start-width: 2px;
1432        border-block-end-width: 2px;
1433      }
1434    "#
1435      },
1436      Browsers {
1437        safari: Some(13 << 16),
1438        ..Browsers::default()
1439      },
1440    );
1441
1442    prefix_test(
1443      r#"
1444      .foo {
1445        border-block-width: 2px;
1446      }
1447    "#,
1448      indoc! {r#"
1449      .foo {
1450        border-block-width: 2px;
1451      }
1452    "#
1453      },
1454      Browsers {
1455        safari: Some(15 << 16),
1456        ..Browsers::default()
1457      },
1458    );
1459
1460    prefix_test(
1461      r#"
1462      .foo {
1463        border-inline-start: 2px solid red;
1464      }
1465    "#,
1466      indoc! {r#"
1467      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
1468        border-left: 2px solid red;
1469      }
1470
1471      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
1472        border-left: 2px solid red;
1473      }
1474
1475      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
1476        border-right: 2px solid red;
1477      }
1478
1479      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
1480        border-right: 2px solid red;
1481      }
1482    "#
1483      },
1484      Browsers {
1485        safari: Some(8 << 16),
1486        ..Browsers::default()
1487      },
1488    );
1489
1490    prefix_test(
1491      r#"
1492      .foo {
1493        border-inline-start-width: 2px;
1494      }
1495    "#,
1496      indoc! {r#"
1497      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
1498        border-left-width: 2px;
1499      }
1500
1501      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
1502        border-left-width: 2px;
1503      }
1504
1505      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
1506        border-right-width: 2px;
1507      }
1508
1509      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
1510        border-right-width: 2px;
1511      }
1512    "#
1513      },
1514      Browsers {
1515        safari: Some(8 << 16),
1516        ..Browsers::default()
1517      },
1518    );
1519
1520    prefix_test(
1521      r#"
1522      .foo {
1523        border-inline-end: 2px solid red;
1524      }
1525    "#,
1526      indoc! {r#"
1527      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
1528        border-right: 2px solid red;
1529      }
1530
1531      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
1532        border-right: 2px solid red;
1533      }
1534
1535      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
1536        border-left: 2px solid red;
1537      }
1538
1539      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
1540        border-left: 2px solid red;
1541      }
1542    "#
1543      },
1544      Browsers {
1545        safari: Some(8 << 16),
1546        ..Browsers::default()
1547      },
1548    );
1549
1550    prefix_test(
1551      r#"
1552      .foo {
1553        border-inline-start: 2px solid red;
1554        border-inline-end: 5px solid green;
1555      }
1556    "#,
1557      indoc! {r#"
1558      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
1559        border-left: 2px solid red;
1560        border-right: 5px solid green;
1561      }
1562
1563      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
1564        border-left: 2px solid red;
1565        border-right: 5px solid green;
1566      }
1567
1568      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
1569        border-left: 5px solid green;
1570        border-right: 2px solid red;
1571      }
1572
1573      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
1574        border-left: 5px solid green;
1575        border-right: 2px solid red;
1576      }
1577    "#
1578      },
1579      Browsers {
1580        safari: Some(8 << 16),
1581        ..Browsers::default()
1582      },
1583    );
1584
1585    prefix_test(
1586      r#"
1587      .foo {
1588        border-inline-start: 2px solid red;
1589        border-inline-end: 5px solid green;
1590      }
1591
1592      .bar {
1593        border-inline-start: 1px dotted gray;
1594        border-inline-end: 1px solid black;
1595      }
1596    "#,
1597      indoc! {r#"
1598      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
1599        border-left: 2px solid red;
1600        border-right: 5px solid green;
1601      }
1602
1603      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
1604        border-left: 2px solid red;
1605        border-right: 5px solid green;
1606      }
1607
1608      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
1609        border-left: 5px solid green;
1610        border-right: 2px solid red;
1611      }
1612
1613      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
1614        border-left: 5px solid green;
1615        border-right: 2px solid red;
1616      }
1617
1618      .bar:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
1619        border-left: 1px dotted gray;
1620        border-right: 1px solid #000;
1621      }
1622
1623      .bar:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
1624        border-left: 1px dotted gray;
1625        border-right: 1px solid #000;
1626      }
1627
1628      .bar:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
1629        border-left: 1px solid #000;
1630        border-right: 1px dotted gray;
1631      }
1632
1633      .bar:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
1634        border-left: 1px solid #000;
1635        border-right: 1px dotted gray;
1636      }
1637    "#
1638      },
1639      Browsers {
1640        safari: Some(8 << 16),
1641        ..Browsers::default()
1642      },
1643    );
1644
1645    prefix_test(
1646      r#"
1647      .foo {
1648        border-inline-width: 2px;
1649      }
1650    "#,
1651      indoc! {r#"
1652      .foo {
1653        border-left-width: 2px;
1654        border-right-width: 2px;
1655      }
1656    "#
1657      },
1658      Browsers {
1659        safari: Some(8 << 16),
1660        ..Browsers::default()
1661      },
1662    );
1663
1664    prefix_test(
1665      r#"
1666      .foo {
1667        border-inline-width: 2px;
1668      }
1669    "#,
1670      indoc! {r#"
1671      .foo {
1672        border-left-width: 2px;
1673        border-right-width: 2px;
1674      }
1675    "#
1676      },
1677      Browsers {
1678        safari: Some(8 << 16),
1679        ..Browsers::default()
1680      },
1681    );
1682
1683    prefix_test(
1684      r#"
1685      .foo {
1686        border-inline-style: solid;
1687      }
1688    "#,
1689      indoc! {r#"
1690      .foo {
1691        border-left-style: solid;
1692        border-right-style: solid;
1693      }
1694    "#
1695      },
1696      Browsers {
1697        safari: Some(8 << 16),
1698        ..Browsers::default()
1699      },
1700    );
1701
1702    prefix_test(
1703      r#"
1704      .foo {
1705        border-inline-color: red;
1706      }
1707    "#,
1708      indoc! {r#"
1709      .foo {
1710        border-left-color: red;
1711        border-right-color: red;
1712      }
1713    "#
1714      },
1715      Browsers {
1716        safari: Some(8 << 16),
1717        ..Browsers::default()
1718      },
1719    );
1720
1721    prefix_test(
1722      r#"
1723      .foo {
1724        border-inline-end: var(--test);
1725      }
1726    "#,
1727      indoc! {r#"
1728      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
1729        border-right: var(--test);
1730      }
1731
1732      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
1733        border-right: var(--test);
1734      }
1735
1736      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
1737        border-left: var(--test);
1738      }
1739
1740      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
1741        border-left: var(--test);
1742      }
1743    "#
1744      },
1745      Browsers {
1746        safari: Some(8 << 16),
1747        ..Browsers::default()
1748      },
1749    );
1750
1751    prefix_test(
1752      r#"
1753      .foo {
1754        border-inline-start: var(--start);
1755        border-inline-end: var(--end);
1756      }
1757    "#,
1758      indoc! {r#"
1759      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
1760        border-left: var(--start);
1761        border-right: var(--end);
1762      }
1763
1764      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
1765        border-left: var(--start);
1766        border-right: var(--end);
1767      }
1768
1769      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
1770        border-right: var(--start);
1771        border-left: var(--end);
1772      }
1773
1774      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
1775        border-right: var(--start);
1776        border-left: var(--end);
1777      }
1778    "#
1779      },
1780      Browsers {
1781        safari: Some(8 << 16),
1782        ..Browsers::default()
1783      },
1784    );
1785
1786    for prop in &[
1787      "border-inline-start-color",
1788      "border-inline-end-color",
1789      "border-block-start-color",
1790      "border-block-end-color",
1791      "border-top-color",
1792      "border-bottom-color",
1793      "border-left-color",
1794      "border-right-color",
1795      "border-color",
1796      "border-block-color",
1797      "border-inline-color",
1798    ] {
1799      prefix_test(
1800        &format!(
1801          r#"
1802        .foo {{
1803          {}: lab(40% 56.6 39);
1804        }}
1805      "#,
1806          prop
1807        ),
1808        &format!(
1809          indoc! {r#"
1810        .foo {{
1811          {}: #b32323;
1812          {}: lab(40% 56.6 39);
1813        }}
1814      "#},
1815          prop, prop
1816        ),
1817        Browsers {
1818          chrome: Some(90 << 16),
1819          ..Browsers::default()
1820        },
1821      );
1822    }
1823
1824    for prop in &[
1825      "border",
1826      "border-inline",
1827      "border-block",
1828      "border-left",
1829      "border-right",
1830      "border-top",
1831      "border-bottom",
1832      "border-block-start",
1833      "border-block-end",
1834      "border-inline-start",
1835      "border-inline-end",
1836    ] {
1837      prefix_test(
1838        &format!(
1839          r#"
1840        .foo {{
1841          {}: 2px solid lab(40% 56.6 39);
1842        }}
1843      "#,
1844          prop
1845        ),
1846        &format!(
1847          indoc! {r#"
1848        .foo {{
1849          {}: 2px solid #b32323;
1850          {}: 2px solid lab(40% 56.6 39);
1851        }}
1852      "#},
1853          prop, prop
1854        ),
1855        Browsers {
1856          chrome: Some(90 << 16),
1857          ..Browsers::default()
1858        },
1859      );
1860    }
1861
1862    for prop in &[
1863      "border",
1864      "border-inline",
1865      "border-block",
1866      "border-left",
1867      "border-right",
1868      "border-top",
1869      "border-bottom",
1870      "border-block-start",
1871      "border-block-end",
1872      "border-inline-start",
1873      "border-inline-end",
1874    ] {
1875      prefix_test(
1876        &format!(
1877          r#"
1878        .foo {{
1879          {}: var(--border-width) solid lab(40% 56.6 39);
1880        }}
1881      "#,
1882          prop
1883        ),
1884        &format!(
1885          indoc! {r#"
1886        .foo {{
1887          {}: var(--border-width) solid #b32323;
1888        }}
1889
1890        @supports (color: lab(0% 0 0)) {{
1891          .foo {{
1892            {}: var(--border-width) solid lab(40% 56.6 39);
1893          }}
1894        }}
1895      "#},
1896          prop, prop
1897        ),
1898        Browsers {
1899          chrome: Some(90 << 16),
1900          ..Browsers::default()
1901        },
1902      );
1903
1904      prefix_test(
1905        &format!(
1906          r#"
1907        @supports (color: lab(0% 0 0)) {{
1908          .foo {{
1909            {}: var(--border-width) solid lab(40% 56.6 39);
1910          }}
1911        }}
1912      "#,
1913          prop
1914        ),
1915        &format!(
1916          indoc! {r#"
1917        @supports (color: lab(0% 0 0)) {{
1918          .foo {{
1919            {}: var(--border-width) solid lab(40% 56.6 39);
1920          }}
1921        }}
1922      "#},
1923          prop,
1924        ),
1925        Browsers {
1926          chrome: Some(90 << 16),
1927          ..Browsers::default()
1928        },
1929      );
1930    }
1931
1932    prefix_test(
1933      r#"
1934      .foo {
1935        border-inline-start-color: lab(40% 56.6 39);
1936      }
1937    "#,
1938      indoc! {r#"
1939      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
1940        border-left-color: #b32323;
1941        border-left-color: lab(40% 56.6 39);
1942      }
1943
1944      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
1945        border-left-color: #b32323;
1946        border-left-color: lab(40% 56.6 39);
1947      }
1948
1949      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
1950        border-right-color: #b32323;
1951        border-right-color: lab(40% 56.6 39);
1952      }
1953
1954      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
1955        border-right-color: #b32323;
1956        border-right-color: lab(40% 56.6 39);
1957      }
1958    "#},
1959      Browsers {
1960        safari: Some(8 << 16),
1961        ..Browsers::default()
1962      },
1963    );
1964
1965    prefix_test(
1966      r#"
1967      .foo {
1968        border-inline-end-color: lab(40% 56.6 39);
1969      }
1970    "#,
1971      indoc! {r#"
1972      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
1973        border-right-color: #b32323;
1974        border-right-color: lab(40% 56.6 39);
1975      }
1976
1977      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
1978        border-right-color: #b32323;
1979        border-right-color: lab(40% 56.6 39);
1980      }
1981
1982      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
1983        border-left-color: #b32323;
1984        border-left-color: lab(40% 56.6 39);
1985      }
1986
1987      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
1988        border-left-color: #b32323;
1989        border-left-color: lab(40% 56.6 39);
1990      }
1991    "#},
1992      Browsers {
1993        safari: Some(8 << 16),
1994        ..Browsers::default()
1995      },
1996    );
1997
1998    prefix_test(
1999      r#"
2000      .foo {
2001        border-inline-start-color: lab(40% 56.6 39);
2002        border-inline-end-color: lch(50.998% 135.363 338);
2003      }
2004    "#,
2005      indoc! {r#"
2006      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
2007        border-left-color: #b32323;
2008        border-left-color: lab(40% 56.6 39);
2009        border-right-color: #f000c0;
2010        border-right-color: lch(50.998% 135.363 338);
2011      }
2012
2013      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
2014        border-left-color: #b32323;
2015        border-left-color: lab(40% 56.6 39);
2016        border-right-color: #f000c0;
2017        border-right-color: lch(50.998% 135.363 338);
2018      }
2019
2020      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
2021        border-left-color: #f000c0;
2022        border-left-color: lch(50.998% 135.363 338);
2023        border-right-color: #b32323;
2024        border-right-color: lab(40% 56.6 39);
2025      }
2026
2027      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
2028        border-left-color: #f000c0;
2029        border-left-color: lch(50.998% 135.363 338);
2030        border-right-color: #b32323;
2031        border-right-color: lab(40% 56.6 39);
2032      }
2033    "#},
2034      Browsers {
2035        safari: Some(8 << 16),
2036        ..Browsers::default()
2037      },
2038    );
2039
2040    prefix_test(
2041      r#"
2042      .foo {
2043        border-inline-start-color: lab(40% 56.6 39);
2044        border-inline-end-color: lch(50.998% 135.363 338);
2045      }
2046    "#,
2047      indoc! {r#"
2048      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
2049        border-left-color: #b32323;
2050        border-left-color: color(display-p3 .643308 .192455 .167712);
2051        border-left-color: lab(40% 56.6 39);
2052        border-right-color: #f000c0;
2053        border-right-color: color(display-p3 .972962 -.362078 .804206);
2054        border-right-color: lch(50.998% 135.363 338);
2055      }
2056
2057      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
2058        border-left-color: #f000c0;
2059        border-left-color: color(display-p3 .972962 -.362078 .804206);
2060        border-left-color: lch(50.998% 135.363 338);
2061        border-right-color: #b32323;
2062        border-right-color: color(display-p3 .643308 .192455 .167712);
2063        border-right-color: lab(40% 56.6 39);
2064      }
2065    "#},
2066      Browsers {
2067        chrome: Some(8 << 16),
2068        safari: Some(14 << 16),
2069        ..Browsers::default()
2070      },
2071    );
2072
2073    prefix_test(
2074      r#"
2075      .foo {
2076        border-inline-start: 2px solid lab(40% 56.6 39);
2077      }
2078    "#,
2079      indoc! {r#"
2080      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
2081        border-left: 2px solid #b32323;
2082        border-left: 2px solid lab(40% 56.6 39);
2083      }
2084
2085      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
2086        border-left: 2px solid #b32323;
2087        border-left: 2px solid lab(40% 56.6 39);
2088      }
2089
2090      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
2091        border-right: 2px solid #b32323;
2092        border-right: 2px solid lab(40% 56.6 39);
2093      }
2094
2095      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
2096        border-right: 2px solid #b32323;
2097        border-right: 2px solid lab(40% 56.6 39);
2098      }
2099    "#},
2100      Browsers {
2101        safari: Some(8 << 16),
2102        ..Browsers::default()
2103      },
2104    );
2105
2106    prefix_test(
2107      r#"
2108      .foo {
2109        border-inline-end: 2px solid lab(40% 56.6 39);
2110      }
2111    "#,
2112      indoc! {r#"
2113      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
2114        border-right: 2px solid #b32323;
2115        border-right: 2px solid lab(40% 56.6 39);
2116      }
2117
2118      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
2119        border-right: 2px solid #b32323;
2120        border-right: 2px solid lab(40% 56.6 39);
2121      }
2122
2123      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
2124        border-left: 2px solid #b32323;
2125        border-left: 2px solid lab(40% 56.6 39);
2126      }
2127
2128      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
2129        border-left: 2px solid #b32323;
2130        border-left: 2px solid lab(40% 56.6 39);
2131      }
2132    "#},
2133      Browsers {
2134        safari: Some(8 << 16),
2135        ..Browsers::default()
2136      },
2137    );
2138
2139    prefix_test(
2140      r#"
2141      .foo {
2142        border-inline-end: var(--border-width) solid lab(40% 56.6 39);
2143      }
2144    "#,
2145      indoc! {r#"
2146      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
2147        border-right: var(--border-width) solid #b32323;
2148      }
2149
2150      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
2151        border-right: var(--border-width) solid #b32323;
2152      }
2153
2154      @supports (color: lab(0% 0 0)) {
2155        .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
2156          border-right: var(--border-width) solid lab(40% 56.6 39);
2157        }
2158      }
2159
2160      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
2161        border-left: var(--border-width) solid #b32323;
2162      }
2163
2164      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
2165        border-left: var(--border-width) solid #b32323;
2166      }
2167
2168      @supports (color: lab(0% 0 0)) {
2169        .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
2170          border-left: var(--border-width) solid lab(40% 56.6 39);
2171        }
2172      }
2173    "#},
2174      Browsers {
2175        safari: Some(8 << 16),
2176        ..Browsers::default()
2177      },
2178    );
2179
2180    prefix_test(
2181      r#"
2182      .foo {
2183        border-inline-start: 2px solid red;
2184        border-inline-end: 2px solid red;
2185      }
2186    "#,
2187      indoc! {r#"
2188      .foo {
2189        border-inline-start: 2px solid red;
2190        border-inline-end: 2px solid red;
2191      }
2192    "#
2193      },
2194      Browsers {
2195        safari: Some(13 << 16),
2196        ..Browsers::default()
2197      },
2198    );
2199
2200    prefix_test(
2201      r#"
2202      .foo {
2203        border-inline-start: 2px solid red;
2204        border-inline-end: 2px solid red;
2205      }
2206    "#,
2207      indoc! {r#"
2208      .foo {
2209        border-inline: 2px solid red;
2210      }
2211    "#
2212      },
2213      Browsers {
2214        safari: Some(15 << 16),
2215        ..Browsers::default()
2216      },
2217    );
2218
2219    prefix_test(
2220      r#"
2221      .foo {
2222        border-width: 22px;
2223        border-width: max(2cqw, 22px);
2224      }
2225    "#,
2226      indoc! {r#"
2227      .foo {
2228        border-width: 22px;
2229        border-width: max(2cqw, 22px);
2230      }
2231    "#
2232      },
2233      Browsers {
2234        safari: Some(14 << 16),
2235        ..Browsers::default()
2236      },
2237    );
2238    prefix_test(
2239      r#"
2240      .foo {
2241        border-width: 22px;
2242        border-width: max(2cqw, 22px);
2243      }
2244    "#,
2245      indoc! {r#"
2246      .foo {
2247        border-width: max(2cqw, 22px);
2248      }
2249    "#
2250      },
2251      Browsers {
2252        safari: Some(16 << 16),
2253        ..Browsers::default()
2254      },
2255    );
2256    prefix_test(
2257      r#"
2258      .foo {
2259        border-color: #4263eb;
2260        border-color: color(display-p3 0 .5 1);
2261      }
2262    "#,
2263      indoc! {r#"
2264      .foo {
2265        border-color: #4263eb;
2266        border-color: color(display-p3 0 .5 1);
2267      }
2268    "#
2269      },
2270      Browsers {
2271        chrome: Some(99 << 16),
2272        ..Browsers::default()
2273      },
2274    );
2275    prefix_test(
2276      r#"
2277      .foo {
2278        border-color: #4263eb;
2279        border-color: color(display-p3 0 .5 1);
2280      }
2281    "#,
2282      indoc! {r#"
2283      .foo {
2284        border-color: color(display-p3 0 .5 1);
2285      }
2286    "#
2287      },
2288      Browsers {
2289        safari: Some(16 << 16),
2290        ..Browsers::default()
2291      },
2292    );
2293    prefix_test(
2294      r#"
2295      .foo {
2296        border: 1px solid #4263eb;
2297        border-color: color(display-p3 0 .5 1);
2298      }
2299    "#,
2300      indoc! {r#"
2301      .foo {
2302        border: 1px solid #4263eb;
2303        border-color: color(display-p3 0 .5 1);
2304      }
2305    "#
2306      },
2307      Browsers {
2308        chrome: Some(99 << 16),
2309        ..Browsers::default()
2310      },
2311    );
2312    prefix_test(
2313      r#"
2314      .foo {
2315        border: 1px solid #4263eb;
2316        border-color: color(display-p3 0 .5 1);
2317      }
2318    "#,
2319      indoc! {r#"
2320      .foo {
2321        border: 1px solid color(display-p3 0 .5 1);
2322      }
2323    "#
2324      },
2325      Browsers {
2326        safari: Some(16 << 16),
2327        ..Browsers::default()
2328      },
2329    );
2330    prefix_test(
2331      r#"
2332      .foo {
2333        border-color: var(--fallback);
2334        border-color: color(display-p3 0 .5 1);
2335      }
2336    "#,
2337      indoc! {r#"
2338      .foo {
2339        border-color: var(--fallback);
2340        border-color: color(display-p3 0 .5 1);
2341      }
2342    "#
2343      },
2344      Browsers {
2345        chrome: Some(99 << 16),
2346        ..Browsers::default()
2347      },
2348    );
2349  }
2350
2351  #[test]
2352  pub fn test_border_image() {
2353    minify_test(
2354      r#"
2355      .foo {
2356        border-image: none;
2357      }
2358      "#,
2359      ".foo{border-image:none}",
2360    );
2361
2362    test(
2363      r#"
2364      .foo {
2365        border-image: none;
2366      }
2367      "#,
2368      indoc! {r#"
2369      .foo {
2370        border-image: none;
2371      }
2372      "#},
2373    );
2374
2375    minify_test(
2376      r#"
2377      .foo {
2378        border-image: none 100% / 1 / 0 stretch;
2379      }
2380      "#,
2381      ".foo{border-image:none}",
2382    );
2383
2384    minify_test(
2385      r#"
2386      .foo {
2387        border-image-source: none;
2388        border-image-slice: 100%;
2389        border-image-width: 1;
2390        border-image-outset: 0;
2391        border-image-repeat: stretch;
2392      }
2393      "#,
2394      ".foo{border-image:none}",
2395    );
2396
2397    minify_test(
2398      r#"
2399      .foo {
2400        -webkit-border-image: none;
2401        border-image: none !important;
2402      }
2403      "#,
2404      ".foo{-webkit-border-image:none;border-image:none!important}",
2405    );
2406
2407    minify_test(
2408      r#"
2409      .foo {
2410        border-image: url(border.png) 1;
2411      }
2412      .foo.active {
2413        border-image: none;
2414      }
2415      "#,
2416      ".foo{border-image:url(border.png) 1}.foo.active{border-image:none}",
2417    );
2418
2419    property_range_test(
2420      &[
2421        "border-image-outset",
2422        "mask-border-outset",
2423        "-webkit-mask-box-image-outset",
2424      ],
2425      &[
2426        ("-1px", None),
2427        ("calc(1px - 2px)", Some("0")),
2428        ("calc(-1px + 2px)", Some("1px")),
2429        ("-1", None),
2430        ("calc(1 - 2)", Some("0")),
2431        ("calc(-1 + 2)", Some("1")),
2432      ],
2433    );
2434    property_range_test(
2435      &["border-image-width", "mask-border-width"],
2436      &[
2437        ("-1px", None),
2438        ("calc(1px - 2px)", Some("0")),
2439        ("calc(-1px + 2px)", Some("1px")),
2440        ("-1%", None),
2441        ("calc(1em - 2px)", Some("calc(1em - 2px)")),
2442        ("calc(-1%)", Some("calc(-1%)")),
2443        ("-1", None),
2444        ("calc(1 - 2)", Some("0")),
2445        ("calc(-1 + 2)", Some("1")),
2446        ("auto", Some("auto")),
2447      ],
2448    );
2449    property_range_test(
2450      &["border-image-slice", "mask-border-slice"],
2451      &[
2452        ("-1", None),
2453        ("calc(1 - 2)", Some("0")),
2454        ("calc(-1 + 2)", Some("1")),
2455        ("-1%", None),
2456      ],
2457    );
2458    test(
2459      r#"
2460      .foo {
2461        border-image: url(test.png) 60;
2462      }
2463    "#,
2464      indoc! {r#"
2465      .foo {
2466        border-image: url("test.png") 60;
2467      }
2468    "#
2469      },
2470    );
2471
2472    test(
2473      r#"
2474      .foo {
2475        border-image: url(test.png) 60;
2476        border-image-source: url(foo.png);
2477      }
2478    "#,
2479      indoc! {r#"
2480      .foo {
2481        border-image: url("foo.png") 60;
2482      }
2483    "#
2484      },
2485    );
2486
2487    test(
2488      r#"
2489      .foo {
2490        border-image-source: url(foo.png);
2491        border-image-slice: 10 40 10 40 fill;
2492        border-image-width: 10px;
2493        border-image-outset: 0;
2494        border-image-repeat: round round;
2495      }
2496    "#,
2497      indoc! {r#"
2498      .foo {
2499        border-image: url("foo.png") 10 40 fill / 10px round;
2500      }
2501    "#
2502      },
2503    );
2504
2505    test(
2506      r#"
2507      .foo {
2508        border-image: url(foo.png) 60;
2509        border-image-source: var(--test);
2510      }
2511    "#,
2512      indoc! {r#"
2513      .foo {
2514        border-image: url("foo.png") 60;
2515        border-image-source: var(--test);
2516      }
2517    "#
2518      },
2519    );
2520
2521    test(
2522      r#"
2523      .foo {
2524        -webkit-border-image: url("test.png") 60;
2525      }
2526    "#,
2527      indoc! {r#"
2528      .foo {
2529        -webkit-border-image: url("test.png") 60;
2530      }
2531    "#
2532      },
2533    );
2534
2535    test(
2536      r#"
2537      .foo {
2538        -webkit-border-image: url("test.png") 60;
2539        border-image: url("test.png") 60;
2540      }
2541    "#,
2542      indoc! {r#"
2543      .foo {
2544        -webkit-border-image: url("test.png") 60;
2545        border-image: url("test.png") 60;
2546      }
2547    "#
2548      },
2549    );
2550
2551    test(
2552      r#"
2553      .foo {
2554        -webkit-border-image: url("test.png") 60;
2555        border-image-source: url(foo.png);
2556      }
2557    "#,
2558      indoc! {r#"
2559      .foo {
2560        -webkit-border-image: url("test.png") 60;
2561        border-image-source: url("foo.png");
2562      }
2563    "#
2564      },
2565    );
2566
2567    test(
2568      r#"
2569      .foo {
2570        border: 1px solid red;
2571        border-image: url(test.png) 60;
2572      }
2573    "#,
2574      indoc! {r#"
2575      .foo {
2576        border: 1px solid red;
2577        border-image: url("test.png") 60;
2578      }
2579    "#
2580      },
2581    );
2582
2583    test(
2584      r#"
2585      .foo {
2586        border-image: url(test.png) 60;
2587        border: 1px solid red;
2588      }
2589    "#,
2590      indoc! {r#"
2591      .foo {
2592        border: 1px solid red;
2593      }
2594    "#
2595      },
2596    );
2597
2598    test(
2599      r#"
2600      .foo {
2601        border: 1px solid red;
2602        border-image: var(--border-image);
2603      }
2604    "#,
2605      indoc! {r#"
2606      .foo {
2607        border: 1px solid red;
2608        border-image: var(--border-image);
2609      }
2610    "#
2611      },
2612    );
2613
2614    prefix_test(
2615      r#"
2616      .foo {
2617        border-image: url("test.png") 60;
2618      }
2619    "#,
2620      indoc! {r#"
2621      .foo {
2622        -webkit-border-image: url("test.png") 60;
2623        -moz-border-image: url("test.png") 60;
2624        -o-border-image: url("test.png") 60;
2625        border-image: url("test.png") 60;
2626      }
2627    "#
2628      },
2629      Browsers {
2630        safari: Some(4 << 16),
2631        firefox: Some(4 << 16),
2632        opera: Some(12 << 16),
2633        ..Browsers::default()
2634      },
2635    );
2636
2637    prefix_test(
2638      r#"
2639      .foo {
2640        border-image: url(foo.png) 10 40 fill / 10px round;
2641      }
2642    "#,
2643      indoc! {r#"
2644      .foo {
2645        border-image: url("foo.png") 10 40 fill / 10px round;
2646      }
2647    "#
2648      },
2649      Browsers {
2650        safari: Some(4 << 16),
2651        firefox: Some(4 << 16),
2652        opera: Some(12 << 16),
2653        ..Browsers::default()
2654      },
2655    );
2656
2657    prefix_test(
2658      r#"
2659      .foo {
2660        border-image: var(--test) 60;
2661      }
2662    "#,
2663      indoc! {r#"
2664      .foo {
2665        -webkit-border-image: var(--test) 60;
2666        -moz-border-image: var(--test) 60;
2667        -o-border-image: var(--test) 60;
2668        border-image: var(--test) 60;
2669      }
2670    "#
2671      },
2672      Browsers {
2673        safari: Some(4 << 16),
2674        firefox: Some(4 << 16),
2675        opera: Some(12 << 16),
2676        ..Browsers::default()
2677      },
2678    );
2679
2680    prefix_test(
2681      r#"
2682      .foo {
2683        -webkit-border-image: url(foo.png) 60;
2684        -moz-border-image: url(foo.png) 60;
2685        -o-border-image: url(foo.png) 60;
2686        border-image: url(foo.png) 60;
2687      }
2688    "#,
2689      indoc! {r#"
2690      .foo {
2691        border-image: url("foo.png") 60;
2692      }
2693    "#
2694      },
2695      Browsers {
2696        chrome: Some(15 << 16),
2697        ..Browsers::default()
2698      },
2699    );
2700
2701    prefix_test(
2702      r#"
2703      .foo {
2704        border-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 60;
2705      }
2706    "#,
2707      indoc! {r#"
2708      .foo {
2709        -webkit-border-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ff0b0c), to(#766eff)) 60;
2710        -webkit-border-image: -webkit-linear-gradient(top, #ff0b0c, #766eff) 60;
2711        border-image: linear-gradient(#ff0b0c, #766eff) 60;
2712        border-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 60;
2713      }
2714    "#
2715      },
2716      Browsers {
2717        chrome: Some(8 << 16),
2718        ..Browsers::default()
2719      },
2720    );
2721
2722    prefix_test(
2723      r#"
2724      .foo {
2725        border-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 60;
2726      }
2727    "#,
2728      indoc! {r#"
2729      .foo {
2730        -webkit-border-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ff0b0c), to(#766eff)) 60;
2731        -webkit-border-image: -webkit-linear-gradient(top, #ff0b0c, #766eff) 60;
2732        -moz-border-image: -moz-linear-gradient(top, #ff0b0c, #766eff) 60;
2733        border-image: linear-gradient(#ff0b0c, #766eff) 60;
2734        border-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 60;
2735      }
2736    "#
2737      },
2738      Browsers {
2739        chrome: Some(8 << 16),
2740        firefox: Some(4 << 16),
2741        ..Browsers::default()
2742      },
2743    );
2744
2745    prefix_test(
2746      r#"
2747      .foo {
2748        border-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 60;
2749      }
2750    "#,
2751      indoc! {r#"
2752      .foo {
2753        border-image: -webkit-linear-gradient(top, #ff0b0c, #766eff) 60;
2754        border-image: -moz-linear-gradient(top, #ff0b0c, #766eff) 60;
2755        border-image: linear-gradient(#ff0b0c, #766eff) 60;
2756        border-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 60;
2757      }
2758    "#
2759      },
2760      Browsers {
2761        chrome: Some(15 << 16),
2762        firefox: Some(15 << 16),
2763        ..Browsers::default()
2764      },
2765    );
2766
2767    prefix_test(
2768      r#"
2769      .foo {
2770        border-image-source: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
2771      }
2772    "#,
2773      indoc! {r#"
2774      .foo {
2775        border-image-source: -webkit-linear-gradient(top, #ff0b0c, #766eff);
2776        border-image-source: linear-gradient(#ff0b0c, #766eff);
2777        border-image-source: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
2778      }
2779    "#
2780      },
2781      Browsers {
2782        chrome: Some(15 << 16),
2783        ..Browsers::default()
2784      },
2785    );
2786
2787    prefix_test(
2788      r#"
2789      .foo {
2790        border-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) var(--foo);
2791      }
2792    "#,
2793      indoc! {r#"
2794      .foo {
2795        border-image: linear-gradient(#ff0b0c, #766eff) var(--foo);
2796      }
2797
2798      @supports (color: lab(0% 0 0)) {
2799        .foo {
2800          border-image: linear-gradient(lab(56.208% 94.4644 98.8928), lab(51% 70.4544 -115.586)) var(--foo);
2801        }
2802      }
2803    "#
2804      },
2805      Browsers {
2806        chrome: Some(90 << 16),
2807        ..Browsers::default()
2808      },
2809    );
2810
2811    prefix_test(
2812      r#"
2813      .foo {
2814        border-image-source: linear-gradient(red, green);
2815        border-image-source: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
2816      }
2817    "#,
2818      indoc! {r#"
2819      .foo {
2820        border-image-source: linear-gradient(red, green);
2821        border-image-source: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
2822      }
2823    "#
2824      },
2825      Browsers {
2826        chrome: Some(95 << 16),
2827        ..Browsers::default()
2828      },
2829    );
2830
2831    prefix_test(
2832      r#"
2833      .foo {
2834        border-image-source: linear-gradient(red, green);
2835        border-image-source: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
2836      }
2837    "#,
2838      indoc! {r#"
2839      .foo {
2840        border-image-source: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
2841      }
2842    "#
2843      },
2844      Browsers {
2845        chrome: Some(112 << 16),
2846        ..Browsers::default()
2847      },
2848    );
2849
2850    prefix_test(
2851      r#"
2852      .foo {
2853        border-image: linear-gradient(red, green);
2854        border-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
2855      }
2856    "#,
2857      indoc! {r#"
2858      .foo {
2859        border-image: linear-gradient(red, green);
2860        border-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
2861      }
2862    "#
2863      },
2864      Browsers {
2865        chrome: Some(95 << 16),
2866        ..Browsers::default()
2867      },
2868    );
2869
2870    prefix_test(
2871      r#"
2872      .foo {
2873        border-image: var(--fallback);
2874        border-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
2875      }
2876    "#,
2877      indoc! {r#"
2878      .foo {
2879        border-image: var(--fallback);
2880        border-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
2881      }
2882    "#
2883      },
2884      Browsers {
2885        chrome: Some(95 << 16),
2886        ..Browsers::default()
2887      },
2888    );
2889
2890    prefix_test(
2891      r#"
2892      .foo {
2893        border-image: url("fallback.png") 10 40 fill / 10px;
2894        border-image: url("main.png") 10 40 fill / 10px space;
2895      }
2896    "#,
2897      indoc! {r#"
2898      .foo {
2899        border-image: url("fallback.png") 10 40 fill / 10px;
2900        border-image: url("main.png") 10 40 fill / 10px space;
2901      }
2902    "#
2903      },
2904      Browsers {
2905        chrome: Some(50 << 16),
2906        ..Browsers::default()
2907      },
2908    );
2909
2910    prefix_test(
2911      r#"
2912      .foo {
2913        border-image: url("fallback.png") 10 40 fill / 10px;
2914        border-image: url("main.png") 10 40 fill / 10px space;
2915      }
2916    "#,
2917      indoc! {r#"
2918      .foo {
2919        border-image: url("main.png") 10 40 fill / 10px space;
2920      }
2921    "#
2922      },
2923      Browsers {
2924        chrome: Some(56 << 16),
2925        ..Browsers::default()
2926      },
2927    );
2928
2929    minify_test(".foo { border: none green }", ".foo{border:green}");
2930  }
2931
2932  #[test]
2933  pub fn test_border_radius() {
2934    property_range_test(
2935      &["border-radius", "border-top-left-radius", "border-start-start-radius"],
2936      &[
2937        ("-1px", None),
2938        ("calc(1px - 2px)", Some("0")),
2939        ("calc(-1px + 2px)", Some("1px")),
2940        ("-1%", None),
2941        ("calc(1em - 2px)", Some("calc(1em - 2px)")),
2942        ("calc(-1%)", Some("calc(-1%)")),
2943      ],
2944    );
2945    test(
2946      r#"
2947      .foo {
2948        border-radius: 10px 100px 10px 100px;
2949      }
2950    "#,
2951      indoc! {r#"
2952      .foo {
2953        border-radius: 10px 100px;
2954      }
2955    "#
2956      },
2957    );
2958
2959    test(
2960      r#"
2961      .foo {
2962        border-radius: 10px 100px 10px 100px / 120px 120px;
2963      }
2964    "#,
2965      indoc! {r#"
2966      .foo {
2967        border-radius: 10px 100px / 120px;
2968      }
2969    "#
2970      },
2971    );
2972
2973    test(
2974      r#"
2975      .foo {
2976        border-top-left-radius: 10px 120px;
2977        border-top-right-radius: 100px 120px;
2978        border-bottom-right-radius: 100px 120px;
2979        border-bottom-left-radius: 10px 120px;
2980      }
2981    "#,
2982      indoc! {r#"
2983      .foo {
2984        border-radius: 10px 100px 100px 10px / 120px;
2985      }
2986    "#
2987      },
2988    );
2989
2990    test(
2991      r#"
2992      .foo {
2993        border-top-left-radius: 4px 2px;
2994        border-top-right-radius: 3px 4px;
2995        border-bottom-right-radius: 6px 2px;
2996        border-bottom-left-radius: 3px 4px;
2997      }
2998    "#,
2999      indoc! {r#"
3000      .foo {
3001        border-radius: 4px 3px 6px / 2px 4px;
3002      }
3003    "#
3004      },
3005    );
3006
3007    test(
3008      r#"
3009      .foo {
3010        border-top-left-radius: 1% 2%;
3011        border-top-right-radius: 3% 4%;
3012        border-bottom-right-radius: 5% 6%;
3013        border-bottom-left-radius: 7% 8%;
3014      }
3015    "#,
3016      indoc! {r#"
3017      .foo {
3018        border-radius: 1% 3% 5% 7% / 2% 4% 6% 8%;
3019      }
3020    "#
3021      },
3022    );
3023
3024    test(
3025      r#"
3026      .foo {
3027        border-radius: 10px 100px 10px 100px / 120px 120px;
3028        border-start-start-radius: 10px;
3029      }
3030    "#,
3031      indoc! {r#"
3032      .foo {
3033        border-radius: 10px 100px / 120px;
3034        border-start-start-radius: 10px;
3035      }
3036    "#
3037      },
3038    );
3039
3040    test(
3041      r#"
3042      .foo {
3043        border-start-start-radius: 10px;
3044        border-radius: 10px 100px 10px 100px / 120px 120px;
3045      }
3046    "#,
3047      indoc! {r#"
3048      .foo {
3049        border-radius: 10px 100px / 120px;
3050      }
3051    "#
3052      },
3053    );
3054
3055    test(
3056      r#"
3057      .foo {
3058        border-top-left-radius: 10px 120px;
3059        border-top-right-radius: 100px 120px;
3060        border-start-start-radius: 10px;
3061        border-bottom-right-radius: 100px 120px;
3062        border-bottom-left-radius: 10px 120px;
3063      }
3064    "#,
3065      indoc! {r#"
3066      .foo {
3067        border-top-left-radius: 10px 120px;
3068        border-top-right-radius: 100px 120px;
3069        border-start-start-radius: 10px;
3070        border-bottom-right-radius: 100px 120px;
3071        border-bottom-left-radius: 10px 120px;
3072      }
3073    "#
3074      },
3075    );
3076
3077    test(
3078      r#"
3079      .foo {
3080        border-radius: 10px;
3081        border-top-left-radius: 20px;
3082      }
3083    "#,
3084      indoc! {r#"
3085      .foo {
3086        border-radius: 20px 10px 10px;
3087      }
3088    "#
3089      },
3090    );
3091
3092    test(
3093      r#"
3094      .foo {
3095        border-radius: 10px;
3096        border-top-left-radius: var(--test);
3097      }
3098    "#,
3099      indoc! {r#"
3100      .foo {
3101        border-radius: 10px;
3102        border-top-left-radius: var(--test);
3103      }
3104    "#
3105      },
3106    );
3107
3108    test(
3109      r#"
3110      .foo {
3111        -webkit-border-radius: 10px 100px 10px 100px;
3112        -moz-border-radius: 10px 100px 10px 100px;
3113        border-radius: 10px 100px 10px 100px;
3114      }
3115    "#,
3116      indoc! {r#"
3117      .foo {
3118        -webkit-border-radius: 10px 100px;
3119        -moz-border-radius: 10px 100px;
3120        border-radius: 10px 100px;
3121      }
3122    "#
3123      },
3124    );
3125
3126    test(
3127      r#"
3128      .foo {
3129        -webkit-border-radius: 10px 100px 10px 100px;
3130        -moz-border-radius: 20px;
3131        border-radius: 30px;
3132      }
3133    "#,
3134      indoc! {r#"
3135      .foo {
3136        -webkit-border-radius: 10px 100px;
3137        -moz-border-radius: 20px;
3138        border-radius: 30px;
3139      }
3140    "#
3141      },
3142    );
3143
3144    test(
3145      r#"
3146      .foo {
3147        -webkit-border-top-left-radius: 10px;
3148        -moz-border-top-left-radius: 10px;
3149        border-top-left-radius: 10px;
3150      }
3151    "#,
3152      indoc! {r#"
3153      .foo {
3154        -webkit-border-top-left-radius: 10px;
3155        -moz-border-top-left-radius: 10px;
3156        border-top-left-radius: 10px;
3157      }
3158    "#
3159      },
3160    );
3161
3162    prefix_test(
3163      r#"
3164      .foo {
3165        border-radius: 30px;
3166      }
3167    "#,
3168      indoc! {r#"
3169      .foo {
3170        -webkit-border-radius: 30px;
3171        -moz-border-radius: 30px;
3172        border-radius: 30px;
3173      }
3174    "#
3175      },
3176      Browsers {
3177        safari: Some(4 << 16),
3178        firefox: Some(3 << 16),
3179        ..Browsers::default()
3180      },
3181    );
3182
3183    prefix_test(
3184      r#"
3185      .foo {
3186        border-top-left-radius: 30px;
3187      }
3188    "#,
3189      indoc! {r#"
3190      .foo {
3191        -webkit-border-top-left-radius: 30px;
3192        -moz-border-top-left-radius: 30px;
3193        border-top-left-radius: 30px;
3194      }
3195    "#
3196      },
3197      Browsers {
3198        safari: Some(4 << 16),
3199        firefox: Some(3 << 16),
3200        ..Browsers::default()
3201      },
3202    );
3203
3204    prefix_test(
3205      r#"
3206      .foo {
3207        -webkit-border-radius: 30px;
3208        -moz-border-radius: 30px;
3209        border-radius: 30px;
3210      }
3211    "#,
3212      indoc! {r#"
3213      .foo {
3214        border-radius: 30px;
3215      }
3216    "#
3217      },
3218      Browsers {
3219        safari: Some(14 << 16),
3220        firefox: Some(46 << 16),
3221        ..Browsers::default()
3222      },
3223    );
3224
3225    prefix_test(
3226      r#"
3227      .foo {
3228        -webkit-border-top-left-radius: 30px;
3229        -moz-border-top-left-radius: 30px;
3230        border-top-left-radius: 30px;
3231      }
3232    "#,
3233      indoc! {r#"
3234      .foo {
3235        border-top-left-radius: 30px;
3236      }
3237    "#
3238      },
3239      Browsers {
3240        safari: Some(14 << 16),
3241        firefox: Some(46 << 16),
3242        ..Browsers::default()
3243      },
3244    );
3245
3246    prefix_test(
3247      r#"
3248      .foo {
3249        -webkit-border-radius: 30px;
3250        -moz-border-radius: 30px;
3251      }
3252    "#,
3253      indoc! {r#"
3254      .foo {
3255        -webkit-border-radius: 30px;
3256        -moz-border-radius: 30px;
3257      }
3258    "#
3259      },
3260      Browsers {
3261        safari: Some(14 << 16),
3262        firefox: Some(46 << 16),
3263        ..Browsers::default()
3264      },
3265    );
3266
3267    prefix_test(
3268      r#"
3269      .foo {
3270        -webkit-border-top-left-radius: 30px;
3271        -moz-border-top-right-radius: 30px;
3272        border-bottom-right-radius: 30px;
3273        border-bottom-left-radius: 30px;
3274      }
3275    "#,
3276      indoc! {r#"
3277      .foo {
3278        -webkit-border-top-left-radius: 30px;
3279        -moz-border-top-right-radius: 30px;
3280        border-bottom-right-radius: 30px;
3281        border-bottom-left-radius: 30px;
3282      }
3283    "#
3284      },
3285      Browsers {
3286        safari: Some(14 << 16),
3287        firefox: Some(46 << 16),
3288        ..Browsers::default()
3289      },
3290    );
3291
3292    prefix_test(
3293      r#"
3294      .foo {
3295        border-radius: var(--test);
3296      }
3297    "#,
3298      indoc! {r#"
3299      .foo {
3300        -webkit-border-radius: var(--test);
3301        -moz-border-radius: var(--test);
3302        border-radius: var(--test);
3303      }
3304    "#
3305      },
3306      Browsers {
3307        safari: Some(4 << 16),
3308        firefox: Some(3 << 16),
3309        ..Browsers::default()
3310      },
3311    );
3312
3313    prefix_test(
3314      r#"
3315      .foo {
3316        border-start-start-radius: 5px;
3317      }
3318    "#,
3319      indoc! {r#"
3320      .foo:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
3321        border-top-left-radius: 5px;
3322      }
3323
3324      .foo:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
3325        border-top-right-radius: 5px;
3326      }
3327    "#
3328      },
3329      Browsers {
3330        safari: Some(12 << 16),
3331        ..Browsers::default()
3332      },
3333    );
3334
3335    prefix_test(
3336      r#"
3337      .foo {
3338        border-start-start-radius: 5px;
3339        border-start-end-radius: 10px;
3340      }
3341    "#,
3342      indoc! {r#"
3343      .foo:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
3344        border-top-left-radius: 5px;
3345        border-top-right-radius: 10px;
3346      }
3347
3348      .foo:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
3349        border-top-left-radius: 10px;
3350        border-top-right-radius: 5px;
3351      }
3352    "#
3353      },
3354      Browsers {
3355        safari: Some(12 << 16),
3356        ..Browsers::default()
3357      },
3358    );
3359
3360    prefix_test(
3361      r#"
3362      .foo {
3363        border-end-end-radius: 10px;
3364        border-end-start-radius: 5px;
3365      }
3366    "#,
3367      indoc! {r#"
3368      .foo:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
3369        border-bottom-right-radius: 10px;
3370        border-bottom-left-radius: 5px;
3371      }
3372
3373      .foo:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
3374        border-bottom-right-radius: 5px;
3375        border-bottom-left-radius: 10px;
3376      }
3377    "#
3378      },
3379      Browsers {
3380        safari: Some(12 << 16),
3381        ..Browsers::default()
3382      },
3383    );
3384
3385    prefix_test(
3386      r#"
3387      .foo {
3388        border-start-start-radius: var(--radius);
3389      }
3390    "#,
3391      indoc! {r#"
3392      .foo:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
3393        border-top-left-radius: var(--radius);
3394      }
3395
3396      .foo:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
3397        border-top-right-radius: var(--radius);
3398      }
3399    "#
3400      },
3401      Browsers {
3402        safari: Some(12 << 16),
3403        ..Browsers::default()
3404      },
3405    );
3406
3407    prefix_test(
3408      r#"
3409      .foo {
3410        border-start-start-radius: var(--start);
3411        border-start-end-radius: var(--end);
3412      }
3413    "#,
3414      indoc! {r#"
3415      .foo:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
3416        border-top-left-radius: var(--start);
3417        border-top-right-radius: var(--end);
3418      }
3419
3420      .foo:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
3421        border-top-right-radius: var(--start);
3422        border-top-left-radius: var(--end);
3423      }
3424    "#
3425      },
3426      Browsers {
3427        safari: Some(12 << 16),
3428        ..Browsers::default()
3429      },
3430    );
3431  }
3432
3433  #[test]
3434  pub fn test_outline() {
3435    test(
3436      r#"
3437      .foo {
3438        outline-width: 2px;
3439        outline-style: solid;
3440        outline-color: blue;
3441      }
3442    "#,
3443      indoc! {r#"
3444      .foo {
3445        outline: 2px solid #00f;
3446      }
3447    "#
3448      },
3449    );
3450
3451    test(
3452      r#"
3453      .foo {
3454        outline: 2px solid blue;
3455      }
3456    "#,
3457      indoc! {r#"
3458      .foo {
3459        outline: 2px solid #00f;
3460      }
3461    "#
3462      },
3463    );
3464
3465    test(
3466      r#"
3467      .foo {
3468        outline: 2px solid red;
3469        outline-color: blue;
3470      }
3471    "#,
3472      indoc! {r#"
3473      .foo {
3474        outline: 2px solid #00f;
3475      }
3476    "#
3477      },
3478    );
3479
3480    test(
3481      r#"
3482      .foo {
3483        outline: 2px solid yellow;
3484        outline-color: var(--color);
3485      }
3486    "#,
3487      indoc! {r#"
3488      .foo {
3489        outline: 2px solid #ff0;
3490        outline-color: var(--color);
3491      }
3492    "#
3493      },
3494    );
3495
3496    prefix_test(
3497      ".foo { outline-color: lab(40% 56.6 39) }",
3498      indoc! { r#"
3499        .foo {
3500          outline-color: #b32323;
3501          outline-color: lab(40% 56.6 39);
3502        }
3503      "#},
3504      Browsers {
3505        chrome: Some(90 << 16),
3506        ..Browsers::default()
3507      },
3508    );
3509
3510    prefix_test(
3511      ".foo { outline: 2px solid lab(40% 56.6 39) }",
3512      indoc! { r#"
3513        .foo {
3514          outline: 2px solid #b32323;
3515          outline: 2px solid lab(40% 56.6 39);
3516        }
3517      "#},
3518      Browsers {
3519        chrome: Some(90 << 16),
3520        ..Browsers::default()
3521      },
3522    );
3523
3524    prefix_test(
3525      ".foo { outline: var(--width) solid lab(40% 56.6 39) }",
3526      indoc! { r#"
3527        .foo {
3528          outline: var(--width) solid #b32323;
3529        }
3530
3531        @supports (color: lab(0% 0 0)) {
3532          .foo {
3533            outline: var(--width) solid lab(40% 56.6 39);
3534          }
3535        }
3536      "#},
3537      Browsers {
3538        chrome: Some(90 << 16),
3539        ..Browsers::default()
3540      },
3541    );
3542  }
3543
3544  #[test]
3545  pub fn test_margin() {
3546    property_range_test(&["margin", "inset", "scroll-margin"], &[("-1px", Some("-1px"))]);
3547    test(
3548      r#"
3549      .foo {
3550        margin-left: 10px;
3551        margin-right: 10px;
3552        margin-top: 20px;
3553        margin-bottom: 20px;
3554      }
3555    "#,
3556      indoc! {r#"
3557      .foo {
3558        margin: 20px 10px;
3559      }
3560    "#
3561      },
3562    );
3563
3564    test(
3565      r#"
3566      .foo {
3567        margin-block-start: 15px;
3568        margin-block-end: 15px;
3569      }
3570    "#,
3571      indoc! {r#"
3572      .foo {
3573        margin-block: 15px;
3574      }
3575    "#
3576      },
3577    );
3578
3579    test(
3580      r#"
3581      .foo {
3582        margin-left: 10px;
3583        margin-right: 10px;
3584        margin-inline-start: 15px;
3585        margin-inline-end: 15px;
3586        margin-top: 20px;
3587        margin-bottom: 20px;
3588
3589      }
3590    "#,
3591      indoc! {r#"
3592      .foo {
3593        margin-left: 10px;
3594        margin-right: 10px;
3595        margin-inline: 15px;
3596        margin-top: 20px;
3597        margin-bottom: 20px;
3598      }
3599    "#
3600      },
3601    );
3602
3603    test(
3604      r#"
3605      .foo {
3606        margin: 10px;
3607        margin-top: 20px;
3608      }
3609    "#,
3610      indoc! {r#"
3611      .foo {
3612        margin: 20px 10px 10px;
3613      }
3614    "#
3615      },
3616    );
3617
3618    test(
3619      r#"
3620      .foo {
3621        margin: 10px;
3622        margin-top: var(--top);
3623      }
3624    "#,
3625      indoc! {r#"
3626      .foo {
3627        margin: 10px;
3628        margin-top: var(--top);
3629      }
3630    "#
3631      },
3632    );
3633
3634    prefix_test(
3635      r#"
3636      .foo {
3637        margin-inline-start: 2px;
3638      }
3639    "#,
3640      indoc! {r#"
3641      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
3642        margin-left: 2px;
3643      }
3644
3645      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
3646        margin-left: 2px;
3647      }
3648
3649      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
3650        margin-right: 2px;
3651      }
3652
3653      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
3654        margin-right: 2px;
3655      }
3656    "#
3657      },
3658      Browsers {
3659        safari: Some(8 << 16),
3660        ..Browsers::default()
3661      },
3662    );
3663
3664    prefix_test(
3665      r#"
3666      .foo {
3667        margin-inline-start: 2px;
3668        margin-inline-end: 4px;
3669      }
3670    "#,
3671      indoc! {r#"
3672      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
3673        margin-left: 2px;
3674        margin-right: 4px;
3675      }
3676
3677      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
3678        margin-left: 2px;
3679        margin-right: 4px;
3680      }
3681
3682      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
3683        margin-left: 4px;
3684        margin-right: 2px;
3685      }
3686
3687      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
3688        margin-left: 4px;
3689        margin-right: 2px;
3690      }
3691    "#
3692      },
3693      Browsers {
3694        safari: Some(8 << 16),
3695        ..Browsers::default()
3696      },
3697    );
3698
3699    prefix_test(
3700      r#"
3701      .foo {
3702        margin-inline: 2px;
3703      }
3704    "#,
3705      indoc! {r#"
3706      .foo {
3707        margin-left: 2px;
3708        margin-right: 2px;
3709      }
3710    "#
3711      },
3712      Browsers {
3713        safari: Some(8 << 16),
3714        ..Browsers::default()
3715      },
3716    );
3717
3718    prefix_test(
3719      r#"
3720      .foo {
3721        margin-block-start: 2px;
3722      }
3723    "#,
3724      indoc! {r#"
3725      .foo {
3726        margin-top: 2px;
3727      }
3728    "#
3729      },
3730      Browsers {
3731        safari: Some(8 << 16),
3732        ..Browsers::default()
3733      },
3734    );
3735
3736    prefix_test(
3737      r#"
3738      .foo {
3739        margin-block-end: 2px;
3740      }
3741    "#,
3742      indoc! {r#"
3743      .foo {
3744        margin-bottom: 2px;
3745      }
3746    "#
3747      },
3748      Browsers {
3749        safari: Some(8 << 16),
3750        ..Browsers::default()
3751      },
3752    );
3753
3754    prefix_test(
3755      r#"
3756      .foo {
3757        margin-inline-start: 2px;
3758        margin-inline-end: 2px;
3759      }
3760    "#,
3761      indoc! {r#"
3762      .foo {
3763        margin-inline-start: 2px;
3764        margin-inline-end: 2px;
3765      }
3766    "#
3767      },
3768      Browsers {
3769        safari: Some(13 << 16),
3770        ..Browsers::default()
3771      },
3772    );
3773
3774    prefix_test(
3775      r#"
3776      .foo {
3777        margin-inline: 2px;
3778      }
3779    "#,
3780      indoc! {r#"
3781      .foo {
3782        margin-inline-start: 2px;
3783        margin-inline-end: 2px;
3784      }
3785    "#
3786      },
3787      Browsers {
3788        safari: Some(13 << 16),
3789        ..Browsers::default()
3790      },
3791    );
3792
3793    prefix_test(
3794      r#"
3795      .foo {
3796        margin-inline-start: 2px;
3797        margin-inline-end: 2px;
3798      }
3799    "#,
3800      indoc! {r#"
3801      .foo {
3802        margin-inline: 2px;
3803      }
3804    "#
3805      },
3806      Browsers {
3807        safari: Some(15 << 16),
3808        ..Browsers::default()
3809      },
3810    );
3811
3812    prefix_test(
3813      r#"
3814      .foo {
3815        margin-inline: 2px;
3816      }
3817    "#,
3818      indoc! {r#"
3819      .foo {
3820        margin-inline: 2px;
3821      }
3822    "#
3823      },
3824      Browsers {
3825        safari: Some(15 << 16),
3826        ..Browsers::default()
3827      },
3828    );
3829  }
3830
3831  #[test]
3832  fn test_length() {
3833    use crate::values::length::{Length, LengthOrNumber, LengthPercentage, LengthPercentageOrAuto, LengthValue};
3834    use crate::values::number::NonNegative;
3835
3836    for source in ["-1px", "-1em", "-1vw", "-1"] {
3837      non_negative_test::<LengthValue>(source, None);
3838      non_negative_test::<Length>(source, None);
3839      non_negative_test::<LengthPercentage>(source, None);
3840      non_negative_test::<LengthPercentageOrAuto>(source, None);
3841      non_negative_test::<LengthOrNumber>(source, None);
3842      assert!(Length::parse_string(source).is_ok());
3843    }
3844    for source in ["0", "-0", "-0px"] {
3845      non_negative_test::<LengthValue>(source, Some("0"));
3846      non_negative_test::<Length>(source, Some("0"));
3847    }
3848    non_negative_test::<LengthValue>("2em", Some("2em"));
3849    non_negative_test::<LengthPercentage>("-1%", None);
3850    non_negative_test::<LengthPercentage>("10%", Some("10%"));
3851    non_negative_test::<LengthPercentageOrAuto>("auto", Some("auto"));
3852    non_negative_test::<LengthPercentageOrAuto>("-1%", None);
3853    non_negative_test::<LengthOrNumber>("2", Some("2"));
3854    non_negative_test::<LengthOrNumber>("2px", Some("2px"));
3855    non_negative_test::<LengthOrNumber>("calc(-2)", Some("0"));
3856    non_negative_test::<LengthOrNumber>("calc(-2px)", Some("0"));
3857
3858    // Backtracking a rejected range must leave the input available to another parser.
3859    let mut input = cssparser::ParserInput::new("-1px");
3860    let mut parser = cssparser::Parser::new(&mut input);
3861    assert!(parser.try_parse(NonNegative::<Length>::parse).is_err());
3862    assert_eq!(Length::parse(&mut parser).unwrap(), Length::px(-1.0));
3863
3864    for prop in &[
3865      "margin-right",
3866      "margin",
3867      "padding-right",
3868      "padding",
3869      "width",
3870      "height",
3871      "min-height",
3872      "max-height",
3873      "line-height",
3874      "border-radius",
3875    ] {
3876      prefix_test(
3877        &format!(
3878          r#"
3879        .foo {{
3880          {}: 22px;
3881          {}: max(4%, 22px);
3882        }}
3883      "#,
3884          prop, prop
3885        ),
3886        &format!(
3887          indoc! {r#"
3888        .foo {{
3889          {}: 22px;
3890          {}: max(4%, 22px);
3891        }}
3892      "#
3893          },
3894          prop, prop
3895        ),
3896        Browsers {
3897          safari: Some(10 << 16),
3898          ..Browsers::default()
3899        },
3900      );
3901
3902      prefix_test(
3903        &format!(
3904          r#"
3905        .foo {{
3906          {}: 22px;
3907          {}: max(4%, 22px);
3908        }}
3909      "#,
3910          prop, prop
3911        ),
3912        &format!(
3913          indoc! {r#"
3914        .foo {{
3915          {}: max(4%, 22px);
3916        }}
3917      "#
3918          },
3919          prop
3920        ),
3921        Browsers {
3922          safari: Some(14 << 16),
3923          ..Browsers::default()
3924        },
3925      );
3926
3927      prefix_test(
3928        &format!(
3929          r#"
3930        .foo {{
3931          {}: 22px;
3932          {}: max(2cqw, 22px);
3933        }}
3934      "#,
3935          prop, prop
3936        ),
3937        &format!(
3938          indoc! {r#"
3939        .foo {{
3940          {}: 22px;
3941          {}: max(2cqw, 22px);
3942        }}
3943      "#
3944          },
3945          prop, prop
3946        ),
3947        Browsers {
3948          safari: Some(14 << 16),
3949          ..Browsers::default()
3950        },
3951      );
3952      prefix_test(
3953        &format!(
3954          r#"
3955        .foo {{
3956          {}: 22px;
3957          {}: max(2cqw, 22px);
3958        }}
3959      "#,
3960          prop, prop
3961        ),
3962        &format!(
3963          indoc! {r#"
3964        .foo {{
3965          {}: max(2cqw, 22px);
3966        }}
3967      "#
3968          },
3969          prop
3970        ),
3971        Browsers {
3972          safari: Some(16 << 16),
3973          ..Browsers::default()
3974        },
3975      );
3976    }
3977  }
3978
3979  #[test]
3980  pub fn test_padding() {
3981    property_range_test(
3982      &[
3983        "padding",
3984        "padding-inline",
3985        "padding-block",
3986        "padding-top",
3987        "padding-inline-start",
3988      ],
3989      &[
3990        ("-1px", None),
3991        ("calc(1px - 2px)", Some("0")),
3992        ("calc(-1px + 2px)", Some("1px")),
3993        ("-1%", None),
3994        ("calc(1em - 2px)", Some("calc(1em - 2px)")),
3995        ("calc(-1%)", Some("calc(-1%)")),
3996        ("auto", None),
3997        ("1px -1px", None),
3998      ],
3999    );
4000    test(
4001      r#"
4002      .foo {
4003        padding-left: 10px;
4004        padding-right: 10px;
4005        padding-top: 20px;
4006        padding-bottom: 20px;
4007      }
4008    "#,
4009      indoc! {r#"
4010      .foo {
4011        padding: 20px 10px;
4012      }
4013    "#
4014      },
4015    );
4016
4017    test(
4018      r#"
4019      .foo {
4020        padding-block-start: 15px;
4021        padding-block-end: 15px;
4022      }
4023    "#,
4024      indoc! {r#"
4025      .foo {
4026        padding-block: 15px;
4027      }
4028    "#
4029      },
4030    );
4031
4032    test(
4033      r#"
4034      .foo {
4035        padding-left: 10px;
4036        padding-right: 10px;
4037        padding-inline-start: 15px;
4038        padding-inline-end: 15px;
4039        padding-top: 20px;
4040        padding-bottom: 20px;
4041
4042      }
4043    "#,
4044      indoc! {r#"
4045      .foo {
4046        padding-left: 10px;
4047        padding-right: 10px;
4048        padding-inline: 15px;
4049        padding-top: 20px;
4050        padding-bottom: 20px;
4051      }
4052    "#
4053      },
4054    );
4055
4056    prefix_test(
4057      r#"
4058      .foo {
4059        padding-inline-start: 2px;
4060      }
4061    "#,
4062      indoc! {r#"
4063      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
4064        padding-left: 2px;
4065      }
4066
4067      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
4068        padding-left: 2px;
4069      }
4070
4071      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
4072        padding-right: 2px;
4073      }
4074
4075      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
4076        padding-right: 2px;
4077      }
4078    "#
4079      },
4080      Browsers {
4081        safari: Some(8 << 16),
4082        ..Browsers::default()
4083      },
4084    );
4085
4086    prefix_test(
4087      r#"
4088      .foo {
4089        padding-inline-start: 2px;
4090        padding-inline-end: 4px;
4091      }
4092    "#,
4093      indoc! {r#"
4094      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
4095        padding-left: 2px;
4096        padding-right: 4px;
4097      }
4098
4099      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
4100        padding-left: 2px;
4101        padding-right: 4px;
4102      }
4103
4104      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
4105        padding-left: 4px;
4106        padding-right: 2px;
4107      }
4108
4109      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
4110        padding-left: 4px;
4111        padding-right: 2px;
4112      }
4113    "#
4114      },
4115      Browsers {
4116        safari: Some(8 << 16),
4117        ..Browsers::default()
4118      },
4119    );
4120
4121    prefix_test(
4122      r#"
4123      .foo {
4124        padding-inline-start: var(--padding);
4125      }
4126    "#,
4127      indoc! {r#"
4128      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
4129        padding-left: var(--padding);
4130      }
4131
4132      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
4133        padding-left: var(--padding);
4134      }
4135
4136      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
4137        padding-right: var(--padding);
4138      }
4139
4140      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
4141        padding-right: var(--padding);
4142      }
4143    "#
4144      },
4145      Browsers {
4146        safari: Some(8 << 16),
4147        ..Browsers::default()
4148      },
4149    );
4150
4151    prefix_test(
4152      r#"
4153      .foo {
4154        padding-inline: 2px;
4155      }
4156    "#,
4157      indoc! {r#"
4158      .foo {
4159        padding-left: 2px;
4160        padding-right: 2px;
4161      }
4162    "#
4163      },
4164      Browsers {
4165        safari: Some(8 << 16),
4166        ..Browsers::default()
4167      },
4168    );
4169
4170    prefix_test(
4171      r#"
4172      .foo {
4173        padding-block-start: 2px;
4174      }
4175    "#,
4176      indoc! {r#"
4177      .foo {
4178        padding-top: 2px;
4179      }
4180    "#
4181      },
4182      Browsers {
4183        safari: Some(8 << 16),
4184        ..Browsers::default()
4185      },
4186    );
4187
4188    prefix_test(
4189      r#"
4190      .foo {
4191        padding-block-end: 2px;
4192      }
4193    "#,
4194      indoc! {r#"
4195      .foo {
4196        padding-bottom: 2px;
4197      }
4198    "#
4199      },
4200      Browsers {
4201        safari: Some(8 << 16),
4202        ..Browsers::default()
4203      },
4204    );
4205
4206    prefix_test(
4207      r#"
4208      .foo {
4209        padding-top: 1px;
4210        padding-left: 2px;
4211        padding-bottom: 3px;
4212        padding-right: 4px;
4213      }
4214    "#,
4215      indoc! {r#"
4216      .foo {
4217        padding: 1px 4px 3px 2px;
4218      }
4219    "#},
4220      Browsers {
4221        safari: Some(8 << 16),
4222        ..Browsers::default()
4223      },
4224    );
4225
4226    prefix_test(
4227      r#"
4228      .foo {
4229        padding-inline-start: 2px;
4230        padding-inline-end: 2px;
4231      }
4232    "#,
4233      indoc! {r#"
4234      .foo {
4235        padding-inline-start: 2px;
4236        padding-inline-end: 2px;
4237      }
4238    "#
4239      },
4240      Browsers {
4241        safari: Some(13 << 16),
4242        ..Browsers::default()
4243      },
4244    );
4245
4246    prefix_test(
4247      r#"
4248      .foo {
4249        padding-inline-start: 2px;
4250        padding-inline-end: 2px;
4251      }
4252    "#,
4253      indoc! {r#"
4254      .foo {
4255        padding-inline: 2px;
4256      }
4257    "#
4258      },
4259      Browsers {
4260        safari: Some(15 << 16),
4261        ..Browsers::default()
4262      },
4263    );
4264  }
4265
4266  #[test]
4267  fn test_scroll_padding() {
4268    property_range_test(
4269      &["scroll-padding", "scroll-padding-inline", "scroll-padding-top"],
4270      &[
4271        ("-1px", None),
4272        ("calc(1px - 2px)", Some("0")),
4273        ("calc(-1px + 2px)", Some("1px")),
4274        ("-1%", None),
4275        ("calc(1em - 2px)", Some("calc(1em - 2px)")),
4276        ("calc(-1%)", Some("calc(-1%)")),
4277        ("auto", Some("auto")),
4278      ],
4279    );
4280    prefix_test(
4281      r#"
4282      .foo {
4283        scroll-padding-inline: 2px;
4284      }
4285    "#,
4286      indoc! {r#"
4287      .foo {
4288        scroll-padding-inline: 2px;
4289      }
4290    "#
4291      },
4292      Browsers {
4293        safari: Some(8 << 16),
4294        ..Browsers::default()
4295      },
4296    );
4297  }
4298
4299  #[test]
4300  fn test_size() {
4301    minify_test(".foo { width: 10px; width: -1px }", ".foo{width:10px;width:-1px}");
4302    property_range_test(
4303      &["aspect-ratio"],
4304      &[
4305        ("-1 / 2", None),
4306        ("1 / -2", None),
4307        ("calc(-1) / 2", Some("0/2")),
4308        ("0 / 0", Some("0/0")),
4309      ],
4310    );
4311    property_range_test(
4312      &["width", "max-height"],
4313      &[
4314        ("fit-content(-1px)", None),
4315        ("fit-content(calc(-1px))", Some("fit-content(0)")),
4316      ],
4317    );
4318    property_range_test(
4319      &[
4320        "width",
4321        "height",
4322        "min-width",
4323        "max-width",
4324        "min-height",
4325        "max-height",
4326        "block-size",
4327        "inline-size",
4328        "min-block-size",
4329        "max-inline-size",
4330      ],
4331      &[
4332        ("-1px", None),
4333        ("calc(1px - 2px)", Some("0")),
4334        ("calc(-1px + 2px)", Some("1px")),
4335        ("-1%", None),
4336        ("calc(1em - 2px)", Some("calc(1em - 2px)")),
4337        ("calc(-1%)", Some("calc(-1%)")),
4338      ],
4339    );
4340    prefix_test(
4341      r#"
4342      .foo {
4343        block-size: 25px;
4344        inline-size: 25px;
4345        min-block-size: 25px;
4346        min-inline-size: 25px;
4347      }
4348    "#,
4349      indoc! {r#"
4350      .foo {
4351        height: 25px;
4352        min-height: 25px;
4353        width: 25px;
4354        min-width: 25px;
4355      }
4356    "#},
4357      Browsers {
4358        safari: Some(8 << 16),
4359        ..Browsers::default()
4360      },
4361    );
4362
4363    prefix_test(
4364      r#"
4365      .foo {
4366        block-size: 25px;
4367        min-block-size: 25px;
4368        inline-size: 25px;
4369        min-inline-size: 25px;
4370      }
4371    "#,
4372      indoc! {r#"
4373      .foo {
4374        block-size: 25px;
4375        min-block-size: 25px;
4376        inline-size: 25px;
4377        min-inline-size: 25px;
4378      }
4379    "#},
4380      Browsers {
4381        safari: Some(14 << 16),
4382        ..Browsers::default()
4383      },
4384    );
4385
4386    prefix_test(
4387      r#"
4388      .foo {
4389        block-size: var(--size);
4390        min-block-size: var(--size);
4391        inline-size: var(--size);
4392        min-inline-size: var(--size);
4393      }
4394    "#,
4395      indoc! {r#"
4396      .foo {
4397        height: var(--size);
4398        min-height: var(--size);
4399        width: var(--size);
4400        min-width: var(--size);
4401      }
4402    "#},
4403      Browsers {
4404        safari: Some(8 << 16),
4405        ..Browsers::default()
4406      },
4407    );
4408
4409    for (in_prop, out_prop) in [
4410      ("width", "width"),
4411      ("height", "height"),
4412      ("block-size", "height"),
4413      ("inline-size", "width"),
4414      ("min-width", "min-width"),
4415      ("min-height", "min-height"),
4416      ("min-block-size", "min-height"),
4417      ("min-inline-size", "min-width"),
4418      ("max-width", "max-width"),
4419      ("max-height", "max-height"),
4420      ("max-block-size", "max-height"),
4421      ("max-inline-size", "max-width"),
4422    ] {
4423      prefix_test(
4424        &format!(
4425          r#"
4426        .foo {{
4427          {}: stretch;
4428        }}
4429      "#,
4430          in_prop
4431        ),
4432        &format!(
4433          indoc! {r#"
4434        .foo {{
4435          {}: -webkit-fill-available;
4436          {}: -moz-available;
4437          {}: stretch;
4438        }}
4439      "#},
4440          out_prop, out_prop, out_prop
4441        ),
4442        Browsers {
4443          safari: Some(8 << 16),
4444          firefox: Some(4 << 16),
4445          ..Browsers::default()
4446        },
4447      );
4448
4449      prefix_test(
4450        &format!(
4451          r#"
4452        .foo {{
4453          {}: -webkit-fill-available;
4454        }}
4455      "#,
4456          in_prop
4457        ),
4458        &format!(
4459          indoc! {r#"
4460        .foo {{
4461          {}: -webkit-fill-available;
4462        }}
4463      "#},
4464          out_prop
4465        ),
4466        Browsers {
4467          safari: Some(8 << 16),
4468          firefox: Some(4 << 16),
4469          ..Browsers::default()
4470        },
4471      );
4472
4473      prefix_test(
4474        &format!(
4475          r#"
4476        .foo {{
4477          {}: 100vw;
4478          {}: -webkit-fill-available;
4479        }}
4480      "#,
4481          in_prop, in_prop
4482        ),
4483        &format!(
4484          indoc! {r#"
4485        .foo {{
4486          {}: 100vw;
4487          {}: -webkit-fill-available;
4488        }}
4489      "#},
4490          out_prop, out_prop
4491        ),
4492        Browsers {
4493          safari: Some(8 << 16),
4494          firefox: Some(4 << 16),
4495          ..Browsers::default()
4496        },
4497      );
4498
4499      prefix_test(
4500        &format!(
4501          r#"
4502        .foo {{
4503          {}: fit-content;
4504        }}
4505      "#,
4506          in_prop
4507        ),
4508        &format!(
4509          indoc! {r#"
4510        .foo {{
4511          {}: -webkit-fit-content;
4512          {}: -moz-fit-content;
4513          {}: fit-content;
4514        }}
4515      "#},
4516          out_prop, out_prop, out_prop
4517        ),
4518        Browsers {
4519          safari: Some(8 << 16),
4520          firefox: Some(4 << 16),
4521          ..Browsers::default()
4522        },
4523      );
4524
4525      prefix_test(
4526        &format!(
4527          r#"
4528        .foo {{
4529          {}: fit-content(50%);
4530        }}
4531      "#,
4532          in_prop
4533        ),
4534        &format!(
4535          indoc! {r#"
4536        .foo {{
4537          {}: fit-content(50%);
4538        }}
4539      "#},
4540          out_prop
4541        ),
4542        Browsers {
4543          safari: Some(8 << 16),
4544          firefox: Some(4 << 16),
4545          ..Browsers::default()
4546        },
4547      );
4548
4549      prefix_test(
4550        &format!(
4551          r#"
4552        .foo {{
4553          {}: min-content;
4554        }}
4555      "#,
4556          in_prop
4557        ),
4558        &format!(
4559          indoc! {r#"
4560        .foo {{
4561          {}: -webkit-min-content;
4562          {}: -moz-min-content;
4563          {}: min-content;
4564        }}
4565      "#},
4566          out_prop, out_prop, out_prop
4567        ),
4568        Browsers {
4569          safari: Some(8 << 16),
4570          firefox: Some(4 << 16),
4571          ..Browsers::default()
4572        },
4573      );
4574
4575      prefix_test(
4576        &format!(
4577          r#"
4578        .foo {{
4579          {}: max-content;
4580        }}
4581      "#,
4582          in_prop
4583        ),
4584        &format!(
4585          indoc! {r#"
4586        .foo {{
4587          {}: -webkit-max-content;
4588          {}: -moz-max-content;
4589          {}: max-content;
4590        }}
4591      "#},
4592          out_prop, out_prop, out_prop
4593        ),
4594        Browsers {
4595          safari: Some(8 << 16),
4596          firefox: Some(4 << 16),
4597          ..Browsers::default()
4598        },
4599      );
4600
4601      prefix_test(
4602        &format!(
4603          r#"
4604        .foo {{
4605          {}: 100%;
4606          {}: max-content;
4607        }}
4608      "#,
4609          in_prop, in_prop
4610        ),
4611        &format!(
4612          indoc! {r#"
4613        .foo {{
4614          {}: 100%;
4615          {}: max-content;
4616        }}
4617      "#},
4618          out_prop, out_prop
4619        ),
4620        Browsers {
4621          safari: Some(8 << 16),
4622          firefox: Some(4 << 16),
4623          ..Browsers::default()
4624        },
4625      );
4626
4627      prefix_test(
4628        &format!(
4629          r#"
4630        .foo {{
4631          {}: var(--fallback);
4632          {}: max-content;
4633        }}
4634      "#,
4635          in_prop, in_prop
4636        ),
4637        &format!(
4638          indoc! {r#"
4639        .foo {{
4640          {}: var(--fallback);
4641          {}: max-content;
4642        }}
4643      "#},
4644          out_prop, out_prop
4645        ),
4646        Browsers {
4647          safari: Some(8 << 16),
4648          firefox: Some(4 << 16),
4649          ..Browsers::default()
4650        },
4651      );
4652    }
4653
4654    minify_test(".foo { aspect-ratio: auto }", ".foo{aspect-ratio:auto}");
4655    minify_test(".foo { aspect-ratio: 2 / 3 }", ".foo{aspect-ratio:2/3}");
4656    minify_test(".foo { aspect-ratio: auto 2 / 3 }", ".foo{aspect-ratio:auto 2/3}");
4657    minify_test(".foo { aspect-ratio: 2 / 3 auto }", ".foo{aspect-ratio:auto 2/3}");
4658
4659    minify_test(
4660      ".foo { width: 200px; width: var(--foo); }",
4661      ".foo{width:200px;width:var(--foo)}",
4662    );
4663    minify_test(
4664      ".foo { width: var(--foo); width: 200px; }",
4665      ".foo{width:var(--foo);width:200px}",
4666    );
4667  }
4668
4669  #[test]
4670  pub fn test_background() {
4671    property_range_test(
4672      &["background-size", "mask-size"],
4673      &[
4674        ("-1px", None),
4675        ("calc(1px - 2px)", Some("0")),
4676        ("calc(-1px + 2px)", Some("1px")),
4677        ("-1%", None),
4678        ("calc(1em - 2px)", Some("calc(1em - 2px)")),
4679        ("calc(-1%)", Some("calc(-1%)")),
4680        ("auto", Some("auto")),
4681        ("1px -1px", None),
4682      ],
4683    );
4684    test(
4685      r#"
4686      .foo {
4687        background: url(img.png);
4688        background-position-x: 20px;
4689        background-position-y: 10px;
4690        background-size: 50px 100px;
4691        background-repeat: repeat no-repeat;
4692      }
4693    "#,
4694      indoc! {r#"
4695      .foo {
4696        background: url("img.png") 20px 10px / 50px 100px repeat-x;
4697      }
4698    "#
4699      },
4700    );
4701
4702    test(
4703      r#"
4704      .foo {
4705        background-color: red;
4706        background-position: 0% 0%;
4707        background-size: auto;
4708        background-repeat: repeat;
4709        background-clip: border-box;
4710        background-origin: padding-box;
4711        background-attachment: scroll;
4712        background-image: none
4713      }
4714    "#,
4715      indoc! {r#"
4716      .foo {
4717        background: red;
4718      }
4719    "#
4720      },
4721    );
4722
4723    test(
4724      r#"
4725      .foo {
4726        background-color: gray;
4727        background-position: 40% 50%;
4728        background-size: 10em auto;
4729        background-repeat: round;
4730        background-clip: border-box;
4731        background-origin: border-box;
4732        background-attachment: fixed;
4733        background-image: url('chess.png');
4734      }
4735    "#,
4736      indoc! {r#"
4737      .foo {
4738        background: gray url("chess.png") 40% / 10em round fixed border-box;
4739      }
4740    "#
4741      },
4742    );
4743
4744    test(
4745      r#"
4746      .foo {
4747        background: url(img.png), url(test.jpg) gray;
4748        background-position-x: right 20px, 10px;
4749        background-position-y: top 20px, 15px;
4750        background-size: 50px 50px, auto;
4751        background-repeat: repeat no-repeat, no-repeat;
4752      }
4753    "#,
4754      indoc! {r#"
4755      .foo {
4756        background: url("img.png") right 20px top 20px / 50px 50px repeat-x, gray url("test.jpg") 10px 15px no-repeat;
4757      }
4758    "#
4759      },
4760    );
4761
4762    minify_test(
4763      r#"
4764      .foo {
4765        background-position: center center;
4766      }
4767    "#,
4768      indoc! {".foo{background-position:50%}"
4769      },
4770    );
4771
4772    test(
4773      r#"
4774      .foo {
4775        background: url(img.png) gray;
4776        background-clip: content-box;
4777        -webkit-background-clip: text;
4778      }
4779    "#,
4780      indoc! {r#"
4781      .foo {
4782        background: gray url("img.png") padding-box content-box;
4783        -webkit-background-clip: text;
4784      }
4785    "#
4786      },
4787    );
4788
4789    test(
4790      r#"
4791      .foo {
4792        background: url(img.png) gray;
4793        -webkit-background-clip: text;
4794        background-clip: content-box;
4795      }
4796    "#,
4797      indoc! {r#"
4798      .foo {
4799        background: gray url("img.png");
4800        -webkit-background-clip: text;
4801        background-clip: content-box;
4802      }
4803    "#
4804      },
4805    );
4806
4807    test(
4808      r#"
4809      .foo {
4810        background: url(img.png) gray;
4811        background-position: var(--pos);
4812      }
4813    "#,
4814      indoc! {r#"
4815      .foo {
4816        background: gray url("img.png");
4817        background-position: var(--pos);
4818      }
4819    "#
4820      },
4821    );
4822
4823    minify_test(
4824      ".foo { background-position: bottom left }",
4825      ".foo{background-position:0 100%}",
4826    );
4827    minify_test(
4828      ".foo { background-position: left 10px center }",
4829      ".foo{background-position:10px}",
4830    );
4831    minify_test(
4832      ".foo { background-position: right 10px center }",
4833      ".foo{background-position:right 10px center}",
4834    );
4835    minify_test(
4836      ".foo { background-position: center top 10px }",
4837      ".foo{background-position:50% 10px}",
4838    );
4839    minify_test(
4840      ".foo { background-position: center bottom 10px }",
4841      ".foo{background-position:center bottom 10px}",
4842    );
4843    minify_test(
4844      ".foo { background-position: center 10px }",
4845      ".foo{background-position:50% 10px}",
4846    );
4847    minify_test(
4848      ".foo { background-position: right 10px top 20px }",
4849      ".foo{background-position:right 10px top 20px}",
4850    );
4851    minify_test(
4852      ".foo { background-position: left 10px top 20px }",
4853      ".foo{background-position:10px 20px}",
4854    );
4855    minify_test(
4856      ".foo { background-position: left 10px bottom 20px }",
4857      ".foo{background-position:left 10px bottom 20px}",
4858    );
4859    minify_test(
4860      ".foo { background-position: left 10px top }",
4861      ".foo{background-position:10px 0}",
4862    );
4863    minify_test(
4864      ".foo { background-position: bottom right }",
4865      ".foo{background-position:100% 100%}",
4866    );
4867    minify_test(
4868      ".foo { background-position: center top }",
4869      ".foo{background-position:top}",
4870    );
4871    minify_test(
4872      ".foo { background-position: center bottom }",
4873      ".foo{background-position:bottom}",
4874    );
4875    minify_test(
4876      ".foo { background-position: left center }",
4877      ".foo{background-position:0}",
4878    );
4879    minify_test(
4880      ".foo { background-position: right center }",
4881      ".foo{background-position:100%}",
4882    );
4883    minify_test(
4884      ".foo { background-position: 20px center }",
4885      ".foo{background-position:20px}",
4886    );
4887
4888    minify_test(
4889      ".foo { background: url('img-sprite.png') no-repeat bottom right }",
4890      ".foo{background:url(img-sprite.png) 100% 100% no-repeat}",
4891    );
4892    minify_test(".foo { background: transparent }", ".foo{background:0 0}");
4893
4894    minify_test(".foo { background: url(\"data:image/svg+xml,%3Csvg width='168' height='24' xmlns='http://www.w3.org/2000/svg'%3E%3C/svg%3E\") }", ".foo{background:url(\"data:image/svg+xml,%3Csvg width='168' height='24' xmlns='http://www.w3.org/2000/svg'%3E%3C/svg%3E\")}");
4895
4896    test(
4897      r#"
4898      .foo {
4899        background: url(img.png);
4900        background-clip: text;
4901      }
4902    "#,
4903      indoc! {r#"
4904      .foo {
4905        background: url("img.png") text;
4906      }
4907    "#
4908      },
4909    );
4910
4911    prefix_test(
4912      r#"
4913      .foo {
4914        background: url(img.png);
4915        background-clip: text;
4916      }
4917    "#,
4918      indoc! {r#"
4919      .foo {
4920        background: url("img.png");
4921        -webkit-background-clip: text;
4922        background-clip: text;
4923      }
4924    "#
4925      },
4926      Browsers {
4927        safari: Some(8 << 16),
4928        ..Browsers::default()
4929      },
4930    );
4931
4932    prefix_test(
4933      r#"
4934      .foo {
4935        background: url(img.png);
4936        background-clip: text;
4937      }
4938    "#,
4939      indoc! {r#"
4940      .foo {
4941        background: url("img.png") text;
4942      }
4943    "#
4944      },
4945      Browsers {
4946        safari: Some(14 << 16),
4947        ..Browsers::default()
4948      },
4949    );
4950
4951    prefix_test(
4952      r#"
4953      .foo {
4954        background: url(img.png) text;
4955      }
4956    "#,
4957      indoc! {r#"
4958      .foo {
4959        background: url("img.png");
4960        -webkit-background-clip: text;
4961        background-clip: text;
4962      }
4963    "#
4964      },
4965      Browsers {
4966        chrome: Some(45 << 16),
4967        ..Browsers::default()
4968      },
4969    );
4970
4971    prefix_test(
4972      r#"
4973      .foo {
4974        background: url(img.png);
4975        -webkit-background-clip: text;
4976      }
4977    "#,
4978      indoc! {r#"
4979      .foo {
4980        background: url("img.png");
4981        -webkit-background-clip: text;
4982      }
4983    "#
4984      },
4985      Browsers {
4986        chrome: Some(45 << 16),
4987        ..Browsers::default()
4988      },
4989    );
4990
4991    prefix_test(
4992      r#"
4993      .foo {
4994        background: url(img.png);
4995        background-clip: text;
4996      }
4997    "#,
4998      indoc! {r#"
4999      .foo {
5000        background: url("img.png");
5001        -webkit-background-clip: text;
5002        background-clip: text;
5003      }
5004    "#
5005      },
5006      Browsers {
5007        safari: Some(14 << 16),
5008        chrome: Some(95 << 16),
5009        ..Browsers::default()
5010      },
5011    );
5012
5013    prefix_test(
5014      r#"
5015      .foo {
5016        background-image: url(img.png);
5017        background-clip: text;
5018      }
5019    "#,
5020      indoc! {r#"
5021      .foo {
5022        background-image: url("img.png");
5023        -webkit-background-clip: text;
5024        background-clip: text;
5025      }
5026    "#
5027      },
5028      Browsers {
5029        safari: Some(8 << 16),
5030        ..Browsers::default()
5031      },
5032    );
5033
5034    prefix_test(
5035      r#"
5036      .foo {
5037        -webkit-background-clip: text;
5038        background-clip: text;
5039      }
5040    "#,
5041      indoc! {r#"
5042      .foo {
5043        -webkit-background-clip: text;
5044        background-clip: text;
5045      }
5046    "#
5047      },
5048      Browsers {
5049        chrome: Some(45 << 16),
5050        ..Browsers::default()
5051      },
5052    );
5053
5054    prefix_test(
5055      r#"
5056      .foo {
5057        background-image: url(img.png);
5058        background-clip: text;
5059      }
5060    "#,
5061      indoc! {r#"
5062      .foo {
5063        background-image: url("img.png");
5064        background-clip: text;
5065      }
5066    "#
5067      },
5068      Browsers {
5069        safari: Some(14 << 16),
5070        ..Browsers::default()
5071      },
5072    );
5073
5074    minify_test(".foo { background: none center }", ".foo{background:50%}");
5075    minify_test(".foo { background: none }", ".foo{background:0 0}");
5076
5077    prefix_test(
5078      r#"
5079      .foo {
5080        background: lab(51.5117% 43.3777 -29.0443);
5081      }
5082    "#,
5083      indoc! {r#"
5084      .foo {
5085        background: #af5cae;
5086        background: lab(51.5117% 43.3777 -29.0443);
5087      }
5088    "#
5089      },
5090      Browsers {
5091        chrome: Some(95 << 16),
5092        safari: Some(15 << 16),
5093        ..Browsers::default()
5094      },
5095    );
5096
5097    prefix_test(
5098      r#"
5099      .foo {
5100        background: lab(51.5117% 43.3777 -29.0443) url(foo.png);
5101      }
5102    "#,
5103      indoc! {r#"
5104      .foo {
5105        background: #af5cae url("foo.png");
5106        background: lab(51.5117% 43.3777 -29.0443) url("foo.png");
5107      }
5108    "#
5109      },
5110      Browsers {
5111        chrome: Some(95 << 16),
5112        safari: Some(15 << 16),
5113        ..Browsers::default()
5114      },
5115    );
5116
5117    prefix_test(
5118      r#"
5119      .foo {
5120        background: lab(51.5117% 43.3777 -29.0443) linear-gradient(lab(52.2319% 40.1449 59.9171), lab(47.7776% -34.2947 -7.65904));
5121      }
5122    "#,
5123      indoc! {r#"
5124      .foo {
5125        background: #af5cae linear-gradient(#c65d07, #00817d);
5126        background: lab(51.5117% 43.3777 -29.0443) linear-gradient(lab(52.2319% 40.1449 59.9171), lab(47.7776% -34.2947 -7.65904));
5127      }
5128    "#
5129      },
5130      Browsers {
5131        chrome: Some(95 << 16),
5132        safari: Some(15 << 16),
5133        ..Browsers::default()
5134      },
5135    );
5136
5137    test(
5138      ".foo { background: calc(var(--v) / 0.3)",
5139      indoc! {r#"
5140      .foo {
5141        background: calc(var(--v) / .3);
5142      }
5143    "#},
5144    );
5145
5146    prefix_test(
5147      r#"
5148      .foo {
5149        background-color: #4263eb;
5150        background-color: color(display-p3 0 .5 1);
5151      }
5152    "#,
5153      indoc! {r#"
5154      .foo {
5155        background-color: #4263eb;
5156        background-color: color(display-p3 0 .5 1);
5157      }
5158    "#
5159      },
5160      Browsers {
5161        chrome: Some(99 << 16),
5162        ..Browsers::default()
5163      },
5164    );
5165    prefix_test(
5166      r#"
5167      .foo {
5168        background-color: #4263eb;
5169        background-color: color(display-p3 0 .5 1);
5170      }
5171    "#,
5172      indoc! {r#"
5173      .foo {
5174        background-color: color(display-p3 0 .5 1);
5175      }
5176    "#
5177      },
5178      Browsers {
5179        safari: Some(16 << 16),
5180        ..Browsers::default()
5181      },
5182    );
5183    prefix_test(
5184      r#"
5185      .foo {
5186        background-image: linear-gradient(red, green);
5187        background-image: linear-gradient(lch(50% 132 50), lch(50% 130 150));
5188      }
5189    "#,
5190      indoc! {r#"
5191      .foo {
5192        background-image: linear-gradient(red, green);
5193        background-image: linear-gradient(lch(50% 132 50), lch(50% 130 150));
5194      }
5195    "#
5196      },
5197      Browsers {
5198        chrome: Some(99 << 16),
5199        ..Browsers::default()
5200      },
5201    );
5202    prefix_test(
5203      r#"
5204      .foo {
5205        background-image: linear-gradient(red, green);
5206        background-image: linear-gradient(lch(50% 132 50), lch(50% 130 150));
5207      }
5208    "#,
5209      indoc! {r#"
5210      .foo {
5211        background-image: linear-gradient(lch(50% 132 50), lch(50% 130 150));
5212      }
5213    "#
5214      },
5215      Browsers {
5216        safari: Some(16 << 16),
5217        ..Browsers::default()
5218      },
5219    );
5220    prefix_test(
5221      r#"
5222      .foo {
5223        background: #4263eb;
5224        background: color(display-p3 0 .5 1);
5225      }
5226    "#,
5227      indoc! {r#"
5228      .foo {
5229        background: #4263eb;
5230        background: color(display-p3 0 .5 1);
5231      }
5232    "#
5233      },
5234      Browsers {
5235        chrome: Some(99 << 16),
5236        ..Browsers::default()
5237      },
5238    );
5239    prefix_test(
5240      r#"
5241      .foo {
5242        background: #4263eb;
5243        background: color(display-p3 0 .5 1);
5244      }
5245    "#,
5246      indoc! {r#"
5247      .foo {
5248        background: color(display-p3 0 .5 1);
5249      }
5250    "#
5251      },
5252      Browsers {
5253        safari: Some(16 << 16),
5254        ..Browsers::default()
5255      },
5256    );
5257    prefix_test(
5258      r#"
5259      .foo {
5260        background: linear-gradient(red, green);
5261        background: linear-gradient(lch(50% 132 50), lch(50% 130 150));
5262      }
5263    "#,
5264      indoc! {r#"
5265      .foo {
5266        background: linear-gradient(red, green);
5267        background: linear-gradient(lch(50% 132 50), lch(50% 130 150));
5268      }
5269    "#
5270      },
5271      Browsers {
5272        chrome: Some(99 << 16),
5273        ..Browsers::default()
5274      },
5275    );
5276    prefix_test(
5277      r#"
5278      .foo {
5279        background: red;
5280        background: linear-gradient(lch(50% 132 50), lch(50% 130 150));
5281      }
5282    "#,
5283      indoc! {r#"
5284      .foo {
5285        background: red;
5286        background: linear-gradient(lch(50% 132 50), lch(50% 130 150));
5287      }
5288    "#
5289      },
5290      Browsers {
5291        chrome: Some(99 << 16),
5292        ..Browsers::default()
5293      },
5294    );
5295    prefix_test(
5296      r#"
5297      .foo {
5298        background: linear-gradient(red, green);
5299        background: linear-gradient(lch(50% 132 50), lch(50% 130 150));
5300      }
5301    "#,
5302      indoc! {r#"
5303      .foo {
5304        background: linear-gradient(lch(50% 132 50), lch(50% 130 150));
5305      }
5306    "#
5307      },
5308      Browsers {
5309        safari: Some(16 << 16),
5310        ..Browsers::default()
5311      },
5312    );
5313    prefix_test(
5314      r#"
5315      .foo {
5316        background: var(--fallback);
5317        background: linear-gradient(lch(50% 132 50), lch(50% 130 150));
5318      }
5319    "#,
5320      indoc! {r#"
5321      .foo {
5322        background: var(--fallback);
5323        background: linear-gradient(lch(50% 132 50), lch(50% 130 150));
5324      }
5325    "#
5326      },
5327      Browsers {
5328        chrome: Some(99 << 16),
5329        ..Browsers::default()
5330      },
5331    );
5332    prefix_test(
5333      r#"
5334      .foo {
5335        background: red url(foo.png);
5336        background: lch(50% 132 50) url(foo.png);
5337      }
5338    "#,
5339      indoc! {r#"
5340      .foo {
5341        background: red url("foo.png");
5342        background: lch(50% 132 50) url("foo.png");
5343      }
5344    "#
5345      },
5346      Browsers {
5347        chrome: Some(99 << 16),
5348        ..Browsers::default()
5349      },
5350    );
5351  }
5352
5353  #[test]
5354  pub fn test_flex() {
5355    property_range_test(&["flex"], &[("-1", None), ("1 -1", None), ("1 1 -1px", None)]);
5356    property_range_test(
5357      &["flex-basis", "-ms-flex-preferred-size"],
5358      &[
5359        ("-1px", None),
5360        ("calc(1px - 2px)", Some("0")),
5361        ("calc(-1px + 2px)", Some("1px")),
5362        ("-1%", None),
5363        ("calc(1em - 2px)", Some("calc(1em - 2px)")),
5364        ("calc(-1%)", Some("calc(-1%)")),
5365      ],
5366    );
5367    property_range_test(
5368      &[
5369        "flex-grow",
5370        "flex-shrink",
5371        "-webkit-box-flex",
5372        "-ms-flex-positive",
5373        "-ms-flex-negative",
5374      ],
5375      &[("-1", None), ("calc(1 - 2)", Some("0")), ("calc(-1 + 2)", Some("1"))],
5376    );
5377    test(
5378      r#"
5379      .foo {
5380        flex-direction: column;
5381        flex-wrap: wrap;
5382      }
5383    "#,
5384      indoc! {r#"
5385      .foo {
5386        flex-flow: column wrap;
5387      }
5388    "#
5389      },
5390    );
5391
5392    test(
5393      r#"
5394      .foo {
5395        flex-direction: row;
5396        flex-wrap: wrap;
5397      }
5398    "#,
5399      indoc! {r#"
5400      .foo {
5401        flex-flow: wrap;
5402      }
5403    "#
5404      },
5405    );
5406
5407    test(
5408      r#"
5409      .foo {
5410        flex-direction: row;
5411        flex-wrap: nowrap;
5412      }
5413    "#,
5414      indoc! {r#"
5415      .foo {
5416        flex-flow: row;
5417      }
5418    "#
5419      },
5420    );
5421
5422    test(
5423      r#"
5424      .foo {
5425        flex-direction: column;
5426        flex-wrap: nowrap;
5427      }
5428    "#,
5429      indoc! {r#"
5430      .foo {
5431        flex-flow: column;
5432      }
5433    "#
5434      },
5435    );
5436
5437    test(
5438      r#"
5439      .foo {
5440        flex-grow: 1;
5441        flex-shrink: 1;
5442        flex-basis: 0%;
5443      }
5444    "#,
5445      indoc! {r#"
5446      .foo {
5447        flex: 1;
5448      }
5449    "#
5450      },
5451    );
5452
5453    test(
5454      r#"
5455      .foo {
5456        flex-grow: 1;
5457        flex-shrink: 1;
5458        flex-basis: 0;
5459      }
5460    "#,
5461      indoc! {r#"
5462      .foo {
5463        flex: 1 1 0;
5464      }
5465    "#
5466      },
5467    );
5468
5469    test(
5470      r#"
5471      .foo {
5472        flex-grow: 1;
5473        flex-shrink: 1;
5474        flex-basis: 0px;
5475      }
5476    "#,
5477      indoc! {r#"
5478      .foo {
5479        flex: 1 1 0;
5480      }
5481    "#
5482      },
5483    );
5484
5485    test(
5486      r#"
5487      .foo {
5488        flex-grow: 1;
5489        flex-shrink: 2;
5490        flex-basis: 0%;
5491      }
5492    "#,
5493      indoc! {r#"
5494      .foo {
5495        flex: 1 2;
5496      }
5497    "#
5498      },
5499    );
5500
5501    test(
5502      r#"
5503      .foo {
5504        flex-grow: 2;
5505        flex-shrink: 1;
5506        flex-basis: 0%;
5507      }
5508    "#,
5509      indoc! {r#"
5510      .foo {
5511        flex: 2;
5512      }
5513    "#
5514      },
5515    );
5516
5517    test(
5518      r#"
5519      .foo {
5520        flex-grow: 2;
5521        flex-shrink: 2;
5522        flex-basis: 0%;
5523      }
5524    "#,
5525      indoc! {r#"
5526      .foo {
5527        flex: 2 2;
5528      }
5529    "#
5530      },
5531    );
5532
5533    test(
5534      r#"
5535      .foo {
5536        flex-grow: 1;
5537        flex-shrink: 1;
5538        flex-basis: 10px;
5539      }
5540    "#,
5541      indoc! {r#"
5542      .foo {
5543        flex: 10px;
5544      }
5545    "#
5546      },
5547    );
5548
5549    test(
5550      r#"
5551      .foo {
5552        flex-grow: 2;
5553        flex-shrink: 1;
5554        flex-basis: 10px;
5555      }
5556    "#,
5557      indoc! {r#"
5558      .foo {
5559        flex: 2 10px;
5560      }
5561    "#
5562      },
5563    );
5564
5565    test(
5566      r#"
5567      .foo {
5568        flex-grow: 1;
5569        flex-shrink: 0;
5570        flex-basis: 0%;
5571      }
5572    "#,
5573      indoc! {r#"
5574      .foo {
5575        flex: 1 0;
5576      }
5577    "#
5578      },
5579    );
5580
5581    test(
5582      r#"
5583      .foo {
5584        flex-grow: 1;
5585        flex-shrink: 0;
5586        flex-basis: auto;
5587      }
5588    "#,
5589      indoc! {r#"
5590      .foo {
5591        flex: 1 0 auto;
5592      }
5593    "#
5594      },
5595    );
5596
5597    test(
5598      r#"
5599      .foo {
5600        flex-grow: 1;
5601        flex-shrink: 1;
5602        flex-basis: auto;
5603      }
5604    "#,
5605      indoc! {r#"
5606      .foo {
5607        flex: auto;
5608      }
5609    "#
5610      },
5611    );
5612
5613    test(
5614      r#"
5615      .foo {
5616        flex: 0 0;
5617        flex-grow: 1;
5618      }
5619    "#,
5620      indoc! {r#"
5621      .foo {
5622        flex: 1 0;
5623      }
5624    "#
5625      },
5626    );
5627
5628    test(
5629      r#"
5630      .foo {
5631        flex: 0 0;
5632        flex-grow: var(--grow);
5633      }
5634    "#,
5635      indoc! {r#"
5636      .foo {
5637        flex: 0 0;
5638        flex-grow: var(--grow);
5639      }
5640    "#
5641      },
5642    );
5643
5644    test(
5645      r#"
5646      .foo {
5647        align-content: center;
5648        justify-content: center;
5649      }
5650    "#,
5651      indoc! {r#"
5652      .foo {
5653        place-content: center;
5654      }
5655    "#
5656      },
5657    );
5658
5659    test(
5660      r#"
5661      .foo {
5662        align-content: first baseline;
5663        justify-content: safe right;
5664      }
5665    "#,
5666      indoc! {r#"
5667      .foo {
5668        place-content: baseline safe right;
5669      }
5670    "#
5671      },
5672    );
5673
5674    test(
5675      r#"
5676      .foo {
5677        place-content: first baseline unsafe left;
5678      }
5679    "#,
5680      indoc! {r#"
5681      .foo {
5682        place-content: baseline unsafe left;
5683      }
5684    "#
5685      },
5686    );
5687
5688    test(
5689      r#"
5690      .foo {
5691        place-content: center center;
5692      }
5693    "#,
5694      indoc! {r#"
5695      .foo {
5696        place-content: center;
5697      }
5698    "#
5699      },
5700    );
5701
5702    test(
5703      r#"
5704      .foo {
5705        align-self: center;
5706        justify-self: center;
5707      }
5708    "#,
5709      indoc! {r#"
5710      .foo {
5711        place-self: center;
5712      }
5713    "#
5714      },
5715    );
5716
5717    test(
5718      r#"
5719      .foo {
5720        align-self: center;
5721        justify-self: unsafe left;
5722      }
5723    "#,
5724      indoc! {r#"
5725      .foo {
5726        place-self: center unsafe left;
5727      }
5728    "#
5729      },
5730    );
5731
5732    test(
5733      r#"
5734      .foo {
5735        align-items: center;
5736        justify-items: center;
5737      }
5738    "#,
5739      indoc! {r#"
5740      .foo {
5741        place-items: center;
5742      }
5743    "#
5744      },
5745    );
5746
5747    test(
5748      r#"
5749      .foo {
5750        align-items: center;
5751        justify-items: legacy left;
5752      }
5753    "#,
5754      indoc! {r#"
5755      .foo {
5756        place-items: center legacy left;
5757      }
5758    "#
5759      },
5760    );
5761
5762    test(
5763      r#"
5764      .foo {
5765        place-items: center;
5766        justify-items: var(--justify);
5767      }
5768    "#,
5769      indoc! {r#"
5770      .foo {
5771        place-items: center;
5772        justify-items: var(--justify);
5773      }
5774    "#
5775      },
5776    );
5777
5778    test(
5779      r#"
5780      .foo {
5781        row-gap: 10px;
5782        column-gap: 20px;
5783      }
5784    "#,
5785      indoc! {r#"
5786      .foo {
5787        gap: 10px 20px;
5788      }
5789    "#
5790      },
5791    );
5792
5793    test(
5794      r#"
5795      .foo {
5796        row-gap: 10px;
5797        column-gap: 10px;
5798      }
5799    "#,
5800      indoc! {r#"
5801      .foo {
5802        gap: 10px;
5803      }
5804    "#
5805      },
5806    );
5807
5808    test(
5809      r#"
5810      .foo {
5811        gap: 10px;
5812        column-gap: 20px;
5813      }
5814    "#,
5815      indoc! {r#"
5816      .foo {
5817        gap: 10px 20px;
5818      }
5819    "#
5820      },
5821    );
5822
5823    test(
5824      r#"
5825      .foo {
5826        column-gap: 20px;
5827        gap: 10px;
5828      }
5829    "#,
5830      indoc! {r#"
5831      .foo {
5832        gap: 10px;
5833      }
5834    "#
5835      },
5836    );
5837
5838    test(
5839      r#"
5840      .foo {
5841        row-gap: normal;
5842        column-gap: 20px;
5843      }
5844    "#,
5845      indoc! {r#"
5846      .foo {
5847        gap: normal 20px;
5848      }
5849    "#
5850      },
5851    );
5852
5853    test(
5854      r#"
5855      .foo {
5856        -webkit-flex-grow: 1;
5857        -webkit-flex-shrink: 1;
5858        -webkit-flex-basis: auto;
5859      }
5860    "#,
5861      indoc! {r#"
5862      .foo {
5863        -webkit-flex: auto;
5864      }
5865    "#
5866      },
5867    );
5868    test(
5869      r#"
5870      .foo {
5871        -webkit-flex-grow: 1;
5872        -webkit-flex-shrink: 1;
5873        -webkit-flex-basis: auto;
5874        flex-grow: 1;
5875        flex-shrink: 1;
5876        flex-basis: auto;
5877      }
5878    "#,
5879      indoc! {r#"
5880      .foo {
5881        -webkit-flex: auto;
5882        flex: auto;
5883      }
5884    "#
5885      },
5886    );
5887    prefix_test(
5888      r#"
5889      .foo {
5890        -webkit-box-orient: horizontal;
5891        -webkit-box-direction: normal;
5892        flex-direction: row;
5893      }
5894    "#,
5895      indoc! {r#"
5896      .foo {
5897        -webkit-box-orient: horizontal;
5898        -webkit-box-direction: normal;
5899        -webkit-flex-direction: row;
5900        flex-direction: row;
5901      }
5902    "#},
5903      Browsers {
5904        safari: Some(4 << 16),
5905        ..Browsers::default()
5906      },
5907    );
5908    prefix_test(
5909      r#"
5910      .foo {
5911        flex-direction: row;
5912      }
5913    "#,
5914      indoc! {r#"
5915      .foo {
5916        -webkit-box-orient: horizontal;
5917        -moz-box-orient: horizontal;
5918        -webkit-box-direction: normal;
5919        -moz-box-direction: normal;
5920        -webkit-flex-direction: row;
5921        -ms-flex-direction: row;
5922        flex-direction: row;
5923      }
5924    "#},
5925      Browsers {
5926        safari: Some(4 << 16),
5927        firefox: Some(4 << 16),
5928        ie: Some(10 << 16),
5929        ..Browsers::default()
5930      },
5931    );
5932    prefix_test(
5933      r#"
5934      .foo {
5935        -webkit-box-orient: horizontal;
5936        -webkit-box-direction: normal;
5937        -moz-box-orient: horizontal;
5938        -moz-box-direction: normal;
5939        -webkit-flex-direction: row;
5940        -ms-flex-direction: row;
5941        flex-direction: row;
5942      }
5943    "#,
5944      indoc! {r#"
5945      .foo {
5946        flex-direction: row;
5947      }
5948    "#},
5949      Browsers {
5950        safari: Some(14 << 16),
5951        ..Browsers::default()
5952      },
5953    );
5954    prefix_test(
5955      r#"
5956      .foo {
5957        flex-wrap: wrap;
5958      }
5959    "#,
5960      indoc! {r#"
5961      .foo {
5962        -webkit-box-lines: multiple;
5963        -moz-box-lines: multiple;
5964        -webkit-flex-wrap: wrap;
5965        -ms-flex-wrap: wrap;
5966        flex-wrap: wrap;
5967      }
5968    "#},
5969      Browsers {
5970        safari: Some(4 << 16),
5971        firefox: Some(4 << 16),
5972        ie: Some(10 << 16),
5973        ..Browsers::default()
5974      },
5975    );
5976    prefix_test(
5977      r#"
5978      .foo {
5979        -webkit-box-lines: multiple;
5980        -moz-box-lines: multiple;
5981        -webkit-flex-wrap: wrap;
5982        -ms-flex-wrap: wrap;
5983        flex-wrap: wrap;
5984      }
5985    "#,
5986      indoc! {r#"
5987      .foo {
5988        flex-wrap: wrap;
5989      }
5990    "#},
5991      Browsers {
5992        safari: Some(11 << 16),
5993        ..Browsers::default()
5994      },
5995    );
5996    prefix_test(
5997      r#"
5998      .foo {
5999        flex-flow: row wrap;
6000      }
6001    "#,
6002      indoc! {r#"
6003      .foo {
6004        -webkit-box-orient: horizontal;
6005        -moz-box-orient: horizontal;
6006        -webkit-box-direction: normal;
6007        -moz-box-direction: normal;
6008        -webkit-flex-flow: wrap;
6009        -ms-flex-flow: wrap;
6010        flex-flow: wrap;
6011      }
6012    "#},
6013      Browsers {
6014        safari: Some(4 << 16),
6015        firefox: Some(4 << 16),
6016        ie: Some(10 << 16),
6017        ..Browsers::default()
6018      },
6019    );
6020    prefix_test(
6021      r#"
6022      .foo {
6023        -webkit-box-orient: horizontal;
6024        -moz-box-orient: horizontal;
6025        -webkit-box-direction: normal;
6026        -moz-box-direction: normal;
6027        -webkit-flex-flow: wrap;
6028        -ms-flex-flow: wrap;
6029        flex-flow: wrap;
6030      }
6031    "#,
6032      indoc! {r#"
6033      .foo {
6034        flex-flow: wrap;
6035      }
6036    "#},
6037      Browsers {
6038        safari: Some(11 << 16),
6039        ..Browsers::default()
6040      },
6041    );
6042    prefix_test(
6043      r#"
6044      .foo {
6045        flex-grow: 1;
6046      }
6047    "#,
6048      indoc! {r#"
6049      .foo {
6050        -webkit-box-flex: 1;
6051        -moz-box-flex: 1;
6052        -ms-flex-positive: 1;
6053        -webkit-flex-grow: 1;
6054        flex-grow: 1;
6055      }
6056    "#},
6057      Browsers {
6058        safari: Some(4 << 16),
6059        firefox: Some(4 << 16),
6060        ie: Some(10 << 16),
6061        ..Browsers::default()
6062      },
6063    );
6064    prefix_test(
6065      r#"
6066      .foo {
6067        -webkit-box-flex: 1;
6068        -moz-box-flex: 1;
6069        -ms-flex-positive: 1;
6070        -webkit-flex-grow: 1;
6071        flex-grow: 1;
6072      }
6073    "#,
6074      indoc! {r#"
6075      .foo {
6076        flex-grow: 1;
6077      }
6078    "#},
6079      Browsers {
6080        safari: Some(11 << 16),
6081        ..Browsers::default()
6082      },
6083    );
6084    prefix_test(
6085      r#"
6086      .foo {
6087        flex-shrink: 1;
6088      }
6089    "#,
6090      indoc! {r#"
6091      .foo {
6092        -ms-flex-negative: 1;
6093        -webkit-flex-shrink: 1;
6094        flex-shrink: 1;
6095      }
6096    "#},
6097      Browsers {
6098        safari: Some(4 << 16),
6099        firefox: Some(4 << 16),
6100        ie: Some(10 << 16),
6101        ..Browsers::default()
6102      },
6103    );
6104    prefix_test(
6105      r#"
6106      .foo {
6107        -ms-flex-negative: 1;
6108        -webkit-flex-shrink: 1;
6109        flex-shrink: 1;
6110      }
6111    "#,
6112      indoc! {r#"
6113      .foo {
6114        flex-shrink: 1;
6115      }
6116    "#},
6117      Browsers {
6118        safari: Some(11 << 16),
6119        ..Browsers::default()
6120      },
6121    );
6122    prefix_test(
6123      r#"
6124      .foo {
6125        flex-basis: 1px;
6126      }
6127    "#,
6128      indoc! {r#"
6129      .foo {
6130        -ms-flex-preferred-size: 1px;
6131        -webkit-flex-basis: 1px;
6132        flex-basis: 1px;
6133      }
6134    "#},
6135      Browsers {
6136        safari: Some(4 << 16),
6137        firefox: Some(4 << 16),
6138        ie: Some(10 << 16),
6139        ..Browsers::default()
6140      },
6141    );
6142    prefix_test(
6143      r#"
6144      .foo {
6145        -ms-flex-preferred-size: 1px;
6146        -webkit-flex-basis: 1px;
6147        flex-basis: 1px;
6148      }
6149    "#,
6150      indoc! {r#"
6151      .foo {
6152        flex-basis: 1px;
6153      }
6154    "#},
6155      Browsers {
6156        safari: Some(11 << 16),
6157        ..Browsers::default()
6158      },
6159    );
6160    prefix_test(
6161      r#"
6162      .foo {
6163        flex: 1;
6164      }
6165    "#,
6166      indoc! {r#"
6167      .foo {
6168        -webkit-box-flex: 1;
6169        -moz-box-flex: 1;
6170        -webkit-flex: 1;
6171        -ms-flex: 1;
6172        flex: 1;
6173      }
6174    "#},
6175      Browsers {
6176        safari: Some(4 << 16),
6177        firefox: Some(4 << 16),
6178        ie: Some(10 << 16),
6179        ..Browsers::default()
6180      },
6181    );
6182    prefix_test(
6183      r#"
6184      .foo {
6185        -webkit-box-flex: 1;
6186        -moz-box-flex: 1;
6187        -webkit-flex: 1;
6188        -ms-flex: 1;
6189        flex: 1;
6190      }
6191    "#,
6192      indoc! {r#"
6193      .foo {
6194        flex: 1;
6195      }
6196    "#},
6197      Browsers {
6198        safari: Some(11 << 16),
6199        ..Browsers::default()
6200      },
6201    );
6202    prefix_test(
6203      r#"
6204      .foo {
6205        align-content: space-between;
6206      }
6207    "#,
6208      indoc! {r#"
6209      .foo {
6210        -ms-flex-line-pack: justify;
6211        -webkit-align-content: space-between;
6212        align-content: space-between;
6213      }
6214    "#},
6215      Browsers {
6216        safari: Some(4 << 16),
6217        firefox: Some(4 << 16),
6218        ie: Some(10 << 16),
6219        ..Browsers::default()
6220      },
6221    );
6222    prefix_test(
6223      r#"
6224      .foo {
6225        -ms-flex-line-pack: justify;
6226        -webkit-align-content: space-between;
6227        align-content: space-between;
6228      }
6229    "#,
6230      indoc! {r#"
6231      .foo {
6232        align-content: space-between;
6233      }
6234    "#},
6235      Browsers {
6236        safari: Some(11 << 16),
6237        ..Browsers::default()
6238      },
6239    );
6240    prefix_test(
6241      r#"
6242      .foo {
6243        justify-content: space-between;
6244      }
6245    "#,
6246      indoc! {r#"
6247      .foo {
6248        -webkit-box-pack: justify;
6249        -moz-box-pack: justify;
6250        -ms-flex-pack: justify;
6251        -webkit-justify-content: space-between;
6252        justify-content: space-between;
6253      }
6254    "#},
6255      Browsers {
6256        safari: Some(4 << 16),
6257        firefox: Some(4 << 16),
6258        ie: Some(10 << 16),
6259        ..Browsers::default()
6260      },
6261    );
6262    prefix_test(
6263      r#"
6264      .foo {
6265        -webkit-box-pack: justify;
6266        -moz-box-pack: justify;
6267        -ms-flex-pack: justify;
6268        -webkit-justify-content: space-between;
6269        justify-content: space-between;
6270      }
6271    "#,
6272      indoc! {r#"
6273      .foo {
6274        justify-content: space-between;
6275      }
6276    "#},
6277      Browsers {
6278        safari: Some(11 << 16),
6279        ..Browsers::default()
6280      },
6281    );
6282    prefix_test(
6283      r#"
6284      .foo {
6285        place-content: space-between flex-end;
6286      }
6287    "#,
6288      indoc! {r#"
6289      .foo {
6290        -ms-flex-line-pack: justify;
6291        -webkit-box-pack: end;
6292        -moz-box-pack: end;
6293        -ms-flex-pack: end;
6294        -webkit-align-content: space-between;
6295        align-content: space-between;
6296        -webkit-justify-content: flex-end;
6297        justify-content: flex-end;
6298      }
6299    "#},
6300      Browsers {
6301        safari: Some(4 << 16),
6302        firefox: Some(4 << 16),
6303        ie: Some(10 << 16),
6304        ..Browsers::default()
6305      },
6306    );
6307    prefix_test(
6308      r#"
6309      .foo {
6310        -ms-flex-line-pack: justify;
6311        -webkit-box-pack: end;
6312        -moz-box-pack: end;
6313        -ms-flex-pack: end;
6314        -webkit-align-content: space-between;
6315        -webkit-justify-content: flex-end;
6316        place-content: space-between flex-end;
6317      }
6318    "#,
6319      indoc! {r#"
6320      .foo {
6321        place-content: space-between flex-end;
6322      }
6323    "#},
6324      Browsers {
6325        safari: Some(11 << 16),
6326        ..Browsers::default()
6327      },
6328    );
6329    prefix_test(
6330      r#"
6331      .foo {
6332        place-content: space-between flex-end;
6333      }
6334    "#,
6335      indoc! {r#"
6336      .foo {
6337        align-content: space-between;
6338        justify-content: flex-end;
6339      }
6340    "#},
6341      Browsers {
6342        chrome: Some(30 << 16),
6343        ..Browsers::default()
6344      },
6345    );
6346    prefix_test(
6347      r#"
6348      .foo {
6349        place-content: space-between flex-end;
6350      }
6351    "#,
6352      indoc! {r#"
6353      .foo {
6354        place-content: space-between flex-end;
6355      }
6356    "#},
6357      Browsers {
6358        chrome: Some(60 << 16),
6359        ..Browsers::default()
6360      },
6361    );
6362    prefix_test(
6363      r#"
6364      .foo {
6365        align-self: flex-end;
6366      }
6367    "#,
6368      indoc! {r#"
6369      .foo {
6370        -ms-flex-item-align: end;
6371        -webkit-align-self: flex-end;
6372        align-self: flex-end;
6373      }
6374    "#},
6375      Browsers {
6376        safari: Some(4 << 16),
6377        firefox: Some(4 << 16),
6378        ie: Some(10 << 16),
6379        ..Browsers::default()
6380      },
6381    );
6382    prefix_test(
6383      r#"
6384      .foo {
6385        -ms-flex-item-align: end;
6386        -webkit-align-self: flex-end;
6387        align-self: flex-end;
6388      }
6389    "#,
6390      indoc! {r#"
6391      .foo {
6392        align-self: flex-end;
6393      }
6394    "#},
6395      Browsers {
6396        safari: Some(11 << 16),
6397        ..Browsers::default()
6398      },
6399    );
6400    prefix_test(
6401      r#"
6402      .foo {
6403        place-self: center flex-end;
6404      }
6405    "#,
6406      indoc! {r#"
6407      .foo {
6408        -ms-flex-item-align: center;
6409        -webkit-align-self: center;
6410        align-self: center;
6411        justify-self: flex-end;
6412      }
6413    "#},
6414      Browsers {
6415        safari: Some(4 << 16),
6416        firefox: Some(4 << 16),
6417        ie: Some(10 << 16),
6418        ..Browsers::default()
6419      },
6420    );
6421    prefix_test(
6422      r#"
6423      .foo {
6424        -ms-flex-item-align: center;
6425        -webkit-align-self: center;
6426        place-self: center flex-end;
6427      }
6428    "#,
6429      indoc! {r#"
6430      .foo {
6431        place-self: center flex-end;
6432      }
6433    "#},
6434      Browsers {
6435        safari: Some(11 << 16),
6436        ..Browsers::default()
6437      },
6438    );
6439    prefix_test(
6440      r#"
6441      .foo {
6442        place-self: center flex-end;
6443      }
6444    "#,
6445      indoc! {r#"
6446      .foo {
6447        align-self: center;
6448        justify-self: flex-end;
6449      }
6450    "#},
6451      Browsers {
6452        chrome: Some(57 << 16),
6453        ..Browsers::default()
6454      },
6455    );
6456    prefix_test(
6457      r#"
6458      .foo {
6459        place-self: center flex-end;
6460      }
6461    "#,
6462      indoc! {r#"
6463      .foo {
6464        place-self: center flex-end;
6465      }
6466    "#},
6467      Browsers {
6468        chrome: Some(59 << 16),
6469        ..Browsers::default()
6470      },
6471    );
6472    prefix_test(
6473      r#"
6474      .foo {
6475        align-items: flex-end;
6476      }
6477    "#,
6478      indoc! {r#"
6479      .foo {
6480        -webkit-box-align: end;
6481        -moz-box-align: end;
6482        -ms-flex-align: end;
6483        -webkit-align-items: flex-end;
6484        align-items: flex-end;
6485      }
6486    "#},
6487      Browsers {
6488        safari: Some(4 << 16),
6489        firefox: Some(4 << 16),
6490        ie: Some(10 << 16),
6491        ..Browsers::default()
6492      },
6493    );
6494    prefix_test(
6495      r#"
6496      .foo {
6497        -webkit-box-align: end;
6498        -moz-box-align: end;
6499        -ms-flex-align: end;
6500        -webkit-align-items: flex-end;
6501        align-items: flex-end;
6502      }
6503    "#,
6504      indoc! {r#"
6505      .foo {
6506        align-items: flex-end;
6507      }
6508    "#},
6509      Browsers {
6510        safari: Some(11 << 16),
6511        ..Browsers::default()
6512      },
6513    );
6514    prefix_test(
6515      r#"
6516      .foo {
6517        place-items: flex-end center;
6518      }
6519    "#,
6520      indoc! {r#"
6521      .foo {
6522        -webkit-box-align: end;
6523        -moz-box-align: end;
6524        -ms-flex-align: end;
6525        -webkit-align-items: flex-end;
6526        align-items: flex-end;
6527        justify-items: center;
6528      }
6529    "#},
6530      Browsers {
6531        safari: Some(4 << 16),
6532        firefox: Some(4 << 16),
6533        ie: Some(10 << 16),
6534        ..Browsers::default()
6535      },
6536    );
6537    prefix_test(
6538      r#"
6539      .foo {
6540        -webkit-box-align: end;
6541        -moz-box-align: end;
6542        -ms-flex-align: end;
6543        -webkit-align-items: flex-end;
6544        place-items: flex-end center;
6545      }
6546    "#,
6547      indoc! {r#"
6548      .foo {
6549        place-items: flex-end center;
6550      }
6551    "#},
6552      Browsers {
6553        safari: Some(11 << 16),
6554        ..Browsers::default()
6555      },
6556    );
6557    prefix_test(
6558      r#"
6559      .foo {
6560        place-items: flex-end center;
6561      }
6562    "#,
6563      indoc! {r#"
6564      .foo {
6565        align-items: flex-end;
6566        justify-items: center;
6567      }
6568    "#},
6569      Browsers {
6570        safari: Some(10 << 16),
6571        ..Browsers::default()
6572      },
6573    );
6574    prefix_test(
6575      r#"
6576      .foo {
6577        order: 1;
6578      }
6579    "#,
6580      indoc! {r#"
6581      .foo {
6582        -webkit-box-ordinal-group: 1;
6583        -moz-box-ordinal-group: 1;
6584        -ms-flex-order: 1;
6585        -webkit-order: 1;
6586        order: 1;
6587      }
6588    "#},
6589      Browsers {
6590        safari: Some(4 << 16),
6591        firefox: Some(4 << 16),
6592        ie: Some(10 << 16),
6593        ..Browsers::default()
6594      },
6595    );
6596    prefix_test(
6597      r#"
6598      .foo {
6599        -webkit-box-ordinal-group: 1;
6600        -moz-box-ordinal-group: 1;
6601        -ms-flex-order: 1;
6602        -webkit-order: 1;
6603        order: 1;
6604      }
6605    "#,
6606      indoc! {r#"
6607      .foo {
6608        order: 1;
6609      }
6610    "#},
6611      Browsers {
6612        safari: Some(11 << 16),
6613        ..Browsers::default()
6614      },
6615    );
6616    prefix_test(
6617      r#"
6618      .foo {
6619        -ms-flex: 0 0 8%;
6620        flex: 0 0 5%;
6621      }
6622    "#,
6623      indoc! {r#"
6624      .foo {
6625        -ms-flex: 0 0 8%;
6626        flex: 0 0 5%;
6627      }
6628    "#},
6629      Browsers {
6630        safari: Some(11 << 16),
6631        ..Browsers::default()
6632      },
6633    );
6634  }
6635
6636  #[test]
6637  fn test_font() {
6638    property_range_test(&["font-stretch"], &[("-1%", None), ("calc(-1%)", Some("0%"))]);
6639    property_range_test(
6640      &["line-height"],
6641      &[("-1", None), ("calc(1 - 2)", Some("0")), ("calc(-1 + 2)", Some("1"))],
6642    );
6643    property_range_test(
6644      &["font-size", "line-height"],
6645      &[
6646        ("-1px", None),
6647        ("calc(1px - 2px)", Some("0")),
6648        ("calc(-1px + 2px)", Some("1px")),
6649        ("-1%", None),
6650        ("calc(1em - 2px)", Some("calc(1em - 2px)")),
6651        ("calc(-1%)", Some("calc(-1%)")),
6652      ],
6653    );
6654    test(
6655      r#"
6656      .foo {
6657        font-family: "Helvetica", "Times New Roman", sans-serif;
6658        font-size: 12px;
6659        font-weight: bold;
6660        font-style: italic;
6661        font-stretch: expanded;
6662        font-variant-caps: small-caps;
6663        line-height: 1.2em;
6664      }
6665    "#,
6666      indoc! {r#"
6667      .foo {
6668        font: italic small-caps bold expanded 12px / 1.2em Helvetica, Times New Roman, sans-serif;
6669      }
6670    "#
6671      },
6672    );
6673
6674    minify_test(
6675      r#"
6676      .foo {
6677        font-family: "Helvetica", "Times New Roman", sans-serif;
6678        font-size: 12px;
6679        font-weight: bold;
6680        font-style: italic;
6681        font-stretch: expanded;
6682        font-variant-caps: small-caps;
6683        line-height: 1.2em;
6684      }
6685    "#,
6686      indoc! {".foo{font:italic small-caps 700 125% 12px/1.2em Helvetica,Times New Roman,sans-serif}"
6687      },
6688    );
6689
6690    test(
6691      r#"
6692      .foo {
6693        font: 12px "Helvetica", "Times New Roman", sans-serif;
6694        line-height: 1.2em;
6695      }
6696    "#,
6697      indoc! {r#"
6698      .foo {
6699        font: 12px / 1.2em Helvetica, Times New Roman, sans-serif;
6700      }
6701    "#
6702      },
6703    );
6704
6705    test(
6706      r#"
6707      .foo {
6708        font: 12px "Helvetica", "Times New Roman", sans-serif;
6709        line-height: var(--lh);
6710      }
6711    "#,
6712      indoc! {r#"
6713      .foo {
6714        font: 12px Helvetica, Times New Roman, sans-serif;
6715        line-height: var(--lh);
6716      }
6717    "#
6718      },
6719    );
6720
6721    minify_test(
6722      r#"
6723      .foo {
6724        font-family: "Helvetica", "Times New Roman", sans-serif;
6725        font-size: 12px;
6726        font-stretch: expanded;
6727      }
6728    "#,
6729      indoc! {".foo{font-family:Helvetica,Times New Roman,sans-serif;font-size:12px;font-stretch:125%}"
6730      },
6731    );
6732
6733    test(
6734      r#"
6735      .foo {
6736        font-family: "Helvetica", "Times New Roman", sans-serif;
6737        font-size: 12px;
6738        font-weight: bold;
6739        font-style: italic;
6740        font-stretch: expanded;
6741        font-variant-caps: all-small-caps;
6742        line-height: 1.2em;
6743      }
6744    "#,
6745      indoc! {r#"
6746      .foo {
6747        font: italic bold expanded 12px / 1.2em Helvetica, Times New Roman, sans-serif;
6748        font-variant-caps: all-small-caps;
6749      }
6750    "#
6751      },
6752    );
6753
6754    minify_test(
6755      ".foo { font: normal normal 600 9px/normal Charcoal; }",
6756      ".foo{font:600 9px Charcoal}",
6757    );
6758    minify_test(
6759      ".foo { font: normal normal 500 medium/normal Charcoal; }",
6760      ".foo{font:500 medium Charcoal}",
6761    );
6762    minify_test(
6763      ".foo { font: normal normal 400 medium Charcoal; }",
6764      ".foo{font:400 medium Charcoal}",
6765    );
6766    minify_test(
6767      ".foo { font: normal normal 500 medium/10px Charcoal; }",
6768      ".foo{font:500 medium/10px Charcoal}",
6769    );
6770    minify_test(
6771      ".foo { font-family: 'sans-serif'; }",
6772      ".foo{font-family:\"sans-serif\"}",
6773    );
6774    minify_test(".foo { font-family: sans-serif; }", ".foo{font-family:sans-serif}");
6775    minify_test(".foo { font-family: 'default'; }", ".foo{font-family:\"default\"}");
6776    minify_test(".foo { font-family: default; }", ".foo{font-family:default}");
6777    minify_test(".foo { font-family: 'inherit'; }", ".foo{font-family:\"inherit\"}");
6778    minify_test(".foo { font-family: inherit; }", ".foo{font-family:inherit}");
6779    minify_test(".foo { font-family: inherit test; }", ".foo{font-family:inherit test}");
6780    minify_test(
6781      ".foo { font-family: 'inherit test'; }",
6782      ".foo{font-family:inherit test}",
6783    );
6784    minify_test(".foo { font-family: revert; }", ".foo{font-family:revert}");
6785    minify_test(".foo { font-family: 'revert'; }", ".foo{font-family:\"revert\"}");
6786    minify_test(".foo { font-family: revert-layer; }", ".foo{font-family:revert-layer}");
6787    minify_test(
6788      ".foo { font-family: revert-layer, serif; }",
6789      ".foo{font-family:revert-layer,serif}",
6790    );
6791    minify_test(
6792      ".foo { font-family: 'revert', sans-serif; }",
6793      ".foo{font-family:\"revert\",sans-serif}",
6794    );
6795    minify_test(
6796      ".foo { font-family: 'revert', foo, sans-serif; }",
6797      ".foo{font-family:\"revert\",foo,sans-serif}",
6798    );
6799    minify_test(".foo { font-family: ''; }", ".foo{font-family:\"\"}");
6800
6801    // font-family in @font-face
6802    minify_test(
6803      "@font-face { font-family: 'revert'; }",
6804      "@font-face{font-family:\"revert\"}",
6805    );
6806    minify_test(
6807      "@font-face { font-family: 'revert-layer'; }",
6808      "@font-face{font-family:\"revert-layer\"}",
6809    );
6810
6811    prefix_test(
6812      r#"
6813      .foo {
6814        font-family: Helvetica, system-ui, sans-serif;
6815      }
6816    "#,
6817      indoc! {r#"
6818      .foo {
6819        font-family: Helvetica, system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Noto Sans, Ubuntu, Cantarell, Helvetica Neue, sans-serif;
6820      }
6821    "#
6822      },
6823      Browsers {
6824        safari: Some(8 << 16),
6825        ..Browsers::default()
6826      },
6827    );
6828
6829    prefix_test(
6830      r#"
6831      .foo {
6832        font: 100%/1.5 Helvetica, system-ui, sans-serif;
6833      }
6834    "#,
6835      indoc! {r#"
6836      .foo {
6837        font: 100% / 1.5 Helvetica, system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Noto Sans, Ubuntu, Cantarell, Helvetica Neue, sans-serif;
6838      }
6839    "#
6840      },
6841      Browsers {
6842        safari: Some(8 << 16),
6843        ..Browsers::default()
6844      },
6845    );
6846
6847    prefix_test(
6848      r#"
6849      .foo {
6850        font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
6851      }
6852    "#,
6853      indoc! {r#"
6854      .foo {
6855        font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Noto Sans, Ubuntu, Cantarell, Helvetica Neue, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji;
6856      }
6857    "#
6858      },
6859      Browsers {
6860        firefox: Some(91 << 16),
6861        ..Browsers::default()
6862      },
6863    );
6864
6865    prefix_test(
6866      r#"
6867      .foo {
6868        font-size: 22px;
6869        font-size: max(2cqw, 22px);
6870      }
6871    "#,
6872      indoc! {r#"
6873      .foo {
6874        font-size: 22px;
6875        font-size: max(2cqw, 22px);
6876      }
6877    "#
6878      },
6879      Browsers {
6880        safari: Some(14 << 16),
6881        ..Browsers::default()
6882      },
6883    );
6884    prefix_test(
6885      r#"
6886      .foo {
6887        font-size: 22px;
6888        font-size: max(2cqw, 22px);
6889      }
6890    "#,
6891      indoc! {r#"
6892      .foo {
6893        font-size: max(2cqw, 22px);
6894      }
6895    "#
6896      },
6897      Browsers {
6898        safari: Some(16 << 16),
6899        ..Browsers::default()
6900      },
6901    );
6902
6903    prefix_test(
6904      r#"
6905      .foo {
6906        font-size: 22px;
6907        font-size: xxx-large;
6908      }
6909    "#,
6910      indoc! {r#"
6911      .foo {
6912        font-size: 22px;
6913        font-size: xxx-large;
6914      }
6915    "#
6916      },
6917      Browsers {
6918        chrome: Some(70 << 16),
6919        ..Browsers::default()
6920      },
6921    );
6922    prefix_test(
6923      r#"
6924      .foo {
6925        font-size: 22px;
6926        font-size: xxx-large;
6927      }
6928    "#,
6929      indoc! {r#"
6930      .foo {
6931        font-size: xxx-large;
6932      }
6933    "#
6934      },
6935      Browsers {
6936        chrome: Some(80 << 16),
6937        ..Browsers::default()
6938      },
6939    );
6940
6941    prefix_test(
6942      r#"
6943      .foo {
6944        font-weight: 700;
6945        font-weight: 789;
6946      }
6947    "#,
6948      indoc! {r#"
6949      .foo {
6950        font-weight: 700;
6951        font-weight: 789;
6952      }
6953    "#
6954      },
6955      Browsers {
6956        chrome: Some(60 << 16),
6957        ..Browsers::default()
6958      },
6959    );
6960    prefix_test(
6961      r#"
6962      .foo {
6963        font-weight: 700;
6964        font-weight: 789;
6965      }
6966    "#,
6967      indoc! {r#"
6968      .foo {
6969        font-weight: 789;
6970      }
6971    "#
6972      },
6973      Browsers {
6974        chrome: Some(80 << 16),
6975        ..Browsers::default()
6976      },
6977    );
6978
6979    prefix_test(
6980      r#"
6981      .foo {
6982        font-family: Helvetica;
6983        font-family: system-ui;
6984      }
6985    "#,
6986      indoc! {r#"
6987      .foo {
6988        font-family: Helvetica;
6989        font-family: system-ui;
6990      }
6991    "#
6992      },
6993      Browsers {
6994        chrome: Some(50 << 16),
6995        ..Browsers::default()
6996      },
6997    );
6998    prefix_test(
6999      r#"
7000      .foo {
7001        font-family: Helvetica;
7002        font-family: system-ui;
7003      }
7004    "#,
7005      indoc! {r#"
7006      .foo {
7007        font-family: system-ui;
7008      }
7009    "#
7010      },
7011      Browsers {
7012        chrome: Some(80 << 16),
7013        ..Browsers::default()
7014      },
7015    );
7016
7017    prefix_test(
7018      r#"
7019      .foo {
7020        font-style: oblique;
7021        font-style: oblique 40deg;
7022      }
7023    "#,
7024      indoc! {r#"
7025      .foo {
7026        font-style: oblique;
7027        font-style: oblique 40deg;
7028      }
7029    "#
7030      },
7031      Browsers {
7032        firefox: Some(50 << 16),
7033        ..Browsers::default()
7034      },
7035    );
7036    prefix_test(
7037      r#"
7038      .foo {
7039        font-style: oblique;
7040        font-style: oblique 40deg;
7041      }
7042    "#,
7043      indoc! {r#"
7044      .foo {
7045        font-style: oblique 40deg;
7046      }
7047    "#
7048      },
7049      Browsers {
7050        firefox: Some(80 << 16),
7051        ..Browsers::default()
7052      },
7053    );
7054
7055    prefix_test(
7056      r#"
7057      .foo {
7058        font: 22px Helvetica;
7059        font: xxx-large system-ui;
7060      }
7061    "#,
7062      indoc! {r#"
7063      .foo {
7064        font: 22px Helvetica;
7065        font: xxx-large system-ui;
7066      }
7067    "#
7068      },
7069      Browsers {
7070        chrome: Some(70 << 16),
7071        ..Browsers::default()
7072      },
7073    );
7074    prefix_test(
7075      r#"
7076      .foo {
7077        font: 22px Helvetica;
7078        font: xxx-large system-ui;
7079      }
7080    "#,
7081      indoc! {r#"
7082      .foo {
7083        font: xxx-large system-ui;
7084      }
7085    "#
7086      },
7087      Browsers {
7088        chrome: Some(80 << 16),
7089        ..Browsers::default()
7090      },
7091    );
7092
7093    prefix_test(
7094      r#"
7095      .foo {
7096        font: var(--fallback);
7097        font: xxx-large system-ui;
7098      }
7099    "#,
7100      indoc! {r#"
7101      .foo {
7102        font: var(--fallback);
7103        font: xxx-large system-ui;
7104      }
7105    "#
7106      },
7107      Browsers {
7108        chrome: Some(50 << 16),
7109        ..Browsers::default()
7110      },
7111    );
7112  }
7113
7114  #[test]
7115  fn test_vertical_align() {
7116    minify_test(".foo { vertical-align: middle }", ".foo{vertical-align:middle}");
7117    minify_test(".foo { vertical-align: 0.3em }", ".foo{vertical-align:.3em}");
7118  }
7119
7120  #[test]
7121  fn test_selectors() {
7122    minify_test(":nth-col(2n) {width: 20px}", ":nth-col(2n){width:20px}");
7123    minify_test(":nth-col(10n-1) {width: 20px}", ":nth-col(10n-1){width:20px}");
7124    minify_test(":nth-col(-n+2) {width: 20px}", ":nth-col(-n+2){width:20px}");
7125    minify_test(":nth-col(even) {width: 20px}", ":nth-col(2n){width:20px}");
7126    minify_test(":nth-col(odd) {width: 20px}", ":nth-col(odd){width:20px}");
7127    minify_test(":nth-last-col(2n) {width: 20px}", ":nth-last-col(2n){width:20px}");
7128    minify_test(":nth-last-col(10n-1) {width: 20px}", ":nth-last-col(10n-1){width:20px}");
7129    minify_test(":nth-last-col(-n+2) {width: 20px}", ":nth-last-col(-n+2){width:20px}");
7130    minify_test(":nth-last-col(even) {width: 20px}", ":nth-last-col(2n){width:20px}");
7131    minify_test(":nth-last-col(odd) {width: 20px}", ":nth-last-col(odd){width:20px}");
7132    minify_test(":nth-child(odd) {width: 20px}", ":nth-child(odd){width:20px}");
7133    minify_test(":nth-child(2n) {width: 20px}", ":nth-child(2n){width:20px}");
7134    minify_test(":nth-child(2n+1) {width: 20px}", ":nth-child(odd){width:20px}");
7135    minify_test(":first-child {width: 20px}", ":first-child{width:20px}");
7136    minify_test(":nth-child(1) {width: 20px}", ":first-child{width:20px}");
7137    minify_test(":nth-last-child(1) {width: 20px}", ":last-child{width:20px}");
7138    minify_test(":nth-of-type(1) {width: 20px}", ":first-of-type{width:20px}");
7139    minify_test(":nth-last-of-type(1) {width: 20px}", ":last-of-type{width:20px}");
7140    minify_test(
7141      ":nth-child(even of li.important) {width: 20px}",
7142      ":nth-child(2n of li.important){width:20px}",
7143    );
7144    minify_test(
7145      ":nth-child(1 of li.important) {width: 20px}",
7146      ":nth-child(1 of li.important){width:20px}",
7147    );
7148    minify_test(
7149      ":nth-last-child(even of li.important) {width: 20px}",
7150      ":nth-last-child(2n of li.important){width:20px}",
7151    );
7152    minify_test(
7153      ":nth-last-child(1 of li.important) {width: 20px}",
7154      ":nth-last-child(1 of li.important){width:20px}",
7155    );
7156    minify_test(
7157      ":nth-last-child(1 of.important) {width: 20px}",
7158      ":nth-last-child(1 of .important){width:20px}",
7159    );
7160
7161    minify_test("[foo=\"baz\"] {color:red}", "[foo=baz]{color:red}");
7162    minify_test("[foo=\"foo bar\"] {color:red}", "[foo=foo\\ bar]{color:red}");
7163    minify_test("[foo=\"foo bar baz\"] {color:red}", "[foo=\"foo bar baz\"]{color:red}");
7164    minify_test("[foo=\"\"] {color:red}", "[foo=\"\"]{color:red}");
7165    minify_test(
7166      ".test:not([foo=\"bar\"]) {color:red}",
7167      ".test:not([foo=bar]){color:red}",
7168    );
7169    minify_test(".test + .foo {color:red}", ".test+.foo{color:red}");
7170    minify_test(".test ~ .foo {color:red}", ".test~.foo{color:red}");
7171    minify_test(".test .foo {color:red}", ".test .foo{color:red}");
7172    minify_test(
7173      ".custom-range::-webkit-slider-thumb:active {color:red}",
7174      ".custom-range::-webkit-slider-thumb:active{color:red}",
7175    );
7176    minify_test(".test:not(.foo, .bar) {color:red}", ".test:not(.foo,.bar){color:red}");
7177    minify_test(".test:is(.foo, .bar) {color:red}", ".test:is(.foo,.bar){color:red}");
7178    minify_test(
7179      ".test:where(.foo, .bar) {color:red}",
7180      ".test:where(.foo,.bar){color:red}",
7181    );
7182    minify_test(
7183      ".test:where(.foo, .bar) {color:red}",
7184      ".test:where(.foo,.bar){color:red}",
7185    );
7186
7187    // Test scroll navigation controls pseudo-classes
7188    let scroll_navigation_controls_options = ParserOptions {
7189      flags: ParserFlags::SCROLL_NAVIGATION_CONTROLS,
7190      ..ParserOptions::default()
7191    };
7192    minify_test_with_options(
7193      "a:target-current { color: green }",
7194      "a:target-current{color:green}",
7195      scroll_navigation_controls_options.clone(),
7196    );
7197    minify_test_with_options(
7198      "a:target-before { color: green }",
7199      "a:target-before{color:green}",
7200      scroll_navigation_controls_options.clone(),
7201    );
7202    minify_test_with_options(
7203      "a:target-after { color: green }",
7204      "a:target-after{color:green}",
7205      scroll_navigation_controls_options.clone(),
7206    );
7207    minify_test_with_options(
7208      ":is(a:target-before, a:target-after) { color: green }",
7209      ":is(a:target-before,a:target-after){color:green}",
7210      scroll_navigation_controls_options.clone(),
7211    );
7212    minify_test_with_options(
7213      "a:where(:target-before, :target-after) { color: green }",
7214      "a:where(:target-before,:target-after){color:green}",
7215      scroll_navigation_controls_options.clone(),
7216    );
7217    // If the browser does not support it, it will output the `:is()` selector.
7218    minify_test_with_options_and_browsers(
7219      "a:target-before, a:target-after { color: green }",
7220      ":is(a:target-before,a:target-after){color:green}",
7221      scroll_navigation_controls_options.clone(),
7222      Some(Browsers {
7223        chrome: Some(130 << 16),
7224        ..Browsers::default()
7225      }),
7226    );
7227    minify_test_with_options_and_browsers(
7228      "a:target-before, a:target-after { color: green }",
7229      "a:target-before,a:target-after{color:green}",
7230      scroll_navigation_controls_options.clone(),
7231      Some(Browsers {
7232        chrome: Some(150 << 16),
7233        ..Browsers::default()
7234      }),
7235    );
7236
7237    error_test_with_options(
7238      "a::before:target-current { color: green }",
7239      ParserError::SelectorError(SelectorError::InvalidPseudoClassAfterPseudoElement),
7240      ParserOptions {
7241        flags: ParserFlags::SCROLL_NAVIGATION_CONTROLS,
7242        ..ParserOptions::default()
7243      },
7244    );
7245
7246    let warnings = Some(Arc::new(RwLock::new(Vec::new())));
7247    let _ = StyleSheet::parse(
7248      "a:target-current { color: green }",
7249      ParserOptions {
7250        warnings: warnings.clone(),
7251        ..ParserOptions::default()
7252      },
7253    )
7254    .unwrap();
7255    let warnings = Arc::try_unwrap(warnings.unwrap()).unwrap().into_inner().unwrap();
7256    assert_eq!(warnings.len(), 1);
7257    assert_eq!(
7258      warnings[0].kind,
7259      ParserError::SelectorError(SelectorError::UnsupportedPseudoClass("target-current".into()))
7260    );
7261
7262    minify_test(":host {color:red}", ":host{color:red}");
7263    minify_test(":host(.foo) {color:red}", ":host(.foo){color:red}");
7264    minify_test("::slotted(span) {color:red", "::slotted(span){color:red}");
7265    minify_test(
7266      "custom-element::part(foo) {color:red}",
7267      "custom-element::part(foo){color:red}",
7268    );
7269    minify_test(".sm\\:text-5xl { font-size: 3rem }", ".sm\\:text-5xl{font-size:3rem}");
7270    minify_test("a:has(> img) {color:red}", "a:has(>img){color:red}");
7271    minify_test("dt:has(+ dt) {color:red}", "dt:has(+dt){color:red}");
7272    minify_test(
7273      "section:not(:has(h1, h2, h3, h4, h5, h6)) {color:red}",
7274      "section:not(:has(h1,h2,h3,h4,h5,h6)){color:red}",
7275    );
7276    minify_test(
7277      ":has(.sibling ~ .target) {color:red}",
7278      ":has(.sibling~.target){color:red}",
7279    );
7280    minify_test(".x:has(> .a > .b) {color:red}", ".x:has(>.a>.b){color:red}");
7281    minify_test(".x:has(.bar, #foo) {color:red}", ".x:has(.bar,#foo){color:red}");
7282    minify_test(".x:has(span + span) {color:red}", ".x:has(span+span){color:red}");
7283    minify_test("a:has(:visited) {color:red}", "a:has(:visited){color:red}");
7284    for element in [
7285      "-webkit-scrollbar",
7286      "-webkit-scrollbar-button",
7287      "-webkit-scrollbar-track",
7288      "-webkit-scrollbar-track-piece",
7289      "-webkit-scrollbar-thumb",
7290      "-webkit-scrollbar-corner",
7291      "-webkit-resizer",
7292    ] {
7293      for class in [
7294        "enabled",
7295        "disabled",
7296        "hover",
7297        "active",
7298        "horizontal",
7299        "vertical",
7300        "decrement",
7301        "increment",
7302        "start",
7303        "end",
7304        "double-button",
7305        "single-button",
7306        "no-button",
7307        "corner-present",
7308        "window-inactive",
7309      ] {
7310        minify_test(
7311          &format!("::{}:{} {{color:red}}", element, class),
7312          &format!("::{}:{}{{color:red}}", element, class),
7313        );
7314      }
7315    }
7316    for class in [
7317      "horizontal",
7318      "vertical",
7319      "decrement",
7320      "increment",
7321      "start",
7322      "end",
7323      "double-button",
7324      "single-button",
7325      "no-button",
7326      "corner-present",
7327      "window-inactive",
7328    ] {
7329      error_test(
7330        &format!(":{} {{color:red}}", class),
7331        ParserError::SelectorError(SelectorError::InvalidPseudoClassBeforeWebKitScrollbar),
7332      );
7333    }
7334    for element in [
7335      "-webkit-scrollbar",
7336      "-webkit-scrollbar-button",
7337      "-webkit-scrollbar-track",
7338      "-webkit-scrollbar-track-piece",
7339      "-webkit-scrollbar-thumb",
7340      "-webkit-scrollbar-corner",
7341      "-webkit-resizer",
7342    ] {
7343      error_test(
7344        &format!("::{}:focus {{color:red}}", element),
7345        ParserError::SelectorError(SelectorError::InvalidPseudoClassAfterWebKitScrollbar),
7346      );
7347    }
7348
7349    error_test(
7350      "a::first-letter:last-child {color:red}",
7351      ParserError::SelectorError(SelectorError::InvalidPseudoClassAfterPseudoElement),
7352    );
7353    minify_test(
7354      "a:last-child::first-letter {color:red}",
7355      "a:last-child:first-letter{color:red}",
7356    );
7357
7358    prefix_test(
7359      ".test:not(.foo, .bar) {color:red}",
7360      indoc! {r#"
7361      .test:not(:-webkit-any(.foo, .bar)) {
7362        color: red;
7363      }
7364
7365      .test:not(:is(.foo, .bar)) {
7366        color: red;
7367      }
7368      "#},
7369      Browsers {
7370        safari: Some(8 << 16),
7371        ..Browsers::default()
7372      },
7373    );
7374    prefix_test(
7375      ".test:not(.foo, .bar) {color:red}",
7376      indoc! {r#"
7377      .test:not(.foo, .bar) {
7378        color: red;
7379      }
7380      "#},
7381      Browsers {
7382        safari: Some(11 << 16),
7383        ..Browsers::default()
7384      },
7385    );
7386
7387    minify_test("a:lang(en) {color:red}", "a:lang(en){color:red}");
7388    minify_test("a:lang(en, fr) {color:red}", "a:lang(en,fr){color:red}");
7389    minify_test("a:lang('en') {color:red}", "a:lang(en){color:red}");
7390    minify_test(
7391      "a:-webkit-any(.foo, .bar) {color:red}",
7392      "a:-webkit-any(.foo,.bar){color:red}",
7393    );
7394    minify_test("a:-moz-any(.foo, .bar) {color:red}", "a:-moz-any(.foo,.bar){color:red}");
7395
7396    prefix_test(
7397      "a:is(.foo, .bar) {color:red}",
7398      indoc! {r#"
7399      a:-webkit-any(.foo, .bar) {
7400        color: red;
7401      }
7402
7403      a:-moz-any(.foo, .bar) {
7404        color: red;
7405      }
7406
7407      a:is(.foo, .bar) {
7408        color: red;
7409      }
7410      "#},
7411      Browsers {
7412        safari: Some(11 << 16),
7413        firefox: Some(50 << 16),
7414        ..Browsers::default()
7415      },
7416    );
7417
7418    prefix_test(
7419      "a:is(.foo > .bar) {color:red}",
7420      indoc! {r#"
7421      a:is(.foo > .bar) {
7422        color: red;
7423      }
7424      "#},
7425      Browsers {
7426        safari: Some(11 << 16),
7427        firefox: Some(50 << 16),
7428        ..Browsers::default()
7429      },
7430    );
7431
7432    prefix_test(
7433      "a:lang(en, fr) {color:red}",
7434      indoc! {r#"
7435      a:-webkit-any(:lang(en), :lang(fr)) {
7436        color: red;
7437      }
7438
7439      a:-moz-any(:lang(en), :lang(fr)) {
7440        color: red;
7441      }
7442
7443      a:is(:lang(en), :lang(fr)) {
7444        color: red;
7445      }
7446      "#},
7447      Browsers {
7448        safari: Some(11 << 16),
7449        firefox: Some(50 << 16),
7450        ..Browsers::default()
7451      },
7452    );
7453
7454    prefix_test(
7455      "a:lang(en, fr) {color:red}",
7456      indoc! {r#"
7457      a:is(:lang(en), :lang(fr)) {
7458        color: red;
7459      }
7460      "#},
7461      Browsers {
7462        safari: Some(14 << 16),
7463        firefox: Some(88 << 16),
7464        ..Browsers::default()
7465      },
7466    );
7467
7468    prefix_test(
7469      "a:lang(en, fr) {color:red}",
7470      indoc! {r#"
7471      a:lang(en, fr) {
7472        color: red;
7473      }
7474      "#},
7475      Browsers {
7476        safari: Some(14 << 16),
7477        ..Browsers::default()
7478      },
7479    );
7480
7481    prefix_test(
7482      "a:dir(rtl) {color:red}",
7483      indoc! {r#"
7484      a:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
7485        color: red;
7486      }
7487
7488      a:-moz-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
7489        color: red;
7490      }
7491
7492      a:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
7493        color: red;
7494      }
7495      "#},
7496      Browsers {
7497        safari: Some(11 << 16),
7498        firefox: Some(50 << 16),
7499        ..Browsers::default()
7500      },
7501    );
7502
7503    prefix_test(
7504      "a:dir(ltr) {color:red}",
7505      indoc! {r#"
7506      a:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
7507        color: red;
7508      }
7509
7510      a:not(:-moz-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
7511        color: red;
7512      }
7513
7514      a:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
7515        color: red;
7516      }
7517      "#},
7518      Browsers {
7519        safari: Some(11 << 16),
7520        firefox: Some(50 << 16),
7521        ..Browsers::default()
7522      },
7523    );
7524
7525    prefix_test(
7526      "a:dir(rtl) {color:red}",
7527      indoc! {r#"
7528      a:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
7529        color: red;
7530      }
7531      "#},
7532      Browsers {
7533        safari: Some(14 << 16),
7534        firefox: Some(88 << 16),
7535        ..Browsers::default()
7536      },
7537    );
7538
7539    prefix_test(
7540      "a:dir(ltr) {color:red}",
7541      indoc! {r#"
7542      a:not(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
7543        color: red;
7544      }
7545      "#},
7546      Browsers {
7547        safari: Some(14 << 16),
7548        firefox: Some(88 << 16),
7549        ..Browsers::default()
7550      },
7551    );
7552
7553    prefix_test(
7554      "a:dir(rtl) {color:red}",
7555      indoc! {r#"
7556      a:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
7557        color: red;
7558      }
7559      "#},
7560      Browsers {
7561        safari: Some(14 << 16),
7562        ..Browsers::default()
7563      },
7564    );
7565
7566    prefix_test(
7567      "a:dir(ltr) {color:red}",
7568      indoc! {r#"
7569      a:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
7570        color: red;
7571      }
7572      "#},
7573      Browsers {
7574        safari: Some(14 << 16),
7575        ..Browsers::default()
7576      },
7577    );
7578
7579    prefix_test(
7580      "a:is(:dir(rtl)) {color:red}",
7581      indoc! {r#"
7582      a:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
7583        color: red;
7584      }
7585      "#},
7586      Browsers {
7587        safari: Some(14 << 16),
7588        ..Browsers::default()
7589      },
7590    );
7591
7592    prefix_test(
7593      "a:where(:dir(rtl)) {color:red}",
7594      indoc! {r#"
7595      a:where(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
7596        color: red;
7597      }
7598      "#},
7599      Browsers {
7600        safari: Some(14 << 16),
7601        ..Browsers::default()
7602      },
7603    );
7604
7605    prefix_test(
7606      "a:has(:dir(rtl)) {color:red}",
7607      indoc! {r#"
7608      a:has(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
7609        color: red;
7610      }
7611      "#},
7612      Browsers {
7613        safari: Some(14 << 16),
7614        ..Browsers::default()
7615      },
7616    );
7617
7618    prefix_test(
7619      "a:not(:dir(rtl)) {color:red}",
7620      indoc! {r#"
7621      a:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
7622        color: red;
7623      }
7624      "#},
7625      Browsers {
7626        safari: Some(14 << 16),
7627        ..Browsers::default()
7628      },
7629    );
7630
7631    prefix_test(
7632      "a:dir(rtl)::after {color:red}",
7633      indoc! {r#"
7634      a:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi):after {
7635        color: red;
7636      }
7637      "#},
7638      Browsers {
7639        safari: Some(14 << 16),
7640        ..Browsers::default()
7641      },
7642    );
7643
7644    prefix_test(
7645      "a:dir(rtl) div {color:red}",
7646      indoc! {r#"
7647      a:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) div {
7648        color: red;
7649      }
7650      "#},
7651      Browsers {
7652        safari: Some(14 << 16),
7653        ..Browsers::default()
7654      },
7655    );
7656
7657    minify_test(".foo::cue {color: red}", ".foo::cue{color:red}");
7658    minify_test(".foo::cue-region {color: red}", ".foo::cue-region{color:red}");
7659    minify_test(".foo::cue(b) {color: red}", ".foo::cue(b){color:red}");
7660    minify_test(".foo::cue-region(b) {color: red}", ".foo::cue-region(b){color:red}");
7661    minify_test(
7662      "::cue(v[voice='active']) {color: yellow;}",
7663      "::cue(v[voice=active]){color:#ff0}",
7664    );
7665    minify_test(":foo(bar) { color: yellow }", ":foo(bar){color:#ff0}");
7666    minify_test("::foo(bar) { color: yellow }", "::foo(bar){color:#ff0}");
7667    minify_test("::foo(*) { color: yellow }", "::foo(*){color:#ff0}");
7668
7669    minify_test(":is(.foo) { color: yellow }", ".foo{color:#ff0}");
7670    minify_test(":is(#foo) { color: yellow }", "#foo{color:#ff0}");
7671    minify_test("a:is(.foo) { color: yellow }", "a.foo{color:#ff0}");
7672    minify_test("a:is([data-test]) { color: yellow }", "a[data-test]{color:#ff0}");
7673    minify_test(".foo:is(a) { color: yellow }", ".foo:is(a){color:#ff0}");
7674    minify_test(".foo:is(*|a) { color: yellow }", ".foo:is(*|a){color:#ff0}");
7675    minify_test(".foo:is(*) { color: yellow }", ".foo:is(*){color:#ff0}");
7676    minify_test(
7677      "@namespace svg url(http://www.w3.org/2000/svg); .foo:is(svg|a) { color: yellow }",
7678      "@namespace svg \"http://www.w3.org/2000/svg\";.foo:is(svg|a){color:#ff0}",
7679    );
7680    minify_test("a:is(.foo .bar) { color: yellow }", "a:is(.foo .bar){color:#ff0}");
7681    minify_test(":is(.foo, .bar) { color: yellow }", ":is(.foo,.bar){color:#ff0}");
7682    minify_test("a:is(:not(.foo)) { color: yellow }", "a:not(.foo){color:#ff0}");
7683    minify_test("a:is(:first-child) { color: yellow }", "a:first-child{color:#ff0}");
7684    minify_test("a:is(:has(.foo)) { color: yellow }", "a:has(.foo){color:#ff0}");
7685    minify_test("a:is(:is(.foo)) { color: yellow }", "a.foo{color:#ff0}");
7686    minify_test(":host(:hover) {color: red}", ":host(:hover){color:red}");
7687    minify_test("::slotted(:hover) {color: red}", "::slotted(:hover){color:red}");
7688
7689    minify_test(
7690      ":root::view-transition {position: fixed}",
7691      ":root::view-transition{position:fixed}",
7692    );
7693    minify_test(
7694      ":root:active-view-transition {position: fixed}",
7695      ":root:active-view-transition{position:fixed}",
7696    );
7697    minify_test(
7698      ":root:active-view-transition-type(slide-in) {position: fixed}",
7699      ":root:active-view-transition-type(slide-in){position:fixed}",
7700    );
7701    minify_test(
7702      ":root:active-view-transition-type(slide-in, reverse) {position: fixed}",
7703      ":root:active-view-transition-type(slide-in,reverse){position:fixed}",
7704    );
7705
7706    for name in &[
7707      "view-transition-group",
7708      "view-transition-image-pair",
7709      "view-transition-new",
7710      "view-transition-old",
7711    ] {
7712      minify_test(
7713        &format!(":root::{}(*) {{position: fixed}}", name),
7714        &format!(":root::{}(*){{position:fixed}}", name),
7715      );
7716      minify_test(
7717        &format!(":root::{}(*.class) {{position: fixed}}", name),
7718        &format!(":root::{}(*.class){{position:fixed}}", name),
7719      );
7720      minify_test(
7721        &format!(":root::{}(*.class.class) {{position: fixed}}", name),
7722        &format!(":root::{}(*.class.class){{position:fixed}}", name),
7723      );
7724      minify_test(
7725        &format!(":root::{}(foo) {{position: fixed}}", name),
7726        &format!(":root::{}(foo){{position:fixed}}", name),
7727      );
7728      minify_test(
7729        &format!(":root::{}(foo.class) {{position: fixed}}", name),
7730        &format!(":root::{}(foo.class){{position:fixed}}", name),
7731      );
7732      minify_test(
7733        &format!(":root::{}(foo.bar.baz) {{position: fixed}}", name),
7734        &format!(":root::{}(foo.bar.baz){{position:fixed}}", name),
7735      );
7736      minify_test(
7737        &format!(":root::{}(foo):only-child {{position: fixed}}", name),
7738        &format!(":root::{}(foo):only-child{{position:fixed}}", name),
7739      );
7740      minify_test(
7741        &format!(":root::{}(foo.bar.baz):only-child {{position: fixed}}", name),
7742        &format!(":root::{}(foo.bar.baz):only-child{{position:fixed}}", name),
7743      );
7744      minify_test(
7745        &format!(":root::{}(.foo) {{position: fixed}}", name),
7746        &format!(":root::{}(.foo){{position:fixed}}", name),
7747      );
7748      minify_test(
7749        &format!(":root::{}(.foo.bar) {{position: fixed}}", name),
7750        &format!(":root::{}(.foo.bar){{position:fixed}}", name),
7751      );
7752      minify_test(
7753        &format!(":root::{}(  .foo.bar  ) {{position: fixed}}", name),
7754        &format!(":root::{}(.foo.bar){{position:fixed}}", name),
7755      );
7756      error_test(
7757        &format!(":root::{}(foo):first-child {{position: fixed}}", name),
7758        ParserError::SelectorError(SelectorError::InvalidPseudoClassAfterPseudoElement),
7759      );
7760      error_test(
7761        &format!(":root::{}(foo)::before {{position: fixed}}", name),
7762        ParserError::SelectorError(SelectorError::InvalidState),
7763      );
7764      error_test(
7765        &format!(":root::{}(*.*) {{position: fixed}}", name),
7766        ParserError::SelectorError(SelectorError::InvalidState),
7767      );
7768      error_test(
7769        &format!(":root::{}(*. cls) {{position: fixed}}", name),
7770        ParserError::SelectorError(SelectorError::InvalidState),
7771      );
7772      error_test(
7773        &format!(":root::{}(foo .bar) {{position: fixed}}", name),
7774        ParserError::SelectorError(SelectorError::InvalidState),
7775      );
7776      error_test(
7777        &format!(":root::{}(*.cls. c) {{position: fixed}}", name),
7778        ParserError::SelectorError(SelectorError::InvalidState),
7779      );
7780      error_test(
7781        &format!(":root::{}(*.cls>cls) {{position: fixed}}", name),
7782        ParserError::SelectorError(SelectorError::InvalidState),
7783      );
7784      error_test(
7785        &format!(":root::{}(*.cls.foo.*) {{position: fixed}}", name),
7786        ParserError::SelectorError(SelectorError::InvalidState),
7787      );
7788    }
7789    minify_test(
7790      "wa-checkbox:state(disabled) {color:red}",
7791      "wa-checkbox:state(disabled){color:red}",
7792    );
7793    minify_test(
7794      "button:state(checked) {background:blue}",
7795      "button:state(checked){background:#00f}",
7796    );
7797    minify_test(
7798      "input:state(custom-state) {border:1px solid}",
7799      "input:state(custom-state){border:1px solid}",
7800    );
7801    minify_test(
7802      "button:active:not(:state(disabled))::part(control) {border:1px solid}",
7803      "button:active:not(:state(disabled))::part(control){border:1px solid}",
7804    );
7805    // Test nested CSS with :state() selector
7806    nesting_test(
7807      r#"
7808        custom-element {
7809          color: blue;
7810          &:state(loading) {
7811            opacity: 0.5;
7812            & .spinner {
7813              display: block;
7814            }
7815          }
7816          &:state(error) {
7817            border: 2px solid red;
7818          }
7819        }
7820      "#,
7821      indoc! {r#"
7822        custom-element {
7823          color: #00f;
7824        }
7825
7826        custom-element:state(loading) {
7827          opacity: .5;
7828        }
7829
7830        custom-element:state(loading) .spinner {
7831          display: block;
7832        }
7833
7834        custom-element:state(error) {
7835          border: 2px solid red;
7836        }
7837      "#},
7838    );
7839    minify_test(".foo ::deep .bar {width: 20px}", ".foo ::deep .bar{width:20px}");
7840    minify_test(".foo::deep .bar {width: 20px}", ".foo::deep .bar{width:20px}");
7841    minify_test(".foo ::deep.bar {width: 20px}", ".foo ::deep.bar{width:20px}");
7842    minify_test(".foo ::unknown .bar {width: 20px}", ".foo ::unknown .bar{width:20px}");
7843    minify_test(
7844      ".foo ::unknown(foo) .bar {width: 20px}",
7845      ".foo ::unknown(foo) .bar{width:20px}",
7846    );
7847    minify_test(
7848      ".foo ::unknown:only-child {width: 20px}",
7849      ".foo ::unknown:only-child{width:20px}",
7850    );
7851    minify_test(
7852      ".foo ::unknown(.foo) .bar {width: 20px}",
7853      ".foo ::unknown(.foo) .bar{width:20px}",
7854    );
7855    minify_test(
7856      ".foo ::unknown(.foo .bar / .baz) .bar {width: 20px}",
7857      ".foo ::unknown(.foo .bar / .baz) .bar{width:20px}",
7858    );
7859    minify_test(
7860      ".foo ::unknown(something(foo)) .bar {width: 20px}",
7861      ".foo ::unknown(something(foo)) .bar{width:20px}",
7862    );
7863    minify_test(
7864      ".foo ::unknown([abc]) .bar {width: 20px}",
7865      ".foo ::unknown([abc]) .bar{width:20px}",
7866    );
7867
7868    let deep_options = ParserOptions {
7869      flags: ParserFlags::DEEP_SELECTOR_COMBINATOR,
7870      ..ParserOptions::default()
7871    };
7872
7873    error_test(
7874      ".foo >>> .bar {width: 20px}",
7875      ParserError::SelectorError(SelectorError::DanglingCombinator),
7876    );
7877    error_test(
7878      ".foo /deep/ .bar {width: 20px}",
7879      ParserError::SelectorError(SelectorError::DanglingCombinator),
7880    );
7881    minify_test_with_options(
7882      ".foo >>> .bar {width: 20px}",
7883      ".foo>>>.bar{width:20px}",
7884      deep_options.clone(),
7885    );
7886    minify_test_with_options(
7887      ".foo /deep/ .bar {width: 20px}",
7888      ".foo /deep/ .bar{width:20px}",
7889      deep_options.clone(),
7890    );
7891
7892    let pure_css_module_options = ParserOptions {
7893      css_modules: Some(crate::css_modules::Config {
7894        pure: true,
7895        ..Default::default()
7896      }),
7897      ..ParserOptions::default()
7898    };
7899
7900    minify_error_test_with_options(
7901      "div {width: 20px}",
7902      MinifyErrorKind::ImpureCSSModuleSelector,
7903      pure_css_module_options.clone(),
7904    );
7905    minify_error_test_with_options(
7906      ":global(.foo) {width: 20px}",
7907      MinifyErrorKind::ImpureCSSModuleSelector,
7908      pure_css_module_options.clone(),
7909    );
7910    minify_error_test_with_options(
7911      "[foo=bar] {width: 20px}",
7912      MinifyErrorKind::ImpureCSSModuleSelector,
7913      pure_css_module_options.clone(),
7914    );
7915    minify_error_test_with_options(
7916      "div, .foo {width: 20px}",
7917      MinifyErrorKind::ImpureCSSModuleSelector,
7918      pure_css_module_options.clone(),
7919    );
7920    minify_test_with_options(
7921      ":local(.foo) {width: 20px}",
7922      "._8Z4fiW_foo{width:20px}",
7923      pure_css_module_options.clone(),
7924    );
7925    minify_test_with_options(
7926      "div.my-class {color: red;}",
7927      "div._8Z4fiW_my-class{color:red}",
7928      pure_css_module_options.clone(),
7929    );
7930    minify_test_with_options(
7931      "#id {color: red;}",
7932      "#_8Z4fiW_id{color:red}",
7933      pure_css_module_options.clone(),
7934    );
7935    minify_test_with_options(
7936      "a .my-class{color: red;}",
7937      "a ._8Z4fiW_my-class{color:red}",
7938      pure_css_module_options.clone(),
7939    );
7940    minify_test_with_options(
7941      ".my-class a {color: red;}",
7942      "._8Z4fiW_my-class a{color:red}",
7943      pure_css_module_options.clone(),
7944    );
7945    minify_test_with_options(
7946      ".my-class:is(a) {color: red;}",
7947      "._8Z4fiW_my-class:is(a){color:red}",
7948      pure_css_module_options.clone(),
7949    );
7950    minify_test_with_options(
7951      "div:has(.my-class) {color: red;}",
7952      "div:has(._8Z4fiW_my-class){color:red}",
7953      pure_css_module_options.clone(),
7954    );
7955    minify_test_with_options(
7956      ".foo { html &:hover { a_value: some-value; } }",
7957      "._8Z4fiW_foo{html &:hover{a_value:some-value}}",
7958      pure_css_module_options.clone(),
7959    );
7960    minify_test_with_options(
7961      ".foo { span { color: red; } }",
7962      "._8Z4fiW_foo{& span{color:red}}",
7963      pure_css_module_options.clone(),
7964    );
7965    minify_error_test_with_options(
7966      "html { .foo { span { color: red; } } }",
7967      MinifyErrorKind::ImpureCSSModuleSelector,
7968      pure_css_module_options.clone(),
7969    );
7970    minify_test_with_options(
7971      ".foo { div { span { color: red; } } }",
7972      "._8Z4fiW_foo{& div{& span{color:red}}}",
7973      pure_css_module_options.clone(),
7974    );
7975    minify_error_test_with_options(
7976      "@scope (div) { .foo { color: red } }",
7977      MinifyErrorKind::ImpureCSSModuleSelector,
7978      pure_css_module_options.clone(),
7979    );
7980    minify_error_test_with_options(
7981      "@scope (.a) to (div) { .foo { color: red } }",
7982      MinifyErrorKind::ImpureCSSModuleSelector,
7983      pure_css_module_options.clone(),
7984    );
7985    minify_error_test_with_options(
7986      "@scope (.a) to (.b) { div { color: red } }",
7987      MinifyErrorKind::ImpureCSSModuleSelector,
7988      pure_css_module_options.clone(),
7989    );
7990    minify_test_with_options(
7991      "@scope (.a) to (.b) { .foo { color: red } }",
7992      "@scope(._8Z4fiW_a) to (._8Z4fiW_b){._8Z4fiW_foo{color:red}}",
7993      pure_css_module_options.clone(),
7994    );
7995    minify_test_with_options(
7996      "/* cssmodules-pure-no-check */ :global(.foo) { color: red }",
7997      ".foo{color:red}",
7998      pure_css_module_options.clone(),
7999    );
8000    minify_test_with_options(
8001      "/*! some license */ /* cssmodules-pure-no-check */ :global(.foo) { color: red }",
8002      "/*! some license */\n.foo{color:red}",
8003      pure_css_module_options.clone(),
8004    );
8005
8006    error_test(
8007      "input.defaultCheckbox::before h1 {width: 20px}",
8008      ParserError::SelectorError(SelectorError::UnexpectedSelectorAfterPseudoElement(Token::Ident(
8009        "h1".into(),
8010      ))),
8011    );
8012    error_test(
8013      "input.defaultCheckbox::before .my-class {width: 20px}",
8014      ParserError::SelectorError(SelectorError::UnexpectedSelectorAfterPseudoElement(Token::Delim('.'))),
8015    );
8016    error_test(
8017      "input.defaultCheckbox::before.my-class {width: 20px}",
8018      ParserError::SelectorError(SelectorError::UnexpectedSelectorAfterPseudoElement(Token::Delim('.'))),
8019    );
8020    error_test(
8021      "input.defaultCheckbox::before #id {width: 20px}",
8022      ParserError::SelectorError(SelectorError::UnexpectedSelectorAfterPseudoElement(Token::IDHash(
8023        "id".into(),
8024      ))),
8025    );
8026    error_test(
8027      "input.defaultCheckbox::before#id {width: 20px}",
8028      ParserError::SelectorError(SelectorError::UnexpectedSelectorAfterPseudoElement(Token::IDHash(
8029        "id".into(),
8030      ))),
8031    );
8032    error_test(
8033      "input.defaultCheckbox::before [attr] {width: 20px}",
8034      ParserError::SelectorError(SelectorError::UnexpectedSelectorAfterPseudoElement(
8035        Token::SquareBracketBlock,
8036      )),
8037    );
8038    error_test(
8039      "input.defaultCheckbox::before[attr] {width: 20px}",
8040      ParserError::SelectorError(SelectorError::UnexpectedSelectorAfterPseudoElement(
8041        Token::SquareBracketBlock,
8042      )),
8043    );
8044  }
8045
8046  #[test]
8047  fn test_keyframes() {
8048    minify_test(
8049      r#"
8050      @keyframes "test" {
8051        100% {
8052          background: blue
8053        }
8054      }
8055    "#,
8056      "@keyframes test{to{background:#00f}}",
8057    );
8058    minify_test(
8059      r#"
8060      @keyframes test {
8061        100% {
8062          background: blue
8063        }
8064      }
8065    "#,
8066      "@keyframes test{to{background:#00f}}",
8067    );
8068
8069    // named animation range percentages
8070    minify_test(
8071      r#"
8072      @keyframes test {
8073        entry 0% {
8074          background: blue
8075        }
8076        exit 100% {
8077          background: green
8078        }
8079      }
8080    "#,
8081      "@keyframes test{entry 0%{background:#00f}exit 100%{background:green}}",
8082    );
8083
8084    // CSS-wide keywords and `none` cannot remove quotes.
8085    minify_test(
8086      r#"
8087      @keyframes "revert" {
8088        from {
8089          background: green;
8090        }
8091      }
8092    "#,
8093      "@keyframes \"revert\"{0%{background:green}}",
8094    );
8095
8096    minify_test(
8097      r#"
8098      @keyframes "none" {
8099        from {
8100          background: green;
8101        }
8102      }
8103    "#,
8104      "@keyframes \"none\"{0%{background:green}}",
8105    );
8106
8107    // named animation ranges cannot be used with to or from
8108    minify_test(
8109      r#"
8110      @keyframes test {
8111        entry to {
8112          background: blue
8113        }
8114      }
8115    "#,
8116      "@keyframes test{}",
8117    );
8118
8119    // CSS-wide keywords without quotes throws an error.
8120    error_test(
8121      r#"
8122      @keyframes revert {}
8123    "#,
8124      ParserError::UnexpectedToken(Token::Ident("revert".into())),
8125    );
8126
8127    error_test(
8128      r#"
8129      @keyframes revert-layer {}
8130    "#,
8131      ParserError::UnexpectedToken(Token::Ident("revert-layer".into())),
8132    );
8133
8134    error_test(
8135      r#"
8136      @keyframes none {}
8137    "#,
8138      ParserError::UnexpectedToken(Token::Ident("none".into())),
8139    );
8140
8141    error_test(
8142      r#"
8143      @keyframes NONE {}
8144    "#,
8145      ParserError::UnexpectedToken(Token::Ident("NONE".into())),
8146    );
8147
8148    minify_test(
8149      r#"
8150      @-webkit-keyframes test {
8151        from {
8152          background: green;
8153          background-color: red;
8154        }
8155
8156        100% {
8157          background: blue
8158        }
8159      }
8160    "#,
8161      "@-webkit-keyframes test{0%{background:red}to{background:#00f}}",
8162    );
8163    minify_test(
8164      r#"
8165      @-moz-keyframes test {
8166        from {
8167          background: green;
8168          background-color: red;
8169        }
8170
8171        100% {
8172          background: blue
8173        }
8174      }
8175    "#,
8176      "@-moz-keyframes test{0%{background:red}to{background:#00f}}",
8177    );
8178    minify_test(r#"
8179      @-webkit-keyframes test {
8180        from {
8181          background: green;
8182          background-color: red;
8183        }
8184
8185        100% {
8186          background: blue
8187        }
8188      }
8189      @-moz-keyframes test {
8190        from {
8191          background: green;
8192          background-color: red;
8193        }
8194
8195        100% {
8196          background: blue
8197        }
8198      }
8199    "#, "@-webkit-keyframes test{0%{background:red}to{background:#00f}}@-moz-keyframes test{0%{background:red}to{background:#00f}}");
8200
8201    prefix_test(
8202      r#"
8203      @keyframes test {
8204        from {
8205          background: green;
8206        }
8207        to {
8208          background: blue
8209        }
8210      }
8211    "#,
8212      indoc! { r#"
8213      @-webkit-keyframes test {
8214        from {
8215          background: green;
8216        }
8217
8218        to {
8219          background: #00f;
8220        }
8221      }
8222
8223      @-moz-keyframes test {
8224        from {
8225          background: green;
8226        }
8227
8228        to {
8229          background: #00f;
8230        }
8231      }
8232
8233      @keyframes test {
8234        from {
8235          background: green;
8236        }
8237
8238        to {
8239          background: #00f;
8240        }
8241      }
8242    "#},
8243      Browsers {
8244        safari: Some(5 << 16),
8245        firefox: Some(6 << 16),
8246        ..Browsers::default()
8247      },
8248    );
8249    prefix_test(
8250      r#"
8251      @-webkit-keyframes test {
8252        from {
8253          background: green;
8254        }
8255
8256        to {
8257          background: blue;
8258        }
8259      }
8260      @-moz-keyframes test {
8261        from {
8262          background: green;
8263        }
8264
8265        to {
8266          background: blue;
8267        }
8268      }
8269      @keyframes test {
8270        from {
8271          background: green;
8272        }
8273        to {
8274          background: blue
8275        }
8276      }
8277    "#,
8278      indoc! { r#"
8279      @keyframes test {
8280        from {
8281          background: green;
8282        }
8283
8284        to {
8285          background: #00f;
8286        }
8287      }
8288    "#},
8289      Browsers {
8290        safari: Some(10 << 16),
8291        firefox: Some(17 << 16),
8292        ..Browsers::default()
8293      },
8294    );
8295    prefix_test(
8296      r#"
8297      @-webkit-keyframes test1 {
8298        from {
8299          background: green;
8300        }
8301
8302        to {
8303          background: blue;
8304        }
8305      }
8306
8307      @-moz-keyframes test2 {
8308        from {
8309          background: green;
8310        }
8311
8312        to {
8313          background: blue;
8314        }
8315      }
8316
8317      @keyframes test3 {
8318        from {
8319          background: green;
8320        }
8321        to {
8322          background: blue
8323        }
8324      }
8325    "#,
8326      indoc! { r#"
8327      @-webkit-keyframes test1 {
8328        from {
8329          background: green;
8330        }
8331
8332        to {
8333          background: #00f;
8334        }
8335      }
8336
8337      @-moz-keyframes test2 {
8338        from {
8339          background: green;
8340        }
8341
8342        to {
8343          background: #00f;
8344        }
8345      }
8346
8347      @keyframes test3 {
8348        from {
8349          background: green;
8350        }
8351
8352        to {
8353          background: #00f;
8354        }
8355      }
8356    "#},
8357      Browsers {
8358        safari: Some(10 << 16),
8359        firefox: Some(17 << 16),
8360        ..Browsers::default()
8361      },
8362    );
8363    prefix_test(
8364      r#"
8365      @-webkit-keyframes test {
8366        from {
8367          background: green;
8368        }
8369
8370        to {
8371          background: red;
8372        }
8373      }
8374      @-moz-keyframes test {
8375        from {
8376          background: green;
8377        }
8378
8379        to {
8380          background: pink;
8381        }
8382      }
8383      @keyframes test {
8384        from {
8385          background: green;
8386        }
8387        to {
8388          background: blue
8389        }
8390      }
8391    "#,
8392      indoc! { r#"
8393      @-webkit-keyframes test {
8394        from {
8395          background: green;
8396        }
8397
8398        to {
8399          background: red;
8400        }
8401      }
8402
8403      @-moz-keyframes test {
8404        from {
8405          background: green;
8406        }
8407
8408        to {
8409          background: pink;
8410        }
8411      }
8412
8413      @keyframes test {
8414        from {
8415          background: green;
8416        }
8417
8418        to {
8419          background: #00f;
8420        }
8421      }
8422    "#},
8423      Browsers {
8424        safari: Some(10 << 16),
8425        firefox: Some(17 << 16),
8426        ..Browsers::default()
8427      },
8428    );
8429
8430    minify_test(
8431      r#"
8432      @keyframes test {
8433        100% {
8434          background: blue
8435        }
8436      }
8437
8438      @keyframes test {
8439        100% {
8440          background: red
8441        }
8442      }
8443    "#,
8444      "@keyframes test{to{background:red}}",
8445    );
8446    minify_test(
8447      r#"
8448      @keyframes test {
8449        100% {
8450          background: blue
8451        }
8452      }
8453
8454      @-webkit-keyframes test {
8455        100% {
8456          background: red
8457        }
8458      }
8459    "#,
8460      "@keyframes test{to{background:#00f}}@-webkit-keyframes test{to{background:red}}",
8461    );
8462  }
8463
8464  #[test]
8465  fn test_important() {
8466    test(
8467      r#"
8468      .foo {
8469        align-items: center;
8470        justify-items: center !important;
8471      }
8472    "#,
8473      indoc! {r#"
8474      .foo {
8475        align-items: center;
8476        justify-items: center !important;
8477      }
8478    "#},
8479    );
8480
8481    test(
8482      r#"
8483      .foo {
8484        justify-items: center !important;
8485        align-items: center;
8486      }
8487    "#,
8488      indoc! {r#"
8489      .foo {
8490        align-items: center;
8491        justify-items: center !important;
8492      }
8493    "#},
8494    );
8495
8496    minify_test(
8497      r#"
8498      .foo {
8499        font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace !important;
8500      }
8501    "#,
8502      ".foo{font-family:SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace!important}",
8503    );
8504  }
8505
8506  #[test]
8507  fn test_calc() {
8508    use crate::values::length::{Length, LengthPercentage, LengthPercentageOrAuto};
8509    use crate::values::number::NonNegative;
8510
8511    for (source, expected) in [
8512      ("calc(-5px)", "0"),
8513      ("calc(5px - 10px)", "0"),
8514      ("calc(-5px + 10px)", "5px"),
8515      ("calc(-5px * -2)", "10px"),
8516      ("calc(calc(-5px) + 10px)", "5px"),
8517      ("calc(-1em)", "0"),
8518      ("calc(1in - 100px)", "0"),
8519      ("calc(1em - 10px)", "calc(1em - 10px)"),
8520      ("min(-1em, -10px)", "min(-1em, -10px)"),
8521    ] {
8522      non_negative_test::<Length>(source, Some(expected));
8523      non_negative_test::<LengthPercentage>(source, Some(expected));
8524      non_negative_test::<LengthPercentageOrAuto>(source, Some(expected));
8525    }
8526    assert_eq!(Length::parse_string("calc(-5px)").unwrap(), Length::px(-5.0));
8527    for source in ["calc(0)", "calc(-5)", "calc(1s)"] {
8528      non_negative_test::<Length>(source, None);
8529      non_negative_test::<LengthPercentage>(source, None);
8530    }
8531    for (source, expected) in [
8532      ("calc(5%)", "5%"),
8533      ("calc(0%)", "0%"),
8534      ("calc(-5% + 10%)", "5%"),
8535      ("calc(5% - 5%)", "0%"),
8536      ("calc(100px - (100px - 100%))", "100%"),
8537    ] {
8538      non_negative_test::<LengthPercentage>(source, Some(expected));
8539      non_negative_test::<LengthPercentageOrAuto>(source, Some(expected));
8540    }
8541    // Negative percentages and unresolved calculations retain their math boundary.
8542    for source in ["calc(-5%)", "calc(100% - 10px)"] {
8543      non_negative_test::<LengthPercentage>(source, Some(source));
8544      let value = NonNegative::<LengthPercentage>::parse_string(source).unwrap();
8545      let css = value.to_css_string(PrinterOptions::default()).unwrap();
8546      assert_eq!(NonNegative::<LengthPercentage>::parse_string(&css).unwrap(), value);
8547    }
8548
8549    minify_test(".foo { width: calc(20px * 2) }", ".foo{width:40px}");
8550    minify_test(".foo { font-size: calc(100vw / 35) }", ".foo{font-size:2.85714vw}");
8551    minify_test(".foo { width: calc(20px * 2 * 3) }", ".foo{width:120px}");
8552    minify_test(".foo { width: calc(20px + 30px) }", ".foo{width:50px}");
8553    minify_test(".foo { width: calc(20px + 30px + 40px) }", ".foo{width:90px}");
8554    minify_test(".foo { width: calc(100% - 30px) }", ".foo{width:calc(100% - 30px)}");
8555    minify_test(
8556      ".foo { width: calc(100% - 30px + 20px) }",
8557      ".foo{width:calc(100% - 10px)}",
8558    );
8559    minify_test(
8560      ".foo { width: calc(20px + 100% - 30px) }",
8561      ".foo{width:calc(100% - 10px)}",
8562    );
8563    minify_test(
8564      ".foo { width: calc(20px + 100% + 10vw - 30px) }",
8565      ".foo{width:calc(100% - 10px + 10vw)}",
8566    );
8567    minify_test(
8568      ".foo { width: calc(20px + 100% - 30px) }",
8569      ".foo{width:calc(100% - 10px)}",
8570    );
8571    minify_test(
8572      ".foo { width: calc(2 * (100% - 20px)) }",
8573      ".foo{width:calc(200% - 40px)}",
8574    );
8575    minify_test(
8576      ".foo { width: calc((100% - 20px) * 2) }",
8577      ".foo{width:calc(200% - 40px)}",
8578    );
8579    minify_test(".foo { width: calc(100% - 20px * 2) }", ".foo{width:calc(100% - 40px)}");
8580    minify_test(".foo { width: calc(1px + 1px) }", ".foo{width:2px}");
8581    minify_test(".foo { width: calc(100vw / 2) }", ".foo{width:50vw}");
8582    minify_test(".foo { width: calc(50px - (20px - 30px)) }", ".foo{width:60px}");
8583    minify_test(".foo { width: calc(100px - (100px - 100%)) }", ".foo{width:100%}");
8584    minify_test(
8585      ".foo { width: calc(100px + (100px - 100%)) }",
8586      ".foo{width:calc(200px - 100%)}",
8587    );
8588    minify_test(
8589      ".foo { width: calc(1px - (2em + 3%)) }",
8590      ".foo{width:calc(1px + -2em - 3%)}",
8591    ); // TODO: fix sign
8592    minify_test(
8593      ".foo { width: calc((100vw - 50em) / 2) }",
8594      ".foo{width:calc(50vw - 25em)}",
8595    );
8596    minify_test(
8597      ".foo { width: calc(1px - (2em + 4vh + 3%)) }",
8598      ".foo{width:calc(1px + -2em - 4vh - 3%)}",
8599    ); // TODO
8600    minify_test(
8601      ".foo { width: calc(1px + (2em + (3vh + 4px))) }",
8602      ".foo{width:calc(2em + 3vh + 5px)}",
8603    );
8604    minify_test(
8605      ".foo { width: calc(1px - (2em + 4px - 6vh) / 2) }",
8606      ".foo{width:calc(-1em - 1px + 3vh)}",
8607    );
8608    minify_test(
8609      ".foo { width: calc(100% - calc(50% + 25px)) }",
8610      ".foo{width:calc(50% - 25px)}",
8611    );
8612    minify_test(".foo { width: calc(1px/100) }", ".foo{width:.01px}");
8613    minify_test(
8614      ".foo { width: calc(100vw / 2 - 6px + 0px) }",
8615      ".foo{width:calc(50vw - 6px)}",
8616    );
8617    minify_test(".foo { width: calc(1px + 1) }", ".foo{width:calc(1px + 1)}");
8618    minify_test(".foo { width: calc( (1em - calc( 10px + 1em)) / 2) }", ".foo{width:0}");
8619    minify_test(
8620      ".foo { width: calc((100px - 1em) + (-50px + 1em)) }",
8621      ".foo{width:50px}",
8622    );
8623    minify_test(
8624      ".foo { width: calc(100% + (2 * 100px) - ((75.37% - 63.5px) - 900px)) }",
8625      ".foo{width:calc(24.63% + 1163.5px)}",
8626    );
8627    minify_test(
8628      ".foo { width: calc(((((100% + (2 * 30px) + 63.5px) / 0.7537) - (100vw - 60px)) / 2) + 30px) }",
8629      ".foo{width:calc(66.3394% + 141.929px - 50vw)}",
8630    );
8631    minify_test(
8632      ".foo { width: calc(((75.37% - 63.5px) - 900px) + (2 * 100px)) }",
8633      ".foo{width:calc(75.37% - 763.5px)}",
8634    );
8635    minify_test(
8636      ".foo { width: calc((900px - (10% - 63.5px)) + (2 * 100px)) }",
8637      ".foo{width:calc(1163.5px - 10%)}",
8638    );
8639    minify_test(".foo { width: calc(500px/0) }", ".foo{width:calc(500px/0)}");
8640    minify_test(".foo { width: calc(500px/2px) }", ".foo{width:calc(500px/2px)}");
8641    minify_test(".foo { width: calc(100% / 3 * 3) }", ".foo{width:100%}");
8642    minify_test(".foo { width: calc(+100px + +100px) }", ".foo{width:200px}");
8643    minify_test(".foo { width: calc(+100px - +100px) }", ".foo{width:0}");
8644    minify_test(".foo { width: calc(200px * +1) }", ".foo{width:200px}");
8645    minify_test(".foo { width: calc(200px / +1) }", ".foo{width:200px}");
8646    minify_test(".foo { width: calc(1.1e+1px + 1.1e+1px) }", ".foo{width:22px}");
8647    minify_test(".foo { border-width: calc(1px + 2px) }", ".foo{border-width:3px}");
8648    minify_test(
8649      ".foo { border-width: calc(1em + 2px + 2em + 3px) }",
8650      ".foo{border-width:calc(3em + 5px)}",
8651    );
8652
8653    minify_test(
8654      ".foo { border-width: min(1em, 2px) }",
8655      ".foo{border-width:min(1em,2px)}",
8656    );
8657    minify_test(
8658      ".foo { border-width: min(1em + 2em, 2px + 2px) }",
8659      ".foo{border-width:min(3em,4px)}",
8660    );
8661    minify_test(
8662      ".foo { border-width: min(1em + 2px, 2px + 1em) }",
8663      ".foo{border-width:min(1em + 2px,2px + 1em)}",
8664    );
8665    minify_test(
8666      ".foo { border-width: min(1em + 2px + 2px, 2px + 1em + 1px) }",
8667      ".foo{border-width:min(1em + 4px,3px + 1em)}",
8668    );
8669    minify_test(
8670      ".foo { border-width: min(2px + 1px, 3px + 4px) }",
8671      ".foo{border-width:3px}",
8672    );
8673    minify_test(
8674      ".foo { border-width: min(1px, 1em, 2px, 3in) }",
8675      ".foo{border-width:min(1px,1em)}",
8676    );
8677
8678    minify_test(
8679      ".foo { border-width: max(1em, 2px) }",
8680      ".foo{border-width:max(1em,2px)}",
8681    );
8682    minify_test(
8683      ".foo { border-width: max(1em + 2em, 2px + 2px) }",
8684      ".foo{border-width:max(3em,4px)}",
8685    );
8686    minify_test(
8687      ".foo { border-width: max(1em + 2px, 2px + 1em) }",
8688      ".foo{border-width:max(1em + 2px,2px + 1em)}",
8689    );
8690    minify_test(
8691      ".foo { border-width: max(1em + 2px + 2px, 2px + 1em + 1px) }",
8692      ".foo{border-width:max(1em + 4px,3px + 1em)}",
8693    );
8694    minify_test(
8695      ".foo { border-width: max(2px + 1px, 3px + 4px) }",
8696      ".foo{border-width:7px}",
8697    );
8698    minify_test(
8699      ".foo { border-width: max(1px, 1em, 2px, 3in) }",
8700      ".foo{border-width:max(3in,1em)}",
8701    );
8702
8703    minify_test(".foo { border-width: clamp(1px, 2px, 3px) }", ".foo{border-width:2px}");
8704    minify_test(".foo { border-width: clamp(1px, 10px, 3px) }", ".foo{border-width:3px}");
8705    minify_test(".foo { border-width: clamp(5px, 2px, 10px) }", ".foo{border-width:5px}");
8706    minify_test(
8707      ".foo { border-width: clamp(100px, 2px, 10px) }",
8708      ".foo{border-width:100px}",
8709    );
8710    minify_test(
8711      ".foo { border-width: clamp(5px + 5px, 5px + 7px, 10px + 20px) }",
8712      ".foo{border-width:12px}",
8713    );
8714
8715    minify_test(
8716      ".foo { border-width: clamp(1em, 2px, 4vh) }",
8717      ".foo{border-width:clamp(1em,2px,4vh)}",
8718    );
8719    minify_test(
8720      ".foo { border-width: clamp(1em, 2em, 4vh) }",
8721      ".foo{border-width:clamp(1em,2em,4vh)}",
8722    );
8723    minify_test(
8724      ".foo { border-width: clamp(1em, 2vh, 4vh) }",
8725      ".foo{border-width:max(1em,2vh)}",
8726    );
8727    minify_test(
8728      ".foo { border-width: clamp(1px, 1px + 2em, 4px) }",
8729      ".foo{border-width:clamp(1px,1px + 2em,4px)}",
8730    );
8731    minify_test(".foo { border-width: clamp(1px, 2pt, 1in) }", ".foo{border-width:2pt}");
8732    minify_test(
8733      ".foo { width: clamp(-100px, 0px, 50% - 50vw); }",
8734      ".foo{width:clamp(-100px,0px,50% - 50vw)}",
8735    );
8736
8737    minify_test(
8738      ".foo { top: calc(-1 * clamp(1.75rem, 8vw, 4rem)) }",
8739      ".foo{top:calc(-1*clamp(1.75rem,8vw,4rem))}",
8740    );
8741    minify_test(
8742      ".foo { top: calc(-1 * min(1.75rem, 8vw, 4rem)) }",
8743      ".foo{top:calc(-1*min(1.75rem,8vw))}",
8744    );
8745    minify_test(
8746      ".foo { top: calc(-1 * max(1.75rem, 8vw, 4rem)) }",
8747      ".foo{top:calc(-1*max(4rem,8vw))}",
8748    );
8749    minify_test(
8750      ".foo { top: calc(clamp(1.75rem, 8vw, 4rem) * -1) }",
8751      ".foo{top:calc(-1*clamp(1.75rem,8vw,4rem))}",
8752    );
8753    minify_test(
8754      ".foo { top: calc(min(1.75rem, 8vw, 4rem) * -1) }",
8755      ".foo{top:calc(-1*min(1.75rem,8vw))}",
8756    );
8757    minify_test(
8758      ".foo { top: calc(max(1.75rem, 8vw, 4rem) * -1) }",
8759      ".foo{top:calc(-1*max(4rem,8vw))}",
8760    );
8761    minify_test(
8762      ".foo { top: calc(clamp(1.75rem, 8vw, 4rem) / 2) }",
8763      ".foo{top:calc(clamp(1.75rem,8vw,4rem)/2)}",
8764    );
8765    minify_test(
8766      ".foo { top: calc(min(1.75rem, 8vw, 4rem) / 2) }",
8767      ".foo{top:calc(min(1.75rem,8vw)/2)}",
8768    );
8769    minify_test(
8770      ".foo { top: calc(max(1.75rem, 8vw, 4rem) / 2) }",
8771      ".foo{top:calc(max(4rem,8vw)/2)}",
8772    );
8773    minify_test(
8774      ".foo { top: calc(0.5 * clamp(1.75rem, 8vw, 4rem)) }",
8775      ".foo{top:calc(clamp(1.75rem,8vw,4rem)/2)}",
8776    );
8777    minify_test(
8778      ".foo { top: calc(1 * clamp(1.75rem, 8vw, 4rem)) }",
8779      ".foo{top:calc(clamp(1.75rem,8vw,4rem))}",
8780    );
8781    minify_test(
8782      ".foo { top: calc(2 * clamp(1.75rem, 8vw, 4rem) / 2) }",
8783      ".foo{top:calc(clamp(1.75rem,8vw,4rem))}",
8784    );
8785
8786    minify_test(".foo { width: max(0px, 1vw) }", ".foo{width:max(0px,1vw)}");
8787
8788    prefix_test(
8789      ".foo { border-width: clamp(1em, 2px, 4vh) }",
8790      indoc! { r#"
8791        .foo {
8792          border-width: max(1em, min(2px, 4vh));
8793        }
8794      "#},
8795      Browsers {
8796        safari: Some(12 << 16),
8797        ..Browsers::default()
8798      },
8799    );
8800
8801    prefix_test(
8802      ".foo { border-width: clamp(1em, 2px, 4vh) }",
8803      indoc! { r#"
8804        .foo {
8805          border-width: clamp(1em, 2px, 4vh);
8806        }
8807      "#},
8808      Browsers {
8809        safari: Some(14 << 16),
8810        ..Browsers::default()
8811      },
8812    );
8813
8814    minify_test(".foo { width: calc(1vh + 2vh) }", ".foo{width:3vh}");
8815    minify_test(".foo { width: calc(1dvh + 2dvh) }", ".foo{width:3dvh}");
8816    minify_test(".foo { width: calc(1lvh + 2lvh) }", ".foo{width:3lvh}");
8817    minify_test(".foo { width: calc(1svh + 2svh) }", ".foo{width:3svh}");
8818    minify_test(".foo { width: calc(1sVmin + 2Svmin) }", ".foo{width:3svmin}");
8819    minify_test(".foo { width: calc(1ic + 2ic) }", ".foo{width:3ic}");
8820    minify_test(".foo { width: calc(1ric + 2ric) }", ".foo{width:3ric}");
8821    minify_test(".foo { width: calc(1cap + 2cap) }", ".foo{width:3cap}");
8822    minify_test(".foo { width: calc(1lh + 2lh) }", ".foo{width:3lh}");
8823    minify_test(".foo { width: calc(1x + 2x) }", ".foo{width:calc(1x + 2x)}");
8824    minify_test(
8825      ".foo { left: calc(50% - 100px + clamp(0px, calc(50vw - 50px), 100px)) }",
8826      ".foo{left:calc(50% - 100px + clamp(0px,50vw - 50px,100px))}",
8827    );
8828    minify_test(
8829      ".foo { left: calc(10px + min(10px, 1rem) + max(2px, 1vw)) }",
8830      ".foo{left:calc(10px + min(10px,1rem) + max(2px,1vw))}",
8831    );
8832    minify_test(".foo { width: round(22px, 5px) }", ".foo{width:20px}");
8833    minify_test(".foo { width: round(nearest, 22px, 5px) }", ".foo{width:20px}");
8834    minify_test(".foo { width: round(down, 22px, 5px) }", ".foo{width:20px}");
8835    minify_test(".foo { width: round(to-zero, 22px, 5px) }", ".foo{width:20px}");
8836    minify_test(".foo { width: round(up, 22px, 5px) }", ".foo{width:25px}");
8837    minify_test(".foo { width: round(23px, 5px) }", ".foo{width:25px}");
8838    minify_test(".foo { width: round(nearest, 23px, 5px) }", ".foo{width:25px}");
8839    minify_test(".foo { width: round(down, 23px, 5px) }", ".foo{width:20px}");
8840    minify_test(".foo { width: round(to-zero, 23px, 5px) }", ".foo{width:20px}");
8841    minify_test(".foo { width: round(up, 23px, 5px) }", ".foo{width:25px}");
8842    minify_test(".foo { width: round(22px, 5vw) }", ".foo{width:round(22px,5vw)}");
8843    minify_test(".foo { rotate: round(22deg, 5deg) }", ".foo{rotate:20deg}");
8844    minify_test(".foo { rotate: round(22deg, 5deg) }", ".foo{rotate:20deg}");
8845    minify_test(
8846      ".foo { transition-duration: round(22ms, 5ms) }",
8847      ".foo{transition-duration:20ms}",
8848    );
8849    minify_test(".foo { margin: round(to-zero, -23px, 5px) }", ".foo{margin:-20px}");
8850    minify_test(".foo { margin: round(nearest, -23px, 5px) }", ".foo{margin:-25px}");
8851    minify_test(".foo { margin: calc(10px * round(22, 5)) }", ".foo{margin:200px}");
8852    minify_test(".foo { width: rem(18px, 5px) }", ".foo{width:3px}");
8853    minify_test(".foo { width: rem(-18px, 5px) }", ".foo{width:0}");
8854    minify_test(".foo { width: rem(18px, 5vw) }", ".foo{width:rem(18px,5vw)}");
8855    minify_test(".foo { rotate: rem(-140deg, -90deg) }", ".foo{rotate:-50deg}");
8856    minify_test(".foo { rotate: rem(140deg, -90deg) }", ".foo{rotate:50deg}");
8857    minify_test(".foo { width: calc(10px * rem(18, 5)) }", ".foo{width:30px}");
8858    minify_test(".foo { width: mod(18px, 5px) }", ".foo{width:3px}");
8859    minify_test(".foo { width: mod(-18px, 5px) }", ".foo{width:2px}");
8860    minify_test(".foo { rotate: mod(-140deg, -90deg) }", ".foo{rotate:-50deg}");
8861    minify_test(".foo { rotate: mod(140deg, -90deg) }", ".foo{rotate:-40deg}");
8862    minify_test(".foo { width: mod(18px, 5vw) }", ".foo{width:mod(18px,5vw)}");
8863    minify_test(
8864      ".foo { transform: rotateX(mod(140deg, -90deg)) rotateY(rem(140deg, -90deg)) }",
8865      ".foo{transform:rotateX(-40deg)rotateY(50deg)}",
8866    );
8867    minify_test(".foo { width: calc(10px * mod(18, 5)) }", ".foo{width:30px}");
8868
8869    minify_test(
8870      ".foo { width: calc(100% - 30px - 0) }",
8871      ".foo{width:calc(100% - 30px - 0)}",
8872    );
8873    minify_test(
8874      ".foo { width: calc(100% - 30px - 1 - 2) }",
8875      ".foo{width:calc(100% - 30px - 3)}",
8876    );
8877    minify_test(
8878      ".foo { width: calc(1 - 2 - 100% - 30px) }",
8879      ".foo{width:calc(-1 - 100% - 30px)}",
8880    );
8881    minify_test(
8882      ".foo { width: calc(2 * min(1px, 1vmin) - min(1px, 1vmin)); }",
8883      ".foo{width:calc(2*min(1px,1vmin) - min(1px,1vmin))}",
8884    );
8885    minify_test(
8886      ".foo { width: calc(100% - clamp(1.125rem, 1.25vw, 1.2375rem) - clamp(1.125rem, 1.25vw, 1.2375rem)); }",
8887      ".foo{width:calc(100% - clamp(1.125rem,1.25vw,1.2375rem) - clamp(1.125rem,1.25vw,1.2375rem))}",
8888    );
8889    minify_test(
8890      ".foo { width: calc(100% - 2 (2 * var(--card-margin))); }",
8891      ".foo{width:calc(100% - 2 (2 * var(--card-margin)))}",
8892    );
8893
8894    test(
8895      indoc! {r#"
8896    .test {
8897      width: calc(var(--test) + 2px);
8898      width: calc(var(--test) - 2px);
8899    }
8900    "#},
8901      indoc! {r#"
8902    .test {
8903      width: calc(var(--test) + 2px);
8904      width: calc(var(--test) - 2px);
8905    }
8906    "#},
8907    );
8908  }
8909
8910  #[test]
8911  fn test_trig() {
8912    minify_test(".foo { width: calc(2px * pi); }", ".foo{width:6.28319px}");
8913    minify_test(".foo { width: calc(2px / pi); }", ".foo{width:.63662px}");
8914    // minify_test(
8915    //   ".foo { width: calc(2px * infinity); }",
8916    //   ".foo{width:calc(2px*infinity)}",
8917    // );
8918    // minify_test(
8919    //   ".foo { width: calc(2px * -infinity); }",
8920    //   ".foo{width:calc(2px*-infinity)}",
8921    // );
8922    minify_test(".foo { width: calc(100px * sin(45deg))", ".foo{width:70.7107px}");
8923    minify_test(".foo { width: calc(100px * sin(.125turn))", ".foo{width:70.7107px}");
8924    minify_test(
8925      ".foo { width: calc(100px * sin(3.14159265 / 4))",
8926      ".foo{width:70.7107px}",
8927    );
8928    minify_test(".foo { width: calc(100px * sin(pi / 4))", ".foo{width:70.7107px}");
8929    minify_test(
8930      ".foo { width: calc(100px * sin(22deg + 23deg))",
8931      ".foo{width:70.7107px}",
8932    );
8933
8934    minify_test(".foo { width: calc(2px * cos(45deg))", ".foo{width:1.41421px}");
8935    minify_test(".foo { width: calc(2px * tan(45deg))", ".foo{width:2px}");
8936
8937    minify_test(".foo { rotate: asin(sin(45deg))", ".foo{rotate:45deg}");
8938    minify_test(".foo { rotate: asin(1)", ".foo{rotate:90deg}");
8939    minify_test(".foo { rotate: asin(-1)", ".foo{rotate:-90deg}");
8940    minify_test(".foo { rotate: asin(0.5)", ".foo{rotate:30deg}");
8941    minify_test(".foo { rotate: asin(45deg)", ".foo{rotate:asin(45deg)}"); // invalid
8942    minify_test(".foo { rotate: asin(-20)", ".foo{rotate:asin(-20)}"); // evaluates to NaN
8943    minify_test(".foo { width: asin(sin(45deg))", ".foo{width:asin(sin(45deg))}"); // invalid
8944
8945    minify_test(".foo { rotate: acos(cos(45deg))", ".foo{rotate:45deg}");
8946    minify_test(".foo { rotate: acos(-1)", ".foo{rotate:180deg}");
8947    minify_test(".foo { rotate: acos(0)", ".foo{rotate:90deg}");
8948    minify_test(".foo { rotate: acos(1)", ".foo{rotate:0deg}");
8949    minify_test(".foo { rotate: acos(45deg)", ".foo{rotate:acos(45deg)}"); // invalid
8950    minify_test(".foo { rotate: acos(-20)", ".foo{rotate:acos(-20)}"); // evaluates to NaN
8951
8952    minify_test(".foo { rotate: atan(tan(45deg))", ".foo{rotate:45deg}");
8953    minify_test(".foo { rotate: atan(1)", ".foo{rotate:45deg}");
8954    minify_test(".foo { rotate: atan(0)", ".foo{rotate:0deg}");
8955    minify_test(".foo { rotate: atan(45deg)", ".foo{rotate:atan(45deg)}"); // invalid
8956
8957    minify_test(".foo { rotate: atan2(1px, -1px)", ".foo{rotate:135deg}");
8958    minify_test(".foo { rotate: atan2(1vw, -1vw)", ".foo{rotate:135deg}");
8959    minify_test(".foo { rotate: atan2(1, -1)", ".foo{rotate:135deg}");
8960    minify_test(".foo { rotate: atan2(1ms, -1ms)", ".foo{rotate:135deg}");
8961    minify_test(".foo { rotate: atan2(1%, -1%)", ".foo{rotate:135deg}");
8962    minify_test(".foo { rotate: atan2(1deg, -1deg)", ".foo{rotate:135deg}");
8963    minify_test(".foo { rotate: atan2(1cm, 1mm)", ".foo{rotate:84.2894deg}");
8964    minify_test(".foo { rotate: atan2(0, -1)", ".foo{rotate:180deg}");
8965    minify_test(".foo { rotate: atan2(-1, 1)", ".foo{rotate:-45deg}");
8966    // incompatible units
8967    minify_test(".foo { rotate: atan2(1px, -1vw)", ".foo{rotate:atan2(1px, -1vw)}");
8968
8969    minify_test(".foo { transform: rotate(acos(1)) }", ".foo{transform:rotate(0)}");
8970    minify_test(".foo { transform: rotate(atan(0)) }", ".foo{transform:rotate(0)}");
8971  }
8972
8973  #[test]
8974  fn test_exp() {
8975    minify_test(".foo { width: hypot()", ".foo{width:hypot()}");
8976    minify_test(".foo { width: hypot(1px)", ".foo{width:1px}");
8977    minify_test(".foo { width: hypot(1px, 2px)", ".foo{width:2.23607px}");
8978    minify_test(".foo { width: hypot(1px, 2px, 3px)", ".foo{width:3.74166px}");
8979    minify_test(".foo { width: hypot(1px, 2vw)", ".foo{width:hypot(1px,2vw)}");
8980    minify_test(".foo { width: hypot(1px, 2px, 3vw)", ".foo{width:hypot(1px,2px,3vw)}");
8981    minify_test(".foo { width: calc(100px * hypot(3, 4))", ".foo{width:500px}");
8982    minify_test(".foo { width: calc(1px * pow(2, sqrt(100))", ".foo{width:1024px}");
8983    minify_test(".foo { width: calc(100px * pow(2, pow(2, 2)", ".foo{width:1600px}");
8984    minify_test(".foo { width: calc(1px * log(1))", ".foo{width:0}");
8985    minify_test(".foo { width: calc(1px * log(10, 10))", ".foo{width:1px}");
8986    minify_test(".foo { width: calc(1px * exp(0))", ".foo{width:1px}");
8987    minify_test(".foo { width: calc(1px * log(e))", ".foo{width:1px}");
8988    minify_test(".foo { width: calc(1px * (e - exp(1)))", ".foo{width:0}");
8989    minify_test(
8990      ".foo { width: calc(1px * (exp(log(1) + exp(0)*2))",
8991      ".foo{width:7.38906px}",
8992    );
8993  }
8994
8995  #[test]
8996  fn test_sign() {
8997    minify_test(".foo { width: abs(1px)", ".foo{width:1px}");
8998    minify_test(".foo { width: abs(-1px)", ".foo{width:1px}");
8999    minify_test(".foo { width: abs(1%)", ".foo{width:abs(1%)}"); // spec says percentages must be against resolved value
9000
9001    minify_test(".foo { width: calc(10px * sign(-1vw)", ".foo{width:0}");
9002    minify_test(
9003      ".foo { width: calc(10px * sign(1%)",
9004      ".foo{width:calc(10px * sign(1%))}",
9005    );
9006  }
9007
9008  #[test]
9009  fn test_box_shadow() {
9010    property_range_test(
9011      &["box-shadow"],
9012      &[
9013        ("1px 2px -3px", None),
9014        ("1px 2px -3px 4px", None),
9015        ("1px 2px 0 -4px", Some("1px 2px 0 -4px")),
9016        ("1px 2px calc(-3px)", Some("1px 2px")),
9017      ],
9018    );
9019    minify_test(
9020      ".foo { box-shadow: 64px 64px 12px 40px rgba(0,0,0,0.4) }",
9021      ".foo{box-shadow:64px 64px 12px 40px #0006}",
9022    );
9023    minify_test(
9024      ".foo { box-shadow: 12px 12px 0px 8px rgba(0,0,0,0.4) inset }",
9025      ".foo{box-shadow:inset 12px 12px 0 8px #0006}",
9026    );
9027    minify_test(
9028      ".foo { box-shadow: inset 12px 12px 0px 8px rgba(0,0,0,0.4) }",
9029      ".foo{box-shadow:inset 12px 12px 0 8px #0006}",
9030    );
9031    minify_test(
9032      ".foo { box-shadow: 12px 12px 8px 0px rgba(0,0,0,0.4) }",
9033      ".foo{box-shadow:12px 12px 8px #0006}",
9034    );
9035    minify_test(
9036      ".foo { box-shadow: 12px 12px 0px 0px rgba(0,0,0,0.4) }",
9037      ".foo{box-shadow:12px 12px #0006}",
9038    );
9039    minify_test(
9040      ".foo { box-shadow: 64px 64px 12px 40px rgba(0,0,0,0.4), 12px 12px 0px 8px rgba(0,0,0,0.4) inset }",
9041      ".foo{box-shadow:64px 64px 12px 40px #0006,inset 12px 12px 0 8px #0006}",
9042    );
9043
9044    prefix_test(
9045      ".foo { box-shadow: 12px 12px lab(40% 56.6 39) }",
9046      indoc! { r#"
9047        .foo {
9048          box-shadow: 12px 12px #b32323;
9049          box-shadow: 12px 12px lab(40% 56.6 39);
9050        }
9051      "#},
9052      Browsers {
9053        chrome: Some(90 << 16),
9054        ..Browsers::default()
9055      },
9056    );
9057
9058    prefix_test(
9059      ".foo { box-shadow: 12px 12px lab(40% 56.6 39) }",
9060      indoc! { r#"
9061        .foo {
9062          -webkit-box-shadow: 12px 12px #b32323;
9063          box-shadow: 12px 12px #b32323;
9064          box-shadow: 12px 12px lab(40% 56.6 39);
9065        }
9066      "#},
9067      Browsers {
9068        chrome: Some(4 << 16),
9069        ..Browsers::default()
9070      },
9071    );
9072
9073    prefix_test(
9074      ".foo { box-shadow: 12px 12px lab(40% 56.6 39), 12px 12px yellow }",
9075      indoc! { r#"
9076        .foo {
9077          -webkit-box-shadow: 12px 12px #b32323, 12px 12px #ff0;
9078          box-shadow: 12px 12px #b32323, 12px 12px #ff0;
9079          box-shadow: 12px 12px lab(40% 56.6 39), 12px 12px #ff0;
9080        }
9081      "#},
9082      Browsers {
9083        chrome: Some(4 << 16),
9084        ..Browsers::default()
9085      },
9086    );
9087
9088    prefix_test(
9089      ".foo { -webkit-box-shadow: 12px 12px #0006 }",
9090      indoc! { r#"
9091        .foo {
9092          -webkit-box-shadow: 12px 12px rgba(0, 0, 0, .4);
9093        }
9094      "#},
9095      Browsers {
9096        chrome: Some(4 << 16),
9097        ..Browsers::default()
9098      },
9099    );
9100
9101    prefix_test(
9102      ".foo {
9103        -webkit-box-shadow: 12px 12px #0006;
9104        -moz-box-shadow: 12px 12px #0009;
9105      }",
9106      indoc! { r#"
9107        .foo {
9108          -webkit-box-shadow: 12px 12px rgba(0, 0, 0, .4);
9109          -moz-box-shadow: 12px 12px rgba(0, 0, 0, .6);
9110        }
9111      "#},
9112      Browsers {
9113        chrome: Some(4 << 16),
9114        ..Browsers::default()
9115      },
9116    );
9117
9118    prefix_test(
9119      ".foo {
9120        -webkit-box-shadow: 12px 12px #0006;
9121        -moz-box-shadow: 12px 12px #0006;
9122        box-shadow: 12px 12px #0006;
9123      }",
9124      indoc! { r#"
9125        .foo {
9126          box-shadow: 12px 12px #0006;
9127        }
9128      "#},
9129      Browsers {
9130        chrome: Some(95 << 16),
9131        ..Browsers::default()
9132      },
9133    );
9134
9135    prefix_test(
9136      ".foo { box-shadow: var(--foo) 12px lab(40% 56.6 39) }",
9137      indoc! { r#"
9138        .foo {
9139          box-shadow: var(--foo) 12px #b32323;
9140        }
9141
9142        @supports (color: lab(0% 0 0)) {
9143          .foo {
9144            box-shadow: var(--foo) 12px lab(40% 56.6 39);
9145          }
9146        }
9147      "#},
9148      Browsers {
9149        chrome: Some(90 << 16),
9150        ..Browsers::default()
9151      },
9152    );
9153
9154    prefix_test(
9155      r#"
9156      .foo {
9157        box-shadow: 0px 0px 22px red;
9158        box-shadow: 0px 0px max(2cqw, 22px) red;
9159      }
9160    "#,
9161      indoc! {r#"
9162      .foo {
9163        box-shadow: 0 0 22px red;
9164        box-shadow: 0 0 max(2cqw, 22px) red;
9165      }
9166    "#
9167      },
9168      Browsers {
9169        safari: Some(14 << 16),
9170        ..Browsers::default()
9171      },
9172    );
9173    prefix_test(
9174      r#"
9175      .foo {
9176        box-shadow: 0px 0px 22px red;
9177        box-shadow: 0px 0px max(2cqw, 22px) red;
9178      }
9179    "#,
9180      indoc! {r#"
9181      .foo {
9182        box-shadow: 0 0 max(2cqw, 22px) red;
9183      }
9184    "#
9185      },
9186      Browsers {
9187        safari: Some(16 << 16),
9188        ..Browsers::default()
9189      },
9190    );
9191
9192    prefix_test(
9193      r#"
9194      .foo {
9195        box-shadow: 0px 0px 22px red;
9196        box-shadow: 0px 0px 22px lab(40% 56.6 39);
9197      }
9198    "#,
9199      indoc! {r#"
9200      .foo {
9201        box-shadow: 0 0 22px red;
9202        box-shadow: 0 0 22px lab(40% 56.6 39);
9203      }
9204    "#
9205      },
9206      Browsers {
9207        safari: Some(14 << 16),
9208        ..Browsers::default()
9209      },
9210    );
9211    prefix_test(
9212      r#"
9213      .foo {
9214        box-shadow: 0px 0px 22px red;
9215        box-shadow: 0px 0px 22px lab(40% 56.6 39);
9216      }
9217    "#,
9218      indoc! {r#"
9219      .foo {
9220        box-shadow: 0 0 22px lab(40% 56.6 39);
9221      }
9222    "#
9223      },
9224      Browsers {
9225        safari: Some(16 << 16),
9226        ..Browsers::default()
9227      },
9228    );
9229
9230    prefix_test(
9231      r#"
9232      .foo {
9233        box-shadow: var(--fallback);
9234        box-shadow: 0px 0px 22px lab(40% 56.6 39);
9235      }
9236    "#,
9237      indoc! {r#"
9238      .foo {
9239        box-shadow: var(--fallback);
9240        box-shadow: 0 0 22px lab(40% 56.6 39);
9241      }
9242    "#
9243      },
9244      Browsers {
9245        safari: Some(16 << 16),
9246        ..Browsers::default()
9247      },
9248    );
9249  }
9250
9251  #[test]
9252  fn test_selector_compatibility() {
9253    fn selectors(source: &str) -> crate::selector::SelectorList<'_> {
9254      let stylesheet = StyleSheet::parse(
9255        source,
9256        ParserOptions {
9257          flags: ParserFlags::SCROLL_NAVIGATION_CONTROLS,
9258          ..ParserOptions::default()
9259        },
9260      )
9261      .unwrap();
9262      match &stylesheet.rules.0[0] {
9263        CssRule::Style(rule) => rule.selectors.clone(),
9264        _ => unreachable!(),
9265      }
9266    }
9267
9268    let target_current = selectors("a:target-current { color: green }");
9269    assert!(!crate::selector::is_compatible(
9270      &target_current.0,
9271      Browsers {
9272        chrome: Some(134 << 16),
9273        ..Browsers::default()
9274      }
9275      .into()
9276    ));
9277    assert!(crate::selector::is_compatible(
9278      &target_current.0,
9279      Browsers {
9280        chrome: Some(135 << 16),
9281        ..Browsers::default()
9282      }
9283      .into()
9284    ));
9285
9286    let target_before = selectors("a:target-before { color: green }");
9287    assert!(!crate::selector::is_compatible(
9288      &target_before.0,
9289      Browsers {
9290        chrome: Some(141 << 16),
9291        ..Browsers::default()
9292      }
9293      .into()
9294    ));
9295    assert!(crate::selector::is_compatible(
9296      &target_before.0,
9297      Browsers {
9298        chrome: Some(142 << 16),
9299        ..Browsers::default()
9300      }
9301      .into()
9302    ));
9303
9304    let target_after = selectors("a:target-after { color: green }");
9305    assert!(crate::selector::is_compatible(
9306      &target_after.0,
9307      Browsers {
9308        chrome: Some(142 << 16),
9309        ..Browsers::default()
9310      }
9311      .into()
9312    ));
9313  }
9314
9315  #[test]
9316  fn test_media() {
9317    minify_test(
9318      "@media (min-width: 240px) { .foo { color: chartreuse }}",
9319      "@media (width>=240px){.foo{color:#7fff00}}",
9320    );
9321    minify_test(
9322      "@media (width < 240px) { .foo { color: chartreuse }}",
9323      "@media (width<240px){.foo{color:#7fff00}}",
9324    );
9325    minify_test(
9326      "@media (width <= 240px) { .foo { color: chartreuse }}",
9327      "@media (width<=240px){.foo{color:#7fff00}}",
9328    );
9329    minify_test(
9330      "@media (width > 240px) { .foo { color: chartreuse }}",
9331      "@media (width>240px){.foo{color:#7fff00}}",
9332    );
9333    minify_test(
9334      "@media (width >= 240px) { .foo { color: chartreuse }}",
9335      "@media (width>=240px){.foo{color:#7fff00}}",
9336    );
9337    minify_test(
9338      "@media (240px < width) { .foo { color: chartreuse }}",
9339      "@media (width>240px){.foo{color:#7fff00}}",
9340    );
9341    minify_test(
9342      "@media (240px <= width) { .foo { color: chartreuse }}",
9343      "@media (width>=240px){.foo{color:#7fff00}}",
9344    );
9345    minify_test(
9346      "@media (240px > width) { .foo { color: chartreuse }}",
9347      "@media (width<240px){.foo{color:#7fff00}}",
9348    );
9349    minify_test(
9350      "@media (240px >= width) { .foo { color: chartreuse }}",
9351      "@media (width<=240px){.foo{color:#7fff00}}",
9352    );
9353    minify_test(
9354      "@media (100px < width < 200px) { .foo { color: chartreuse }}",
9355      "@media (100px<width<200px){.foo{color:#7fff00}}",
9356    );
9357    minify_test(
9358      "@media (100px <= width <= 200px) { .foo { color: chartreuse }}",
9359      "@media (100px<=width<=200px){.foo{color:#7fff00}}",
9360    );
9361    minify_test(
9362      "@media (min-width: 30em) and (max-width: 50em) { .foo { color: chartreuse }}",
9363      "@media (width>=30em) and (width<=50em){.foo{color:#7fff00}}",
9364    );
9365    minify_test(
9366      "@media screen, print { .foo { color: chartreuse }}",
9367      "@media screen,print{.foo{color:#7fff00}}",
9368    );
9369    minify_test(
9370      "@media (hover: hover) { .foo { color: chartreuse }}",
9371      "@media (hover:hover){.foo{color:#7fff00}}",
9372    );
9373    minify_test(
9374      "@media (hover) { .foo { color: chartreuse }}",
9375      "@media (hover){.foo{color:#7fff00}}",
9376    );
9377    minify_test(
9378      "@media (aspect-ratio: 11/5) { .foo { color: chartreuse }}",
9379      "@media (aspect-ratio:11/5){.foo{color:#7fff00}}",
9380    );
9381    minify_test(
9382      "@media (aspect-ratio: 2/1) { .foo { color: chartreuse }}",
9383      "@media (aspect-ratio:2){.foo{color:#7fff00}}",
9384    );
9385    minify_test(
9386      "@media (aspect-ratio: 2) { .foo { color: chartreuse }}",
9387      "@media (aspect-ratio:2){.foo{color:#7fff00}}",
9388    );
9389    minify_test(
9390      "@media not screen and (color) { .foo { color: chartreuse }}",
9391      "@media not screen and (color){.foo{color:#7fff00}}",
9392    );
9393    minify_test(
9394      "@media only screen and (color) { .foo { color: chartreuse }}",
9395      "@media only screen and (color){.foo{color:#7fff00}}",
9396    );
9397    minify_test(
9398      "@media (update: slow) or (hover: none) { .foo { color: chartreuse }}",
9399      "@media (update:slow) or (hover:none){.foo{color:#7fff00}}",
9400    );
9401    minify_test(
9402      "@media (width < 600px) and (height < 600px) { .foo { color: chartreuse }}",
9403      "@media (width<600px) and (height<600px){.foo{color:#7fff00}}",
9404    );
9405    minify_test(
9406      "@media (not (color)) or (hover) { .foo { color: chartreuse }}",
9407      "@media (not (color)) or (hover){.foo{color:#7fff00}}",
9408    );
9409    error_test(
9410      "@media (example, all,), speech { .foo { color: chartreuse }}",
9411      ParserError::UnexpectedToken(Token::Comma),
9412    );
9413    error_test(
9414      "@media &test, speech { .foo { color: chartreuse }}",
9415      ParserError::UnexpectedToken(Token::Delim('&')),
9416    );
9417    error_test(
9418      "@media &test { .foo { color: chartreuse }}",
9419      ParserError::UnexpectedToken(Token::Delim('&')),
9420    );
9421    minify_test(
9422      "@media (min-width: calc(200px + 40px)) { .foo { color: chartreuse }}",
9423      "@media (width>=240px){.foo{color:#7fff00}}",
9424    );
9425    minify_test(
9426      "@media (min-width: calc(1em + 5px)) { .foo { color: chartreuse }}",
9427      "@media (width>=calc(1em + 5px)){.foo{color:#7fff00}}",
9428    );
9429    minify_test("@media { .foo { color: chartreuse }}", ".foo{color:#7fff00}");
9430    minify_test("@media all { .foo { color: chartreuse }}", ".foo{color:#7fff00}");
9431    minify_test(
9432      "@media not (((color) or (hover))) { .foo { color: chartreuse }}",
9433      "@media not ((color) or (hover)){.foo{color:#7fff00}}",
9434    );
9435    minify_test(
9436      "@media (hover) and ((color) and (test)) { .foo { color: chartreuse }}",
9437      "@media (hover) and (color) and (test){.foo{color:#7fff00}}",
9438    );
9439    minify_test(
9440      "@media (grid: 1) { .foo { color: chartreuse }}",
9441      "@media (grid:1){.foo{color:#7fff00}}",
9442    );
9443    minify_test(
9444      "@media (width >= calc(2px + 4px)) { .foo { color: chartreuse }}",
9445      "@media (width>=6px){.foo{color:#7fff00}}",
9446    );
9447
9448    prefix_test(
9449      r#"
9450        @media (width >= 240px) {
9451          .foo {
9452            color: chartreuse;
9453          }
9454        }
9455      "#,
9456      indoc! { r#"
9457        @media (min-width: 240px) {
9458          .foo {
9459            color: #7fff00;
9460          }
9461        }
9462      "#},
9463      Browsers {
9464        firefox: Some(60 << 16),
9465        ..Browsers::default()
9466      },
9467    );
9468
9469    prefix_test(
9470      r#"
9471        @media (width >= 240px) {
9472          .foo {
9473            color: chartreuse;
9474          }
9475        }
9476      "#,
9477      indoc! { r#"
9478        @media (width >= 240px) {
9479          .foo {
9480            color: #7fff00;
9481          }
9482        }
9483      "#},
9484      Browsers {
9485        firefox: Some(64 << 16),
9486        ..Browsers::default()
9487      },
9488    );
9489
9490    prefix_test(
9491      r#"
9492        @media (color > 2) {
9493          .foo {
9494            color: chartreuse;
9495          }
9496        }
9497      "#,
9498      indoc! { r#"
9499        @media not (max-color: 2) {
9500          .foo {
9501            color: #7fff00;
9502          }
9503        }
9504      "#},
9505      Browsers {
9506        firefox: Some(60 << 16),
9507        ..Browsers::default()
9508      },
9509    );
9510
9511    prefix_test(
9512      r#"
9513        @media (color < 2) {
9514          .foo {
9515            color: chartreuse;
9516          }
9517        }
9518      "#,
9519      indoc! { r#"
9520        @media not (min-color: 2) {
9521          .foo {
9522            color: #7fff00;
9523          }
9524        }
9525      "#},
9526      Browsers {
9527        firefox: Some(60 << 16),
9528        ..Browsers::default()
9529      },
9530    );
9531
9532    prefix_test(
9533      r#"
9534        @media (width > 240px) {
9535          .foo {
9536            color: chartreuse;
9537          }
9538        }
9539      "#,
9540      indoc! { r#"
9541        @media not (max-width: 240px) {
9542          .foo {
9543            color: #7fff00;
9544          }
9545        }
9546      "#},
9547      Browsers {
9548        firefox: Some(60 << 16),
9549        ..Browsers::default()
9550      },
9551    );
9552
9553    prefix_test(
9554      r#"
9555        @media (width <= 240px) {
9556          .foo {
9557            color: chartreuse;
9558          }
9559        }
9560      "#,
9561      indoc! { r#"
9562        @media (max-width: 240px) {
9563          .foo {
9564            color: #7fff00;
9565          }
9566        }
9567      "#},
9568      Browsers {
9569        firefox: Some(60 << 16),
9570        ..Browsers::default()
9571      },
9572    );
9573
9574    prefix_test(
9575      r#"
9576        @media (width <= 240px) {
9577          .foo {
9578            color: chartreuse;
9579          }
9580        }
9581      "#,
9582      indoc! { r#"
9583        @media (width <= 240px) {
9584          .foo {
9585            color: #7fff00;
9586          }
9587        }
9588      "#},
9589      Browsers {
9590        firefox: Some(64 << 16),
9591        ..Browsers::default()
9592      },
9593    );
9594
9595    prefix_test(
9596      r#"
9597        @media (width < 240px) {
9598          .foo {
9599            color: chartreuse;
9600          }
9601        }
9602      "#,
9603      indoc! { r#"
9604        @media not (min-width: 240px) {
9605          .foo {
9606            color: #7fff00;
9607          }
9608        }
9609      "#},
9610      Browsers {
9611        firefox: Some(60 << 16),
9612        ..Browsers::default()
9613      },
9614    );
9615
9616    prefix_test(
9617      r#"
9618        @media not (width < 240px) {
9619          .foo {
9620            color: chartreuse;
9621          }
9622        }
9623      "#,
9624      indoc! { r#"
9625        @media (min-width: 240px) {
9626          .foo {
9627            color: #7fff00;
9628          }
9629        }
9630      "#},
9631      Browsers {
9632        firefox: Some(60 << 16),
9633        ..Browsers::default()
9634      },
9635    );
9636
9637    test(
9638      r#"
9639        @media not (width < 240px) {
9640          .foo {
9641            color: chartreuse;
9642          }
9643        }
9644      "#,
9645      indoc! { r#"
9646        @media (width >= 240px) {
9647          .foo {
9648            color: #7fff00;
9649          }
9650        }
9651      "#},
9652    );
9653
9654    prefix_test(
9655      r#"
9656        @media (width < 240px) and (hover) {
9657          .foo {
9658            color: chartreuse;
9659          }
9660        }
9661      "#,
9662      indoc! { r#"
9663        @media (not (min-width: 240px)) and (hover) {
9664          .foo {
9665            color: #7fff00;
9666          }
9667        }
9668      "#},
9669      Browsers {
9670        firefox: Some(60 << 16),
9671        ..Browsers::default()
9672      },
9673    );
9674
9675    prefix_test(
9676      r#"
9677        @media (100px <= width <= 200px) {
9678          .foo {
9679            color: chartreuse;
9680          }
9681        }
9682      "#,
9683      indoc! { r#"
9684        @media (min-width: 100px) and (max-width: 200px) {
9685          .foo {
9686            color: #7fff00;
9687          }
9688        }
9689      "#},
9690      Browsers {
9691        firefox: Some(85 << 16),
9692        ..Browsers::default()
9693      },
9694    );
9695
9696    prefix_test(
9697      r#"
9698        @media not (100px <= width <= 200px) {
9699          .foo {
9700            color: chartreuse;
9701          }
9702        }
9703      "#,
9704      indoc! { r#"
9705        @media not ((min-width: 100px) and (max-width: 200px)) {
9706          .foo {
9707            color: #7fff00;
9708          }
9709        }
9710      "#},
9711      Browsers {
9712        firefox: Some(85 << 16),
9713        ..Browsers::default()
9714      },
9715    );
9716
9717    prefix_test(
9718      r#"
9719        @media (hover) and (100px <= width <= 200px) {
9720          .foo {
9721            color: chartreuse;
9722          }
9723        }
9724      "#,
9725      indoc! { r#"
9726        @media (hover) and (min-width: 100px) and (max-width: 200px) {
9727          .foo {
9728            color: #7fff00;
9729          }
9730        }
9731      "#},
9732      Browsers {
9733        firefox: Some(85 << 16),
9734        ..Browsers::default()
9735      },
9736    );
9737
9738    prefix_test(
9739      r#"
9740        @media (hover) or (100px <= width <= 200px) {
9741          .foo {
9742            color: chartreuse;
9743          }
9744        }
9745      "#,
9746      indoc! { r#"
9747        @media (hover) or ((min-width: 100px) and (max-width: 200px)) {
9748          .foo {
9749            color: #7fff00;
9750          }
9751        }
9752      "#},
9753      Browsers {
9754        firefox: Some(85 << 16),
9755        ..Browsers::default()
9756      },
9757    );
9758
9759    prefix_test(
9760      r#"
9761        @media (100px < width < 200px) {
9762          .foo {
9763            color: chartreuse;
9764          }
9765        }
9766      "#,
9767      indoc! { r#"
9768        @media (not (max-width: 100px)) and (not (min-width: 200px)) {
9769          .foo {
9770            color: #7fff00;
9771          }
9772        }
9773      "#},
9774      Browsers {
9775        firefox: Some(85 << 16),
9776        ..Browsers::default()
9777      },
9778    );
9779
9780    prefix_test(
9781      r#"
9782        @media not (100px < width < 200px) {
9783          .foo {
9784            color: chartreuse;
9785          }
9786        }
9787      "#,
9788      indoc! { r#"
9789        @media not ((not (max-width: 100px)) and (not (min-width: 200px))) {
9790          .foo {
9791            color: #7fff00;
9792          }
9793        }
9794      "#},
9795      Browsers {
9796        firefox: Some(85 << 16),
9797        ..Browsers::default()
9798      },
9799    );
9800
9801    prefix_test(
9802      r#"
9803        @media (200px >= width >= 100px) {
9804          .foo {
9805            color: chartreuse;
9806          }
9807        }
9808      "#,
9809      indoc! { r#"
9810        @media (max-width: 200px) and (min-width: 100px) {
9811          .foo {
9812            color: #7fff00;
9813          }
9814        }
9815      "#},
9816      Browsers {
9817        firefox: Some(85 << 16),
9818        ..Browsers::default()
9819      },
9820    );
9821
9822    test(
9823      r#"
9824      @media not all {
9825        .a {
9826          color: green;
9827        }
9828      }
9829      "#,
9830      "\n",
9831    );
9832
9833    prefix_test(
9834      r#"
9835      @media (width > calc(1px + 1rem)) {
9836        .foo { color: yellow; }
9837      }
9838      "#,
9839      indoc! { r#"
9840        @media not (max-width: calc(1px + 1rem)) {
9841          .foo {
9842            color: #ff0;
9843          }
9844        }
9845      "#},
9846      Browsers {
9847        chrome: Some(85 << 16),
9848        ..Browsers::default()
9849      },
9850    );
9851    prefix_test(
9852      r#"
9853      @media (width > max(10px, 1rem)) {
9854        .foo { color: yellow; }
9855      }
9856      "#,
9857      indoc! { r#"
9858        @media not (max-width: max(10px, 1rem)) {
9859          .foo {
9860            color: #ff0;
9861          }
9862        }
9863      "#},
9864      Browsers {
9865        chrome: Some(85 << 16),
9866        ..Browsers::default()
9867      },
9868    );
9869    prefix_test(
9870      r#"
9871      @media (width > 0) {
9872        .foo { color: yellow; }
9873      }
9874      "#,
9875      indoc! { r#"
9876        @media not (max-width: 0) {
9877          .foo {
9878            color: #ff0;
9879          }
9880        }
9881      "#},
9882      Browsers {
9883        chrome: Some(85 << 16),
9884        ..Browsers::default()
9885      },
9886    );
9887    prefix_test(
9888      r#"
9889      @media (min-resolution: 2dppx) {
9890        .foo { color: yellow; }
9891      }
9892      "#,
9893      indoc! { r#"
9894        @media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 2dppx) {
9895          .foo {
9896            color: #ff0;
9897          }
9898        }
9899      "#},
9900      Browsers {
9901        safari: Some(15 << 16),
9902        ..Browsers::default()
9903      },
9904    );
9905    prefix_test(
9906      r#"
9907      @media (min-resolution: 2dppx) {
9908        .foo { color: yellow; }
9909      }
9910      "#,
9911      indoc! { r#"
9912        @media (min--moz-device-pixel-ratio: 2), (min-resolution: 2dppx) {
9913          .foo {
9914            color: #ff0;
9915          }
9916        }
9917      "#},
9918      Browsers {
9919        firefox: Some(10 << 16),
9920        ..Browsers::default()
9921      },
9922    );
9923    prefix_test(
9924      r#"
9925      @media (resolution > 2dppx) {
9926        .foo { color: yellow; }
9927      }
9928      "#,
9929      indoc! { r#"
9930        @media not (-webkit-max-device-pixel-ratio: 2), not (max-resolution: 2dppx) {
9931          .foo {
9932            color: #ff0;
9933          }
9934        }
9935      "#},
9936      Browsers {
9937        safari: Some(15 << 16),
9938        ..Browsers::default()
9939      },
9940    );
9941    prefix_test(
9942      r#"
9943      @media (resolution >= 300dpi) {
9944        .foo { color: yellow; }
9945      }
9946      "#,
9947      indoc! { r#"
9948        @media (-webkit-min-device-pixel-ratio: 3.125), (min-resolution: 300dpi) {
9949          .foo {
9950            color: #ff0;
9951          }
9952        }
9953      "#},
9954      Browsers {
9955        safari: Some(15 << 16),
9956        ..Browsers::default()
9957      },
9958    );
9959    prefix_test(
9960      r#"
9961      @media (min-resolution: 113.38dpcm) {
9962        .foo { color: yellow; }
9963      }
9964      "#,
9965      indoc! { r#"
9966        @media (-webkit-min-device-pixel-ratio: 2.99985), (min--moz-device-pixel-ratio: 2.99985), (min-resolution: 113.38dpcm) {
9967          .foo {
9968            color: #ff0;
9969          }
9970        }
9971      "#},
9972      Browsers {
9973        safari: Some(15 << 16),
9974        firefox: Some(10 << 16),
9975        ..Browsers::default()
9976      },
9977    );
9978    prefix_test(
9979      r#"
9980      @media (color) and (min-resolution: 2dppx) {
9981        .foo { color: yellow; }
9982      }
9983      "#,
9984      indoc! { r#"
9985        @media (color) and (-webkit-min-device-pixel-ratio: 2), (color) and (min-resolution: 2dppx) {
9986          .foo {
9987            color: #ff0;
9988          }
9989        }
9990      "#},
9991      Browsers {
9992        safari: Some(15 << 16),
9993        ..Browsers::default()
9994      },
9995    );
9996    prefix_test(
9997      r#"
9998      @media (min-resolution: 2dppx),
9999             (min-resolution: 192dpi) {
10000        .foo { color: yellow; }
10001      }
10002      "#,
10003      indoc! { r#"
10004        @media (-webkit-min-device-pixel-ratio: 2), (min--moz-device-pixel-ratio: 2), (min-resolution: 2dppx), (min-resolution: 192dpi) {
10005          .foo {
10006            color: #ff0;
10007          }
10008        }
10009      "#},
10010      Browsers {
10011        safari: Some(15 << 16),
10012        firefox: Some(10 << 16),
10013        ..Browsers::default()
10014      },
10015    );
10016    prefix_test(
10017      r#"
10018      @media only screen and (min-resolution: 124.8dpi) {
10019        .foo { color: yellow; }
10020      }
10021      "#,
10022      indoc! { r#"
10023        @media only screen and (-webkit-min-device-pixel-ratio: 1.3), only screen and (min--moz-device-pixel-ratio: 1.3), only screen and (min-resolution: 124.8dpi) {
10024          .foo {
10025            color: #ff0;
10026          }
10027        }
10028      "#},
10029      Browsers {
10030        safari: Some(15 << 16),
10031        firefox: Some(10 << 16),
10032        ..Browsers::default()
10033      },
10034    );
10035
10036    test_with_printer_options(
10037      r#"
10038        @media (width < 256px) or (hover: none) {
10039          .foo {
10040            color: #fff;
10041          }
10042        }
10043      "#,
10044      indoc! { r#"
10045        @media (not (min-width: 256px)) or (hover: none) {
10046          .foo {
10047            color: #fff;
10048          }
10049        }
10050      "#},
10051      PrinterOptions {
10052        targets: Targets {
10053          browsers: None,
10054          include: Features::MediaRangeSyntax,
10055          exclude: Features::empty(),
10056        },
10057        ..Default::default()
10058      },
10059    );
10060
10061    error_test(
10062      "@media (min-width: hi) { .foo { color: chartreuse }}",
10063      ParserError::InvalidMediaQuery,
10064    );
10065    error_test(
10066      "@media (width >= hi) { .foo { color: chartreuse }}",
10067      ParserError::InvalidMediaQuery,
10068    );
10069    error_test(
10070      "@media (width >= 2/1) { .foo { color: chartreuse }}",
10071      ParserError::UnexpectedToken(Token::Delim('/')),
10072    );
10073    error_test(
10074      "@media (600px <= min-height) { .foo { color: chartreuse }}",
10075      ParserError::InvalidMediaQuery,
10076    );
10077    error_test(
10078      "@media (scan >= 1) { .foo { color: chartreuse }}",
10079      ParserError::InvalidMediaQuery,
10080    );
10081    error_test(
10082      "@media (min-scan: interlace) { .foo { color: chartreuse }}",
10083      ParserError::InvalidMediaQuery,
10084    );
10085    error_test(
10086      "@media (1px <= width <= bar) { .foo { color: chartreuse }}",
10087      ParserError::InvalidMediaQuery,
10088    );
10089    error_test(
10090      "@media (1px <= min-width <= 2px) { .foo { color: chartreuse }}",
10091      ParserError::InvalidMediaQuery,
10092    );
10093    error_test(
10094      "@media (1px <= scan <= 2px) { .foo { color: chartreuse }}",
10095      ParserError::InvalidMediaQuery,
10096    );
10097    error_test(
10098      "@media (grid: 10) { .foo { color: chartreuse }}",
10099      ParserError::InvalidMediaQuery,
10100    );
10101    error_test(
10102      "@media (prefers-color-scheme = dark) { .foo { color: chartreuse }}",
10103      ParserError::InvalidMediaQuery,
10104    );
10105    error_test(
10106      "@media unknown(foo) {}",
10107      ParserError::UnexpectedToken(crate::properties::custom::Token::Function("unknown".into())),
10108    );
10109
10110    // empty brackets should return a clearer error message
10111    error_test("@media () {}", ParserError::EmptyBracketInCondition);
10112    error_test("@media screen and () {}", ParserError::EmptyBracketInCondition);
10113
10114    error_recovery_test("@media unknown(foo) {}");
10115  }
10116
10117  #[test]
10118  fn test_merge_layers() {
10119    test(
10120      r#"
10121      @layer foo {
10122        .foo {
10123          color: red;
10124        }
10125      }
10126      @layer foo {
10127        .foo {
10128          background: #fff;
10129        }
10130
10131        .baz {
10132          color: #fff;
10133        }
10134      }
10135      "#,
10136      indoc! {r#"
10137      @layer foo {
10138        .foo {
10139          color: red;
10140          background: #fff;
10141        }
10142
10143        .baz {
10144          color: #fff;
10145        }
10146      }
10147    "#},
10148    );
10149    test(
10150      r#"
10151      @layer a {}
10152      @layer b {}
10153
10154      @layer b {
10155        foo {
10156          color: red;
10157        }
10158      }
10159
10160      @layer a {
10161        bar {
10162          color: yellow;
10163        }
10164      }
10165      "#,
10166      indoc! {r#"
10167      @layer a {
10168        bar {
10169          color: #ff0;
10170        }
10171      }
10172
10173      @layer b {
10174        foo {
10175          color: red;
10176        }
10177      }
10178    "#},
10179    );
10180
10181    test(
10182      r#"
10183      @layer a {}
10184      @layer b {}
10185
10186      @layer b {
10187        foo {
10188          color: red;
10189        }
10190      }
10191      "#,
10192      indoc! {r#"
10193      @layer a;
10194
10195      @layer b {
10196        foo {
10197          color: red;
10198        }
10199      }
10200    "#},
10201    );
10202
10203    test(
10204      r#"
10205      @layer a;
10206      @layer b;
10207      @layer c;
10208      "#,
10209      indoc! {r#"
10210      @layer a, b, c;
10211    "#},
10212    );
10213
10214    test(
10215      r#"
10216      @layer a {}
10217      @layer b {}
10218      @layer c {}
10219      "#,
10220      indoc! {r#"
10221      @layer a, b, c;
10222    "#},
10223    );
10224
10225    test(
10226      r#"
10227      @layer a;
10228      @layer b {
10229        .foo {
10230          color: red;
10231        }
10232      }
10233      @layer c {}
10234      "#,
10235      indoc! {r#"
10236      @layer a;
10237
10238      @layer b {
10239        .foo {
10240          color: red;
10241        }
10242      }
10243
10244      @layer c;
10245    "#},
10246    );
10247
10248    test(
10249      r#"
10250      @layer a, b;
10251      @layer c {}
10252
10253      @layer d {
10254        foo {
10255          color: red;
10256        }
10257      }
10258      "#,
10259      indoc! {r#"
10260      @layer a, b, c;
10261
10262      @layer d {
10263        foo {
10264          color: red;
10265        }
10266      }
10267    "#},
10268    );
10269
10270    test(
10271      r#"
10272      @layer a;
10273      @layer b;
10274      @import "a.css" layer(x);
10275      @layer c;
10276
10277      @layer d {
10278        foo {
10279          color: red;
10280        }
10281      }
10282      "#,
10283      indoc! {r#"
10284      @layer a, b;
10285      @import "a.css" layer(x);
10286      @layer c;
10287
10288      @layer d {
10289        foo {
10290          color: red;
10291        }
10292      }
10293    "#},
10294    );
10295
10296    test(
10297      r#"
10298      @layer a, b, c;
10299
10300      @layer a {
10301        foo {
10302          color: red;
10303        }
10304      }
10305      "#,
10306      indoc! {r#"
10307      @layer a {
10308        foo {
10309          color: red;
10310        }
10311      }
10312
10313      @layer b, c;
10314    "#},
10315    );
10316
10317    test(
10318      r#"
10319      @layer a;
10320      @import "foo.css";
10321
10322      @layer a {
10323        foo {
10324          color: red;
10325        }
10326      }
10327      "#,
10328      indoc! {r#"
10329      @layer a;
10330      @import "foo.css";
10331
10332      @layer a {
10333        foo {
10334          color: red;
10335        }
10336      }
10337    "#},
10338    );
10339  }
10340
10341  #[test]
10342  fn test_layer_order_across_rules() {
10343    // A conditional declaration can establish `a` before `b`. Hoisting the
10344    // final statement changes their order when the condition matches.
10345    minify_test(
10346      "@layer c; @media (min-width: 600px) { @layer a { .x { --v: a } } } @layer b, a;",
10347      "@layer c;@media (width>=600px){@layer a{.x{--v:a}}}@layer b,a;",
10348    );
10349    minify_test(
10350      "@layer c; @supports (display: grid) { @layer a { .x { --v: a } } } @layer b, a;",
10351      "@layer c;@supports (display:grid){@layer a{.x{--v:a}}}@layer b,a;",
10352    );
10353    // An unlayered import may declare layers in its stylesheet too.
10354    minify_test(
10355      "@layer c; @import 'a.css'; @layer b, a;",
10356      "@layer c;@import \"a.css\";@layer b,a;",
10357    );
10358    // A conditional import cannot make a later unconditional declaration
10359    // redundant: that declaration must still apply if the condition is false.
10360    minify_test(
10361      "@import 'a.css' layer(a) screen; @layer a, b;",
10362      "@import \"a.css\" layer(a) screen;@layer a,b;",
10363    );
10364    // Moving the last block into the first reverses the order of declarations
10365    // within `a` when the intervening condition matches.
10366    minify_test(
10367      "@layer a { .x { --v: first } } @media print { @layer a { .x { --v: middle } } } @layer a { .x { --v: last } }",
10368      "@layer a{.x{--v:first}}@media print{@layer a{.x{--v:middle}}}@layer a{.x{--v:last}}",
10369    );
10370    minify_test(
10371      "@layer a { .x { --v: first } } @supports (display: grid) { @layer a { .x { --v: middle } } } @layer a { .x { --v: last } }",
10372      "@layer a{.x{--v:first}}@supports (display:grid){@layer a{.x{--v:middle}}}@layer a{.x{--v:last}}",
10373    );
10374    // Dotted layer names and nested blocks address the same layer hierarchy.
10375    // Merging the two `a` blocks would declare `a.z` before `a.y`.
10376    minify_test(
10377      "@layer a { @layer x; } @layer a.y { .x { --v: y } } @layer a { @layer z { .x { --v: z } } }",
10378      "@layer a{@layer x;}@layer a.y{.x{--v:y}}@layer a{@layer z{.x{--v:z}}}",
10379    );
10380  }
10381
10382  #[test]
10383  fn test_duplicate_rules_preserve_importance() {
10384    minify_test(
10385      ".x { --c: first !important } @layer a { .y { --c: middle } } .x { --c: last }",
10386      ".x{--c:first!important}@layer a{.y{--c:middle}}.x{--c:last}",
10387    );
10388    minify_test(
10389      ".x { color: red !important } .y { color: green } .x { color: blue }",
10390      ".x{color:red!important}.y{color:green}.x{color:#00f}",
10391    );
10392  }
10393
10394  #[test]
10395  fn test_merge_common_custom_properties() {
10396    test(
10397      r#"
10398      html {
10399        --foreground: #000;
10400        --foreground-rgb: 0,0,0;
10401        --background: #fff;
10402      }
10403
10404      html[data-theme="dark"] {
10405        --foreground: #000;
10406        --foreground-rgb: 0,0,0;
10407        --background: #222;
10408      }
10409      "#,
10410      indoc! {r#"
10411      html {
10412        --background: #fff;
10413      }
10414
10415      html, html[data-theme="dark"] {
10416        --foreground: #000;
10417        --foreground-rgb: 0,0,0;
10418      }
10419
10420      html[data-theme="dark"] {
10421        --background: #222;
10422      }
10423      "#},
10424    );
10425
10426    // Either original rule may become empty after extraction.
10427    test(
10428      r#"
10429      .a {
10430        --shared: long-value;
10431      }
10432
10433      .b {
10434        --shared: long-value;
10435        color: red;
10436      }
10437      "#,
10438      indoc! {r#"
10439      .a, .b {
10440        --shared: long-value;
10441      }
10442
10443      .b {
10444        color: red;
10445      }
10446      "#},
10447    );
10448
10449    test(
10450      r#"
10451      .a {
10452        --shared: long-value;
10453        color: red;
10454      }
10455
10456      .b {
10457        --shared: long-value;
10458      }
10459      "#,
10460      indoc! {r#"
10461      .a {
10462        color: red;
10463      }
10464
10465      .a, .b {
10466        --shared: long-value;
10467      }
10468      "#},
10469    );
10470
10471    // Shared declarations retain their importance.
10472    test(
10473      r#"
10474      .a {
10475        --shared: long-value !important;
10476        color: red;
10477      }
10478
10479      .b {
10480        --shared: long-value !important;
10481        color: blue;
10482      }
10483      "#,
10484      indoc! {r#"
10485      .a {
10486        color: red;
10487      }
10488
10489      .a, .b {
10490        --shared: long-value !important;
10491      }
10492
10493      .b {
10494        color: #00f;
10495      }
10496      "#},
10497    );
10498
10499    // Variable references do not depend on declaration order.
10500    test(
10501      r#"
10502      .a {
10503        --shared: var(--color);
10504        --color: red;
10505      }
10506
10507      .b {
10508        --color: blue;
10509        --shared: var(--color);
10510      }
10511      "#,
10512      indoc! {r#"
10513      .a {
10514        --color: red;
10515      }
10516
10517      .a, .b {
10518        --shared: var(--color);
10519      }
10520
10521      .b {
10522        --color: blue;
10523      }
10524      "#},
10525    );
10526
10527    // The all shorthand does not reset custom properties.
10528    test(
10529      r#"
10530      .a {
10531        all: initial;
10532        --shared: long-value;
10533      }
10534
10535      .b {
10536        all: unset;
10537        --shared: long-value;
10538      }
10539      "#,
10540      indoc! {r#"
10541      .a {
10542        all: initial;
10543      }
10544
10545      .a, .b {
10546        --shared: long-value;
10547      }
10548
10549      .b {
10550        all: unset;
10551      }
10552      "#},
10553    );
10554
10555    // Rules can share declarations within the same conditional block.
10556    test(
10557      r#"
10558      @media print {
10559        .a {
10560          --shared: long-value;
10561          color: red;
10562        }
10563
10564        .b {
10565          --shared: long-value;
10566          color: blue;
10567        }
10568      }
10569      "#,
10570      indoc! {r#"
10571      @media print {
10572        .a {
10573          color: red;
10574        }
10575
10576        .a, .b {
10577          --shared: long-value;
10578        }
10579
10580        .b {
10581          color: #00f;
10582        }
10583      }
10584      "#},
10585    );
10586
10587    // Factor when the serialized declaration saves one byte over the extra selectors.
10588    test(
10589      r#"
10590      .a {
10591        --x: ab;
10592        color: red;
10593      }
10594
10595      .b {
10596        --x: ab;
10597        color: green;
10598      }
10599      "#,
10600      indoc! {r#"
10601      .a {
10602        color: red;
10603      }
10604
10605      .a, .b {
10606        --x: ab;
10607      }
10608
10609      .b {
10610        color: green;
10611      }
10612      "#},
10613    );
10614  }
10615
10616  #[test]
10617  fn test_merge_common_custom_properties_boundaries() {
10618    for source in [
10619      // Names are case-sensitive.
10620      indoc! {r#"
10621      .a {
10622        --shared: long-value;
10623        color: red;
10624      }
10625
10626      .b {
10627        --SHARED: long-value;
10628        color: green;
10629      }
10630      "#},
10631      // Values must match.
10632      indoc! {r#"
10633      .a {
10634        --shared: long-value;
10635        color: red;
10636      }
10637
10638      .b {
10639        --shared: other-value;
10640        color: green;
10641      }
10642      "#},
10643      // Importance must match.
10644      indoc! {r#"
10645      .a {
10646        color: red;
10647        --shared: long-value !important;
10648      }
10649
10650      .b {
10651        --shared: long-value;
10652        color: green;
10653      }
10654      "#},
10655      // Repeated selectors would cost more than the shared declaration.
10656      indoc! {r#"
10657      .long-selector-a {
10658        --x: 0;
10659        color: red;
10660      }
10661
10662      .long-selector-b {
10663        --x: 0;
10664        color: green;
10665      }
10666      "#},
10667      // A tie is left unchanged.
10668      indoc! {r#"
10669      .a {
10670        --x: 0;
10671        color: red;
10672      }
10673
10674      .b {
10675        --x: 0;
10676        color: green;
10677      }
10678      "#},
10679      // Do not move declarations across intervening rules.
10680      indoc! {r#"
10681      .a {
10682        --shared: long-value;
10683        color: red;
10684      }
10685
10686      .c {
10687        --shared: override;
10688      }
10689
10690      .b {
10691        --shared: long-value;
10692        color: green;
10693      }
10694      "#},
10695      // Do not move declarations across conditional boundaries.
10696      indoc! {r#"
10697      .a {
10698        --shared: long-value;
10699        color: red;
10700      }
10701
10702      @media print {
10703        .b {
10704          --shared: long-value;
10705          color: green;
10706        }
10707      }
10708      "#},
10709      // Ordinary declarations may have shorthand interactions.
10710      indoc! {r#"
10711      .a {
10712        color: red;
10713        padding-top: 20px;
10714      }
10715
10716      .b {
10717        color: green;
10718        padding-top: 20px;
10719      }
10720      "#},
10721    ] {
10722      test(source, source);
10723    }
10724
10725    // Unsupported selectors must not invalidate the other rule in a selector list.
10726    let source = indoc! {r#"
10727    .a {
10728      --shared: long-value;
10729      color: red;
10730    }
10731
10732    .b:has(.c) {
10733      --shared: long-value;
10734      color: green;
10735    }
10736    "#};
10737    prefix_test(
10738      source,
10739      source,
10740      Browsers {
10741        chrome: Some(90 << 16),
10742        ..Browsers::default()
10743      },
10744    );
10745
10746    // CSS Modules can change selector and variable lengths when printing.
10747    let source = indoc! {r#"
10748    html {
10749      --shared: long-value;
10750      color: red;
10751    }
10752
10753    body {
10754      --shared: long-value;
10755      color: green;
10756    }
10757    "#};
10758    test_with_options(
10759      source,
10760      source,
10761      ParserOptions {
10762        css_modules: Some(Default::default()),
10763        ..ParserOptions::default()
10764      },
10765    );
10766
10767    // Nested selectors can expand to much longer selector lists when lowered.
10768    for source in [
10769      indoc! {r#"
10770      .parent {
10771        &.a {
10772          --shared: long-value;
10773          color: red;
10774        }
10775
10776        &.b {
10777          --shared: long-value;
10778          color: green;
10779        }
10780      }
10781      "#},
10782      indoc! {r#"
10783      .parent {
10784        :is(&, .a) {
10785          --shared: long-value;
10786          color: red;
10787        }
10788
10789        :is(&, .b) {
10790          --shared: long-value;
10791          color: green;
10792        }
10793      }
10794      "#},
10795    ] {
10796      test(source, source);
10797    }
10798  }
10799
10800  #[test]
10801  fn test_merge_common_custom_properties_revisit() {
10802    // Adapted from cssnano's "should revisit a predecessor after replacing an adjacent pair".
10803    let expected = indoc! {r#"
10804      .a, .b {
10805        --x: 1;
10806        --color: red;
10807      }
10808
10809      .b {
10810        --background: blue;
10811      }
10812    "#};
10813    test(
10814      r#"
10815      .a, .b {
10816        --x: 1;
10817      }
10818
10819      .a {
10820        --color: red;
10821      }
10822
10823      .b {
10824        --color: red;
10825        --background: blue;
10826      }
10827    "#,
10828      expected,
10829    );
10830    // Like cssnano's convergence test, a second pass must not find another merge.
10831    test(expected, expected);
10832
10833    // Extraction can also expose identical blocks of ordinary declarations.
10834    let expected = indoc! {r#"
10835      .a, .b {
10836        color: red;
10837      }
10838
10839      .b, .c {
10840        --shared: long-value;
10841      }
10842
10843      .c {
10844        color: green;
10845      }
10846    "#};
10847    test(
10848      r#"
10849      .a {
10850        color: red;
10851      }
10852
10853      .b {
10854        --shared: long-value;
10855        color: red;
10856      }
10857
10858      .c {
10859        --shared: long-value;
10860        color: green;
10861      }
10862    "#,
10863      expected,
10864    );
10865    test(expected, expected);
10866  }
10867
10868  #[test]
10869  fn test_merge_common_custom_properties_selector_arguments() {
10870    // Extend cssnano's unknown-selector and :host regression cases to nested arguments.
10871    for source in [
10872      indoc! {r#"
10873        .a {
10874          --shared: very-long-shared-value;
10875          color: red;
10876        }
10877
10878        :host(:nonsense) {
10879          --shared: very-long-shared-value;
10880          color: green;
10881        }
10882      "#},
10883      indoc! {r#"
10884        .a {
10885          --shared: very-long-shared-value;
10886          color: red;
10887        }
10888
10889        ::slotted(:nonsense) {
10890          --shared: very-long-shared-value;
10891          color: green;
10892        }
10893      "#},
10894      indoc! {r#"
10895        .a {
10896          --shared: very-long-shared-value;
10897          color: red;
10898        }
10899
10900        ::cue(:nonsense) {
10901          --shared: very-long-shared-value;
10902          color: green;
10903        }
10904      "#},
10905      indoc! {r#"
10906        .a {
10907          --shared: very-long-shared-value;
10908          color: red;
10909        }
10910
10911        ::cue(.b .c) {
10912          --shared: very-long-shared-value;
10913          color: green;
10914        }
10915      "#},
10916    ] {
10917      test(source, source);
10918    }
10919  }
10920
10921  #[test]
10922  fn test_merge_common_custom_properties_nested_has() {
10923    // Nesting inside :has() must be detected just like nesting inside :is().
10924    let source = indoc! {r#"
10925      .parent {
10926        :has(&) {
10927          --shared: very-long-shared-value;
10928          color: red;
10929        }
10930
10931        :has(&.b) {
10932          --shared: very-long-shared-value;
10933          color: green;
10934        }
10935      }
10936    "#};
10937    test(source, source);
10938  }
10939
10940  // Cases adapted from cssnano/postcss-merge-rules (MIT), with declarations
10941  // changed to custom properties where appropriate:
10942  // https://github.com/cssnano/cssnano/blob/13b2373173ce49c78b8a2015d8c3f6b025ccfc3e/packages/postcss-merge-rules/test/index.js
10943  //
10944  // Copyright (c) Ben Briggs <beneb.info@gmail.com> (https://beneb.info)
10945  //
10946  // Permission is hereby granted, free of charge, to any person
10947  // obtaining a copy of this software and associated documentation
10948  // files (the "Software"), to deal in the Software without
10949  // restriction, including without limitation the rights to use,
10950  // copy, modify, merge, publish, distribute, sublicense, and/or sell
10951  // copies of the Software, and to permit persons to whom the
10952  // Software is furnished to do so, subject to the following
10953  // conditions:
10954  //
10955  // The above copyright notice and this permission notice shall be
10956  // included in all copies or substantial portions of the Software.
10957  //
10958  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10959  // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
10960  // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
10961  // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
10962  // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
10963  // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
10964  // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
10965  // OTHER DEALINGS IN THE SOFTWARE.
10966  #[test]
10967  fn test_merge_common_custom_properties_cssnano() {
10968    // Different declaration order (cssnano test/index.js:40).
10969    test(
10970      r#"
10971      h1 {
10972        --color: red;
10973        --line-height: 1.5;
10974        --font-size: 2em;
10975      }
10976
10977      h2 {
10978        --font-size: 2em;
10979        --color: red;
10980        --line-height: 1.5;
10981      }
10982    "#,
10983      indoc! {r#"
10984      h1, h2 {
10985        --color: red;
10986        --line-height: 1.5;
10987        --font-size: 2em;
10988      }
10989    "#},
10990    );
10991
10992    // Partial merging across three rules (cssnano test/index.js:194).
10993    test(
10994      r#"
10995      h1 {
10996        --color: red;
10997        --text-decoration: underline;
10998      }
10999
11000      h2 {
11001        --text-decoration: underline;
11002        --color: green;
11003      }
11004
11005      h3 {
11006        --font-weight: bold;
11007        --color: green;
11008      }
11009    "#,
11010      indoc! {r#"
11011      h1 {
11012        --color: red;
11013      }
11014
11015      h1, h2 {
11016        --text-decoration: underline;
11017      }
11018
11019      h2, h3 {
11020        --color: green;
11021      }
11022
11023      h3 {
11024        --font-weight: bold;
11025      }
11026    "#},
11027    );
11028
11029    // The middle rule becomes empty (cssnano test/index.js:226).
11030    test(
11031      r#"
11032      .test-1 {
11033        --margin-top: 10px;
11034        --margin-bottom: 20px;
11035      }
11036
11037      .test-2 {
11038        --margin-top: 10px;
11039      }
11040
11041      .another-test {
11042        --margin-top: 10px;
11043        --margin-bottom: 30px;
11044      }
11045    "#,
11046      indoc! {r#"
11047      .test-1 {
11048        --margin-bottom: 20px;
11049      }
11050
11051      .test-1, .test-2, .another-test {
11052        --margin-top: 10px;
11053      }
11054
11055      .another-test {
11056        --margin-bottom: 30px;
11057      }
11058    "#},
11059    );
11060
11061    // Repeated declarations are already deduplicated by Lightning CSS (cssnano test/index.js:478).
11062    test(
11063      r#"
11064      h1 {
11065        --display: block;
11066        --display: block;
11067      }
11068
11069      h2 {
11070        --display: block;
11071        --display: block;
11072      }
11073    "#,
11074      indoc! {r#"
11075      h1, h2 {
11076        --display: block;
11077      }
11078    "#},
11079    );
11080
11081    // An overridden value must not be extracted (cssnano test/index.js:510).
11082    test(
11083      r#"
11084      .a {
11085        --font-family: Arial;
11086        --font-family: Helvetica;
11087      }
11088
11089      .b {
11090        --font-family: Arial;
11091      }
11092    "#,
11093      indoc! {r#"
11094      .a {
11095        --font-family: Helvetica;
11096      }
11097
11098      .b {
11099        --font-family: Arial;
11100      }
11101    "#},
11102    );
11103
11104    // Only the final matching value survives (cssnano test/index.js:646).
11105    test(
11106      r#"
11107      .a {
11108        --margin-left: 2px;
11109        color: red;
11110      }
11111
11112      .b {
11113        --margin-left: 2px;
11114        --margin-left: 1px;
11115        --margin-left: 2px;
11116      }
11117    "#,
11118      indoc! {r#"
11119      .a {
11120        color: red;
11121      }
11122
11123      .a, .b {
11124        --margin-left: 2px;
11125      }
11126    "#},
11127    );
11128
11129    // Custom properties with related-looking names are independent (cssnano test/propertyRelations.js).
11130    test(
11131      r#"
11132      .a {
11133        --font: serif;
11134        --font-size: 12px;
11135        color: red;
11136      }
11137
11138      .b {
11139        --font: serif;
11140        --font-size: 18px;
11141        color: green;
11142      }
11143    "#,
11144      indoc! {r#"
11145      .a {
11146        --font-size: 12px;
11147        color: red;
11148      }
11149
11150      .a, .b {
11151        --font: serif;
11152      }
11153
11154      .b {
11155        --font-size: 18px;
11156        color: green;
11157      }
11158    "#},
11159    );
11160
11161    // A predecessor merge preserves normal and important overrides independently.
11162    test(
11163      r#"
11164      .a, .b {
11165        --color: black;
11166        --fallback: stable;
11167        --color: green !important;
11168      }
11169
11170      .a {
11171        --color: red;
11172        --shared: long-value;
11173      }
11174
11175      .b {
11176        --color: red;
11177        --shared: long-value;
11178        --background: blue;
11179      }
11180    "#,
11181      indoc! {r#"
11182      .a, .b {
11183        --color: red;
11184        --fallback: stable;
11185        --shared: long-value;
11186        --color: green !important;
11187      }
11188
11189      .b {
11190        --background: blue;
11191      }
11192    "#},
11193    );
11194
11195    // Logical and physical declarations retain their order (cssnano test/index.js:1261).
11196    test(
11197      r#"
11198      .a {
11199        --shared: long-value;
11200        margin-inline-start: 1px;
11201        margin-top: 2px;
11202      }
11203
11204      .b {
11205        --shared: long-value;
11206        margin-inline-start: 3px;
11207        margin-top: 4px;
11208      }
11209    "#,
11210      indoc! {r#"
11211      .a {
11212        margin-inline-start: 1px;
11213        margin-top: 2px;
11214      }
11215
11216      .a, .b {
11217        --shared: long-value;
11218      }
11219
11220      .b {
11221        margin-inline-start: 3px;
11222        margin-top: 4px;
11223      }
11224    "#},
11225    );
11226
11227    // A forgiving selector argument may contain unsupported selectors.
11228    test(
11229      r#"
11230      .a {
11231        --shared: very-very-long-shared-value;
11232        color: red;
11233      }
11234
11235      :is(:nonsense, .b) {
11236        --shared: very-very-long-shared-value;
11237        color: green;
11238      }
11239    "#,
11240      indoc! {r#"
11241      .a {
11242        color: red;
11243      }
11244
11245      .a, :is(:nonsense, .b) {
11246        --shared: very-very-long-shared-value;
11247      }
11248
11249      :is(:nonsense, .b) {
11250        color: green;
11251      }
11252    "#},
11253    );
11254  }
11255
11256  #[test]
11257  fn test_merge_common_custom_properties_cssnano_boundaries() {
11258    for source in [
11259      // The selector cost exceeds the saving (cssnano test/index.js:303).
11260      indoc! {r#"
11261      .test0 {
11262        --color: red;
11263        --border: none;
11264        --margin: 0;
11265      }
11266
11267      .longlonglonglong {
11268        --color: green;
11269        --border: none;
11270        --margin: 0;
11271      }
11272    "#},
11273      // Different container queries (cssnano test/index.js:164).
11274      indoc! {r#"
11275      @container (width >= 200px) {
11276        .mobile {
11277          --display: none;
11278        }
11279      }
11280
11281      @container (width <= 100px) {
11282        .notMobile {
11283          --display: none;
11284        }
11285      }
11286    "#},
11287      // Different nested contexts (cssnano test/index.js:1004).
11288      indoc! {r#"
11289      @media (width >= 48rem) {
11290        .wrapper {
11291          --display: block;
11292        }
11293      }
11294
11295      @supports (display: flex) {
11296        @media (width >= 48rem) {
11297          .wrapper {
11298            --display: flex;
11299          }
11300        }
11301      }
11302    "#},
11303      // Keyframes use a separate rule type (cssnano test/index.js:662).
11304      indoc! {r#"
11305      @keyframes foo {
11306        0% {
11307          --shared: long-value;
11308          --opacity: 0;
11309        }
11310
11311        to {
11312          --shared: long-value;
11313          --opacity: 1;
11314        }
11315      }
11316    "#},
11317      // Different cascade layers must not share rules.
11318      indoc! {r#"
11319      @layer base {
11320        .a {
11321          --shared: long-value;
11322          color: red;
11323        }
11324      }
11325
11326      @layer theme {
11327        .b {
11328          --shared: long-value;
11329          color: green;
11330        }
11331      }
11332    "#},
11333      // Mixed vendor pseudo selectors (cssnano test/index.js:325).
11334      indoc! {r#"
11335      code :-ms-placeholder-shown {
11336        --shared: very-long-shared-value;
11337        color: red;
11338      }
11339
11340      code::-moz-placeholder {
11341        --shared: very-long-shared-value;
11342        color: green;
11343      }
11344    "#},
11345      // Unknown and known selectors (cssnano test/index.js:878).
11346      indoc! {r#"
11347      p {
11348        --shared: long-value;
11349        color: red;
11350      }
11351
11352      :nonsense {
11353        --shared: long-value;
11354        color: green;
11355      }
11356    "#},
11357    ] {
11358      test(source, source);
11359    }
11360  }
11361
11362  #[test]
11363  fn test_merge_rules() {
11364    test(
11365      r#"
11366      .foo {
11367        color: red;
11368      }
11369      .bar {
11370        color: red;
11371      }
11372    "#,
11373      indoc! {r#"
11374      .foo, .bar {
11375        color: red;
11376      }
11377    "#},
11378    );
11379    test(
11380      r#"
11381      .foo {
11382        color: red;
11383      }
11384      .foo {
11385        background: green;
11386      }
11387    "#,
11388      indoc! {r#"
11389      .foo {
11390        color: red;
11391        background: green;
11392      }
11393    "#},
11394    );
11395    test(
11396      r#"
11397      .foo {
11398        color: red;
11399      }
11400      .foo {
11401        background: green !important;
11402      }
11403    "#,
11404      indoc! {r#"
11405      .foo {
11406        color: red;
11407        background: green !important;
11408      }
11409    "#},
11410    );
11411    test(
11412      r#"
11413      .foo {
11414        background: red;
11415      }
11416      .foo {
11417        background: green;
11418      }
11419    "#,
11420      indoc! {r#"
11421      .foo {
11422        background: green;
11423      }
11424    "#},
11425    );
11426    test(
11427      r#"
11428      .foo {
11429        --foo: red;
11430        --foo: purple;
11431      }
11432      .foo {
11433        --foo: green;
11434      }
11435    "#,
11436      indoc! {r#"
11437      .foo {
11438        --foo: green;
11439      }
11440    "#},
11441    );
11442    test(
11443      r#"
11444      .foo {
11445        color: red;
11446      }
11447
11448      .bar {
11449        background: green;
11450      }
11451    "#,
11452      indoc! {r#"
11453      .foo {
11454        color: red;
11455      }
11456
11457      .bar {
11458        background: green;
11459      }
11460    "#},
11461    );
11462    test(
11463      r#"
11464      .foo {
11465        color: red;
11466      }
11467
11468      .baz {
11469        color: blue;
11470      }
11471
11472      .bar {
11473        color: red;
11474      }
11475    "#,
11476      indoc! {r#"
11477      .foo {
11478        color: red;
11479      }
11480
11481      .baz {
11482        color: #00f;
11483      }
11484
11485      .bar {
11486        color: red;
11487      }
11488    "#},
11489    );
11490    test(
11491      r#"
11492      .foo {
11493        background: red;
11494      }
11495      .bar {
11496        background: red;
11497      }
11498      .foo {
11499        color: green;
11500      }
11501      .bar {
11502        color: green;
11503      }
11504    "#,
11505      indoc! {r#"
11506      .foo, .bar {
11507        color: green;
11508        background: red;
11509      }
11510    "#},
11511    );
11512    test(
11513      r#"
11514      .foo, .bar {
11515        background: red;
11516      }
11517      .foo {
11518        color: green;
11519      }
11520      .bar {
11521        color: green;
11522      }
11523    "#,
11524      indoc! {r#"
11525      .foo, .bar {
11526        color: green;
11527        background: red;
11528      }
11529    "#},
11530    );
11531    test(
11532      r#"
11533      .foo {
11534        background: red;
11535      }
11536      .foo {
11537        color: green;
11538      }
11539      .bar {
11540        background: red;
11541      }
11542      .bar {
11543        color: green;
11544      }
11545    "#,
11546      indoc! {r#"
11547      .foo, .bar {
11548        color: green;
11549        background: red;
11550      }
11551    "#},
11552    );
11553    test(
11554      r#"
11555      [foo="bar"] {
11556        color: red;
11557      }
11558      .bar {
11559        color: red;
11560      }
11561    "#,
11562      indoc! {r#"
11563      [foo="bar"], .bar {
11564        color: red;
11565      }
11566    "#},
11567    );
11568    test(
11569      r#"
11570      .a {
11571        color: red;
11572      }
11573      .b {
11574        color: green;
11575      }
11576      .a {
11577        color: red;
11578      }
11579    "#,
11580      indoc! {r#"
11581      .b {
11582        color: green;
11583      }
11584
11585      .a {
11586        color: red;
11587      }
11588    "#},
11589    );
11590    test(
11591      r#"
11592      .a {
11593        color: red;
11594      }
11595      .b {
11596        color: green;
11597      }
11598      .a {
11599        color: pink;
11600      }
11601    "#,
11602      indoc! {r#"
11603      .b {
11604        color: green;
11605      }
11606
11607      .a {
11608        color: pink;
11609      }
11610    "#},
11611    );
11612    test(
11613      r#"
11614      .a:foo(#000) {
11615        color: red;
11616      }
11617      .b {
11618        color: green;
11619      }
11620      .a:foo(#ff0) {
11621        color: pink;
11622      }
11623    "#,
11624      indoc! {r#"
11625      .a:foo(#000) {
11626        color: red;
11627      }
11628
11629      .b {
11630        color: green;
11631      }
11632
11633      .a:foo(#ff0) {
11634        color: pink;
11635      }
11636    "#},
11637    );
11638    test(
11639      r#"
11640      .a {
11641        border-radius: 10px;
11642      }
11643      .b {
11644        color: green;
11645      }
11646      .a {
11647        border-radius: 10px;
11648      }
11649    "#,
11650      indoc! {r#"
11651      .b {
11652        color: green;
11653      }
11654
11655      .a {
11656        border-radius: 10px;
11657      }
11658    "#},
11659    );
11660    test(
11661      r#"
11662      .a {
11663        border-radius: 10px;
11664      }
11665      .b {
11666        color: green;
11667      }
11668      .a {
11669        -webkit-border-radius: 10px;
11670      }
11671    "#,
11672      indoc! {r#"
11673      .a {
11674        border-radius: 10px;
11675      }
11676
11677      .b {
11678        color: green;
11679      }
11680
11681      .a {
11682        -webkit-border-radius: 10px;
11683      }
11684    "#},
11685    );
11686    test(
11687      r#"
11688      .a {
11689        border-radius: 10px;
11690      }
11691      .b {
11692        color: green;
11693      }
11694      .a {
11695        border-radius: var(--foo);
11696      }
11697    "#,
11698      indoc! {r#"
11699      .b {
11700        color: green;
11701      }
11702
11703      .a {
11704        border-radius: var(--foo);
11705      }
11706    "#},
11707    );
11708    test(
11709      r#"
11710      .a {
11711        border-radius: 10px;
11712      }
11713      .b {
11714        color: green;
11715      }
11716      .c {
11717        border-radius: 20px;
11718      }
11719    "#,
11720      indoc! {r#"
11721      .a {
11722        border-radius: 10px;
11723      }
11724
11725      .b {
11726        color: green;
11727      }
11728
11729      .c {
11730        border-radius: 20px;
11731      }
11732    "#},
11733    );
11734    test(
11735      r#"
11736      @media print {
11737        .a {
11738          color: red;
11739        }
11740        .b {
11741          color: green;
11742        }
11743        .a {
11744          color: red;
11745        }
11746      }
11747    "#,
11748      indoc! {r#"
11749      @media print {
11750        .b {
11751          color: green;
11752        }
11753
11754        .a {
11755          color: red;
11756        }
11757      }
11758    "#},
11759    );
11760    test(
11761      r#"
11762      .a {
11763        border-radius: 10px;
11764      }
11765      .b {
11766        color: green;
11767      }
11768      .a {
11769        border-radius: 20px;
11770        color: pink;
11771      }
11772    "#,
11773      indoc! {r#"
11774      .a {
11775        border-radius: 10px;
11776      }
11777
11778      .b {
11779        color: green;
11780      }
11781
11782      .a {
11783        color: pink;
11784        border-radius: 20px;
11785      }
11786    "#},
11787    );
11788    test(
11789      r#"
11790      .a {
11791        color: red;
11792      }
11793      .b {
11794        color: green;
11795      }
11796      .a {
11797        color: red;
11798      }
11799      .b {
11800        color: green;
11801      }
11802    "#,
11803      indoc! {r#"
11804      .a {
11805        color: red;
11806      }
11807
11808      .b {
11809        color: green;
11810      }
11811    "#},
11812    );
11813
11814    prefix_test(
11815      r#"
11816      [foo="bar"] {
11817        color: red;
11818      }
11819      .bar {
11820        color: red;
11821      }
11822    "#,
11823      indoc! {r#"
11824      [foo="bar"] {
11825        color: red;
11826      }
11827
11828      .bar {
11829        color: red;
11830      }
11831    "#},
11832      Browsers {
11833        ie: Some(6 << 16),
11834        ..Browsers::default()
11835      },
11836    );
11837
11838    prefix_test(
11839      r#"
11840      [foo="bar"] {
11841        color: red;
11842      }
11843      .bar {
11844        color: red;
11845      }
11846    "#,
11847      indoc! {r#"
11848      [foo="bar"], .bar {
11849        color: red;
11850      }
11851    "#},
11852      Browsers {
11853        ie: Some(10 << 16),
11854        ..Browsers::default()
11855      },
11856    );
11857
11858    test(
11859      r#"
11860      .foo:-moz-read-only {
11861        color: red;
11862      }
11863    "#,
11864      indoc! {r#"
11865      .foo:-moz-read-only {
11866        color: red;
11867      }
11868    "#},
11869    );
11870
11871    test(
11872      r#"
11873      .foo:-moz-read-only {
11874        color: red;
11875      }
11876
11877      .foo:read-only {
11878        color: red;
11879      }
11880    "#,
11881      indoc! {r#"
11882      .foo:-moz-read-only {
11883        color: red;
11884      }
11885
11886      .foo:read-only {
11887        color: red;
11888      }
11889    "#},
11890    );
11891
11892    prefix_test(
11893      r#"
11894      .foo:-moz-read-only {
11895        color: red;
11896      }
11897
11898      .foo:read-only {
11899        color: red;
11900      }
11901    "#,
11902      indoc! {r#"
11903      .foo:read-only {
11904        color: red;
11905      }
11906    "#},
11907      Browsers {
11908        firefox: Some(85 << 16),
11909        ..Browsers::default()
11910      },
11911    );
11912
11913    prefix_test(
11914      r#"
11915      .foo:-moz-read-only {
11916        color: red;
11917      }
11918
11919      .bar {
11920        color: yellow;
11921      }
11922
11923      .foo:read-only {
11924        color: red;
11925      }
11926    "#,
11927      indoc! {r#"
11928      .foo:-moz-read-only {
11929        color: red;
11930      }
11931
11932      .bar {
11933        color: #ff0;
11934      }
11935
11936      .foo:read-only {
11937        color: red;
11938      }
11939    "#},
11940      Browsers {
11941        firefox: Some(85 << 16),
11942        ..Browsers::default()
11943      },
11944    );
11945
11946    prefix_test(
11947      r#"
11948      .foo:-moz-read-only {
11949        color: red;
11950      }
11951
11952      .foo:read-only {
11953        color: red;
11954      }
11955    "#,
11956      indoc! {r#"
11957      .foo:-moz-read-only {
11958        color: red;
11959      }
11960
11961      .foo:read-only {
11962        color: red;
11963      }
11964    "#},
11965      Browsers {
11966        firefox: Some(36 << 16),
11967        ..Browsers::default()
11968      },
11969    );
11970
11971    prefix_test(
11972      r#"
11973      .foo:read-only {
11974        color: red;
11975      }
11976    "#,
11977      indoc! {r#"
11978      .foo:-moz-read-only {
11979        color: red;
11980      }
11981
11982      .foo:read-only {
11983        color: red;
11984      }
11985    "#},
11986      Browsers {
11987        firefox: Some(36 << 16),
11988        ..Browsers::default()
11989      },
11990    );
11991
11992    prefix_test(
11993      r#"
11994      .foo:-webkit-full-screen {
11995        color: red;
11996      }
11997      .foo:-moz-full-screen {
11998        color: red;
11999      }
12000      .foo:-ms-fullscreen {
12001        color: red;
12002      }
12003      .foo:fullscreen {
12004        color: red;
12005      }
12006    "#,
12007      indoc! {r#"
12008      .foo:fullscreen {
12009        color: red;
12010      }
12011    "#},
12012      Browsers {
12013        chrome: Some(96 << 16),
12014        ..Browsers::default()
12015      },
12016    );
12017
12018    prefix_test(
12019      r#"
12020      .foo:fullscreen {
12021        color: red;
12022      }
12023    "#,
12024      indoc! {r#"
12025      .foo:-webkit-full-screen {
12026        color: red;
12027      }
12028
12029      .foo:-moz-full-screen {
12030        color: red;
12031      }
12032
12033      .foo:-ms-fullscreen {
12034        color: red;
12035      }
12036
12037      .foo:fullscreen {
12038        color: red;
12039      }
12040    "#},
12041      Browsers {
12042        chrome: Some(45 << 16),
12043        firefox: Some(45 << 16),
12044        ie: Some(11 << 16),
12045        ..Browsers::default()
12046      },
12047    );
12048
12049    prefix_test(
12050      r#"
12051      .foo::placeholder {
12052        color: red;
12053      }
12054    "#,
12055      indoc! {r#"
12056      .foo::-webkit-input-placeholder {
12057        color: red;
12058      }
12059
12060      .foo::-moz-placeholder {
12061        color: red;
12062      }
12063
12064      .foo::-ms-input-placeholder {
12065        color: red;
12066      }
12067
12068      .foo::placeholder {
12069        color: red;
12070      }
12071    "#},
12072      Browsers {
12073        chrome: Some(45 << 16),
12074        firefox: Some(45 << 16),
12075        ie: Some(11 << 16),
12076        ..Browsers::default()
12077      },
12078    );
12079
12080    prefix_test(
12081      r#"
12082      .foo::file-selector-button {
12083        color: red;
12084      }
12085    "#,
12086      indoc! {r#"
12087      .foo::-webkit-file-upload-button {
12088        color: red;
12089      }
12090
12091      .foo::-ms-browse {
12092        color: red;
12093      }
12094
12095      .foo::file-selector-button {
12096        color: red;
12097      }
12098    "#},
12099      Browsers {
12100        chrome: Some(84 << 16),
12101        ie: Some(10 << 16),
12102        ..Browsers::default()
12103      },
12104    );
12105
12106    prefix_test(
12107      r#"
12108      .foo::file-selector-button {
12109        margin-inline-start: 2px;
12110      }
12111    "#,
12112      indoc! {r#"
12113      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)))::-webkit-file-upload-button {
12114        margin-left: 2px;
12115      }
12116
12117      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)))::-ms-browse {
12118        margin-left: 2px;
12119      }
12120
12121      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)))::file-selector-button {
12122        margin-left: 2px;
12123      }
12124
12125      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))::-webkit-file-upload-button {
12126        margin-right: 2px;
12127      }
12128
12129      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))::-ms-browse {
12130        margin-right: 2px;
12131      }
12132
12133      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))::file-selector-button {
12134        margin-right: 2px;
12135      }
12136    "#},
12137      Browsers {
12138        chrome: Some(84 << 16),
12139        ie: Some(10 << 16),
12140        ..Browsers::default()
12141      },
12142    );
12143
12144    prefix_test(
12145      r#"
12146      .foo:placeholder-shown .bar { color: red; }
12147      .foo:autofill .baz { color: red; }
12148      "#,
12149      indoc! {r#"
12150      .foo:placeholder-shown .bar {
12151        color: red;
12152      }
12153
12154      .foo:-webkit-autofill .baz {
12155        color: red;
12156      }
12157
12158      .foo:autofill .baz {
12159        color: red;
12160      }
12161      "#},
12162      Browsers {
12163        chrome: Some(103 << 16),
12164        ..Browsers::default()
12165      },
12166    );
12167
12168    prefix_test(
12169      r#"
12170      .foo:placeholder-shown .bar,.foo:autofill .baz{color:red}
12171      "#,
12172      indoc! {r#"
12173      :-webkit-any(.foo:placeholder-shown .bar, .foo:-webkit-autofill .baz) {
12174        color: red;
12175      }
12176
12177      :is(.foo:placeholder-shown .bar, .foo:autofill .baz) {
12178        color: red;
12179      }
12180      "#},
12181      Browsers {
12182        chrome: Some(103 << 16),
12183        ..Browsers::default()
12184      },
12185    );
12186
12187    prefix_test(
12188      r#"
12189      .foo:placeholder-shown .bar, .foo:-webkit-autofill .baz {
12190        color: red;
12191      }
12192
12193      .foo:placeholder-shown .bar, .foo:autofill .baz {
12194        color: red;
12195      }
12196      "#,
12197      indoc! {r#"
12198      :-webkit-any(.foo:placeholder-shown .bar, .foo:-webkit-autofill .baz) {
12199        color: red;
12200      }
12201
12202      :is(.foo:placeholder-shown .bar, .foo:autofill .baz) {
12203        color: red;
12204      }
12205      "#},
12206      Browsers {
12207        chrome: Some(103 << 16),
12208        ..Browsers::default()
12209      },
12210    );
12211
12212    test(
12213      r#"
12214      .foo:placeholder-shown .bar, .foo:-webkit-autofill .baz {
12215        color: red;
12216      }
12217
12218      .foo:placeholder-shown .bar, .foo:autofill .baz {
12219        color: red;
12220      }
12221      "#,
12222      indoc! {r#"
12223      .foo:placeholder-shown .bar, .foo:-webkit-autofill .baz {
12224        color: red;
12225      }
12226
12227      .foo:placeholder-shown .bar, .foo:autofill .baz {
12228        color: red;
12229      }
12230      "#},
12231    );
12232
12233    prefix_test(
12234      r#"
12235      :hover, :focus-visible {
12236        color: red;
12237      }
12238      "#,
12239      indoc! {r#"
12240      :hover {
12241        color: red;
12242      }
12243
12244      :focus-visible {
12245        color: red;
12246      }
12247      "#},
12248      Browsers {
12249        safari: Some(13 << 16),
12250        ..Browsers::default()
12251      },
12252    );
12253
12254    prefix_test(
12255      r#"
12256      .foo {
12257        color: red;
12258      }
12259
12260      :hover, :focus-visible {
12261        color: red;
12262      }
12263      "#,
12264      indoc! {r#"
12265      .foo, :hover {
12266        color: red;
12267      }
12268
12269      :focus-visible {
12270        color: red;
12271      }
12272      "#},
12273      Browsers {
12274        safari: Some(13 << 16),
12275        ..Browsers::default()
12276      },
12277    );
12278
12279    prefix_test(
12280      r#"
12281      :hover, :focus-visible {
12282        margin-inline-start: 24px;
12283      }
12284      "#,
12285      indoc! {r#"
12286      :hover:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
12287        margin-left: 24px;
12288      }
12289
12290      :hover:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
12291        margin-right: 24px;
12292      }
12293
12294      :focus-visible:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
12295        margin-left: 24px;
12296      }
12297
12298      :focus-visible:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
12299        margin-right: 24px;
12300      }
12301      "#},
12302      Browsers {
12303        safari: Some(11 << 16),
12304        ..Browsers::default()
12305      },
12306    );
12307
12308    prefix_test(
12309      r#"
12310      :focus-within, :focus-visible {
12311        color: red;
12312      }
12313      "#,
12314      indoc! {r#"
12315      :focus-within {
12316        color: red;
12317      }
12318
12319      :focus-visible {
12320        color: red;
12321      }
12322      "#},
12323      Browsers {
12324        safari: Some(9 << 16),
12325        ..Browsers::default()
12326      },
12327    );
12328
12329    prefix_test(
12330      r#"
12331      :hover, :focus-visible {
12332        color: red;
12333      }
12334      "#,
12335      indoc! {r#"
12336      :is(:hover, :focus-visible) {
12337        color: red;
12338      }
12339      "#},
12340      Browsers {
12341        safari: Some(14 << 16),
12342        ..Browsers::default()
12343      },
12344    );
12345
12346    prefix_test(
12347      r#"
12348      a::after:hover, a::after:focus-visible {
12349        color: red;
12350      }
12351      "#,
12352      indoc! {r#"
12353      a:after:hover {
12354        color: red;
12355      }
12356
12357      a:after:focus-visible {
12358        color: red;
12359      }
12360      "#},
12361      Browsers {
12362        safari: Some(14 << 16),
12363        ..Browsers::default()
12364      },
12365    );
12366
12367    prefix_test(
12368      r#"
12369      a:not(:hover), a:not(:focus-visible) {
12370        color: red;
12371      }
12372      "#,
12373      indoc! {r#"
12374      :is(a:not(:hover), a:not(:focus-visible)) {
12375        color: red;
12376      }
12377      "#},
12378      Browsers {
12379        safari: Some(14 << 16),
12380        ..Browsers::default()
12381      },
12382    );
12383
12384    prefix_test(
12385      r#"
12386      a:has(:hover), a:has(:focus-visible) {
12387        color: red;
12388      }
12389      "#,
12390      indoc! {r#"
12391      :is(a:has(:hover), a:has(:focus-visible)) {
12392        color: red;
12393      }
12394      "#},
12395      Browsers {
12396        safari: Some(14 << 16),
12397        ..Browsers::default()
12398      },
12399    );
12400
12401    prefix_test(
12402      r#"
12403      .foo.foo:hover, .bar:focus-visible {
12404        color: red;
12405      }
12406      "#,
12407      indoc! {r#"
12408      .foo.foo:hover {
12409        color: red;
12410      }
12411
12412      .bar:focus-visible {
12413        color: red;
12414      }
12415      "#},
12416      Browsers {
12417        safari: Some(14 << 16),
12418        ..Browsers::default()
12419      },
12420    );
12421
12422    prefix_test(
12423      r#"
12424      a::unknown-a, a::unknown-b {
12425        color: red;
12426      }
12427      "#,
12428      indoc! {r#"
12429      a::unknown-a {
12430        color: red;
12431      }
12432
12433      a::unknown-b {
12434        color: red;
12435      }
12436      "#},
12437      Browsers {
12438        safari: Some(14 << 16),
12439        ..Browsers::default()
12440      },
12441    );
12442
12443    nesting_test_with_targets(
12444      r#"
12445      .foo {
12446        padding-inline-start: 3px;
12447
12448        .bar {
12449          padding-inline-start: 5px;
12450        }
12451      }
12452      "#,
12453      indoc! {r#"
12454      .foo:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
12455        padding-left: 3px;
12456      }
12457
12458      .foo:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
12459        padding-right: 3px;
12460      }
12461
12462      .foo .bar:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
12463        padding-left: 5px;
12464      }
12465
12466      .foo .bar:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
12467        padding-right: 5px;
12468      }
12469      "#},
12470      Browsers {
12471        safari: Some(12 << 16),
12472        ..Browsers::default()
12473      }
12474      .into(),
12475    );
12476
12477    prefix_test(
12478      r#"
12479      .foo::part(header), .foo::part(body) {
12480        display: none
12481      }
12482      "#,
12483      indoc! {r#"
12484      .foo::part(header), .foo::part(body) {
12485        display: none;
12486      }
12487      "#},
12488      Browsers {
12489        safari: Some(14 << 16),
12490        ..Browsers::default()
12491      },
12492    );
12493
12494    prefix_test(
12495      r#"
12496      .foo :is(.bar) {
12497        color: red;
12498      }
12499      "#,
12500      indoc! {r#"
12501        .foo .bar {
12502          color: red;
12503        }
12504      "#},
12505      Browsers {
12506        chrome: Some(87 << 16),
12507        ..Browsers::default()
12508      },
12509    );
12510
12511    prefix_test(
12512      r#"
12513      .foo :is(.bar), .bar :is(.baz) {
12514        color: red;
12515      }
12516      "#,
12517      indoc! {r#"
12518        .foo .bar, .bar .baz {
12519          color: red;
12520        }
12521      "#},
12522      Browsers {
12523        chrome: Some(87 << 16),
12524        ..Browsers::default()
12525      },
12526    );
12527
12528    prefix_test(
12529      r#"
12530      .foo :is(.bar:focus-visible), .bar :is(.baz:hover) {
12531        color: red;
12532      }
12533      "#,
12534      indoc! {r#"
12535        .bar .baz:hover {
12536          color: red;
12537        }
12538
12539        .foo .bar:focus-visible {
12540          color: red;
12541        }
12542      "#},
12543      Browsers {
12544        chrome: Some(85 << 16),
12545        ..Browsers::default()
12546      },
12547    );
12548
12549    prefix_test(
12550      r#"
12551      *,
12552      ::before,
12553      ::after,
12554      ::backdrop {
12555        padding: 5px;
12556      }
12557      "#,
12558      indoc! {r#"
12559        *, :before, :after {
12560          padding: 5px;
12561        }
12562
12563        ::-webkit-backdrop {
12564          padding: 5px;
12565        }
12566
12567        ::backdrop {
12568          padding: 5px;
12569        }
12570      "#},
12571      Browsers {
12572        chrome: Some(33 << 16),
12573        ..Browsers::default()
12574      },
12575    );
12576
12577    test(
12578      r#"
12579      .foo:-webkit-any(.bar, .baz):after {
12580        color: red;
12581      }
12582
12583      .foo:is(.bar, .baz):after {
12584        color: red;
12585      }
12586      "#,
12587      indoc! {r#"
12588        .foo:-webkit-any(.bar, .baz):after {
12589          color: red;
12590        }
12591
12592        .foo:is(.bar, .baz):after {
12593          color: red;
12594        }
12595      "#},
12596    );
12597
12598    prefix_test(
12599      r#"
12600      .foo:-webkit-any(.bar, .baz):after {
12601        color: red;
12602      }
12603
12604      .foo:is(.bar, .baz):after {
12605        color: red;
12606      }
12607      "#,
12608      indoc! {r#"
12609        .foo:is(.bar, .baz):after {
12610          color: red;
12611        }
12612      "#},
12613      Browsers {
12614        safari: Some(16 << 16),
12615        ..Browsers::default()
12616      },
12617    );
12618
12619    prefix_test(
12620      r#"
12621      .foo:-webkit-any(.bar):after {
12622        color: red;
12623      }
12624
12625      .foo:is(.bar, .baz):after {
12626        color: red;
12627      }
12628      "#,
12629      indoc! {r#"
12630        .foo:-webkit-any(.bar):after {
12631          color: red;
12632        }
12633
12634        .foo:is(.bar, .baz):after {
12635          color: red;
12636        }
12637      "#},
12638      Browsers {
12639        safari: Some(16 << 16),
12640        ..Browsers::default()
12641      },
12642    );
12643
12644    prefix_test(
12645      r#"
12646      .foo:-webkit-any(.bar, .baz):after {
12647        color: red;
12648      }
12649
12650      .foo:is(.bar, .baz):after {
12651        color: red;
12652      }
12653      "#,
12654      indoc! {r#"
12655        .foo:-webkit-any(.bar, .baz):after {
12656          color: red;
12657        }
12658
12659        .foo:is(.bar, .baz):after {
12660          color: red;
12661        }
12662      "#},
12663      Browsers {
12664        safari: Some(12 << 16),
12665        ..Browsers::default()
12666      },
12667    );
12668
12669    prefix_test(
12670      r#"
12671      .foo:-webkit-any(.bar, .baz):after {
12672        color: red;
12673      }
12674
12675      .foo:-moz-any(.bar, .baz):after {
12676        color: red;
12677      }
12678      "#,
12679      indoc! {r#"
12680        .foo:-webkit-any(.bar, .baz):after {
12681          color: red;
12682        }
12683
12684        .foo:-moz-any(.bar, .baz):after {
12685          color: red;
12686        }
12687      "#},
12688      Browsers {
12689        safari: Some(12 << 16),
12690        firefox: Some(67 << 16),
12691        ..Browsers::default()
12692      },
12693    );
12694
12695    prefix_test(
12696      r#"
12697      .a {
12698        padding-inline: var(--foo);
12699      }
12700
12701      .a:-webkit-any(.b, .c) {
12702        padding-inline: var(--foo);
12703      }
12704      "#,
12705      indoc! {r#"
12706        .a {
12707          padding-inline: var(--foo);
12708        }
12709
12710        .a:-webkit-any(.b, .c) {
12711          padding-inline: var(--foo);
12712        }
12713      "#},
12714      Browsers {
12715        safari: Some(12 << 16),
12716        ..Browsers::default()
12717      },
12718    );
12719  }
12720
12721  #[test]
12722  fn test_merge_media_rules() {
12723    test(
12724      r#"
12725      @media (hover) {
12726        .foo {
12727          color: red;
12728        }
12729      }
12730      @media (hover) {
12731        .foo {
12732          background: #fff;
12733        }
12734
12735        .baz {
12736          color: #fff;
12737        }
12738      }
12739      "#,
12740      indoc! {r#"
12741      @media (hover) {
12742        .foo {
12743          color: red;
12744          background: #fff;
12745        }
12746
12747        .baz {
12748          color: #fff;
12749        }
12750      }
12751    "#},
12752    );
12753
12754    test(
12755      r#"
12756      @media (hover) {
12757        .foo {
12758          color: red;
12759        }
12760      }
12761      @media (min-width: 250px) {
12762        .foo {
12763          background: #fff;
12764        }
12765
12766        .baz {
12767          color: #fff;
12768        }
12769      }
12770      "#,
12771      indoc! {r#"
12772      @media (hover) {
12773        .foo {
12774          color: red;
12775        }
12776      }
12777
12778      @media (width >= 250px) {
12779        .foo {
12780          background: #fff;
12781        }
12782
12783        .baz {
12784          color: #fff;
12785        }
12786      }
12787    "#},
12788    );
12789  }
12790
12791  #[test]
12792  fn test_merge_supports() {
12793    test(
12794      r#"
12795      @supports (flex: 1) {
12796        .foo {
12797          color: red;
12798        }
12799      }
12800      @supports (flex: 1) {
12801        .foo {
12802          background: #fff;
12803        }
12804
12805        .baz {
12806          color: #fff;
12807        }
12808      }
12809      "#,
12810      indoc! {r#"
12811      @supports (flex: 1) {
12812        .foo {
12813          color: red;
12814          background: #fff;
12815        }
12816
12817        .baz {
12818          color: #fff;
12819        }
12820      }
12821    "#},
12822    );
12823
12824    test(
12825      r#"
12826      @supports (flex: 1) {
12827        .foo {
12828          color: red;
12829        }
12830      }
12831      @supports (display: grid) {
12832        .foo {
12833          background: #fff;
12834        }
12835
12836        .baz {
12837          color: #fff;
12838        }
12839      }
12840      "#,
12841      indoc! {r#"
12842      @supports (flex: 1) {
12843        .foo {
12844          color: red;
12845        }
12846      }
12847
12848      @supports (display: grid) {
12849        .foo {
12850          background: #fff;
12851        }
12852
12853        .baz {
12854          color: #fff;
12855        }
12856      }
12857    "#},
12858    );
12859  }
12860
12861  #[test]
12862  fn test_opacity() {
12863    minify_test(".foo { opacity: 0 }", ".foo{opacity:0}");
12864    minify_test(".foo { opacity: 0% }", ".foo{opacity:0}");
12865    minify_test(".foo { opacity: 0.5 }", ".foo{opacity:.5}");
12866    minify_test(".foo { opacity: 50% }", ".foo{opacity:.5}");
12867    minify_test(".foo { opacity: 1 }", ".foo{opacity:1}");
12868    minify_test(".foo { opacity: 100% }", ".foo{opacity:1}");
12869  }
12870
12871  #[test]
12872  fn test_transitions() {
12873    property_range_test(&["transition-delay"], &[("-1s", Some("-1s"))]);
12874    property_range_test(
12875      &["transition"],
12876      &[("opacity -1s", None), ("opacity 1s -1s", Some("opacity 1s -1s"))],
12877    );
12878    property_range_test(
12879      &["transition-duration"],
12880      &[("-1s", None), ("calc(1s - 2s)", Some("0s"))],
12881    );
12882    use crate::values::time::Time;
12883
12884    for (source, expected) in [
12885      ("-1s", None),
12886      ("-1ms", None),
12887      ("0s", Some("0s")),
12888      ("calc(-1s)", Some("0s")),
12889      ("calc(500ms - 1s)", Some("0s")),
12890      ("calc(-1s + 1500ms)", Some(".5s")),
12891      ("calc(min(-1s, -2s) + 3s)", Some("1s")),
12892      ("calc(1px)", None),
12893      ("calc(1)", None),
12894    ] {
12895      non_negative_test::<Time>(source, expected);
12896    }
12897    assert!(Time::parse_string("-1s").is_ok());
12898
12899    minify_test(".foo { transition-duration: 500ms }", ".foo{transition-duration:.5s}");
12900    minify_test(".foo { transition-duration: .5s }", ".foo{transition-duration:.5s}");
12901    minify_test(".foo { transition-duration: 99ms }", ".foo{transition-duration:99ms}");
12902    minify_test(".foo { transition-duration: .099s }", ".foo{transition-duration:99ms}");
12903    minify_test(".foo { transition-duration: 2000ms }", ".foo{transition-duration:2s}");
12904    minify_test(".foo { transition-duration: 2s }", ".foo{transition-duration:2s}");
12905    minify_test(
12906      ".foo { transition-duration: calc(1s - 50ms) }",
12907      ".foo{transition-duration:.95s}",
12908    );
12909    minify_test(
12910      ".foo { transition-duration: calc(1s - 50ms + 2s) }",
12911      ".foo{transition-duration:2.95s}",
12912    );
12913    minify_test(
12914      ".foo { transition-duration: calc((1s - 50ms) * 2) }",
12915      ".foo{transition-duration:1.9s}",
12916    );
12917    minify_test(
12918      ".foo { transition-duration: calc(2 * (1s - 50ms)) }",
12919      ".foo{transition-duration:1.9s}",
12920    );
12921    minify_test(
12922      ".foo { transition-duration: calc((2s + 50ms) - (1s - 50ms)) }",
12923      ".foo{transition-duration:1.1s}",
12924    );
12925    minify_test(
12926      ".foo { transition-duration: 500ms, 50ms }",
12927      ".foo{transition-duration:.5s,50ms}",
12928    );
12929    minify_test(".foo { transition-delay: 500ms }", ".foo{transition-delay:.5s}");
12930    minify_test(
12931      ".foo { transition-property: background }",
12932      ".foo{transition-property:background}",
12933    );
12934    minify_test(
12935      ".foo { transition-property: background, opacity }",
12936      ".foo{transition-property:background,opacity}",
12937    );
12938    minify_test(
12939      ".foo { transition-timing-function: linear }",
12940      ".foo{transition-timing-function:linear}",
12941    );
12942    minify_test(
12943      ".foo { transition-timing-function: ease }",
12944      ".foo{transition-timing-function:ease}",
12945    );
12946    minify_test(
12947      ".foo { transition-timing-function: ease-in }",
12948      ".foo{transition-timing-function:ease-in}",
12949    );
12950    minify_test(
12951      ".foo { transition-timing-function: ease-out }",
12952      ".foo{transition-timing-function:ease-out}",
12953    );
12954    minify_test(
12955      ".foo { transition-timing-function: ease-in-out }",
12956      ".foo{transition-timing-function:ease-in-out}",
12957    );
12958    minify_test(
12959      ".foo { transition-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1) }",
12960      ".foo{transition-timing-function:ease}",
12961    );
12962    minify_test(
12963      ".foo { transition-timing-function: cubic-bezier(0.42, 0, 1, 1) }",
12964      ".foo{transition-timing-function:ease-in}",
12965    );
12966    minify_test(
12967      ".foo { transition-timing-function: cubic-bezier(0, 0, 0.58, 1) }",
12968      ".foo{transition-timing-function:ease-out}",
12969    );
12970    minify_test(
12971      ".foo { transition-timing-function: cubic-bezier(0.42, 0, 0.58, 1) }",
12972      ".foo{transition-timing-function:ease-in-out}",
12973    );
12974    minify_test(
12975      ".foo { transition-timing-function: cubic-bezier(0.58, 0.2, 0.11, 1.2) }",
12976      ".foo{transition-timing-function:cubic-bezier(.58,.2,.11,1.2)}",
12977    );
12978    minify_test(
12979      ".foo { transition-timing-function: step-start }",
12980      ".foo{transition-timing-function:step-start}",
12981    );
12982    minify_test(
12983      ".foo { transition-timing-function: step-end }",
12984      ".foo{transition-timing-function:step-end}",
12985    );
12986    minify_test(
12987      ".foo { transition-timing-function: steps(1, start) }",
12988      ".foo{transition-timing-function:step-start}",
12989    );
12990    minify_test(
12991      ".foo { transition-timing-function: steps(1, jump-start) }",
12992      ".foo{transition-timing-function:step-start}",
12993    );
12994    minify_test(
12995      ".foo { transition-timing-function: steps(1, end) }",
12996      ".foo{transition-timing-function:step-end}",
12997    );
12998    minify_test(
12999      ".foo { transition-timing-function: steps(1, jump-end) }",
13000      ".foo{transition-timing-function:step-end}",
13001    );
13002    minify_test(
13003      ".foo { transition-timing-function: steps(5, jump-start) }",
13004      ".foo{transition-timing-function:steps(5,start)}",
13005    );
13006    minify_test(
13007      ".foo { transition-timing-function: steps(5, jump-end) }",
13008      ".foo{transition-timing-function:steps(5,end)}",
13009    );
13010    minify_test(
13011      ".foo { transition-timing-function: steps(5, jump-both) }",
13012      ".foo{transition-timing-function:steps(5,jump-both)}",
13013    );
13014    minify_test(
13015      ".foo { transition-timing-function: ease-in-out, cubic-bezier(0.42, 0, 1, 1) }",
13016      ".foo{transition-timing-function:ease-in-out,ease-in}",
13017    );
13018    minify_test(
13019      ".foo { transition-timing-function: cubic-bezier(0.42, 0, 1, 1), cubic-bezier(0.58, 0.2, 0.11, 1.2) }",
13020      ".foo{transition-timing-function:ease-in,cubic-bezier(.58,.2,.11,1.2)}",
13021    );
13022    minify_test(
13023      ".foo { transition-timing-function: step-start, steps(5, jump-start) }",
13024      ".foo{transition-timing-function:step-start,steps(5,start)}",
13025    );
13026    minify_test(".foo { transition: width 2s ease }", ".foo{transition:width 2s}");
13027    minify_test(
13028      ".foo { transition: width 2s ease, height 1000ms cubic-bezier(0.25, 0.1, 0.25, 1) }",
13029      ".foo{transition:width 2s,height 1s}",
13030    );
13031    minify_test(".foo { transition: width 2s 1s }", ".foo{transition:width 2s 1s}");
13032    minify_test(".foo { transition: width 2s ease 1s }", ".foo{transition:width 2s 1s}");
13033    minify_test(
13034      ".foo { transition: ease-in 1s width 4s }",
13035      ".foo{transition:width 1s ease-in 4s}",
13036    );
13037    minify_test(".foo { transition: opacity 0s .6s }", ".foo{transition:opacity 0s .6s}");
13038    test(
13039      r#"
13040      .foo {
13041        transition-property: opacity;
13042        transition-duration: 0.09s;
13043        transition-timing-function: ease-in-out;
13044        transition-delay: 500ms;
13045      }
13046    "#,
13047      indoc! {r#"
13048      .foo {
13049        transition: opacity 90ms ease-in-out .5s;
13050      }
13051    "#},
13052    );
13053    test(
13054      r#"
13055      .foo {
13056        transition: opacity 2s;
13057        transition-timing-function: ease;
13058        transition-delay: 500ms;
13059      }
13060    "#,
13061      indoc! {r#"
13062      .foo {
13063        transition: opacity 2s .5s;
13064      }
13065    "#},
13066    );
13067    test(
13068      r#"
13069      .foo {
13070        transition: opacity 500ms;
13071        transition-timing-function: var(--ease);
13072      }
13073    "#,
13074      indoc! {r#"
13075      .foo {
13076        transition: opacity .5s;
13077        transition-timing-function: var(--ease);
13078      }
13079    "#},
13080    );
13081    test(
13082      r#"
13083      .foo {
13084        transition-property: opacity;
13085        transition-duration: 0.09s;
13086        transition-timing-function: ease-in-out;
13087        transition-delay: 500ms;
13088        transition: color 2s;
13089      }
13090    "#,
13091      indoc! {r#"
13092      .foo {
13093        transition: color 2s;
13094      }
13095    "#},
13096    );
13097    test(
13098      r#"
13099      .foo {
13100        transition-property: opacity, color;
13101        transition-duration: 2s, 4s;
13102        transition-timing-function: ease-in-out, ease-in;
13103        transition-delay: 500ms, 0s;
13104      }
13105    "#,
13106      indoc! {r#"
13107      .foo {
13108        transition: opacity 2s ease-in-out .5s, color 4s ease-in;
13109      }
13110    "#},
13111    );
13112    test(
13113      r#"
13114      .foo {
13115        transition-property: opacity, color;
13116        transition-duration: 2s;
13117        transition-timing-function: ease-in-out;
13118        transition-delay: 500ms;
13119      }
13120    "#,
13121      indoc! {r#"
13122      .foo {
13123        transition: opacity 2s ease-in-out .5s, color 2s ease-in-out .5s;
13124      }
13125    "#},
13126    );
13127    test(
13128      r#"
13129      .foo {
13130        transition-property: opacity, color, width, height;
13131        transition-duration: 2s, 4s;
13132        transition-timing-function: ease;
13133        transition-delay: 0s;
13134      }
13135    "#,
13136      indoc! {r#"
13137      .foo {
13138        transition: opacity 2s, color 4s, width 2s, height 4s;
13139      }
13140    "#},
13141    );
13142
13143    test(
13144      r#"
13145      .foo {
13146        -webkit-transition-property: opacity, color;
13147        -webkit-transition-duration: 2s, 4s;
13148        -webkit-transition-timing-function: ease-in-out, ease-in;
13149        -webkit-transition-delay: 500ms, 0s;
13150      }
13151    "#,
13152      indoc! {r#"
13153      .foo {
13154        -webkit-transition: opacity 2s ease-in-out .5s, color 4s ease-in;
13155      }
13156    "#},
13157    );
13158
13159    test(
13160      r#"
13161      .foo {
13162        -webkit-transition-property: opacity, color;
13163        -webkit-transition-duration: 2s, 4s;
13164        -webkit-transition-timing-function: ease-in-out, ease-in;
13165        -webkit-transition-delay: 500ms, 0s;
13166        -moz-transition-property: opacity, color;
13167        -moz-transition-duration: 2s, 4s;
13168        -moz-transition-timing-function: ease-in-out, ease-in;
13169        -moz-transition-delay: 500ms, 0s;
13170        transition-property: opacity, color;
13171        transition-duration: 2s, 4s;
13172        transition-timing-function: ease-in-out, ease-in;
13173        transition-delay: 500ms, 0s;
13174      }
13175    "#,
13176      indoc! {r#"
13177      .foo {
13178        -webkit-transition: opacity 2s ease-in-out .5s, color 4s ease-in;
13179        -moz-transition: opacity 2s ease-in-out .5s, color 4s ease-in;
13180        transition: opacity 2s ease-in-out .5s, color 4s ease-in;
13181      }
13182    "#},
13183    );
13184
13185    test(
13186      r#"
13187      .foo {
13188        -webkit-transition-property: opacity, color;
13189        -moz-transition-property: opacity, color;
13190        transition-property: opacity, color;
13191        -webkit-transition-duration: 2s, 4s;
13192        -moz-transition-duration: 2s, 4s;
13193        transition-duration: 2s, 4s;
13194        -webkit-transition-timing-function: ease-in-out, ease-in;
13195        transition-timing-function: ease-in-out, ease-in;
13196        -moz-transition-timing-function: ease-in-out, ease-in;
13197        -webkit-transition-delay: 500ms, 0s;
13198        -moz-transition-delay: 500ms, 0s;
13199        transition-delay: 500ms, 0s;
13200      }
13201    "#,
13202      indoc! {r#"
13203      .foo {
13204        -webkit-transition: opacity 2s ease-in-out .5s, color 4s ease-in;
13205        -moz-transition: opacity 2s ease-in-out .5s, color 4s ease-in;
13206        transition: opacity 2s ease-in-out .5s, color 4s ease-in;
13207      }
13208    "#},
13209    );
13210
13211    test(
13212      r#"
13213      .foo {
13214        -webkit-transition-property: opacity;
13215        -moz-transition-property: color;
13216        transition-property: opacity, color;
13217        -webkit-transition-duration: 2s;
13218        -moz-transition-duration: 4s;
13219        transition-duration: 2s, 4s;
13220        -webkit-transition-timing-function: ease-in-out;
13221        -moz-transition-timing-function: ease-in-out;
13222        transition-timing-function: ease-in-out, ease-in;
13223        -webkit-transition-delay: 500ms;
13224        -moz-transition-delay: 0s;
13225        transition-delay: 500ms, 0s;
13226      }
13227    "#,
13228      indoc! {r#"
13229      .foo {
13230        -webkit-transition-property: opacity;
13231        -moz-transition-property: color;
13232        transition-property: opacity, color;
13233        -webkit-transition-duration: 2s;
13234        -moz-transition-duration: 4s;
13235        transition-duration: 2s, 4s;
13236        -webkit-transition-timing-function: ease-in-out;
13237        -moz-transition-timing-function: ease-in-out;
13238        -webkit-transition-delay: .5s;
13239        transition-timing-function: ease-in-out, ease-in;
13240        -moz-transition-delay: 0s;
13241        transition-delay: .5s, 0s;
13242      }
13243    "#},
13244    );
13245
13246    test(
13247      r#"
13248      .foo {
13249        -webkit-transition-property: opacity;
13250        transition-property: opacity, color;
13251        -moz-transition-property: color;
13252        -webkit-transition-duration: 2s;
13253        transition-duration: 2s, 4s;
13254        -moz-transition-duration: 4s;
13255        -webkit-transition-timing-function: ease-in-out;
13256        transition-timing-function: ease-in-out, ease-in;
13257        -moz-transition-timing-function: ease-in-out;
13258        -webkit-transition-delay: 500ms;
13259        transition-delay: 500ms, 0s;
13260        -moz-transition-delay: 0s;
13261      }
13262    "#,
13263      indoc! {r#"
13264      .foo {
13265        -webkit-transition-property: opacity;
13266        transition-property: opacity, color;
13267        -moz-transition-property: color;
13268        -webkit-transition-duration: 2s;
13269        transition-duration: 2s, 4s;
13270        -moz-transition-duration: 4s;
13271        -webkit-transition-timing-function: ease-in-out;
13272        transition-timing-function: ease-in-out, ease-in;
13273        -webkit-transition-delay: .5s;
13274        -moz-transition-timing-function: ease-in-out;
13275        transition-delay: .5s, 0s;
13276        -moz-transition-delay: 0s;
13277      }
13278    "#},
13279    );
13280
13281    test(
13282      r#"
13283      .foo {
13284        transition: opacity 2s;
13285        -webkit-transition-duration: 2s;
13286      }
13287    "#,
13288      indoc! {r#"
13289      .foo {
13290        transition: opacity 2s;
13291        -webkit-transition-duration: 2s;
13292      }
13293    "#},
13294    );
13295
13296    prefix_test(
13297      r#"
13298      .foo {
13299        transition-property: margin-inline-start;
13300      }
13301    "#,
13302      indoc! {r#"
13303      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
13304        transition-property: margin-left;
13305      }
13306
13307      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
13308        transition-property: margin-left;
13309      }
13310
13311      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
13312        transition-property: margin-right;
13313      }
13314
13315      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
13316        transition-property: margin-right;
13317      }
13318    "#
13319      },
13320      Browsers {
13321        safari: Some(8 << 16),
13322        ..Browsers::default()
13323      },
13324    );
13325
13326    prefix_test(
13327      r#"
13328      .foo {
13329        transition-property: margin-inline-start, padding-inline-start;
13330      }
13331    "#,
13332      indoc! {r#"
13333      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
13334        transition-property: margin-left, padding-left;
13335      }
13336
13337      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
13338        transition-property: margin-left, padding-left;
13339      }
13340
13341      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
13342        transition-property: margin-right, padding-right;
13343      }
13344
13345      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
13346        transition-property: margin-right, padding-right;
13347      }
13348    "#
13349      },
13350      Browsers {
13351        safari: Some(8 << 16),
13352        ..Browsers::default()
13353      },
13354    );
13355
13356    prefix_test(
13357      r#"
13358      .foo {
13359        transition-property: margin-inline-start, opacity, padding-inline-start, color;
13360      }
13361    "#,
13362      indoc! {r#"
13363      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
13364        transition-property: margin-left, opacity, padding-left, color;
13365      }
13366
13367      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
13368        transition-property: margin-left, opacity, padding-left, color;
13369      }
13370
13371      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
13372        transition-property: margin-right, opacity, padding-right, color;
13373      }
13374
13375      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
13376        transition-property: margin-right, opacity, padding-right, color;
13377      }
13378    "#
13379      },
13380      Browsers {
13381        safari: Some(8 << 16),
13382        ..Browsers::default()
13383      },
13384    );
13385
13386    prefix_test(
13387      r#"
13388      .foo {
13389        transition-property: margin-block;
13390      }
13391    "#,
13392      indoc! {r#"
13393      .foo {
13394        transition-property: margin-top, margin-bottom;
13395      }
13396    "#
13397      },
13398      Browsers {
13399        safari: Some(8 << 16),
13400        ..Browsers::default()
13401      },
13402    );
13403
13404    prefix_test(
13405      r#"
13406      .foo {
13407        transition: margin-inline-start 2s;
13408      }
13409    "#,
13410      indoc! {r#"
13411      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
13412        transition: margin-left 2s;
13413      }
13414
13415      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
13416        transition: margin-left 2s;
13417      }
13418
13419      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
13420        transition: margin-right 2s;
13421      }
13422
13423      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
13424        transition: margin-right 2s;
13425      }
13426    "#
13427      },
13428      Browsers {
13429        safari: Some(8 << 16),
13430        ..Browsers::default()
13431      },
13432    );
13433
13434    prefix_test(
13435      r#"
13436      .foo {
13437        transition: margin-inline-start 2s, padding-inline-start 2s;
13438      }
13439    "#,
13440      indoc! {r#"
13441      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
13442        transition: margin-left 2s, padding-left 2s;
13443      }
13444
13445      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
13446        transition: margin-left 2s, padding-left 2s;
13447      }
13448
13449      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
13450        transition: margin-right 2s, padding-right 2s;
13451      }
13452
13453      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
13454        transition: margin-right 2s, padding-right 2s;
13455      }
13456    "#
13457      },
13458      Browsers {
13459        safari: Some(8 << 16),
13460        ..Browsers::default()
13461      },
13462    );
13463
13464    prefix_test(
13465      r#"
13466      .foo {
13467        transition: margin-block-start 2s;
13468      }
13469    "#,
13470      indoc! {r#"
13471      .foo {
13472        transition: margin-top 2s;
13473      }
13474    "#
13475      },
13476      Browsers {
13477        safari: Some(8 << 16),
13478        ..Browsers::default()
13479      },
13480    );
13481
13482    prefix_test(
13483      r#"
13484      .foo {
13485        transition: transform;
13486      }
13487    "#,
13488      indoc! {r#"
13489      .foo {
13490        -webkit-transition: -webkit-transform, transform;
13491        transition: -webkit-transform, transform;
13492      }
13493    "#
13494      },
13495      Browsers {
13496        safari: Some(6 << 16),
13497        ..Browsers::default()
13498      },
13499    );
13500
13501    prefix_test(
13502      r#"
13503      .foo {
13504        transition: border-start-start-radius;
13505      }
13506    "#,
13507      indoc! {r#"
13508      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
13509        -webkit-transition: -webkit-border-top-left-radius, border-top-left-radius;
13510        transition: -webkit-border-top-left-radius, border-top-left-radius;
13511      }
13512
13513      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
13514        -webkit-transition: -webkit-border-top-right-radius, border-top-right-radius;
13515        transition: -webkit-border-top-right-radius, border-top-right-radius;
13516      }
13517    "#
13518      },
13519      Browsers {
13520        safari: Some(4 << 16),
13521        ..Browsers::default()
13522      },
13523    );
13524
13525    prefix_test(
13526      r#"
13527      .foo {
13528        transition: border-start-start-radius;
13529      }
13530    "#,
13531      indoc! {r#"
13532      .foo:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
13533        transition: border-top-left-radius;
13534      }
13535
13536      .foo:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
13537        transition: border-top-right-radius;
13538      }
13539    "#
13540      },
13541      Browsers {
13542        safari: Some(12 << 16),
13543        ..Browsers::default()
13544      },
13545    );
13546
13547    test(
13548      r#"
13549      .foo {
13550        -webkit-transition: background 200ms;
13551        -moz-transition: background 200ms;
13552        transition: background 230ms;
13553      }
13554    "#,
13555      indoc! {r#"
13556      .foo {
13557        -webkit-transition: background .2s;
13558        -moz-transition: background .2s;
13559        transition: background .23s;
13560      }
13561    "#},
13562    );
13563
13564    prefix_test(
13565      r#"
13566      .foo {
13567        -webkit-transition: background 200ms;
13568        -moz-transition: background 200ms;
13569        transition: background 230ms;
13570      }
13571    "#,
13572      indoc! {r#"
13573      .foo {
13574        -webkit-transition: background .2s;
13575        -moz-transition: background .2s;
13576        transition: background .23s;
13577      }
13578    "#},
13579      Browsers {
13580        chrome: Some(95 << 16),
13581        ..Browsers::default()
13582      },
13583    );
13584    prefix_test(
13585      r#"
13586       .foo {
13587         transition-property: -webkit-backdrop-filter, backdrop-filter;
13588       }
13589       .bar {
13590         transition-property: backdrop-filter;
13591       }
13592       .baz {
13593         transition-property: -webkit-backdrop-filter;
13594       }
13595     "#,
13596      indoc! {r#"
13597       .foo, .bar {
13598         transition-property: -webkit-backdrop-filter, backdrop-filter;
13599       }
13600
13601       .baz {
13602         transition-property: -webkit-backdrop-filter;
13603       }
13604     "#
13605      },
13606      Browsers {
13607        safari: Some(15 << 16),
13608        ..Browsers::default()
13609      },
13610    );
13611    prefix_test(
13612      r#"
13613       .foo {
13614         transition-property: -webkit-border-radius, -webkit-border-radius, -moz-border-radius;
13615       }
13616     "#,
13617      indoc! {r#"
13618       .foo {
13619         transition-property: -webkit-border-radius, -moz-border-radius;
13620       }
13621     "#
13622      },
13623      Browsers {
13624        safari: Some(15 << 16),
13625        ..Browsers::default()
13626      },
13627    );
13628    prefix_test(
13629      r#"
13630       .foo {
13631         transition: -webkit-backdrop-filter, backdrop-filter;
13632       }
13633       .bar {
13634         transition: backdrop-filter;
13635       }
13636       .baz {
13637         transition: -webkit-backdrop-filter;
13638       }
13639     "#,
13640      indoc! {r#"
13641       .foo, .bar {
13642         transition: -webkit-backdrop-filter, backdrop-filter;
13643       }
13644
13645       .baz {
13646         transition: -webkit-backdrop-filter;
13647       }
13648     "#
13649      },
13650      Browsers {
13651        safari: Some(15 << 16),
13652        ..Browsers::default()
13653      },
13654    );
13655  }
13656
13657  #[test]
13658  fn test_animation() {
13659    property_range_test(&["animation-delay"], &[("-1s", Some("-1s"))]);
13660    property_range_test(
13661      &["animation"],
13662      &[
13663        ("test -1s", None),
13664        ("test 1s -1s", Some("1s -1s test")),
13665        ("test 1s -1", None),
13666      ],
13667    );
13668    property_range_test(
13669      &["animation-iteration-count"],
13670      &[("-1", None), ("calc(1 - 2)", Some("0")), ("calc(-1 + 2)", Some("1"))],
13671    );
13672    property_range_test(&["animation-duration"], &[("-1s", None), ("calc(-1s)", Some("0s"))]);
13673    minify_test(".foo { animation-name: test }", ".foo{animation-name:test}");
13674    minify_test(".foo { animation-name: \"test\" }", ".foo{animation-name:test}");
13675    minify_test(".foo { animation-name: foo, bar }", ".foo{animation-name:foo,bar}");
13676    minify_test(".foo { animation-name: \"none\" }", ".foo{animation-name:\"none\"}");
13677    minify_test(
13678      ".foo { animation-name: \"none\", foo }",
13679      ".foo{animation-name:\"none\",foo}",
13680    );
13681    let name = crate::properties::animation::AnimationName::parse_string("default");
13682    assert!(matches!(name, Err(..)));
13683
13684    minify_test(".foo { animation-name: none }", ".foo{animation-name:none}");
13685    minify_test(".foo { animation-name: none, none }", ".foo{animation-name:none,none}");
13686
13687    // Test CSS-wide keywords
13688    minify_test(".foo { animation-name: unset }", ".foo{animation-name:unset}");
13689    minify_test(".foo { animation-name: \"unset\" }", ".foo{animation-name:\"unset\"}");
13690    minify_test(".foo { animation-name: \"revert\" }", ".foo{animation-name:\"revert\"}");
13691    minify_test(
13692      ".foo { animation-name: \"unset\", \"revert\"}",
13693      ".foo{animation-name:\"unset\",\"revert\"}",
13694    );
13695    minify_test(
13696      ".foo { animation-name: foo, \"revert\"}",
13697      ".foo{animation-name:foo,\"revert\"}",
13698    );
13699    minify_test(
13700      ".foo { animation-name: \"string\", \"revert\"}",
13701      ".foo{animation-name:string,\"revert\"}",
13702    );
13703    minify_test(
13704      ".foo { animation-name: \"string\", foo, \"revert\"}",
13705      ".foo{animation-name:string,foo,\"revert\"}",
13706    );
13707    minify_test(
13708      ".foo { animation-name: \"default\" }",
13709      ".foo{animation-name:\"default\"}",
13710    );
13711    minify_test(".foo { animation-duration: 100ms }", ".foo{animation-duration:.1s}");
13712    minify_test(
13713      ".foo { animation-duration: 100ms, 2000ms }",
13714      ".foo{animation-duration:.1s,2s}",
13715    );
13716    minify_test(
13717      ".foo { animation-timing-function: ease }",
13718      ".foo{animation-timing-function:ease}",
13719    );
13720    minify_test(
13721      ".foo { animation-timing-function: cubic-bezier(0.42, 0, 1, 1) }",
13722      ".foo{animation-timing-function:ease-in}",
13723    );
13724    minify_test(
13725      ".foo { animation-timing-function: ease, cubic-bezier(0.42, 0, 1, 1) }",
13726      ".foo{animation-timing-function:ease,ease-in}",
13727    );
13728    minify_test(
13729      ".foo { animation-iteration-count: 5 }",
13730      ".foo{animation-iteration-count:5}",
13731    );
13732    minify_test(
13733      ".foo { animation-iteration-count: 2.5 }",
13734      ".foo{animation-iteration-count:2.5}",
13735    );
13736    minify_test(
13737      ".foo { animation-iteration-count: 2.0 }",
13738      ".foo{animation-iteration-count:2}",
13739    );
13740    minify_test(
13741      ".foo { animation-iteration-count: infinite }",
13742      ".foo{animation-iteration-count:infinite}",
13743    );
13744    minify_test(
13745      ".foo { animation-iteration-count: 1, infinite }",
13746      ".foo{animation-iteration-count:1,infinite}",
13747    );
13748    minify_test(
13749      ".foo { animation-direction: reverse }",
13750      ".foo{animation-direction:reverse}",
13751    );
13752    minify_test(
13753      ".foo { animation-direction: alternate, reverse }",
13754      ".foo{animation-direction:alternate,reverse}",
13755    );
13756    minify_test(
13757      ".foo { animation-play-state: paused }",
13758      ".foo{animation-play-state:paused}",
13759    );
13760    minify_test(
13761      ".foo { animation-play-state: running, paused }",
13762      ".foo{animation-play-state:running,paused}",
13763    );
13764    minify_test(".foo { animation-delay: 100ms }", ".foo{animation-delay:.1s}");
13765    minify_test(
13766      ".foo { animation-delay: 100ms, 2000ms }",
13767      ".foo{animation-delay:.1s,2s}",
13768    );
13769    minify_test(
13770      ".foo { animation-fill-mode: forwards }",
13771      ".foo{animation-fill-mode:forwards}",
13772    );
13773    minify_test(
13774      ".foo { animation-fill-mode: Backwards,forwards }",
13775      ".foo{animation-fill-mode:backwards,forwards}",
13776    );
13777    minify_test(".foo { animation: none }", ".foo{animation:none}");
13778    minify_test(".foo { animation: \"none\" }", ".foo{animation:\"none\"}");
13779    minify_test(".foo { animation: \"None\" }", ".foo{animation:\"None\"}");
13780    minify_test(".foo { animation: \"none\", none }", ".foo{animation:\"none\",none}");
13781    minify_test(".foo { animation: none, none }", ".foo{animation:none,none}");
13782    minify_test(".foo { animation: \"none\" none }", ".foo{animation:\"none\"}");
13783    minify_test(".foo { animation: none none }", ".foo{animation:none}");
13784
13785    // Test animation-name + animation-fill-mode
13786    minify_test(
13787      ".foo { animation: 2s both \"none\"}",
13788      ".foo{animation:2s both \"none\"}",
13789    );
13790    minify_test(
13791      ".foo { animation: both \"none\" 2s}",
13792      ".foo{animation:2s both \"none\"}",
13793    );
13794    minify_test(".foo { animation: \"none\" 2s none}", ".foo{animation:2s \"none\"}");
13795    minify_test(".foo { animation: none \"none\" 2s}", ".foo{animation:2s \"none\"}");
13796    minify_test(
13797      ".foo { animation: none, \"none\" 2s forwards}",
13798      ".foo{animation:none,2s forwards \"none\"}",
13799    );
13800
13801    minify_test(".foo { animation: \"unset\" }", ".foo{animation:\"unset\"}");
13802    minify_test(".foo { animation: \"string\" .5s }", ".foo{animation:.5s string}");
13803    minify_test(".foo { animation: \"unset\" .5s }", ".foo{animation:.5s \"unset\"}");
13804    minify_test(
13805      ".foo { animation: none, \"unset\" .5s}",
13806      ".foo{animation:none,.5s \"unset\"}",
13807    );
13808    minify_test(
13809      ".foo { animation: \"unset\" 0s 3s infinite, none }",
13810      ".foo{animation:0s 3s infinite \"unset\",none}",
13811    );
13812
13813    minify_test(".foo { animation: \"infinite\" 2s 1 }", ".foo{animation:2s 1 infinite}");
13814    minify_test(".foo { animation: \"paused\" 2s }", ".foo{animation:2s running paused}");
13815    minify_test(
13816      ".foo { animation: \"forwards\" 2s }",
13817      ".foo{animation:2s none forwards}",
13818    );
13819    minify_test(
13820      ".foo { animation: \"reverse\" 2s }",
13821      ".foo{animation:2s normal reverse}",
13822    );
13823    minify_test(
13824      ".foo { animation: \"reverse\" 2s alternate }",
13825      ".foo{animation:2s alternate reverse}",
13826    );
13827
13828    minify_test(
13829      ".foo { animation: 3s ease-in 1s infinite reverse both running slidein }",
13830      ".foo{animation:3s ease-in 1s infinite reverse both slidein}",
13831    );
13832    minify_test(
13833      ".foo { animation: 3s slidein paused ease 1s 1 reverse both }",
13834      ".foo{animation:3s 1s reverse both paused slidein}",
13835    );
13836    minify_test(".foo { animation: 3s ease ease }", ".foo{animation:3s ease ease}");
13837    minify_test(
13838      ".foo { animation: 3s cubic-bezier(0.25, 0.1, 0.25, 1) foo }",
13839      ".foo{animation:3s foo}",
13840    );
13841    minify_test(
13842      ".foo { animation: foo 0s 3s infinite }",
13843      ".foo{animation:0s 3s infinite foo}",
13844    );
13845    minify_test(".foo { animation: foo 3s --test }", ".foo{animation:3s foo --test}");
13846    minify_test(".foo { animation: foo 3s scroll() }", ".foo{animation:3s foo scroll()}");
13847    minify_test(
13848      ".foo { animation: foo 3s scroll(block) }",
13849      ".foo{animation:3s foo scroll()}",
13850    );
13851    minify_test(
13852      ".foo { animation: foo 3s scroll(root inline) }",
13853      ".foo{animation:3s foo scroll(root inline)}",
13854    );
13855    minify_test(
13856      ".foo { animation: foo 3s scroll(inline root) }",
13857      ".foo{animation:3s foo scroll(root inline)}",
13858    );
13859    minify_test(
13860      ".foo { animation: foo 3s scroll(inline nearest) }",
13861      ".foo{animation:3s foo scroll(inline)}",
13862    );
13863    minify_test(
13864      ".foo { animation: foo 3s view(block) }",
13865      ".foo{animation:3s foo view()}",
13866    );
13867    minify_test(
13868      ".foo { animation: foo 3s view(inline) }",
13869      ".foo{animation:3s foo view(inline)}",
13870    );
13871    minify_test(
13872      ".foo { animation: foo 3s view(inline 10px 10px) }",
13873      ".foo{animation:3s foo view(inline 10px)}",
13874    );
13875    minify_test(
13876      ".foo { animation: foo 3s view(inline 10px 12px) }",
13877      ".foo{animation:3s foo view(inline 10px 12px)}",
13878    );
13879    minify_test(
13880      ".foo { animation: foo 3s view(inline auto auto) }",
13881      ".foo{animation:3s foo view(inline)}",
13882    );
13883    minify_test(".foo { animation: foo 3s auto }", ".foo{animation:3s foo}");
13884    minify_test(".foo { animation-composition: add }", ".foo{animation-composition:add}");
13885    test(
13886      r#"
13887      .foo {
13888        animation-name: foo;
13889        animation-duration: 0.09s;
13890        animation-timing-function: ease-in-out;
13891        animation-iteration-count: 2;
13892        animation-direction: alternate;
13893        animation-play-state: running;
13894        animation-delay: 100ms;
13895        animation-fill-mode: forwards;
13896        animation-timeline: auto;
13897      }
13898    "#,
13899      indoc! {r#"
13900      .foo {
13901        animation: 90ms ease-in-out .1s 2 alternate forwards foo;
13902      }
13903    "#},
13904    );
13905    test(
13906      r#"
13907      .foo {
13908        animation-name: foo, bar;
13909        animation-duration: 0.09s, 200ms;
13910        animation-timing-function: ease-in-out, ease;
13911        animation-iteration-count: 2, 1;
13912        animation-direction: alternate, normal;
13913        animation-play-state: running, paused;
13914        animation-delay: 100ms, 0s;
13915        animation-fill-mode: forwards, none;
13916        animation-timeline: auto, auto;
13917      }
13918    "#,
13919      indoc! {r#"
13920      .foo {
13921        animation: 90ms ease-in-out .1s 2 alternate forwards foo, .2s paused bar;
13922      }
13923    "#},
13924    );
13925    test(
13926      r#"
13927      .foo {
13928        animation: bar 200ms;
13929        animation-timing-function: ease-in-out;
13930      }
13931    "#,
13932      indoc! {r#"
13933      .foo {
13934        animation: .2s ease-in-out bar;
13935      }
13936    "#},
13937    );
13938    test(
13939      r#"
13940      .foo {
13941        animation: bar 200ms;
13942        animation-timing-function: var(--ease);
13943      }
13944    "#,
13945      indoc! {r#"
13946      .foo {
13947        animation: .2s bar;
13948        animation-timing-function: var(--ease);
13949      }
13950    "#},
13951    );
13952    test(
13953      r#"
13954      .foo {
13955        animation-name: foo, bar;
13956        animation-duration: 0.09s;
13957        animation-timing-function: ease-in-out;
13958        animation-iteration-count: 2;
13959        animation-direction: alternate;
13960        animation-play-state: running;
13961        animation-delay: 100ms;
13962        animation-fill-mode: forwards;
13963        animation-timeline: auto;
13964      }
13965    "#,
13966      indoc! {r#"
13967      .foo {
13968        animation-name: foo, bar;
13969        animation-duration: 90ms;
13970        animation-timing-function: ease-in-out;
13971        animation-iteration-count: 2;
13972        animation-direction: alternate;
13973        animation-play-state: running;
13974        animation-delay: .1s;
13975        animation-fill-mode: forwards;
13976        animation-timeline: auto;
13977      }
13978    "#},
13979    );
13980    test(
13981      r#"
13982      .foo {
13983        animation-name: foo;
13984        animation-duration: 0.09s;
13985        animation-timing-function: ease-in-out;
13986        animation-iteration-count: 2;
13987        animation-direction: alternate;
13988        animation-play-state: running;
13989        animation-delay: 100ms;
13990        animation-fill-mode: forwards;
13991        animation-timeline: scroll();
13992      }
13993    "#,
13994      indoc! {r#"
13995      .foo {
13996        animation: 90ms ease-in-out .1s 2 alternate forwards foo scroll();
13997      }
13998    "#},
13999    );
14000    test(
14001      r#"
14002      .foo {
14003        animation-name: foo;
14004        animation-duration: 0.09s;
14005        animation-timing-function: ease-in-out;
14006        animation-iteration-count: 2;
14007        animation-direction: alternate;
14008        animation-play-state: running;
14009        animation-delay: 100ms;
14010        animation-fill-mode: forwards;
14011        animation-timeline: scroll(), view();
14012      }
14013    "#,
14014      indoc! {r#"
14015      .foo {
14016        animation-name: foo;
14017        animation-duration: 90ms;
14018        animation-timing-function: ease-in-out;
14019        animation-iteration-count: 2;
14020        animation-direction: alternate;
14021        animation-play-state: running;
14022        animation-delay: .1s;
14023        animation-fill-mode: forwards;
14024        animation-timeline: scroll(), view();
14025      }
14026    "#},
14027    );
14028    test(
14029      r#"
14030      .foo {
14031        -webkit-animation-name: foo;
14032        -webkit-animation-duration: 0.09s;
14033        -webkit-animation-timing-function: ease-in-out;
14034        -webkit-animation-iteration-count: 2;
14035        -webkit-animation-direction: alternate;
14036        -webkit-animation-play-state: running;
14037        -webkit-animation-delay: 100ms;
14038        -webkit-animation-fill-mode: forwards;
14039      }
14040    "#,
14041      indoc! {r#"
14042      .foo {
14043        -webkit-animation: 90ms ease-in-out .1s 2 alternate forwards foo;
14044      }
14045    "#},
14046    );
14047    test(
14048      r#"
14049      .foo {
14050        -moz-animation: bar 200ms;
14051        -moz-animation-timing-function: ease-in-out;
14052      }
14053    "#,
14054      indoc! {r#"
14055      .foo {
14056        -moz-animation: .2s ease-in-out bar;
14057      }
14058    "#},
14059    );
14060    test(
14061      r#"
14062      .foo {
14063        -webkit-animation: bar 200ms;
14064        -webkit-animation-timing-function: ease-in-out;
14065        -moz-animation: bar 200ms;
14066        -moz-animation-timing-function: ease-in-out;
14067      }
14068    "#,
14069      indoc! {r#"
14070      .foo {
14071        -webkit-animation: .2s ease-in-out bar;
14072        -moz-animation: .2s ease-in-out bar;
14073      }
14074    "#},
14075    );
14076
14077    prefix_test(
14078      r#"
14079      .foo {
14080        animation: .2s ease-in-out bar;
14081      }
14082    "#,
14083      indoc! {r#"
14084      .foo {
14085        -webkit-animation: .2s ease-in-out bar;
14086        -moz-animation: .2s ease-in-out bar;
14087        animation: .2s ease-in-out bar;
14088      }
14089    "#},
14090      Browsers {
14091        firefox: Some(6 << 16),
14092        safari: Some(6 << 16),
14093        ..Browsers::default()
14094      },
14095    );
14096
14097    prefix_test(
14098      r#"
14099      .foo {
14100        -webkit-animation: .2s ease-in-out bar;
14101        -moz-animation: .2s ease-in-out bar;
14102        animation: .2s ease-in-out bar;
14103      }
14104    "#,
14105      indoc! {r#"
14106      .foo {
14107        animation: .2s ease-in-out bar;
14108      }
14109    "#},
14110      Browsers {
14111        firefox: Some(20 << 16),
14112        safari: Some(14 << 16),
14113        ..Browsers::default()
14114      },
14115    );
14116    prefix_test(
14117      r#"
14118      .foo {
14119        animation: 200ms var(--ease) bar;
14120      }
14121    "#,
14122      indoc! {r#"
14123      .foo {
14124        -webkit-animation: .2s var(--ease) bar;
14125        -moz-animation: .2s var(--ease) bar;
14126        animation: .2s var(--ease) bar;
14127      }
14128    "#},
14129      Browsers {
14130        firefox: Some(6 << 16),
14131        safari: Some(6 << 16),
14132        ..Browsers::default()
14133      },
14134    );
14135
14136    prefix_test(
14137      r#"
14138      .foo {
14139        animation: .2s ease-in-out bar scroll();
14140      }
14141    "#,
14142      indoc! {r#"
14143      .foo {
14144        animation: .2s ease-in-out bar;
14145        animation-timeline: scroll();
14146      }
14147    "#},
14148      Browsers {
14149        safari: Some(16 << 16),
14150        ..Browsers::default()
14151      },
14152    );
14153    prefix_test(
14154      r#"
14155      .foo {
14156        animation: .2s ease-in-out bar scroll();
14157      }
14158    "#,
14159      indoc! {r#"
14160      .foo {
14161        animation: .2s ease-in-out bar scroll();
14162      }
14163    "#},
14164      Browsers {
14165        chrome: Some(120 << 16),
14166        ..Browsers::default()
14167      },
14168    );
14169    prefix_test(
14170      r#"
14171      .foo {
14172        animation: .2s ease-in-out bar scroll();
14173      }
14174    "#,
14175      indoc! {r#"
14176      .foo {
14177        -webkit-animation: .2s ease-in-out bar;
14178        animation: .2s ease-in-out bar;
14179        animation-timeline: scroll();
14180      }
14181    "#},
14182      Browsers {
14183        safari: Some(6 << 16),
14184        ..Browsers::default()
14185      },
14186    );
14187
14188    minify_test(
14189      ".foo { animation-range-start: entry 10% }",
14190      ".foo{animation-range-start:entry 10%}",
14191    );
14192    minify_test(
14193      ".foo { animation-range-start: entry 0% }",
14194      ".foo{animation-range-start:entry}",
14195    );
14196    minify_test(
14197      ".foo { animation-range-start: entry }",
14198      ".foo{animation-range-start:entry}",
14199    );
14200    minify_test(".foo { animation-range-start: 50% }", ".foo{animation-range-start:50%}");
14201    minify_test(
14202      ".foo { animation-range-end: exit 10% }",
14203      ".foo{animation-range-end:exit 10%}",
14204    );
14205    minify_test(
14206      ".foo { animation-range-end: exit 100% }",
14207      ".foo{animation-range-end:exit}",
14208    );
14209    minify_test(".foo { animation-range-end: exit }", ".foo{animation-range-end:exit}");
14210    minify_test(".foo { animation-range-end: 50% }", ".foo{animation-range-end:50%}");
14211    minify_test(
14212      ".foo { animation-range: entry 10% exit 90% }",
14213      ".foo{animation-range:entry 10% exit 90%}",
14214    );
14215    minify_test(
14216      ".foo { animation-range: entry 0% exit 100% }",
14217      ".foo{animation-range:entry exit}",
14218    );
14219    minify_test(".foo { animation-range: entry }", ".foo{animation-range:entry}");
14220    minify_test(
14221      ".foo { animation-range: entry 0% entry 100% }",
14222      ".foo{animation-range:entry}",
14223    );
14224    minify_test(".foo { animation-range: 50% normal }", ".foo{animation-range:50%}");
14225    minify_test(
14226      ".foo { animation-range: normal normal }",
14227      ".foo{animation-range:normal}",
14228    );
14229    test(
14230      r#"
14231      .foo {
14232        animation-range-start: entry 10%;
14233        animation-range-end: exit 90%;
14234      }
14235      "#,
14236      indoc! {r#"
14237      .foo {
14238        animation-range: entry 10% exit 90%;
14239      }
14240      "#},
14241    );
14242    test(
14243      r#"
14244      .foo {
14245        animation-range-start: entry 0%;
14246        animation-range-end: entry 100%;
14247      }
14248      "#,
14249      indoc! {r#"
14250      .foo {
14251        animation-range: entry;
14252      }
14253      "#},
14254    );
14255    test(
14256      r#"
14257      .foo {
14258        animation-range-start: entry 0%;
14259        animation-range-end: exit 100%;
14260      }
14261      "#,
14262      indoc! {r#"
14263      .foo {
14264        animation-range: entry exit;
14265      }
14266      "#},
14267    );
14268    test(
14269      r#"
14270      .foo {
14271        animation-range-start: 10%;
14272        animation-range-end: normal;
14273      }
14274      "#,
14275      indoc! {r#"
14276      .foo {
14277        animation-range: 10%;
14278      }
14279      "#},
14280    );
14281    test(
14282      r#"
14283      .foo {
14284        animation-range-start: 10%;
14285        animation-range-end: 90%;
14286      }
14287      "#,
14288      indoc! {r#"
14289      .foo {
14290        animation-range: 10% 90%;
14291      }
14292      "#},
14293    );
14294    test(
14295      r#"
14296      .foo {
14297        animation-range-start: entry 10%;
14298        animation-range-end: exit 100%;
14299      }
14300      "#,
14301      indoc! {r#"
14302      .foo {
14303        animation-range: entry 10% exit;
14304      }
14305      "#},
14306    );
14307    test(
14308      r#"
14309      .foo {
14310        animation-range-start: 10%;
14311        animation-range-end: exit 90%;
14312      }
14313      "#,
14314      indoc! {r#"
14315      .foo {
14316        animation-range: 10% exit 90%;
14317      }
14318      "#},
14319    );
14320    test(
14321      r#"
14322      .foo {
14323        animation-range-start: entry 10%;
14324        animation-range-end: 90%;
14325      }
14326      "#,
14327      indoc! {r#"
14328      .foo {
14329        animation-range: entry 10% 90%;
14330      }
14331      "#},
14332    );
14333    test(
14334      r#"
14335      .foo {
14336        animation-range: entry;
14337        animation-range-end: 90%;
14338      }
14339      "#,
14340      indoc! {r#"
14341      .foo {
14342        animation-range: entry 90%;
14343      }
14344      "#},
14345    );
14346    test(
14347      r#"
14348      .foo {
14349        animation-range: entry;
14350        animation-range-end: var(--end);
14351      }
14352      "#,
14353      indoc! {r#"
14354      .foo {
14355        animation-range: entry;
14356        animation-range-end: var(--end);
14357      }
14358      "#},
14359    );
14360    test(
14361      r#"
14362      .foo {
14363        animation-range-start: entry 10%, entry 50%;
14364        animation-range-end: exit 90%;
14365      }
14366      "#,
14367      indoc! {r#"
14368      .foo {
14369        animation-range-start: entry 10%, entry 50%;
14370        animation-range-end: exit 90%;
14371      }
14372      "#},
14373    );
14374    test(
14375      r#"
14376      .foo {
14377        animation-range-start: entry 10%, entry 50%;
14378        animation-range-end: exit 90%, exit 100%;
14379      }
14380      "#,
14381      indoc! {r#"
14382      .foo {
14383        animation-range: entry 10% exit 90%, entry 50% exit;
14384      }
14385      "#},
14386    );
14387    test(
14388      r#"
14389      .foo {
14390        animation-range: entry;
14391        animation-range-end: 90%;
14392        animation: spin 100ms;
14393      }
14394      "#,
14395      indoc! {r#"
14396      .foo {
14397        animation: .1s spin;
14398      }
14399      "#},
14400    );
14401    test(
14402      r#"
14403      .foo {
14404        animation: spin 100ms;
14405        animation-range: entry;
14406        animation-range-end: 90%;
14407      }
14408      "#,
14409      indoc! {r#"
14410      .foo {
14411        animation: .1s spin;
14412        animation-range: entry 90%;
14413      }
14414      "#},
14415    );
14416    test(
14417      r#"
14418      .foo {
14419        animation-range: entry;
14420        animation-range-end: 90%;
14421        animation: var(--animation) 100ms;
14422      }
14423      "#,
14424      indoc! {r#"
14425      .foo {
14426        animation: var(--animation) .1s;
14427      }
14428      "#},
14429    );
14430  }
14431
14432  #[test]
14433  fn test_transform() {
14434    property_range_test(
14435      &["transform"],
14436      &[
14437        ("perspective(-1px)", None),
14438        ("perspective(calc(-1px))", Some("perspective(0)")),
14439        ("translateX(-1px)", Some("translate(-1px)")),
14440      ],
14441    );
14442    property_range_test(
14443      &["perspective"],
14444      &[
14445        ("-1px", None),
14446        ("calc(1px - 2px)", Some("0")),
14447        ("calc(-1px + 2px)", Some("1px")),
14448      ],
14449    );
14450    test(
14451      ".foo { transform: perspective(500px)translate3d(10px, 0, 20px)rotateY(30deg) }",
14452      indoc! {r#"
14453      .foo {
14454        transform: perspective(500px) translate3d(10px, 0, 20px) rotateY(30deg);
14455      }
14456      "#},
14457    );
14458    test(
14459      ".foo { transform: translate3d(12px,50%,3em)scale(2,.5) }",
14460      indoc! {r#"
14461      .foo {
14462        transform: translate3d(12px, 50%, 3em) scale(2, .5);
14463      }
14464      "#},
14465    );
14466    test(
14467      ".foo { transform:matrix(1,2,-1,1,80,80) }",
14468      indoc! {r#"
14469      .foo {
14470        transform: matrix(1, 2, -1, 1, 80, 80);
14471      }
14472      "#},
14473    );
14474
14475    minify_test(
14476      ".foo { transform: scale(  0.5 )translateX(10px ) }",
14477      ".foo{transform:scale(.5)translate(10px)}",
14478    );
14479    minify_test(
14480      ".foo { transform: translate(2px, 3px)",
14481      ".foo{transform:translate(2px,3px)}",
14482    );
14483    minify_test(
14484      ".foo { transform: translate(2px, 0px)",
14485      ".foo{transform:translate(2px)}",
14486    );
14487    minify_test(
14488      ".foo { transform: translate(0px, 2px)",
14489      ".foo{transform:translateY(2px)}",
14490    );
14491    minify_test(".foo { transform: translateX(2px)", ".foo{transform:translate(2px)}");
14492    minify_test(".foo { transform: translateY(2px)", ".foo{transform:translateY(2px)}");
14493    minify_test(".foo { transform: translateZ(2px)", ".foo{transform:translateZ(2px)}");
14494    minify_test(
14495      ".foo { transform: translate3d(2px, 3px, 4px)",
14496      ".foo{transform:translate3d(2px,3px,4px)}",
14497    );
14498    minify_test(
14499      ".foo { transform: translate3d(10%, 20%, 4px)",
14500      ".foo{transform:translate3d(10%,20%,4px)}",
14501    );
14502    minify_test(
14503      ".foo { transform: translate3d(2px, 0px, 0px)",
14504      ".foo{transform:translate(2px)}",
14505    );
14506    minify_test(
14507      ".foo { transform: translate3d(0px, 2px, 0px)",
14508      ".foo{transform:translateY(2px)}",
14509    );
14510    minify_test(
14511      ".foo { transform: translate3d(0px, 0px, 2px)",
14512      ".foo{transform:translateZ(2px)}",
14513    );
14514    minify_test(
14515      ".foo { transform: translate3d(2px, 3px, 0px)",
14516      ".foo{transform:translate(2px,3px)}",
14517    );
14518    minify_test(".foo { transform: scale(2, 3)", ".foo{transform:scale(2,3)}");
14519    minify_test(".foo { transform: scale(10%, 20%)", ".foo{transform:scale(.1,.2)}");
14520    minify_test(".foo { transform: scale(2, 2)", ".foo{transform:scale(2)}");
14521    minify_test(".foo { transform: scale(2, 1)", ".foo{transform:scaleX(2)}");
14522    minify_test(".foo { transform: scale(1, 2)", ".foo{transform:scaleY(2)}");
14523    minify_test(".foo { transform: scaleX(2)", ".foo{transform:scaleX(2)}");
14524    minify_test(".foo { transform: scaleY(2)", ".foo{transform:scaleY(2)}");
14525    minify_test(".foo { transform: scaleZ(2)", ".foo{transform:scaleZ(2)}");
14526    minify_test(".foo { transform: scale3d(2, 3, 4)", ".foo{transform:scale3d(2,3,4)}");
14527    minify_test(".foo { transform: scale3d(2, 1, 1)", ".foo{transform:scaleX(2)}");
14528    minify_test(".foo { transform: scale3d(1, 2, 1)", ".foo{transform:scaleY(2)}");
14529    minify_test(".foo { transform: scale3d(1, 1, 2)", ".foo{transform:scaleZ(2)}");
14530    minify_test(".foo { transform: scale3d(2, 2, 1)", ".foo{transform:scale(2)}");
14531
14532    // transform: scale(), Convert <percentage> to <number>
14533    test(
14534      ".foo { transform: scale3d(50%, 1, 200%) }",
14535      indoc! {r#"
14536      .foo {
14537        transform: scale3d(.5, 1, 2);
14538      }
14539      "#},
14540    );
14541    minify_test(".foo { transform: scale(1%) }", ".foo{transform:scale(.01)}");
14542    minify_test(".foo { transform: scale(0%) }", ".foo{transform:scale(0)}");
14543    minify_test(".foo { transform: scale(0.0%) }", ".foo{transform:scale(0)}");
14544    minify_test(".foo { transform: scale(-0%) }", ".foo{transform:scale(0)}");
14545    minify_test(".foo { transform: scale(-0) }", ".foo{transform:scale(0)}");
14546    minify_test(".foo { transform: scale(-0.0) }", ".foo{transform:scale(0)}");
14547    minify_test(".foo { transform: scale(100%) }", ".foo{transform:scale(1)}");
14548    minify_test(".foo { transform: scale(-100%) }", ".foo{transform:scale(-1)}");
14549    minify_test(".foo { transform: scale(68%) }", ".foo{transform:scale(.68)}");
14550    minify_test(".foo { transform: scale(5.96%) }", ".foo{transform:scale(.0596)}");
14551    // Match WPT coverage for repeated and multi-value percentages.
14552    minify_test(".foo { transform: scale(100%, 100%) }", ".foo{transform:scale(1)}");
14553    minify_test(".foo { transform: scale3d(100%, 100%, 1) }", ".foo{transform:scale(1)}");
14554    minify_test(".foo { transform: scale(-100%, -100%) }", ".foo{transform:scale(-1)}");
14555    minify_test(
14556      ".foo { transform: scale3d(-100%, -100%, 1) }",
14557      ".foo{transform:scale(-1)}",
14558    );
14559    minify_test(".foo { transform: scale(100%, 200%) }", ".foo{transform:scaleY(2)}");
14560    minify_test(
14561      ".foo { transform: scale3d(100%, 200%, 1) }",
14562      ".foo{transform:scaleY(2)}",
14563    );
14564    minify_test(
14565      ".foo { transform: scale3d(100%, 100%, 0%) }",
14566      ".foo{transform:scaleZ(0)}",
14567    );
14568    minify_test(
14569      ".foo { transform: scale3d(100%, 100%, 100%) }",
14570      ".foo{transform:scale(1)}",
14571    );
14572    minify_test(
14573      ".foo { transform: scale3d(-0%, -0%, -0%) }",
14574      ".foo{transform:scale3d(0,0,0)}",
14575    );
14576    // Additional edge cases: mixed inputs and computed percentages.
14577    minify_test(".foo { transform: scale(2, 100%) }", ".foo{transform:scaleX(2)}");
14578    minify_test(".foo { transform: scale(2, -50%) }", ".foo{transform:scale(2,-.5)}");
14579    minify_test(".foo { transform: scale(-90%, -1) }", ".foo{transform:scale(-.9,-1)}");
14580    minify_test(
14581      ".foo { transform: scale(calc(10% + 20%)) }",
14582      ".foo{transform:scale(.3)}",
14583    );
14584    minify_test(
14585      ".foo { transform: scale(calc(150% - 50%), 200%) }",
14586      ".foo{transform:scaleY(2)}",
14587    );
14588    minify_test(
14589      ".foo { transform: scale(200%, calc(50% - 80%)) }",
14590      ".foo{transform:scale(2,-.3)}",
14591    );
14592    // TODO: For infinite decimals, please do not attempt to resolve calc
14593    // Expected: calc(1 / 3)
14594    // https://github.com/parcel-bundler/lightningcss/issues/12
14595    minify_test(
14596      ".foo { transform: scale(calc(100% / 3)) }",
14597      ".foo{transform:scale(.333333)}",
14598    );
14599    // Transform::ScaleX/Y/Z
14600    minify_test(".foo { transform: scaleX(10%) }", ".foo{transform:scaleX(.1)}");
14601    minify_test(".foo { transform: scaleY(20%) }", ".foo{transform:scaleY(.2)}");
14602    minify_test(".foo { transform: scaleZ(30%) }", ".foo{transform:scaleZ(.3)}");
14603    minify_test(".foo { transform: scaleX(0%) }", ".foo{transform:scaleX(0)}");
14604    minify_test(".foo { transform: scaleX(-0%) }", ".foo{transform:scaleX(0)}");
14605    minify_test(
14606      ".foo { transform: scaleX(calc(10% + 20%)) }",
14607      ".foo{transform:scaleX(.3)}",
14608    );
14609    minify_test(
14610      ".foo { transform: scaleX(calc(180% - 20%)) }",
14611      ".foo{transform:scaleX(1.6)}",
14612    );
14613    minify_test(
14614      ".foo { transform: scaleX(calc(50% - 80%)) }",
14615      ".foo{transform:scaleX(-.3)}",
14616    );
14617
14618    minify_test(".foo { transform: rotate(20deg)", ".foo{transform:rotate(20deg)}");
14619    minify_test(".foo { transform: rotateX(20deg)", ".foo{transform:rotateX(20deg)}");
14620    minify_test(".foo { transform: rotateY(20deg)", ".foo{transform:rotateY(20deg)}");
14621    minify_test(".foo { transform: rotateZ(20deg)", ".foo{transform:rotate(20deg)}");
14622    minify_test(".foo { transform: rotate(360deg)", ".foo{transform:rotate(360deg)}");
14623    minify_test(
14624      ".foo { transform: rotate3d(2, 3, 4, 20deg)",
14625      ".foo{transform:rotate3d(2,3,4,20deg)}",
14626    );
14627    minify_test(
14628      ".foo { transform: rotate3d(1, 0, 0, 20deg)",
14629      ".foo{transform:rotateX(20deg)}",
14630    );
14631    minify_test(
14632      ".foo { transform: rotate3d(0, 1, 0, 20deg)",
14633      ".foo{transform:rotateY(20deg)}",
14634    );
14635    minify_test(
14636      ".foo { transform: rotate3d(0, 0, 1, 20deg)",
14637      ".foo{transform:rotate(20deg)}",
14638    );
14639    minify_test(".foo { transform: rotate(405deg)}", ".foo{transform:rotate(405deg)}");
14640    minify_test(".foo { transform: rotateX(405deg)}", ".foo{transform:rotateX(405deg)}");
14641    minify_test(".foo { transform: rotateY(405deg)}", ".foo{transform:rotateY(405deg)}");
14642    minify_test(".foo { transform: rotate(-200deg)}", ".foo{transform:rotate(-200deg)}");
14643    minify_test(".foo { transform: rotate(0)", ".foo{transform:rotate(0)}");
14644    minify_test(".foo { transform: rotate(0deg)", ".foo{transform:rotate(0)}");
14645    minify_test(
14646      ".foo { transform: rotateX(-200deg)}",
14647      ".foo{transform:rotateX(-200deg)}",
14648    );
14649    minify_test(
14650      ".foo { transform: rotateY(-200deg)}",
14651      ".foo{transform:rotateY(-200deg)}",
14652    );
14653    minify_test(
14654      ".foo { transform: rotate3d(1, 1, 0, -200deg)",
14655      ".foo{transform:rotate3d(1,1,0,-200deg)}",
14656    );
14657    minify_test(".foo { transform: skew(20deg)", ".foo{transform:skew(20deg)}");
14658    minify_test(".foo { transform: skew(20deg, 0deg)", ".foo{transform:skew(20deg)}");
14659    minify_test(".foo { transform: skew(0deg, 20deg)", ".foo{transform:skewY(20deg)}");
14660    minify_test(".foo { transform: skewX(20deg)", ".foo{transform:skew(20deg)}");
14661    minify_test(".foo { transform: skewY(20deg)", ".foo{transform:skewY(20deg)}");
14662    minify_test(
14663      ".foo { transform: perspective(10px)",
14664      ".foo{transform:perspective(10px)}",
14665    );
14666    minify_test(
14667      ".foo { transform: matrix(1, 2, -1, 1, 80, 80)",
14668      ".foo{transform:matrix(1,2,-1,1,80,80)}",
14669    );
14670    minify_test(
14671      ".foo { transform: matrix3d(1, 0, 0, 0, 0, 1, 6, 0, 0, 0, 1, 0, 50, 100, 0, 1.1)",
14672      ".foo{transform:matrix3d(1,0,0,0,0,1,6,0,0,0,1,0,50,100,0,1.1)}",
14673    );
14674    // TODO: Re-enable with a better solution
14675    //       See: https://github.com/parcel-bundler/lightningcss/issues/288
14676    // minify_test(
14677    //   ".foo{transform:translate(100px,200px) rotate(45deg) skew(10deg) scale(2)}",
14678    //   ".foo{transform:matrix(1.41421,1.41421,-1.16485,1.66358,100,200)}",
14679    // );
14680    // minify_test(
14681    //   ".foo{transform:translate(200px,300px) translate(100px,200px) scale(2)}",
14682    //   ".foo{transform:matrix(2,0,0,2,300,500)}",
14683    // );
14684    minify_test(
14685      ".foo{transform:translate(100px,200px) rotate(45deg)}",
14686      ".foo{transform:translate(100px,200px)rotate(45deg)}",
14687    );
14688    minify_test(
14689      ".foo{transform:rotate3d(1, 1, 1, 45deg) translate3d(100px, 100px, 10px)}",
14690      ".foo{transform:rotate3d(1,1,1,45deg)translate3d(100px,100px,10px)}",
14691    );
14692    // TODO: Re-enable with a better solution
14693    //       See: https://github.com/parcel-bundler/lightningcss/issues/288
14694    // minify_test(
14695    //   ".foo{transform:translate3d(100px, 100px, 10px) skew(10deg) scale3d(2, 3, 4)}",
14696    //   ".foo{transform:matrix3d(2,0,0,0,.528981,3,0,0,0,0,4,0,100,100,10,1)}",
14697    // );
14698    // minify_test(
14699    //   ".foo{transform:matrix3d(0.804737854124365, 0.5058793634016805, -0.31061721752604554, 0, -0.31061721752604554, 0.804737854124365, 0.5058793634016805, 0, 0.5058793634016805, -0.31061721752604554, 0.804737854124365, 0, 100, 100, 10, 1)}",
14700    //   ".foo{transform:translate3d(100px,100px,10px)rotate3d(1,1,1,45deg)}"
14701    // );
14702    // minify_test(
14703    //   ".foo{transform:matrix3d(1, 0, 0, 0, 0, 0.7071067811865476, 0.7071067811865475, 0, 0, -0.7071067811865475, 0.7071067811865476, 0, 100, 100, 10, 1)}",
14704    //   ".foo{transform:translate3d(100px,100px,10px)rotateX(45deg)}"
14705    // );
14706    // minify_test(
14707    //   ".foo{transform:translate3d(100px, 200px, 10px) translate(100px, 100px)}",
14708    //   ".foo{transform:translate3d(200px,300px,10px)}",
14709    // );
14710    // minify_test(
14711    //   ".foo{transform:rotate(45deg) rotate(45deg)}",
14712    //   ".foo{transform:rotate(90deg)}",
14713    // );
14714    // minify_test(
14715    //   ".foo{transform:matrix(0.7071067811865476, 0.7071067811865475, -0.7071067811865475, 0.7071067811865476, 100, 100)}",
14716    //   ".foo{transform:translate(100px,100px)rotate(45deg)}"
14717    // );
14718    // minify_test(
14719    //   ".foo{transform:translateX(2in) translateX(50px)}",
14720    //   ".foo{transform:translate(242px)}",
14721    // );
14722    minify_test(
14723      ".foo{transform:translateX(calc(2in + 50px))}",
14724      ".foo{transform:translate(242px)}",
14725    );
14726    minify_test(".foo{transform:translateX(50%)}", ".foo{transform:translate(50%)}");
14727    minify_test(
14728      ".foo{transform:translateX(calc(50% - 100px + 20px))}",
14729      ".foo{transform:translate(calc(50% - 80px))}",
14730    );
14731    minify_test(
14732      ".foo{transform:rotate(calc(10deg + 20deg))}",
14733      ".foo{transform:rotate(30deg)}",
14734    );
14735    minify_test(
14736      ".foo{transform:rotate(calc(10deg + 0.349066rad))}",
14737      ".foo{transform:rotate(30deg)}",
14738    );
14739    minify_test(
14740      ".foo{transform:rotate(calc(10deg + 1.5turn))}",
14741      ".foo{transform:rotate(550deg)}",
14742    );
14743    minify_test(
14744      ".foo{transform:rotate(calc(10deg * 2))}",
14745      ".foo{transform:rotate(20deg)}",
14746    );
14747    minify_test(
14748      ".foo{transform:rotate(calc(-10deg * 2))}",
14749      ".foo{transform:rotate(-20deg)}",
14750    );
14751    minify_test(
14752      ".foo{transform:rotate(calc(10deg + var(--test)))}",
14753      ".foo{transform:rotate(calc(10deg + var(--test)))}",
14754    );
14755    minify_test(".foo { transform: scale(calc(.1 + .2))", ".foo{transform:scale(.3)}");
14756
14757    minify_test(
14758      ".foo { -webkit-transform: scale(calc(10% + 20%))",
14759      ".foo{-webkit-transform:scale(.3)}",
14760    );
14761
14762    minify_test(".foo { translate: 1px 2px 3px }", ".foo{translate:1px 2px 3px}");
14763    minify_test(".foo { translate: 1px 0px 0px }", ".foo{translate:1px}");
14764    minify_test(".foo { translate: 1px 2px 0px }", ".foo{translate:1px 2px}");
14765    minify_test(".foo { translate: 1px 0px 2px }", ".foo{translate:1px 0 2px}");
14766    minify_test(".foo { translate: none }", ".foo{translate:none}");
14767    minify_test(".foo { rotate: none }", ".foo{rotate:none}");
14768    minify_test(".foo { rotate: 0deg }", ".foo{rotate:0deg}");
14769    minify_test(".foo { rotate: -0deg }", ".foo{rotate:0deg}");
14770    minify_test(".foo { rotate: 10deg }", ".foo{rotate:10deg}");
14771    minify_test(".foo { rotate: z 10deg }", ".foo{rotate:10deg}");
14772    minify_test(".foo { rotate: 0 0 1 10deg }", ".foo{rotate:10deg}");
14773    minify_test(".foo { rotate: x 10deg }", ".foo{rotate:x 10deg}");
14774    minify_test(".foo { rotate: 1 0 0 10deg }", ".foo{rotate:x 10deg}");
14775    minify_test(".foo { rotate: 2 0 0 10deg }", ".foo{rotate:x 10deg}");
14776    minify_test(".foo { rotate: 0 2 0 10deg }", ".foo{rotate:y 10deg}");
14777    minify_test(".foo { rotate: 0 0 2 10deg }", ".foo{rotate:10deg}");
14778    minify_test(".foo { rotate: 0 0 5.3 10deg }", ".foo{rotate:10deg}");
14779    minify_test(".foo { rotate: 0 0 1 0deg }", ".foo{rotate:0deg}");
14780    minify_test(".foo { rotate: 10deg 0 0 -1 }", ".foo{rotate:-10deg}");
14781    minify_test(".foo { rotate: 10deg 0 0 -233 }", ".foo{rotate:-10deg}");
14782    minify_test(".foo { rotate: -1 0 0 0deg }", ".foo{rotate:x 0deg}");
14783    minify_test(".foo { rotate: 0deg 0 0 1 }", ".foo{rotate:0deg}");
14784    minify_test(".foo { rotate: 0deg 0 0 -1 }", ".foo{rotate:0deg}");
14785    minify_test(".foo { rotate: 0 1 0 10deg }", ".foo{rotate:y 10deg}");
14786    minify_test(".foo { rotate: x 0rad }", ".foo{rotate:x 0deg}");
14787    // TODO: In minify mode, convert units to the shortest form.
14788    // minify_test(".foo { rotate: y 0turn }", ".foo{rotate:y 0deg}");
14789    minify_test(".foo { rotate: z 0deg }", ".foo{rotate:0deg}");
14790    minify_test(".foo { rotate: 10deg y }", ".foo{rotate:y 10deg}");
14791    minify_test(".foo { rotate: 1 1 1 10deg }", ".foo{rotate:1 1 1 10deg}");
14792    minify_test(".foo { scale: 1 }", ".foo{scale:1}");
14793    minify_test(".foo { scale: 1 1 }", ".foo{scale:1}");
14794    minify_test(".foo { scale: 1 1 1 }", ".foo{scale:1}");
14795    minify_test(".foo { scale: none }", ".foo{scale:none}");
14796    minify_test(".foo { scale: 1 0 }", ".foo{scale:1 0}");
14797    minify_test(".foo { scale: 1 0 1 }", ".foo{scale:1 0}");
14798    minify_test(".foo { scale: 1 0 0 }", ".foo{scale:1 0 0}");
14799
14800    // scale, Convert <percentage> to <number>
14801    test(
14802      ".foo { scale: 50% 1 200% }",
14803      indoc! {r#"
14804      .foo {
14805        scale: .5 1 2;
14806      }
14807      "#},
14808    );
14809    minify_test(".foo { scale: 1% }", ".foo{scale:.01}");
14810    minify_test(".foo { scale: 0% }", ".foo{scale:0}");
14811    minify_test(".foo { scale: 0.0% }", ".foo{scale:0}");
14812    minify_test(".foo { scale: -0% }", ".foo{scale:0}");
14813    minify_test(".foo { scale: -0 }", ".foo{scale:0}");
14814    minify_test(".foo { scale: -0.0 }", ".foo{scale:0}");
14815    minify_test(".foo { scale: 100% }", ".foo{scale:1}");
14816    minify_test(".foo { scale: -100% }", ".foo{scale:-1}");
14817    minify_test(".foo { scale: 68% }", ".foo{scale:.68}");
14818    minify_test(".foo { scale: 5.96% }", ".foo{scale:.0596}");
14819    // Match WPT coverage for repeated and multi-value percentages.
14820    minify_test(".foo { scale: 100% 100% }", ".foo{scale:1}");
14821    minify_test(".foo { scale: 100% 100% 1 }", ".foo{scale:1}");
14822    minify_test(".foo { scale: -100% -100% }", ".foo{scale:-1}");
14823    minify_test(".foo { scale: -100% -100% 1 }", ".foo{scale:-1}");
14824    minify_test(".foo { scale: 100% 200% }", ".foo{scale:1 2}");
14825    minify_test(".foo { scale: 100% 200% 1 }", ".foo{scale:1 2}");
14826    minify_test(".foo { scale: 100% 100% 0% }", ".foo{scale:1 1 0}");
14827    minify_test(".foo { scale: 100% 100% 100% }", ".foo{scale:1}");
14828    minify_test(".foo { scale: -0% -0% -0% }", ".foo{scale:0 0 0}");
14829    // Additional edge cases: mixed inputs and computed percentages.
14830    minify_test(".foo { scale: 2 100% }", ".foo{scale:2 1}");
14831    minify_test(".foo { scale: 2 -50% }", ".foo{scale:2 -.5}");
14832    minify_test(".foo { scale: -90% -1 }", ".foo{scale:-.9 -1}");
14833    minify_test(".foo { scale: calc(10% + 20%) }", ".foo{scale:.3}");
14834    minify_test(".foo { scale: calc(150% - 50%) 200% }", ".foo{scale:1 2}");
14835    minify_test(".foo { scale: 200% calc(50% - 80%) }", ".foo{scale:2 -.3}");
14836    // TODO: For infinite decimals, please do not attempt to resolve calc
14837    // Expected: calc(1 / 3)
14838    // https://github.com/parcel-bundler/lightningcss/issues/12
14839    minify_test(".foo { scale: calc(100% / 3) }", ".foo{scale:.333333}");
14840
14841    assert_eq!(
14842      Property::Scale(crate::properties::transform::Scale::XYZ {
14843        x: crate::values::percentage::NumberOrPercentage::Percentage(crate::values::percentage::Percentage(0.5)),
14844        y: crate::values::percentage::NumberOrPercentage::Percentage(crate::values::percentage::Percentage(2.0)),
14845        z: crate::values::percentage::NumberOrPercentage::Percentage(crate::values::percentage::Percentage(1.0)),
14846      })
14847      .to_css_string(
14848        false,
14849        PrinterOptions {
14850          minify: true,
14851          ..PrinterOptions::default()
14852        },
14853      )
14854      .unwrap(),
14855      "scale:.5 2"
14856    );
14857    assert_eq!(
14858      Property::Transform(
14859        crate::properties::transform::TransformList(vec![crate::properties::transform::Transform::ScaleX(
14860          crate::values::percentage::NumberOrPercentage::Percentage(crate::values::percentage::Percentage(0.1)),
14861        )]),
14862        VendorPrefix::None,
14863      )
14864      .to_css_string(
14865        false,
14866        PrinterOptions {
14867          minify: true,
14868          ..PrinterOptions::default()
14869        },
14870      )
14871      .unwrap(),
14872      "transform:scaleX(.1)"
14873    );
14874
14875    minify_test(
14876      r#"
14877      .foo {
14878        transform: scale(3);
14879        scale: 0.5;
14880      }
14881      "#,
14882      ".foo{transform:scale(3);scale:.5}",
14883    );
14884    minify_test(
14885      r#"
14886      .foo {
14887        scale: 0.5;
14888        transform: scale(3);
14889      }
14890      "#,
14891      ".foo{transform:scale(3);scale:.5}",
14892    );
14893
14894    prefix_test(
14895      r#"
14896      .foo {
14897        transform: scale(0.5);
14898      }
14899    "#,
14900      indoc! {r#"
14901      .foo {
14902        -webkit-transform: scale(.5);
14903        -moz-transform: scale(.5);
14904        transform: scale(.5);
14905      }
14906    "#},
14907      Browsers {
14908        firefox: Some(6 << 16),
14909        safari: Some(6 << 16),
14910        ..Browsers::default()
14911      },
14912    );
14913
14914    prefix_test(
14915      r#"
14916      .foo {
14917        transform: var(--transform);
14918      }
14919    "#,
14920      indoc! {r#"
14921      .foo {
14922        -webkit-transform: var(--transform);
14923        -moz-transform: var(--transform);
14924        transform: var(--transform);
14925      }
14926    "#},
14927      Browsers {
14928        firefox: Some(6 << 16),
14929        safari: Some(6 << 16),
14930        ..Browsers::default()
14931      },
14932    );
14933
14934    test(
14935      r#"
14936      .foo {
14937        transform: translateX(-50%);
14938        transform: translateX(20px);
14939      }
14940      "#,
14941      indoc! {r#"
14942      .foo {
14943        transform: translateX(20px);
14944      }
14945      "#},
14946    );
14947  }
14948
14949  #[test]
14950  fn test_individual_transforms() {
14951    for (property, value, identity) in [
14952      ("translate", "10px", "0"),
14953      ("rotate", "30deg", "0deg"),
14954      ("scale", "2", "1"),
14955    ] {
14956      // `transform` is not a shorthand that resets the individual properties.
14957      for (transform, individual) in [("scale(3)", value), ("none", "none"), ("none", identity)] {
14958        let expected = format!(
14959          indoc! {r#"
14960          .box {{
14961            transform: {transform};
14962            {property}: {individual};
14963          }}
14964          "#},
14965          transform = transform,
14966          property = property,
14967          individual = individual,
14968        );
14969        test(
14970          &format!(
14971            r#"
14972            .box {{
14973              transform: {transform};
14974              {property}: {individual};
14975            }}
14976            "#,
14977          ),
14978          &expected,
14979        );
14980        test(
14981          &format!(
14982            r#"
14983            .box {{
14984              {property}: {individual};
14985              transform: {transform};
14986            }}
14987            "#,
14988          ),
14989          &expected,
14990        );
14991      }
14992    }
14993
14994    test(
14995      r#"
14996      .box {
14997        transform: translateX(5px);
14998        scale: 2;
14999        rotate: 30deg;
15000        translate: 10px;
15001        transform: scale(3);
15002        translate: 20px 30px;
15003        rotate: x 40deg;
15004        scale: 4 5;
15005      }
15006      "#,
15007      indoc! {r#"
15008      .box {
15009        transform: scale(3);
15010        translate: 20px 30px;
15011        rotate: x 40deg;
15012        scale: 4 5;
15013      }
15014      "#},
15015    );
15016
15017    test(
15018      r#"
15019      .base {
15020        translate: 10px;
15021        rotate: 30deg;
15022        scale: 2;
15023      }
15024
15025      .base.reset {
15026        transform: none;
15027        translate: none;
15028        rotate: none;
15029        scale: none;
15030      }
15031
15032      .base.identity {
15033        translate: 0;
15034        rotate: 0deg;
15035        scale: 1;
15036        transform: none;
15037      }
15038      "#,
15039      indoc! {r#"
15040      .base {
15041        translate: 10px;
15042        rotate: 30deg;
15043        scale: 2;
15044      }
15045
15046      .base.reset {
15047        transform: none;
15048        translate: none;
15049        rotate: none;
15050        scale: none;
15051      }
15052
15053      .base.identity {
15054        transform: none;
15055        translate: 0;
15056        rotate: 0deg;
15057        scale: 1;
15058      }
15059      "#},
15060    );
15061
15062    test(
15063      r#"
15064      .box {
15065        transform: scale(2) !important;
15066        translate: 10px;
15067        rotate: 30deg !important;
15068        scale: 3;
15069        translate: 20px !important;
15070        transform: none;
15071        translate: 30px !important;
15072      }
15073      "#,
15074      indoc! {r#"
15075      .box {
15076        transform: none;
15077        translate: 10px;
15078        scale: 3;
15079        transform: scale(2) !important;
15080        translate: 30px !important;
15081        rotate: 30deg !important;
15082      }
15083      "#},
15084    );
15085
15086    test(
15087      r#"
15088      .box {
15089        transform: rotate(10deg);
15090        translate: 10px;
15091        translate: var(--shift);
15092        rotate: 20deg;
15093        transform: var(--motion);
15094        scale: 2;
15095        scale: var(--zoom);
15096        transform: translateX(2px);
15097      }
15098      "#,
15099      indoc! {r#"
15100      .box {
15101        transform: rotate(10deg);
15102        translate: 10px;
15103        translate: var(--shift);
15104        rotate: 20deg;
15105        transform: var(--motion);
15106        scale: 2;
15107        scale: var(--zoom);
15108        transform: translateX(2px);
15109      }
15110      "#},
15111    );
15112
15113    test(
15114      r#"
15115      .box {
15116        -webkit-transform: scale(2);
15117        translate: 10px;
15118        transform: scale(3);
15119        rotate: 30deg;
15120      }
15121      "#,
15122      indoc! {r#"
15123      .box {
15124        -webkit-transform: scale(2);
15125        translate: 10px;
15126        transform: scale(3);
15127        rotate: 30deg;
15128      }
15129      "#},
15130    );
15131
15132    prefix_test(
15133      r#"
15134      .box {
15135        translate: 10px;
15136        transform: scale(2);
15137        rotate: none;
15138        scale: 1;
15139      }
15140      "#,
15141      indoc! {r#"
15142      .box {
15143        -webkit-transform: scale(2);
15144        -moz-transform: scale(2);
15145        transform: scale(2);
15146        translate: 10px;
15147        rotate: none;
15148        scale: 1;
15149      }
15150      "#},
15151      Browsers {
15152        firefox: Some(6 << 16),
15153        safari: Some(6 << 16),
15154        ..Browsers::default()
15155      },
15156    );
15157  }
15158
15159  #[test]
15160  fn test_zero_translate3d() {
15161    minify_test(
15162      indoc! {"
15163        .foo {
15164          transform: translate3d(0, 0, 0);
15165        }
15166      "},
15167      ".foo{transform:translate(0)}",
15168    );
15169    minify_test(
15170      indoc! {"
15171        .foo {
15172          transform: translate3d(0px, -0%, 0em);
15173        }
15174      "},
15175      ".foo{transform:translate(0)}",
15176    );
15177    minify_test(
15178      indoc! {"
15179        .foo {
15180          transform: translate3d(0%, 0px, -0px);
15181        }
15182      "},
15183      ".foo{transform:translate(0%)}",
15184    );
15185    minify_test(
15186      indoc! {"
15187        .foo {
15188          transform: translate3d(calc(1px - 1px), 0, 0) rotate(30deg);
15189        }
15190      "},
15191      ".foo{transform:translate(0)rotate(30deg)}",
15192    );
15193    minify_test(
15194      indoc! {"
15195        .foo {
15196          -webkit-transform: translate3d(0, 0, 0);
15197        }
15198      "},
15199      ".foo{-webkit-transform:translate(0)}",
15200    );
15201    minify_test(
15202      indoc! {"
15203        .foo {
15204          transform: translate3d(0, 0, var(--z));
15205        }
15206      "},
15207      ".foo{transform:translate3d(0, 0, var(--z))}",
15208    );
15209    test(
15210      indoc! {"
15211        .foo {
15212          transform: translate3d(0, 0, 0);
15213        }
15214      "},
15215      indoc! {"
15216        .foo {
15217          transform: translate3d(0, 0, 0);
15218        }
15219      "},
15220    );
15221  }
15222
15223  #[test]
15224  pub fn test_gradients() {
15225    property_range_test(&["clip-path"], &[("circle(-1px)", None), ("ellipse(1px -2%)", None)]);
15226    property_range_test(
15227      &["background-image"],
15228      &[
15229        ("radial-gradient(-1px, red, blue)", None),
15230        ("radial-gradient(1px -2%, red, blue)", None),
15231      ],
15232    );
15233    minify_test(
15234      ".foo { background: linear-gradient(yellow, blue) }",
15235      ".foo{background:linear-gradient(#ff0,#00f)}",
15236    );
15237    minify_test(
15238      ".foo { background: linear-gradient(to bottom, yellow, blue); }",
15239      ".foo{background:linear-gradient(#ff0,#00f)}",
15240    );
15241    minify_test(
15242      ".foo { background: linear-gradient(180deg, yellow, blue); }",
15243      ".foo{background:linear-gradient(#ff0,#00f)}",
15244    );
15245    minify_test(
15246      ".foo { background: linear-gradient(0.5turn, yellow, blue); }",
15247      ".foo{background:linear-gradient(#ff0,#00f)}",
15248    );
15249    minify_test(
15250      ".foo { background: linear-gradient(yellow 10%, blue 20%) }",
15251      ".foo{background:linear-gradient(#ff0 10%,#00f 20%)}",
15252    );
15253    minify_test(
15254      ".foo { background: linear-gradient(to top, blue, yellow); }",
15255      ".foo{background:linear-gradient(#ff0,#00f)}",
15256    );
15257    minify_test(
15258      ".foo { background: linear-gradient(to top, blue 10%, yellow 20%); }",
15259      ".foo{background:linear-gradient(#ff0 80%,#00f 90%)}",
15260    );
15261    minify_test(
15262      ".foo { background: linear-gradient(to top, blue 10px, yellow 20px); }",
15263      ".foo{background:linear-gradient(0deg,#00f 10px,#ff0 20px)}",
15264    );
15265    minify_test(
15266      ".foo { background: linear-gradient(135deg, yellow, blue); }",
15267      ".foo{background:linear-gradient(135deg,#ff0,#00f)}",
15268    );
15269    minify_test(
15270      ".foo { background: linear-gradient(-1.42109e-14deg, rgba(10, 132, 255, 0.14) 0%, rgba(112, 183, 255, 0.14) 100%); }",
15271      ".foo{background:linear-gradient(-1.42109e-14deg,#0a84ff24 0%,#70b7ff24 100%)}",
15272    );
15273    minify_test(
15274      ".foo { background: linear-gradient(yellow, blue 20%, #0f0); }",
15275      ".foo{background:linear-gradient(#ff0,#00f 20%,#0f0)}",
15276    );
15277    minify_test(
15278      ".foo { background: linear-gradient(to top right, red, white, blue) }",
15279      ".foo{background:linear-gradient(to top right,red,#fff,#00f)}",
15280    );
15281    minify_test(
15282      ".foo { background: linear-gradient(yellow, blue calc(10% * 2), #0f0); }",
15283      ".foo{background:linear-gradient(#ff0,#00f 20%,#0f0)}",
15284    );
15285    minify_test(
15286      ".foo { background: linear-gradient(yellow, 20%, blue); }",
15287      ".foo{background:linear-gradient(#ff0,20%,#00f)}",
15288    );
15289    minify_test(
15290      ".foo { background: linear-gradient(yellow, 50%, blue); }",
15291      ".foo{background:linear-gradient(#ff0,#00f)}",
15292    );
15293    minify_test(
15294      ".foo { background: linear-gradient(yellow, 20px, blue); }",
15295      ".foo{background:linear-gradient(#ff0,20px,#00f)}",
15296    );
15297    minify_test(
15298      ".foo { background: linear-gradient(yellow, 50px, blue); }",
15299      ".foo{background:linear-gradient(#ff0,50px,#00f)}",
15300    );
15301    minify_test(
15302      ".foo { background: linear-gradient(yellow, 50px, blue); }",
15303      ".foo{background:linear-gradient(#ff0,50px,#00f)}",
15304    );
15305    minify_test(
15306      ".foo { background: linear-gradient(yellow, red 30% 40%, blue); }",
15307      ".foo{background:linear-gradient(#ff0,red 30% 40%,#00f)}",
15308    );
15309    minify_test(
15310      ".foo { background: linear-gradient(yellow, red 30%, red 40%, blue); }",
15311      ".foo{background:linear-gradient(#ff0,red 30% 40%,#00f)}",
15312    );
15313    minify_test(
15314      ".foo { background: linear-gradient(0, yellow, blue); }",
15315      ".foo{background:linear-gradient(#00f,#ff0)}",
15316    );
15317    minify_test(
15318      ".foo { background: -webkit-linear-gradient(yellow, blue) }",
15319      ".foo{background:-webkit-linear-gradient(#ff0,#00f)}",
15320    );
15321    minify_test(
15322      ".foo { background: -webkit-linear-gradient(bottom, yellow, blue); }",
15323      ".foo{background:-webkit-linear-gradient(#ff0,#00f)}",
15324    );
15325    minify_test(
15326      ".foo { background: -webkit-linear-gradient(top right, red, white, blue) }",
15327      ".foo{background:-webkit-linear-gradient(top right,red,#fff,#00f)}",
15328    );
15329    minify_test(
15330      ".foo { background: -moz-linear-gradient(yellow, blue) }",
15331      ".foo{background:-moz-linear-gradient(#ff0,#00f)}",
15332    );
15333    minify_test(
15334      ".foo { background: -moz-linear-gradient(bottom, yellow, blue); }",
15335      ".foo{background:-moz-linear-gradient(#ff0,#00f)}",
15336    );
15337    minify_test(
15338      ".foo { background: -moz-linear-gradient(top right, red, white, blue) }",
15339      ".foo{background:-moz-linear-gradient(top right,red,#fff,#00f)}",
15340    );
15341    minify_test(
15342      ".foo { background: -o-linear-gradient(yellow, blue) }",
15343      ".foo{background:-o-linear-gradient(#ff0,#00f)}",
15344    );
15345    minify_test(
15346      ".foo { background: -o-linear-gradient(bottom, yellow, blue); }",
15347      ".foo{background:-o-linear-gradient(#ff0,#00f)}",
15348    );
15349    minify_test(
15350      ".foo { background: -o-linear-gradient(top right, red, white, blue) }",
15351      ".foo{background:-o-linear-gradient(top right,red,#fff,#00f)}",
15352    );
15353    minify_test(
15354      ".foo { background: -webkit-gradient(linear, left top, left bottom, from(blue), to(yellow)) }",
15355      ".foo{background:-webkit-gradient(linear,0 0,0 100%,from(#00f),to(#ff0))}",
15356    );
15357    minify_test(
15358      ".foo { background: -webkit-gradient(linear, left top, left bottom, from(blue), color-stop(50%, red), to(yellow)) }",
15359      ".foo{background:-webkit-gradient(linear,0 0,0 100%,from(#00f),color-stop(.5,red),to(#ff0))}"
15360    );
15361    minify_test(
15362      ".foo { background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, blue), color-stop(50%, red), color-stop(100%, yellow)) }",
15363      ".foo{background:-webkit-gradient(linear,0 0,0 100%,from(#00f),color-stop(.5,red),to(#ff0))}"
15364    );
15365    minify_test(
15366      ".foo { background: repeating-linear-gradient(yellow 10px, blue 50px) }",
15367      ".foo{background:repeating-linear-gradient(#ff0 10px,#00f 50px)}",
15368    );
15369    minify_test(
15370      ".foo { background: -webkit-repeating-linear-gradient(yellow 10px, blue 50px) }",
15371      ".foo{background:-webkit-repeating-linear-gradient(#ff0 10px,#00f 50px)}",
15372    );
15373    minify_test(
15374      ".foo { background: -moz-repeating-linear-gradient(yellow 10px, blue 50px) }",
15375      ".foo{background:-moz-repeating-linear-gradient(#ff0 10px,#00f 50px)}",
15376    );
15377    minify_test(
15378      ".foo { background: -o-repeating-linear-gradient(yellow 10px, blue 50px) }",
15379      ".foo{background:-o-repeating-linear-gradient(#ff0 10px,#00f 50px)}",
15380    );
15381    minify_test(
15382      ".foo { background: radial-gradient(yellow, blue) }",
15383      ".foo{background:radial-gradient(#ff0,#00f)}",
15384    );
15385    minify_test(
15386      ".foo { background: radial-gradient(at top left, yellow, blue) }",
15387      ".foo{background:radial-gradient(at 0 0,#ff0,#00f)}",
15388    );
15389    minify_test(
15390      ".foo { background: radial-gradient(5em circle at top left, yellow, blue) }",
15391      ".foo{background:radial-gradient(5em at 0 0,#ff0,#00f)}",
15392    );
15393    minify_test(
15394      ".foo { background: radial-gradient(circle at 100%, #333, #333 50%, #eee 75%, #333 75%) }",
15395      ".foo{background:radial-gradient(circle at 100%,#333,#333 50%,#eee 75%,#333 75%)}",
15396    );
15397    minify_test(
15398      ".foo { background: radial-gradient(farthest-corner circle at 100% 50%, #333, #333 50%, #eee 75%, #333 75%) }",
15399      ".foo{background:radial-gradient(circle at 100%,#333,#333 50%,#eee 75%,#333 75%)}"
15400    );
15401    minify_test(
15402      ".foo { background: radial-gradient(farthest-corner circle at 50% 50%, #333, #333 50%, #eee 75%, #333 75%) }",
15403      ".foo{background:radial-gradient(circle,#333,#333 50%,#eee 75%,#333 75%)}"
15404    );
15405    minify_test(
15406      ".foo { background: radial-gradient(ellipse at top, #e66465, transparent) }",
15407      ".foo{background:radial-gradient(at top,#e66465,#0000)}",
15408    );
15409    minify_test(
15410      ".foo { background: radial-gradient(20px, yellow, blue) }",
15411      ".foo{background:radial-gradient(20px,#ff0,#00f)}",
15412    );
15413    minify_test(
15414      ".foo { background: radial-gradient(circle 20px, yellow, blue) }",
15415      ".foo{background:radial-gradient(20px,#ff0,#00f)}",
15416    );
15417    minify_test(
15418      ".foo { background: radial-gradient(20px 40px, yellow, blue) }",
15419      ".foo{background:radial-gradient(20px 40px,#ff0,#00f)}",
15420    );
15421    minify_test(
15422      ".foo { background: radial-gradient(ellipse 20px 40px, yellow, blue) }",
15423      ".foo{background:radial-gradient(20px 40px,#ff0,#00f)}",
15424    );
15425    minify_test(
15426      ".foo { background: radial-gradient(ellipse calc(20px + 10px) 40px, yellow, blue) }",
15427      ".foo{background:radial-gradient(30px 40px,#ff0,#00f)}",
15428    );
15429    minify_test(
15430      ".foo { background: radial-gradient(circle farthest-side, yellow, blue) }",
15431      ".foo{background:radial-gradient(circle farthest-side,#ff0,#00f)}",
15432    );
15433    minify_test(
15434      ".foo { background: radial-gradient(farthest-side circle, yellow, blue) }",
15435      ".foo{background:radial-gradient(circle farthest-side,#ff0,#00f)}",
15436    );
15437    minify_test(
15438      ".foo { background: radial-gradient(ellipse farthest-side, yellow, blue) }",
15439      ".foo{background:radial-gradient(farthest-side,#ff0,#00f)}",
15440    );
15441    minify_test(
15442      ".foo { background: radial-gradient(farthest-side ellipse, yellow, blue) }",
15443      ".foo{background:radial-gradient(farthest-side,#ff0,#00f)}",
15444    );
15445    minify_test(
15446      ".foo { background: -webkit-radial-gradient(yellow, blue) }",
15447      ".foo{background:-webkit-radial-gradient(#ff0,#00f)}",
15448    );
15449    minify_test(
15450      ".foo { background: -moz-radial-gradient(yellow, blue) }",
15451      ".foo{background:-moz-radial-gradient(#ff0,#00f)}",
15452    );
15453    minify_test(
15454      ".foo { background: -o-radial-gradient(yellow, blue) }",
15455      ".foo{background:-o-radial-gradient(#ff0,#00f)}",
15456    );
15457    minify_test(
15458      ".foo { background: repeating-radial-gradient(circle 20px, yellow, blue) }",
15459      ".foo{background:repeating-radial-gradient(20px,#ff0,#00f)}",
15460    );
15461    minify_test(
15462      ".foo { background: -webkit-repeating-radial-gradient(circle 20px, yellow, blue) }",
15463      ".foo{background:-webkit-repeating-radial-gradient(20px,#ff0,#00f)}",
15464    );
15465    minify_test(
15466      ".foo { background: -moz-repeating-radial-gradient(circle 20px, yellow, blue) }",
15467      ".foo{background:-moz-repeating-radial-gradient(20px,#ff0,#00f)}",
15468    );
15469    minify_test(
15470      ".foo { background: -o-repeating-radial-gradient(circle 20px, yellow, blue) }",
15471      ".foo{background:-o-repeating-radial-gradient(20px,#ff0,#00f)}",
15472    );
15473    minify_test(
15474      ".foo { background: -webkit-gradient(radial, center center, 0, center center, 100, from(blue), to(yellow)) }",
15475      ".foo{background:-webkit-gradient(radial,50% 50%,0,50% 50%,100,from(#00f),to(#ff0))}"
15476    );
15477    minify_test(
15478      ".foo { background: conic-gradient(#f06, gold) }",
15479      ".foo{background:conic-gradient(#f06,gold)}",
15480    );
15481    minify_test(
15482      ".foo { background: conic-gradient(at 50% 50%, #f06, gold) }",
15483      ".foo{background:conic-gradient(#f06,gold)}",
15484    );
15485    minify_test(
15486      ".foo { background: conic-gradient(from 0deg, #f06, gold) }",
15487      ".foo{background:conic-gradient(#f06,gold)}",
15488    );
15489    minify_test(
15490      ".foo { background: conic-gradient(from 0, #f06, gold) }",
15491      ".foo{background:conic-gradient(#f06,gold)}",
15492    );
15493    minify_test(
15494      ".foo { background: conic-gradient(from 0deg at center, #f06, gold) }",
15495      ".foo{background:conic-gradient(#f06,gold)}",
15496    );
15497    minify_test(
15498      ".foo { background: conic-gradient(white -50%, black 150%) }",
15499      ".foo{background:conic-gradient(#fff -50%,#000 150%)}",
15500    );
15501    minify_test(
15502      ".foo { background: conic-gradient(white -180deg, black 540deg) }",
15503      ".foo{background:conic-gradient(#fff -180deg,#000 540deg)}",
15504    );
15505    minify_test(
15506      ".foo { background: conic-gradient(from 45deg, white, black, white) }",
15507      ".foo{background:conic-gradient(from 45deg,#fff,#000,#fff)}",
15508    );
15509    minify_test(
15510      ".foo { background: repeating-conic-gradient(from 45deg, white, black, white) }",
15511      ".foo{background:repeating-conic-gradient(from 45deg,#fff,#000,#fff)}",
15512    );
15513    minify_test(
15514      ".foo { background: repeating-conic-gradient(black 0deg 25%, white 0deg 50%) }",
15515      ".foo{background:repeating-conic-gradient(#000 0deg 25%,#fff 0deg 50%)}",
15516    );
15517
15518    test(
15519      r#"
15520        .foo {
15521          background: -webkit-gradient(linear, left top, left bottom, from(red), to(blue));
15522          background: -webkit-linear-gradient(red, blue);
15523          background: -moz-linear-gradient(red, blue);
15524          background: -o-linear-gradient(red, blue);
15525          background: linear-gradient(red, blue);
15526        }
15527      "#,
15528      indoc! {r#"
15529        .foo {
15530          background: -webkit-gradient(linear, left top, left bottom, from(red), to(#00f));
15531          background: -webkit-linear-gradient(red, #00f);
15532          background: -moz-linear-gradient(red, #00f);
15533          background: -o-linear-gradient(red, #00f);
15534          background: linear-gradient(red, #00f);
15535        }
15536      "#},
15537    );
15538
15539    prefix_test(
15540      r#"
15541      .foo {
15542        background: -webkit-gradient(linear, left top, left bottom, from(red), to(blue));
15543        background: -webkit-linear-gradient(red, blue);
15544        background: -moz-linear-gradient(red, blue);
15545        background: -o-linear-gradient(red, blue);
15546        background: linear-gradient(red, blue);
15547      }
15548      "#,
15549      indoc! {r#"
15550      .foo {
15551        background: linear-gradient(red, #00f);
15552      }
15553      "#},
15554      Browsers {
15555        chrome: Some(95 << 16),
15556        ..Browsers::default()
15557      },
15558    );
15559    prefix_test(
15560      r#"
15561      .foo {
15562        background: -webkit-gradient(linear, left top, left bottom, from(red), to(blue));
15563        background: -webkit-linear-gradient(red, blue);
15564        background: -moz-linear-gradient(red, blue);
15565        background: -o-linear-gradient(red, blue);
15566      }
15567      "#,
15568      indoc! {r#"
15569      .foo {
15570        background: -webkit-gradient(linear, left top, left bottom, from(red), to(#00f));
15571        background: -webkit-linear-gradient(red, #00f);
15572        background: -moz-linear-gradient(red, #00f);
15573        background: -o-linear-gradient(red, #00f);
15574      }
15575      "#},
15576      Browsers {
15577        chrome: Some(95 << 16),
15578        ..Browsers::default()
15579      },
15580    );
15581    prefix_test(
15582      r#"
15583      .foo {
15584        background-image: linear-gradient(red, blue);
15585      }
15586      "#,
15587      indoc! {r#"
15588      .foo {
15589        background-image: -webkit-gradient(linear, 0 0, 0 100%, from(red), to(#00f));
15590        background-image: -webkit-linear-gradient(top, red, #00f);
15591        background-image: linear-gradient(red, #00f);
15592      }
15593      "#},
15594      Browsers {
15595        chrome: Some(8 << 16),
15596        ..Browsers::default()
15597      },
15598    );
15599    prefix_test(
15600      r#"
15601      .foo {
15602        background-image: linear-gradient(to right, red, blue);
15603      }
15604      "#,
15605      indoc! {r#"
15606      .foo {
15607        background-image: -webkit-gradient(linear, 0 0, 100% 0, from(red), to(#00f));
15608        background-image: -webkit-linear-gradient(left, red, #00f);
15609        background-image: linear-gradient(to right, red, #00f);
15610      }
15611      "#},
15612      Browsers {
15613        chrome: Some(8 << 16),
15614        ..Browsers::default()
15615      },
15616    );
15617    prefix_test(
15618      r#"
15619      .foo {
15620        background-image: linear-gradient(to top, red, blue);
15621      }
15622      "#,
15623      indoc! {r#"
15624      .foo {
15625        background-image: -webkit-gradient(linear, 0 100%, 0 0, from(red), to(#00f));
15626        background-image: -webkit-linear-gradient(red, #00f);
15627        background-image: linear-gradient(to top, red, #00f);
15628      }
15629      "#},
15630      Browsers {
15631        chrome: Some(8 << 16),
15632        ..Browsers::default()
15633      },
15634    );
15635    prefix_test(
15636      r#"
15637      .foo {
15638        background-image: linear-gradient(to left, red, blue);
15639      }
15640      "#,
15641      indoc! {r#"
15642      .foo {
15643        background-image: -webkit-gradient(linear, 100% 0, 0 0, from(red), to(#00f));
15644        background-image: -webkit-linear-gradient(right, red, #00f);
15645        background-image: linear-gradient(to left, red, #00f);
15646      }
15647      "#},
15648      Browsers {
15649        chrome: Some(8 << 16),
15650        ..Browsers::default()
15651      },
15652    );
15653    prefix_test(
15654      r#"
15655      .foo {
15656        background-image: linear-gradient(to left bottom, red, blue);
15657      }
15658      "#,
15659      indoc! {r#"
15660      .foo {
15661        background-image: -webkit-gradient(linear, 100% 0, 0 100%, from(red), to(#00f));
15662        background-image: -webkit-linear-gradient(top right, red, #00f);
15663        background-image: linear-gradient(to bottom left, red, #00f);
15664      }
15665      "#},
15666      Browsers {
15667        chrome: Some(8 << 16),
15668        ..Browsers::default()
15669      },
15670    );
15671    prefix_test(
15672      r#"
15673      .foo {
15674        background-image: linear-gradient(to top right, red, blue);
15675      }
15676      "#,
15677      indoc! {r#"
15678      .foo {
15679        background-image: -webkit-gradient(linear, 0 100%, 100% 0, from(red), to(#00f));
15680        background-image: -webkit-linear-gradient(bottom left, red, #00f);
15681        background-image: linear-gradient(to top right, red, #00f);
15682      }
15683      "#},
15684      Browsers {
15685        chrome: Some(8 << 16),
15686        ..Browsers::default()
15687      },
15688    );
15689    prefix_test(
15690      r#"
15691      .foo {
15692        background-image: linear-gradient(90deg, red, blue);
15693      }
15694      "#,
15695      indoc! {r#"
15696      .foo {
15697        background-image: -webkit-gradient(linear, 0 0, 100% 0, from(red), to(#00f));
15698        background-image: -webkit-linear-gradient(0deg, red, #00f);
15699        background-image: linear-gradient(90deg, red, #00f);
15700      }
15701      "#},
15702      Browsers {
15703        chrome: Some(8 << 16),
15704        ..Browsers::default()
15705      },
15706    );
15707    prefix_test(
15708      r#"
15709      .foo {
15710        background-image: linear-gradient(45deg, red, blue);
15711      }
15712      "#,
15713      indoc! {r#"
15714      .foo {
15715        background-image: -webkit-linear-gradient(45deg, red, #00f);
15716        background-image: linear-gradient(45deg, red, #00f);
15717      }
15718      "#},
15719      Browsers {
15720        chrome: Some(8 << 16),
15721        ..Browsers::default()
15722      },
15723    );
15724    prefix_test(
15725      r#"
15726      .foo {
15727        background-image: linear-gradient(red, blue);
15728      }
15729      "#,
15730      indoc! {r#"
15731      .foo {
15732        background-image: -webkit-linear-gradient(top, red, #00f);
15733        background-image: linear-gradient(red, #00f);
15734      }
15735      "#},
15736      Browsers {
15737        chrome: Some(10 << 16),
15738        ..Browsers::default()
15739      },
15740    );
15741    prefix_test(
15742      r#"
15743      .foo {
15744        background-image: radial-gradient(20px, red, blue);
15745      }
15746      "#,
15747      indoc! {r#"
15748      .foo {
15749        background-image: -webkit-gradient(radial, center center, 0, center center, 20, from(red), to(#00f));
15750        background-image: -webkit-radial-gradient(20px, red, #00f);
15751        background-image: radial-gradient(20px, red, #00f);
15752      }
15753      "#},
15754      Browsers {
15755        chrome: Some(8 << 16),
15756        ..Browsers::default()
15757      },
15758    );
15759    prefix_test(
15760      r#"
15761      .foo {
15762        background-image: radial-gradient(20px at top left, red, blue);
15763      }
15764      "#,
15765      indoc! {r#"
15766      .foo {
15767        background-image: -webkit-gradient(radial, left top, 0, left top, 20, from(red), to(#00f));
15768        background-image: -webkit-radial-gradient(20px at 0 0, red, #00f);
15769        background-image: radial-gradient(20px at 0 0, red, #00f);
15770      }
15771      "#},
15772      Browsers {
15773        chrome: Some(8 << 16),
15774        ..Browsers::default()
15775      },
15776    );
15777    prefix_test(
15778      r#"
15779      .foo {
15780        background-image: radial-gradient(red, blue);
15781      }
15782      "#,
15783      indoc! {r#"
15784      .foo {
15785        background-image: -webkit-radial-gradient(red, #00f);
15786        background-image: radial-gradient(red, #00f);
15787      }
15788      "#},
15789      Browsers {
15790        chrome: Some(8 << 16),
15791        ..Browsers::default()
15792      },
15793    );
15794    prefix_test(
15795      r#"
15796      .foo {
15797        background-image: -webkit-gradient(radial, left top, 0, left top, 20, from(red), to(#00f));
15798        background-image: -webkit-radial-gradient(20px at 0% 0%, red, #00f);
15799        background-image: radial-gradient(20px at 0% 0%, red, #00f);
15800      }
15801      "#,
15802      indoc! {r#"
15803      .foo {
15804        background-image: radial-gradient(20px at 0 0, red, #00f);
15805      }
15806      "#},
15807      Browsers {
15808        chrome: Some(30 << 16),
15809        ..Browsers::default()
15810      },
15811    );
15812    prefix_test(
15813      r#"
15814      .foo {
15815        background: -webkit-gradient(radial, left top, 0, left top, 20, from(red), to(#00f));
15816        background: -webkit-radial-gradient(20px at 0% 0%, red, #00f);
15817        background: radial-gradient(20px at 0% 0%, red, #00f);
15818      }
15819      "#,
15820      indoc! {r#"
15821      .foo {
15822        background: radial-gradient(20px at 0 0, red, #00f);
15823      }
15824      "#},
15825      Browsers {
15826        chrome: Some(30 << 16),
15827        ..Browsers::default()
15828      },
15829    );
15830    prefix_test(
15831      r#"
15832      .foo {
15833        background: radial-gradient(red, blue);
15834      }
15835      "#,
15836      indoc! {r#"
15837      .foo {
15838        background: -webkit-radial-gradient(red, #00f);
15839        background: radial-gradient(red, #00f);
15840      }
15841      "#},
15842      Browsers {
15843        chrome: Some(8 << 16),
15844        ..Browsers::default()
15845      },
15846    );
15847    prefix_test(
15848      r#"
15849      .foo {
15850        background: radial-gradient(red, blue), linear-gradient(yellow, red), url(bg.jpg);
15851      }
15852      "#,
15853      indoc! {r#"
15854      .foo {
15855        background: -webkit-gradient(linear, 0 0, 0 100%, from(#ff0), to(red)), url("bg.jpg");
15856        background: -webkit-radial-gradient(red, #00f), -webkit-linear-gradient(top, #ff0, red), url("bg.jpg");
15857        background: -moz-radial-gradient(red, #00f), -moz-linear-gradient(top, #ff0, red), url("bg.jpg");
15858        background: -o-radial-gradient(red, #00f), -o-linear-gradient(top, #ff0, red), url("bg.jpg");
15859        background: radial-gradient(red, #00f), linear-gradient(#ff0, red), url("bg.jpg");
15860      }
15861      "#},
15862      Browsers {
15863        chrome: Some(8 << 16),
15864        firefox: Some(4 << 16),
15865        opera: Some(11 << 16 | 5 << 8),
15866        ..Browsers::default()
15867      },
15868    );
15869
15870    prefix_test(
15871      r#"
15872      .foo {
15873        background: linear-gradient(yellow, red 30% 40%, blue);
15874      }
15875      "#,
15876      indoc! {r#"
15877      .foo {
15878        background: linear-gradient(#ff0, red 30%, red 40%, #00f);
15879      }
15880      "#},
15881      Browsers {
15882        chrome: Some(70 << 16),
15883        ..Browsers::default()
15884      },
15885    );
15886
15887    prefix_test(
15888      r#"
15889      .foo {
15890        background: linear-gradient(yellow, red 30% 40%, blue);
15891      }
15892      "#,
15893      indoc! {r#"
15894      .foo {
15895        background: linear-gradient(#ff0, red 30% 40%, #00f);
15896      }
15897      "#},
15898      Browsers {
15899        chrome: Some(71 << 16),
15900        ..Browsers::default()
15901      },
15902    );
15903
15904    prefix_test(
15905      ".foo { background: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
15906      indoc! { r#"
15907        .foo {
15908          background: linear-gradient(#ff0b0c, #766eff);
15909          background: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
15910        }
15911      "#},
15912      Browsers {
15913        chrome: Some(90 << 16),
15914        ..Browsers::default()
15915      },
15916    );
15917
15918    prefix_test(
15919      ".foo { background: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
15920      indoc! { r#"
15921        .foo {
15922          background: linear-gradient(#ff0b0c, #766eff);
15923          background: linear-gradient(color(display-p3 1 .0000153435 -.00000303562), color(display-p3 .440289 .28452 1.23485));
15924          background: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
15925        }
15926      "#},
15927      Browsers {
15928        chrome: Some(90 << 16),
15929        safari: Some(14 << 16),
15930        ..Browsers::default()
15931      },
15932    );
15933
15934    prefix_test(
15935      ".foo { background: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
15936      indoc! { r#"
15937        .foo {
15938          background: -webkit-linear-gradient(top, #ff0b0c, #766eff);
15939          background: linear-gradient(#ff0b0c, #766eff);
15940          background: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
15941        }
15942      "#},
15943      Browsers {
15944        chrome: Some(20 << 16),
15945        ..Browsers::default()
15946      },
15947    );
15948
15949    prefix_test(
15950      ".foo { background: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
15951      indoc! { r#"
15952        .foo {
15953          background: -webkit-gradient(linear, 0 0, 0 100%, from(#ff0b0c), to(#766eff));
15954          background: -webkit-linear-gradient(top, #ff0b0c, #766eff);
15955          background: linear-gradient(#ff0b0c, #766eff);
15956          background: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
15957        }
15958      "#},
15959      Browsers {
15960        chrome: Some(8 << 16),
15961        ..Browsers::default()
15962      },
15963    );
15964
15965    prefix_test(
15966      ".foo { background: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
15967      indoc! { r#"
15968        .foo {
15969          background: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
15970        }
15971      "#},
15972      Browsers {
15973        safari: Some(15 << 16),
15974        ..Browsers::default()
15975      },
15976    );
15977
15978    prefix_test(
15979      ".foo { background-image: linear-gradient(oklab(59.686% 0.1009 0.1192), oklab(54.0% -0.10 -0.02)); }",
15980      indoc! { r#"
15981        .foo {
15982          background-image: linear-gradient(lab(52.2319% 40.1449 59.9171), lab(47.7776% -34.2947 -7.65904));
15983        }
15984      "#},
15985      Browsers {
15986        safari: Some(15 << 16),
15987        ..Browsers::default()
15988      },
15989    );
15990
15991    prefix_test(
15992      ".foo { background-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
15993      indoc! { r#"
15994        .foo {
15995          background-image: linear-gradient(#ff0b0c, #766eff);
15996          background-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
15997        }
15998      "#},
15999      Browsers {
16000        chrome: Some(90 << 16),
16001        ..Browsers::default()
16002      },
16003    );
16004
16005    prefix_test(
16006      ".foo { background-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
16007      indoc! { r#"
16008        .foo {
16009          background-image: linear-gradient(#ff0b0c, #766eff);
16010          background-image: linear-gradient(color(display-p3 1 .0000153435 -.00000303562), color(display-p3 .440289 .28452 1.23485));
16011          background-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
16012        }
16013      "#},
16014      Browsers {
16015        chrome: Some(90 << 16),
16016        safari: Some(14 << 16),
16017        ..Browsers::default()
16018      },
16019    );
16020
16021    prefix_test(
16022      ".foo { background-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
16023      indoc! { r#"
16024        .foo {
16025          background-image: -webkit-linear-gradient(top, #ff0b0c, #766eff);
16026          background-image: linear-gradient(#ff0b0c, #766eff);
16027          background-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
16028        }
16029      "#},
16030      Browsers {
16031        chrome: Some(20 << 16),
16032        ..Browsers::default()
16033      },
16034    );
16035
16036    prefix_test(
16037      ".foo { background-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
16038      indoc! { r#"
16039        .foo {
16040          background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ff0b0c), to(#766eff));
16041          background-image: -webkit-linear-gradient(top, #ff0b0c, #766eff);
16042          background-image: linear-gradient(#ff0b0c, #766eff);
16043          background-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
16044        }
16045      "#},
16046      Browsers {
16047        chrome: Some(8 << 16),
16048        ..Browsers::default()
16049      },
16050    );
16051
16052    prefix_test(
16053      ".foo { background-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
16054      indoc! { r#"
16055        .foo {
16056          background-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
16057        }
16058      "#},
16059      Browsers {
16060        safari: Some(15 << 16),
16061        ..Browsers::default()
16062      },
16063    );
16064
16065    prefix_test(
16066      ".foo { background-image: linear-gradient(oklab(59.686% 0.1009 0.1192), oklab(54.0% -0.10 -0.02)); }",
16067      indoc! { r#"
16068        .foo {
16069          background-image: linear-gradient(lab(52.2319% 40.1449 59.9171), lab(47.7776% -34.2947 -7.65904));
16070        }
16071      "#},
16072      Browsers {
16073        safari: Some(15 << 16),
16074        ..Browsers::default()
16075      },
16076    );
16077
16078    // Test cases from https://github.com/postcss/autoprefixer/blob/541295c0e6dd348db2d3f52772b59cd403c59d29/test/cases/gradient.css
16079    prefix_test(
16080      r#"
16081        a {
16082          background: linear-gradient(350.5deg, white, black), linear-gradient(-130deg, black, white), linear-gradient(45deg, black, white);
16083        }
16084        b {
16085          background-image: linear-gradient(rgba(0,0,0,1), white), linear-gradient(white, black);
16086        }
16087        strong {
16088          background: linear-gradient(to top, transparent, rgba(0, 0, 0, 0.8) 20px, #000 30px, #000) no-repeat;
16089        }
16090        div {
16091          background-image: radial-gradient(to left, white, black), repeating-linear-gradient(to bottom right, black, white), repeating-radial-gradient(to top, aqua, red);
16092        }
16093        .old-radial {
16094          background: radial-gradient(0 50%, ellipse farthest-corner, black, white);
16095        }
16096        .simple1 {
16097          background: linear-gradient(black, white);
16098        }
16099        .simple2 {
16100          background: linear-gradient(to left, black 0%, rgba(0, 0, 0, 0.5)50%, white 100%);
16101        }
16102        .simple3 {
16103          background: linear-gradient(to left, black 50%, white 100%);
16104        }
16105        .simple4 {
16106          background: linear-gradient(to right top, black, white);
16107        }
16108        .direction {
16109          background: linear-gradient(top left, black, rgba(0, 0, 0, 0.5), white);
16110        }
16111        .silent {
16112          background: -webkit-linear-gradient(top left, black, white);
16113        }
16114        .radial {
16115          background: radial-gradient(farthest-side at 0 50%, white, black);
16116        }
16117        .second {
16118          background: red linear-gradient(red, blue);
16119          background: url('logo.png'), linear-gradient(#fff, #000);
16120        }
16121        .px {
16122          background: linear-gradient(black 0, white 100px);
16123        }
16124        .list {
16125          list-style-image: linear-gradient(white, black);
16126        }
16127        .mask {
16128          mask: linear-gradient(white, black);
16129        }
16130        .newline {
16131          background-image:
16132              linear-gradient( white, black ),
16133              linear-gradient( black, white );
16134        }
16135        .convert {
16136          background: linear-gradient(0deg, white, black);
16137          background: linear-gradient(90deg, white, black);
16138          background: linear-gradient(180deg, white, black);
16139          background: linear-gradient(270deg, white, black);
16140        }
16141        .grad {
16142          background: linear-gradient(1grad, white, black);
16143        }
16144        .rad {
16145          background: linear-gradient(1rad, white, black);
16146        }
16147        .turn {
16148          background: linear-gradient(0.3turn, white, black);
16149        }
16150        .norm {
16151          background: linear-gradient(-90deg, white, black);
16152        }
16153        .mask {
16154          mask-image: radial-gradient(circle at 86% 86%, transparent 8px, black 8px);
16155        }
16156        .cover {
16157          background: radial-gradient(ellipse cover at center, white, black);
16158        }
16159        .contain {
16160          background: radial-gradient(contain at center, white, black);
16161        }
16162        .no-div {
16163          background: linear-gradient(black);
16164        }
16165        .background-shorthand {
16166          background: radial-gradient(#FFF, transparent) 0 0 / cover no-repeat #F0F;
16167        }
16168        .background-advanced {
16169          background: radial-gradient(ellipse farthest-corner at 5px 15px, rgba(214, 168, 18, 0.7) 0%, rgba(255, 21, 177, 0.7) 50%, rgba(210, 7, 148, 0.7) 95%),
16170                      radial-gradient(#FFF, transparent),
16171                      url(path/to/image.jpg) 50%/cover;
16172        }
16173        .multiradial {
16174          mask-image: radial-gradient(circle closest-corner at 100% 50%, #000, transparent);
16175        }
16176        .broken {
16177          mask-image: radial-gradient(white, black);
16178        }
16179        .loop {
16180          background-image: url("https://test.com/lol(test.png"), radial-gradient(yellow, black, yellow);
16181        }
16182        .unitless-zero {
16183          background-image: linear-gradient(0, green, blue);
16184          background: repeating-linear-gradient(0, blue, red 33.3%)
16185        }
16186        .zero-grad {
16187          background: linear-gradient(0grad, green, blue);
16188          background-image: repeating-linear-gradient(0grad, blue, red 33.3%)
16189        }
16190        .zero-rad {
16191          background: linear-gradient(0rad, green, blue);
16192        }
16193        .zero-turn {
16194          background: linear-gradient(0turn, green, blue);
16195        }
16196      "#,
16197      indoc! { r#"
16198        a {
16199          background: -webkit-linear-gradient(99.5deg, #fff, #000), -webkit-linear-gradient(220deg, #000, #fff), -webkit-linear-gradient(45deg, #000, #fff);
16200          background: -o-linear-gradient(99.5deg, #fff, #000), -o-linear-gradient(220deg, #000, #fff), -o-linear-gradient(45deg, #000, #fff);
16201          background: linear-gradient(350.5deg, #fff, #000), linear-gradient(-130deg, #000, #fff), linear-gradient(45deg, #000, #fff);
16202        }
16203
16204        b {
16205          background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#000), to(#fff)), -webkit-gradient(linear, 0 0, 0 100%, from(#fff), to(#000));
16206          background-image: -webkit-linear-gradient(top, #000, #fff), -webkit-linear-gradient(top, #fff, #000);
16207          background-image: -o-linear-gradient(top, #000, #fff), -o-linear-gradient(top, #fff, #000);
16208          background-image: linear-gradient(#000, #fff), linear-gradient(#fff, #000);
16209        }
16210
16211        strong {
16212          background: -webkit-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, .8) 20px, #000 30px, #000) no-repeat;
16213          background: -o-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, .8) 20px, #000 30px, #000) no-repeat;
16214          background: linear-gradient(to top, rgba(0, 0, 0, 0), rgba(0, 0, 0, .8) 20px, #000 30px, #000) no-repeat;
16215        }
16216
16217        div {
16218          background-image: radial-gradient(to left, white, black), repeating-linear-gradient(to bottom right, black, white), repeating-radial-gradient(to top, aqua, red);
16219        }
16220
16221        .old-radial {
16222          background: radial-gradient(0 50%, ellipse farthest-corner, black, white);
16223        }
16224
16225        .simple1 {
16226          background: -webkit-gradient(linear, 0 0, 0 100%, from(#000), to(#fff));
16227          background: -webkit-linear-gradient(top, #000, #fff);
16228          background: -o-linear-gradient(top, #000, #fff);
16229          background: linear-gradient(#000, #fff);
16230        }
16231
16232        .simple2 {
16233          background: -webkit-gradient(linear, 100% 0, 0 0, from(#000), color-stop(.5, rgba(0, 0, 0, .5)), to(#fff));
16234          background: -webkit-linear-gradient(right, #000 0%, rgba(0, 0, 0, .5) 50%, #fff 100%);
16235          background: -o-linear-gradient(right, #000 0%, rgba(0, 0, 0, .5) 50%, #fff 100%);
16236          background: linear-gradient(to left, #000 0%, rgba(0, 0, 0, .5) 50%, #fff 100%);
16237        }
16238
16239        .simple3 {
16240          background: -webkit-gradient(linear, 100% 0, 0 0, color-stop(.5, #000), to(#fff));
16241          background: -webkit-linear-gradient(right, #000 50%, #fff 100%);
16242          background: -o-linear-gradient(right, #000 50%, #fff 100%);
16243          background: linear-gradient(to left, #000 50%, #fff 100%);
16244        }
16245
16246        .simple4 {
16247          background: -webkit-gradient(linear, 0 100%, 100% 0, from(#000), to(#fff));
16248          background: -webkit-linear-gradient(bottom left, #000, #fff);
16249          background: -o-linear-gradient(bottom left, #000, #fff);
16250          background: linear-gradient(to top right, #000, #fff);
16251        }
16252
16253        .direction {
16254          background: linear-gradient(top left, black, rgba(0, 0, 0, .5), white);
16255        }
16256
16257        .silent {
16258          background: -webkit-gradient(linear, 100% 100%, 0 0, from(#000), to(#fff));
16259          background: -webkit-linear-gradient(top left, #000, #fff);
16260        }
16261
16262        .radial {
16263          background: -webkit-radial-gradient(farthest-side at 0, #fff, #000);
16264          background: -o-radial-gradient(farthest-side at 0, #fff, #000);
16265          background: radial-gradient(farthest-side at 0, #fff, #000);
16266        }
16267
16268        .second {
16269          background: red -webkit-gradient(linear, 0 0, 0 100%, from(red), to(#00f));
16270          background: red -webkit-linear-gradient(top, red, #00f);
16271          background: red -o-linear-gradient(top, red, #00f);
16272          background: red linear-gradient(red, #00f);
16273          background: url("logo.png"), linear-gradient(#fff, #000);
16274        }
16275
16276        .px {
16277          background: -webkit-linear-gradient(top, #000 0, #fff 100px);
16278          background: -o-linear-gradient(top, #000 0, #fff 100px);
16279          background: linear-gradient(#000 0, #fff 100px);
16280        }
16281
16282        .list {
16283          list-style-image: -webkit-gradient(linear, 0 0, 0 100%, from(#fff), to(#000));
16284          list-style-image: -webkit-linear-gradient(top, #fff, #000);
16285          list-style-image: -o-linear-gradient(top, #fff, #000);
16286          list-style-image: linear-gradient(#fff, #000);
16287        }
16288
16289        .mask {
16290          -webkit-mask: -webkit-gradient(linear, 0 0, 0 100%, from(#fff), to(#000));
16291          -webkit-mask: -webkit-linear-gradient(top, #fff, #000);
16292          -webkit-mask: -o-linear-gradient(top, #fff, #000);
16293          mask: -o-linear-gradient(top, #fff, #000);
16294          -webkit-mask: linear-gradient(#fff, #000);
16295          mask: linear-gradient(#fff, #000);
16296        }
16297
16298        .newline {
16299          background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#fff), to(#000)), -webkit-gradient(linear, 0 0, 0 100%, from(#000), to(#fff));
16300          background-image: -webkit-linear-gradient(top, #fff, #000), -webkit-linear-gradient(top, #000, #fff);
16301          background-image: -o-linear-gradient(top, #fff, #000), -o-linear-gradient(top, #000, #fff);
16302          background-image: linear-gradient(#fff, #000), linear-gradient(#000, #fff);
16303        }
16304
16305        .convert {
16306          background: -webkit-gradient(linear, 0 100%, 0 0, from(#fff), to(#000));
16307          background: -webkit-linear-gradient(90deg, #fff, #000);
16308          background: -o-linear-gradient(90deg, #fff, #000);
16309          background: linear-gradient(0deg, #fff, #000);
16310          background: linear-gradient(90deg, #fff, #000);
16311          background: linear-gradient(#fff, #000);
16312          background: linear-gradient(270deg, #fff, #000);
16313        }
16314
16315        .grad {
16316          background: -webkit-linear-gradient(89.1deg, #fff, #000);
16317          background: -o-linear-gradient(89.1deg, #fff, #000);
16318          background: linear-gradient(1grad, #fff, #000);
16319        }
16320
16321        .rad {
16322          background: -webkit-linear-gradient(32.704deg, #fff, #000);
16323          background: -o-linear-gradient(32.704deg, #fff, #000);
16324          background: linear-gradient(57.2958deg, #fff, #000);
16325        }
16326
16327        .turn {
16328          background: -webkit-linear-gradient(342deg, #fff, #000);
16329          background: -o-linear-gradient(342deg, #fff, #000);
16330          background: linear-gradient(.3turn, #fff, #000);
16331        }
16332
16333        .norm {
16334          background: -webkit-linear-gradient(#fff, #000);
16335          background: -o-linear-gradient(#fff, #000);
16336          background: linear-gradient(-90deg, #fff, #000);
16337        }
16338
16339        .mask {
16340          -webkit-mask-image: -webkit-radial-gradient(circle at 86% 86%, rgba(0, 0, 0, 0) 8px, #000 8px);
16341          -webkit-mask-image: -o-radial-gradient(circle at 86% 86%, rgba(0, 0, 0, 0) 8px, #000 8px);
16342          mask-image: -o-radial-gradient(circle at 86% 86%, rgba(0, 0, 0, 0) 8px, #000 8px);
16343          -webkit-mask-image: radial-gradient(circle at 86% 86%, rgba(0, 0, 0, 0) 8px, #000 8px);
16344          mask-image: radial-gradient(circle at 86% 86%, rgba(0, 0, 0, 0) 8px, #000 8px);
16345        }
16346
16347        .cover {
16348          background: radial-gradient(ellipse cover at center, white, black);
16349        }
16350
16351        .contain {
16352          background: radial-gradient(contain at center, white, black);
16353        }
16354
16355        .no-div {
16356          background: -webkit-gradient(linear, 0 0, 0 100%, from(#000));
16357          background: -webkit-linear-gradient(top, #000);
16358          background: -o-linear-gradient(top, #000);
16359          background: linear-gradient(#000);
16360        }
16361
16362        .background-shorthand {
16363          background: #f0f -webkit-radial-gradient(#fff, rgba(0, 0, 0, 0)) 0 0 / cover no-repeat;
16364          background: #f0f -o-radial-gradient(#fff, rgba(0, 0, 0, 0)) 0 0 / cover no-repeat;
16365          background: #f0f radial-gradient(#fff, rgba(0, 0, 0, 0)) 0 0 / cover no-repeat;
16366        }
16367
16368        .background-advanced {
16369          background: url("path/to/image.jpg") 50% / cover;
16370          background: -webkit-radial-gradient(at 5px 15px, rgba(214, 168, 18, .7) 0%, rgba(255, 21, 177, .7) 50%, rgba(210, 7, 148, .7) 95%), -webkit-radial-gradient(#fff, rgba(0, 0, 0, 0)), url("path/to/image.jpg") 50% / cover;
16371          background: -o-radial-gradient(at 5px 15px, rgba(214, 168, 18, .7) 0%, rgba(255, 21, 177, .7) 50%, rgba(210, 7, 148, .7) 95%), -o-radial-gradient(#fff, rgba(0, 0, 0, 0)), url("path/to/image.jpg") 50% / cover;
16372          background: radial-gradient(at 5px 15px, rgba(214, 168, 18, .7) 0%, rgba(255, 21, 177, .7) 50%, rgba(210, 7, 148, .7) 95%), radial-gradient(#fff, rgba(0, 0, 0, 0)), url("path/to/image.jpg") 50% / cover;
16373        }
16374
16375        .multiradial {
16376          -webkit-mask-image: -webkit-radial-gradient(circle closest-corner at 100%, #000, rgba(0, 0, 0, 0));
16377          -webkit-mask-image: -o-radial-gradient(circle closest-corner at 100%, #000, rgba(0, 0, 0, 0));
16378          mask-image: -o-radial-gradient(circle closest-corner at 100%, #000, rgba(0, 0, 0, 0));
16379          -webkit-mask-image: radial-gradient(circle closest-corner at 100%, #000, rgba(0, 0, 0, 0));
16380          mask-image: radial-gradient(circle closest-corner at 100%, #000, rgba(0, 0, 0, 0));
16381        }
16382
16383        .broken {
16384          -webkit-mask-image: -webkit-radial-gradient(#fff, #000);
16385          -webkit-mask-image: -o-radial-gradient(#fff, #000);
16386          mask-image: -o-radial-gradient(#fff, #000);
16387          -webkit-mask-image: radial-gradient(#fff, #000);
16388          mask-image: radial-gradient(#fff, #000);
16389        }
16390
16391        .loop {
16392          background-image: url("https://test.com/lol(test.png");
16393          background-image: url("https://test.com/lol(test.png"), -webkit-radial-gradient(#ff0, #000, #ff0);
16394          background-image: url("https://test.com/lol(test.png"), -o-radial-gradient(#ff0, #000, #ff0);
16395          background-image: url("https://test.com/lol(test.png"), radial-gradient(#ff0, #000, #ff0);
16396        }
16397
16398        .unitless-zero {
16399          background-image: -webkit-gradient(linear, 0 100%, 0 0, from(green), to(#00f));
16400          background-image: -webkit-linear-gradient(90deg, green, #00f);
16401          background-image: -o-linear-gradient(90deg, green, #00f);
16402          background-image: linear-gradient(0deg, green, #00f);
16403          background: repeating-linear-gradient(0deg, #00f, red 33.3%);
16404        }
16405
16406        .zero-grad {
16407          background: -webkit-gradient(linear, 0 100%, 0 0, from(green), to(#00f));
16408          background: -webkit-linear-gradient(90deg, green, #00f);
16409          background: -o-linear-gradient(90deg, green, #00f);
16410          background: linear-gradient(0grad, green, #00f);
16411          background-image: repeating-linear-gradient(0grad, #00f, red 33.3%);
16412        }
16413
16414        .zero-rad, .zero-turn {
16415          background: -webkit-gradient(linear, 0 100%, 0 0, from(green), to(#00f));
16416          background: -webkit-linear-gradient(90deg, green, #00f);
16417          background: -o-linear-gradient(90deg, green, #00f);
16418          background: linear-gradient(0deg, green, #00f);
16419        }
16420      "#},
16421      Browsers {
16422        chrome: Some(25 << 16),
16423        opera: Some(12 << 16),
16424        android: Some(2 << 16 | 3 << 8),
16425        ..Browsers::default()
16426      },
16427    );
16428  }
16429
16430  #[test]
16431  fn test_font_face() {
16432    minify_test(
16433      r#"@font-face {
16434      src: url("test.woff");
16435      font-family: "Helvetica";
16436      font-weight: bold;
16437      font-style: italic;
16438    }"#,
16439      "@font-face{src:url(test.woff);font-family:Helvetica;font-weight:700;font-style:italic}",
16440    );
16441    minify_test("@font-face {src: url(test.woff);}", "@font-face{src:url(test.woff)}");
16442    minify_test("@font-face {src: local(\"Test\");}", "@font-face{src:local(Test)}");
16443    minify_test(
16444      "@font-face {src: local(\"Foo Bar\");}",
16445      "@font-face{src:local(Foo Bar)}",
16446    );
16447    minify_test("@font-face {src: local(Test);}", "@font-face{src:local(Test)}");
16448    minify_test("@font-face {src: local(Foo Bar);}", "@font-face{src:local(Foo Bar)}");
16449
16450    minify_test(
16451      "@font-face {src: url(\"test.woff\") format(woff);}",
16452      "@font-face{src:url(test.woff)format(\"woff\")}",
16453    );
16454    minify_test(
16455      "@font-face {src: url(\"test.ttc\") format(collection), url(test.ttf) format(truetype);}",
16456      "@font-face{src:url(test.ttc)format(\"collection\"),url(test.ttf)format(\"truetype\")}",
16457    );
16458    minify_test(
16459      "@font-face {src: url(\"test.otf\") format(opentype) tech(features-aat);}",
16460      "@font-face{src:url(test.otf)format(\"opentype\")tech(features-aat)}",
16461    );
16462    minify_test(
16463      "@font-face {src: url(\"test.woff\") format(woff) tech(color-colrv1);}",
16464      "@font-face{src:url(test.woff)format(\"woff\")tech(color-colrv1)}",
16465    );
16466    minify_test(
16467      "@font-face {src: url(\"test.woff2\") format(woff2) tech(variations);}",
16468      "@font-face{src:url(test.woff2)format(\"woff2\")tech(variations)}",
16469    );
16470    minify_test(
16471      "@font-face {src: url(\"test.woff\") format(woff) tech(palettes);}",
16472      "@font-face{src:url(test.woff)format(\"woff\")tech(palettes)}",
16473    );
16474    // multiple tech
16475    minify_test(
16476      "@font-face {src: url(\"test.woff\") format(woff) tech(features-opentype, color-sbix);}",
16477      "@font-face{src:url(test.woff)format(\"woff\")tech(features-opentype,color-sbix)}",
16478    );
16479    minify_test(
16480      "@font-face {src: url(\"test.woff\")   format(woff)    tech(incremental, color-svg, features-graphite, features-aat);}",
16481      "@font-face{src:url(test.woff)format(\"woff\")tech(incremental,color-svg,features-graphite,features-aat)}",
16482    );
16483    // format() function must precede tech() if both are present
16484    minify_test(
16485      "@font-face {src: url(\"foo.ttf\") format(opentype) tech(color-colrv1);}",
16486      "@font-face{src:url(foo.ttf)format(\"opentype\")tech(color-colrv1)}",
16487    );
16488    // only have tech is valid
16489    minify_test(
16490      "@font-face {src: url(\"foo.ttf\") tech(color-SVG);}",
16491      "@font-face{src:url(foo.ttf)tech(color-svg)}",
16492    );
16493    // CGQAQ: if tech and format both presence, order is matter, tech before format is invalid
16494    // but now just return raw token, we don't have strict mode yet.
16495    // ref: https://github.com/parcel-bundler/lightningcss/pull/255#issuecomment-1219049998
16496    minify_test(
16497      "@font-face {src: url(\"foo.ttf\") tech(palettes  color-colrv0  variations) format(opentype);}",
16498      "@font-face{src:url(foo.ttf) tech(palettes color-colrv0 variations) format(opentype)}",
16499    );
16500    // TODO(CGQAQ): make this test pass when we have strict mode
16501    // ref: https://github.com/web-platform-tests/wpt/blob/9f8a6ccc41aa725e8f51f4f096f686313bb88d8d/css/css-fonts/parsing/font-face-src-tech.html#L45
16502    // error_test(
16503    //   "@font-face {src: url(\"foo.ttf\") tech(features-opentype) format(opentype);}",
16504    //   ParserError::AtRuleBodyInvalid,
16505    // );
16506    // error_test(
16507    //   "@font-face {src: url(\"foo.ttf\") tech();}",
16508    //   ParserError::AtRuleBodyInvalid,
16509    // );
16510    // error_test(
16511    //   "@font-face {src: url(\"foo.ttf\") tech(\"features-opentype\");}",
16512    //   ParserError::AtRuleBodyInvalid,
16513    // );
16514    // error_test(
16515    //   "@font-face {src: url(\"foo.ttf\") tech(\"color-colrv0\");}",
16516    //   ParserError::AtRuleBodyInvalid,
16517    // );
16518    minify_test(
16519      "@font-face {src: local(\"\") url(\"test.woff\");}",
16520      "@font-face{src:local(\"\") url(test.woff)}",
16521    );
16522    minify_test("@font-face {font-weight: 200 400}", "@font-face{font-weight:200 400}");
16523    minify_test("@font-face {font-weight: 400 400}", "@font-face{font-weight:400}");
16524    minify_test(
16525      "@font-face {font-stretch: 50% 200%}",
16526      "@font-face{font-stretch:50% 200%}",
16527    );
16528    minify_test("@font-face {font-stretch: 50% 50%}", "@font-face{font-stretch:50%}");
16529    minify_test("@font-face {unicode-range: U+26;}", "@font-face{unicode-range:U+26}");
16530    minify_test("@font-face {unicode-range: u+26;}", "@font-face{unicode-range:U+26}");
16531    minify_test(
16532      "@font-face {unicode-range: U+0-7F;}",
16533      "@font-face{unicode-range:U+0-7F}",
16534    );
16535    minify_test(
16536      "@font-face {unicode-range: U+0025-00FF;}",
16537      "@font-face{unicode-range:U+25-FF}",
16538    );
16539    minify_test("@font-face {unicode-range: U+4??;}", "@font-face{unicode-range:U+4??}");
16540    minify_test(
16541      "@font-face {unicode-range: U+400-4FF;}",
16542      "@font-face{unicode-range:U+4??}",
16543    );
16544    minify_test(
16545      "@font-face {unicode-range: U+0025-00FF, U+4??;}",
16546      "@font-face{unicode-range:U+25-FF,U+4??}",
16547    );
16548    minify_test(
16549      "@font-face {unicode-range: U+A5, U+4E00-9FFF, U+30??, U+FF00-FF9F;}",
16550      "@font-face{unicode-range:U+A5,U+4E00-9FFF,U+30??,U+FF00-FF9F}",
16551    );
16552    minify_test(
16553      "@font-face {unicode-range: U+????;}",
16554      "@font-face{unicode-range:U+????}",
16555    );
16556    minify_test(
16557      "@font-face {unicode-range: U+0000-FFFF;}",
16558      "@font-face{unicode-range:U+????}",
16559    );
16560    minify_test(
16561      "@font-face {unicode-range: U+10????;}",
16562      "@font-face{unicode-range:U+10????}",
16563    );
16564    minify_test(
16565      "@font-face {unicode-range: U+100000-10FFFF;}",
16566      "@font-face{unicode-range:U+10????}",
16567    );
16568    minify_test(
16569      "@font-face {unicode-range: U+1e1e?;}",
16570      "@font-face{unicode-range:U+1E1E?}",
16571    );
16572    minify_test(
16573      "@font-face {unicode-range: u+????, U+1????, U+10????;}",
16574      "@font-face{unicode-range:U+????,U+1????,U+10????}",
16575    );
16576    minify_test(r#"
16577      @font-face {
16578        font-family: Inter;
16579        font-style: oblique 0deg 10deg;
16580        font-weight: 100 900;
16581        src: url("../fonts/Inter.var.woff2?v=3.19") format("woff2");
16582        font-display: swap;
16583      }
16584    "#, "@font-face{font-family:Inter;font-style:oblique 0deg 10deg;font-weight:100 900;src:url(../fonts/Inter.var.woff2?v=3.19)format(\"woff2\");font-display:swap}");
16585    minify_test(r#"
16586    @font-face {
16587      font-family: Inter;
16588      font-style: oblique 14deg 14deg;
16589      font-weight: 100 900;
16590      src: url("../fonts/Inter.var.woff2?v=3.19") format("woff2");
16591      font-display: swap;
16592    }
16593  "#, "@font-face{font-family:Inter;font-style:oblique;font-weight:100 900;src:url(../fonts/Inter.var.woff2?v=3.19)format(\"woff2\");font-display:swap}");
16594  }
16595
16596  #[test]
16597  fn test_font_palette_values() {
16598    minify_test(
16599      r#"@font-palette-values --Cooler {
16600      font-family: Bixa;
16601      base-palette: 1;
16602      override-colors: 1 #7EB7E4;
16603    }"#,
16604      "@font-palette-values --Cooler{font-family:Bixa;base-palette:1;override-colors:1 #7eb7e4}",
16605    );
16606    minify_test(
16607      r#"@font-palette-values --Cooler {
16608      font-family: Handover Sans;
16609      base-palette: 3;
16610      override-colors: 1 rgb(43, 12, 9), 3 lime;
16611    }"#,
16612      "@font-palette-values --Cooler{font-family:Handover Sans;base-palette:3;override-colors:1 #2b0c09,3 #0f0}",
16613    );
16614    minify_test(r#"@font-palette-values --Cooler {
16615      font-family: Handover Sans;
16616      base-palette: 3;
16617      override-colors: 1 rgb(43, 12, 9), 3 var(--highlight);
16618    }"#, "@font-palette-values --Cooler{font-family:Handover Sans;base-palette:3;override-colors:1 #2b0c09, 3 var(--highlight)}");
16619    prefix_test(
16620      r#"@font-palette-values --Cooler {
16621      font-family: Handover Sans;
16622      base-palette: 3;
16623      override-colors: 1 rgb(43, 12, 9), 3 lch(50.998% 135.363 338);
16624    }"#,
16625      indoc! {r#"@font-palette-values --Cooler {
16626      font-family: Handover Sans;
16627      base-palette: 3;
16628      override-colors: 1 #2b0c09, 3 #f000c0;
16629      override-colors: 1 #2b0c09, 3 lch(50.998% 135.363 338);
16630    }
16631    "#},
16632      Browsers {
16633        chrome: Some(90 << 16),
16634        ..Browsers::default()
16635      },
16636    );
16637    prefix_test(
16638      r#"@font-palette-values --Cooler {
16639      font-family: Handover Sans;
16640      base-palette: 3;
16641      override-colors: 1 var(--foo), 3 lch(50.998% 135.363 338);
16642    }"#,
16643      indoc! {r#"@font-palette-values --Cooler {
16644      font-family: Handover Sans;
16645      base-palette: 3;
16646      override-colors: 1 var(--foo), 3 #f000c0;
16647    }
16648
16649    @supports (color: lab(0% 0 0)) {
16650      @font-palette-values --Cooler {
16651        font-family: Handover Sans;
16652        base-palette: 3;
16653        override-colors: 1 var(--foo), 3 lab(50.998% 125.506 -50.7078);
16654      }
16655    }
16656    "#},
16657      Browsers {
16658        chrome: Some(90 << 16),
16659        ..Browsers::default()
16660      },
16661    );
16662    prefix_test(
16663      r#"@supports (color: lab(0% 0 0)) {
16664      @font-palette-values --Cooler {
16665        font-family: Handover Sans;
16666        base-palette: 3;
16667        override-colors: 1 var(--foo), 3 lab(50.998% 125.506 -50.7078);
16668      }
16669    }"#,
16670      indoc! {r#"@supports (color: lab(0% 0 0)) {
16671      @font-palette-values --Cooler {
16672        font-family: Handover Sans;
16673        base-palette: 3;
16674        override-colors: 1 var(--foo), 3 lab(50.998% 125.506 -50.7078);
16675      }
16676    }
16677    "#},
16678      Browsers {
16679        chrome: Some(90 << 16),
16680        ..Browsers::default()
16681      },
16682    );
16683    minify_test(".foo { font-palette: --Custom; }", ".foo{font-palette:--Custom}");
16684  }
16685
16686  #[test]
16687  fn test_position_try() {
16688    minify_test(
16689      r#"@position-try --outside-right-to-bottom {
16690        left: anchor(left);
16691        margin: 0;
16692        width: auto;
16693      }"#,
16694      "@position-try --outside-right-to-bottom{left:anchor(left);margin:0;width:auto}",
16695    );
16696    test(
16697      r#"@position-try --foo {
16698  top: anchor(bottom);
16699  left: anchor(right);
16700}"#,
16701      indoc! {r#"
16702        @position-try --foo {
16703          top: anchor(bottom);
16704          left: anchor(right);
16705        }
16706      "#},
16707    );
16708    // Nested inside @supports
16709    minify_test(
16710      r#"@supports (anchor-name: --foo) {
16711        @position-try --bar {
16712          top: anchor(bottom);
16713        }
16714      }"#,
16715      "@supports (anchor-name:--foo){@position-try --bar{top:anchor(bottom)}}",
16716    );
16717  }
16718
16719  #[test]
16720  fn test_font_feature_values() {
16721    // https://github.com/clagnut/TODS/blob/e693d52ad411507b960cf01a9734265e3efab102/tods.css#L116-L142
16722    minify_test(
16723      r#"
16724@font-feature-values "Fancy Font Name" {
16725  @styleset { cursive: 1; swoopy: 7 16; }
16726  @character-variant { ampersand: 1; capital-q: 2; }
16727  @stylistic { two-story-g: 1; straight-y: 2; }
16728  @swash { swishy: 1; flowing: 2; }
16729  @ornaments { clover: 1; fleuron: 2; }
16730  @annotation { circled: 1; boxed: 2; }
16731}
16732    "#,
16733      r#"@font-feature-values Fancy Font Name{@styleset{cursive:1;swoopy:7 16}@character-variant{ampersand:1;capital-q:2}@stylistic{two-story-g:1;straight-y:2}@swash{swishy:1;flowing:2}@ornaments{clover:1;fleuron:2}@annotation{circled:1;boxed:2}}"#,
16734    );
16735
16736    // https://github.com/Sorixelle/srxl.me/blob/4eb4f4a15cb2d21356df24c096d6a819cfdc1a99/public/fonts/inter/inter.css#L201-L222
16737    minify_test(
16738      r#"
16739@font-feature-values "Inter", "Inter var", "Inter var experimental" {
16740  @styleset {
16741    open-digits: 1;
16742    disambiguation: 2;
16743    curved-r: 3;
16744    disambiguation-without-zero: 4;
16745  }
16746
16747  @character-variant {
16748    alt-one: 1;
16749    open-four: 2;
16750    open-six: 3;
16751    open-nine: 4;
16752    lower-l-with-tail: 5;
16753    curved-lower-r: 6;
16754    german-double-s: 7;
16755    upper-i-with-serif: 8;
16756    flat-top-three: 9;
16757    upper-g-with-spur: 10;
16758    single-storey-a: 11;
16759  }
16760}
16761      "#,
16762      r#"@font-feature-values Inter,Inter var,Inter var experimental{@styleset{open-digits:1;disambiguation:2;curved-r:3;disambiguation-without-zero:4}@character-variant{alt-one:1;open-four:2;open-six:3;open-nine:4;lower-l-with-tail:5;curved-lower-r:6;german-double-s:7;upper-i-with-serif:8;flat-top-three:9;upper-g-with-spur:10;single-storey-a:11}}"#,
16763    );
16764
16765    // https://github.com/MihailJP/Inconsolata-LGC/blob/7c53cf455787096c93d82d9a51018f12ec39a6e9/Inconsolata-LGC.css#L65-L91
16766    minify_test(
16767      r#"
16768@font-feature-values "Inconsolata LGC" {
16769	@styleset {
16770		alternative-umlaut: 1;
16771	}
16772	@character-variant {
16773		zero-plain: 1 1;
16774		zero-dotted: 1 2;
16775		zero-longslash: 1 3;
16776		r-with-serif: 2 1;
16777		eng-descender: 3 1;
16778		eng-uppercase: 3 2;
16779		dollar-open: 4 1;
16780		dollar-oldstyle: 4 2;
16781		dollar-cifrao: 4 2;
16782		ezh-no-descender: 5 1;
16783		ezh-reversed-sigma: 5 2;
16784		triangle-text-form: 6 1;
16785		el-with-hook-old: 7 1;
16786		qa-enlarged-lowercase: 8 1;
16787		qa-reversed-p: 8 2;
16788		che-with-hook: 9 1;
16789		che-with-hook-alt: 9 2;
16790		ge-with-hook: 10 1;
16791		ge-with-hook-alt: 10 2;
16792		ge-with-stroke-and-descender: 11 1;
16793	}
16794}
16795    "#,
16796      r#"@font-feature-values Inconsolata LGC{@styleset{alternative-umlaut:1}@character-variant{zero-plain:1 1;zero-dotted:1 2;zero-longslash:1 3;r-with-serif:2 1;eng-descender:3 1;eng-uppercase:3 2;dollar-open:4 1;dollar-oldstyle:4 2;dollar-cifrao:4 2;ezh-no-descender:5 1;ezh-reversed-sigma:5 2;triangle-text-form:6 1;el-with-hook-old:7 1;qa-enlarged-lowercase:8 1;qa-reversed-p:8 2;che-with-hook:9 1;che-with-hook-alt:9 2;ge-with-hook:10 1;ge-with-hook-alt:10 2;ge-with-stroke-and-descender:11 1}}"#,
16797    );
16798
16799    minify_test(
16800      r#"
16801      @font-feature-values "Fancy Font Name" {
16802        @styleset { cursive: 1; swoopy: 7 16; }
16803        @character-variant { ampersand: 1; capital-q: 2; }
16804      }
16805      "#,
16806      r#"@font-feature-values Fancy Font Name{@styleset{cursive:1;swoopy:7 16}@character-variant{ampersand:1;capital-q:2}}"#,
16807    );
16808    minify_test(
16809      r#"
16810      @font-feature-values foo {
16811          @swash { pretty: 0; pretty: 1; cool: 2; }
16812      }
16813      "#,
16814      "@font-feature-values foo{@swash{pretty:1;cool:2}}",
16815    );
16816    minify_test(
16817      r#"
16818      @font-feature-values foo {
16819          @swash { pretty: 1; }
16820          @swash { cool: 2; }
16821      }
16822      "#,
16823      "@font-feature-values foo{@swash{pretty:1;cool:2}}",
16824    );
16825    minify_test(
16826      r#"
16827      @font-feature-values foo {
16828          @swash { pretty: 1; }
16829      }
16830      @font-feature-values foo {
16831          @swash { cool: 2; }
16832      }
16833      "#,
16834      "@font-feature-values foo{@swash{pretty:1;cool:2}}",
16835    );
16836  }
16837
16838  #[test]
16839  fn test_page_rule() {
16840    minify_test("@page {margin: 0.5cm}", "@page{margin:.5cm}");
16841    minify_test("@page :left {margin: 0.5cm}", "@page:left{margin:.5cm}");
16842    minify_test("@page :right {margin: 0.5cm}", "@page:right{margin:.5cm}");
16843    minify_test(
16844      "@page LandscapeTable {margin: 0.5cm}",
16845      "@page LandscapeTable{margin:.5cm}",
16846    );
16847    minify_test(
16848      "@page CompanyLetterHead:first {margin: 0.5cm}",
16849      "@page CompanyLetterHead:first{margin:.5cm}",
16850    );
16851    minify_test("@page:first {margin: 0.5cm}", "@page:first{margin:.5cm}");
16852    minify_test("@page :blank:first {margin: 0.5cm}", "@page:blank:first{margin:.5cm}");
16853    minify_test("@page toc, index {margin: 0.5cm}", "@page toc,index{margin:.5cm}");
16854    minify_test(
16855      r#"
16856    @page :right {
16857      @bottom-left {
16858        margin: 10pt;
16859      }
16860    }
16861    "#,
16862      "@page:right{@bottom-left{margin:10pt}}",
16863    );
16864    minify_test(
16865      r#"
16866    @page :right {
16867      margin: 1in;
16868
16869      @bottom-left {
16870        margin: 10pt;
16871      }
16872    }
16873    "#,
16874      "@page:right{margin:1in;@bottom-left{margin:10pt}}",
16875    );
16876
16877    test(
16878      r#"
16879    @page :right {
16880      @bottom-left {
16881        margin: 10pt;
16882      }
16883    }
16884    "#,
16885      indoc! {r#"
16886      @page :right {
16887        @bottom-left {
16888          margin: 10pt;
16889        }
16890      }
16891      "#},
16892    );
16893
16894    test(
16895      r#"
16896    @page :right {
16897      margin: 1in;
16898
16899      @bottom-left-corner { content: "Foo"; }
16900      @bottom-right-corner { content: "Bar"; }
16901    }
16902    "#,
16903      indoc! {r#"
16904      @page :right {
16905        margin: 1in;
16906
16907        @bottom-left-corner {
16908          content: "Foo";
16909        }
16910
16911        @bottom-right-corner {
16912          content: "Bar";
16913        }
16914      }
16915      "#},
16916    );
16917
16918    error_test(
16919      r#"
16920      @page {
16921        @foo {
16922          margin: 1in;
16923        }
16924      }
16925      "#,
16926      ParserError::AtRuleInvalid("foo".into()),
16927    );
16928
16929    error_test(
16930      r#"
16931      @page {
16932        @top-left-corner {
16933          @bottom-left {
16934            margin: 1in;
16935          }
16936        }
16937      }
16938      "#,
16939      ParserError::AtRuleInvalid("bottom-left".into()),
16940    );
16941  }
16942
16943  #[test]
16944  fn test_supports_rule() {
16945    test(
16946      r#"
16947      @supports (foo: bar) {
16948        .test {
16949          foo: bar;
16950        }
16951      }
16952    "#,
16953      indoc! { r#"
16954      @supports (foo: bar) {
16955        .test {
16956          foo: bar;
16957        }
16958      }
16959    "#},
16960    );
16961    test(
16962      r#"
16963      @supports not (foo: bar) {
16964        .test {
16965          foo: bar;
16966        }
16967      }
16968    "#,
16969      indoc! { r#"
16970      @supports not (foo: bar) {
16971        .test {
16972          foo: bar;
16973        }
16974      }
16975    "#},
16976    );
16977    test(
16978      r#"
16979      @supports (foo: bar) or (bar: baz) {
16980        .test {
16981          foo: bar;
16982        }
16983      }
16984    "#,
16985      indoc! { r#"
16986      @supports (foo: bar) or (bar: baz) {
16987        .test {
16988          foo: bar;
16989        }
16990      }
16991    "#},
16992    );
16993    test(
16994      r#"
16995      @supports (((foo: bar) or (bar: baz))) {
16996        .test {
16997          foo: bar;
16998        }
16999      }
17000    "#,
17001      indoc! { r#"
17002      @supports (foo: bar) or (bar: baz) {
17003        .test {
17004          foo: bar;
17005        }
17006      }
17007    "#},
17008    );
17009    test(
17010      r#"
17011      @supports (foo: bar) and (bar: baz) {
17012        .test {
17013          foo: bar;
17014        }
17015      }
17016    "#,
17017      indoc! { r#"
17018      @supports (foo: bar) and (bar: baz) {
17019        .test {
17020          foo: bar;
17021        }
17022      }
17023    "#},
17024    );
17025    test(
17026      r#"
17027      @supports (((foo: bar) and (bar: baz))) {
17028        .test {
17029          foo: bar;
17030        }
17031      }
17032    "#,
17033      indoc! { r#"
17034      @supports (foo: bar) and (bar: baz) {
17035        .test {
17036          foo: bar;
17037        }
17038      }
17039    "#},
17040    );
17041    test(
17042      r#"
17043      @supports (foo: bar) and (((bar: baz) or (test: foo))) {
17044        .test {
17045          foo: bar;
17046        }
17047      }
17048    "#,
17049      indoc! { r#"
17050      @supports (foo: bar) and ((bar: baz) or (test: foo)) {
17051        .test {
17052          foo: bar;
17053        }
17054      }
17055    "#},
17056    );
17057    test(
17058      r#"
17059      @supports not (((foo: bar) and (bar: baz))) {
17060        .test {
17061          foo: bar;
17062        }
17063      }
17064    "#,
17065      indoc! { r#"
17066      @supports not ((foo: bar) and (bar: baz)) {
17067        .test {
17068          foo: bar;
17069        }
17070      }
17071    "#},
17072    );
17073    test(
17074      r#"
17075      @supports selector(a > b) {
17076        .test {
17077          foo: bar;
17078        }
17079      }
17080    "#,
17081      indoc! { r#"
17082      @supports selector(a > b) {
17083        .test {
17084          foo: bar;
17085        }
17086      }
17087    "#},
17088    );
17089    test(
17090      r#"
17091      @supports unknown(test) {
17092        .test {
17093          foo: bar;
17094        }
17095      }
17096    "#,
17097      indoc! { r#"
17098      @supports unknown(test) {
17099        .test {
17100          foo: bar;
17101        }
17102      }
17103    "#},
17104    );
17105    test(
17106      r#"
17107      @supports (unknown) {
17108        .test {
17109          foo: bar;
17110        }
17111      }
17112    "#,
17113      indoc! { r#"
17114      @supports (unknown) {
17115        .test {
17116          foo: bar;
17117        }
17118      }
17119    "#},
17120    );
17121    test(
17122      r#"
17123      @supports (display: grid) and (not (display: inline-grid)) {
17124        .test {
17125          foo: bar;
17126        }
17127      }
17128    "#,
17129      indoc! { r#"
17130      @supports (display: grid) and (not (display: inline-grid)) {
17131        .test {
17132          foo: bar;
17133        }
17134      }
17135    "#},
17136    );
17137    prefix_test(
17138      r#"
17139      @supports (backdrop-filter: blur(10px)) {
17140        div {
17141          backdrop-filter: blur(10px);
17142        }
17143      }
17144    "#,
17145      indoc! { r#"
17146      @supports ((-webkit-backdrop-filter: blur(10px)) or (backdrop-filter: blur(10px))) {
17147        div {
17148          -webkit-backdrop-filter: blur(10px);
17149          backdrop-filter: blur(10px);
17150        }
17151      }
17152    "#},
17153      Browsers {
17154        safari: Some(14 << 16),
17155        ..Default::default()
17156      },
17157    );
17158    prefix_test(
17159      r#"
17160      @supports ((-webkit-backdrop-filter: blur(10px)) or (backdrop-filter: blur(10px))) {
17161        div {
17162          backdrop-filter: blur(10px);
17163        }
17164      }
17165    "#,
17166      indoc! { r#"
17167      @supports ((-webkit-backdrop-filter: blur(10px)) or (backdrop-filter: blur(10px))) {
17168        div {
17169          -webkit-backdrop-filter: blur(10px);
17170          backdrop-filter: blur(10px);
17171        }
17172      }
17173    "#},
17174      Browsers {
17175        safari: Some(14 << 16),
17176        ..Default::default()
17177      },
17178    );
17179    prefix_test(
17180      r#"
17181      @supports ((-webkit-backdrop-filter: blur(20px)) or (backdrop-filter: blur(10px))) {
17182        div {
17183          backdrop-filter: blur(10px);
17184        }
17185      }
17186    "#,
17187      indoc! { r#"
17188      @supports ((-webkit-backdrop-filter: blur(20px))) or ((-webkit-backdrop-filter: blur(10px)) or (backdrop-filter: blur(10px))) {
17189        div {
17190          -webkit-backdrop-filter: blur(10px);
17191          backdrop-filter: blur(10px);
17192        }
17193      }
17194    "#},
17195      Browsers {
17196        safari: Some(14 << 16),
17197        ..Default::default()
17198      },
17199    );
17200    prefix_test(
17201      r#"
17202      @supports ((-webkit-backdrop-filter: blur(10px)) or (backdrop-filter: blur(10px))) {
17203        div {
17204          backdrop-filter: blur(10px);
17205        }
17206      }
17207    "#,
17208      indoc! { r#"
17209      @supports (backdrop-filter: blur(10px)) {
17210        div {
17211          backdrop-filter: blur(10px);
17212        }
17213      }
17214    "#},
17215      Browsers {
17216        chrome: Some(80 << 16),
17217        ..Default::default()
17218      },
17219    );
17220    minify_test(
17221      r#"
17222      @supports (width: calc(10px * 2)) {
17223        .test {
17224          width: calc(10px * 2);
17225        }
17226      }
17227    "#,
17228      "@supports (width:calc(10px * 2)){.test{width:20px}}",
17229    );
17230    minify_test(
17231      r#"
17232      @supports (color: hsl(0deg, 0%, 0%)) {
17233        .test {
17234          color: hsl(0deg, 0%, 0%);
17235        }
17236      }
17237    "#,
17238      "@supports (color:hsl(0deg, 0%, 0%)){.test{color:#000}}",
17239    );
17240  }
17241
17242  #[test]
17243  fn test_counter_style() {
17244    test(
17245      r#"
17246      @counter-style circled-alpha {
17247        system: fixed;
17248        symbols: Ⓐ Ⓑ Ⓒ;
17249        suffix: " ";
17250      }
17251    "#,
17252      indoc! { r#"
17253      @counter-style circled-alpha {
17254        system: fixed;
17255        symbols: Ⓐ Ⓑ Ⓒ;
17256        suffix: " ";
17257      }
17258    "#},
17259    );
17260  }
17261
17262  #[test]
17263  fn test_namespace() {
17264    minify_test(
17265      "@namespace url(http://toto.example.org);",
17266      "@namespace \"http://toto.example.org\";",
17267    );
17268    minify_test(
17269      "@namespace \"http://toto.example.org\";",
17270      "@namespace \"http://toto.example.org\";",
17271    );
17272    minify_test(
17273      "@namespace toto \"http://toto.example.org\";",
17274      "@namespace toto \"http://toto.example.org\";",
17275    );
17276    minify_test(
17277      "@namespace toto url(http://toto.example.org);",
17278      "@namespace toto \"http://toto.example.org\";",
17279    );
17280
17281    test(
17282      r#"
17283      @namespace "http://example.com/foo";
17284
17285      x {
17286        color: red;
17287      }
17288    "#,
17289      indoc! {r#"
17290      @namespace "http://example.com/foo";
17291
17292      x {
17293        color: red;
17294      }
17295    "#},
17296    );
17297
17298    test(
17299      r#"
17300      @namespace toto "http://toto.example.org";
17301
17302      toto|x {
17303        color: red;
17304      }
17305
17306      [toto|att=val] {
17307        color: blue
17308      }
17309    "#,
17310      indoc! {r#"
17311      @namespace toto "http://toto.example.org";
17312
17313      toto|x {
17314        color: red;
17315      }
17316
17317      [toto|att="val"] {
17318        color: #00f;
17319      }
17320    "#},
17321    );
17322
17323    test(
17324      r#"
17325      @namespace "http://example.com/foo";
17326
17327      |x {
17328        color: red;
17329      }
17330
17331      [|att=val] {
17332        color: blue
17333      }
17334    "#,
17335      indoc! {r#"
17336      @namespace "http://example.com/foo";
17337
17338      |x {
17339        color: red;
17340      }
17341
17342      [att="val"] {
17343        color: #00f;
17344      }
17345    "#},
17346    );
17347
17348    test(
17349      r#"
17350      @namespace "http://example.com/foo";
17351
17352      *|x {
17353        color: red;
17354      }
17355
17356      [*|att=val] {
17357        color: blue
17358      }
17359    "#,
17360      indoc! {r#"
17361      @namespace "http://example.com/foo";
17362
17363      *|x {
17364        color: red;
17365      }
17366
17367      [*|att="val"] {
17368        color: #00f;
17369      }
17370    "#},
17371    );
17372
17373    error_test(
17374      ".foo { color: red } @namespace \"http://example.com/foo\";",
17375      ParserError::UnexpectedNamespaceRule,
17376    );
17377  }
17378
17379  #[test]
17380  fn test_import() {
17381    minify_test("@import url(foo.css);", "@import \"foo.css\";");
17382    minify_test("@import \"foo.css\";", "@import \"foo.css\";");
17383    minify_test("@import url(foo.css) print;", "@import \"foo.css\" print;");
17384    minify_test("@import \"foo.css\" print;", "@import \"foo.css\" print;");
17385    minify_test(
17386      "@import \"foo.css\" screen and (orientation: landscape);",
17387      "@import \"foo.css\" screen and (orientation:landscape);",
17388    );
17389    minify_test(
17390      "@import url(foo.css) supports(display: flex);",
17391      "@import \"foo.css\" supports(display:flex);",
17392    );
17393    minify_test(
17394      "@import url(foo.css) supports(display: flex) print;",
17395      "@import \"foo.css\" supports(display:flex) print;",
17396    );
17397    minify_test(
17398      "@import url(foo.css) supports(not (display: flex));",
17399      "@import \"foo.css\" supports(not (display:flex));",
17400    );
17401    minify_test(
17402      "@import url(foo.css) supports((display: flex));",
17403      "@import \"foo.css\" supports(display:flex);",
17404    );
17405    minify_test("@charset \"UTF-8\"; @import url(foo.css);", "@import \"foo.css\";");
17406    minify_test("@layer foo; @import url(foo.css);", "@layer foo;@import \"foo.css\";");
17407    error_test(
17408      ".foo { color: red } @import url(bar.css);",
17409      ParserError::UnexpectedImportRule,
17410    );
17411    error_test(
17412      "@namespace \"http://example.com/foo\"; @import url(bar.css);",
17413      ParserError::UnexpectedImportRule,
17414    );
17415    error_test(
17416      "@media print { .foo { color: red }} @import url(bar.css);",
17417      ParserError::UnexpectedImportRule,
17418    );
17419    error_test(
17420      "@layer foo; @import url(foo.css); @layer bar; @import url(bar.css)",
17421      ParserError::UnexpectedImportRule,
17422    );
17423    let warnings = error_recovery_test("@import './actual-styles.css';");
17424    assert_eq!(warnings, vec![]);
17425  }
17426
17427  #[test]
17428  fn test_prefixes() {
17429    prefix_test(
17430      r#"
17431      .foo {
17432        -webkit-transition: opacity 200ms;
17433        -moz-transition: opacity 200ms;
17434        transition: opacity 200ms;
17435      }
17436      "#,
17437      indoc! {r#"
17438      .foo {
17439        transition: opacity .2s;
17440      }
17441      "#},
17442      Browsers {
17443        chrome: Some(95 << 16),
17444        ..Browsers::default()
17445      },
17446    );
17447
17448    prefix_test(
17449      ".foo{transition:opacity 200ms}",
17450      indoc! {r#"
17451      .foo {
17452        -webkit-transition: opacity .2s;
17453        -moz-transition: opacity .2s;
17454        transition: opacity .2s;
17455      }
17456      "#},
17457      Browsers {
17458        safari: Some(5 << 16),
17459        firefox: Some(14 << 16),
17460        ..Browsers::default()
17461      },
17462    );
17463  }
17464
17465  #[test]
17466  fn test_display() {
17467    minify_test(".foo { display: block }", ".foo{display:block}");
17468    minify_test(".foo { display: block flow }", ".foo{display:block}");
17469    minify_test(".foo { display: flow-root }", ".foo{display:flow-root}");
17470    minify_test(".foo { display: block flow-root }", ".foo{display:flow-root}");
17471    minify_test(".foo { display: inline }", ".foo{display:inline}");
17472    minify_test(".foo { display: inline flow }", ".foo{display:inline}");
17473    minify_test(".foo { display: inline-block }", ".foo{display:inline-block}");
17474    minify_test(".foo { display: inline flow-root }", ".foo{display:inline-block}");
17475    minify_test(".foo { display: run-in }", ".foo{display:run-in}");
17476    minify_test(".foo { display: run-in flow }", ".foo{display:run-in}");
17477    minify_test(".foo { display: list-item }", ".foo{display:list-item}");
17478    minify_test(".foo { display: block flow list-item }", ".foo{display:list-item}");
17479    minify_test(".foo { display: inline list-item }", ".foo{display:inline list-item}");
17480    minify_test(
17481      ".foo { display: inline flow list-item }",
17482      ".foo{display:inline list-item}",
17483    );
17484    minify_test(".foo { display: flex }", ".foo{display:flex}");
17485    minify_test(".foo { display: block flex }", ".foo{display:flex}");
17486    minify_test(".foo { display: inline-flex }", ".foo{display:inline-flex}");
17487    minify_test(".foo { display: inline flex }", ".foo{display:inline-flex}");
17488    minify_test(".foo { display: grid }", ".foo{display:grid}");
17489    minify_test(".foo { display: block grid }", ".foo{display:grid}");
17490    minify_test(".foo { display: inline-grid }", ".foo{display:inline-grid}");
17491    minify_test(".foo { display: inline grid }", ".foo{display:inline-grid}");
17492    minify_test(".foo { display: ruby }", ".foo{display:ruby}");
17493    minify_test(".foo { display: inline ruby }", ".foo{display:ruby}");
17494    minify_test(".foo { display: block ruby }", ".foo{display:block ruby}");
17495    minify_test(".foo { display: table }", ".foo{display:table}");
17496    minify_test(".foo { display: block table }", ".foo{display:table}");
17497    minify_test(".foo { display: inline-table }", ".foo{display:inline-table}");
17498    minify_test(".foo { display: inline table }", ".foo{display:inline-table}");
17499    minify_test(".foo { display: table-row-group }", ".foo{display:table-row-group}");
17500    minify_test(".foo { display: contents }", ".foo{display:contents}");
17501    minify_test(".foo { display: none }", ".foo{display:none}");
17502    minify_test(".foo { display: -webkit-flex }", ".foo{display:-webkit-flex}");
17503    minify_test(".foo { display: -ms-flexbox }", ".foo{display:-ms-flexbox}");
17504    minify_test(".foo { display: -webkit-box }", ".foo{display:-webkit-box}");
17505    minify_test(".foo { display: -moz-box }", ".foo{display:-moz-box}");
17506    minify_test(
17507      ".foo { display: -webkit-flex; display: -moz-box; display: flex }",
17508      ".foo{display:-webkit-flex;display:-moz-box;display:flex}",
17509    );
17510    minify_test(
17511      ".foo { display: -webkit-flex; display: flex; display: -moz-box }",
17512      ".foo{display:-webkit-flex;display:flex;display:-moz-box}",
17513    );
17514    minify_test(".foo { display: flex; display: grid }", ".foo{display:grid}");
17515    minify_test(
17516      ".foo { display: -webkit-inline-flex; display: -moz-inline-box; display: inline-flex }",
17517      ".foo{display:-webkit-inline-flex;display:-moz-inline-box;display:inline-flex}",
17518    );
17519    minify_test(
17520      ".foo { display: flex; display: var(--grid); }",
17521      ".foo{display:flex;display:var(--grid)}",
17522    );
17523    prefix_test(
17524      ".foo{ display: flex }",
17525      indoc! {r#"
17526      .foo {
17527        display: -webkit-box;
17528        display: -moz-box;
17529        display: -webkit-flex;
17530        display: -ms-flexbox;
17531        display: flex;
17532      }
17533      "#},
17534      Browsers {
17535        safari: Some(4 << 16),
17536        firefox: Some(14 << 16),
17537        ie: Some(10 << 16),
17538        ..Browsers::default()
17539      },
17540    );
17541    prefix_test(
17542      ".foo{ display: flex; display: -webkit-box; }",
17543      indoc! {r#"
17544      .foo {
17545        display: -webkit-box;
17546      }
17547      "#},
17548      Browsers {
17549        safari: Some(4 << 16),
17550        firefox: Some(14 << 16),
17551        ie: Some(10 << 16),
17552        ..Browsers::default()
17553      },
17554    );
17555    prefix_test(
17556      ".foo{ display: -webkit-box; display: flex; }",
17557      indoc! {r#"
17558      .foo {
17559        display: -webkit-box;
17560        display: -moz-box;
17561        display: -webkit-flex;
17562        display: -ms-flexbox;
17563        display: flex;
17564      }
17565      "#},
17566      Browsers {
17567        safari: Some(4 << 16),
17568        firefox: Some(14 << 16),
17569        ie: Some(10 << 16),
17570        ..Browsers::default()
17571      },
17572    );
17573    prefix_test(
17574      r#"
17575      .foo {
17576        display: -webkit-box;
17577        display: -moz-box;
17578        display: -webkit-flex;
17579        display: -ms-flexbox;
17580        display: flex;
17581      }
17582      "#,
17583      indoc! {r#"
17584      .foo {
17585        display: flex;
17586      }
17587      "#},
17588      Browsers {
17589        safari: Some(14 << 16),
17590        ..Browsers::default()
17591      },
17592    );
17593    prefix_test(
17594      r#"
17595      .foo {
17596        display: -webkit-box;
17597        display: flex;
17598        display: -moz-box;
17599        display: -webkit-flex;
17600        display: -ms-flexbox;
17601      }
17602      "#,
17603      indoc! {r#"
17604      .foo {
17605        display: -moz-box;
17606        display: -webkit-flex;
17607        display: -ms-flexbox;
17608      }
17609      "#},
17610      Browsers {
17611        safari: Some(14 << 16),
17612        ..Browsers::default()
17613      },
17614    );
17615    prefix_test(
17616      ".foo{ display: inline-flex }",
17617      indoc! {r#"
17618      .foo {
17619        display: -webkit-inline-box;
17620        display: -moz-inline-box;
17621        display: -webkit-inline-flex;
17622        display: -ms-inline-flexbox;
17623        display: inline-flex;
17624      }
17625      "#},
17626      Browsers {
17627        safari: Some(4 << 16),
17628        firefox: Some(14 << 16),
17629        ie: Some(10 << 16),
17630        ..Browsers::default()
17631      },
17632    );
17633    prefix_test(
17634      r#"
17635      .foo {
17636        display: -webkit-inline-box;
17637        display: -moz-inline-box;
17638        display: -webkit-inline-flex;
17639        display: -ms-inline-flexbox;
17640        display: inline-flex;
17641      }
17642      "#,
17643      indoc! {r#"
17644      .foo {
17645        display: inline-flex;
17646      }
17647      "#},
17648      Browsers {
17649        safari: Some(14 << 16),
17650        ..Browsers::default()
17651      },
17652    );
17653  }
17654
17655  #[test]
17656  fn test_visibility() {
17657    minify_test(".foo { visibility: visible }", ".foo{visibility:visible}");
17658    minify_test(".foo { visibility: hidden }", ".foo{visibility:hidden}");
17659    minify_test(".foo { visibility: collapse }", ".foo{visibility:collapse}");
17660    minify_test(".foo { visibility: Visible }", ".foo{visibility:visible}");
17661  }
17662
17663  #[test]
17664  fn test_text_transform() {
17665    minify_test(".foo { text-transform: uppercase }", ".foo{text-transform:uppercase}");
17666    minify_test(".foo { text-transform: lowercase }", ".foo{text-transform:lowercase}");
17667    minify_test(".foo { text-transform: capitalize }", ".foo{text-transform:capitalize}");
17668    minify_test(".foo { text-transform: none }", ".foo{text-transform:none}");
17669    minify_test(".foo { text-transform: full-width }", ".foo{text-transform:full-width}");
17670    minify_test(
17671      ".foo { text-transform: full-size-kana }",
17672      ".foo{text-transform:full-size-kana}",
17673    );
17674    minify_test(
17675      ".foo { text-transform: uppercase full-width }",
17676      ".foo{text-transform:uppercase full-width}",
17677    );
17678    minify_test(
17679      ".foo { text-transform: full-width uppercase }",
17680      ".foo{text-transform:uppercase full-width}",
17681    );
17682    minify_test(
17683      ".foo { text-transform: uppercase full-width full-size-kana }",
17684      ".foo{text-transform:uppercase full-width full-size-kana}",
17685    );
17686    minify_test(
17687      ".foo { text-transform: full-width uppercase full-size-kana }",
17688      ".foo{text-transform:uppercase full-width full-size-kana}",
17689    );
17690  }
17691
17692  #[test]
17693  fn test_whitespace() {
17694    minify_test(".foo { white-space: normal }", ".foo{white-space:normal}");
17695    minify_test(".foo { white-space: pre }", ".foo{white-space:pre}");
17696    minify_test(".foo { white-space: nowrap }", ".foo{white-space:nowrap}");
17697    minify_test(".foo { white-space: pre-wrap }", ".foo{white-space:pre-wrap}");
17698    minify_test(".foo { white-space: break-spaces }", ".foo{white-space:break-spaces}");
17699    minify_test(".foo { white-space: pre-line }", ".foo{white-space:pre-line}");
17700    minify_test(".foo { white-space: NoWrAp }", ".foo{white-space:nowrap}");
17701  }
17702
17703  #[test]
17704  fn test_tab_size() {
17705    property_range_test(
17706      &["tab-size"],
17707      &[
17708        ("-1px", None),
17709        ("calc(1px - 2px)", Some("0")),
17710        ("calc(-1px + 2px)", Some("1px")),
17711        ("-1", None),
17712        ("calc(1 - 2)", Some("0")),
17713        ("calc(-1 + 2)", Some("1")),
17714      ],
17715    );
17716    minify_test(".foo { tab-size: 8 }", ".foo{tab-size:8}");
17717    minify_test(".foo { tab-size: 4px }", ".foo{tab-size:4px}");
17718    minify_test(".foo { -moz-tab-size: 4px }", ".foo{-moz-tab-size:4px}");
17719    minify_test(".foo { -o-tab-size: 4px }", ".foo{-o-tab-size:4px}");
17720    prefix_test(
17721      ".foo{ tab-size: 4 }",
17722      indoc! {r#"
17723      .foo {
17724        -moz-tab-size: 4;
17725        -o-tab-size: 4;
17726        tab-size: 4;
17727      }
17728      "#},
17729      Browsers {
17730        safari: Some(8 << 16),
17731        firefox: Some(50 << 16),
17732        opera: Some(12 << 16),
17733        ..Browsers::default()
17734      },
17735    );
17736    prefix_test(
17737      r#"
17738      .foo {
17739        -moz-tab-size: 4;
17740        -o-tab-size: 4;
17741        tab-size: 4;
17742      }
17743      "#,
17744      indoc! {r#"
17745      .foo {
17746        tab-size: 4;
17747      }
17748      "#},
17749      Browsers {
17750        safari: Some(8 << 16),
17751        firefox: Some(94 << 16),
17752        opera: Some(30 << 16),
17753        ..Browsers::default()
17754      },
17755    );
17756  }
17757
17758  #[test]
17759  fn test_word_break() {
17760    minify_test(".foo { word-break: normal }", ".foo{word-break:normal}");
17761    minify_test(".foo { word-break: keep-all }", ".foo{word-break:keep-all}");
17762    minify_test(".foo { word-break: break-all }", ".foo{word-break:break-all}");
17763    minify_test(".foo { word-break: break-word }", ".foo{word-break:break-word}");
17764  }
17765
17766  #[test]
17767  fn test_line_break() {
17768    minify_test(".foo { line-break: auto }", ".foo{line-break:auto}");
17769    minify_test(".foo { line-break: Loose }", ".foo{line-break:loose}");
17770    minify_test(".foo { line-break: anywhere }", ".foo{line-break:anywhere}");
17771  }
17772
17773  #[test]
17774  fn test_wrap() {
17775    minify_test(".foo { overflow-wrap: nOrmal }", ".foo{overflow-wrap:normal}");
17776    minify_test(".foo { overflow-wrap: break-Word }", ".foo{overflow-wrap:break-word}");
17777    minify_test(".foo { overflow-wrap: Anywhere }", ".foo{overflow-wrap:anywhere}");
17778    minify_test(".foo { word-wrap: Normal }", ".foo{word-wrap:normal}");
17779    minify_test(".foo { word-wrap: Break-wOrd }", ".foo{word-wrap:break-word}");
17780    minify_test(".foo { word-wrap: Anywhere }", ".foo{word-wrap:anywhere}");
17781  }
17782
17783  #[test]
17784  fn test_hyphens() {
17785    minify_test(".foo { hyphens: manual }", ".foo{hyphens:manual}");
17786    minify_test(".foo { hyphens: auto }", ".foo{hyphens:auto}");
17787    minify_test(".foo { hyphens: none }", ".foo{hyphens:none}");
17788    minify_test(".foo { -webkit-hyphens: manual }", ".foo{-webkit-hyphens:manual}");
17789    minify_test(".foo { -moz-hyphens: manual }", ".foo{-moz-hyphens:manual}");
17790    minify_test(".foo { -ms-hyphens: manual }", ".foo{-ms-hyphens:manual}");
17791    prefix_test(
17792      ".foo{ hyphens: manual }",
17793      indoc! {r#"
17794      .foo {
17795        -webkit-hyphens: manual;
17796        -moz-hyphens: manual;
17797        -ms-hyphens: manual;
17798        hyphens: manual;
17799      }
17800      "#},
17801      Browsers {
17802        safari: Some(14 << 16),
17803        firefox: Some(40 << 16),
17804        ie: Some(10 << 16),
17805        ..Browsers::default()
17806      },
17807    );
17808    prefix_test(
17809      r#"
17810      .foo {
17811        -webkit-hyphens: manual;
17812        -moz-hyphens: manual;
17813        -ms-hyphens: manual;
17814        hyphens: manual;
17815      }
17816      "#,
17817      indoc! {r#"
17818      .foo {
17819        -webkit-hyphens: manual;
17820        hyphens: manual;
17821      }
17822      "#},
17823      Browsers {
17824        safari: Some(14 << 16),
17825        chrome: Some(88 << 16),
17826        firefox: Some(88 << 16),
17827        edge: Some(79 << 16),
17828        ..Browsers::default()
17829      },
17830    );
17831    prefix_test(
17832      r#"
17833      .foo {
17834        -webkit-hyphens: manual;
17835        -moz-hyphens: manual;
17836        -ms-hyphens: manual;
17837        hyphens: manual;
17838      }
17839      "#,
17840      indoc! {r#"
17841      .foo {
17842        hyphens: manual;
17843      }
17844      "#},
17845      Browsers {
17846        chrome: Some(88 << 16),
17847        firefox: Some(88 << 16),
17848        edge: Some(79 << 16),
17849        ..Browsers::default()
17850      },
17851    );
17852  }
17853
17854  #[test]
17855  fn test_text_align() {
17856    minify_test(".foo { text-align: left }", ".foo{text-align:left}");
17857    minify_test(".foo { text-align: Left }", ".foo{text-align:left}");
17858    minify_test(".foo { text-align: END }", ".foo{text-align:end}");
17859    minify_test(".foo { text-align: left }", ".foo{text-align:left}");
17860
17861    prefix_test(
17862      r#"
17863      .foo {
17864        text-align: start;
17865      }
17866    "#,
17867      indoc! {r#"
17868      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
17869        text-align: left;
17870      }
17871
17872      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
17873        text-align: right;
17874      }
17875    "#
17876      },
17877      Browsers {
17878        safari: Some(2 << 16),
17879        ..Browsers::default()
17880      },
17881    );
17882
17883    prefix_test(
17884      r#"
17885      .foo {
17886        text-align: end;
17887      }
17888    "#,
17889      indoc! {r#"
17890      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
17891        text-align: right;
17892      }
17893
17894      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
17895        text-align: left;
17896      }
17897    "#
17898      },
17899      Browsers {
17900        safari: Some(2 << 16),
17901        ..Browsers::default()
17902      },
17903    );
17904
17905    prefix_test(
17906      r#"
17907      .foo {
17908        text-align: start;
17909      }
17910    "#,
17911      indoc! {r#"
17912      .foo {
17913        text-align: start;
17914      }
17915    "#
17916      },
17917      Browsers {
17918        safari: Some(14 << 16),
17919        ..Browsers::default()
17920      },
17921    );
17922
17923    prefix_test(
17924      r#"
17925      .foo > .bar {
17926        text-align: start;
17927      }
17928    "#,
17929      indoc! {r#"
17930      .foo > .bar:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
17931        text-align: left;
17932      }
17933
17934      .foo > .bar:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
17935        text-align: right;
17936      }
17937    "#
17938      },
17939      Browsers {
17940        safari: Some(2 << 16),
17941        ..Browsers::default()
17942      },
17943    );
17944
17945    prefix_test(
17946      r#"
17947      .foo:after {
17948        text-align: start;
17949      }
17950    "#,
17951      indoc! {r#"
17952      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))):after {
17953        text-align: left;
17954      }
17955
17956      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)):after {
17957        text-align: right;
17958      }
17959    "#
17960      },
17961      Browsers {
17962        safari: Some(2 << 16),
17963        ..Browsers::default()
17964      },
17965    );
17966
17967    prefix_test(
17968      r#"
17969      .foo:hover {
17970        text-align: start;
17971      }
17972    "#,
17973      indoc! {r#"
17974      .foo:hover:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
17975        text-align: left;
17976      }
17977
17978      .foo:hover:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
17979        text-align: right;
17980      }
17981    "#
17982      },
17983      Browsers {
17984        safari: Some(2 << 16),
17985        ..Browsers::default()
17986      },
17987    );
17988  }
17989
17990  #[test]
17991  fn test_text_align_last() {
17992    minify_test(".foo { text-align-last: left }", ".foo{text-align-last:left}");
17993    minify_test(".foo { text-align-last: justify }", ".foo{text-align-last:justify}");
17994    prefix_test(
17995      ".foo{ text-align-last: left }",
17996      indoc! {r#"
17997      .foo {
17998        -moz-text-align-last: left;
17999        text-align-last: left;
18000      }
18001      "#},
18002      Browsers {
18003        firefox: Some(40 << 16),
18004        ..Browsers::default()
18005      },
18006    );
18007    prefix_test(
18008      r#"
18009      .foo {
18010        -moz-text-align-last: left;
18011        text-align-last: left;
18012      }
18013      "#,
18014      indoc! {r#"
18015      .foo {
18016        text-align-last: left;
18017      }
18018      "#},
18019      Browsers {
18020        firefox: Some(88 << 16),
18021        ..Browsers::default()
18022      },
18023    );
18024  }
18025
18026  #[test]
18027  fn test_text_justify() {
18028    minify_test(".foo { text-justify: auto }", ".foo{text-justify:auto}");
18029    minify_test(".foo { text-justify: inter-word }", ".foo{text-justify:inter-word}");
18030  }
18031
18032  #[test]
18033  fn test_word_spacing() {
18034    minify_test(".foo { word-spacing: normal }", ".foo{word-spacing:normal}");
18035    minify_test(".foo { word-spacing: 3px }", ".foo{word-spacing:3px}");
18036  }
18037
18038  #[test]
18039  fn test_letter_spacing() {
18040    minify_test(".foo { letter-spacing: normal }", ".foo{letter-spacing:normal}");
18041    minify_test(".foo { letter-spacing: 3px }", ".foo{letter-spacing:3px}");
18042  }
18043
18044  #[test]
18045  fn test_text_indent() {
18046    minify_test(".foo { text-indent: 20px }", ".foo{text-indent:20px}");
18047    minify_test(".foo { text-indent: 10% }", ".foo{text-indent:10%}");
18048    minify_test(".foo { text-indent: 3em hanging }", ".foo{text-indent:3em hanging}");
18049    minify_test(".foo { text-indent: 3em each-line }", ".foo{text-indent:3em each-line}");
18050    minify_test(
18051      ".foo { text-indent: 3em hanging each-line }",
18052      ".foo{text-indent:3em hanging each-line}",
18053    );
18054    minify_test(
18055      ".foo { text-indent: 3em each-line hanging }",
18056      ".foo{text-indent:3em hanging each-line}",
18057    );
18058    minify_test(
18059      ".foo { text-indent: each-line 3em hanging }",
18060      ".foo{text-indent:3em hanging each-line}",
18061    );
18062    minify_test(
18063      ".foo { text-indent: each-line hanging 3em }",
18064      ".foo{text-indent:3em hanging each-line}",
18065    );
18066  }
18067
18068  #[test]
18069  fn test_text_size_adjust() {
18070    property_range_test(&["text-size-adjust"], &[("-1%", None), ("calc(-1%)", Some("0%"))]);
18071    minify_test(".foo { text-size-adjust: none }", ".foo{text-size-adjust:none}");
18072    minify_test(".foo { text-size-adjust: auto }", ".foo{text-size-adjust:auto}");
18073    minify_test(".foo { text-size-adjust: 80% }", ".foo{text-size-adjust:80%}");
18074    prefix_test(
18075      r#"
18076      .foo {
18077        text-size-adjust: none;
18078      }
18079    "#,
18080      indoc! {r#"
18081      .foo {
18082        -webkit-text-size-adjust: none;
18083        -moz-text-size-adjust: none;
18084        -ms-text-size-adjust: none;
18085        text-size-adjust: none;
18086      }
18087    "#},
18088      Browsers {
18089        ios_saf: Some(16 << 16),
18090        edge: Some(15 << 16),
18091        firefox: Some(20 << 16),
18092        ..Browsers::default()
18093      },
18094    );
18095    prefix_test(
18096      r#"
18097      .foo {
18098        -webkit-text-size-adjust: none;
18099        -moz-text-size-adjust: none;
18100        -ms-text-size-adjust: none;
18101        text-size-adjust: none;
18102      }
18103    "#,
18104      indoc! {r#"
18105      .foo {
18106        text-size-adjust: none;
18107      }
18108    "#},
18109      Browsers {
18110        chrome: Some(110 << 16),
18111        ..Browsers::default()
18112      },
18113    );
18114  }
18115
18116  #[test]
18117  fn test_text_decoration() {
18118    minify_test(".foo { text-decoration-line: none }", ".foo{text-decoration-line:none}");
18119    minify_test(
18120      ".foo { text-decoration-line: underline }",
18121      ".foo{text-decoration-line:underline}",
18122    );
18123    minify_test(
18124      ".foo { text-decoration-line: overline }",
18125      ".foo{text-decoration-line:overline}",
18126    );
18127    minify_test(
18128      ".foo { text-decoration-line: line-through }",
18129      ".foo{text-decoration-line:line-through}",
18130    );
18131    minify_test(
18132      ".foo { text-decoration-line: blink }",
18133      ".foo{text-decoration-line:blink}",
18134    );
18135    minify_test(
18136      ".foo { text-decoration-line: underline overline }",
18137      ".foo{text-decoration-line:underline overline}",
18138    );
18139    minify_test(
18140      ".foo { text-decoration-line: overline underline }",
18141      ".foo{text-decoration-line:underline overline}",
18142    );
18143    minify_test(
18144      ".foo { text-decoration-line: overline line-through underline }",
18145      ".foo{text-decoration-line:underline overline line-through}",
18146    );
18147    minify_test(
18148      ".foo { text-decoration-line: spelling-error }",
18149      ".foo{text-decoration-line:spelling-error}",
18150    );
18151    minify_test(
18152      ".foo { text-decoration-line: grammar-error }",
18153      ".foo{text-decoration-line:grammar-error}",
18154    );
18155    minify_test(
18156      ".foo { -webkit-text-decoration-line: overline underline }",
18157      ".foo{-webkit-text-decoration-line:underline overline}",
18158    );
18159    minify_test(
18160      ".foo { -moz-text-decoration-line: overline underline }",
18161      ".foo{-moz-text-decoration-line:underline overline}",
18162    );
18163
18164    minify_test(
18165      ".foo { text-decoration-style: solid }",
18166      ".foo{text-decoration-style:solid}",
18167    );
18168    minify_test(
18169      ".foo { text-decoration-style: dotted }",
18170      ".foo{text-decoration-style:dotted}",
18171    );
18172    minify_test(
18173      ".foo { -webkit-text-decoration-style: solid }",
18174      ".foo{-webkit-text-decoration-style:solid}",
18175    );
18176
18177    minify_test(
18178      ".foo { text-decoration-color: yellow }",
18179      ".foo{text-decoration-color:#ff0}",
18180    );
18181    minify_test(
18182      ".foo { -webkit-text-decoration-color: yellow }",
18183      ".foo{-webkit-text-decoration-color:#ff0}",
18184    );
18185
18186    minify_test(".foo { text-decoration: none }", ".foo{text-decoration:none}");
18187    minify_test(
18188      ".foo { text-decoration: underline dotted }",
18189      ".foo{text-decoration:underline dotted}",
18190    );
18191    minify_test(
18192      ".foo { text-decoration: underline dotted yellow }",
18193      ".foo{text-decoration:underline dotted #ff0}",
18194    );
18195    minify_test(
18196      ".foo { text-decoration: yellow dotted underline }",
18197      ".foo{text-decoration:underline dotted #ff0}",
18198    );
18199    minify_test(
18200      ".foo { text-decoration: underline overline dotted yellow }",
18201      ".foo{text-decoration:underline overline dotted #ff0}",
18202    );
18203    minify_test(
18204      ".foo { -webkit-text-decoration: yellow dotted underline }",
18205      ".foo{-webkit-text-decoration:underline dotted #ff0}",
18206    );
18207    minify_test(
18208      ".foo { -moz-text-decoration: yellow dotted underline }",
18209      ".foo{-moz-text-decoration:underline dotted #ff0}",
18210    );
18211
18212    test(
18213      r#"
18214      .foo {
18215        text-decoration-line: underline;
18216        text-decoration-style: dotted;
18217        text-decoration-color: yellow;
18218        text-decoration-thickness: 2px;
18219      }
18220    "#,
18221      indoc! {r#"
18222      .foo {
18223        text-decoration: underline 2px dotted #ff0;
18224      }
18225    "#},
18226    );
18227
18228    test(
18229      r#"
18230      .foo {
18231        text-decoration: underline;
18232        text-decoration-style: dotted;
18233      }
18234    "#,
18235      indoc! {r#"
18236      .foo {
18237        text-decoration: underline dotted;
18238      }
18239    "#},
18240    );
18241
18242    test(
18243      r#"
18244      .foo {
18245        text-decoration: underline;
18246        text-decoration-style: var(--style);
18247      }
18248    "#,
18249      indoc! {r#"
18250      .foo {
18251        text-decoration: underline;
18252        text-decoration-style: var(--style);
18253      }
18254    "#},
18255    );
18256
18257    test(
18258      r#"
18259      .foo {
18260        -webkit-text-decoration: underline;
18261        -webkit-text-decoration-style: dotted;
18262      }
18263    "#,
18264      indoc! {r#"
18265      .foo {
18266        -webkit-text-decoration: underline dotted;
18267      }
18268    "#},
18269    );
18270
18271    prefix_test(
18272      r#"
18273      .foo {
18274        text-decoration: underline dotted;
18275      }
18276    "#,
18277      indoc! {r#"
18278      .foo {
18279        -webkit-text-decoration: underline dotted;
18280        text-decoration: underline dotted;
18281      }
18282    "#},
18283      Browsers {
18284        safari: Some(8 << 16),
18285        firefox: Some(30 << 16),
18286        ..Browsers::default()
18287      },
18288    );
18289
18290    prefix_test(
18291      r#"
18292      .foo {
18293        text-decoration-line: underline;
18294      }
18295    "#,
18296      indoc! {r#"
18297      .foo {
18298        -webkit-text-decoration-line: underline;
18299        -moz-text-decoration-line: underline;
18300        text-decoration-line: underline;
18301      }
18302    "#},
18303      Browsers {
18304        safari: Some(8 << 16),
18305        firefox: Some(30 << 16),
18306        ..Browsers::default()
18307      },
18308    );
18309
18310    prefix_test(
18311      r#"
18312      .foo {
18313        text-decoration-style: dotted;
18314      }
18315    "#,
18316      indoc! {r#"
18317      .foo {
18318        -webkit-text-decoration-style: dotted;
18319        -moz-text-decoration-style: dotted;
18320        text-decoration-style: dotted;
18321      }
18322    "#},
18323      Browsers {
18324        safari: Some(8 << 16),
18325        firefox: Some(30 << 16),
18326        ..Browsers::default()
18327      },
18328    );
18329
18330    prefix_test(
18331      r#"
18332      .foo {
18333        text-decoration-color: yellow;
18334      }
18335    "#,
18336      indoc! {r#"
18337      .foo {
18338        -webkit-text-decoration-color: #ff0;
18339        -moz-text-decoration-color: #ff0;
18340        text-decoration-color: #ff0;
18341      }
18342    "#},
18343      Browsers {
18344        safari: Some(8 << 16),
18345        firefox: Some(30 << 16),
18346        ..Browsers::default()
18347      },
18348    );
18349
18350    prefix_test(
18351      r#"
18352      .foo {
18353        text-decoration: underline;
18354      }
18355    "#,
18356      indoc! {r#"
18357      .foo {
18358        text-decoration: underline;
18359      }
18360    "#},
18361      Browsers {
18362        safari: Some(8 << 16),
18363        firefox: Some(30 << 16),
18364        ..Browsers::default()
18365      },
18366    );
18367
18368    prefix_test(
18369      r#"
18370      .foo {
18371        -webkit-text-decoration: underline dotted;
18372        text-decoration: underline dotted;
18373      }
18374    "#,
18375      indoc! {r#"
18376      .foo {
18377        -webkit-text-decoration: underline dotted;
18378        text-decoration: underline dotted;
18379      }
18380    "#},
18381      Browsers {
18382        safari: Some(14 << 16),
18383        firefox: Some(45 << 16),
18384        ..Browsers::default()
18385      },
18386    );
18387
18388    prefix_test(
18389      r#"
18390      .foo {
18391        text-decoration: double underline;
18392      }
18393    "#,
18394      indoc! {r#"
18395      .foo {
18396        -webkit-text-decoration: underline double;
18397        text-decoration: underline double;
18398      }
18399    "#},
18400      Browsers {
18401        safari: Some(16 << 16),
18402        ..Browsers::default()
18403      },
18404    );
18405
18406    prefix_test(
18407      r#"
18408      .foo {
18409        text-decoration: underline;
18410        text-decoration-style: double;
18411      }
18412    "#,
18413      indoc! {r#"
18414      .foo {
18415        -webkit-text-decoration: underline double;
18416        text-decoration: underline double;
18417      }
18418    "#},
18419      Browsers {
18420        safari: Some(16 << 16),
18421        ..Browsers::default()
18422      },
18423    );
18424
18425    prefix_test(
18426      r#"
18427      .foo {
18428        text-decoration: underline;
18429        text-decoration-color: red;
18430      }
18431    "#,
18432      indoc! {r#"
18433      .foo {
18434        -webkit-text-decoration: underline red;
18435        text-decoration: underline red;
18436      }
18437    "#},
18438      Browsers {
18439        safari: Some(16 << 16),
18440        ..Browsers::default()
18441      },
18442    );
18443
18444    prefix_test(
18445      r#"
18446      .foo {
18447        text-decoration: var(--test);
18448      }
18449    "#,
18450      indoc! {r#"
18451      .foo {
18452        -webkit-text-decoration: var(--test);
18453        text-decoration: var(--test);
18454      }
18455    "#},
18456      Browsers {
18457        safari: Some(8 << 16),
18458        firefox: Some(30 << 16),
18459        ..Browsers::default()
18460      },
18461    );
18462
18463    minify_test(
18464      ".foo { text-decoration-skip-ink: all }",
18465      ".foo{text-decoration-skip-ink:all}",
18466    );
18467    minify_test(
18468      ".foo { -webkit-text-decoration-skip-ink: all }",
18469      ".foo{-webkit-text-decoration-skip-ink:all}",
18470    );
18471
18472    prefix_test(
18473      r#"
18474      .foo {
18475        text-decoration: lch(50.998% 135.363 338) underline;
18476      }
18477    "#,
18478      indoc! {r#"
18479      .foo {
18480        -webkit-text-decoration: underline #f000c0;
18481        text-decoration: underline #f000c0;
18482        -webkit-text-decoration: underline lch(50.998% 135.363 338);
18483        text-decoration: underline lch(50.998% 135.363 338);
18484      }
18485    "#},
18486      Browsers {
18487        safari: Some(8 << 16),
18488        firefox: Some(30 << 16),
18489        ..Browsers::default()
18490      },
18491    );
18492
18493    prefix_test(
18494      r#"
18495      .foo {
18496        text-decoration-color: lch(50.998% 135.363 338);
18497      }
18498    "#,
18499      indoc! {r#"
18500      .foo {
18501        -webkit-text-decoration-color: #f000c0;
18502        -moz-text-decoration-color: #f000c0;
18503        text-decoration-color: #f000c0;
18504        -webkit-text-decoration-color: lch(50.998% 135.363 338);
18505        -moz-text-decoration-color: lch(50.998% 135.363 338);
18506        text-decoration-color: lch(50.998% 135.363 338);
18507      }
18508    "#},
18509      Browsers {
18510        safari: Some(8 << 16),
18511        firefox: Some(30 << 16),
18512        ..Browsers::default()
18513      },
18514    );
18515
18516    prefix_test(
18517      r#"
18518      .foo {
18519        text-decoration: lch(50.998% 135.363 338) var(--style);
18520      }
18521    "#,
18522      indoc! {r#"
18523      .foo {
18524        text-decoration: #f000c0 var(--style);
18525      }
18526
18527      @supports (color: lab(0% 0 0)) {
18528        .foo {
18529          text-decoration: lab(50.998% 125.506 -50.7078) var(--style);
18530        }
18531      }
18532    "#},
18533      Browsers {
18534        chrome: Some(90 << 16),
18535        ..Browsers::default()
18536      },
18537    );
18538
18539    prefix_test(
18540      r#"
18541      @supports (color: lab(0% 0 0)) {
18542        .foo {
18543          text-decoration: lab(50.998% 125.506 -50.7078) var(--style);
18544        }
18545      }
18546    "#,
18547      indoc! {r#"
18548      @supports (color: lab(0% 0 0)) {
18549        .foo {
18550          text-decoration: lab(50.998% 125.506 -50.7078) var(--style);
18551        }
18552      }
18553    "#},
18554      Browsers {
18555        chrome: Some(90 << 16),
18556        ..Browsers::default()
18557      },
18558    );
18559
18560    prefix_test(
18561      r#"
18562      .foo {
18563        text-decoration: underline 10px;
18564      }
18565    "#,
18566      indoc! {r#"
18567      .foo {
18568        text-decoration: underline;
18569        text-decoration-thickness: 10px;
18570      }
18571    "#},
18572      Browsers {
18573        safari: Some(15 << 16),
18574        ..Browsers::default()
18575      },
18576    );
18577
18578    prefix_test(
18579      r#"
18580      .foo {
18581        text-decoration: underline 10px;
18582      }
18583    "#,
18584      indoc! {r#"
18585      .foo {
18586        text-decoration: underline 10px;
18587      }
18588    "#},
18589      Browsers {
18590        chrome: Some(90 << 16),
18591        ..Browsers::default()
18592      },
18593    );
18594
18595    prefix_test(
18596      r#"
18597      .foo {
18598        text-decoration: underline 10%;
18599      }
18600    "#,
18601      indoc! {r#"
18602      .foo {
18603        text-decoration: underline;
18604        text-decoration-thickness: calc(1em / 10);
18605      }
18606    "#},
18607      Browsers {
18608        safari: Some(12 << 16),
18609        ..Browsers::default()
18610      },
18611    );
18612
18613    prefix_test(
18614      r#"
18615      .foo {
18616        text-decoration: underline 10%;
18617      }
18618    "#,
18619      indoc! {r#"
18620      .foo {
18621        text-decoration: underline 10%;
18622      }
18623    "#},
18624      Browsers {
18625        firefox: Some(89 << 16),
18626        ..Browsers::default()
18627      },
18628    );
18629
18630    prefix_test(
18631      r#"
18632      .foo {
18633        text-decoration-thickness: 10%;
18634      }
18635    "#,
18636      indoc! {r#"
18637      .foo {
18638        text-decoration-thickness: calc(1em / 10);
18639      }
18640    "#},
18641      Browsers {
18642        safari: Some(12 << 16),
18643        ..Browsers::default()
18644      },
18645    );
18646
18647    prefix_test(
18648      r#"
18649      .foo {
18650        text-decoration-thickness: 10%;
18651      }
18652    "#,
18653      indoc! {r#"
18654      .foo {
18655        text-decoration-thickness: 10%;
18656      }
18657    "#},
18658      Browsers {
18659        firefox: Some(89 << 16),
18660        ..Browsers::default()
18661      },
18662    );
18663  }
18664
18665  #[test]
18666  fn test_unparsed_text_decoration_prefixes() {
18667    let targets = Browsers {
18668      safari: Some((14 << 16) | (1 << 8)),
18669      ..Browsers::default()
18670    };
18671    let expected = indoc! {"
18672      .link {
18673        -webkit-text-decoration: underline var(--accent);
18674        text-decoration: underline var(--accent);
18675      }
18676    "};
18677
18678    for source in [
18679      indoc! {"
18680        .link {
18681          text-decoration: underline var(--accent);
18682        }
18683      "},
18684      indoc! {"
18685        .link {
18686          -webkit-text-decoration: underline var(--accent);
18687          text-decoration: underline var(--accent);
18688        }
18689      "},
18690      indoc! {"
18691        .link {
18692          text-decoration: underline var(--accent);
18693          -webkit-text-decoration: underline var(--accent);
18694        }
18695      "},
18696      indoc! {"
18697        .link {
18698          -webkit-text-decoration: underline var(--accent);
18699          -webkit-text-decoration: underline var(--accent);
18700          text-decoration: underline var(--accent);
18701        }
18702      "},
18703      indoc! {"
18704        .link {
18705          -webkit-text-decoration: underline var(--accent);
18706          /* An ordinary comment does not prevent deduplication. */
18707          text-decoration: underline var(--accent);
18708        }
18709      "},
18710    ] {
18711      prefix_test(source, expected, targets);
18712    }
18713
18714    // An already-prefixed result must not grow when minified again.
18715    prefix_test(expected, expected, targets);
18716
18717    let important = indoc! {"
18718      .link {
18719        -webkit-text-decoration: underline var(--accent) !important;
18720        text-decoration: underline var(--accent) !important;
18721      }
18722    "};
18723    prefix_test(important, important, targets);
18724
18725    let fallback = indoc! {"
18726      .link {
18727        -webkit-text-decoration: underline var(--accent, red);
18728        text-decoration: underline var(--accent, red);
18729      }
18730    "};
18731    prefix_test(fallback, fallback, targets);
18732
18733    // Explicit prefixes are retained even if the targets do not require them.
18734    prefix_test(
18735      expected,
18736      expected,
18737      Browsers {
18738        chrome: Some(120 << 16),
18739        ..Browsers::default()
18740      },
18741    );
18742    test(expected, expected);
18743  }
18744
18745  #[test]
18746  fn test_unparsed_text_prefix_boundaries() {
18747    let targets = Browsers {
18748      safari: Some((14 << 16) | (1 << 8)),
18749      ..Browsers::default()
18750    };
18751
18752    for source in [
18753      // Different values must retain their vendor-specific fallbacks.
18754      indoc! {"
18755        .link {
18756          -webkit-text-decoration: var(--old);
18757          -webkit-text-decoration: var(--new);
18758          text-decoration: var(--new);
18759        }
18760      "},
18761      // Normal and important declarations must not share prefix state.
18762      indoc! {"
18763        .link {
18764          -webkit-text-decoration: var(--decoration);
18765          -webkit-text-decoration: var(--decoration) !important;
18766          text-decoration: var(--decoration) !important;
18767        }
18768      "},
18769      // An intervening parsed longhand prevents moving the later shorthand.
18770      indoc! {"
18771        .link {
18772          -webkit-text-decoration: var(--decoration);
18773          text-decoration: var(--decoration);
18774          text-decoration-color: red;
18775          -webkit-text-decoration: var(--decoration);
18776          text-decoration: var(--decoration);
18777        }
18778      "},
18779      // An unparsed longhand is also a barrier, even with identical tokens.
18780      indoc! {"
18781        .link {
18782          -webkit-text-decoration: var(--value);
18783          text-decoration: var(--value);
18784          -webkit-text-decoration-color: var(--value);
18785          text-decoration-color: var(--value);
18786          -webkit-text-decoration: var(--value);
18787          text-decoration: var(--value);
18788        }
18789      "},
18790      // Prefix state cannot cross rule or conditional boundaries.
18791      indoc! {"
18792        .link {
18793          -webkit-text-decoration: var(--decoration);
18794          text-decoration: var(--decoration);
18795        }
18796
18797        @media print {
18798          .link {
18799            -webkit-text-decoration: var(--decoration);
18800            text-decoration: var(--decoration);
18801          }
18802        }
18803      "},
18804    ] {
18805      prefix_test(source, source, targets);
18806    }
18807
18808    // Prefix-only input must not acquire an unprefixed declaration.
18809    let prefixed = indoc! {"
18810      .link {
18811        -webkit-text-decoration: var(--decoration);
18812      }
18813    "};
18814    prefix_test(prefixed, prefixed, targets);
18815  }
18816
18817  #[test]
18818  fn test_unparsed_text_longhand_prefixes() {
18819    let source = indoc! {"
18820      .link {
18821        -webkit-text-decoration-line: var(--value);
18822        text-decoration-line: var(--value);
18823        -webkit-text-decoration-style: var(--value);
18824        text-decoration-style: var(--value);
18825        -webkit-text-decoration-color: var(--value);
18826        text-decoration-color: var(--value);
18827        text-decoration-thickness: var(--value);
18828      }
18829    "};
18830    prefix_test(
18831      source,
18832      source,
18833      Browsers {
18834        safari: Some(12 << 16),
18835        ..Browsers::default()
18836      },
18837    );
18838  }
18839
18840  #[test]
18841  fn test_unparsed_text_emphasis_prefixes() {
18842    let targets = Browsers {
18843      chrome: Some(80 << 16),
18844      ..Browsers::default()
18845    };
18846    let source = indoc! {"
18847      .label {
18848        -webkit-text-emphasis: filled var(--mark);
18849        text-emphasis: filled var(--mark);
18850      }
18851    "};
18852    prefix_test(source, source, targets);
18853
18854    let longhands = indoc! {"
18855      .label {
18856        -webkit-text-emphasis-style: var(--value);
18857        text-emphasis-style: var(--value);
18858        -webkit-text-emphasis-color: var(--value);
18859        text-emphasis-color: var(--value);
18860        -webkit-text-emphasis-position: var(--value);
18861        text-emphasis-position: var(--value);
18862      }
18863    "};
18864    prefix_test(longhands, longhands, targets);
18865  }
18866
18867  #[test]
18868  fn test_text_emphasis() {
18869    minify_test(".foo { text-emphasis-style: none }", ".foo{text-emphasis-style:none}");
18870    minify_test(
18871      ".foo { text-emphasis-style: filled }",
18872      ".foo{text-emphasis-style:filled}",
18873    );
18874    minify_test(".foo { text-emphasis-style: open }", ".foo{text-emphasis-style:open}");
18875    minify_test(".foo { text-emphasis-style: dot }", ".foo{text-emphasis-style:dot}");
18876    minify_test(
18877      ".foo { text-emphasis-style: filled dot }",
18878      ".foo{text-emphasis-style:dot}",
18879    );
18880    minify_test(
18881      ".foo { text-emphasis-style: dot filled }",
18882      ".foo{text-emphasis-style:dot}",
18883    );
18884    minify_test(
18885      ".foo { text-emphasis-style: open dot }",
18886      ".foo{text-emphasis-style:open dot}",
18887    );
18888    minify_test(
18889      ".foo { text-emphasis-style: dot open }",
18890      ".foo{text-emphasis-style:open dot}",
18891    );
18892    minify_test(".foo { text-emphasis-style: \"x\" }", ".foo{text-emphasis-style:\"x\"}");
18893
18894    minify_test(".foo { text-emphasis-color: yellow }", ".foo{text-emphasis-color:#ff0}");
18895
18896    minify_test(".foo { text-emphasis: none }", ".foo{text-emphasis:none}");
18897    minify_test(".foo { text-emphasis: filled }", ".foo{text-emphasis:filled}");
18898    minify_test(
18899      ".foo { text-emphasis: filled yellow }",
18900      ".foo{text-emphasis:filled #ff0}",
18901    );
18902    minify_test(
18903      ".foo { text-emphasis: dot filled yellow }",
18904      ".foo{text-emphasis:dot #ff0}",
18905    );
18906
18907    test(
18908      r#"
18909      .foo {
18910        text-emphasis-style: filled;
18911        text-emphasis-color: yellow;
18912      }
18913    "#,
18914      indoc! {r#"
18915      .foo {
18916        text-emphasis: filled #ff0;
18917      }
18918    "#},
18919    );
18920
18921    test(
18922      r#"
18923      .foo {
18924        text-emphasis: filled red;
18925        text-emphasis-color: yellow;
18926      }
18927    "#,
18928      indoc! {r#"
18929      .foo {
18930        text-emphasis: filled #ff0;
18931      }
18932    "#},
18933    );
18934
18935    test(
18936      r#"
18937      .foo {
18938        text-emphasis: filled yellow;
18939        text-emphasis-color: var(--color);
18940      }
18941    "#,
18942      indoc! {r#"
18943      .foo {
18944        text-emphasis: filled #ff0;
18945        text-emphasis-color: var(--color);
18946      }
18947    "#},
18948    );
18949
18950    prefix_test(
18951      r#"
18952      .foo {
18953        text-emphasis-style: filled;
18954      }
18955    "#,
18956      indoc! {r#"
18957      .foo {
18958        -webkit-text-emphasis-style: filled;
18959        text-emphasis-style: filled;
18960      }
18961    "#},
18962      Browsers {
18963        safari: Some(10 << 16),
18964        chrome: Some(30 << 16),
18965        firefox: Some(45 << 16),
18966        ..Browsers::default()
18967      },
18968    );
18969
18970    prefix_test(
18971      r#"
18972      .foo {
18973        -webkit-text-emphasis-style: filled;
18974        text-emphasis-style: filled;
18975      }
18976    "#,
18977      indoc! {r#"
18978      .foo {
18979        text-emphasis-style: filled;
18980      }
18981    "#},
18982      Browsers {
18983        safari: Some(10 << 16),
18984        firefox: Some(45 << 16),
18985        ..Browsers::default()
18986      },
18987    );
18988
18989    minify_test(
18990      ".foo { text-emphasis-position: over }",
18991      ".foo{text-emphasis-position:over}",
18992    );
18993    minify_test(
18994      ".foo { text-emphasis-position: under }",
18995      ".foo{text-emphasis-position:under}",
18996    );
18997    minify_test(
18998      ".foo { text-emphasis-position: over right }",
18999      ".foo{text-emphasis-position:over}",
19000    );
19001    minify_test(
19002      ".foo { text-emphasis-position: over left }",
19003      ".foo{text-emphasis-position:over left}",
19004    );
19005
19006    prefix_test(
19007      r#"
19008      .foo {
19009        text-emphasis-position: over;
19010      }
19011    "#,
19012      indoc! {r#"
19013      .foo {
19014        -webkit-text-emphasis-position: over;
19015        text-emphasis-position: over;
19016      }
19017    "#},
19018      Browsers {
19019        safari: Some(10 << 16),
19020        chrome: Some(30 << 16),
19021        firefox: Some(45 << 16),
19022        ..Browsers::default()
19023      },
19024    );
19025
19026    prefix_test(
19027      r#"
19028      .foo {
19029        text-emphasis-position: over left;
19030      }
19031    "#,
19032      indoc! {r#"
19033      .foo {
19034        text-emphasis-position: over left;
19035      }
19036    "#},
19037      Browsers {
19038        safari: Some(10 << 16),
19039        chrome: Some(30 << 16),
19040        firefox: Some(45 << 16),
19041        ..Browsers::default()
19042      },
19043    );
19044
19045    prefix_test(
19046      r#"
19047      .foo {
19048        text-emphasis-position: var(--test);
19049      }
19050    "#,
19051      indoc! {r#"
19052      .foo {
19053        -webkit-text-emphasis-position: var(--test);
19054        text-emphasis-position: var(--test);
19055      }
19056    "#},
19057      Browsers {
19058        safari: Some(10 << 16),
19059        chrome: Some(30 << 16),
19060        firefox: Some(45 << 16),
19061        ..Browsers::default()
19062      },
19063    );
19064
19065    prefix_test(
19066      r#"
19067      .foo {
19068        text-emphasis: filled lch(50.998% 135.363 338);
19069      }
19070    "#,
19071      indoc! {r#"
19072      .foo {
19073        -webkit-text-emphasis: filled #f000c0;
19074        text-emphasis: filled #f000c0;
19075        -webkit-text-emphasis: filled lch(50.998% 135.363 338);
19076        text-emphasis: filled lch(50.998% 135.363 338);
19077      }
19078    "#},
19079      Browsers {
19080        chrome: Some(25 << 16),
19081        firefox: Some(48 << 16),
19082        ..Browsers::default()
19083      },
19084    );
19085
19086    prefix_test(
19087      r#"
19088      .foo {
19089        text-emphasis-color: lch(50.998% 135.363 338);
19090      }
19091    "#,
19092      indoc! {r#"
19093      .foo {
19094        -webkit-text-emphasis-color: #f000c0;
19095        text-emphasis-color: #f000c0;
19096        -webkit-text-emphasis-color: lch(50.998% 135.363 338);
19097        text-emphasis-color: lch(50.998% 135.363 338);
19098      }
19099    "#},
19100      Browsers {
19101        chrome: Some(25 << 16),
19102        firefox: Some(48 << 16),
19103        ..Browsers::default()
19104      },
19105    );
19106
19107    prefix_test(
19108      r#"
19109      .foo {
19110        text-emphasis: lch(50.998% 135.363 338) var(--style);
19111      }
19112    "#,
19113      indoc! {r#"
19114      .foo {
19115        text-emphasis: #f000c0 var(--style);
19116      }
19117
19118      @supports (color: lab(0% 0 0)) {
19119        .foo {
19120          text-emphasis: lab(50.998% 125.506 -50.7078) var(--style);
19121        }
19122      }
19123    "#},
19124      Browsers {
19125        safari: Some(8 << 16),
19126        ..Browsers::default()
19127      },
19128    );
19129
19130    prefix_test(
19131      r#"
19132      @supports (color: lab(0% 0 0)) {
19133        .foo {
19134          text-emphasis: lab(50.998% 125.506 -50.7078) var(--style);
19135        }
19136      }
19137    "#,
19138      indoc! {r#"
19139      @supports (color: lab(0% 0 0)) {
19140        .foo {
19141          text-emphasis: lab(50.998% 125.506 -50.7078) var(--style);
19142        }
19143      }
19144    "#},
19145      Browsers {
19146        safari: Some(8 << 16),
19147        ..Browsers::default()
19148      },
19149    );
19150  }
19151
19152  #[test]
19153  fn test_text_shadow() {
19154    property_range_test(
19155      &["text-shadow"],
19156      &[
19157        ("1px 2px -3px", None),
19158        ("1px 2px 0 -4px", None),
19159        ("-1px -2px", Some("-1px -2px")),
19160        ("1px 2px calc(-3px)", Some("1px 2px")),
19161      ],
19162    );
19163    minify_test(
19164      ".foo { text-shadow: 1px 1px 2px yellow; }",
19165      ".foo{text-shadow:1px 1px 2px #ff0}",
19166    );
19167    minify_test(
19168      ".foo { text-shadow: 1px 1px 2px 3px yellow; }",
19169      ".foo{text-shadow:1px 1px 2px 3px #ff0}",
19170    );
19171    minify_test(
19172      ".foo { text-shadow: 1px 1px 0 yellow; }",
19173      ".foo{text-shadow:1px 1px #ff0}",
19174    );
19175    minify_test(
19176      ".foo { text-shadow: 1px 1px yellow; }",
19177      ".foo{text-shadow:1px 1px #ff0}",
19178    );
19179    minify_test(
19180      ".foo { text-shadow: 1px 1px yellow, 2px 3px red; }",
19181      ".foo{text-shadow:1px 1px #ff0,2px 3px red}",
19182    );
19183
19184    prefix_test(
19185      ".foo { text-shadow: 12px 12px lab(40% 56.6 39) }",
19186      indoc! { r#"
19187        .foo {
19188          text-shadow: 12px 12px #b32323;
19189          text-shadow: 12px 12px lab(40% 56.6 39);
19190        }
19191      "#},
19192      Browsers {
19193        chrome: Some(4 << 16),
19194        ..Browsers::default()
19195      },
19196    );
19197
19198    prefix_test(
19199      ".foo { text-shadow: 12px 12px lab(40% 56.6 39) }",
19200      indoc! { r#"
19201        .foo {
19202          text-shadow: 12px 12px #b32323;
19203          text-shadow: 12px 12px color(display-p3 .643308 .192455 .167712);
19204          text-shadow: 12px 12px lab(40% 56.6 39);
19205        }
19206      "#},
19207      Browsers {
19208        chrome: Some(90 << 16),
19209        safari: Some(14 << 16),
19210        ..Browsers::default()
19211      },
19212    );
19213
19214    prefix_test(
19215      ".foo { text-shadow: 12px 12px lab(40% 56.6 39), 12px 12px yellow }",
19216      indoc! { r#"
19217        .foo {
19218          text-shadow: 12px 12px #b32323, 12px 12px #ff0;
19219          text-shadow: 12px 12px lab(40% 56.6 39), 12px 12px #ff0;
19220        }
19221      "#},
19222      Browsers {
19223        chrome: Some(4 << 16),
19224        ..Browsers::default()
19225      },
19226    );
19227
19228    prefix_test(
19229      ".foo { text-shadow: var(--foo) 12px lab(40% 56.6 39) }",
19230      indoc! { r#"
19231        .foo {
19232          text-shadow: var(--foo) 12px #b32323;
19233        }
19234
19235        @supports (color: lab(0% 0 0)) {
19236          .foo {
19237            text-shadow: var(--foo) 12px lab(40% 56.6 39);
19238          }
19239        }
19240      "#},
19241      Browsers {
19242        chrome: Some(4 << 16),
19243        ..Browsers::default()
19244      },
19245    );
19246
19247    prefix_test(
19248      r#"
19249        @supports (color: lab(0% 0 0)) {
19250          .foo {
19251            text-shadow: var(--foo) 12px lab(40% 56.6 39);
19252          }
19253        }
19254      "#,
19255      indoc! { r#"
19256        @supports (color: lab(0% 0 0)) {
19257          .foo {
19258            text-shadow: var(--foo) 12px lab(40% 56.6 39);
19259          }
19260        }
19261      "#},
19262      Browsers {
19263        chrome: Some(4 << 16),
19264        ..Browsers::default()
19265      },
19266    );
19267  }
19268
19269  #[test]
19270  fn test_break() {
19271    prefix_test(
19272      r#"
19273      .foo {
19274        box-decoration-break: clone;
19275      }
19276    "#,
19277      indoc! {r#"
19278      .foo {
19279        -webkit-box-decoration-break: clone;
19280        box-decoration-break: clone;
19281      }
19282    "#},
19283      Browsers {
19284        safari: Some(15 << 16),
19285        ..Browsers::default()
19286      },
19287    );
19288
19289    prefix_test(
19290      r#"
19291      .foo {
19292        box-decoration-break: clone;
19293      }
19294    "#,
19295      indoc! {r#"
19296      .foo {
19297        box-decoration-break: clone;
19298      }
19299    "#},
19300      Browsers {
19301        firefox: Some(95 << 16),
19302        ..Browsers::default()
19303      },
19304    );
19305  }
19306
19307  #[test]
19308  fn test_position() {
19309    test(
19310      r#"
19311      .foo {
19312        position: relative;
19313        position: absolute;
19314      }
19315    "#,
19316      indoc! {r#"
19317      .foo {
19318        position: absolute;
19319      }
19320    "#},
19321    );
19322
19323    test(
19324      r#"
19325      .foo {
19326        position: -webkit-sticky;
19327        position: sticky;
19328      }
19329    "#,
19330      indoc! {r#"
19331      .foo {
19332        position: -webkit-sticky;
19333        position: sticky;
19334      }
19335    "#},
19336    );
19337
19338    prefix_test(
19339      r#"
19340      .foo {
19341        position: sticky;
19342      }
19343    "#,
19344      indoc! {r#"
19345      .foo {
19346        position: -webkit-sticky;
19347        position: sticky;
19348      }
19349    "#},
19350      Browsers {
19351        safari: Some(8 << 16),
19352        ..Browsers::default()
19353      },
19354    );
19355
19356    prefix_test(
19357      r#"
19358      .foo {
19359        position: -webkit-sticky;
19360        position: sticky;
19361      }
19362    "#,
19363      indoc! {r#"
19364      .foo {
19365        position: sticky;
19366      }
19367    "#},
19368      Browsers {
19369        safari: Some(13 << 16),
19370        ..Browsers::default()
19371      },
19372    );
19373
19374    test(
19375      r#"
19376      .foo {
19377        top: 0;
19378        left: 0;
19379        bottom: 0;
19380        right: 0;
19381      }
19382    "#,
19383      indoc! {r#"
19384      .foo {
19385        inset: 0;
19386      }
19387    "#},
19388    );
19389
19390    test(
19391      r#"
19392      .foo {
19393        top: 2px;
19394        left: 4px;
19395        bottom: 2px;
19396        right: 4px;
19397      }
19398    "#,
19399      indoc! {r#"
19400      .foo {
19401        inset: 2px 4px;
19402      }
19403    "#},
19404    );
19405
19406    test(
19407      r#"
19408      .foo {
19409        top: 1px;
19410        left: 2px;
19411        bottom: 3px;
19412        right: 4px;
19413      }
19414    "#,
19415      indoc! {r#"
19416      .foo {
19417        inset: 1px 4px 3px 2px;
19418      }
19419    "#},
19420    );
19421
19422    test(
19423      r#"
19424      .foo {
19425        inset-block-start: 2px;
19426        inset-block-end: 2px;
19427        inset-inline-start: 4px;
19428        inset-inline-end: 4px;
19429      }
19430    "#,
19431      indoc! {r#"
19432      .foo {
19433        inset-block: 2px;
19434        inset-inline: 4px;
19435      }
19436    "#},
19437    );
19438
19439    test(
19440      r#"
19441      .foo {
19442        inset-block-start: 2px;
19443        inset-block-end: 3px;
19444        inset-inline-start: 4px;
19445        inset-inline-end: 5px;
19446      }
19447    "#,
19448      indoc! {r#"
19449      .foo {
19450        inset-block: 2px 3px;
19451        inset-inline: 4px 5px;
19452      }
19453    "#},
19454    );
19455
19456    test(
19457      r#"
19458      .foo {
19459        inset-block-start: 2px;
19460        inset-block-end: 3px;
19461        inset: 4px;
19462        inset-inline-start: 4px;
19463        inset-inline-end: 5px;
19464      }
19465    "#,
19466      indoc! {r#"
19467      .foo {
19468        inset: 4px;
19469        inset-inline: 4px 5px;
19470      }
19471    "#},
19472    );
19473
19474    prefix_test(
19475      r#"
19476      .foo {
19477        inset-inline-start: 2px;
19478      }
19479    "#,
19480      indoc! {r#"
19481      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
19482        left: 2px;
19483      }
19484
19485      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
19486        left: 2px;
19487      }
19488
19489      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
19490        right: 2px;
19491      }
19492
19493      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
19494        right: 2px;
19495      }
19496    "#
19497      },
19498      Browsers {
19499        safari: Some(8 << 16),
19500        ..Browsers::default()
19501      },
19502    );
19503
19504    prefix_test(
19505      r#"
19506      .foo {
19507        inset-inline-start: 2px;
19508        inset-inline-end: 4px;
19509      }
19510    "#,
19511      indoc! {r#"
19512      .foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
19513        left: 2px;
19514        right: 4px;
19515      }
19516
19517      .foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {
19518        left: 2px;
19519        right: 4px;
19520      }
19521
19522      .foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
19523        left: 4px;
19524        right: 2px;
19525      }
19526
19527      .foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {
19528        left: 4px;
19529        right: 2px;
19530      }
19531    "#
19532      },
19533      Browsers {
19534        safari: Some(8 << 16),
19535        ..Browsers::default()
19536      },
19537    );
19538
19539    prefix_test(
19540      r#"
19541      .foo {
19542        inset-inline: 2px;
19543      }
19544    "#,
19545      indoc! {r#"
19546      .foo {
19547        left: 2px;
19548        right: 2px;
19549      }
19550    "#
19551      },
19552      Browsers {
19553        safari: Some(8 << 16),
19554        ..Browsers::default()
19555      },
19556    );
19557
19558    prefix_test(
19559      r#"
19560      .foo {
19561        inset-block-start: 2px;
19562      }
19563    "#,
19564      indoc! {r#"
19565      .foo {
19566        top: 2px;
19567      }
19568    "#
19569      },
19570      Browsers {
19571        safari: Some(8 << 16),
19572        ..Browsers::default()
19573      },
19574    );
19575
19576    prefix_test(
19577      r#"
19578      .foo {
19579        inset-block-end: 2px;
19580      }
19581    "#,
19582      indoc! {r#"
19583      .foo {
19584        bottom: 2px;
19585      }
19586    "#
19587      },
19588      Browsers {
19589        safari: Some(8 << 16),
19590        ..Browsers::default()
19591      },
19592    );
19593
19594    prefix_test(
19595      r#"
19596      .foo {
19597        top: 1px;
19598        left: 2px;
19599        bottom: 3px;
19600        right: 4px;
19601      }
19602    "#,
19603      indoc! {r#"
19604      .foo {
19605        top: 1px;
19606        bottom: 3px;
19607        left: 2px;
19608        right: 4px;
19609      }
19610    "#},
19611      Browsers {
19612        safari: Some(8 << 16),
19613        ..Browsers::default()
19614      },
19615    );
19616  }
19617
19618  #[test]
19619  fn test_overflow() {
19620    minify_test(".foo { overflow: hidden }", ".foo{overflow:hidden}");
19621    minify_test(".foo { overflow: hidden hidden }", ".foo{overflow:hidden}");
19622    minify_test(".foo { overflow: hidden auto }", ".foo{overflow:hidden auto}");
19623
19624    test(
19625      r#"
19626      .foo {
19627        overflow-x: hidden;
19628        overflow-y: auto;
19629      }
19630    "#,
19631      indoc! {r#"
19632      .foo {
19633        overflow: hidden auto;
19634      }
19635    "#},
19636    );
19637
19638    test(
19639      r#"
19640      .foo {
19641        overflow: hidden;
19642        overflow-y: auto;
19643      }
19644    "#,
19645      indoc! {r#"
19646      .foo {
19647        overflow: hidden auto;
19648      }
19649    "#},
19650    );
19651    test(
19652      r#"
19653      .foo {
19654        overflow: hidden;
19655        overflow-y: var(--y);
19656      }
19657    "#,
19658      indoc! {r#"
19659      .foo {
19660        overflow: hidden;
19661        overflow-y: var(--y);
19662      }
19663    "#},
19664    );
19665    prefix_test(
19666      r#"
19667      .foo {
19668        overflow: hidden auto;
19669      }
19670    "#,
19671      indoc! {r#"
19672      .foo {
19673        overflow-x: hidden;
19674        overflow-y: auto;
19675      }
19676    "#},
19677      Browsers {
19678        chrome: Some(67 << 16),
19679        ..Browsers::default()
19680      },
19681    );
19682    prefix_test(
19683      r#"
19684      .foo {
19685        overflow: hidden hidden;
19686      }
19687    "#,
19688      indoc! {r#"
19689      .foo {
19690        overflow: hidden;
19691      }
19692    "#},
19693      Browsers {
19694        chrome: Some(67 << 16),
19695        ..Browsers::default()
19696      },
19697    );
19698    prefix_test(
19699      r#"
19700      .foo {
19701        overflow: hidden auto;
19702      }
19703    "#,
19704      indoc! {r#"
19705      .foo {
19706        overflow: hidden auto;
19707      }
19708    "#},
19709      Browsers {
19710        chrome: Some(68 << 16),
19711        ..Browsers::default()
19712      },
19713    );
19714
19715    minify_test(".foo { text-overflow: ellipsis }", ".foo{text-overflow:ellipsis}");
19716    prefix_test(
19717      r#"
19718      .foo {
19719        text-overflow: ellipsis;
19720      }
19721    "#,
19722      indoc! {r#"
19723      .foo {
19724        -o-text-overflow: ellipsis;
19725        text-overflow: ellipsis;
19726      }
19727    "#},
19728      Browsers {
19729        safari: Some(4 << 16),
19730        opera: Some(10 << 16),
19731        ..Browsers::default()
19732      },
19733    );
19734
19735    prefix_test(
19736      r#"
19737      .foo {
19738        -o-text-overflow: ellipsis;
19739        text-overflow: ellipsis;
19740      }
19741    "#,
19742      indoc! {r#"
19743      .foo {
19744        text-overflow: ellipsis;
19745      }
19746    "#},
19747      Browsers {
19748        safari: Some(4 << 16),
19749        opera: Some(14 << 16),
19750        ..Browsers::default()
19751      },
19752    );
19753  }
19754
19755  #[test]
19756  fn test_ui() {
19757    minify_test(".foo { resize: both }", ".foo{resize:both}");
19758    minify_test(".foo { resize: Horizontal }", ".foo{resize:horizontal}");
19759    minify_test(".foo { cursor: ew-resize }", ".foo{cursor:ew-resize}");
19760    minify_test(
19761      ".foo { cursor: url(\"test.cur\"), ew-resize }",
19762      ".foo{cursor:url(test.cur),ew-resize}",
19763    );
19764    minify_test(
19765      ".foo { cursor: url(\"test.cur\"), url(\"foo.cur\"), ew-resize }",
19766      ".foo{cursor:url(test.cur),url(foo.cur),ew-resize}",
19767    );
19768    minify_test(".foo { caret-color: auto }", ".foo{caret-color:auto}");
19769    minify_test(".foo { caret-color: yellow }", ".foo{caret-color:#ff0}");
19770    minify_test(".foo { caret-shape: block }", ".foo{caret-shape:block}");
19771    minify_test(".foo { caret: yellow block }", ".foo{caret:#ff0 block}");
19772    minify_test(".foo { caret: block yellow }", ".foo{caret:#ff0 block}");
19773    minify_test(".foo { caret: block }", ".foo{caret:block}");
19774    minify_test(".foo { caret: yellow }", ".foo{caret:#ff0}");
19775    minify_test(".foo { caret: auto auto }", ".foo{caret:auto}");
19776    minify_test(".foo { caret: auto }", ".foo{caret:auto}");
19777    minify_test(".foo { caret: yellow auto }", ".foo{caret:#ff0}");
19778    minify_test(".foo { caret: auto block }", ".foo{caret:block}");
19779    minify_test(".foo { user-select: none }", ".foo{user-select:none}");
19780    minify_test(".foo { -webkit-user-select: none }", ".foo{-webkit-user-select:none}");
19781    minify_test(".foo { accent-color: auto }", ".foo{accent-color:auto}");
19782    minify_test(".foo { accent-color: yellow }", ".foo{accent-color:#ff0}");
19783    minify_test(".foo { appearance: None }", ".foo{appearance:none}");
19784    minify_test(
19785      ".foo { -webkit-appearance: textfield }",
19786      ".foo{-webkit-appearance:textfield}",
19787    );
19788
19789    prefix_test(
19790      r#"
19791      .foo {
19792        user-select: none;
19793      }
19794    "#,
19795      indoc! {r#"
19796      .foo {
19797        -webkit-user-select: none;
19798        -moz-user-select: none;
19799        -ms-user-select: none;
19800        user-select: none;
19801      }
19802    "#},
19803      Browsers {
19804        safari: Some(8 << 16),
19805        opera: Some(5 << 16),
19806        firefox: Some(10 << 16),
19807        ie: Some(10 << 16),
19808        ..Browsers::default()
19809      },
19810    );
19811
19812    prefix_test(
19813      r#"
19814      .foo {
19815        -webkit-user-select: none;
19816        -moz-user-select: none;
19817        -ms-user-select: none;
19818        user-select: none;
19819      }
19820    "#,
19821      indoc! {r#"
19822      .foo {
19823        -webkit-user-select: none;
19824        user-select: none;
19825      }
19826    "#},
19827      Browsers {
19828        safari: Some(8 << 16),
19829        opera: Some(80 << 16),
19830        firefox: Some(80 << 16),
19831        edge: Some(80 << 16),
19832        ..Browsers::default()
19833      },
19834    );
19835
19836    prefix_test(
19837      r#"
19838      .foo {
19839        -webkit-user-select: none;
19840        -moz-user-select: none;
19841        -ms-user-select: none;
19842        user-select: none;
19843      }
19844    "#,
19845      indoc! {r#"
19846      .foo {
19847        user-select: none;
19848      }
19849    "#},
19850      Browsers {
19851        opera: Some(80 << 16),
19852        firefox: Some(80 << 16),
19853        edge: Some(80 << 16),
19854        ..Browsers::default()
19855      },
19856    );
19857
19858    prefix_test(
19859      r#"
19860      .foo {
19861        appearance: none;
19862      }
19863    "#,
19864      indoc! {r#"
19865      .foo {
19866        -webkit-appearance: none;
19867        -moz-appearance: none;
19868        -ms-appearance: none;
19869        appearance: none;
19870      }
19871    "#},
19872      Browsers {
19873        safari: Some(8 << 16),
19874        chrome: Some(80 << 16),
19875        firefox: Some(10 << 16),
19876        ie: Some(11 << 16),
19877        ..Browsers::default()
19878      },
19879    );
19880
19881    prefix_test(
19882      r#"
19883      .foo {
19884        -webkit-appearance: none;
19885        -moz-appearance: none;
19886        -ms-appearance: none;
19887        appearance: none;
19888      }
19889    "#,
19890      indoc! {r#"
19891      .foo {
19892        -webkit-appearance: none;
19893        appearance: none;
19894      }
19895    "#},
19896      Browsers {
19897        safari: Some(15 << 16),
19898        chrome: Some(85 << 16),
19899        firefox: Some(80 << 16),
19900        edge: Some(85 << 16),
19901        ..Browsers::default()
19902      },
19903    );
19904
19905    prefix_test(
19906      r#"
19907      .foo {
19908        -webkit-appearance: none;
19909        -moz-appearance: none;
19910        -ms-appearance: none;
19911        appearance: none;
19912      }
19913    "#,
19914      indoc! {r#"
19915      .foo {
19916        appearance: none;
19917      }
19918    "#},
19919      Browsers {
19920        chrome: Some(85 << 16),
19921        firefox: Some(80 << 16),
19922        edge: Some(85 << 16),
19923        ..Browsers::default()
19924      },
19925    );
19926
19927    prefix_test(
19928      ".foo { caret-color: lch(50.998% 135.363 338) }",
19929      indoc! { r#"
19930        .foo {
19931          caret-color: #f000c0;
19932          caret-color: color(display-p3 .972962 -.362078 .804206);
19933          caret-color: lch(50.998% 135.363 338);
19934        }
19935      "#},
19936      Browsers {
19937        chrome: Some(90 << 16),
19938        safari: Some(14 << 16),
19939        ..Browsers::default()
19940      },
19941    );
19942
19943    prefix_test(
19944      ".foo { caret: lch(50.998% 135.363 338) block }",
19945      indoc! { r#"
19946        .foo {
19947          caret: #f000c0 block;
19948          caret: color(display-p3 .972962 -.362078 .804206) block;
19949          caret: lch(50.998% 135.363 338) block;
19950        }
19951      "#},
19952      Browsers {
19953        chrome: Some(90 << 16),
19954        safari: Some(14 << 16),
19955        ..Browsers::default()
19956      },
19957    );
19958
19959    prefix_test(
19960      ".foo { caret: lch(50.998% 135.363 338) var(--foo) }",
19961      indoc! { r#"
19962        .foo {
19963          caret: #f000c0 var(--foo);
19964        }
19965
19966        @supports (color: lab(0% 0 0)) {
19967          .foo {
19968            caret: lab(50.998% 125.506 -50.7078) var(--foo);
19969          }
19970        }
19971      "#},
19972      Browsers {
19973        chrome: Some(90 << 16),
19974        ..Browsers::default()
19975      },
19976    );
19977
19978    prefix_test(
19979      r#"
19980        @supports (color: lab(0% 0 0)) {
19981          .foo {
19982            caret: lab(50.998% 125.506 -50.7078) var(--foo);
19983          }
19984        }
19985      "#,
19986      indoc! { r#"
19987        @supports (color: lab(0% 0 0)) {
19988          .foo {
19989            caret: lab(50.998% 125.506 -50.7078) var(--foo);
19990          }
19991        }
19992      "#},
19993      Browsers {
19994        chrome: Some(90 << 16),
19995        ..Browsers::default()
19996      },
19997    );
19998  }
19999
20000  #[test]
20001  fn test_list() {
20002    minify_test(".foo { list-style-type: disc; }", ".foo{list-style-type:disc}");
20003    minify_test(".foo { list-style-type: \"★\"; }", ".foo{list-style-type:\"★\"}");
20004    minify_test(
20005      ".foo { list-style-type: symbols(cyclic '○' '●'); }",
20006      ".foo{list-style-type:symbols(cyclic \"○\" \"●\")}",
20007    );
20008    minify_test(
20009      ".foo { list-style-type: symbols('○' '●'); }",
20010      ".foo{list-style-type:symbols(\"○\" \"●\")}",
20011    );
20012    minify_test(
20013      ".foo { list-style-type: symbols(symbolic '○' '●'); }",
20014      ".foo{list-style-type:symbols(\"○\" \"●\")}",
20015    );
20016    minify_test(
20017      ".foo { list-style-type: symbols(symbolic url('ellipse.png')); }",
20018      ".foo{list-style-type:symbols(url(ellipse.png))}",
20019    );
20020    minify_test(
20021      ".foo { list-style-image: url('ellipse.png'); }",
20022      ".foo{list-style-image:url(ellipse.png)}",
20023    );
20024    minify_test(
20025      ".foo { list-style-position: outside; }",
20026      ".foo{list-style-position:outside}",
20027    );
20028    minify_test(
20029      ".foo { list-style: \"★\" url(ellipse.png) outside; }",
20030      ".foo{list-style:url(ellipse.png) \"★\"}",
20031    );
20032    minify_test(".foo { list-style: none; }", ".foo{list-style:none}");
20033    minify_test(".foo { list-style: none none outside; }", ".foo{list-style:none}");
20034    minify_test(".foo { list-style: none none inside; }", ".foo{list-style:inside none}");
20035    minify_test(".foo { list-style: none inside; }", ".foo{list-style:inside none}");
20036    minify_test(".foo { list-style: none disc; }", ".foo{list-style:outside}");
20037    minify_test(".foo { list-style: none inside disc; }", ".foo{list-style:inside}");
20038    minify_test(".foo { list-style: none \"★\"; }", ".foo{list-style:\"★\"}");
20039    minify_test(
20040      ".foo { list-style: none url(foo.png); }",
20041      ".foo{list-style:url(foo.png) none}",
20042    );
20043
20044    test(
20045      r#"
20046      .foo {
20047        list-style-type: disc;
20048        list-style-image: url(ellipse.png);
20049        list-style-position: outside;
20050      }
20051    "#,
20052      indoc! {r#"
20053      .foo {
20054        list-style: url("ellipse.png");
20055      }
20056    "#},
20057    );
20058
20059    test(
20060      r#"
20061      .foo {
20062        list-style: \"★\" url(ellipse.png) outside;
20063        list-style-image: none;
20064      }
20065    "#,
20066      indoc! {r#"
20067      .foo {
20068        list-style: \"★\";
20069      }
20070    "#},
20071    );
20072
20073    test(
20074      r#"
20075      .foo {
20076        list-style: \"★\" url(ellipse.png) outside;
20077        list-style-image: var(--img);
20078      }
20079    "#,
20080      indoc! {r#"
20081      .foo {
20082        list-style: url("ellipse.png") \"★\";
20083        list-style-image: var(--img);
20084      }
20085    "#},
20086    );
20087
20088    prefix_test(
20089      ".foo { list-style-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
20090      indoc! { r#"
20091        .foo {
20092          list-style-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ff0b0c), to(#766eff));
20093          list-style-image: -webkit-linear-gradient(top, #ff0b0c, #766eff);
20094          list-style-image: linear-gradient(#ff0b0c, #766eff);
20095          list-style-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
20096        }
20097      "#},
20098      Browsers {
20099        chrome: Some(8 << 16),
20100        ..Browsers::default()
20101      },
20102    );
20103
20104    prefix_test(
20105      ".foo { list-style: \"★\" linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
20106      indoc! { r#"
20107        .foo {
20108          list-style: linear-gradient(#ff0b0c, #766eff) "★";
20109          list-style: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) "★";
20110        }
20111      "#},
20112      Browsers {
20113        chrome: Some(90 << 16),
20114        ..Browsers::default()
20115      },
20116    );
20117
20118    prefix_test(
20119      ".foo { list-style: var(--foo) linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
20120      indoc! { r#"
20121        .foo {
20122          list-style: var(--foo) linear-gradient(#ff0b0c, #766eff);
20123        }
20124
20125        @supports (color: lab(0% 0 0)) {
20126          .foo {
20127            list-style: var(--foo) linear-gradient(lab(56.208% 94.4644 98.8928), lab(51% 70.4544 -115.586));
20128          }
20129        }
20130      "#},
20131      Browsers {
20132        chrome: Some(90 << 16),
20133        ..Browsers::default()
20134      },
20135    );
20136
20137    prefix_test(
20138      r#"
20139        @supports (color: lab(0% 0 0)) {
20140          .foo {
20141            list-style: var(--foo) linear-gradient(lab(56.208% 94.4644 98.8928), lab(51% 70.4544 -115.586));
20142          }
20143        }
20144      "#,
20145      indoc! { r#"
20146        @supports (color: lab(0% 0 0)) {
20147          .foo {
20148            list-style: var(--foo) linear-gradient(lab(56.208% 94.4644 98.8928), lab(51% 70.4544 -115.586));
20149          }
20150        }
20151      "#},
20152      Browsers {
20153        chrome: Some(90 << 16),
20154        ..Browsers::default()
20155      },
20156    );
20157
20158    test(
20159      r#"
20160      .foo {
20161        list-style: inside;
20162        list-style-type: disc;
20163      }
20164    "#,
20165      indoc! {r#"
20166      .foo {
20167        list-style: inside;
20168      }
20169    "#},
20170    );
20171    test(
20172      r#"
20173      .foo {
20174        list-style: inside;
20175        list-style-type: decimal;
20176      }
20177    "#,
20178      indoc! {r#"
20179      .foo {
20180        list-style: inside decimal;
20181      }
20182    "#},
20183    );
20184  }
20185
20186  #[test]
20187  fn test_image_set() {
20188    // Spec: https://drafts.csswg.org/css-images-4/#image-set-notation
20189    // WPT: https://github.com/web-platform-tests/wpt/blob/master/css/css-images/image-set/image-set-parsing.html
20190    // test image-set(<string>)
20191    minify_test(
20192      ".foo { background: image-set(\"foo.png\" 2x, url(bar.png) 1x) }",
20193      ".foo{background:image-set(\"foo.png\" 2x,\"bar.png\" 1x)}",
20194    );
20195
20196    // test image-set(type(<string>))
20197    minify_test(
20198      ".foo { background: image-set('foo.webp' type('webp'), url(foo.jpg)) }",
20199      ".foo{background:image-set(\"foo.webp\" 1x type(\"webp\"),\"foo.jpg\" 1x)}",
20200    );
20201    minify_test(
20202      ".foo { background: image-set('foo.avif' 2x type('image/avif'), url(foo.png)) }",
20203      ".foo{background:image-set(\"foo.avif\" 2x type(\"image/avif\"),\"foo.png\" 1x)}",
20204    );
20205    minify_test(
20206      ".foo { background: image-set(url('example.png') 3x type('image/png')) }",
20207      ".foo{background:image-set(\"example.png\" 3x type(\"image/png\"))}",
20208    );
20209
20210    minify_test(
20211      ".foo { background: image-set(url(example.png) type('image/png') 1x) }",
20212      ".foo{background:image-set(\"example.png\" 1x type(\"image/png\"))}",
20213    );
20214
20215    minify_test(
20216      ".foo { background: -webkit-image-set(url(\"foo.png\") 2x, url(bar.png) 1x) }",
20217      ".foo{background:-webkit-image-set(url(foo.png) 2x,url(bar.png) 1x)}",
20218    );
20219
20220    test(
20221      r#"
20222      .foo {
20223        background: -webkit-image-set(url("foo.png") 2x, url(bar.png) 1x);
20224        background: image-set(url("foo.png") 2x, url(bar.png) 1x);
20225      }
20226    "#,
20227      indoc! {r#"
20228      .foo {
20229        background: -webkit-image-set(url("foo.png") 2x, url("bar.png") 1x);
20230        background: image-set("foo.png" 2x, "bar.png" 1x);
20231      }
20232    "#},
20233    );
20234
20235    // test image-set(<gradient>)
20236    test(
20237      r#"
20238      .foo {
20239        background: image-set(linear-gradient(cornflowerblue, white) 1x, url("detailed-gradient.png") 3x);
20240      }
20241    "#,
20242      indoc! {r#"
20243      .foo {
20244        background: image-set(linear-gradient(#6495ed, #fff) 1x, "detailed-gradient.png" 3x);
20245      }
20246    "#},
20247    );
20248
20249    prefix_test(
20250      r#"
20251      .foo {
20252        background: image-set(url("foo.png") 2x, url(bar.png) 1x);
20253      }
20254    "#,
20255      indoc! {r#"
20256      .foo {
20257        background: -webkit-image-set(url("foo.png") 2x, url("bar.png") 1x);
20258        background: image-set("foo.png" 2x, "bar.png" 1x);
20259      }
20260    "#},
20261      Browsers {
20262        chrome: Some(85 << 16),
20263        firefox: Some(80 << 16),
20264        ..Browsers::default()
20265      },
20266    );
20267
20268    prefix_test(
20269      r#"
20270      .foo {
20271        background: -webkit-image-set(url("foo.png") 2x, url(bar.png) 1x);
20272        background: image-set(url("foo.png") 2x, url(bar.png) 1x);
20273      }
20274    "#,
20275      indoc! {r#"
20276      .foo {
20277        background: -webkit-image-set(url("foo.png") 2x, url("bar.png") 1x);
20278        background: image-set("foo.png" 2x, "bar.png" 1x);
20279      }
20280    "#},
20281      Browsers {
20282        firefox: Some(80 << 16),
20283        ..Browsers::default()
20284      },
20285    );
20286
20287    prefix_test(
20288      r#"
20289      .foo {
20290        background: -webkit-image-set(url("foo.png") 2x, url(bar.png) 1x);
20291      }
20292    "#,
20293      indoc! {r#"
20294      .foo {
20295        background: -webkit-image-set(url("foo.png") 2x, url("bar.png") 1x);
20296      }
20297    "#},
20298      Browsers {
20299        chrome: Some(95 << 16),
20300        ..Browsers::default()
20301      },
20302    );
20303
20304    for property in &[
20305      "background",
20306      "background-image",
20307      "border-image-source",
20308      "border-image",
20309      "border-image-source",
20310      "-webkit-mask-image",
20311      "-webkit-mask",
20312      "list-style-image",
20313      "list-style",
20314    ] {
20315      prefix_test(
20316        &format!(
20317          r#"
20318        .foo {{
20319          {}: url(foo.png);
20320          {}: image-set(url("foo.png") 2x, url(bar.png) 1x);
20321        }}
20322      "#,
20323          property, property
20324        ),
20325        &format!(
20326          indoc! {r#"
20327        .foo {{
20328          {}: url("foo.png");
20329          {}: image-set("foo.png" 2x, "bar.png" 1x);
20330        }}
20331      "#},
20332          property, property
20333        ),
20334        Browsers {
20335          ie: Some(11 << 16),
20336          chrome: Some(95 << 16),
20337          ..Browsers::default()
20338        },
20339      );
20340
20341      prefix_test(
20342        &format!(
20343          r#"
20344        .foo {{
20345          {}: url(foo.png);
20346          {}: image-set(url("foo.png") 2x, url(bar.png) 1x);
20347        }}
20348      "#,
20349          property, property
20350        ),
20351        &format!(
20352          indoc! {r#"
20353        .foo {{
20354          {}: -webkit-image-set(url("foo.png") 2x, url("bar.png") 1x);
20355          {}: image-set("foo.png" 2x, "bar.png" 1x);
20356        }}
20357      "#},
20358          property, property
20359        ),
20360        Browsers {
20361          chrome: Some(95 << 16),
20362          ..Browsers::default()
20363        },
20364      );
20365    }
20366  }
20367
20368  #[test]
20369  fn test_color() {
20370    minify_test(".foo { color: yellow }", ".foo{color:#ff0}");
20371    minify_test(".foo { color: rgb(255, 255, 0) }", ".foo{color:#ff0}");
20372    minify_test(".foo { color: rgba(255, 255, 0, 1) }", ".foo{color:#ff0}");
20373    minify_test(".foo { color: rgba(255, 255, 0, 0.8) }", ".foo{color:#ff0c}");
20374    minify_test(".foo { color: rgb(128, 128, 128) }", ".foo{color:gray}");
20375    minify_test(".foo { color: rgb(123, 255, 255) }", ".foo{color:#7bffff}");
20376    minify_test(".foo { color: rgba(123, 255, 255, 0.5) }", ".foo{color:#7bffff80}");
20377    minify_test(".foo { color: rgb(123 255 255) }", ".foo{color:#7bffff}");
20378    minify_test(".foo { color: rgb(123 255 255 / .5) }", ".foo{color:#7bffff80}");
20379    minify_test(".foo { color: rgb(123 255 255 / 50%) }", ".foo{color:#7bffff80}");
20380    minify_test(".foo { color: rgb(48% 100% 100% / 50%) }", ".foo{color:#7affff80}");
20381    minify_test(".foo { color: hsl(100deg, 100%, 50%) }", ".foo{color:#5f0}");
20382    minify_test(".foo { color: hsl(100, 100%, 50%) }", ".foo{color:#5f0}");
20383    minify_test(".foo { color: hsl(100 100% 50%) }", ".foo{color:#5f0}");
20384    minify_test(".foo { color: hsl(100 100 50) }", ".foo{color:#5f0}");
20385    minify_test(".foo { color: hsl(100, 100%, 50%, .8) }", ".foo{color:#5f0c}");
20386    minify_test(".foo { color: hsl(100 100% 50% / .8) }", ".foo{color:#5f0c}");
20387    minify_test(".foo { color: hsla(100, 100%, 50%, .8) }", ".foo{color:#5f0c}");
20388    minify_test(".foo { color: hsla(100 100% 50% / .8) }", ".foo{color:#5f0c}");
20389    minify_test(".foo { color: transparent }", ".foo{color:#0000}");
20390    minify_test(".foo { color: currentColor }", ".foo{color:currentColor}");
20391    minify_test(".foo { color: ButtonBorder }", ".foo{color:buttonborder}");
20392    minify_test(".foo { color: hwb(194 0% 0%) }", ".foo{color:#00c4ff}");
20393    minify_test(".foo { color: hwb(194 0% 0% / 50%) }", ".foo{color:#00c4ff80}");
20394    minify_test(".foo { color: hwb(194 0% 50%) }", ".foo{color:#006280}");
20395    minify_test(".foo { color: hwb(194 50% 0%) }", ".foo{color:#80e1ff}");
20396    minify_test(".foo { color: hwb(194 50 0) }", ".foo{color:#80e1ff}");
20397    minify_test(".foo { color: hwb(194 50% 50%) }", ".foo{color:gray}");
20398    minify_test(".foo { color: light-dark(#FFF, #FFF) }", ".foo{color:#fff}");
20399    // minify_test(".foo { color: ActiveText }", ".foo{color:ActiveTet}");
20400    minify_test(
20401      ".foo { color: lab(29.2345% 39.3825 20.0664); }",
20402      ".foo{color:lab(29.2345% 39.3825 20.0664)}",
20403    );
20404    minify_test(
20405      ".foo { color: lab(29.2345 39.3825 20.0664); }",
20406      ".foo{color:lab(29.2345% 39.3825 20.0664)}",
20407    );
20408    minify_test(
20409      ".foo { color: lab(29.2345% 39.3825% 20.0664%); }",
20410      ".foo{color:lab(29.2345% 49.2281 25.083)}",
20411    );
20412    minify_test(
20413      ".foo { color: lab(29.2345% 39.3825 20.0664 / 100%); }",
20414      ".foo{color:lab(29.2345% 39.3825 20.0664)}",
20415    );
20416    minify_test(
20417      ".foo { color: lab(29.2345% 39.3825 20.0664 / 50%); }",
20418      ".foo{color:lab(29.2345% 39.3825 20.0664/.5)}",
20419    );
20420    minify_test(
20421      ".foo { color: lch(29.2345% 44.2 27); }",
20422      ".foo{color:lch(29.2345% 44.2 27)}",
20423    );
20424    minify_test(
20425      ".foo { color: lch(29.2345 44.2 27); }",
20426      ".foo{color:lch(29.2345% 44.2 27)}",
20427    );
20428    minify_test(
20429      ".foo { color: lch(29.2345% 44.2% 27deg); }",
20430      ".foo{color:lch(29.2345% 66.3 27)}",
20431    );
20432    minify_test(
20433      ".foo { color: lch(29.2345% 44.2 45deg); }",
20434      ".foo{color:lch(29.2345% 44.2 45)}",
20435    );
20436    minify_test(
20437      ".foo { color: lch(29.2345% 44.2 .5turn); }",
20438      ".foo{color:lch(29.2345% 44.2 180)}",
20439    );
20440    minify_test(
20441      ".foo { color: lch(29.2345% 44.2 27 / 100%); }",
20442      ".foo{color:lch(29.2345% 44.2 27)}",
20443    );
20444    minify_test(
20445      ".foo { color: lch(29.2345% 44.2 27 / 50%); }",
20446      ".foo{color:lch(29.2345% 44.2 27/.5)}",
20447    );
20448    minify_test(
20449      ".foo { color: oklab(40.101% 0.1147 0.0453); }",
20450      ".foo{color:oklab(40.101% .1147 .0453)}",
20451    );
20452    minify_test(
20453      ".foo { color: oklab(.40101 0.1147 0.0453); }",
20454      ".foo{color:oklab(40.101% .1147 .0453)}",
20455    );
20456    minify_test(
20457      ".foo { color: oklab(40.101% 0.1147% 0.0453%); }",
20458      ".foo{color:oklab(40.101% .0004588 .0001812)}",
20459    );
20460    minify_test(
20461      ".foo { color: oklch(40.101% 0.12332 21.555); }",
20462      ".foo{color:oklch(40.101% .12332 21.555)}",
20463    );
20464    minify_test(
20465      ".foo { color: oklch(.40101 0.12332 21.555); }",
20466      ".foo{color:oklch(40.101% .12332 21.555)}",
20467    );
20468    minify_test(
20469      ".foo { color: oklch(40.101% 0.12332% 21.555); }",
20470      ".foo{color:oklch(40.101% .00049328 21.555)}",
20471    );
20472    minify_test(
20473      ".foo { color: oklch(40.101% 0.12332 .5turn); }",
20474      ".foo{color:oklch(40.101% .12332 180)}",
20475    );
20476    minify_test(
20477      ".foo { color: color(display-p3 1 0.5 0); }",
20478      ".foo{color:color(display-p3 1 .5 0)}",
20479    );
20480    minify_test(
20481      ".foo { color: color(display-p3 100% 50% 0%); }",
20482      ".foo{color:color(display-p3 1 .5 0)}",
20483    );
20484    minify_test(
20485      ".foo { color: color(xyz-d50 0.2005 0.14089 0.4472); }",
20486      ".foo{color:color(xyz-d50 .2005 .14089 .4472)}",
20487    );
20488    minify_test(
20489      ".foo { color: color(xyz-d50 20.05% 14.089% 44.72%); }",
20490      ".foo{color:color(xyz-d50 .2005 .14089 .4472)}",
20491    );
20492    minify_test(
20493      ".foo { color: color(xyz-d65 0.2005 0.14089 0.4472); }",
20494      ".foo{color:color(xyz .2005 .14089 .4472)}",
20495    );
20496    minify_test(
20497      ".foo { color: color(xyz-d65 20.05% 14.089% 44.72%); }",
20498      ".foo{color:color(xyz .2005 .14089 .4472)}",
20499    );
20500    minify_test(
20501      ".foo { color: color(xyz 0.2005 0.14089 0.4472); }",
20502      ".foo{color:color(xyz .2005 .14089 .4472)}",
20503    );
20504    minify_test(
20505      ".foo { color: color(xyz 20.05% 14.089% 44.72%); }",
20506      ".foo{color:color(xyz .2005 .14089 .4472)}",
20507    );
20508    minify_test(
20509      ".foo { color: color(xyz 0.2005 0 0); }",
20510      ".foo{color:color(xyz .2005 0 0)}",
20511    );
20512    minify_test(".foo { color: color(xyz 0 0 0); }", ".foo{color:color(xyz 0 0 0)}");
20513    minify_test(".foo { color: color(xyz 0 1 0); }", ".foo{color:color(xyz 0 1 0)}");
20514    minify_test(
20515      ".foo { color: color(xyz 0 1 0 / 20%); }",
20516      ".foo{color:color(xyz 0 1 0/.2)}",
20517    );
20518    minify_test(
20519      ".foo { color: color(xyz 0 0 0 / 20%); }",
20520      ".foo{color:color(xyz 0 0 0/.2)}",
20521    );
20522    minify_test(
20523      ".foo { color: color(display-p3 100% 50% 0 / 20%); }",
20524      ".foo{color:color(display-p3 1 .5 0/.2)}",
20525    );
20526    minify_test(
20527      ".foo { color: color(display-p3 100% 0 0 / 20%); }",
20528      ".foo{color:color(display-p3 1 0 0/.2)}",
20529    );
20530    minify_test(".foo { color: hsl(none none none) }", ".foo{color:#000}");
20531    minify_test(".foo { color: hwb(none none none) }", ".foo{color:red}");
20532    minify_test(".foo { color: rgb(none none none) }", ".foo{color:#000}");
20533
20534    // If the browser doesn't support `#rrggbbaa` color syntax, it is converted to `transparent`.
20535    attr_test(
20536      "color: rgba(0, 0, 0, 0)",
20537      "color:transparent",
20538      true,
20539      Some(Browsers {
20540        chrome: Some(61 << 16), // Chrome >= 62 supports `#rrggbbaa` color.
20541        ..Browsers::default()
20542      }),
20543    );
20544
20545    attr_test(
20546      "color: #0000",
20547      "color:transparent",
20548      true,
20549      Some(Browsers {
20550        chrome: Some(61 << 16), // Chrome >= 62 supports `#rrggbbaa` color.
20551        ..Browsers::default()
20552      }),
20553    );
20554
20555    attr_test(
20556      "color: transparent",
20557      "color:transparent",
20558      true,
20559      Some(Browsers {
20560        chrome: Some(61 << 16),
20561        ..Browsers::default()
20562      }),
20563    );
20564
20565    attr_test(
20566      "color: rgba(0, 0, 0, 0)",
20567      "color: rgba(0, 0, 0, 0)",
20568      false,
20569      Some(Browsers {
20570        chrome: Some(61 << 16),
20571        ..Browsers::default()
20572      }),
20573    );
20574
20575    attr_test(
20576      "color: rgba(255, 0, 0, 0)",
20577      "color:rgba(255,0,0,0)",
20578      true,
20579      Some(Browsers {
20580        chrome: Some(61 << 16),
20581        ..Browsers::default()
20582      }),
20583    );
20584
20585    attr_test(
20586      "color: rgba(255, 0, 0, 0)",
20587      "color:#f000",
20588      true,
20589      Some(Browsers {
20590        chrome: Some(62 << 16),
20591        ..Browsers::default()
20592      }),
20593    );
20594
20595    prefix_test(
20596      ".foo { color: rgba(123, 456, 789, 0.5) }",
20597      indoc! { r#"
20598        .foo {
20599          color: #7bffff80;
20600        }
20601      "#},
20602      Browsers {
20603        chrome: Some(95 << 16),
20604        ..Browsers::default()
20605      },
20606    );
20607
20608    prefix_test(
20609      ".foo { color: rgba(123, 255, 255, 0.5) }",
20610      indoc! { r#"
20611        .foo {
20612          color: rgba(123, 255, 255, .5);
20613        }
20614      "#},
20615      Browsers {
20616        ie: Some(11 << 16),
20617        ..Browsers::default()
20618      },
20619    );
20620
20621    prefix_test(
20622      ".foo { color: #7bffff80 }",
20623      indoc! { r#"
20624        .foo {
20625          color: rgba(123, 255, 255, .5);
20626        }
20627      "#},
20628      Browsers {
20629        ie: Some(11 << 16),
20630        ..Browsers::default()
20631      },
20632    );
20633
20634    prefix_test(
20635      ".foo { color: rgba(123, 456, 789, 0.5) }",
20636      indoc! { r#"
20637        .foo {
20638          color: rgba(123, 255, 255, .5);
20639        }
20640      "#},
20641      Browsers {
20642        firefox: Some(48 << 16),
20643        safari: Some(10 << 16),
20644        ios_saf: Some(9 << 16),
20645        ..Browsers::default()
20646      },
20647    );
20648
20649    prefix_test(
20650      ".foo { color: rgba(123, 456, 789, 0.5) }",
20651      indoc! { r#"
20652        .foo {
20653          color: #7bffff80;
20654        }
20655      "#},
20656      Browsers {
20657        firefox: Some(49 << 16),
20658        safari: Some(10 << 16),
20659        ios_saf: Some(10 << 16),
20660        ..Browsers::default()
20661      },
20662    );
20663
20664    prefix_test(
20665      ".foo { background-color: lab(40% 56.6 39) }",
20666      indoc! { r#"
20667        .foo {
20668          background-color: #b32323;
20669          background-color: lab(40% 56.6 39);
20670        }
20671      "#},
20672      Browsers {
20673        chrome: Some(90 << 16),
20674        ..Browsers::default()
20675      },
20676    );
20677
20678    prefix_test(
20679      ".foo { background-color: lch(40% 68.735435 34.568626) }",
20680      indoc! { r#"
20681        .foo {
20682          background-color: #b32323;
20683          background-color: lch(40% 68.7354 34.5686);
20684        }
20685      "#},
20686      Browsers {
20687        chrome: Some(90 << 16),
20688        ..Browsers::default()
20689      },
20690    );
20691
20692    prefix_test(
20693      ".foo { background-color: oklab(59.686% 0.1009 0.1192); }",
20694      indoc! { r#"
20695        .foo {
20696          background-color: #c65d07;
20697          background-color: lab(52.2319% 40.1449 59.9171);
20698        }
20699      "#},
20700      Browsers {
20701        chrome: Some(90 << 16),
20702        ..Browsers::default()
20703      },
20704    );
20705
20706    prefix_test(
20707      ".foo { background-color: oklch(40% 0.1268735435 34.568626) }",
20708      indoc! { r#"
20709        .foo {
20710          background-color: #7e250f;
20711          background-color: lab(29.2661% 38.2437 35.3889);
20712        }
20713      "#},
20714      Browsers {
20715        chrome: Some(90 << 16),
20716        ..Browsers::default()
20717      },
20718    );
20719
20720    prefix_test(
20721      ".foo { background-color: lab(40% 56.6 39) }",
20722      indoc! { r#"
20723        .foo {
20724          background-color: lab(40% 56.6 39);
20725        }
20726      "#},
20727      Browsers {
20728        safari: Some(15 << 16),
20729        ..Browsers::default()
20730      },
20731    );
20732
20733    prefix_test(
20734      ".foo { background-color: oklab(59.686% 0.1009 0.1192); }",
20735      indoc! { r#"
20736        .foo {
20737          background-color: #c65d07;
20738          background-color: lab(52.2319% 40.1449 59.9171);
20739        }
20740      "#},
20741      Browsers {
20742        chrome: Some(90 << 16),
20743        safari: Some(15 << 16),
20744        ..Browsers::default()
20745      },
20746    );
20747
20748    prefix_test(
20749      ".foo { background-color: oklab(59.686% 0.1009 0.1192); }",
20750      indoc! { r#"
20751        .foo {
20752          background-color: #c65d07;
20753          background-color: color(display-p3 .724144 .386777 .148795);
20754          background-color: lab(52.2319% 40.1449 59.9171);
20755        }
20756      "#},
20757      Browsers {
20758        chrome: Some(90 << 16),
20759        safari: Some(14 << 16),
20760        ..Browsers::default()
20761      },
20762    );
20763
20764    prefix_test(
20765      ".foo { background-color: lab(40% 56.6 39) }",
20766      indoc! { r#"
20767        .foo {
20768          background-color: #b32323;
20769          background-color: color(display-p3 .643308 .192455 .167712);
20770          background-color: lab(40% 56.6 39);
20771        }
20772      "#},
20773      Browsers {
20774        chrome: Some(90 << 16),
20775        safari: Some(14 << 16),
20776        ..Browsers::default()
20777      },
20778    );
20779
20780    prefix_test(
20781      ".foo { background-color: oklch(59.686% 0.15619 49.7694); }",
20782      indoc! { r#"
20783        .foo {
20784          background-color: #c65d06;
20785          background-color: lab(52.2321% 40.1417 59.9527);
20786        }
20787      "#},
20788      Browsers {
20789        chrome: Some(90 << 16),
20790        safari: Some(15 << 16),
20791        ..Browsers::default()
20792      },
20793    );
20794
20795    prefix_test(
20796      ".foo { background-color: color(sRGB 0.41587 0.503670 0.36664); }",
20797      indoc! { r#"
20798        .foo {
20799          background-color: #6a805d;
20800          background-color: color(srgb .41587 .50367 .36664);
20801        }
20802      "#},
20803      Browsers {
20804        chrome: Some(90 << 16),
20805        ..Browsers::default()
20806      },
20807    );
20808
20809    prefix_test(
20810      ".foo { background-color: color(display-p3 0.43313 0.50108 0.37950); }",
20811      indoc! { r#"
20812        .foo {
20813          background-color: #6a805d;
20814          background-color: color(display-p3 .43313 .50108 .3795);
20815        }
20816      "#},
20817      Browsers {
20818        chrome: Some(90 << 16),
20819        ..Browsers::default()
20820      },
20821    );
20822
20823    prefix_test(
20824      ".foo { background-color: color(display-p3 0.43313 0.50108 0.37950); }",
20825      indoc! { r#"
20826        .foo {
20827          background-color: #6a805d;
20828          background-color: color(display-p3 .43313 .50108 .3795);
20829        }
20830      "#},
20831      Browsers {
20832        chrome: Some(90 << 16),
20833        safari: Some(14 << 16),
20834        ..Browsers::default()
20835      },
20836    );
20837
20838    prefix_test(
20839      ".foo { background-color: color(display-p3 0.43313 0.50108 0.37950); }",
20840      indoc! { r#"
20841        .foo {
20842          background-color: color(display-p3 .43313 .50108 .3795);
20843        }
20844      "#},
20845      Browsers {
20846        safari: Some(14 << 16),
20847        ..Browsers::default()
20848      },
20849    );
20850
20851    prefix_test(
20852      ".foo { background-color: color(display-p3 0.43313 0.50108 0.37950); }",
20853      indoc! { r#"
20854        .foo {
20855          background-color: #6a805d;
20856          background-color: color(display-p3 .43313 .50108 .3795);
20857        }
20858      "#},
20859      Browsers {
20860        chrome: Some(90 << 16),
20861        safari: Some(15 << 16),
20862        ..Browsers::default()
20863      },
20864    );
20865
20866    prefix_test(
20867      ".foo { background-color: color(display-p3 0.43313 0.50108 0.37950); }",
20868      indoc! { r#"
20869        .foo {
20870          background-color: #6a805d;
20871          background-color: color(display-p3 .43313 .50108 .3795);
20872        }
20873      "#},
20874      Browsers {
20875        chrome: Some(90 << 16),
20876        ..Browsers::default()
20877      },
20878    );
20879
20880    prefix_test(
20881      ".foo { background-color: color(a98-rgb 0.44091 0.49971 0.37408); }",
20882      indoc! { r#"
20883        .foo {
20884          background-color: #6a805d;
20885          background-color: color(a98-rgb .44091 .49971 .37408);
20886        }
20887      "#},
20888      Browsers {
20889        chrome: Some(90 << 16),
20890        ..Browsers::default()
20891      },
20892    );
20893
20894    prefix_test(
20895      ".foo { background-color: color(a98-rgb 0.44091 0.49971 0.37408); }",
20896      indoc! { r#"
20897        .foo {
20898          background-color: color(a98-rgb .44091 .49971 .37408);
20899        }
20900      "#},
20901      Browsers {
20902        safari: Some(15 << 16),
20903        ..Browsers::default()
20904      },
20905    );
20906
20907    prefix_test(
20908      ".foo { background-color: color(prophoto-rgb 0.36589 0.41717 0.31333); }",
20909      indoc! { r#"
20910        .foo {
20911          background-color: #6a805d;
20912          background-color: color(prophoto-rgb .36589 .41717 .31333);
20913        }
20914      "#},
20915      Browsers {
20916        chrome: Some(90 << 16),
20917        ..Browsers::default()
20918      },
20919    );
20920
20921    prefix_test(
20922      ".foo { background-color: color(rec2020 0.42210 0.47580 0.35605); }",
20923      indoc! { r#"
20924        .foo {
20925          background-color: #728765;
20926          background-color: color(rec2020 .4221 .4758 .35605);
20927        }
20928      "#},
20929      Browsers {
20930        chrome: Some(90 << 16),
20931        ..Browsers::default()
20932      },
20933    );
20934
20935    prefix_test(
20936      ".foo { background-color: color(xyz-d50 0.2005 0.14089 0.4472); }",
20937      indoc! { r#"
20938        .foo {
20939          background-color: #7654cd;
20940          background-color: color(xyz-d50 .2005 .14089 .4472);
20941        }
20942      "#},
20943      Browsers {
20944        chrome: Some(90 << 16),
20945        ..Browsers::default()
20946      },
20947    );
20948
20949    prefix_test(
20950      ".foo { background-color: color(xyz-d65 0.21661 0.14602 0.59452); }",
20951      indoc! { r#"
20952        .foo {
20953          background-color: #7654cd;
20954          background-color: color(xyz .21661 .14602 .59452);
20955        }
20956      "#},
20957      Browsers {
20958        chrome: Some(90 << 16),
20959        ..Browsers::default()
20960      },
20961    );
20962
20963    prefix_test(
20964      ".foo { background-color: lch(50.998% 135.363 338) }",
20965      indoc! { r#"
20966        .foo {
20967          background-color: #f000c0;
20968          background-color: color(display-p3 .972962 -.362078 .804206);
20969          background-color: lch(50.998% 135.363 338);
20970        }
20971      "#},
20972      Browsers {
20973        chrome: Some(90 << 16),
20974        safari: Some(14 << 16),
20975        ..Browsers::default()
20976      },
20977    );
20978
20979    prefix_test(
20980      ".foo { color: lch(50.998% 135.363 338) }",
20981      indoc! { r#"
20982        .foo {
20983          color: #f000c0;
20984          color: color(display-p3 .972962 -.362078 .804206);
20985          color: lch(50.998% 135.363 338);
20986        }
20987      "#},
20988      Browsers {
20989        chrome: Some(90 << 16),
20990        safari: Some(14 << 16),
20991        ..Browsers::default()
20992      },
20993    );
20994
20995    prefix_test(
20996      ".foo { color: lab(98.2504% -7.697 88.7581) }",
20997      indoc! { r#"
20998        .foo {
20999          color: #fffc44;
21000          color: lab(98.2504% -7.697 88.7581);
21001        }
21002      "#},
21003      Browsers {
21004        chrome: Some(80 << 16),
21005        ..Browsers::default()
21006      },
21007    );
21008
21009    prefix_test(
21010      ".foo { color: color(prophoto-rgb 0.9784 0.9925 0.3037) }",
21011      indoc! { r#"
21012        .foo {
21013          color: #ffff6d;
21014          color: color(prophoto-rgb .9784 .9925 .3037);
21015        }
21016      "#},
21017      Browsers {
21018        chrome: Some(80 << 16),
21019        ..Browsers::default()
21020      },
21021    );
21022
21023    prefix_test(
21024      ".foo { color: lch(94.4698% 111.9227 117.6737deg) }",
21025      indoc! { r#"
21026        .foo {
21027          color: #b0ff00;
21028          color: lch(94.4698% 111.923 117.674);
21029        }
21030      "#},
21031      Browsers {
21032        chrome: Some(80 << 16),
21033        ..Browsers::default()
21034      },
21035    );
21036
21037    prefix_test(
21038      ".foo { color: oklch(99.995% .01 0) }",
21039      indoc! { r#"
21040        .foo {
21041          color: #fffcff;
21042          color: lab(99.8686% 3.37896 .0330329);
21043        }
21044      "#},
21045      Browsers {
21046        chrome: Some(80 << 16),
21047        ..Browsers::default()
21048      },
21049    );
21050
21051    prefix_test(
21052      ".foo { background: var(--image) lch(40% 68.735435 34.568626) }",
21053      indoc! { r#"
21054        .foo {
21055          background: var(--image) #b32323;
21056        }
21057
21058        @supports (color: lab(0% 0 0)) {
21059          .foo {
21060            background: var(--image) lab(40% 56.6 39);
21061          }
21062        }
21063      "#},
21064      Browsers {
21065        chrome: Some(90 << 16),
21066        ..Browsers::default()
21067      },
21068    );
21069
21070    prefix_test(
21071      r#"
21072        @supports (color: lab(0% 0 0)) {
21073          .foo {
21074            background: var(--image) lab(40% 56.6 39);
21075          }
21076        }
21077      "#,
21078      indoc! { r#"
21079        @supports (color: lab(0% 0 0)) {
21080          .foo {
21081            background: var(--image) lab(40% 56.6 39);
21082          }
21083        }
21084      "#},
21085      Browsers {
21086        chrome: Some(90 << 16),
21087        ..Browsers::default()
21088      },
21089    );
21090
21091    prefix_test(
21092      r#"
21093      .foo {
21094        color: red;
21095        color: lab(40% 56.6 39);
21096      }
21097    "#,
21098      indoc! {r#"
21099      .foo {
21100        color: red;
21101        color: lab(40% 56.6 39);
21102      }
21103    "#
21104      },
21105      Browsers {
21106        safari: Some(14 << 16),
21107        ..Browsers::default()
21108      },
21109    );
21110    prefix_test(
21111      r#"
21112      .foo {
21113        color: red;
21114        color: lab(40% 56.6 39);
21115      }
21116    "#,
21117      indoc! {r#"
21118      .foo {
21119        color: lab(40% 56.6 39);
21120      }
21121    "#
21122      },
21123      Browsers {
21124        safari: Some(16 << 16),
21125        ..Browsers::default()
21126      },
21127    );
21128
21129    prefix_test(
21130      r#"
21131      .foo {
21132        color: var(--fallback);
21133        color: lab(40% 56.6 39);
21134      }
21135    "#,
21136      indoc! {r#"
21137      .foo {
21138        color: var(--fallback);
21139        color: lab(40% 56.6 39);
21140      }
21141    "#
21142      },
21143      Browsers {
21144        safari: Some(14 << 16),
21145        ..Browsers::default()
21146      },
21147    );
21148
21149    prefix_test(
21150      r#"
21151      .foo {
21152        color: var(--fallback);
21153        color: lab(40% 56.6 39);
21154      }
21155    "#,
21156      indoc! {r#"
21157      .foo {
21158        color: lab(40% 56.6 39);
21159      }
21160    "#
21161      },
21162      Browsers {
21163        safari: Some(16 << 16),
21164        ..Browsers::default()
21165      },
21166    );
21167
21168    prefix_test(
21169      r#"
21170      .foo {
21171        color: red;
21172        color: var(--foo, lab(40% 56.6 39));
21173      }
21174    "#,
21175      indoc! {r#"
21176      .foo {
21177        color: var(--foo, color(display-p3 .643308 .192455 .167712));
21178      }
21179
21180      @supports (color: lab(0% 0 0)) {
21181        .foo {
21182          color: var(--foo, lab(40% 56.6 39));
21183        }
21184      }
21185    "#
21186      },
21187      Browsers {
21188        safari: Some(14 << 16),
21189        ..Browsers::default()
21190      },
21191    );
21192
21193    prefix_test(
21194      r#"
21195      @supports (color: lab(0% 0 0)) {
21196        .foo {
21197          color: var(--foo, lab(40% 56.6 39));
21198        }
21199      }
21200    "#,
21201      indoc! {r#"
21202      @supports (color: lab(0% 0 0)) {
21203        .foo {
21204          color: var(--foo, lab(40% 56.6 39));
21205        }
21206      }
21207    "#
21208      },
21209      Browsers {
21210        safari: Some(14 << 16),
21211        ..Browsers::default()
21212      },
21213    );
21214
21215    prefix_test(
21216      r#"
21217      .foo {
21218        --a: rgb(0 0 0 / var(--alpha));
21219        --b: rgb(50% 50% 50% / var(--alpha));
21220        --c: rgb(var(--x) 0 0);
21221        --d: rgb(0 var(--x) 0);
21222        --e: rgb(0 0 var(--x));
21223        --f: rgb(var(--x) 0 0 / var(--alpha));
21224        --g: rgb(0 var(--x) 0 / var(--alpha));
21225        --h: rgb(0 0 var(--x) / var(--alpha));
21226        --i: rgb(none 0 0 / var(--alpha));
21227        --j: rgb(from yellow r g b / var(--alpha));
21228      }
21229      "#,
21230      indoc! { r#"
21231        .foo {
21232          --a: rgba(0, 0, 0, var(--alpha));
21233          --b: rgba(128, 128, 128, var(--alpha));
21234          --c: rgb(var(--x) 0 0);
21235          --d: rgb(0 var(--x) 0);
21236          --e: rgb(0 0 var(--x));
21237          --f: rgb(var(--x) 0 0 / var(--alpha));
21238          --g: rgb(0 var(--x) 0 / var(--alpha));
21239          --h: rgb(0 0 var(--x) / var(--alpha));
21240          --i: rgb(none 0 0 / var(--alpha));
21241          --j: rgba(255, 255, 0, var(--alpha));
21242        }
21243      "#},
21244      Browsers {
21245        safari: Some(11 << 16),
21246        ..Browsers::default()
21247      },
21248    );
21249
21250    prefix_test(
21251      r#"
21252      .foo {
21253        --a: rgb(0 0 0 / var(--alpha));
21254        --b: rgb(50% 50% 50% / var(--alpha));
21255        --c: rgb(var(--x) 0 0);
21256        --d: rgb(0 var(--x) 0);
21257        --e: rgb(0 0 var(--x));
21258        --f: rgb(var(--x) 0 0 / var(--alpha));
21259        --g: rgb(0 var(--x) 0 / var(--alpha));
21260        --h: rgb(0 0 var(--x) / var(--alpha));
21261        --i: rgb(none 0 0 / var(--alpha));
21262        --j: rgb(from yellow r g b / var(--alpha));
21263      }
21264      "#,
21265      indoc! { r#"
21266        .foo {
21267          --a: rgb(0 0 0 / var(--alpha));
21268          --b: rgb(128 128 128 / var(--alpha));
21269          --c: rgb(var(--x) 0 0);
21270          --d: rgb(0 var(--x) 0);
21271          --e: rgb(0 0 var(--x));
21272          --f: rgb(var(--x) 0 0 / var(--alpha));
21273          --g: rgb(0 var(--x) 0 / var(--alpha));
21274          --h: rgb(0 0 var(--x) / var(--alpha));
21275          --i: rgb(none 0 0 / var(--alpha));
21276          --j: rgb(255 255 0 / var(--alpha));
21277        }
21278      "#},
21279      Browsers {
21280        safari: Some(13 << 16),
21281        ..Browsers::default()
21282      },
21283    );
21284
21285    prefix_test(
21286      r#"
21287      .foo {
21288        --a: hsl(270 100% 50% / var(--alpha));
21289        --b: hsl(var(--x) 0 0);
21290        --c: hsl(0 var(--x) 0);
21291        --d: hsl(0 0 var(--x));
21292        --e: hsl(var(--x) 0 0 / var(--alpha));
21293        --f: hsl(0 var(--x) 0 / var(--alpha));
21294        --g: hsl(0 0 var(--x) / var(--alpha));
21295        --h: hsl(270 100% 50% / calc(var(--alpha) / 2));
21296        --i: hsl(none 100% 50% / var(--alpha));
21297        --j: hsl(from yellow h s l / var(--alpha));
21298      }
21299      "#,
21300      indoc! { r#"
21301        .foo {
21302          --a: hsla(270, 100%, 50%, var(--alpha));
21303          --b: hsl(var(--x) 0 0);
21304          --c: hsl(0 var(--x) 0);
21305          --d: hsl(0 0 var(--x));
21306          --e: hsl(var(--x) 0 0 / var(--alpha));
21307          --f: hsl(0 var(--x) 0 / var(--alpha));
21308          --g: hsl(0 0 var(--x) / var(--alpha));
21309          --h: hsla(270, 100%, 50%, calc(var(--alpha) / 2));
21310          --i: hsl(none 100% 50% / var(--alpha));
21311          --j: hsla(60, 100%, 50%, var(--alpha));
21312        }
21313      "#},
21314      Browsers {
21315        safari: Some(11 << 16),
21316        ..Browsers::default()
21317      },
21318    );
21319
21320    prefix_test(
21321      r#"
21322      .foo {
21323        --a: hsl(270 100% 50% / var(--alpha));
21324        --b: hsl(var(--x) 0 0);
21325        --c: hsl(0 var(--x) 0);
21326        --d: hsl(0 0 var(--x));
21327        --e: hsl(var(--x) 0 0 / var(--alpha));
21328        --f: hsl(0 var(--x) 0 / var(--alpha));
21329        --g: hsl(0 0 var(--x) / var(--alpha));
21330        --h: hsl(270 100% 50% / calc(var(--alpha) / 2));
21331        --i: hsl(none 100% 50% / var(--alpha));
21332      }
21333      "#,
21334      indoc! { r#"
21335        .foo {
21336          --a: hsl(270 100% 50% / var(--alpha));
21337          --b: hsl(var(--x) 0 0);
21338          --c: hsl(0 var(--x) 0);
21339          --d: hsl(0 0 var(--x));
21340          --e: hsl(var(--x) 0 0 / var(--alpha));
21341          --f: hsl(0 var(--x) 0 / var(--alpha));
21342          --g: hsl(0 0 var(--x) / var(--alpha));
21343          --h: hsl(270 100% 50% / calc(var(--alpha) / 2));
21344          --i: hsl(none 100% 50% / var(--alpha));
21345        }
21346      "#},
21347      Browsers {
21348        safari: Some(13 << 16),
21349        ..Browsers::default()
21350      },
21351    );
21352
21353    test(
21354      r#"
21355      .foo {
21356        --a: rgb(50% 50% 50% / calc(100% / 2));
21357        --b: hsl(calc(360deg / 2) 50% 50%);
21358        --c: oklab(40.101% calc(0.1 + 0.2) 0.0453);
21359        --d: color(display-p3 0.43313 0.50108 calc(0.1 + 0.2));
21360        --e: rgb(calc(255 / 2), calc(255 / 2), calc(255 / 2));
21361      }
21362      "#,
21363      indoc! { r#"
21364        .foo {
21365          --a: #80808080;
21366          --b: #40bfbf;
21367          --c: oklab(40.101% .3 .0453);
21368          --d: color(display-p3 .43313 .50108 .3);
21369          --e: gray;
21370        }
21371      "#},
21372    );
21373  }
21374
21375  #[test]
21376  fn test_relative_color() {
21377    #[track_caller]
21378    fn test(input: &str, output: &str) {
21379      let parsed = match CssColor::parse_string(output) {
21380        Ok(c) => c,
21381        Err(e) => panic!(
21382          "test_relative_color: parse expected output failed\nerror: {e:?}\ninput: {input}\noutput: {output}",
21383        ),
21384      };
21385      let output_css = match parsed.to_css_string(PrinterOptions {
21386        minify: true,
21387        ..PrinterOptions::default()
21388      }) {
21389        Ok(s) => s,
21390        Err(e) => panic!(
21391          "test_relative_color: stringify expected output failed\nerror: {e}\nerror(debug): {e:?}\ninput: {input}\noutput: {output}",
21392        ),
21393      };
21394      minify_test(
21395        &format!(".foo {{ color: {} }}", input),
21396        &format!(".foo{{color:{}}}", output_css),
21397      );
21398    }
21399
21400    test("lab(from indianred calc(l * .8) a b)", "lab(43.1402% 45.7516 23.1557)");
21401    test("lch(from indianred calc(l + 10) c h)", "lch(63.9252% 51.2776 26.8448)");
21402    test("lch(from indianred l calc(c - 50) h)", "lch(53.9252% 1.27763 26.8448)");
21403    test(
21404      "lch(from indianred l c calc(h + 180deg))",
21405      "lch(53.9252% 51.2776 206.845)",
21406    );
21407    test("lch(from orchid l 30 h)", "lch(62.7526% 30 326.969)");
21408    test("lch(from orchid l 30 h)", "lch(62.7526% 30 326.969)");
21409    test("lch(from peru calc(l * 0.8) c h)", "lch(49.8022% 54.0117 63.6804)");
21410    test("rgb(from indianred 255 g b)", "rgb(255, 92, 92)");
21411    test("rgb(from indianred r g b / .5)", "rgba(205, 92, 92, .5)");
21412    test(
21413      "rgb(from rgba(205, 92, 92, .5) r g b / calc(alpha + .2))",
21414      "rgba(205, 92, 92, .7)",
21415    );
21416    test(
21417      "rgb(from rgba(205, 92, 92, .5) r g b / calc(alpha + .2))",
21418      "rgba(205, 92, 92, .7)",
21419    );
21420    test("lch(from indianred l sin(c) h)", "lch(53.9252% .84797 26.8448)");
21421    test("lch(from indianred l sqrt(c) h)", "lch(53.9252% 7.16084 26.8448)");
21422    test("lch(from indianred l c sin(h))", "lch(53.9252% 51.2776 .451575)");
21423    test("lch(from indianred calc(10% + 20%) c h)", "lch(30% 51.2776 26.8448)");
21424    test("lch(from indianred calc(10 + 20) c h)", "lch(30% 51.2776 26.8448)");
21425    test("lch(from indianred l c calc(10 + 20))", "lch(53.9252% 51.2776 30)");
21426    test(
21427      "lch(from indianred l c calc(10deg + 20deg))",
21428      "lch(53.9252% 51.2776 30)",
21429    );
21430    test(
21431      "lch(from indianred l c calc(10deg + 0.35rad))",
21432      "lch(53.9252% 51.2776 30.0535)",
21433    );
21434    minify_test(
21435      ".foo{color:lch(from currentColor l c sin(h))}",
21436      ".foo{color:lch(from currentColor l c sin(h))}",
21437    );
21438
21439    // The following tests were converted from WPT:
21440    // https://github.com/web-platform-tests/wpt/blob/master/css/css-color/parsing/alpha-color-parsing-valid.html
21441
21442    // Basic usage with literal alpha.
21443    test("alpha(from red / 0.5)", "rgba(255, 0, 0, 0.5)");
21444    test("alpha(from blue / 1)", "rgb(0, 0, 255)");
21445    test("alpha(from green / 0)", "rgba(0, 128, 0, 0)");
21446
21447    // Percentage alpha.
21448    test("alpha(from red / 50%)", "rgba(255, 0, 0, 0.5)");
21449    test("alpha(from red / 0%)", "rgba(255, 0, 0, 0)");
21450    test("alpha(from red / 100%)", "rgb(255, 0, 0)");
21451
21452    // None alpha.
21453    test("alpha(from red / none)", "rgba(255, 0, 0, 0)");
21454
21455    // Omitted alpha (defaults to origin's alpha).
21456    test("alpha(from red)", "rgb(255, 0, 0)");
21457    // test() does not support keywords such as currentcolor; change it to minify_test()
21458    minify_test(
21459      ".foo{color:alpha(from currentcolor)}",
21460      ".foo{color:alpha(from currentcolor)}",
21461    );
21462
21463    // Alpha keyword referencing origin's alpha.
21464    minify_test(
21465      ".foo{color:alpha(from currentcolor / alpha)}",
21466      ".foo{color:alpha(from currentcolor / alpha)}",
21467    );
21468    test("alpha(from rgba(255, 0, 0, 0.8) / alpha)", "rgba(255, 0, 0, 0.8)");
21469
21470    // Calc with alpha keyword.
21471    test(
21472      "alpha(from rgba(255, 0, 0, 0.8) / calc(alpha * 0.5))",
21473      "rgba(255, 0, 0, 0.4)",
21474    );
21475    test(
21476      "alpha(from rgba(255, 0, 0, 0.8) / calc(alpha + 0.1))",
21477      "rgba(255, 0, 0, 0.9)",
21478    );
21479
21480    // Supplementary testing
21481    // TODO: calc does not support division by zero yet, so `alpha / 0` fails while `alpha / 1` works.
21482    // Depends on: https://github.com/parcel-bundler/lightningcss/pull/1122
21483    // test(
21484    //   "alpha(from green / calc(alpha / 0))",
21485    //   "rgb(0, 128, 0)",
21486    // );
21487    test("alpha(from green / calc(alpha / 1))", "rgb(0, 128, 0)");
21488
21489    // Test sibling-index() and sibling-count()
21490    minify_test(
21491      ".foo{color:alpha(from green / sibling-index())}",
21492      ".foo{color:alpha(from green / sibling-index())}",
21493    );
21494    minify_test(
21495      ".foo{color:alpha(from green / calc(sibling-index() * 0.2))}",
21496      ".foo{color:alpha(from green / calc(sibling-index() * .2))}",
21497    );
21498    minify_test(
21499      ".foo{color:alpha(from green / sibling-count())}",
21500      ".foo{color:alpha(from green / sibling-count())}",
21501    );
21502
21503    // Nested in other color functions.
21504    minify_test(
21505      ".foo{color:color-mix(in srgb, alpha(from red / 0.5), blue)}",
21506      ".foo{color:#5500aabf}",
21507    );
21508    test("rgb(from alpha(from red / 0.5) r g b / alpha)", "rgba(255, 0, 0, 0.5)");
21509
21510    // Other color functions as origin.
21511    test("alpha(from color-mix(in srgb, red, blue) / 0.5)", "#80008080");
21512    test("alpha(from rgb(from red r g b) / 0.8)", "rgba(255, 0, 0, 0.8)");
21513
21514    // Non-sRGB color spaces preserved.
21515    test(
21516      "alpha(from color(display-p3 1 0 0) / 0.5)",
21517      "color(display-p3 1 0 0 / 0.5)",
21518    );
21519    test("alpha(from lab(50 20 -30) / 0.5)", "lab(50% 20 -30 / 0.5)");
21520    test("alpha(from oklch(0.5 0.2 120) / 0.5)", "oklch(50% 0.2 120 / 0.5)");
21521
21522    // System and named colors.
21523    // https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/system-color#syntax
21524    minify_test(
21525      ".foo{color:alpha(from ActiveText / 0.5)}",
21526      ".foo{color:alpha(from ActiveText / .5)}",
21527    );
21528
21529    // Out-of-range alpha values.
21530    test("alpha(from red / 2)", "rgb(255, 0, 0)");
21531    test("alpha(from red / -1)", "rgba(255, 0, 0, 0)");
21532
21533    // Supplementary testing
21534    // nested alpha() precision.
21535    test("alpha(from alpha(from red / 0.5) / calc(alpha + 0.25))", "#ff0000bf");
21536    test("alpha(from alpha(from red / -0.5) / calc(alpha + 0.6))", "#f009");
21537    test("alpha(from alpha(from green / 0%) / 100%)", "green");
21538
21539    // Unresolved relative colors keep their tokens.
21540    minify_test(
21541      ".foo{color:rgb(from alpha(from currentColor / 0.5) r g b)}",
21542      ".foo{color:rgb(from alpha(from currentColor / .5) r g b)}",
21543    );
21544    minify_test(
21545      ".foo{color:alpha(from red / var(--alpha))}",
21546      ".foo{color:alpha(from red / var(--alpha))}",
21547    );
21548
21549    // RGBA origin alpha preserve/replace.
21550    test("alpha(from rgba(255, 0, 0, 0.3))", "rgba(255, 0, 0, 0.3)");
21551    test("alpha(from rgba(255, 0, 0, 0.3) / 0.8)", "rgba(255, 0, 0, 0.8)");
21552
21553    // color(srgb) preserves its color space.
21554    test("alpha(from color(srgb 1 0 0) / 50%)", "color(srgb 1 0 0 / 0.5)");
21555
21556    // alpha() nested in more relative color functions.
21557    test("hsl(from alpha(from red / 0.5) h s l / alpha)", "rgba(255, 0, 0, 0.5)");
21558    test("hwb(from alpha(from red / 0.5) h w b / alpha)", "rgba(255, 0, 0, 0.5)");
21559    test(
21560      "lab(from alpha(from lab(50% 20 -30) / 0.5) l a b / alpha)",
21561      "lab(50% 20 -30 / 0.5)",
21562    );
21563    test(
21564      "lch(from alpha(from lch(50% 20 30) / 0.5) l c h / alpha)",
21565      "lch(50% 20 30 / 0.5)",
21566    );
21567    test(
21568      "oklab(from alpha(from oklab(50% 0.2 -0.3) / 0.5) l a b / alpha)",
21569      "oklab(50% 0.2 -0.3 / 0.5)",
21570    );
21571    test(
21572      "oklch(from alpha(from oklch(50% 0.2 120) / 0.5) l c h / alpha)",
21573      "oklch(50% 0.2 120 / 0.5)",
21574    );
21575    test(
21576      "color(from alpha(from color(display-p3 1 0 0) / 0.5) display-p3 r g b / alpha)",
21577      "color(display-p3 1 0 0 / 0.5)",
21578    );
21579    test(
21580      "color(from alpha(from red / 1.5) srgb r g b / calc(alpha - 0.2))",
21581      "color(srgb 1 0 0 / 0.8)", // alpha = 1 - 0.2
21582    );
21583
21584    // Test in image()
21585    minify_test(".foo { mask: image(alpha(from red / 1))}", ".foo{mask:image(red)}");
21586
21587    // Test in linear-gradient()
21588    minify_test(
21589      ".foo { mask: linear-gradient(90deg, alpha(from red / 0%), red) }",
21590      ".foo{mask:linear-gradient(90deg,#f000,red)}",
21591    );
21592    // Compare relative color
21593    // TODO: Support <color-interpolation-method>
21594    minify_test(
21595      ".foo { mask: linear-gradient(90deg in hsl longer hue, rgb(from red r g b / 0), red) }",
21596      ".foo{mask:linear-gradient(90deg in hsl longer hue, #f000, red)}",
21597    );
21598    minify_test(
21599      ".foo { mask: linear-gradient(90deg in hsl longer hue, alpha(from red / 0%), red) }",
21600      ".foo{mask:linear-gradient(90deg in hsl longer hue, #f000, red)}",
21601    );
21602
21603    minify_test(
21604      ".foo { color: alpha(from color(display-p3 1 0 0) / 0.5) }",
21605      ".foo{color:color(display-p3 1 0 0/.5)}",
21606    );
21607
21608    // The following tests were converted from WPT: https://github.com/web-platform-tests/wpt/blob/master/css/css-color/parsing/relative-color-valid.html
21609    // Find: test_valid_value\(`color`, `(.*?)`,\s*`(.*?)`\)
21610    // Replace: test("$1", "$2")
21611
21612    // Testing no modifications.
21613    test("rgb(from rebeccapurple r g b)", "#639");
21614    test("rgb(from rebeccapurple r g b / alpha)", "#639");
21615    test("rgb(from rgb(20%, 40%, 60%, 80%) r g b / alpha)", "#369c");
21616    test("rgb(from rgb(20%, 40%, 60%, 80%) r g b)", "#369c");
21617    test("rgb(from hsl(120deg 20% 50% / .5) r g b / alpha)", "#66996680");
21618    test("rgb(from rgb(255 0 0 / 50%) r g b)", "rgba(255, 0, 0, 0.5)");
21619    test("rgb(from rgb(255, 0, 0, 0) r g b)", "#f000");
21620    test("rgb(from color(srgb 1 0 0 / 50%) r g b)", "rgba(255, 0, 0, 0.5)");
21621    test(
21622      "rgb(from color(srgb 1 0 0 / 50%) r g b / alpha)",
21623      "rgba(255, 0, 0, 0.5)",
21624    );
21625    test(
21626      "color(from color(srgb 1 0 0 / 50%) srgb r g b)",
21627      "color(srgb 1 0 0 / 0.5)",
21628    );
21629    test(
21630      "color(from color(srgb 1 0 0 / 50%) srgb r g b / alpha)",
21631      "color(srgb 1 0 0 / 0.5)",
21632    );
21633
21634    // Test with alpha()
21635    test(
21636      "color(from alpha(from red / 0.5) srgb r g b)",
21637      "color(srgb 1 0 0 / 0.5)",
21638    );
21639    test(
21640      "color(from alpha(from red / 0.5) srgb r g b / alpha)",
21641      "color(srgb 1 0 0 / 0.5)",
21642    );
21643    test(
21644      "color(from alpha(from red / 0.5) srgb r g b / 0.8)",
21645      "color(srgb 1 0 0 / 0.8)",
21646    );
21647    test(
21648      "color(from alpha(from rgba(255, 0, 0, 1) / 0.5) srgb r g b)",
21649      "color(srgb 1 0 0 / 0.5)",
21650    );
21651    // TODO: Floating-point precision issue; the current result is: .501961
21652    // test("color(from alpha(from rgb(255 0 0 / 50%) / alpha) srgb r g b)", "color(srgb 1 0 0 / 0.5)");
21653
21654    // Explicit alpha overrides the inherited value.
21655    test("rgb(from rgb(255 0 0 / 0.8) r g b / 1)", "red");
21656    test("rgb(from rgb(255 0 0 / 0) r g b / 1)", "red");
21657    test("rgb(from rgb(255 0 0 / 50%) r g b / none)", "rgba(255, 0, 0, 0)");
21658    test("rgb(from color(srgb 1 0 0) r g b / 80%)", "rgba(255, 0, 0, 0.8)");
21659    test(
21660      "rgb(from color(srgb 1 0 0 / 0.5) r g b / calc(alpha - 0.3))",
21661      "rgba(255, 0, 0, 0.2)",
21662    );
21663    test(
21664      "color(from color(display-p3 0.7 0.5 0.3 / 0.4) display-p3 r g b / .6)",
21665      "color(display-p3 0.7 0.5 0.3 / 0.6)",
21666    );
21667    test(
21668      "color(from color(srgb 1 0 0) srgb r g b / 0.5)",
21669      "color(srgb 1 0 0 / 0.5)",
21670    );
21671    test(
21672      "color(from color(srgb 1 0 0 / 100%) srgb r g b / 50%)",
21673      "color(srgb 1 0 0 / 0.5)",
21674    );
21675
21676    // Test nesting relative colors.
21677    test("rgb(from rgb(from rebeccapurple r g b) r g b)", "#639");
21678    test("rgb(from rgb(from rgb(255 0 0 / 0.8) g b r) r g b)", "#00fc");
21679
21680    // Testing non-sRGB origin colors to see gamut mapping.
21681    test("rgb(from color(display-p3 0 1 0) r g b / alpha)", "#00fb29"); // Naive clip based mapping would give rgb(0, 255, 0).
21682    test("rgb(from lab(100% 104.3 -50.9) r g b)", "#fff"); // Naive clip based mapping would give rgb(255, 150, 255).
21683    test("rgb(from lab(0% 104.3 -50.9) r g b)", "#2a0022"); // Naive clip based mapping would give rgb(90, 0, 76). NOTE: 0% lightness in Lab/LCH does not automatically correspond with sRGB black.
21684    test("rgb(from lch(100% 116 334) r g b)", "#fff"); // Naive clip based mapping would give rgb(255, 150, 255).
21685    test("rgb(from lch(0% 116 334) r g b)", "#2a0022"); // Naive clip based mapping would give rgb(90, 0, 76). NOTE: 0% lightness in Lab/LCH does not automatically correspond with sRGB black.
21686    test("rgb(from oklab(100% 0.365 -0.16) r g b)", "#fff"); // Naive clip based mapping would give rgb(255, 92, 255).
21687    test("rgb(from oklab(0% 0.365 -0.16) r g b)", "#000"); // Naive clip based mapping would give rgb(19, 0, 24).
21688    test("rgb(from oklch(100% 0.399 336.3) r g b)", "#fff"); // Naive clip based mapping would give rgb(255, 91, 255).
21689    test("rgb(from oklch(0% 0.399 336.3) r g b)", "#000"); // Naive clip based mapping would give rgb(20, 0, 24).
21690
21691    // Testing replacement with 0.
21692    test("rgb(from rebeccapurple 0 0 0)", "rgb(0, 0, 0)");
21693    test("rgb(from rebeccapurple 0 0 0 / 0)", "rgba(0, 0, 0, 0)");
21694    test("rgb(from rebeccapurple 0 g b / alpha)", "rgb(0, 51, 153)");
21695    test("rgb(from rebeccapurple r 0 b / alpha)", "rgb(102, 0, 153)");
21696    test("rgb(from rebeccapurple r g 0 / alpha)", "rgb(102, 51, 0)");
21697    test("rgb(from rebeccapurple r g b / 0)", "rgba(102, 51, 153, 0)");
21698    test(
21699      "rgb(from rgb(20%, 40%, 60%, 80%) 0 g b / alpha)",
21700      "rgba(0, 102, 153, 0.8)",
21701    );
21702    test(
21703      "rgb(from rgb(20%, 40%, 60%, 80%) r 0 b / alpha)",
21704      "rgba(51, 0, 153, 0.8)",
21705    );
21706    test(
21707      "rgb(from rgb(20%, 40%, 60%, 80%) r g 0 / alpha)",
21708      "rgba(51, 102, 0, 0.8)",
21709    );
21710    test("rgb(from rgb(20%, 40%, 60%, 80%) r g b / 0)", "rgba(51, 102, 153, 0)");
21711
21712    // Testing replacement with a number.
21713    test("rgb(from rebeccapurple 25 g b / alpha)", "rgb(25, 51, 153)");
21714    test("rgb(from rebeccapurple r 25 b / alpha)", "rgb(102, 25, 153)");
21715    test("rgb(from rebeccapurple r g 25 / alpha)", "rgb(102, 51, 25)");
21716    test("rgb(from rebeccapurple r g b / .25)", "rgba(102, 51, 153, 0.25)");
21717    test(
21718      "rgb(from rgb(20%, 40%, 60%, 80%) 25 g b / alpha)",
21719      "rgba(25, 102, 153, 0.8)",
21720    );
21721    test(
21722      "rgb(from rgb(20%, 40%, 60%, 80%) r 25 b / alpha)",
21723      "rgba(51, 25, 153, 0.8)",
21724    );
21725    test(
21726      "rgb(from rgb(20%, 40%, 60%, 80%) r g 25 / alpha)",
21727      "rgba(51, 102, 25, 0.8)",
21728    );
21729    test(
21730      "rgb(from rgb(20%, 40%, 60%, 80%) r g b / .20)",
21731      "rgba(51, 102, 153, 0.2)",
21732    );
21733
21734    // Testing replacement with a percentage.
21735    test("rgb(from rebeccapurple 20% g b / alpha)", "rgb(51, 51, 153)");
21736    test("rgb(from rebeccapurple r 20% b / alpha)", "rgb(102, 51, 153)");
21737    test("rgb(from rebeccapurple r g 20% / alpha)", "rgb(102, 51, 51)");
21738    test("rgb(from rebeccapurple r g b / 20%)", "rgba(102, 51, 153, 0.2)");
21739    test(
21740      "rgb(from rgb(20%, 40%, 60%, 80%) 20% g b / alpha)",
21741      "rgba(51, 102, 153, 0.8)",
21742    );
21743    test(
21744      "rgb(from rgb(20%, 40%, 60%, 80%) r 20% b / alpha)",
21745      "rgba(51, 51, 153, 0.8)",
21746    );
21747    test(
21748      "rgb(from rgb(20%, 40%, 60%, 80%) r g 20% / alpha)",
21749      "rgba(51, 102, 51, 0.8)",
21750    );
21751    test(
21752      "rgb(from rgb(20%, 40%, 60%, 80%) r g b / 20%)",
21753      "rgba(51, 102, 153, 0.2)",
21754    );
21755
21756    // Testing replacement with a number for r, g, b but percent for alpha.
21757    test("rgb(from rebeccapurple 25 g b / 25%)", "rgba(25, 51, 153, 0.25)");
21758    test("rgb(from rebeccapurple r 25 b / 25%)", "rgba(102, 25, 153, 0.25)");
21759    test("rgb(from rebeccapurple r g 25 / 25%)", "rgba(102, 51, 25, 0.25)");
21760    test(
21761      "rgb(from rgb(20%, 40%, 60%, 80%) 25 g b / 25%)",
21762      "rgba(25, 102, 153, 0.25)",
21763    );
21764    test(
21765      "rgb(from rgb(20%, 40%, 60%, 80%) r 25 b / 25%)",
21766      "rgba(51, 25, 153, 0.25)",
21767    );
21768    test(
21769      "rgb(from rgb(20%, 40%, 60%, 80%) r g 25 / 25%)",
21770      "rgba(51, 102, 25, 0.25)",
21771    );
21772
21773    // Testing permutation.
21774    test("rgb(from rebeccapurple g b r)", "rgb(51, 153, 102)");
21775    test("rgb(from rebeccapurple b alpha r / g)", "rgba(153, 1, 102, 1)");
21776    test("rgb(from rebeccapurple r r r / r)", "rgba(102, 102, 102, 1)");
21777    test("rgb(from rebeccapurple alpha alpha alpha / alpha)", "rgb(1, 1, 1)");
21778    test("rgb(from rgb(20%, 40%, 60%, 80%) g b r)", "rgba(102, 153, 51, 0.8)");
21779    test("rgb(from rgb(20%, 40%, 60%, 80%) b alpha r / g)", "rgba(153, 1, 51, 1)");
21780    test("rgb(from rgb(20%, 40%, 60%, 80%) r r r / r)", "rgba(51, 51, 51, 1)");
21781    test(
21782      "rgb(from rgb(20%, 40%, 60%, 80%) alpha alpha alpha / alpha)",
21783      "rgba(1, 1, 1, 0.8)",
21784    );
21785
21786    // Testing mixes of number and percentage. (These would not be allowed in the non-relative syntax).
21787    test("rgb(from rebeccapurple r 20% 10)", "rgb(102, 51, 10)");
21788    test("rgb(from rebeccapurple r 10 20%)", "rgb(102, 10, 51)");
21789    test("rgb(from rebeccapurple 0% 10 10)", "rgb(0, 10, 10)");
21790    test("rgb(from rgb(20%, 40%, 60%, 80%) r 20% 10)", "rgba(51, 51, 10, 0.8)");
21791    test("rgb(from rgb(20%, 40%, 60%, 80%) r 10 20%)", "rgba(51, 10, 51, 0.8)");
21792    test("rgb(from rgb(20%, 40%, 60%, 80%) 0% 10 10)", "rgba(0, 10, 10, 0.8)");
21793
21794    // Testing with calc().
21795    test("rgb(from rebeccapurple calc(r) calc(g) calc(b))", "rgb(102, 51, 153)");
21796    test("rgb(from rebeccapurple r calc(g * 2) 10)", "rgb(102, 102, 10)");
21797    test("rgb(from rebeccapurple b calc(r * .5) 10)", "rgb(153, 51, 10)");
21798    test("rgb(from rebeccapurple r calc(g * .5 + g * .5) 10)", "rgb(102, 51, 10)");
21799    test("rgb(from rebeccapurple r calc(b * .5 - g * .5) 10)", "rgb(102, 51, 10)");
21800    test(
21801      "rgb(from rgb(20%, 40%, 60%, 80%) calc(r) calc(g) calc(b) / calc(alpha))",
21802      "rgba(51, 102, 153, 0.8)",
21803    );
21804
21805    // Testing with 'none'.
21806    test("rgb(from rebeccapurple none none none)", "rgb(0, 0, 0)");
21807    test("rgb(from rebeccapurple none none none / none)", "rgba(0, 0, 0, 0)");
21808    test("rgb(from rebeccapurple r g none)", "rgb(102, 51, 0)");
21809    test("rgb(from rebeccapurple r g none / alpha)", "rgb(102, 51, 0)");
21810    test("rgb(from rebeccapurple r g b / none)", "rgba(102, 51, 153, 0)");
21811    test(
21812      "rgb(from rgb(20% 40% 60% / 80%) r g none / alpha)",
21813      "rgba(51, 102, 0, 0.8)",
21814    );
21815    test("rgb(from rgb(20% 40% 60% / 80%) r g b / none)", "rgba(51, 102, 153, 0)");
21816    // FIXME: Clarify with spec editors if 'none' should pass through to the constants.
21817    test("rgb(from rgb(none none none) r g b)", "rgb(0, 0, 0)");
21818    test("rgb(from rgb(none none none / none) r g b / alpha)", "rgba(0, 0, 0, 0)");
21819    test("rgb(from rgb(20% none 60%) r g b)", "rgb(51, 0, 153)");
21820    test(
21821      "rgb(from rgb(20% 40% 60% / none) r g b / alpha)",
21822      "rgba(51, 102, 153, 0)",
21823    );
21824
21825    // hsl(from ...)
21826
21827    // Testing no modifications.
21828    test("hsl(from rebeccapurple h s l)", "rgb(102, 51, 153)");
21829    test("hsl(from rebeccapurple h s l / alpha)", "rgb(102, 51, 153)");
21830    test(
21831      "hsl(from rgb(20%, 40%, 60%, 80%) h s l / alpha)",
21832      "rgba(51, 102, 153, 0.8)",
21833    );
21834    test(
21835      "hsl(from hsl(120deg 20% 50% / .5) h s l / alpha)",
21836      "rgba(102, 153, 102, 0.5)",
21837    );
21838
21839    // Test nesting relative colors.
21840    test("hsl(from hsl(from rebeccapurple h s l) h s l)", "rgb(102, 51, 153)");
21841
21842    // Testing non-sRGB origin colors to see gamut mapping.
21843    test("hsl(from color(display-p3 0 1 0) h s l / alpha)", "rgb(0, 251, 41)"); // Naive clip based mapping would give rgb(0, 255, 0).
21844    test("hsl(from lab(100% 104.3 -50.9) h s l)", "rgb(255, 255, 255)"); // Naive clip based mapping would give rgb(255, 150, 255).
21845    test("hsl(from lab(0% 104.3 -50.9) h s l)", "rgb(42, 0, 34)"); // Naive clip based mapping would give rgb(90, 0, 76). NOTE: 0% lightness in Lab/LCH does not automatically correspond with sRGB black,
21846    test("hsl(from lch(100% 116 334) h s l)", "rgb(255, 255, 255)"); // Naive clip based mapping would give rgb(255, 150, 255).
21847    test("hsl(from lch(0% 116 334) h s l)", "rgb(42, 0, 34)"); // Naive clip based mapping would give rgb(90, 0, 76). NOTE: 0% lightness in Lab/LCH does not automatically correspond with sRGB black,
21848    test("hsl(from oklab(100% 0.365 -0.16) h s l)", "rgb(255, 255, 255)"); // Naive clip based mapping would give rgb(255, 92, 255).
21849    test("hsl(from oklab(0% 0.365 -0.16) h s l)", "rgb(0, 0, 0)"); // Naive clip based mapping would give rgb(19, 0, 24).
21850    test("hsl(from oklch(100% 0.399 336.3) h s l)", "rgb(255, 255, 255)"); // Naive clip based mapping would give rgb(255, 91, 255).
21851    test("hsl(from oklch(0% 0.399 336.3) h s l)", "rgb(0, 0, 0)"); // Naive clip based mapping would give rgb(20, 0, 24).
21852
21853    // Testing replacement with 0.
21854    test("hsl(from rebeccapurple 0 0% 0%)", "rgb(0, 0, 0)");
21855    test("hsl(from rebeccapurple 0deg 0% 0%)", "rgb(0, 0, 0)");
21856    test("hsl(from rebeccapurple 0 0% 0% / 0)", "rgba(0, 0, 0, 0)");
21857    test("hsl(from rebeccapurple 0deg 0% 0% / 0)", "rgba(0, 0, 0, 0)");
21858    test("hsl(from rebeccapurple 0 s l / alpha)", "rgb(153, 51, 51)");
21859    test("hsl(from rebeccapurple 0deg s l / alpha)", "rgb(153, 51, 51)");
21860    test("hsl(from rebeccapurple h 0% l / alpha)", "rgb(102, 102, 102)");
21861    test("hsl(from rebeccapurple h s 0% / alpha)", "rgb(0, 0, 0)");
21862    test("hsl(from rebeccapurple h s l / 0)", "rgba(102, 51, 153, 0)");
21863    test(
21864      "hsl(from rgb(20%, 40%, 60%, 80%) 0 s l / alpha)",
21865      "rgba(153, 51, 51, 0.8)",
21866    );
21867    test(
21868      "hsl(from rgb(20%, 40%, 60%, 80%) 0deg s l / alpha)",
21869      "rgba(153, 51, 51, 0.8)",
21870    );
21871    test(
21872      "hsl(from rgb(20%, 40%, 60%, 80%) h 0% l / alpha)",
21873      "rgba(102, 102, 102, 0.8)",
21874    );
21875    test("hsl(from rgb(20%, 40%, 60%, 80%) h s 0% / alpha)", "rgba(0, 0, 0, 0.8)");
21876    test("hsl(from rgb(20%, 40%, 60%, 80%) h s l / 0)", "rgba(51, 102, 153, 0)");
21877
21878    // Testing replacement with a constant.
21879    test("hsl(from rebeccapurple 25 s l / alpha)", "rgb(153, 94, 51)");
21880    test("hsl(from rebeccapurple 25deg s l / alpha)", "rgb(153, 94, 51)");
21881    test("hsl(from rebeccapurple h 20% l / alpha)", "rgb(102, 82, 122)");
21882    test("hsl(from rebeccapurple h s 20% / alpha)", "rgb(51, 25, 77)");
21883    test("hsl(from rebeccapurple h s l / .25)", "rgba(102, 51, 153, 0.25)");
21884    test(
21885      "hsl(from rgb(20%, 40%, 60%, 80%) 25 s l / alpha)",
21886      "rgba(153, 94, 51, 0.8)",
21887    );
21888    test(
21889      "hsl(from rgb(20%, 40%, 60%, 80%) 25deg s l / alpha)",
21890      "rgba(153, 94, 51, 0.8)",
21891    );
21892    test(
21893      "hsl(from rgb(20%, 40%, 60%, 80%) h 20% l / alpha)",
21894      "rgba(82, 102, 122, 0.8)",
21895    );
21896    test(
21897      "hsl(from rgb(20%, 40%, 60%, 80%) h s 20% / alpha)",
21898      "rgba(25, 51, 77, 0.8)",
21899    );
21900    test(
21901      "hsl(from rgb(20%, 40%, 60%, 80%) h s l / .2)",
21902      "rgba(51, 102, 153, 0.2)",
21903    );
21904
21905    // Testing valid permutation (types match).
21906    test("hsl(from rebeccapurple h l s)", "rgb(128, 77, 179)");
21907    test(
21908      "hsl(from rebeccapurple h calc(alpha * 100) l / calc(s / 100))",
21909      "rgba(102, 0, 204, 0.5)",
21910    );
21911    test(
21912      "hsl(from rebeccapurple h l l / calc(l / 100))",
21913      "rgba(102, 61, 143, 0.4)",
21914    );
21915    test(
21916      "hsl(from rebeccapurple h calc(alpha * 100) calc(alpha * 100) / calc(alpha * 100))",
21917      "rgb(255, 255, 255)",
21918    );
21919    test("hsl(from rgb(20%, 40%, 60%, 80%) h l s)", "rgba(77, 128, 179, 0.8)");
21920    test(
21921      "hsl(from rgb(20%, 40%, 60%, 80%) h calc(alpha * 100) l / calc(s / 100))",
21922      "rgba(20, 102, 184, 0.5)",
21923    );
21924    test(
21925      "hsl(from rgb(20%, 40%, 60%, 80%) h l l / calc(l / 100))",
21926      "rgba(61, 102, 143, 0.4)",
21927    );
21928    test(
21929      "hsl(from rgb(20%, 40%, 60%, 80%) h calc(alpha * 100) calc(alpha * 100) / alpha)",
21930      "rgba(163, 204, 245, 0.8)",
21931    );
21932
21933    // Testing with calc().
21934    test("hsl(from rebeccapurple calc(h) calc(s) calc(l))", "rgb(102, 51, 153)");
21935    test(
21936      "hsl(from rgb(20%, 40%, 60%, 80%) calc(h) calc(s) calc(l) / calc(alpha))",
21937      "rgba(51, 102, 153, 0.8)",
21938    );
21939
21940    // Testing with 'none'.
21941    test("hsl(from rebeccapurple none none none)", "rgb(0, 0, 0)");
21942    test("hsl(from rebeccapurple none none none / none)", "rgba(0, 0, 0, 0)");
21943    test("hsl(from rebeccapurple h s none)", "rgb(0, 0, 0)");
21944    test("hsl(from rebeccapurple h s none / alpha)", "rgb(0, 0, 0)");
21945    test("hsl(from rebeccapurple h s l / none)", "rgba(102, 51, 153, 0)");
21946    test("hsl(from rebeccapurple none s l / alpha)", "rgb(153, 51, 51)");
21947    test(
21948      "hsl(from hsl(120deg 20% 50% / .5) h s none / alpha)",
21949      "rgba(0, 0, 0, 0.5)",
21950    );
21951    test(
21952      "hsl(from hsl(120deg 20% 50% / .5) h s l / none)",
21953      "rgba(102, 153, 102, 0)",
21954    );
21955    test(
21956      "hsl(from hsl(120deg 20% 50% / .5) none s l / alpha)",
21957      "rgba(153, 102, 102, 0.5)",
21958    );
21959    // FIXME: Clarify with spec editors if 'none' should pass through to the constants.
21960    test("hsl(from hsl(none none none) h s l)", "rgb(0, 0, 0)");
21961    test("hsl(from hsl(none none none / none) h s l / alpha)", "rgba(0, 0, 0, 0)");
21962    test("hsl(from hsl(120deg none 50% / .5) h s l)", "rgba(128, 128, 128, 0.5)");
21963    test(
21964      "hsl(from hsl(120deg 20% 50% / none) h s l / alpha)",
21965      "rgba(102, 153, 102, 0)",
21966    );
21967    test(
21968      "hsl(from hsl(none 20% 50% / .5) h s l / alpha)",
21969      "rgba(153, 102, 102, 0.5)",
21970    );
21971
21972    // hwb(from ...)
21973
21974    // Testing no modifications.
21975    test("hwb(from rebeccapurple h w b)", "rgb(102, 51, 153)");
21976    test("hwb(from rebeccapurple h w b / alpha)", "rgb(102, 51, 153)");
21977    test(
21978      "hwb(from rgb(20%, 40%, 60%, 80%) h w b / alpha)",
21979      "rgba(51, 102, 153, 0.8)",
21980    );
21981    test(
21982      "hwb(from hsl(120deg 20% 50% / .5) h w b / alpha)",
21983      "rgba(102, 153, 102, 0.5)",
21984    );
21985
21986    // Test nesting relative colors.
21987    test("hwb(from hwb(from rebeccapurple h w b) h w b)", "rgb(102, 51, 153)");
21988
21989    // Testing non-sRGB origin colors to see gamut mapping.
21990    test("hwb(from color(display-p3 0 1 0) h w b / alpha)", "rgb(0, 251, 41)"); // Naive clip based mapping would give rgb(0, 255, 0).
21991    test("hwb(from lab(100% 104.3 -50.9) h w b)", "rgb(255, 255, 255)"); // Naive clip based mapping would give rgb(255, 150, 255).
21992    test("hwb(from lab(0% 104.3 -50.9) h w b)", "rgb(42, 0, 34)"); // Naive clip based mapping would give rgb(90, 0, 76). NOTE: 0% lightness in Lab/LCH does not automatically correspond with sRGB black,
21993    test("hwb(from lch(100% 116 334) h w b)", "rgb(255, 255, 255)"); // Naive clip based mapping would give rgb(255, 150, 255).
21994    test("hwb(from lch(0% 116 334) h w b)", "rgb(42, 0, 34)"); // Naive clip based mapping would give rgb(90, 0, 76). NOTE: 0% lightness in Lab/LCH does not automatically correspond with sRGB black,
21995    test("hwb(from oklab(100% 0.365 -0.16) h w b)", "rgb(255, 255, 255)"); // Naive clip based mapping would give rgb(255, 92, 255).
21996    test("hwb(from oklab(0% 0.365 -0.16) h w b)", "rgb(0, 0, 0)"); // Naive clip based mapping would give rgb(19, 0, 24).
21997    test("hwb(from oklch(100% 0.399 336.3) h w b)", "rgb(255, 255, 255)"); // Naive clip based mapping would give rgb(255, 91, 255).
21998    test("hwb(from oklch(0% 0.399 336.3) h w b)", "rgb(0, 0, 0)"); // Naive clip based mapping would give rgb(20, 0, 24).
21999
22000    // Testing replacement with 0.
22001    test("hwb(from rebeccapurple 0 0% 0%)", "rgb(255, 0, 0)");
22002    test("hwb(from rebeccapurple 0deg 0% 0%)", "rgb(255, 0, 0)");
22003    test("hwb(from rebeccapurple 0 0% 0% / 0)", "rgba(255, 0, 0, 0)");
22004    test("hwb(from rebeccapurple 0deg 0% 0% / 0)", "rgba(255, 0, 0, 0)");
22005    test("hwb(from rebeccapurple 0 w b / alpha)", "rgb(153, 51, 51)");
22006    test("hwb(from rebeccapurple 0deg w b / alpha)", "rgb(153, 51, 51)");
22007    test("hwb(from rebeccapurple h 0% b / alpha)", "rgb(77, 0, 153)");
22008    test("hwb(from rebeccapurple h w 0% / alpha)", "rgb(153, 51, 255)");
22009    test("hwb(from rebeccapurple h w b / 0)", "rgba(102, 51, 153, 0)");
22010    test(
22011      "hwb(from rgb(20%, 40%, 60%, 80%) 0 w b / alpha)",
22012      "rgba(153, 51, 51, 0.8)",
22013    );
22014    test(
22015      "hwb(from rgb(20%, 40%, 60%, 80%) 0deg w b / alpha)",
22016      "rgba(153, 51, 51, 0.8)",
22017    );
22018    test(
22019      "hwb(from rgb(20%, 40%, 60%, 80%) h 0% b / alpha)",
22020      "rgba(0, 77, 153, 0.8)",
22021    );
22022    test(
22023      "hwb(from rgb(20%, 40%, 60%, 80%) h w 0% / alpha)",
22024      "rgba(51, 153, 255, 0.8)",
22025    );
22026    test("hwb(from rgb(20%, 40%, 60%, 80%) h w b / 0)", "rgba(51, 102, 153, 0)");
22027
22028    // Testing replacement with a constant.
22029    test("hwb(from rebeccapurple 25 w b / alpha)", "rgb(153, 94, 51)");
22030    test("hwb(from rebeccapurple 25deg w b / alpha)", "rgb(153, 94, 51)");
22031    test("hwb(from rebeccapurple h 20% b / alpha)", "rgb(102, 51, 153)");
22032    test("hwb(from rebeccapurple h w 20% / alpha)", "rgb(128, 51, 204)");
22033    test("hwb(from rebeccapurple h w b / .2)", "rgba(102, 51, 153, 0.2)");
22034    test(
22035      "hwb(from rgb(20%, 40%, 60%, 80%) 25 w b / alpha)",
22036      "rgba(153, 94, 51, 0.8)",
22037    );
22038    test(
22039      "hwb(from rgb(20%, 40%, 60%, 80%) 25deg w b / alpha)",
22040      "rgba(153, 94, 51, 0.8)",
22041    );
22042    test(
22043      "hwb(from rgb(20%, 40%, 60%, 80%) h 20% b / alpha)",
22044      "rgba(51, 102, 153, 0.8)",
22045    );
22046    test(
22047      "hwb(from rgb(20%, 40%, 60%, 80%) h w 20% / alpha)",
22048      "rgba(51, 128, 204, 0.8)",
22049    );
22050    test(
22051      "hwb(from rgb(20%, 40%, 60%, 80%) h w b / .2)",
22052      "rgba(51, 102, 153, 0.2)",
22053    );
22054
22055    // Testing valid permutation (types match).
22056    test("hwb(from rebeccapurple h b w)", "rgb(153, 102, 204)");
22057    test(
22058      "hwb(from rebeccapurple h calc(alpha * 100) w / calc(b / 100))",
22059      "rgba(213, 213, 213, 0.4)",
22060    );
22061    test(
22062      "hwb(from rebeccapurple h w w / calc(w / 100))",
22063      "rgba(128, 51, 204, 0.2)",
22064    );
22065    test(
22066      "hwb(from rebeccapurple h calc(alpha * 100) calc(alpha * 100) / alpha)",
22067      "rgb(128, 128, 128)",
22068    );
22069    test("hwb(from rgb(20%, 40%, 60%, 80%) h b w)", "rgba(102, 153, 204, 0.8)");
22070    test(
22071      "hwb(from rgb(20%, 40%, 60%, 80%) h calc(alpha * 100) w / calc(b / 100))",
22072      "rgba(204, 204, 204, 0.4)",
22073    );
22074    test(
22075      "hwb(from rgb(20%, 40%, 60%, 80%) h w w / calc(w / 100))",
22076      "rgba(51, 128, 204, 0.2)",
22077    );
22078    test(
22079      "hwb(from rgb(20%, 40%, 60%, 80%) h calc(alpha * 100) calc(alpha * 100) / alpha)",
22080      "rgba(128, 128, 128, 0.8)",
22081    );
22082
22083    // Testing with calc().
22084    test("hwb(from rebeccapurple calc(h) calc(w) calc(b))", "rgb(102, 51, 153)");
22085    test(
22086      "hwb(from rgb(20%, 40%, 60%, 80%) calc(h) calc(w) calc(b) / calc(alpha))",
22087      "rgba(51, 102, 153, 0.8)",
22088    );
22089
22090    // Testing with 'none'.
22091    test("hwb(from rebeccapurple none none none)", "rgb(255, 0, 0)");
22092    test("hwb(from rebeccapurple none none none / none)", "rgba(255, 0, 0, 0)");
22093    test("hwb(from rebeccapurple h w none)", "rgb(153, 51, 255)");
22094    test("hwb(from rebeccapurple h w none / alpha)", "rgb(153, 51, 255)");
22095    test("hwb(from rebeccapurple h w b / none)", "rgba(102, 51, 153, 0)");
22096    test("hwb(from rebeccapurple none w b / alpha)", "rgb(153, 51, 51)");
22097    test(
22098      "hwb(from hwb(120deg 20% 50% / .5) h w none / alpha)",
22099      "rgba(51, 255, 51, 0.5)",
22100    );
22101    test(
22102      "hwb(from hwb(120deg 20% 50% / .5) h w b / none)",
22103      "rgba(51, 128, 51, 0)",
22104    );
22105    test(
22106      "hwb(from hwb(120deg 20% 50% / .5) none w b / alpha)",
22107      "rgba(128, 51, 51, 0.5)",
22108    );
22109    // FIXME: Clarify with spec editors if 'none' should pass through to the constants.
22110    test("hwb(from hwb(none none none) h w b)", "rgb(255, 0, 0)");
22111    test(
22112      "hwb(from hwb(none none none / none) h w b / alpha)",
22113      "rgba(255, 0, 0, 0)",
22114    );
22115    test("hwb(from hwb(120deg none 50% / .5) h w b)", "rgba(0, 128, 0, 0.5)");
22116    test(
22117      "hwb(from hwb(120deg 20% 50% / none) h w b / alpha)",
22118      "rgba(51, 128, 51, 0)",
22119    );
22120    test(
22121      "hwb(from hwb(none 20% 50% / .5) h w b / alpha)",
22122      "rgba(128, 51, 51, 0.5)",
22123    );
22124
22125    for color_space in &["lab", "oklab"] {
22126      // Testing no modifications.
22127      test(
22128        &format!("{}(from {}(25% 20 50) l a b)", color_space, color_space),
22129        &format!("{}(25% 20 50)", color_space),
22130      );
22131      test(
22132        &format!("{}(from {}(25% 20 50) l a b / alpha)", color_space, color_space),
22133        &format!("{}(25% 20 50)", color_space),
22134      );
22135      test(
22136        &format!("{}(from {}(25% 20 50 / 40%) l a b / alpha)", color_space, color_space),
22137        &format!("{}(25% 20 50 / 0.4)", color_space),
22138      );
22139      test(
22140        &format!(
22141          "{}(from {}(200% 300 400 / 500%) l a b / alpha)",
22142          color_space, color_space
22143        ),
22144        &format!("{}(200% 300 400)", color_space),
22145      );
22146      test(
22147        &format!(
22148          "{}(from {}(-200% -300 -400 / -500%) l a b / alpha)",
22149          color_space, color_space
22150        ),
22151        &format!("{}(0% -300 -400 / 0)", color_space),
22152      );
22153
22154      // Test nesting relative colors.
22155      test(
22156        &format!(
22157          "{}(from {}(from {}(25% 20 50) l a b) l a b)",
22158          color_space, color_space, color_space
22159        ),
22160        &format!("{}(25% 20 50)", color_space),
22161      );
22162
22163      // Testing non-${colorSpace} origin to see conversion.
22164      test(
22165        &format!("{}(from color(display-p3 0 0 0) l a b / alpha)", color_space),
22166        &format!("{}(0% 0 0)", color_space),
22167      );
22168
22169      // Testing replacement with 0.
22170      test(
22171        &format!("{}(from {}(25% 20 50) 0% 0 0)", color_space, color_space),
22172        &format!("{}(0% 0 0)", color_space),
22173      );
22174      test(
22175        &format!("{}(from {}(25% 20 50) 0% 0 0 / 0)", color_space, color_space),
22176        &format!("{}(0% 0 0 / 0)", color_space),
22177      );
22178      test(
22179        &format!("{}(from {}(25% 20 50) 0% a b / alpha)", color_space, color_space),
22180        &format!("{}(0% 20 50)", color_space),
22181      );
22182      test(
22183        &format!("{}(from {}(25% 20 50) l 0 b / alpha)", color_space, color_space),
22184        &format!("{}(25% 0 50)", color_space),
22185      );
22186      test(
22187        &format!("{}(from {}(25% 20 50) l a 0 / alpha)", color_space, color_space),
22188        &format!("{}(25% 20 0)", color_space),
22189      );
22190      test(
22191        &format!("{}(from {}(25% 20 50) l a b / 0)", color_space, color_space),
22192        &format!("{}(25% 20 50 / 0)", color_space),
22193      );
22194      test(
22195        &format!("{}(from {}(25% 20 50 / 40%) 0% a b / alpha)", color_space, color_space),
22196        &format!("{}(0% 20 50 / 0.4)", color_space),
22197      );
22198      test(
22199        &format!("{}(from {}(25% 20 50 / 40%) l 0 b / alpha)", color_space, color_space),
22200        &format!("{}(25% 0 50 / 0.4)", color_space),
22201      );
22202      test(
22203        &format!("{}(from {}(25% 20 50 / 40%) l a 0 / alpha)", color_space, color_space),
22204        &format!("{}(25% 20 0 / 0.4)", color_space),
22205      );
22206      test(
22207        &format!("{}(from {}(25% 20 50 / 40%) l a b / 0)", color_space, color_space),
22208        &format!("{}(25% 20 50 / 0)", color_space),
22209      );
22210
22211      // Testing replacement with a constant.
22212      test(
22213        &format!("{}(from {}(25% 20 50) 35% a b / alpha)", color_space, color_space),
22214        &format!("{}(35% 20 50)", color_space),
22215      );
22216      test(
22217        &format!("{}(from {}(25% 20 50) l 35 b / alpha)", color_space, color_space),
22218        &format!("{}(25% 35 50)", color_space),
22219      );
22220      test(
22221        &format!("{}(from {}(25% 20 50) l a 35 / alpha)", color_space, color_space),
22222        &format!("{}(25% 20 35)", color_space),
22223      );
22224      test(
22225        &format!("{}(from {}(25% 20 50) l a b / .35)", color_space, color_space),
22226        &format!("{}(25% 20 50 / 0.35)", color_space),
22227      );
22228      test(
22229        &format!("{}(from {}(25% 20 50 / 40%) 35% a b / alpha)", color_space, color_space),
22230        &format!("{}(35% 20 50 / 0.4)", color_space),
22231      );
22232      test(
22233        &format!("{}(from {}(25% 20 50 / 40%) l 35 b / alpha)", color_space, color_space),
22234        &format!("{}(25% 35 50 / 0.4)", color_space),
22235      );
22236      test(
22237        &format!("{}(from {}(25% 20 50 / 40%) l a 35 / alpha)", color_space, color_space),
22238        &format!("{}(25% 20 35 / 0.4)", color_space),
22239      );
22240      test(
22241        &format!("{}(from {}(25% 20 50 / 40%) l a b / .35)", color_space, color_space),
22242        &format!("{}(25% 20 50 / 0.35)", color_space),
22243      );
22244      test(
22245        &format!(
22246          "{}(from {}(70% 45 30 / 40%) 200% 300 400 / 500)",
22247          color_space, color_space
22248        ),
22249        &format!("{}(200% 300 400)", color_space),
22250      );
22251      test(
22252        &format!(
22253          "{}(from {}(70% 45 30 / 40%) -200% -300 -400 / -500)",
22254          color_space, color_space
22255        ),
22256        &format!("{}(0% -300 -400 / 0)", color_space),
22257      );
22258
22259      // Testing valid permutation (types match).
22260      test(
22261        &format!("{}(from {}(25% 20 50) l b a)", color_space, color_space),
22262        &format!("{}(25% 50 20)", color_space),
22263      );
22264      test(
22265        &format!("{}(from {}(25% 20 50) l a a / a)", color_space, color_space),
22266        &format!("{}(25% 20 20)", color_space),
22267      );
22268      test(
22269        &format!("{}(from {}(25% 20 50 / 40%) l b a)", color_space, color_space),
22270        &format!("{}(25% 50 20 / 0.4)", color_space),
22271      );
22272      test(
22273        &format!("{}(from {}(25% 20 50 / 40%) l a a / a)", color_space, color_space),
22274        &format!("{}(25% 20 20)", color_space),
22275      );
22276
22277      // Testing with calc().
22278      test(
22279        &format!(
22280          "{}(from {}(25% 20 50) calc(l) calc(a) calc(b))",
22281          color_space, color_space
22282        ),
22283        &format!("{}(25% 20 50)", color_space),
22284      );
22285      test(
22286        &format!(
22287          "{}(from {}(25% 20 50 / 40%) calc(l) calc(a) calc(b) / calc(alpha))",
22288          color_space, color_space
22289        ),
22290        &format!("{}(25% 20 50 / 0.4)", color_space),
22291      );
22292
22293      // Testing with 'none'.
22294      test(
22295        &format!("{}(from {}(25% 20 50) none none none)", color_space, color_space),
22296        &format!("{}(none none none)", color_space),
22297      );
22298      test(
22299        &format!("{}(from {}(25% 20 50) none none none / none)", color_space, color_space),
22300        &format!("{}(none none none / none)", color_space),
22301      );
22302      test(
22303        &format!("{}(from {}(25% 20 50) l a none)", color_space, color_space),
22304        &format!("{}(25% 20 none)", color_space),
22305      );
22306      test(
22307        &format!("{}(from {}(25% 20 50) l a none / alpha)", color_space, color_space),
22308        &format!("{}(25% 20 none)", color_space),
22309      );
22310      test(
22311        &format!("{}(from {}(25% 20 50) l a b / none)", color_space, color_space),
22312        &format!("{}(25% 20 50 / none)", color_space),
22313      );
22314      test(
22315        &format!(
22316          "{}(from {}(25% 20 50 / 40%) l a none / alpha)",
22317          color_space, color_space
22318        ),
22319        &format!("{}(25% 20 none / 0.4)", color_space),
22320      );
22321      test(
22322        &format!("{}(from {}(25% 20 50 / 40%) l a b / none)", color_space, color_space),
22323        &format!("{}(25% 20 50 / none)", color_space),
22324      );
22325      // FIXME: Clarify with spec editors if 'none' should pass through to the constants.
22326      test(
22327        &format!("{}(from {}(none none none) l a b)", color_space, color_space),
22328        &format!("{}(0% 0 0)", color_space),
22329      );
22330      test(
22331        &format!(
22332          "{}(from {}(none none none / none) l a b / alpha)",
22333          color_space, color_space
22334        ),
22335        &format!("{}(0% 0 0 / 0)", color_space),
22336      );
22337      test(
22338        &format!("{}(from {}(25% none 50) l a b)", color_space, color_space),
22339        &format!("{}(25% 0 50)", color_space),
22340      );
22341      test(
22342        &format!("{}(from {}(25% 20 50 / none) l a b / alpha)", color_space, color_space),
22343        &format!("{}(25% 20 50 / 0)", color_space),
22344      );
22345    }
22346
22347    // test_valid_value\(`color`, `\$\{colorSpace\}\(from \$\{colorSpace\}\((.*?)`,\s*`\$\{colorSpace\}(.*?)`\)
22348    // test(&format!("{}(from {}($1", color_space, color_space), &format!("{}$2", color_space))
22349
22350    for color_space in &["lch", "oklch"] {
22351      // Cover omitted alpha in LCH and OKLCH.
22352      test(
22353        &format!("{}(from {}(50% 0.2 120 / 0.4) l c h)", color_space, color_space),
22354        &format!("{}(50% 0.2 120 / 0.4)", color_space),
22355      );
22356
22357      // Testing no modifications.
22358      test(
22359        &format!("{}(from {}(70% 45 30) l c h)", color_space, color_space),
22360        &format!("{}(70% 45 30)", color_space),
22361      );
22362      test(
22363        &format!("{}(from {}(70% 45 30) l c h / alpha)", color_space, color_space),
22364        &format!("{}(70% 45 30)", color_space),
22365      );
22366      test(
22367        &format!("{}(from {}(70% 45 30 / 40%) l c h / alpha)", color_space, color_space),
22368        &format!("{}(70% 45 30 / 0.4)", color_space),
22369      );
22370      test(
22371        &format!(
22372          "{}(from {}(200% 300 400 / 500%) l c h / alpha)",
22373          color_space, color_space
22374        ),
22375        &format!("{}(200% 300 40)", color_space),
22376      );
22377      test(
22378        &format!(
22379          "{}(from {}(-200% -300 -400 / -500%) l c h / alpha)",
22380          color_space, color_space
22381        ),
22382        &format!("{}(0% 0 320 / 0)", color_space),
22383      );
22384
22385      // Test nesting relative colors.
22386      test(
22387        &format!(
22388          "{}(from {}(from {}(70% 45 30) l c h) l c h)",
22389          color_space, color_space, color_space
22390        ),
22391        &format!("{}(70% 45 30)", color_space),
22392      );
22393
22394      // Testing non-sRGB origin colors (no gamut mapping will happen since the destination is not a bounded RGB color space).
22395      test(
22396        &format!("{}(from color(display-p3 0 0 0) l c h / alpha)", color_space),
22397        &format!("{}(0% 0 0)", color_space),
22398      );
22399
22400      // Testing replacement with 0.
22401      test(
22402        &format!("{}(from {}(70% 45 30) 0% 0 0)", color_space, color_space),
22403        &format!("{}(0% 0 0)", color_space),
22404      );
22405      test(
22406        &format!("{}(from {}(70% 45 30) 0% 0 0deg)", color_space, color_space),
22407        &format!("{}(0% 0 0)", color_space),
22408      );
22409      test(
22410        &format!("{}(from {}(70% 45 30) 0% 0 0 / 0)", color_space, color_space),
22411        &format!("{}(0% 0 0 / 0)", color_space),
22412      );
22413      test(
22414        &format!("{}(from {}(70% 45 30) 0% 0 0deg / 0)", color_space, color_space),
22415        &format!("{}(0% 0 0 / 0)", color_space),
22416      );
22417      test(
22418        &format!("{}(from {}(70% 45 30) 0% c h / alpha)", color_space, color_space),
22419        &format!("{}(0% 45 30)", color_space),
22420      );
22421      test(
22422        &format!("{}(from {}(70% 45 30) l 0 h / alpha)", color_space, color_space),
22423        &format!("{}(70% 0 30)", color_space),
22424      );
22425      test(
22426        &format!("{}(from {}(70% 45 30) l c 0 / alpha)", color_space, color_space),
22427        &format!("{}(70% 45 0)", color_space),
22428      );
22429      test(
22430        &format!("{}(from {}(70% 45 30) l c 0deg / alpha)", color_space, color_space),
22431        &format!("{}(70% 45 0)", color_space),
22432      );
22433      test(
22434        &format!("{}(from {}(70% 45 30) l c h / 0)", color_space, color_space),
22435        &format!("{}(70% 45 30 / 0)", color_space),
22436      );
22437      test(
22438        &format!("{}(from {}(70% 45 30 / 40%) 0% c h / alpha)", color_space, color_space),
22439        &format!("{}(0% 45 30 / 0.4)", color_space),
22440      );
22441      test(
22442        &format!("{}(from {}(70% 45 30 / 40%) l 0 h / alpha)", color_space, color_space),
22443        &format!("{}(70% 0 30 / 0.4)", color_space),
22444      );
22445      test(
22446        &format!("{}(from {}(70% 45 30 / 40%) l c 0 / alpha)", color_space, color_space),
22447        &format!("{}(70% 45 0 / 0.4)", color_space),
22448      );
22449      test(
22450        &format!(
22451          "{}(from {}(70% 45 30 / 40%) l c 0deg / alpha)",
22452          color_space, color_space
22453        ),
22454        &format!("{}(70% 45 0 / 0.4)", color_space),
22455      );
22456      test(
22457        &format!("{}(from {}(70% 45 30 / 40%) l c h / 0)", color_space, color_space),
22458        &format!("{}(70% 45 30 / 0)", color_space),
22459      );
22460
22461      // Testing replacement with a constant.
22462      test(
22463        &format!("{}(from {}(70% 45 30) 25% c h / alpha)", color_space, color_space),
22464        &format!("{}(25% 45 30)", color_space),
22465      );
22466      test(
22467        &format!("{}(from {}(70% 45 30) l 25 h / alpha)", color_space, color_space),
22468        &format!("{}(70% 25 30)", color_space),
22469      );
22470      test(
22471        &format!("{}(from {}(70% 45 30) l c 25 / alpha)", color_space, color_space),
22472        &format!("{}(70% 45 25)", color_space),
22473      );
22474      test(
22475        &format!("{}(from {}(70% 45 30) l c 25deg / alpha)", color_space, color_space),
22476        &format!("{}(70% 45 25)", color_space),
22477      );
22478      test(
22479        &format!("{}(from {}(70% 45 30) l c h / .25)", color_space, color_space),
22480        &format!("{}(70% 45 30 / 0.25)", color_space),
22481      );
22482      test(
22483        &format!("{}(from {}(70% 45 30 / 40%) 25% c h / alpha)", color_space, color_space),
22484        &format!("{}(25% 45 30 / 0.4)", color_space),
22485      );
22486      test(
22487        &format!("{}(from {}(70% 45 30 / 40%) l 25 h / alpha)", color_space, color_space),
22488        &format!("{}(70% 25 30 / 0.4)", color_space),
22489      );
22490      test(
22491        &format!("{}(from {}(70% 45 30 / 40%) l c 25 / alpha)", color_space, color_space),
22492        &format!("{}(70% 45 25 / 0.4)", color_space),
22493      );
22494      test(
22495        &format!(
22496          "{}(from {}(70% 45 30 / 40%) l c 25deg / alpha)",
22497          color_space, color_space
22498        ),
22499        &format!("{}(70% 45 25 / 0.4)", color_space),
22500      );
22501      test(
22502        &format!("{}(from {}(70% 45 30 / 40%) l c h / .25)", color_space, color_space),
22503        &format!("{}(70% 45 30 / 0.25)", color_space),
22504      );
22505      test(
22506        &format!(
22507          "{}(from {}(70% 45 30 / 40%) 200% 300 400 / 500)",
22508          color_space, color_space
22509        ),
22510        &format!("{}(200% 300 400)", color_space),
22511      );
22512      test(
22513        &format!(
22514          "{}(from {}(70% 45 30 / 40%) -200% -300 -400 / -500)",
22515          color_space, color_space
22516        ),
22517        &format!("{}(0% 0 -400 / 0)", color_space),
22518      );
22519      test(
22520        &format!(
22521          "{}(from {}(70% 45 30 / 40%) 50% 120 400deg / 500)",
22522          color_space, color_space
22523        ),
22524        &format!("{}(50% 120 400)", color_space),
22525      );
22526      test(
22527        &format!(
22528          "{}(from {}(70% 45 30 / 40%) 50% 120 -400deg / -500)",
22529          color_space, color_space
22530        ),
22531        &format!("{}(50% 120 -400 / 0)", color_space),
22532      );
22533
22534      // Testing valid permutation (types match).
22535      // NOTE: 'c' is a valid hue, as hue is <angle>|<number>.
22536      test(
22537        &format!("{}(from {}(70% 45 30) alpha c h / l)", color_space, color_space),
22538        &format!(
22539          "{}(1 45 30 / {})",
22540          color_space,
22541          if *color_space == "lch" { "1" } else { ".7" }
22542        ),
22543      );
22544      test(
22545        &format!("{}(from {}(70% 45 30) l c c / alpha)", color_space, color_space),
22546        &format!("{}(70% 45 45)", color_space),
22547      );
22548      test(
22549        &format!("{}(from {}(70% 45 30) alpha c h / alpha)", color_space, color_space),
22550        &format!("{}(1 45 30)", color_space),
22551      );
22552      test(
22553        &format!("{}(from {}(70% 45 30) alpha c c / alpha)", color_space, color_space),
22554        &format!("{}(1 45 45)", color_space),
22555      );
22556      test(
22557        &format!("{}(from {}(70% 45 30 / 40%) alpha c h / l)", color_space, color_space),
22558        &format!(
22559          "{}(.4 45 30 / {})",
22560          color_space,
22561          if *color_space == "lch" { "1" } else { ".7" }
22562        ),
22563      );
22564      test(
22565        &format!("{}(from {}(70% 45 30 / 40%) l c c / alpha)", color_space, color_space),
22566        &format!("{}(70% 45 45 / 0.4)", color_space),
22567      );
22568      test(
22569        &format!(
22570          "{}(from {}(70% 45 30 / 40%) alpha c h / alpha)",
22571          color_space, color_space
22572        ),
22573        &format!("{}(.4 45 30 / 0.4)", color_space),
22574      );
22575      test(
22576        &format!(
22577          "{}(from {}(70% 45 30 / 40%) alpha c c / alpha)",
22578          color_space, color_space
22579        ),
22580        &format!("{}(.4 45 45 / 0.4)", color_space),
22581      );
22582
22583      // Testing with calc().
22584      test(
22585        &format!(
22586          "{}(from {}(70% 45 30) calc(l) calc(c) calc(h))",
22587          color_space, color_space
22588        ),
22589        &format!("{}(70% 45 30)", color_space),
22590      );
22591      test(
22592        &format!(
22593          "{}(from {}(70% 45 30 / 40%) calc(l) calc(c) calc(h) / calc(alpha))",
22594          color_space, color_space
22595        ),
22596        &format!("{}(70% 45 30 / 0.4)", color_space),
22597      );
22598
22599      // Testing with 'none'.
22600      test(
22601        &format!("{}(from {}(70% 45 30) none none none)", color_space, color_space),
22602        &format!("{}(none none none)", color_space),
22603      );
22604      test(
22605        &format!("{}(from {}(70% 45 30) none none none / none)", color_space, color_space),
22606        &format!("{}(none none none / none)", color_space),
22607      );
22608      test(
22609        &format!("{}(from {}(70% 45 30) l c none)", color_space, color_space),
22610        &format!("{}(70% 45 none)", color_space),
22611      );
22612      test(
22613        &format!("{}(from {}(70% 45 30) l c none / alpha)", color_space, color_space),
22614        &format!("{}(70% 45 none)", color_space),
22615      );
22616      test(
22617        &format!("{}(from {}(70% 45 30) l c h / none)", color_space, color_space),
22618        &format!("{}(70% 45 30 / none)", color_space),
22619      );
22620      test(
22621        &format!(
22622          "{}(from {}(70% 45 30 / 40%) l c none / alpha)",
22623          color_space, color_space
22624        ),
22625        &format!("{}(70% 45 none / 0.4)", color_space),
22626      );
22627      test(
22628        &format!("{}(from {}(70% 45 30 / 40%) l c h / none)", color_space, color_space),
22629        &format!("{}(70% 45 30 / none)", color_space),
22630      );
22631      // FIXME: Clarify with spec editors if 'none' should pass through to the constants.
22632      test(
22633        &format!("{}(from {}(none none none) l c h)", color_space, color_space),
22634        &format!("{}(0% 0 0)", color_space),
22635      );
22636      test(
22637        &format!(
22638          "{}(from {}(none none none / none) l c h / alpha)",
22639          color_space, color_space
22640        ),
22641        &format!("{}(0% 0 0 / 0)", color_space),
22642      );
22643      test(
22644        &format!("{}(from {}(70% none 30) l c h)", color_space, color_space),
22645        &format!("{}(70% 0 30)", color_space),
22646      );
22647      test(
22648        &format!("{}(from {}(70% 45 30 / none) l c h / alpha)", color_space, color_space),
22649        &format!("{}(70% 45 30 / 0)", color_space),
22650      );
22651    }
22652
22653    // test_valid_value\(`color`, `color\(from color\(\$\{colorSpace\}(.*?) \$\{colorSpace\}(.*?)`,\s*`color\(\$\{colorSpace\}(.*?)`\)
22654    // test(&format!("color(from color({}$1 {}$2", color_space, color_space), &format!("color({}$3", color_space))
22655
22656    for color_space in &["srgb", "srgb-linear", "a98-rgb", "rec2020", "prophoto-rgb"] {
22657      // Testing no modifications.
22658      test(
22659        &format!("color(from color({} 0.7 0.5 0.3) {} r g b)", color_space, color_space),
22660        &format!("color({} 0.7 0.5 0.3)", color_space),
22661      );
22662      test(
22663        &format!(
22664          "color(from color({} 0.7 0.5 0.3) {} r g b / alpha)",
22665          color_space, color_space
22666        ),
22667        &format!("color({} 0.7 0.5 0.3)", color_space),
22668      );
22669      test(
22670        &format!(
22671          "color(from color({} 0.7 0.5 0.3 / 40%) {} r g b)",
22672          color_space, color_space
22673        ),
22674        &format!("color({} 0.7 0.5 0.3 / 0.4)", color_space),
22675      );
22676      test(
22677        &format!(
22678          "color(from color({} 0.7 0.5 0.3 / 40%) {} r g b / alpha)",
22679          color_space, color_space
22680        ),
22681        &format!("color({} 0.7 0.5 0.3 / 0.4)", color_space),
22682      );
22683
22684      // Test nesting relative colors.
22685      test(
22686        &format!(
22687          "color(from color(from color({} 0.7 0.5 0.3) {} r g b) {} r g b)",
22688          color_space, color_space, color_space
22689        ),
22690        &format!("color({} 0.7 0.5 0.3)", color_space),
22691      );
22692
22693      // Testing replacement with 0.
22694      test(
22695        &format!("color(from color({} 0.7 0.5 0.3) {} 0 0 0)", color_space, color_space),
22696        &format!("color({} 0 0 0)", color_space),
22697      );
22698      test(
22699        &format!(
22700          "color(from color({} 0.7 0.5 0.3) {} 0 0 0 / 0)",
22701          color_space, color_space
22702        ),
22703        &format!("color({} 0 0 0 / 0)", color_space),
22704      );
22705      test(
22706        &format!(
22707          "color(from color({} 0.7 0.5 0.3) {} 0 g b / alpha)",
22708          color_space, color_space
22709        ),
22710        &format!("color({} 0 0.5 0.3)", color_space),
22711      );
22712      test(
22713        &format!(
22714          "color(from color({} 0.7 0.5 0.3) {} r 0 b / alpha)",
22715          color_space, color_space
22716        ),
22717        &format!("color({} 0.7 0 0.3)", color_space),
22718      );
22719      test(
22720        &format!(
22721          "color(from color({} 0.7 0.5 0.3) {} r g 0 / alpha)",
22722          color_space, color_space
22723        ),
22724        &format!("color({} 0.7 0.5 0)", color_space),
22725      );
22726      test(
22727        &format!(
22728          "color(from color({} 0.7 0.5 0.3) {} r g b / 0)",
22729          color_space, color_space
22730        ),
22731        &format!("color({} 0.7 0.5 0.3 / 0)", color_space),
22732      );
22733      test(
22734        &format!(
22735          "color(from color({} 0.7 0.5 0.3 / 40%) {} 0 g b / alpha)",
22736          color_space, color_space
22737        ),
22738        &format!("color({} 0 0.5 0.3 / 0.4)", color_space),
22739      );
22740      test(
22741        &format!(
22742          "color(from color({} 0.7 0.5 0.3 / 40%) {} r 0 b / alpha)",
22743          color_space, color_space
22744        ),
22745        &format!("color({} 0.7 0 0.3 / 0.4)", color_space),
22746      );
22747      test(
22748        &format!(
22749          "color(from color({} 0.7 0.5 0.3 / 40%) {} r g 0 / alpha)",
22750          color_space, color_space
22751        ),
22752        &format!("color({} 0.7 0.5 0 / 0.4)", color_space),
22753      );
22754      test(
22755        &format!(
22756          "color(from color({} 0.7 0.5 0.3 / 40%) {} r g b / 0)",
22757          color_space, color_space
22758        ),
22759        &format!("color({} 0.7 0.5 0.3 / 0)", color_space),
22760      );
22761
22762      // Testing replacement with a constant.
22763      test(
22764        &format!(
22765          "color(from color({} 0.7 0.5 0.3) {} 0.2 g b / alpha)",
22766          color_space, color_space
22767        ),
22768        &format!("color({} 0.2 0.5 0.3)", color_space),
22769      );
22770      test(
22771        &format!(
22772          "color(from color({} 0.7 0.5 0.3) {} 20% g b / alpha)",
22773          color_space, color_space
22774        ),
22775        &format!("color({} 0.2 0.5 0.3)", color_space),
22776      );
22777      test(
22778        &format!(
22779          "color(from color({} 0.7 0.5 0.3) {} r 0.2 b / alpha)",
22780          color_space, color_space
22781        ),
22782        &format!("color({} 0.7 0.2 0.3)", color_space),
22783      );
22784      test(
22785        &format!(
22786          "color(from color({} 0.7 0.5 0.3) {} r 20% b / alpha)",
22787          color_space, color_space
22788        ),
22789        &format!("color({} 0.7 0.2 0.3)", color_space),
22790      );
22791      test(
22792        &format!(
22793          "color(from color({} 0.7 0.5 0.3) {} r g 0.2 / alpha)",
22794          color_space, color_space
22795        ),
22796        &format!("color({} 0.7 0.5 0.2)", color_space),
22797      );
22798      test(
22799        &format!(
22800          "color(from color({} 0.7 0.5 0.3) {} r g 20% / alpha)",
22801          color_space, color_space
22802        ),
22803        &format!("color({} 0.7 0.5 0.2)", color_space),
22804      );
22805      test(
22806        &format!(
22807          "color(from color({} 0.7 0.5 0.3) {} r g b / 0.2)",
22808          color_space, color_space
22809        ),
22810        &format!("color({} 0.7 0.5 0.3 / 0.2)", color_space),
22811      );
22812      test(
22813        &format!(
22814          "color(from color({} 0.7 0.5 0.3) {} r g b / 20%)",
22815          color_space, color_space
22816        ),
22817        &format!("color({} 0.7 0.5 0.3 / 0.2)", color_space),
22818      );
22819      test(
22820        &format!(
22821          "color(from color({} 0.7 0.5 0.3 / 40%) {} 0.2 g b / alpha)",
22822          color_space, color_space
22823        ),
22824        &format!("color({} 0.2 0.5 0.3 / 0.4)", color_space),
22825      );
22826      test(
22827        &format!(
22828          "color(from color({} 0.7 0.5 0.3 / 40%) {} 20% g b / alpha)",
22829          color_space, color_space
22830        ),
22831        &format!("color({} 0.2 0.5 0.3 / 0.4)", color_space),
22832      );
22833      test(
22834        &format!(
22835          "color(from color({} 0.7 0.5 0.3 / 40%) {} r 0.2 b / alpha)",
22836          color_space, color_space
22837        ),
22838        &format!("color({} 0.7 0.2 0.3 / 0.4)", color_space),
22839      );
22840      test(
22841        &format!(
22842          "color(from color({} 0.7 0.5 0.3 / 40%) {} r 20% b / alpha)",
22843          color_space, color_space
22844        ),
22845        &format!("color({} 0.7 0.2 0.3 / 0.4)", color_space),
22846      );
22847      test(
22848        &format!(
22849          "color(from color({} 0.7 0.5 0.3 / 40%) {} r g 0.2 / alpha)",
22850          color_space, color_space
22851        ),
22852        &format!("color({} 0.7 0.5 0.2 / 0.4)", color_space),
22853      );
22854      test(
22855        &format!(
22856          "color(from color({} 0.7 0.5 0.3 / 40%) {} r g 20% / alpha)",
22857          color_space, color_space
22858        ),
22859        &format!("color({} 0.7 0.5 0.2 / 0.4)", color_space),
22860      );
22861      test(
22862        &format!(
22863          "color(from color({} 0.7 0.5 0.3 / 40%) {} r g b / 0.2)",
22864          color_space, color_space
22865        ),
22866        &format!("color({} 0.7 0.5 0.3 / 0.2)", color_space),
22867      );
22868      test(
22869        &format!(
22870          "color(from color({} 0.7 0.5 0.3 / 40%) {} r g b / 20%)",
22871          color_space, color_space
22872        ),
22873        &format!("color({} 0.7 0.5 0.3 / 0.2)", color_space),
22874      );
22875      test(
22876        &format!("color(from color({} 0.7 0.5 0.3) {} 2 3 4)", color_space, color_space),
22877        &format!("color({} 2 3 4)", color_space),
22878      );
22879      test(
22880        &format!(
22881          "color(from color({} 0.7 0.5 0.3) {} 2 3 4 / 5)",
22882          color_space, color_space
22883        ),
22884        &format!("color({} 2 3 4)", color_space),
22885      );
22886      test(
22887        &format!(
22888          "color(from color({} 0.7 0.5 0.3) {} -2 -3 -4)",
22889          color_space, color_space
22890        ),
22891        &format!("color({} -2 -3 -4)", color_space),
22892      );
22893      test(
22894        &format!(
22895          "color(from color({} 0.7 0.5 0.3) {} -2 -3 -4 / -5)",
22896          color_space, color_space
22897        ),
22898        &format!("color({} -2 -3 -4 / 0)", color_space),
22899      );
22900      test(
22901        &format!(
22902          "color(from color({} 0.7 0.5 0.3) {} 200% 300% 400%)",
22903          color_space, color_space
22904        ),
22905        &format!("color({} 2 3 4)", color_space),
22906      );
22907      test(
22908        &format!(
22909          "color(from color({} 0.7 0.5 0.3) {} 200% 300% 400% / 500%)",
22910          color_space, color_space
22911        ),
22912        &format!("color({} 2 3 4)", color_space),
22913      );
22914      test(
22915        &format!(
22916          "color(from color({} 0.7 0.5 0.3) {} -200% -300% -400%)",
22917          color_space, color_space
22918        ),
22919        &format!("color({} -2 -3 -4)", color_space),
22920      );
22921      test(
22922        &format!(
22923          "color(from color({} 0.7 0.5 0.3) {} -200% -300% -400% / -500%)",
22924          color_space, color_space
22925        ),
22926        &format!("color({} -2 -3 -4 / 0)", color_space),
22927      );
22928
22929      // Testing valid permutation (types match).
22930      test(
22931        &format!("color(from color({} 0.7 0.5 0.3) {} g b r)", color_space, color_space),
22932        &format!("color({} 0.5 0.3 0.7)", color_space),
22933      );
22934      test(
22935        &format!(
22936          "color(from color({} 0.7 0.5 0.3) {} b alpha r / g)",
22937          color_space, color_space
22938        ),
22939        &format!("color({} 0.3 1 0.7 / 0.5)", color_space),
22940      );
22941      test(
22942        &format!(
22943          "color(from color({} 0.7 0.5 0.3) {} r r r / r)",
22944          color_space, color_space
22945        ),
22946        &format!("color({} 0.7 0.7 0.7 / 0.7)", color_space),
22947      );
22948      test(
22949        &format!(
22950          "color(from color({} 0.7 0.5 0.3) {} alpha alpha alpha / alpha)",
22951          color_space, color_space
22952        ),
22953        &format!("color({} 1 1 1)", color_space),
22954      );
22955      test(
22956        &format!(
22957          "color(from color({} 0.7 0.5 0.3 / 40%) {} g b r)",
22958          color_space, color_space
22959        ),
22960        &format!("color({} 0.5 0.3 0.7 / 0.4)", color_space),
22961      );
22962      test(
22963        &format!(
22964          "color(from color({} 0.7 0.5 0.3 / 40%) {} b alpha r / g)",
22965          color_space, color_space
22966        ),
22967        &format!("color({} 0.3 0.4 0.7 / 0.5)", color_space),
22968      );
22969      test(
22970        &format!(
22971          "color(from color({} 0.7 0.5 0.3 / 40%) {} r r r / r)",
22972          color_space, color_space
22973        ),
22974        &format!("color({} 0.7 0.7 0.7 / 0.7)", color_space),
22975      );
22976      test(
22977        &format!(
22978          "color(from color({} 0.7 0.5 0.3 / 40%) {} alpha alpha alpha / alpha)",
22979          color_space, color_space
22980        ),
22981        &format!("color({} 0.4 0.4 0.4 / 0.4)", color_space),
22982      );
22983
22984      // Testing out of gamut components.
22985      test(
22986        &format!("color(from color({} 1.7 1.5 1.3) {} r g b)", color_space, color_space),
22987        &format!("color({} 1.7 1.5 1.3)", color_space),
22988      );
22989      test(
22990        &format!(
22991          "color(from color({} 1.7 1.5 1.3) {} r g b / alpha)",
22992          color_space, color_space
22993        ),
22994        &format!("color({} 1.7 1.5 1.3)", color_space),
22995      );
22996      test(
22997        &format!(
22998          "color(from color({} 1.7 1.5 1.3 / 140%) {} r g b)",
22999          color_space, color_space
23000        ),
23001        &format!("color({} 1.7 1.5 1.3)", color_space),
23002      );
23003      test(
23004        &format!(
23005          "color(from color({} 1.7 1.5 1.3 / 140%) {} r g b / alpha)",
23006          color_space, color_space
23007        ),
23008        &format!("color({} 1.7 1.5 1.3)", color_space),
23009      );
23010      test(
23011        &format!(
23012          "color(from color({} -0.7 -0.5 -0.3) {} r g b)",
23013          color_space, color_space
23014        ),
23015        &format!("color({} -0.7 -0.5 -0.3)", color_space),
23016      );
23017      test(
23018        &format!(
23019          "color(from color({} -0.7 -0.5 -0.3) {} r g b / alpha)",
23020          color_space, color_space
23021        ),
23022        &format!("color({} -0.7 -0.5 -0.3)", color_space),
23023      );
23024      test(
23025        &format!(
23026          "color(from color({} -0.7 -0.5 -0.3 / -40%) {} r g b)",
23027          color_space, color_space
23028        ),
23029        &format!("color({} -0.7 -0.5 -0.3 / 0)", color_space),
23030      );
23031      test(
23032        &format!(
23033          "color(from color({} -0.7 -0.5 -0.3 / -40%) {} r g b / alpha)",
23034          color_space, color_space
23035        ),
23036        &format!("color({} -0.7 -0.5 -0.3 / 0)", color_space),
23037      );
23038
23039      // Testing with calc().
23040      test(
23041        &format!(
23042          "color(from color({} 0.7 0.5 0.3) {} calc(r) calc(g) calc(b))",
23043          color_space, color_space
23044        ),
23045        &format!("color({} 0.7 0.5 0.3)", color_space),
23046      );
23047      test(
23048        &format!(
23049          "color(from color({} 0.7 0.5 0.3 / 40%) {} calc(r) calc(g) calc(b) / calc(alpha))",
23050          color_space, color_space
23051        ),
23052        &format!("color({} 0.7 0.5 0.3 / 0.4)", color_space),
23053      );
23054
23055      // Testing with 'none'.
23056      test(
23057        &format!(
23058          "color(from color({} 0.7 0.5 0.3) {} none none none)",
23059          color_space, color_space
23060        ),
23061        &format!("color({} none none none)", color_space),
23062      );
23063      test(
23064        &format!(
23065          "color(from color({} 0.7 0.5 0.3) {} none none none / none)",
23066          color_space, color_space
23067        ),
23068        &format!("color({} none none none / none)", color_space),
23069      );
23070      test(
23071        &format!(
23072          "color(from color({} 0.7 0.5 0.3) {} r g none)",
23073          color_space, color_space
23074        ),
23075        &format!("color({} 0.7 0.5 none)", color_space),
23076      );
23077      test(
23078        &format!(
23079          "color(from color({} 0.7 0.5 0.3) {} r g none / alpha)",
23080          color_space, color_space
23081        ),
23082        &format!("color({} 0.7 0.5 none)", color_space),
23083      );
23084      test(
23085        &format!(
23086          "color(from color({} 0.7 0.5 0.3) {} r g b / none)",
23087          color_space, color_space
23088        ),
23089        &format!("color({} 0.7 0.5 0.3 / none)", color_space),
23090      );
23091      test(
23092        &format!(
23093          "color(from color({} 0.7 0.5 0.3 / 40%) {} r g none / alpha)",
23094          color_space, color_space
23095        ),
23096        &format!("color({} 0.7 0.5 none / 0.4)", color_space),
23097      );
23098      test(
23099        &format!(
23100          "color(from color({} 0.7 0.5 0.3 / 40%) {} r g b / none)",
23101          color_space, color_space
23102        ),
23103        &format!("color({} 0.7 0.5 0.3 / none)", color_space),
23104      );
23105      // FIXME: Clarify with spec editors if 'none' should pass through to the constants.
23106      test(
23107        &format!(
23108          "color(from color({} none none none) {} r g b)",
23109          color_space, color_space
23110        ),
23111        &format!("color({} 0 0 0)", color_space),
23112      );
23113      test(
23114        &format!(
23115          "color(from color({} none none none / none) {} r g b / alpha)",
23116          color_space, color_space
23117        ),
23118        &format!("color({} 0 0 0 / 0)", color_space),
23119      );
23120      test(
23121        &format!("color(from color({} 0.7 none 0.3) {} r g b)", color_space, color_space),
23122        &format!("color({} 0.7 0 0.3)", color_space),
23123      );
23124      test(
23125        &format!(
23126          "color(from color({} 0.7 0.5 0.3 / none) {} r g b / alpha)",
23127          color_space, color_space
23128        ),
23129        &format!("color({} 0.7 0.5 0.3 / 0)", color_space),
23130      );
23131    }
23132
23133    // test_valid_value\(`color`, `color\(from color\(\$\{colorSpace\}(.*?) \$\{colorSpace\}(.*?)`,\s*`color\(\$\{resultColorSpace\}(.*?)`\)
23134    // test(&format!("color(from color({}$1 {}$2", color_space, color_space), &format!("color({}$3", result_color_space))
23135
23136    for color_space in &["xyz", "xyz-d50", "xyz-d65"] {
23137      let result_color_space = if *color_space == "xyz" { "xyz-d65" } else { color_space };
23138
23139      // Testing no modifications.
23140      test(
23141        &format!("color(from color({} 7 -20.5 100) {} x y z)", color_space, color_space),
23142        &format!("color({} 7 -20.5 100)", result_color_space),
23143      );
23144      test(
23145        &format!(
23146          "color(from color({} 7 -20.5 100) {} x y z / alpha)",
23147          color_space, color_space
23148        ),
23149        &format!("color({} 7 -20.5 100)", result_color_space),
23150      );
23151      test(
23152        &format!(
23153          "color(from color({} 7 -20.5 100 / 40%) {} x y z)",
23154          color_space, color_space
23155        ),
23156        &format!("color({} 7 -20.5 100 / 0.4)", result_color_space),
23157      );
23158      test(
23159        &format!(
23160          "color(from color({} 7 -20.5 100 / 40%) {} x y z / alpha)",
23161          color_space, color_space
23162        ),
23163        &format!("color({} 7 -20.5 100 / 0.4)", result_color_space),
23164      );
23165
23166      // Test nesting relative colors.
23167      test(
23168        &format!(
23169          "color(from color(from color({} 7 -20.5 100) {} x y z) {} x y z)",
23170          color_space, color_space, color_space
23171        ),
23172        &format!("color({} 7 -20.5 100)", result_color_space),
23173      );
23174
23175      // Testing replacement with 0.
23176      test(
23177        &format!("color(from color({} 7 -20.5 100) {} 0 0 0)", color_space, color_space),
23178        &format!("color({} 0 0 0)", result_color_space),
23179      );
23180      test(
23181        &format!(
23182          "color(from color({} 7 -20.5 100) {} 0 0 0 / 0)",
23183          color_space, color_space
23184        ),
23185        &format!("color({} 0 0 0 / 0)", result_color_space),
23186      );
23187      test(
23188        &format!(
23189          "color(from color({} 7 -20.5 100) {} 0 y z / alpha)",
23190          color_space, color_space
23191        ),
23192        &format!("color({} 0 -20.5 100)", result_color_space),
23193      );
23194      test(
23195        &format!(
23196          "color(from color({} 7 -20.5 100) {} x 0 z / alpha)",
23197          color_space, color_space
23198        ),
23199        &format!("color({} 7 0 100)", result_color_space),
23200      );
23201      test(
23202        &format!(
23203          "color(from color({} 7 -20.5 100) {} x y 0 / alpha)",
23204          color_space, color_space
23205        ),
23206        &format!("color({} 7 -20.5 0)", result_color_space),
23207      );
23208      test(
23209        &format!(
23210          "color(from color({} 7 -20.5 100) {} x y z / 0)",
23211          color_space, color_space
23212        ),
23213        &format!("color({} 7 -20.5 100 / 0)", result_color_space),
23214      );
23215      test(
23216        &format!(
23217          "color(from color({} 7 -20.5 100 / 40%) {} 0 y z / alpha)",
23218          color_space, color_space
23219        ),
23220        &format!("color({} 0 -20.5 100 / 0.4)", result_color_space),
23221      );
23222      test(
23223        &format!(
23224          "color(from color({} 7 -20.5 100 / 40%) {} x 0 z / alpha)",
23225          color_space, color_space
23226        ),
23227        &format!("color({} 7 0 100 / 0.4)", result_color_space),
23228      );
23229      test(
23230        &format!(
23231          "color(from color({} 7 -20.5 100 / 40%) {} x y 0 / alpha)",
23232          color_space, color_space
23233        ),
23234        &format!("color({} 7 -20.5 0 / 0.4)", result_color_space),
23235      );
23236      test(
23237        &format!(
23238          "color(from color({} 7 -20.5 100 / 40%) {} x y z / 0)",
23239          color_space, color_space
23240        ),
23241        &format!("color({} 7 -20.5 100 / 0)", result_color_space),
23242      );
23243
23244      // Testing replacement with a constant.
23245      test(
23246        &format!(
23247          "color(from color({} 7 -20.5 100) {} 0.2 y z / alpha)",
23248          color_space, color_space
23249        ),
23250        &format!("color({} 0.2 -20.5 100)", result_color_space),
23251      );
23252      test(
23253        &format!(
23254          "color(from color({} 7 -20.5 100) {} x 0.2 z / alpha)",
23255          color_space, color_space
23256        ),
23257        &format!("color({} 7 0.2 100)", result_color_space),
23258      );
23259      test(
23260        &format!(
23261          "color(from color({} 7 -20.5 100) {} x y 0.2 / alpha)",
23262          color_space, color_space
23263        ),
23264        &format!("color({} 7 -20.5 0.2)", result_color_space),
23265      );
23266      test(
23267        &format!(
23268          "color(from color({} 7 -20.5 100) {} x y z / 0.2)",
23269          color_space, color_space
23270        ),
23271        &format!("color({} 7 -20.5 100 / 0.2)", result_color_space),
23272      );
23273      test(
23274        &format!(
23275          "color(from color({} 7 -20.5 100) {} x y z / 20%)",
23276          color_space, color_space
23277        ),
23278        &format!("color({} 7 -20.5 100 / 0.2)", result_color_space),
23279      );
23280      test(
23281        &format!(
23282          "color(from color({} 7 -20.5 100 / 40%) {} 0.2 y z / alpha)",
23283          color_space, color_space
23284        ),
23285        &format!("color({} 0.2 -20.5 100 / 0.4)", result_color_space),
23286      );
23287      test(
23288        &format!(
23289          "color(from color({} 7 -20.5 100 / 40%) {} x 0.2 z / alpha)",
23290          color_space, color_space
23291        ),
23292        &format!("color({} 7 0.2 100 / 0.4)", result_color_space),
23293      );
23294      test(
23295        &format!(
23296          "color(from color({} 7 -20.5 100 / 40%) {} x y 0.2 / alpha)",
23297          color_space, color_space
23298        ),
23299        &format!("color({} 7 -20.5 0.2 / 0.4)", result_color_space),
23300      );
23301      test(
23302        &format!(
23303          "color(from color({} 7 -20.5 100 / 40%) {} x y z / 0.2)",
23304          color_space, color_space
23305        ),
23306        &format!("color({} 7 -20.5 100 / 0.2)", result_color_space),
23307      );
23308
23309      // Testing valid permutation (types match).
23310      test(
23311        &format!("color(from color({} 7 -20.5 100) {} y z x)", color_space, color_space),
23312        &format!("color({} -20.5 100 7)", result_color_space),
23313      );
23314      test(
23315        &format!(
23316          "color(from color({} 7 -20.5 100) {} x x x / x)",
23317          color_space, color_space
23318        ),
23319        &format!("color({} 7 7 7)", result_color_space),
23320      );
23321      test(
23322        &format!(
23323          "color(from color({} 7 -20.5 100 / 40%) {} y z x)",
23324          color_space, color_space
23325        ),
23326        &format!("color({} -20.5 100 7 / 0.4)", result_color_space),
23327      );
23328      test(
23329        &format!(
23330          "color(from color({} 7 -20.5 100 / 40%) {} x x x / x)",
23331          color_space, color_space
23332        ),
23333        &format!("color({} 7 7 7)", result_color_space),
23334      );
23335
23336      // Testing with calc().
23337      test(
23338        &format!(
23339          "color(from color({} 7 -20.5 100) {} calc(x) calc(y) calc(z))",
23340          color_space, color_space
23341        ),
23342        &format!("color({} 7 -20.5 100)", result_color_space),
23343      );
23344      test(
23345        &format!(
23346          "color(from color({} 7 -20.5 100 / 40%) {} calc(x) calc(y) calc(z) / calc(alpha))",
23347          color_space, color_space
23348        ),
23349        &format!("color({} 7 -20.5 100 / 0.4)", result_color_space),
23350      );
23351
23352      // Testing with 'none'.
23353      test(
23354        &format!(
23355          "color(from color({} 7 -20.5 100) {} none none none)",
23356          color_space, color_space
23357        ),
23358        &format!("color({} none none none)", result_color_space),
23359      );
23360      test(
23361        &format!(
23362          "color(from color({} 7 -20.5 100) {} none none none / none)",
23363          color_space, color_space
23364        ),
23365        &format!("color({} none none none / none)", result_color_space),
23366      );
23367      test(
23368        &format!(
23369          "color(from color({} 7 -20.5 100) {} x y none)",
23370          color_space, color_space
23371        ),
23372        &format!("color({} 7 -20.5 none)", result_color_space),
23373      );
23374      test(
23375        &format!(
23376          "color(from color({} 7 -20.5 100) {} x y none / alpha)",
23377          color_space, color_space
23378        ),
23379        &format!("color({} 7 -20.5 none)", result_color_space),
23380      );
23381      test(
23382        &format!(
23383          "color(from color({} 7 -20.5 100) {} x y z / none)",
23384          color_space, color_space
23385        ),
23386        &format!("color({} 7 -20.5 100 / none)", result_color_space),
23387      );
23388      test(
23389        &format!(
23390          "color(from color({} 7 -20.5 100 / 40%) {} x y none / alpha)",
23391          color_space, color_space
23392        ),
23393        &format!("color({} 7 -20.5 none / 0.4)", result_color_space),
23394      );
23395      test(
23396        &format!(
23397          "color(from color({} 7 -20.5 100 / 40%) {} x y z / none)",
23398          color_space, color_space
23399        ),
23400        &format!("color({} 7 -20.5 100 / none)", result_color_space),
23401      );
23402      // FIXME: Clarify with spec editors if 'none' should pass through to the constants.
23403      test(
23404        &format!(
23405          "color(from color({} none none none) {} x y z)",
23406          color_space, color_space
23407        ),
23408        &format!("color({} 0 0 0)", result_color_space),
23409      );
23410      test(
23411        &format!(
23412          "color(from color({} none none none / none) {} x y z / alpha)",
23413          color_space, color_space
23414        ),
23415        &format!("color({} 0 0 0 / 0)", result_color_space),
23416      );
23417      test(
23418        &format!("color(from color({} 7 none 100) {} x y z)", color_space, color_space),
23419        &format!("color({} 7 0 100)", result_color_space),
23420      );
23421      test(
23422        &format!(
23423          "color(from color({} 7 -20.5 100 / none) {} x y z / alpha)",
23424          color_space, color_space
23425        ),
23426        &format!("color({} 7 -20.5 100 / 0)", result_color_space),
23427      );
23428
23429      // https://github.com/web-platform-tests/wpt/blob/master/css/css-color/parsing/relative-color-invalid.html
23430      minify_test(
23431        ".foo{color:rgb(from rebeccapurple r 10deg 10)}",
23432        ".foo{color:rgb(from rebeccapurple r 10deg 10)}",
23433      );
23434      minify_test(
23435        ".foo{color:rgb(from rebeccapurple l g b)}",
23436        ".foo{color:rgb(from rebeccapurple l g b)}",
23437      );
23438      minify_test(
23439        ".foo{color:hsl(from rebeccapurple s h l)}",
23440        ".foo{color:hsl(from rebeccapurple s h l)}",
23441      );
23442      minify_test(".foo{color:hsl(from rebeccapurple s s s / s)}", ".foo{color:#bfaa40}");
23443      minify_test(
23444        ".foo{color:hsl(from rebeccapurple calc(alpha * 100) calc(alpha * 100) calc(alpha * 100) / alpha)}",
23445        ".foo{color:#fff}",
23446      );
23447    }
23448  }
23449
23450  #[test]
23451  fn test_relative_alpha_color_fallbacks() {
23452    prefix_test(
23453      ".foo { color: alpha(from color(srgb 1 0 0) / 0.5) }",
23454      indoc! { r#"
23455        .foo {
23456          color: #ff000080;
23457          color: color(srgb 1 0 0 / .5);
23458        }
23459      "#},
23460      Browsers {
23461        chrome: Some(90 << 16),
23462        ..Browsers::default()
23463      },
23464    );
23465    prefix_test(
23466      ".foo { color: alpha(from color(display-p3 1 0 0) / 0.5) }",
23467      indoc! { r#"
23468        .foo {
23469          color: #ff0b0c80;
23470          color: color(display-p3 1 0 0 / .5);
23471        }
23472      "#},
23473      Browsers {
23474        chrome: Some(90 << 16),
23475        ..Browsers::default()
23476      },
23477    );
23478  }
23479
23480  #[test]
23481  fn test_color_mix() {
23482    minify_test(
23483      ".foo { color: color-mix(in lab, purple 50%, plum 50%); }",
23484      ".foo{color:lab(51.5117% 43.3777 -29.0443)}",
23485    );
23486    minify_test(
23487      ".foo { color: color-mix(in lch, peru 40%, palegoldenrod); }",
23488      ".foo{color:lch(79.7255% 40.4542 84.7634)}",
23489    );
23490    minify_test(
23491      ".foo { color: color-mix(in lch, teal 65%, olive); }",
23492      ".foo{color:lch(49.4431% 40.4806 162.546)}",
23493    );
23494    minify_test(
23495      ".foo { color: color-mix(in lch, white, black); }",
23496      ".foo{color:lch(50% 0 none)}",
23497    );
23498    minify_test(
23499      ".foo { color: color-mix(in xyz, rgb(82.02% 30.21% 35.02%) 75.23%, rgb(5.64% 55.94% 85.31%)); }",
23500      ".foo{color:color(xyz .287458 .208776 .260566)}",
23501    );
23502    minify_test(
23503      ".foo { color: color-mix(in lch, white, blue); }",
23504      ".foo{color:lch(64.7842% 65.6007 301.364)}",
23505    );
23506    minify_test(
23507      ".foo { color: color-mix(in oklch, white, blue); }",
23508      ".foo{color:oklch(72.6007% .156607 264.052)}",
23509    );
23510    minify_test(
23511      ".foo { color: color-mix(in srgb, white, blue); }",
23512      ".foo{color:#8080ff}",
23513    );
23514    minify_test(
23515      ".foo { color: color-mix(in lch, blue, white); }",
23516      ".foo{color:lch(64.7842% 65.6007 301.364)}",
23517    );
23518    minify_test(
23519      ".foo { color: color-mix(in oklch, blue, white); }",
23520      ".foo{color:oklch(72.6007% .156607 264.052)}",
23521    );
23522    minify_test(
23523      ".foo { color: color-mix(in srgb, blue, white); }",
23524      ".foo{color:#8080ff}",
23525    );
23526    // minify_test(".foo { color: color-mix(in hsl, color(display-p3 0 1 0) 80%, yellow); }", ".foo{color:hsl(108 100% 49.9184%) }");
23527    minify_test(
23528      ".foo { color: color-mix(in hsl, hsl(120 100% 49.898%) 80%, yellow); }",
23529      ".foo{color:#33fe00}",
23530    );
23531    minify_test(
23532      ".foo { color: color-mix(in srgb, rgb(100% 0% 0% / 0.7) 25%, rgb(0% 100% 0% / 0.2)); }",
23533      ".foo{color:#89760053}",
23534    );
23535    minify_test(
23536      ".foo { color: color-mix(in srgb, rgb(100% 0% 0% / 0.7) 20%, rgb(0% 100% 0% / 0.2) 60%); }",
23537      ".foo{color:#89760042}",
23538    );
23539    minify_test(
23540      ".foo { color: color-mix(in lch, color(display-p3 0 1 none), color(display-p3 0 0 1)); }",
23541      ".foo{color:lch(58.8143% 141.732 218.684)}",
23542    );
23543    minify_test(
23544      ".foo { color: color-mix(in srgb, rgb(128 128 none), rgb(none none 128)); }",
23545      ".foo{color:gray}",
23546    );
23547    minify_test(
23548      ".foo { color: color-mix(in srgb, rgb(50% 50% none), rgb(none none 50%)); }",
23549      ".foo{color:gray}",
23550    );
23551    minify_test(
23552      ".foo { color: color-mix(in srgb, rgb(none 50% none), rgb(50% none 50%)); }",
23553      ".foo{color:gray}",
23554    );
23555    minify_test(
23556      ".foo { --color: color-mix(in lch, teal 65%, olive); }",
23557      ".foo{--color:lch(49.4431% 40.4806 162.546)}",
23558    );
23559    minify_test(
23560      ".foo { color: color-mix(in xyz, transparent, green 65%); }",
23561      ".foo{color:color(xyz .0771883 .154377 .0257295/.65)}",
23562    );
23563    prefix_test(
23564      ".foo { color: color-mix(in xyz, transparent, green 65%); }",
23565      indoc! { r#"
23566      .foo {
23567        color: #008000a6;
23568        color: color(xyz .0771883 .154377 .0257295 / .65);
23569      }
23570      "# },
23571      Browsers {
23572        chrome: Some(95 << 16),
23573        ..Default::default()
23574      },
23575    );
23576    minify_test(
23577      ".foo { color: color-mix(in srgb, currentColor, blue); }",
23578      ".foo{color:color-mix(in srgb, currentColor, blue)}",
23579    );
23580    minify_test(
23581      ".foo { color: color-mix(in srgb, blue, currentColor); }",
23582      ".foo{color:color-mix(in srgb, blue, currentColor)}",
23583    );
23584    minify_test(
23585      ".foo { color: color-mix(in srgb, accentcolor, blue); }",
23586      ".foo{color:color-mix(in srgb, accentcolor, blue)}",
23587    );
23588    minify_test(
23589      ".foo { color: color-mix(in srgb, blue, accentcolor); }",
23590      ".foo{color:color-mix(in srgb, blue, accentcolor)}",
23591    );
23592
23593    // regex for converting web platform tests:
23594    // test_computed_value\(.*?, `(.*?)`, `(.*?)`\);
23595    // minify_test(".foo { color: $1 }", ".foo{color:$2}");
23596
23597    // https://github.com/web-platform-tests/wpt/blob/f8c76b11cff66a7adc87264a18e39353cb5a60c9/css/css-color/parsing/color-mix-computed.html
23598    minify_test(
23599      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20%), hsl(30deg 30% 40%)) }",
23600      ".foo{color:#545c3d}",
23601    );
23602    minify_test(
23603      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20%) 25%, hsl(30deg 30% 40%)) }",
23604      ".foo{color:#706a43}",
23605    );
23606    minify_test(
23607      ".foo { color: color-mix(in hsl, 25% hsl(120deg 10% 20%), hsl(30deg 30% 40%)) }",
23608      ".foo{color:#706a43}",
23609    );
23610    minify_test(
23611      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20%), 25% hsl(30deg 30% 40%)) }",
23612      ".foo{color:#3d4936}",
23613    );
23614    minify_test(
23615      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20%), hsl(30deg 30% 40%) 25%) }",
23616      ".foo{color:#3d4936}",
23617    );
23618    minify_test(
23619      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20%) 25%, hsl(30deg 30% 40%) 75%) }",
23620      ".foo{color:#706a43}",
23621    );
23622    minify_test(
23623      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20%) 30%, hsl(30deg 30% 40%) 90%) }",
23624      ".foo{color:#706a43}",
23625    ); // Scale down > 100% sum.
23626    minify_test(
23627      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20%) 12.5%, hsl(30deg 30% 40%) 37.5%) }",
23628      ".foo{color:#706a4380}",
23629    ); // Scale up < 100% sum, causes alpha multiplication.
23630    minify_test(
23631      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20%) 0%, hsl(30deg 30% 40%)) }",
23632      ".foo{color:#856647}",
23633    );
23634
23635    minify_test(
23636      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20% / .4), hsl(30deg 30% 40% / .8)) }",
23637      ".foo{color:#5f694199}",
23638    );
23639    minify_test(
23640      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20%) 25%, hsl(30deg 30% 40% / .8)) }",
23641      ".foo{color:#6c6742d9}",
23642    );
23643    minify_test(
23644      ".foo { color: color-mix(in hsl, 25% hsl(120deg 10% 20% / .4), hsl(30deg 30% 40% / .8)) }",
23645      ".foo{color:#797245b3}",
23646    );
23647    minify_test(
23648      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20% / .4), 25% hsl(30deg 30% 40% / .8)) }",
23649      ".foo{color:#44543b80}",
23650    );
23651    minify_test(
23652      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20% / .4), hsl(30deg 30% 40% / .8) 25%) }",
23653      ".foo{color:#44543b80}",
23654    );
23655    minify_test(
23656      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20% / .4) 25%, hsl(30deg 30% 40% / .8) 75%) }",
23657      ".foo{color:#797245b3}",
23658    );
23659    minify_test(
23660      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20% / .4) 30%, hsl(30deg 30% 40% / .8) 90%) }",
23661      ".foo{color:#797245b3}",
23662    ); // Scale down > 100% sum.
23663    minify_test(
23664      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20% / .4) 12.5%, hsl(30deg 30% 40% / .8) 37.5%) }",
23665      ".foo{color:#79724559}",
23666    ); // Scale up < 100% sum, causes alpha multiplication.
23667    minify_test(
23668      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20% / .4) 0%, hsl(30deg 30% 40% / .8)) }",
23669      ".foo{color:#856647cc}",
23670    );
23671
23672    fn canonicalize(s: &str) -> String {
23673      use crate::traits::{Parse, ToCss};
23674      use crate::values::color::CssColor;
23675      use cssparser::{Parser, ParserInput};
23676
23677      let mut input = ParserInput::new(s);
23678      let mut parser = Parser::new(&mut input);
23679      let v = CssColor::parse(&mut parser).unwrap().to_rgb().unwrap();
23680      format!(".foo{{color:{}}}", v.to_css_string(PrinterOptions::default()).unwrap())
23681    }
23682
23683    // regex for converting web platform tests:
23684    // test_computed_value\(.*?, `(.*?)`, canonicalize\(`(.*?)`\)\);
23685    // minify_test(".foo { color: $1 }", &canonicalize("$2"));
23686
23687    minify_test(
23688      ".foo { color: color-mix(in hsl, hsl(40deg 50% 50%), hsl(60deg 50% 50%)) }",
23689      &canonicalize("hsl(50deg 50% 50%)"),
23690    );
23691    minify_test(
23692      ".foo { color: color-mix(in hsl, hsl(60deg 50% 50%), hsl(40deg 50% 50%)) }",
23693      &canonicalize("hsl(50deg 50% 50%)"),
23694    );
23695    minify_test(
23696      ".foo { color: color-mix(in hsl, hsl(50deg 50% 50%), hsl(330deg 50% 50%)) }",
23697      &canonicalize("hsl(10deg 50% 50%)"),
23698    );
23699    minify_test(
23700      ".foo { color: color-mix(in hsl, hsl(330deg 50% 50%), hsl(50deg 50% 50%)) }",
23701      &canonicalize("hsl(10deg 50% 50%)"),
23702    );
23703    minify_test(
23704      ".foo { color: color-mix(in hsl, hsl(20deg 50% 50%), hsl(320deg 50% 50%)) }",
23705      &canonicalize("hsl(350deg 50% 50%)"),
23706    );
23707    minify_test(
23708      ".foo { color: color-mix(in hsl, hsl(320deg 50% 50%), hsl(20deg 50% 50%)) }",
23709      &canonicalize("hsl(350deg 50% 50%)"),
23710    );
23711
23712    minify_test(
23713      ".foo { color: color-mix(in hsl shorter hue, hsl(40deg 50% 50%), hsl(60deg 50% 50%)) }",
23714      &canonicalize("hsl(50deg 50% 50%)"),
23715    );
23716    minify_test(
23717      ".foo { color: color-mix(in hsl shorter hue, hsl(60deg 50% 50%), hsl(40deg 50% 50%)) }",
23718      &canonicalize("hsl(50deg 50% 50%)"),
23719    );
23720    minify_test(
23721      ".foo { color: color-mix(in hsl shorter hue, hsl(50deg 50% 50%), hsl(330deg 50% 50%)) }",
23722      &canonicalize("hsl(10deg 50% 50%)"),
23723    );
23724    minify_test(
23725      ".foo { color: color-mix(in hsl shorter hue, hsl(330deg 50% 50%), hsl(50deg 50% 50%)) }",
23726      &canonicalize("hsl(10deg 50% 50%)"),
23727    );
23728    minify_test(
23729      ".foo { color: color-mix(in hsl shorter hue, hsl(20deg 50% 50%), hsl(320deg 50% 50%)) }",
23730      &canonicalize("hsl(350deg 50% 50%)"),
23731    );
23732    minify_test(
23733      ".foo { color: color-mix(in hsl shorter hue, hsl(320deg 50% 50%), hsl(20deg 50% 50%)) }",
23734      &canonicalize("hsl(350deg 50% 50%)"),
23735    );
23736
23737    minify_test(
23738      ".foo { color: color-mix(in hsl longer hue, hsl(40deg 50% 50%), hsl(60deg 50% 50%)) }",
23739      &canonicalize("hsl(230deg 50% 50%)"),
23740    );
23741    minify_test(
23742      ".foo { color: color-mix(in hsl longer hue, hsl(60deg 50% 50%), hsl(40deg 50% 50%)) }",
23743      &canonicalize("hsl(230deg 50% 50%)"),
23744    );
23745    minify_test(
23746      ".foo { color: color-mix(in hsl longer hue, hsl(50deg 50% 50%), hsl(330deg 50% 50%)) }",
23747      &canonicalize("hsl(190deg 50% 50%)"),
23748    );
23749    minify_test(
23750      ".foo { color: color-mix(in hsl longer hue, hsl(330deg 50% 50%), hsl(50deg 50% 50%)) }",
23751      &canonicalize("hsl(190deg 50% 50%)"),
23752    );
23753    // minify_test(".foo { color: color-mix(in hsl longer hue, hsl(20deg 50% 50%), hsl(320deg 50% 50%)) }", &canonicalize("hsl(170deg 50% 50%)"));
23754    // minify_test(".foo { color: color-mix(in hsl longer hue, hsl(320deg 50% 50%), hsl(20deg 50% 50%)) }", &canonicalize("hsl(170deg 50% 50%)"));
23755
23756    minify_test(
23757      ".foo { color: color-mix(in hsl increasing hue, hsl(40deg 50% 50%), hsl(60deg 50% 50%)) }",
23758      &canonicalize("hsl(50deg 50% 50%)"),
23759    );
23760    minify_test(
23761      ".foo { color: color-mix(in hsl increasing hue, hsl(60deg 50% 50%), hsl(40deg 50% 50%)) }",
23762      &canonicalize("hsl(230deg 50% 50%)"),
23763    );
23764    minify_test(
23765      ".foo { color: color-mix(in hsl increasing hue, hsl(50deg 50% 50%), hsl(330deg 50% 50%)) }",
23766      &canonicalize("hsl(190deg 50% 50%)"),
23767    );
23768    minify_test(
23769      ".foo { color: color-mix(in hsl increasing hue, hsl(330deg 50% 50%), hsl(50deg 50% 50%)) }",
23770      &canonicalize("hsl(10deg 50% 50%)"),
23771    );
23772    // minify_test(".foo { color: color-mix(in hsl increasing hue, hsl(20deg 50% 50%), hsl(320deg 50% 50%)) }", &canonicalize("hsl(170deg 50% 50%)"));
23773    // minify_test(".foo { color: color-mix(in hsl increasing hue, hsl(320deg 50% 50%), hsl(20deg 50% 50%)) }", &canonicalize("hsl(350deg 50% 50%)"));
23774
23775    minify_test(
23776      ".foo { color: color-mix(in hsl decreasing hue, hsl(40deg 50% 50%), hsl(60deg 50% 50%)) }",
23777      &canonicalize("hsl(230deg 50% 50%)"),
23778    );
23779    minify_test(
23780      ".foo { color: color-mix(in hsl decreasing hue, hsl(60deg 50% 50%), hsl(40deg 50% 50%)) }",
23781      &canonicalize("hsl(50deg 50% 50%)"),
23782    );
23783    minify_test(
23784      ".foo { color: color-mix(in hsl decreasing hue, hsl(50deg 50% 50%), hsl(330deg 50% 50%)) }",
23785      &canonicalize("hsl(10deg 50% 50%)"),
23786    );
23787    minify_test(
23788      ".foo { color: color-mix(in hsl decreasing hue, hsl(330deg 50% 50%), hsl(50deg 50% 50%)) }",
23789      &canonicalize("hsl(190deg 50% 50%)"),
23790    );
23791    minify_test(
23792      ".foo { color: color-mix(in hsl decreasing hue, hsl(20deg 50% 50%), hsl(320deg 50% 50%)) }",
23793      &canonicalize("hsl(350deg 50% 50%)"),
23794    );
23795    // minify_test(".foo { color: color-mix(in hsl decreasing hue, hsl(320deg 50% 50%), hsl(20deg 50% 50%)) }", &canonicalize("hsl(170deg 50% 50%)"));
23796
23797    minify_test(
23798      ".foo { color: color-mix(in hsl specified hue, hsl(40deg 50% 50%), hsl(60deg 50% 50%)) }",
23799      &canonicalize("hsl(50deg 50% 50%)"),
23800    );
23801    minify_test(
23802      ".foo { color: color-mix(in hsl specified hue, hsl(60deg 50% 50%), hsl(40deg 50% 50%)) }",
23803      &canonicalize("hsl(50deg 50% 50%)"),
23804    );
23805    minify_test(
23806      ".foo { color: color-mix(in hsl specified hue, hsl(50deg 50% 50%), hsl(330deg 50% 50%)) }",
23807      &canonicalize("hsl(190deg 50% 50%)"),
23808    );
23809    minify_test(
23810      ".foo { color: color-mix(in hsl specified hue, hsl(330deg 50% 50%), hsl(50deg 50% 50%)) }",
23811      &canonicalize("hsl(190deg 50% 50%)"),
23812    );
23813    // minify_test(".foo { color: color-mix(in hsl specified hue, hsl(20deg 50% 50%), hsl(320deg 50% 50%)) }", &canonicalize("hsl(170deg 50% 50%)"));
23814    // minify_test(".foo { color: color-mix(in hsl specified hue, hsl(320deg 50% 50%), hsl(20deg 50% 50%)) }", &canonicalize("hsl(170deg 50% 50%)"));
23815
23816    minify_test(
23817      ".foo { color: color-mix(in hsl, hsl(none none none), hsl(none none none)) }",
23818      &canonicalize("hsl(none none none)"),
23819    );
23820    minify_test(
23821      ".foo { color: color-mix(in hsl, hsl(none none none), hsl(30deg 40% 80%)) }",
23822      &canonicalize("hsl(30deg 40% 80%)"),
23823    );
23824    minify_test(
23825      ".foo { color: color-mix(in hsl, hsl(120deg 20% 40%), hsl(none none none)) }",
23826      &canonicalize("hsl(120deg 20% 40%)"),
23827    );
23828    minify_test(
23829      ".foo { color: color-mix(in hsl, hsl(120deg 20% none), hsl(30deg 40% 60%)) }",
23830      &canonicalize("hsl(75deg 30% 60%)"),
23831    );
23832    minify_test(
23833      ".foo { color: color-mix(in hsl, hsl(120deg 20% 40%), hsl(30deg 20% none)) }",
23834      &canonicalize("hsl(75deg 20% 40%)"),
23835    );
23836    minify_test(
23837      ".foo { color: color-mix(in hsl, hsl(none 20% 40%), hsl(30deg none 80%)) }",
23838      &canonicalize("hsl(30deg 20% 60%)"),
23839    );
23840
23841    minify_test(
23842      ".foo { color: color-mix(in hsl, color(display-p3 0 1 0) 100%, rgb(0, 0, 0) 0%) }",
23843      &canonicalize("rgb(0, 251, 41)"),
23844    ); // Naive clip based mapping would give rgb(0, 255, 0).
23845    minify_test(
23846      ".foo { color: color-mix(in hsl, lab(100% 104.3 -50.9) 100%, rgb(0, 0, 0) 0%) }",
23847      &canonicalize("rgb(255, 255, 255)"),
23848    ); // Naive clip based mapping would give rgb(255, 150, 255).
23849    minify_test(
23850      ".foo { color: color-mix(in hsl, lab(0% 104.3 -50.9) 100%, rgb(0, 0, 0) 0%) }",
23851      &canonicalize("rgb(42, 0, 34)"),
23852    ); // Naive clip based mapping would give rgb(90, 0, 76). NOTE: 0% lightness in Lab/LCH does not automatically correspond with sRGB black,
23853    minify_test(
23854      ".foo { color: color-mix(in hsl, lch(100% 116 334) 100%, rgb(0, 0, 0) 0%) }",
23855      &canonicalize("rgb(255, 255, 255)"),
23856    ); // Naive clip based mapping would give rgb(255, 150, 255).
23857    minify_test(
23858      ".foo { color: color-mix(in hsl, lch(0% 116 334) 100%, rgb(0, 0, 0) 0%) }",
23859      &canonicalize("rgb(42, 0, 34)"),
23860    ); // Naive clip based mapping would give rgb(90, 0, 76). NOTE: 0% lightness in Lab/LCH does not automatically correspond with sRGB black,
23861    minify_test(
23862      ".foo { color: color-mix(in hsl, oklab(100% 0.365 -0.16) 100%, rgb(0, 0, 0) 0%) }",
23863      &canonicalize("rgb(255, 255, 255)"),
23864    ); // Naive clip based mapping would give rgb(255, 92, 255).
23865    minify_test(
23866      ".foo { color: color-mix(in hsl, oklab(0% 0.365 -0.16) 100%, rgb(0, 0, 0) 0%) }",
23867      &canonicalize("rgb(0, 0, 0)"),
23868    ); // Naive clip based mapping would give rgb(19, 0, 24).
23869    minify_test(
23870      ".foo { color: color-mix(in hsl, oklch(100% 0.399 336.3) 100%, rgb(0, 0, 0) 0%) }",
23871      &canonicalize("rgb(255, 255, 255)"),
23872    ); // Naive clip based mapping would give rgb(255, 91, 255).
23873    minify_test(
23874      ".foo { color: color-mix(in hsl, oklch(0% 0.399 336.3) 100%, rgb(0, 0, 0) 0%) }",
23875      &canonicalize("rgb(0, 0, 0)"),
23876    ); // Naive clip based mapping would give rgb(20, 0, 24).
23877
23878    minify_test(
23879      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20%), hwb(30deg 30% 40%)) }",
23880      &canonicalize("rgb(147, 179, 52)"),
23881    );
23882    minify_test(
23883      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20%) 25%, hwb(30deg 30% 40%)) }",
23884      &canonicalize("rgb(166, 153, 64)"),
23885    );
23886    minify_test(
23887      ".foo { color: color-mix(in hwb, 25% hwb(120deg 10% 20%), hwb(30deg 30% 40%)) }",
23888      &canonicalize("rgb(166, 153, 64)"),
23889    );
23890    minify_test(
23891      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20%), 25% hwb(30deg 30% 40%)) }",
23892      &canonicalize("rgb(96, 191, 39)"),
23893    );
23894    minify_test(
23895      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20%), hwb(30deg 30% 40%) 25%) }",
23896      &canonicalize("rgb(96, 191, 39)"),
23897    );
23898    minify_test(
23899      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20%) 25%, hwb(30deg 30% 40%) 75%) }",
23900      &canonicalize("rgb(166, 153, 64)"),
23901    );
23902    minify_test(
23903      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20%) 30%, hwb(30deg 30% 40%) 90%) }",
23904      &canonicalize("rgb(166, 153, 64)"),
23905    ); // Scale down > 100% sum.
23906    minify_test(
23907      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20%) 12.5%, hwb(30deg 30% 40%) 37.5%) }",
23908      &canonicalize("rgba(166, 153, 64, 0.5)"),
23909    ); // Scale up < 100% sum, causes alpha multiplication.
23910    minify_test(
23911      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20%) 0%, hwb(30deg 30% 40%)) }",
23912      &canonicalize("rgb(153, 115, 77)"),
23913    );
23914
23915    minify_test(
23916      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20% / .4), hwb(30deg 30% 40% / .8)) }",
23917      &canonicalize("rgba(143, 170, 60, 0.6)"),
23918    );
23919    minify_test(
23920      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20% / .4) 25%, hwb(30deg 30% 40% / .8)) }",
23921      &canonicalize("rgba(160, 149, 70, 0.7)"),
23922    );
23923    minify_test(
23924      ".foo { color: color-mix(in hwb, 25% hwb(120deg 10% 20% / .4), hwb(30deg 30% 40% / .8)) }",
23925      &canonicalize("rgba(160, 149, 70, 0.7)"),
23926    );
23927    minify_test(
23928      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20%), 25% hwb(30deg 30% 40% / .8)) }",
23929      &canonicalize("rgba(95, 193, 37, 0.95)"),
23930    );
23931    minify_test(
23932      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20% / .4), hwb(30deg 30% 40% / .8) 25%) }",
23933      &canonicalize("rgba(98, 184, 46, 0.5)"),
23934    );
23935    minify_test(
23936      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20% / .4) 25%, hwb(30deg 30% 40% / .8) 75%) }",
23937      &canonicalize("rgba(160, 149, 70, 0.7)"),
23938    );
23939    minify_test(
23940      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20% / .4) 30%, hwb(30deg 30% 40% / .8) 90%) }",
23941      &canonicalize("rgba(160, 149, 70, 0.7)"),
23942    ); // Scale down > 100% sum.
23943    minify_test(
23944      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20% / .4) 12.5%, hwb(30deg 30% 40% / .8) 37.5%) }",
23945      &canonicalize("rgba(160, 149, 70, 0.35)"),
23946    ); // Scale up < 100% sum, causes alpha multiplication.
23947    minify_test(
23948      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20% / .4) 0%, hwb(30deg 30% 40% / .8)) }",
23949      &canonicalize("rgba(153, 115, 77, 0.8)"),
23950    );
23951
23952    //  minify_test(".foo { color: color-mix(in hwb, hwb(40deg 30% 40%), hwb(60deg 30% 40%)) }", &canonicalize("hwb(50deg 30% 40%)"));
23953    //  minify_test(".foo { color: color-mix(in hwb, hwb(60deg 30% 40%), hwb(40deg 30% 40%)) }", &canonicalize("hwb(50deg 30% 40%)"));
23954    minify_test(
23955      ".foo { color: color-mix(in hwb, hwb(50deg 30% 40%), hwb(330deg 30% 40%)) }",
23956      &canonicalize("hwb(10deg 30% 40%)"),
23957    );
23958    minify_test(
23959      ".foo { color: color-mix(in hwb, hwb(330deg 30% 40%), hwb(50deg 30% 40%)) }",
23960      &canonicalize("hwb(10deg 30% 40%)"),
23961    );
23962    minify_test(
23963      ".foo { color: color-mix(in hwb, hwb(20deg 30% 40%), hwb(320deg 30% 40%)) }",
23964      &canonicalize("hwb(350deg 30% 40%)"),
23965    );
23966    minify_test(
23967      ".foo { color: color-mix(in hwb, hwb(320deg 30% 40%), hwb(20deg 30% 40%)) }",
23968      &canonicalize("hwb(350deg 30% 40%)"),
23969    );
23970
23971    //  minify_test(".foo { color: color-mix(in hwb shorter hue, hwb(40deg 30% 40%), hwb(60deg 30% 40%)) }", &canonicalize("hwb(50deg 30% 40%)"));
23972    //  minify_test(".foo { color: color-mix(in hwb shorter hue, hwb(60deg 30% 40%), hwb(40deg 30% 40%)) }", &canonicalize("hwb(50deg 30% 40%)"));
23973    minify_test(
23974      ".foo { color: color-mix(in hwb shorter hue, hwb(50deg 30% 40%), hwb(330deg 30% 40%)) }",
23975      &canonicalize("hwb(10deg 30% 40%)"),
23976    );
23977    minify_test(
23978      ".foo { color: color-mix(in hwb shorter hue, hwb(330deg 30% 40%), hwb(50deg 30% 40%)) }",
23979      &canonicalize("hwb(10deg 30% 40%)"),
23980    );
23981    minify_test(
23982      ".foo { color: color-mix(in hwb shorter hue, hwb(20deg 30% 40%), hwb(320deg 30% 40%)) }",
23983      &canonicalize("hwb(350deg 30% 40%)"),
23984    );
23985    minify_test(
23986      ".foo { color: color-mix(in hwb shorter hue, hwb(320deg 30% 40%), hwb(20deg 30% 40%)) }",
23987      &canonicalize("hwb(350deg 30% 40%)"),
23988    );
23989
23990    minify_test(
23991      ".foo { color: color-mix(in hwb longer hue, hwb(40deg 30% 40%), hwb(60deg 30% 40%)) }",
23992      &canonicalize("hwb(230deg 30% 40%)"),
23993    );
23994    minify_test(
23995      ".foo { color: color-mix(in hwb longer hue, hwb(60deg 30% 40%), hwb(40deg 30% 40%)) }",
23996      &canonicalize("hwb(230deg 30% 40%)"),
23997    );
23998    //  minify_test(".foo { color: color-mix(in hwb longer hue, hwb(50deg 30% 40%), hwb(330deg 30% 40%)) }", &canonicalize("hwb(190deg 30% 40%)"));
23999    //  minify_test(".foo { color: color-mix(in hwb longer hue, hwb(330deg 30% 40%), hwb(50deg 30% 40%)) }", &canonicalize("hwb(190deg 30% 40%)"));
24000    //  minify_test(".foo { color: color-mix(in hwb longer hue, hwb(20deg 30% 40%), hwb(320deg 30% 40%)) }", &canonicalize("hwb(170deg 30% 40%)"));
24001    //  minify_test(".foo { color: color-mix(in hwb longer hue, hwb(320deg 30% 40%), hwb(20deg 30% 40%)) }", &canonicalize("hwb(170deg 30% 40%)"));
24002
24003    // minify_test(".foo { color: color-mix(in hwb increasing hue, hwb(40deg 30% 40%), hwb(60deg 30% 40%)) }", &canonicalize("hwb(50deg 30% 40%)"));
24004    minify_test(
24005      ".foo { color: color-mix(in hwb increasing hue, hwb(60deg 30% 40%), hwb(40deg 30% 40%)) }",
24006      &canonicalize("hwb(230deg 30% 40%)"),
24007    );
24008    // minify_test(".foo { color: color-mix(in hwb increasing hue, hwb(50deg 30% 40%), hwb(330deg 30% 40%)) }", &canonicalize("hwb(190deg 30% 40%)"));
24009    minify_test(
24010      ".foo { color: color-mix(in hwb increasing hue, hwb(330deg 30% 40%), hwb(50deg 30% 40%)) }",
24011      &canonicalize("hwb(10deg 30% 40%)"),
24012    );
24013    // minify_test(".foo { color: color-mix(in hwb increasing hue, hwb(20deg 30% 40%), hwb(320deg 30% 40%)) }", &canonicalize("hwb(170deg 30% 40%)"));
24014    minify_test(
24015      ".foo { color: color-mix(in hwb increasing hue, hwb(320deg 30% 40%), hwb(20deg 30% 40%)) }",
24016      &canonicalize("hwb(350deg 30% 40%)"),
24017    );
24018
24019    minify_test(
24020      ".foo { color: color-mix(in hwb decreasing hue, hwb(40deg 30% 40%), hwb(60deg 30% 40%)) }",
24021      &canonicalize("hwb(230deg 30% 40%)"),
24022    );
24023    // minify_test(".foo { color: color-mix(in hwb decreasing hue, hwb(60deg 30% 40%), hwb(40deg 30% 40%)) }", &canonicalize("hwb(50deg 30% 40%)"));
24024    minify_test(
24025      ".foo { color: color-mix(in hwb decreasing hue, hwb(50deg 30% 40%), hwb(330deg 30% 40%)) }",
24026      &canonicalize("hwb(10deg 30% 40%)"),
24027    );
24028    // minify_test(".foo { color: color-mix(in hwb decreasing hue, hwb(330deg 30% 40%), hwb(50deg 30% 40%)) }", &canonicalize("hwb(190deg 30% 40%)"));
24029    minify_test(
24030      ".foo { color: color-mix(in hwb decreasing hue, hwb(20deg 30% 40%), hwb(320deg 30% 40%)) }",
24031      &canonicalize("hwb(350deg 30% 40%)"),
24032    );
24033    // minify_test(".foo { color: color-mix(in hwb decreasing hue, hwb(320deg 30% 40%), hwb(20deg 30% 40%)) }", &canonicalize("hwb(170deg 30% 40%)"));
24034
24035    // minify_test(".foo { color: color-mix(in hwb specified hue, hwb(40deg 30% 40%), hwb(60deg 30% 40%)) }", &canonicalize("hwb(50deg 30% 40%)"));
24036    // minify_test(".foo { color: color-mix(in hwb specified hue, hwb(60deg 30% 40%), hwb(40deg 30% 40%)) }", &canonicalize("hwb(50deg 30% 40%)"));
24037    // minify_test(".foo { color: color-mix(in hwb specified hue, hwb(50deg 30% 40%), hwb(330deg 30% 40%)) }", &canonicalize("hwb(190deg 30% 40%)"));
24038    // minify_test(".foo { color: color-mix(in hwb specified hue, hwb(330deg 30% 40%), hwb(50deg 30% 40%)) }", &canonicalize("hwb(190deg 30% 40%)"));
24039    // minify_test(".foo { color: color-mix(in hwb specified hue, hwb(20deg 30% 40%), hwb(320deg 30% 40%)) }", &canonicalize("hwb(170deg 30% 40%)"));
24040    // minify_test(".foo { color: color-mix(in hwb specified hue, hwb(320deg 30% 40%), hwb(20deg 30% 40%)) }", &canonicalize("hwb(170deg 30% 40%)"));
24041
24042    minify_test(
24043      ".foo { color: color-mix(in hwb, color(display-p3 0 1 0) 100%, rgb(0, 0, 0) 0%) }",
24044      &canonicalize("rgb(0, 251, 41)"),
24045    ); // Naive clip based mapping would give rgb(0, 255, 0).
24046    minify_test(
24047      ".foo { color: color-mix(in hwb, lab(100% 104.3 -50.9) 100%, rgb(0, 0, 0) 0%) }",
24048      &canonicalize("rgb(255, 255, 255)"),
24049    ); // Naive clip based mapping would give rgb(255, 150, 255).
24050    minify_test(
24051      ".foo { color: color-mix(in hwb, lab(0% 104.3 -50.9) 100%, rgb(0, 0, 0) 0%) }",
24052      &canonicalize("rgb(42, 0, 34)"),
24053    ); // Naive clip based mapping would give rgb(90, 0, 76). NOTE: 0% lightness in Lab/LCH does not automatically correspond with sRGB black,
24054    minify_test(
24055      ".foo { color: color-mix(in hwb, lch(100% 116 334) 100%, rgb(0, 0, 0) 0%) }",
24056      &canonicalize("rgb(255, 255, 255)"),
24057    ); // Naive clip based mapping would give rgb(255, 150, 255).
24058    minify_test(
24059      ".foo { color: color-mix(in hwb, lch(0% 116 334) 100%, rgb(0, 0, 0) 0%) }",
24060      &canonicalize("rgb(42, 0, 34)"),
24061    ); // Naive clip based mapping would give rgb(90, 0, 76). NOTE: 0% lightness in Lab/LCH does not automatically correspond with sRGB black,
24062    minify_test(
24063      ".foo { color: color-mix(in hwb, oklab(100% 0.365 -0.16) 100%, rgb(0, 0, 0) 0%) }",
24064      &canonicalize("rgb(255, 255, 255)"),
24065    ); // Naive clip based mapping would give rgb(255, 92, 255).
24066    minify_test(
24067      ".foo { color: color-mix(in hwb, oklab(0% 0.365 -0.16) 100%, rgb(0, 0, 0) 0%) }",
24068      &canonicalize("rgb(0, 0, 0)"),
24069    ); // Naive clip based mapping would give rgb(19, 0, 24).
24070    minify_test(
24071      ".foo { color: color-mix(in hwb, oklch(100% 0.399 336.3) 100%, rgb(0, 0, 0) 0%) }",
24072      &canonicalize("rgb(255, 255, 255)"),
24073    ); // Naive clip based mapping would give rgb(255, 91, 255).
24074    minify_test(
24075      ".foo { color: color-mix(in hwb, oklch(0% 0.399 336.3) 100%, rgb(0, 0, 0) 0%) }",
24076      &canonicalize("rgb(0, 0, 0)"),
24077    ); // Naive clip based mapping would give rgb(20, 0, 24).
24078
24079    for color_space in &["lch", "oklch"] {
24080      // regex for converting web platform tests:
24081      // test_computed_value\(.*?, `color-mix\(in \$\{colorSpace\}(.*?), (.*?)\$\{colorSpace\}(.*?) \$\{colorSpace\}(.*?)`, `\$\{colorSpace\}(.*?)`\);
24082      // minify_test(&format!(".foo {{ color: color-mix(in {0}$1, $2{0}$3 {0}$4 }}", color_space), &format!(".foo{{color:{}$5}}", color_space));
24083
24084      minify_test(
24085        &format!(
24086          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg), {0}(50% 60 70deg)) }}",
24087          color_space
24088        ),
24089        &format!(".foo{{color:{}(30% 40 50)}}", color_space),
24090      );
24091      minify_test(
24092        &format!(
24093          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg) 25%, {0}(50% 60 70deg)) }}",
24094          color_space
24095        ),
24096        &format!(".foo{{color:{}(40% 50 60)}}", color_space),
24097      );
24098      minify_test(
24099        &format!(
24100          ".foo {{ color: color-mix(in {0}, 25% {0}(10% 20 30deg), {0}(50% 60 70deg)) }}",
24101          color_space
24102        ),
24103        &format!(".foo{{color:{}(40% 50 60)}}", color_space),
24104      );
24105      minify_test(
24106        &format!(
24107          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg), 25% {0}(50% 60 70deg)) }}",
24108          color_space
24109        ),
24110        &format!(".foo{{color:{}(20% 30 40)}}", color_space),
24111      );
24112      minify_test(
24113        &format!(
24114          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg), {0}(50% 60 70deg) 25%) }}",
24115          color_space
24116        ),
24117        &format!(".foo{{color:{}(20% 30 40)}}", color_space),
24118      );
24119      minify_test(
24120        &format!(
24121          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg) 25%, {0}(50% 60 70deg) 75%) }}",
24122          color_space
24123        ),
24124        &format!(".foo{{color:{}(40% 50 60)}}", color_space),
24125      );
24126      minify_test(
24127        &format!(
24128          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg) 30%, {0}(50% 60 70deg) 90%) }}",
24129          color_space
24130        ),
24131        &format!(".foo{{color:{}(40% 50 60)}}", color_space),
24132      ); // Scale down > 100% sum.
24133      minify_test(
24134        &format!(
24135          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg) 12.5%, {0}(50% 60 70deg) 37.5%) }}",
24136          color_space
24137        ),
24138        &format!(".foo{{color:{}(40% 50 60/.5)}}", color_space),
24139      ); // Scale up < 100% sum, causes alpha multiplication.
24140      minify_test(
24141        &format!(
24142          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg) 0%, {0}(50% 60 70deg)) }}",
24143          color_space
24144        ),
24145        &format!(".foo{{color:{}(50% 60 70)}}", color_space),
24146      );
24147
24148      minify_test(
24149        &format!(
24150          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg / .4), {0}(50% 60 70deg / .8)) }}",
24151          color_space
24152        ),
24153        &format!(".foo{{color:{}(36.6667% 46.6667 50/.6)}}", color_space),
24154      );
24155      minify_test(
24156        &format!(
24157          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg / .4) 25%, {0}(50% 60 70deg / .8)) }}",
24158          color_space
24159        ),
24160        &format!(".foo{{color:{}(44.2857% 54.2857 60/.7)}}", color_space),
24161      );
24162      minify_test(
24163        &format!(
24164          ".foo {{ color: color-mix(in {0}, 25% {0}(10% 20 30deg / .4), {0}(50% 60 70deg / .8)) }}",
24165          color_space
24166        ),
24167        &format!(".foo{{color:{}(44.2857% 54.2857 60/.7)}}", color_space),
24168      );
24169      minify_test(
24170        &format!(
24171          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg / .4), 25% {0}(50% 60 70deg / .8)) }}",
24172          color_space
24173        ),
24174        &format!(".foo{{color:{}(26% 36 40/.5)}}", color_space),
24175      );
24176      minify_test(
24177        &format!(
24178          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg / .4), {0}(50% 60 70deg / .8) 25%) }}",
24179          color_space
24180        ),
24181        &format!(".foo{{color:{}(26% 36 40/.5)}}", color_space),
24182      );
24183      minify_test(
24184        &format!(
24185          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg / .4) 25%, {0}(50% 60 70deg / .8) 75%) }}",
24186          color_space
24187        ),
24188        &format!(".foo{{color:{}(44.2857% 54.2857 60/.7)}}", color_space),
24189      );
24190      minify_test(
24191        &format!(
24192          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg / .4) 30%, {0}(50% 60 70deg / .8) 90%) }}",
24193          color_space
24194        ),
24195        &format!(".foo{{color:{}(44.2857% 54.2857 60/.7)}}", color_space),
24196      ); // Scale down > 100% sum.
24197      minify_test(
24198        &format!(
24199          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg / .4) 12.5%, {0}(50% 60 70deg / .8) 37.5%) }}",
24200          color_space
24201        ),
24202        &format!(".foo{{color:{}(44.2857% 54.2857 60/.35)}}", color_space),
24203      ); // Scale up < 100% sum, causes alpha multiplication.
24204      minify_test(
24205        &format!(
24206          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg / .4) 0%, {0}(50% 60 70deg / .8)) }}",
24207          color_space
24208        ),
24209        &format!(".foo{{color:{}(50% 60 70/.8)}}", color_space),
24210      );
24211
24212      minify_test(
24213        &format!(
24214          ".foo {{ color: color-mix(in {0}, {0}(100% 0 40deg), {0}(100% 0 60deg)) }}",
24215          color_space
24216        ),
24217        &format!(".foo{{color:{}(100% 0 50)}}", color_space),
24218      );
24219      minify_test(
24220        &format!(
24221          ".foo {{ color: color-mix(in {0}, {0}(100% 0 60deg), {0}(100% 0 40deg)) }}",
24222          color_space
24223        ),
24224        &format!(".foo{{color:{}(100% 0 50)}}", color_space),
24225      );
24226      minify_test(
24227        &format!(
24228          ".foo {{ color: color-mix(in {0}, {0}(100% 0 50deg), {0}(100% 0 330deg)) }}",
24229          color_space
24230        ),
24231        &format!(".foo{{color:{}(100% 0 10)}}", color_space),
24232      );
24233      minify_test(
24234        &format!(
24235          ".foo {{ color: color-mix(in {0}, {0}(100% 0 330deg), {0}(100% 0 50deg)) }}",
24236          color_space
24237        ),
24238        &format!(".foo{{color:{}(100% 0 10)}}", color_space),
24239      );
24240      minify_test(
24241        &format!(
24242          ".foo {{ color: color-mix(in {0}, {0}(100% 0 20deg), {0}(100% 0 320deg)) }}",
24243          color_space
24244        ),
24245        &format!(".foo{{color:{}(100% 0 350)}}", color_space),
24246      );
24247      minify_test(
24248        &format!(
24249          ".foo {{ color: color-mix(in {0}, {0}(100% 0 320deg), {0}(100% 0 20deg)) }}",
24250          color_space
24251        ),
24252        &format!(".foo{{color:{}(100% 0 350)}}", color_space),
24253      );
24254
24255      minify_test(
24256        &format!(
24257          ".foo {{ color: color-mix(in {0} shorter hue, {0}(100% 0 40deg), {0}(100% 0 60deg)) }}",
24258          color_space
24259        ),
24260        &format!(".foo{{color:{}(100% 0 50)}}", color_space),
24261      );
24262      minify_test(
24263        &format!(
24264          ".foo {{ color: color-mix(in {0} shorter hue, {0}(100% 0 60deg), {0}(100% 0 40deg)) }}",
24265          color_space
24266        ),
24267        &format!(".foo{{color:{}(100% 0 50)}}", color_space),
24268      );
24269      minify_test(
24270        &format!(
24271          ".foo {{ color: color-mix(in {0} shorter hue, {0}(100% 0 50deg), {0}(100% 0 330deg)) }}",
24272          color_space
24273        ),
24274        &format!(".foo{{color:{}(100% 0 10)}}", color_space),
24275      );
24276      minify_test(
24277        &format!(
24278          ".foo {{ color: color-mix(in {0} shorter hue, {0}(100% 0 330deg), {0}(100% 0 50deg)) }}",
24279          color_space
24280        ),
24281        &format!(".foo{{color:{}(100% 0 10)}}", color_space),
24282      );
24283      minify_test(
24284        &format!(
24285          ".foo {{ color: color-mix(in {0} shorter hue, {0}(100% 0 20deg), {0}(100% 0 320deg)) }}",
24286          color_space
24287        ),
24288        &format!(".foo{{color:{}(100% 0 350)}}", color_space),
24289      );
24290      minify_test(
24291        &format!(
24292          ".foo {{ color: color-mix(in {0} shorter hue, {0}(100% 0 320deg), {0}(100% 0 20deg)) }}",
24293          color_space
24294        ),
24295        &format!(".foo{{color:{}(100% 0 350)}}", color_space),
24296      );
24297
24298      minify_test(
24299        &format!(
24300          ".foo {{ color: color-mix(in {0} longer hue, {0}(100% 0 40deg), {0}(100% 0 60deg)) }}",
24301          color_space
24302        ),
24303        &format!(".foo{{color:{}(100% 0 230)}}", color_space),
24304      );
24305      minify_test(
24306        &format!(
24307          ".foo {{ color: color-mix(in {0} longer hue, {0}(100% 0 60deg), {0}(100% 0 40deg)) }}",
24308          color_space
24309        ),
24310        &format!(".foo{{color:{}(100% 0 230)}}", color_space),
24311      );
24312      minify_test(
24313        &format!(
24314          ".foo {{ color: color-mix(in {0} longer hue, {0}(100% 0 50deg), {0}(100% 0 330deg)) }}",
24315          color_space
24316        ),
24317        &format!(".foo{{color:{}(100% 0 190)}}", color_space),
24318      );
24319      minify_test(
24320        &format!(
24321          ".foo {{ color: color-mix(in {0} longer hue, {0}(100% 0 330deg), {0}(100% 0 50deg)) }}",
24322          color_space
24323        ),
24324        &format!(".foo{{color:{}(100% 0 190)}}", color_space),
24325      );
24326      minify_test(
24327        &format!(
24328          ".foo {{ color: color-mix(in {0} longer hue, {0}(100% 0 20deg), {0}(100% 0 320deg)) }}",
24329          color_space
24330        ),
24331        &format!(".foo{{color:{}(100% 0 170)}}", color_space),
24332      );
24333      minify_test(
24334        &format!(
24335          ".foo {{ color: color-mix(in {0} longer hue, {0}(100% 0 320deg), {0}(100% 0 20deg)) }}",
24336          color_space
24337        ),
24338        &format!(".foo{{color:{}(100% 0 170)}}", color_space),
24339      );
24340
24341      minify_test(
24342        &format!(
24343          ".foo {{ color: color-mix(in {0} increasing hue, {0}(100% 0 40deg), {0}(100% 0 60deg)) }}",
24344          color_space
24345        ),
24346        &format!(".foo{{color:{}(100% 0 50)}}", color_space),
24347      );
24348      minify_test(
24349        &format!(
24350          ".foo {{ color: color-mix(in {0} increasing hue, {0}(100% 0 60deg), {0}(100% 0 40deg)) }}",
24351          color_space
24352        ),
24353        &format!(".foo{{color:{}(100% 0 230)}}", color_space),
24354      );
24355      minify_test(
24356        &format!(
24357          ".foo {{ color: color-mix(in {0} increasing hue, {0}(100% 0 50deg), {0}(100% 0 330deg)) }}",
24358          color_space
24359        ),
24360        &format!(".foo{{color:{}(100% 0 190)}}", color_space),
24361      );
24362      minify_test(
24363        &format!(
24364          ".foo {{ color: color-mix(in {0} increasing hue, {0}(100% 0 330deg), {0}(100% 0 50deg)) }}",
24365          color_space
24366        ),
24367        &format!(".foo{{color:{}(100% 0 10)}}", color_space),
24368      );
24369      minify_test(
24370        &format!(
24371          ".foo {{ color: color-mix(in {0} increasing hue, {0}(100% 0 20deg), {0}(100% 0 320deg)) }}",
24372          color_space
24373        ),
24374        &format!(".foo{{color:{}(100% 0 170)}}", color_space),
24375      );
24376      minify_test(
24377        &format!(
24378          ".foo {{ color: color-mix(in {0} increasing hue, {0}(100% 0 320deg), {0}(100% 0 20deg)) }}",
24379          color_space
24380        ),
24381        &format!(".foo{{color:{}(100% 0 350)}}", color_space),
24382      );
24383
24384      minify_test(
24385        &format!(
24386          ".foo {{ color: color-mix(in {0} decreasing hue, {0}(100% 0 40deg), {0}(100% 0 60deg)) }}",
24387          color_space
24388        ),
24389        &format!(".foo{{color:{}(100% 0 230)}}", color_space),
24390      );
24391      minify_test(
24392        &format!(
24393          ".foo {{ color: color-mix(in {0} decreasing hue, {0}(100% 0 60deg), {0}(100% 0 40deg)) }}",
24394          color_space
24395        ),
24396        &format!(".foo{{color:{}(100% 0 50)}}", color_space),
24397      );
24398      minify_test(
24399        &format!(
24400          ".foo {{ color: color-mix(in {0} decreasing hue, {0}(100% 0 50deg), {0}(100% 0 330deg)) }}",
24401          color_space
24402        ),
24403        &format!(".foo{{color:{}(100% 0 10)}}", color_space),
24404      );
24405      minify_test(
24406        &format!(
24407          ".foo {{ color: color-mix(in {0} decreasing hue, {0}(100% 0 330deg), {0}(100% 0 50deg)) }}",
24408          color_space
24409        ),
24410        &format!(".foo{{color:{}(100% 0 190)}}", color_space),
24411      );
24412      minify_test(
24413        &format!(
24414          ".foo {{ color: color-mix(in {0} decreasing hue, {0}(100% 0 20deg), {0}(100% 0 320deg)) }}",
24415          color_space
24416        ),
24417        &format!(".foo{{color:{}(100% 0 350)}}", color_space),
24418      );
24419      minify_test(
24420        &format!(
24421          ".foo {{ color: color-mix(in {0} decreasing hue, {0}(100% 0 320deg), {0}(100% 0 20deg)) }}",
24422          color_space
24423        ),
24424        &format!(".foo{{color:{}(100% 0 170)}}", color_space),
24425      );
24426
24427      minify_test(
24428        &format!(
24429          ".foo {{ color: color-mix(in {0} specified hue, {0}(100% 0 40deg), {0}(100% 0 60deg)) }}",
24430          color_space
24431        ),
24432        &format!(".foo{{color:{}(100% 0 50)}}", color_space),
24433      );
24434      minify_test(
24435        &format!(
24436          ".foo {{ color: color-mix(in {0} specified hue, {0}(100% 0 60deg), {0}(100% 0 40deg)) }}",
24437          color_space
24438        ),
24439        &format!(".foo{{color:{}(100% 0 50)}}", color_space),
24440      );
24441      minify_test(
24442        &format!(
24443          ".foo {{ color: color-mix(in {0} specified hue, {0}(100% 0 50deg), {0}(100% 0 330deg)) }}",
24444          color_space
24445        ),
24446        &format!(".foo{{color:{}(100% 0 190)}}", color_space),
24447      );
24448      minify_test(
24449        &format!(
24450          ".foo {{ color: color-mix(in {0} specified hue, {0}(100% 0 330deg), {0}(100% 0 50deg)) }}",
24451          color_space
24452        ),
24453        &format!(".foo{{color:{}(100% 0 190)}}", color_space),
24454      );
24455      minify_test(
24456        &format!(
24457          ".foo {{ color: color-mix(in {0} specified hue, {0}(100% 0 20deg), {0}(100% 0 320deg)) }}",
24458          color_space
24459        ),
24460        &format!(".foo{{color:{}(100% 0 170)}}", color_space),
24461      );
24462      minify_test(
24463        &format!(
24464          ".foo {{ color: color-mix(in {0} specified hue, {0}(100% 0 320deg), {0}(100% 0 20deg)) }}",
24465          color_space
24466        ),
24467        &format!(".foo{{color:{}(100% 0 170)}}", color_space),
24468      );
24469
24470      minify_test(
24471        &format!(
24472          ".foo {{ color: color-mix(in {0}, {0}(none none none), {0}(none none none)) }}",
24473          color_space
24474        ),
24475        &format!(".foo{{color:{}(none none none)}}", color_space),
24476      );
24477      minify_test(
24478        &format!(
24479          ".foo {{ color: color-mix(in {0}, {0}(none none none), {0}(50% 60 70deg)) }}",
24480          color_space
24481        ),
24482        &format!(".foo{{color:{}(50% 60 70)}}", color_space),
24483      );
24484      minify_test(
24485        &format!(
24486          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg), {0}(none none none)) }}",
24487          color_space
24488        ),
24489        &format!(".foo{{color:{}(10% 20 30)}}", color_space),
24490      );
24491      minify_test(
24492        &format!(
24493          ".foo {{ color: color-mix(in {0}, {0}(10% 20 none), {0}(50% 60 70deg)) }}",
24494          color_space
24495        ),
24496        &format!(".foo{{color:{}(30% 40 70)}}", color_space),
24497      );
24498      minify_test(
24499        &format!(
24500          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg), {0}(50% 60 none)) }}",
24501          color_space
24502        ),
24503        &format!(".foo{{color:{}(30% 40 30)}}", color_space),
24504      );
24505      minify_test(
24506        &format!(
24507          ".foo {{ color: color-mix(in {0}, {0}(none 20 30deg), {0}(50% none 70deg)) }}",
24508          color_space
24509        ),
24510        &format!(".foo{{color:{}(50% 20 50)}}", color_space),
24511      );
24512      minify_test(
24513        &format!(
24514          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg / none), {0}(50% 60 70deg)) }}",
24515          color_space
24516        ),
24517        &format!(".foo{{color:{}(30% 40 50)}}", color_space),
24518      );
24519      minify_test(
24520        &format!(
24521          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg / none), {0}(50% 60 70deg / 0.5)) }}",
24522          color_space
24523        ),
24524        &format!(".foo{{color:{}(30% 40 50/.5)}}", color_space),
24525      );
24526      minify_test(
24527        &format!(
24528          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg / none), {0}(50% 60 70deg / none)) }}",
24529          color_space
24530        ),
24531        &format!(".foo{{color:{}(30% 40 50/none)}}", color_space),
24532      );
24533    }
24534
24535    for color_space in ["lab", "oklab"] {
24536      minify_test(
24537        &format!(
24538          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30), {0}(50% 60 70)) }}",
24539          color_space
24540        ),
24541        &format!(".foo{{color:{}(30% 40 50)}}", color_space),
24542      );
24543      minify_test(
24544        &format!(
24545          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30) 25%, {0}(50% 60 70)) }}",
24546          color_space
24547        ),
24548        &format!(".foo{{color:{}(40% 50 60)}}", color_space),
24549      );
24550      minify_test(
24551        &format!(
24552          ".foo {{ color: color-mix(in {0}, 25% {0}(10% 20 30), {0}(50% 60 70)) }}",
24553          color_space
24554        ),
24555        &format!(".foo{{color:{}(40% 50 60)}}", color_space),
24556      );
24557      minify_test(
24558        &format!(
24559          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30), 25% {0}(50% 60 70)) }}",
24560          color_space
24561        ),
24562        &format!(".foo{{color:{}(20% 30 40)}}", color_space),
24563      );
24564      minify_test(
24565        &format!(
24566          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30), {0}(50% 60 70) 25%) }}",
24567          color_space
24568        ),
24569        &format!(".foo{{color:{}(20% 30 40)}}", color_space),
24570      );
24571      minify_test(
24572        &format!(
24573          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30) 25%, {0}(50% 60 70) 75%) }}",
24574          color_space
24575        ),
24576        &format!(".foo{{color:{}(40% 50 60)}}", color_space),
24577      );
24578      minify_test(
24579        &format!(
24580          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30) 30%, {0}(50% 60 70) 90%) }}",
24581          color_space
24582        ),
24583        &format!(".foo{{color:{}(40% 50 60)}}", color_space),
24584      ); // Scale down > 100% sum.
24585      minify_test(
24586        &format!(
24587          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30) 12.5%, {0}(50% 60 70) 37.5%) }}",
24588          color_space
24589        ),
24590        &format!(".foo{{color:{}(40% 50 60/.5)}}", color_space),
24591      ); // Scale up < 100% sum, causes alpha multiplication.
24592      minify_test(
24593        &format!(
24594          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30) 0%, {0}(50% 60 70)) }}",
24595          color_space
24596        ),
24597        &format!(".foo{{color:{}(50% 60 70)}}", color_space),
24598      );
24599
24600      minify_test(
24601        &format!(
24602          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30 / .4), {0}(50% 60 70 / .8)) }}",
24603          color_space
24604        ),
24605        &format!(".foo{{color:{}(36.6667% 46.6667 56.6667/.6)}}", color_space),
24606      );
24607      minify_test(
24608        &format!(
24609          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30 / .4) 25%, {0}(50% 60 70 / .8)) }}",
24610          color_space
24611        ),
24612        &format!(".foo{{color:{}(44.2857% 54.2857 64.2857/.7)}}", color_space),
24613      );
24614      minify_test(
24615        &format!(
24616          ".foo {{ color: color-mix(in {0}, 25% {0}(10% 20 30 / .4), {0}(50% 60 70 / .8)) }}",
24617          color_space
24618        ),
24619        &format!(".foo{{color:{}(44.2857% 54.2857 64.2857/.7)}}", color_space),
24620      );
24621      minify_test(
24622        &format!(
24623          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30 / .4), 25% {0}(50% 60 70 / .8)) }}",
24624          color_space
24625        ),
24626        &format!(".foo{{color:{}(26% 36 46/.5)}}", color_space),
24627      );
24628      minify_test(
24629        &format!(
24630          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30 / .4), {0}(50% 60 70 / .8) 25%) }}",
24631          color_space
24632        ),
24633        &format!(".foo{{color:{}(26% 36 46/.5)}}", color_space),
24634      );
24635      minify_test(
24636        &format!(
24637          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30 / .4) 25%, {0}(50% 60 70 / .8) 75%) }}",
24638          color_space
24639        ),
24640        &format!(".foo{{color:{}(44.2857% 54.2857 64.2857/.7)}}", color_space),
24641      );
24642      minify_test(
24643        &format!(
24644          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30 / .4) 30%, {0}(50% 60 70 / .8) 90%) }}",
24645          color_space
24646        ),
24647        &format!(".foo{{color:{}(44.2857% 54.2857 64.2857/.7)}}", color_space),
24648      ); // Scale down > 100% sum.
24649      minify_test(
24650        &format!(
24651          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30 / .4) 12.5%, {0}(50% 60 70 / .8) 37.5%) }}",
24652          color_space
24653        ),
24654        &format!(".foo{{color:{}(44.2857% 54.2857 64.2857/.35)}}", color_space),
24655      ); // Scale up < 100% sum, causes alpha multiplication.
24656      minify_test(
24657        &format!(
24658          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30 / .4) 0%, {0}(50% 60 70 / .8)) }}",
24659          color_space
24660        ),
24661        &format!(".foo{{color:{}(50% 60 70/.8)}}", color_space),
24662      );
24663
24664      minify_test(
24665        &format!(
24666          ".foo {{ color: color-mix(in {0}, {0}(none none none), {0}(none none none)) }}",
24667          color_space
24668        ),
24669        &format!(".foo{{color:{}(none none none)}}", color_space),
24670      );
24671      minify_test(
24672        &format!(
24673          ".foo {{ color: color-mix(in {0}, {0}(none none none), {0}(50% 60 70)) }}",
24674          color_space
24675        ),
24676        &format!(".foo{{color:{}(50% 60 70)}}", color_space),
24677      );
24678      minify_test(
24679        &format!(
24680          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30), {0}(none none none)) }}",
24681          color_space
24682        ),
24683        &format!(".foo{{color:{}(10% 20 30)}}", color_space),
24684      );
24685      minify_test(
24686        &format!(
24687          ".foo {{ color: color-mix(in {0}, {0}(10% 20 none), {0}(50% 60 70)) }}",
24688          color_space
24689        ),
24690        &format!(".foo{{color:{}(30% 40 70)}}", color_space),
24691      );
24692      minify_test(
24693        &format!(
24694          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30), {0}(50% 60 none)) }}",
24695          color_space
24696        ),
24697        &format!(".foo{{color:{}(30% 40 30)}}", color_space),
24698      );
24699      minify_test(
24700        &format!(
24701          ".foo {{ color: color-mix(in {0}, {0}(none 20 30), {0}(50% none 70)) }}",
24702          color_space
24703        ),
24704        &format!(".foo{{color:{}(50% 20 50)}}", color_space),
24705      );
24706      minify_test(
24707        &format!(
24708          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30 / none), {0}(50% 60 70)) }}",
24709          color_space
24710        ),
24711        &format!(".foo{{color:{}(30% 40 50)}}", color_space),
24712      );
24713      minify_test(
24714        &format!(
24715          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30 / none), {0}(50% 60 70 / 0.5)) }}",
24716          color_space
24717        ),
24718        &format!(".foo{{color:{}(30% 40 50/.5)}}", color_space),
24719      );
24720      minify_test(
24721        &format!(
24722          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30 / none), {0}(50% 60 70 / none)) }}",
24723          color_space
24724        ),
24725        &format!(".foo{{color:{}(30% 40 50/none)}}", color_space),
24726      );
24727    }
24728
24729    for color_space in [/*"srgb", */ "srgb-linear", "xyz", "xyz-d50", "xyz-d65"] {
24730      // regex for converting web platform tests:
24731      // test_computed_value\(.*?, `color-mix\(in \$\{colorSpace\}(.*?), (.*?)color\(\$\{colorSpace\}(.*?) color\(\$\{colorSpace\}(.*?)`, `color\(\$\{resultColorSpace\}(.*?)`\);
24732      // minify_test(&format!(".foo {{ color: color-mix(in {0}$1, $2color({0}$3 color({0}$4 }}", color_space), &format!(".foo{{color:color({}$5}}", result_color_space));
24733
24734      let result_color_space = if color_space == "xyz-d65" { "xyz" } else { color_space };
24735
24736      minify_test(
24737        &format!(
24738          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3), color({0} .5 .6 .7)) }}",
24739          color_space
24740        ),
24741        &format!(".foo{{color:color({} .3 .4 .5)}}", result_color_space),
24742      );
24743      minify_test(
24744        &format!(
24745          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3) 25%, color({0} .5 .6 .7)) }}",
24746          color_space
24747        ),
24748        &format!(".foo{{color:color({} .4 .5 .6)}}", result_color_space),
24749      );
24750      minify_test(
24751        &format!(
24752          ".foo {{ color: color-mix(in {0}, 25% color({0} .1 .2 .3), color({0} .5 .6 .7)) }}",
24753          color_space
24754        ),
24755        &format!(".foo{{color:color({} .4 .5 .6)}}", result_color_space),
24756      );
24757      minify_test(
24758        &format!(
24759          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3), color({0} .5 .6 .7) 25%) }}",
24760          color_space
24761        ),
24762        &format!(".foo{{color:color({} .2 .3 .4)}}", result_color_space),
24763      );
24764      minify_test(
24765        &format!(
24766          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3), 25% color({0} .5 .6 .7)) }}",
24767          color_space
24768        ),
24769        &format!(".foo{{color:color({} .2 .3 .4)}}", result_color_space),
24770      );
24771      minify_test(
24772        &format!(
24773          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3) 25%, color({0} .5 .6 .7) 75%) }}",
24774          color_space
24775        ),
24776        &format!(".foo{{color:color({} .4 .5 .6)}}", result_color_space),
24777      );
24778      minify_test(
24779        &format!(
24780          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3) 30%, color({0} .5 .6 .7) 90%) }}",
24781          color_space
24782        ),
24783        &format!(".foo{{color:color({} .4 .5 .6)}}", result_color_space),
24784      ); // Scale down > 100% sum.
24785      minify_test(
24786        &format!(
24787          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3) 12.5%, color({0} .5 .6 .7) 37.5%) }}",
24788          color_space
24789        ),
24790        &format!(".foo{{color:color({} .4 .5 .6/.5)}}", result_color_space),
24791      ); // Scale up < 100% sum, causes alpha multiplication.
24792      minify_test(
24793        &format!(
24794          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3) 0%, color({0} .5 .6 .7)) }}",
24795          color_space
24796        ),
24797        &format!(".foo{{color:color({} .5 .6 .7)}}", result_color_space),
24798      );
24799
24800      minify_test(
24801        &format!(
24802          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3 / .5), color({0} .5 .6 .7 / .8)) }}",
24803          color_space
24804        ),
24805        &format!(
24806          ".foo{{color:color({} .346154 .446154 .546154/.65)}}",
24807          result_color_space
24808        ),
24809      );
24810      minify_test(
24811        &format!(
24812          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3 / .4) 25%, color({0} .5 .6 .7 / .8)) }}",
24813          color_space
24814        ),
24815        &format!(".foo{{color:color({} .442857 .542857 .642857/.7)}}", result_color_space),
24816      );
24817      minify_test(
24818        &format!(
24819          ".foo {{ color: color-mix(in {0}, 25% color({0} .1 .2 .3 / .4), color({0} .5 .6 .7 / .8)) }}",
24820          color_space
24821        ),
24822        &format!(".foo{{color:color({} .442857 .542857 .642857/.7)}}", result_color_space),
24823      );
24824      minify_test(
24825        &format!(
24826          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3 / .4), color({0} .5 .6 .7 / .8) 25%) }}",
24827          color_space
24828        ),
24829        &format!(".foo{{color:color({} .26 .36 .46/.5)}}", result_color_space),
24830      );
24831      minify_test(
24832        &format!(
24833          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3 / .4), 25% color({0} .5 .6 .7 / .8)) }}",
24834          color_space
24835        ),
24836        &format!(".foo{{color:color({} .26 .36 .46/.5)}}", result_color_space),
24837      );
24838      minify_test(
24839        &format!(
24840          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3 / .4) 25%, color({0} .5 .6 .7 / .8) 75%) }}",
24841          color_space
24842        ),
24843        &format!(".foo{{color:color({} .442857 .542857 .642857/.7)}}", result_color_space),
24844      );
24845      minify_test(
24846        &format!(
24847          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3 / .4) 30%, color({0} .5 .6 .7 / .8) 90%) }}",
24848          color_space
24849        ),
24850        &format!(".foo{{color:color({} .442857 .542857 .642857/.7)}}", result_color_space),
24851      ); // Scale down > 100% sum.
24852      minify_test(
24853        &format!(
24854          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3 / .4) 12.5%, color({0} .5 .6 .7 / .8) 37.5%) }}",
24855          color_space
24856        ),
24857        &format!(
24858          ".foo{{color:color({} .442857 .542857 .642857/.35)}}",
24859          result_color_space
24860        ),
24861      ); // Scale up < 100% sum, causes alpha multiplication.
24862      minify_test(
24863        &format!(
24864          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3 / .4) 0%, color({0} .5 .6 .7 / .8)) }}",
24865          color_space
24866        ),
24867        &format!(".foo{{color:color({} .5 .6 .7/.8)}}", result_color_space),
24868      );
24869
24870      minify_test(
24871        &format!(
24872          ".foo {{ color: color-mix(in {0}, color({0} 2 3 4 / 5), color({0} 4 6 8 / 10)) }}",
24873          color_space
24874        ),
24875        &format!(".foo{{color:color({} 3 4.5 6)}}", result_color_space),
24876      );
24877      minify_test(
24878        &format!(
24879          ".foo {{ color: color-mix(in {0}, color({0} -2 -3 -4), color({0} -4 -6 -8)) }}",
24880          color_space
24881        ),
24882        &format!(".foo{{color:color({} -3 -4.5 -6)}}", result_color_space),
24883      );
24884      minify_test(
24885        &format!(
24886          ".foo {{ color: color-mix(in {0}, color({0} -2 -3 -4 / -5), color({0} -4 -6 -8 / -10)) }}",
24887          color_space
24888        ),
24889        &format!(".foo{{color:color({} 0 0 0/0)}}", result_color_space),
24890      );
24891
24892      minify_test(
24893        &format!(
24894          ".foo {{ color: color-mix(in {0}, color({0} none none none), color({0} none none none)) }}",
24895          color_space
24896        ),
24897        &format!(".foo{{color:color({} none none none)}}", result_color_space),
24898      );
24899      minify_test(
24900        &format!(
24901          ".foo {{ color: color-mix(in {0}, color({0} none none none), color({0} .5 .6 .7)) }}",
24902          color_space
24903        ),
24904        &format!(".foo{{color:color({} .5 .6 .7)}}", result_color_space),
24905      );
24906      minify_test(
24907        &format!(
24908          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3), color({0} none none none)) }}",
24909          color_space
24910        ),
24911        &format!(".foo{{color:color({} .1 .2 .3)}}", result_color_space),
24912      );
24913      minify_test(
24914        &format!(
24915          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 none), color({0} .5 .6 .7)) }}",
24916          color_space
24917        ),
24918        &format!(".foo{{color:color({} .3 .4 .7)}}", result_color_space),
24919      );
24920      minify_test(
24921        &format!(
24922          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3), color({0} .5 .6 none)) }}",
24923          color_space
24924        ),
24925        &format!(".foo{{color:color({} .3 .4 .3)}}", result_color_space),
24926      );
24927      minify_test(
24928        &format!(
24929          ".foo {{ color: color-mix(in {0}, color({0} none .2 .3), color({0} .5 none .7)) }}",
24930          color_space
24931        ),
24932        &format!(".foo{{color:color({} .5 .2 .5)}}", result_color_space),
24933      );
24934      minify_test(
24935        &format!(
24936          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3 / none), color({0} .5 .6 .7)) }}",
24937          color_space
24938        ),
24939        &format!(".foo{{color:color({} .3 .4 .5)}}", result_color_space),
24940      );
24941      minify_test(
24942        &format!(
24943          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3 / none), color({0} .5 .6 .7 / 0.5)) }}",
24944          color_space
24945        ),
24946        &format!(".foo{{color:color({} .3 .4 .5/.5)}}", result_color_space),
24947      );
24948      minify_test(
24949        &format!(
24950          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3 / none), color({0} .5 .6 .7 / none)) }}",
24951          color_space
24952        ),
24953        &format!(".foo{{color:color({} .3 .4 .5/none)}}", result_color_space),
24954      );
24955    }
24956  }
24957
24958  #[test]
24959  fn test_grid() {
24960    property_range_test(
24961      &["gap", "row-gap", "column-gap"],
24962      &[
24963        ("-1px", None),
24964        ("calc(1px - 2px)", Some("0")),
24965        ("calc(-1px + 2px)", Some("1px")),
24966        ("-1%", None),
24967        ("calc(1em - 2px)", Some("calc(1em - 2px)")),
24968        ("calc(-1%)", Some("calc(-1%)")),
24969      ],
24970    );
24971    property_range_test(
24972      &["grid-template-columns", "grid-auto-rows"],
24973      &[
24974        ("-1px", None),
24975        ("calc(1px - 2px)", Some("0")),
24976        ("calc(-1px + 2px)", Some("1px")),
24977        ("-1%", None),
24978        ("calc(1em - 2px)", Some("calc(1em - 2px)")),
24979        ("calc(-1%)", Some("calc(-1%)")),
24980        ("-1fr", None),
24981        ("-0fr", Some("-0fr")),
24982        ("minmax(-1px, 1fr)", None),
24983        ("fit-content(-1px)", None),
24984      ],
24985    );
24986    minify_test(
24987      ".foo { grid-template-columns: [first nav-start]  150px [main-start] 1fr [last]; }",
24988      ".foo{grid-template-columns:[first nav-start]150px[main-start]1fr[last]}",
24989    );
24990    minify_test(
24991      ".foo { grid-template-columns: 150px 1fr; }",
24992      ".foo{grid-template-columns:150px 1fr}",
24993    );
24994    minify_test(
24995      ".foo { grid-template-columns: repeat(4, 1fr); }",
24996      ".foo{grid-template-columns:repeat(4,1fr)}",
24997    );
24998    minify_test(
24999      ".foo { grid-template-columns: repeat(2, [e] 40px); }",
25000      ".foo{grid-template-columns:repeat(2,[e]40px)}",
25001    );
25002    minify_test(
25003      ".foo { grid-template-columns: repeat(4, [col-start] 250px [col-end]); }",
25004      ".foo{grid-template-columns:repeat(4,[col-start]250px[col-end])}",
25005    );
25006    minify_test(
25007      ".foo { grid-template-columns: repeat(4, [col-start] 60% [col-end]); }",
25008      ".foo{grid-template-columns:repeat(4,[col-start]60%[col-end])}",
25009    );
25010    minify_test(
25011      ".foo { grid-template-columns: repeat(4, [col-start] 1fr [col-end]); }",
25012      ".foo{grid-template-columns:repeat(4,[col-start]1fr[col-end])}",
25013    );
25014    minify_test(
25015      ".foo { grid-template-columns: repeat(4, [col-start] min-content [col-end]); }",
25016      ".foo{grid-template-columns:repeat(4,[col-start]min-content[col-end])}",
25017    );
25018    minify_test(
25019      ".foo { grid-template-columns: repeat(4, [col-start] max-content [col-end]); }",
25020      ".foo{grid-template-columns:repeat(4,[col-start]max-content[col-end])}",
25021    );
25022    minify_test(
25023      ".foo { grid-template-columns: repeat(4, [col-start] auto [col-end]); }",
25024      ".foo{grid-template-columns:repeat(4,[col-start]auto[col-end])}",
25025    );
25026    minify_test(
25027      ".foo { grid-template-columns: repeat(4, [col-start] minmax(100px, 1fr) [col-end]); }",
25028      ".foo{grid-template-columns:repeat(4,[col-start]minmax(100px,1fr)[col-end])}",
25029    );
25030    minify_test(
25031      ".foo { grid-template-columns: repeat(4, [col-start] fit-content(200px) [col-end]); }",
25032      ".foo{grid-template-columns:repeat(4,[col-start]fit-content(200px)[col-end])}",
25033    );
25034    minify_test(
25035      ".foo { grid-template-columns: repeat(4, 10px [col-start] 30% [col-middle] auto [col-end]); }",
25036      ".foo{grid-template-columns:repeat(4,10px[col-start]30%[col-middle]auto[col-end])}",
25037    );
25038    minify_test(
25039      ".foo { grid-template-columns: repeat(5, auto); }",
25040      ".foo{grid-template-columns:repeat(5,auto)}",
25041    );
25042    minify_test(
25043      ".foo { grid-template-columns: repeat(auto-fill, 250px); }",
25044      ".foo{grid-template-columns:repeat(auto-fill,250px)}",
25045    );
25046    minify_test(
25047      ".foo { grid-template-columns: repeat(auto-fit, 250px); }",
25048      ".foo{grid-template-columns:repeat(auto-fit,250px)}",
25049    );
25050    minify_test(
25051      ".foo { grid-template-columns: repeat(auto-fill, [col-start] 250px [col-end]); }",
25052      ".foo{grid-template-columns:repeat(auto-fill,[col-start]250px[col-end])}",
25053    );
25054    minify_test(
25055      ".foo { grid-template-columns: repeat(auto-fill, [col-start] minmax(100px, 1fr) [col-end]); }",
25056      ".foo{grid-template-columns:repeat(auto-fill,[col-start]minmax(100px,1fr)[col-end])}",
25057    );
25058    minify_test(
25059      ".foo { grid-template-columns: minmax(min-content, 1fr); }",
25060      ".foo{grid-template-columns:minmax(min-content,1fr)}",
25061    );
25062    minify_test(
25063      ".foo { grid-template-columns: 200px repeat(auto-fill, 100px) 300px; }",
25064      ".foo{grid-template-columns:200px repeat(auto-fill,100px) 300px}",
25065    );
25066    minify_test(".foo { grid-template-columns: [linename1 linename2] 100px repeat(auto-fit, [linename1] 300px) [linename3]; }", ".foo{grid-template-columns:[linename1 linename2]100px repeat(auto-fit,[linename1]300px)[linename3]}");
25067    minify_test(
25068      ".foo { grid-template-rows: [linename1 linename2] 100px repeat(auto-fit, [linename1] 300px) [linename3]; }",
25069      ".foo{grid-template-rows:[linename1 linename2]100px repeat(auto-fit,[linename1]300px)[linename3]}",
25070    );
25071
25072    minify_test(".foo { grid-auto-rows: auto; }", ".foo{grid-auto-rows:auto}");
25073    minify_test(".foo { grid-auto-rows: 1fr; }", ".foo{grid-auto-rows:1fr}");
25074    minify_test(".foo { grid-auto-rows: 100px; }", ".foo{grid-auto-rows:100px}");
25075    minify_test(
25076      ".foo { grid-auto-rows: min-content; }",
25077      ".foo{grid-auto-rows:min-content}",
25078    );
25079    minify_test(
25080      ".foo { grid-auto-rows: max-content; }",
25081      ".foo{grid-auto-rows:max-content}",
25082    );
25083    minify_test(
25084      ".foo { grid-auto-rows: minmax(100px,auto); }",
25085      ".foo{grid-auto-rows:minmax(100px,auto)}",
25086    );
25087    minify_test(
25088      ".foo { grid-auto-rows: fit-content(20%); }",
25089      ".foo{grid-auto-rows:fit-content(20%)}",
25090    );
25091    minify_test(
25092      ".foo { grid-auto-rows: 100px minmax(100px, auto) 10% 0.5fr fit-content(400px); }",
25093      ".foo{grid-auto-rows:100px minmax(100px,auto) 10% .5fr fit-content(400px)}",
25094    );
25095    minify_test(
25096      ".foo { grid-auto-columns: 100px minmax(100px, auto) 10% 0.5fr fit-content(400px); }",
25097      ".foo{grid-auto-columns:100px minmax(100px,auto) 10% .5fr fit-content(400px)}",
25098    );
25099
25100    minify_test(
25101      r#"
25102      .foo {
25103        grid-template-areas: "head head"
25104                             "nav  main"
25105                             "foot ....";
25106      }
25107    "#,
25108      ".foo{grid-template-areas:\"head head\"\"nav main\"\"foot.\"}",
25109    );
25110    minify_test(
25111      r#"
25112      .foo {
25113        grid-template-areas: "head head"
25114                             "nav  main"
25115                             ".... foot";
25116      }
25117    "#,
25118      ".foo{grid-template-areas:\"head head\"\"nav main\"\".foot\"}",
25119    );
25120    minify_test(
25121      r#"
25122      .foo {
25123        grid-template-areas: "head head"
25124                             "nav  main"
25125                             ".... ....";
25126      }
25127    "#,
25128      ".foo{grid-template-areas:\"head head\"\"nav main\"\". .\"}",
25129    );
25130
25131    // to grid-* shorthand
25132    minify_test(
25133      r#"
25134      .test-miss-areas {
25135        grid-template-columns: 1fr 90px;
25136        grid-template-rows: auto 80px;
25137        grid-template-areas: "one";
25138      }
25139    "#,
25140      ".test-miss-areas{grid-template:\"one\"\".\"80px/1fr 90px}",
25141    );
25142    test(
25143      r#"
25144      .test-miss-areas-2 {
25145        grid-template-columns: 1fr 1fr 1fr;
25146        grid-template-rows: 30px 60px 100px;
25147        grid-template-areas: "a a a" "b c c";
25148      }
25149    "#,
25150      indoc! { r#"
25151      .test-miss-areas-2 {
25152        grid-template: "a a a" 30px
25153                       "b c c" 60px
25154                       ". . ." 100px
25155                       / 1fr 1fr 1fr;
25156      }
25157    "#},
25158    );
25159
25160    test(
25161      r#"
25162      .test-miss-areas-3 {
25163        grid-template: 30px 60px 100px / 1fr 1fr 1fr;
25164        grid-template-areas: "a a a" "b c c";
25165      }
25166    "#,
25167      indoc! { r#"
25168      .test-miss-areas-3 {
25169        grid-template: "a a a" 30px
25170                       "b c c" 60px
25171                       ". . ." 100px
25172                       / 1fr 1fr 1fr;
25173      }
25174    "#},
25175    );
25176
25177    test(
25178      r#"
25179      .test-miss-areas-4 {
25180        grid: 30px 60px 100px / 1fr 1fr 1fr;
25181        grid-template-areas: "a a a" "b c c";
25182      }
25183    "#,
25184      indoc! { r#"
25185      .test-miss-areas-4 {
25186        grid: "a a a" 30px
25187              "b c c" 60px
25188              ". . ." 100px
25189              / 1fr 1fr 1fr;
25190      }
25191    "#},
25192    );
25193
25194    // test no unreachable error
25195    minify_test(
25196      r#"
25197    .grid-shorthand-areas {
25198      grid: auto / 1fr 3fr;
25199      grid-template-areas: ". content .";
25200    }
25201  "#,
25202      ".grid-shorthand-areas{grid:\".content.\"/1fr 3fr}",
25203    );
25204    minify_test(
25205      r#"
25206    .grid-shorthand-areas-rows {
25207      grid: auto / 1fr 3fr;
25208      grid-template-rows: 20px;
25209      grid-template-areas: ". content .";
25210    }
25211  "#,
25212      ".grid-shorthand-areas-rows{grid:\".content.\"20px/1fr 3fr}",
25213    );
25214
25215    // test grid-auto-flow: row in grid shorthand
25216    test(
25217      r#"
25218      .test-auto-flow-row-1 {
25219        grid: auto-flow   /  1fr 2fr 1fr;
25220        grid-template-areas: "  .   one  .  ";
25221      }
25222    "#,
25223      indoc! { r#"
25224      .test-auto-flow-row-1 {
25225        grid: auto-flow / 1fr 2fr 1fr;
25226        grid-template-areas: ". one .";
25227      }
25228    "#},
25229    );
25230    test(
25231      r#"
25232      .test-auto-flow-row-2 {
25233        grid: auto-flow   auto   /  100px   100px;
25234        grid-template-areas: " one  two ";
25235      }
25236    "#,
25237      indoc! { r#"
25238      .test-auto-flow-row-2 {
25239        grid: auto-flow / 100px 100px;
25240        grid-template-areas: "one two";
25241      }
25242    "#},
25243    );
25244    test(
25245      r#"
25246      .test-auto-flow-dense {
25247        grid: dense auto-flow  /  1fr 2fr;
25248        grid-template-areas: "  .   content  .  ";
25249      }
25250    "#,
25251      indoc! { r#"
25252      .test-auto-flow-dense {
25253        grid: auto-flow dense / 1fr 2fr;
25254        grid-template-areas: ". content .";
25255      }
25256    "#},
25257    );
25258    minify_test(
25259      r#"
25260      .grid-auto-flow-row-auto-rows {
25261        grid: auto-flow 40px / 1fr 90px;
25262        grid-template-areas: "a";
25263      }
25264    "#,
25265      ".grid-auto-flow-row-auto-rows{grid:auto-flow 40px/1fr 90px;grid-template-areas:\"a\"}",
25266    );
25267    minify_test(
25268      r#"
25269      .grid-auto-flow-row-auto-rows-multiple {
25270        grid: auto-flow 40px max-content / 1fr;
25271        grid-template-areas: ". a";
25272      }
25273    "#,
25274      ".grid-auto-flow-row-auto-rows-multiple{grid:auto-flow 40px max-content/1fr;grid-template-areas:\".a\"}",
25275    );
25276
25277    // test grid-auto-flow: column in grid shorthand
25278    test(
25279      r#"
25280      .test-auto-flow-column-1 {
25281        grid: 300px / auto-flow;
25282        grid-template-areas: "  .   one  .  ";
25283      }
25284    "#,
25285      indoc! { r#"
25286      .test-auto-flow-column-1 {
25287        grid: 300px / auto-flow;
25288        grid-template-areas: ". one .";
25289      }
25290    "#},
25291    );
25292    test(
25293      r#"
25294      .test-auto-flow-column-2 {
25295        grid: 200px 1fr / auto-flow auto;
25296        grid-template-areas: "  .   one  .  ";
25297      }
25298    "#,
25299      indoc! { r#"
25300      .test-auto-flow-column-2 {
25301        grid: 200px 1fr / auto-flow;
25302        grid-template-areas: ". one .";
25303      }
25304    "#},
25305    );
25306    test(
25307      r#"
25308      .test-auto-flow-column-dense {
25309        grid: 1fr 2fr / dense auto-flow;
25310        grid-template-areas: "  .   content  .  ";
25311      }
25312    "#,
25313      indoc! { r#"
25314      .test-auto-flow-column-dense {
25315        grid: 1fr 2fr / auto-flow dense;
25316        grid-template-areas: ". content .";
25317      }
25318    "#},
25319    );
25320    minify_test(
25321      r#"
25322      .grid-auto-flow-column-auto-rows {
25323        grid: 1fr 3fr / auto-flow 40px;
25324        grid-template-areas: "a";
25325      }
25326    "#,
25327      ".grid-auto-flow-column-auto-rows{grid:1fr 3fr/auto-flow 40px;grid-template-areas:\"a\"}",
25328    );
25329    minify_test(
25330      r#"
25331      .grid-auto-flow-column-auto-rows-multiple {
25332        grid: 1fr / auto-flow 40px max-content ;
25333        grid-template-areas: ". a";
25334      }
25335    "#,
25336      ".grid-auto-flow-column-auto-rows-multiple{grid:1fr/auto-flow 40px max-content;grid-template-areas:\".a\"}",
25337    );
25338
25339    test(
25340      r#"
25341      .foo {
25342        grid-template-areas: "head head" "nav  main" "foot ....";
25343      }
25344    "#,
25345      indoc! { r#"
25346      .foo {
25347        grid-template-areas: "head head"
25348                             "nav main"
25349                             "foot .";
25350      }
25351    "#},
25352    );
25353
25354    minify_test(
25355      r#"
25356      .foo {
25357        grid-template: [header-top] "a   a   a"     [header-bottom]
25358                       [main-top] "b   b   b" 1fr [main-bottom];
25359      }
25360    "#,
25361      ".foo{grid-template:[header-top]\"a a a\"[header-bottom main-top]\"b b b\"1fr[main-bottom]}",
25362    );
25363    minify_test(
25364      r#"
25365      .foo {
25366        grid-template: "head head"
25367                       "nav  main" 1fr
25368                       "foot ....";
25369      }
25370    "#,
25371      ".foo{grid-template:\"head head\"\"nav main\"1fr\"foot.\"}",
25372    );
25373    minify_test(
25374      r#"
25375      .foo {
25376        grid-template: [header-top] "a   a   a"     [header-bottom]
25377                         [main-top] "b   b   b" 1fr [main-bottom]
25378                                  / auto 1fr auto;
25379      }
25380    "#,
25381      ".foo{grid-template:[header-top]\"a a a\"[header-bottom main-top]\"b b b\"1fr[main-bottom]/auto 1fr auto}",
25382    );
25383
25384    minify_test(
25385      ".foo { grid-template: auto 1fr / auto 1fr auto; }",
25386      ".foo{grid-template:auto 1fr/auto 1fr auto}",
25387    );
25388    minify_test(
25389      ".foo { grid-template: [linename1 linename2] 100px repeat(auto-fit, [linename1] 300px) [linename3] / [linename1 linename2] 100px repeat(auto-fit, [linename1] 300px) [linename3]; }",
25390      ".foo{grid-template:[linename1 linename2]100px repeat(auto-fit,[linename1]300px)[linename3]/[linename1 linename2]100px repeat(auto-fit,[linename1]300px)[linename3]}"
25391    );
25392
25393    test(
25394      ".foo{grid-template:[header-top]\"a a a\"[header-bottom main-top]\"b b b\"1fr[main-bottom]/auto 1fr auto}",
25395      indoc! {r#"
25396        .foo {
25397          grid-template: [header-top] "a a a" [header-bottom]
25398                         [main-top] "b b b" 1fr [main-bottom]
25399                         / auto 1fr auto;
25400        }
25401      "#},
25402    );
25403    test(
25404      ".foo{grid-template:[header-top]\"a a a\"[main-top]\"b b b\"1fr/auto 1fr auto}",
25405      indoc! {r#"
25406        .foo {
25407          grid-template: [header-top] "a a a"
25408                         [main-top] "b b b" 1fr
25409                         / auto 1fr auto;
25410        }
25411      "#},
25412    );
25413
25414    minify_test(".foo { grid-auto-flow: row }", ".foo{grid-auto-flow:row}");
25415    minify_test(".foo { grid-auto-flow: column }", ".foo{grid-auto-flow:column}");
25416    minify_test(".foo { grid-auto-flow: row dense }", ".foo{grid-auto-flow:dense}");
25417    minify_test(".foo { grid-auto-flow: dense row }", ".foo{grid-auto-flow:dense}");
25418    minify_test(
25419      ".foo { grid-auto-flow: column dense }",
25420      ".foo{grid-auto-flow:column dense}",
25421    );
25422    minify_test(
25423      ".foo { grid-auto-flow: dense column }",
25424      ".foo{grid-auto-flow:column dense}",
25425    );
25426
25427    minify_test(".foo { grid: none }", ".foo{grid:none}");
25428    minify_test(".foo { grid: \"a\" 100px \"b\" 1fr }", ".foo{grid:\"a\"100px\"b\"1fr}");
25429    minify_test(
25430      ".foo { grid: [linename1] \"a\" 100px [linename2] }",
25431      ".foo{grid:[linename1]\"a\"100px[linename2]}",
25432    );
25433    minify_test(
25434      ".foo { grid: \"a\" 200px \"b\" min-content }",
25435      ".foo{grid:\"a\"200px\"b\"min-content}",
25436    );
25437    minify_test(
25438      ".foo { grid: \"a\" minmax(100px, max-content) \"b\" 20% }",
25439      ".foo{grid:\"a\"minmax(100px,max-content)\"b\"20%}",
25440    );
25441    minify_test(".foo { grid: 100px / 200px }", ".foo{grid:100px/200px}");
25442    minify_test(
25443      ".foo { grid: minmax(400px, min-content) / repeat(auto-fill, 50px) }",
25444      ".foo{grid:minmax(400px,min-content)/repeat(auto-fill,50px)}",
25445    );
25446
25447    minify_test(".foo { grid: 200px / auto-flow }", ".foo{grid:200px/auto-flow}");
25448    minify_test(".foo { grid: 30% / auto-flow dense }", ".foo{grid:30%/auto-flow dense}");
25449    minify_test(".foo { grid: 30% / dense auto-flow }", ".foo{grid:30%/auto-flow dense}");
25450    minify_test(
25451      ".foo { grid: repeat(3, [line1 line2 line3] 200px) / auto-flow 300px }",
25452      ".foo{grid:repeat(3,[line1 line2 line3]200px)/auto-flow 300px}",
25453    );
25454    minify_test(
25455      ".foo { grid: [line1] minmax(20em, max-content) / auto-flow dense 40% }",
25456      ".foo{grid:[line1]minmax(20em,max-content)/auto-flow dense 40%}",
25457    );
25458    minify_test(".foo { grid: none / auto-flow 1fr }", ".foo{grid:none/auto-flow 1fr}");
25459
25460    minify_test(".foo { grid: auto-flow / 200px }", ".foo{grid:none/200px}");
25461    minify_test(".foo { grid: auto-flow dense / 30% }", ".foo{grid:auto-flow dense/30%}");
25462    minify_test(".foo { grid: dense auto-flow / 30% }", ".foo{grid:auto-flow dense/30%}");
25463    minify_test(
25464      ".foo { grid: auto-flow 300px / repeat(3, [line1 line2 line3] 200px) }",
25465      ".foo{grid:auto-flow 300px/repeat(3,[line1 line2 line3]200px)}",
25466    );
25467    minify_test(
25468      ".foo { grid: auto-flow dense 40% / [line1] minmax(20em, max-content) }",
25469      ".foo{grid:auto-flow dense 40%/[line1]minmax(20em,max-content)}",
25470    );
25471
25472    minify_test(".foo { grid-row-start: auto }", ".foo{grid-row-start:auto}");
25473    minify_test(".foo { grid-row-start: some-area }", ".foo{grid-row-start:some-area}");
25474    minify_test(".foo { grid-row-start: 2 }", ".foo{grid-row-start:2}");
25475    minify_test(
25476      ".foo { grid-row-start: 2 some-line }",
25477      ".foo{grid-row-start:2 some-line}",
25478    );
25479    minify_test(
25480      ".foo { grid-row-start: some-line 2 }",
25481      ".foo{grid-row-start:2 some-line}",
25482    );
25483    minify_test(".foo { grid-row-start: span 3 }", ".foo{grid-row-start:span 3}");
25484    minify_test(
25485      ".foo { grid-row-start: span some-line }",
25486      ".foo{grid-row-start:span some-line}",
25487    );
25488    minify_test(
25489      ".foo { grid-row-start: span some-line 1 }",
25490      ".foo{grid-row-start:span some-line}",
25491    );
25492    minify_test(
25493      ".foo { grid-row-start: span 1 some-line }",
25494      ".foo{grid-row-start:span some-line}",
25495    );
25496    minify_test(
25497      ".foo { grid-row-start: span 5 some-line }",
25498      ".foo{grid-row-start:span 5 some-line}",
25499    );
25500    minify_test(
25501      ".foo { grid-row-start: span some-line 5 }",
25502      ".foo{grid-row-start:span 5 some-line}",
25503    );
25504
25505    minify_test(
25506      ".foo { grid-row-end: span 1 some-line }",
25507      ".foo{grid-row-end:span some-line}",
25508    );
25509    minify_test(
25510      ".foo { grid-column-start: span 1 some-line }",
25511      ".foo{grid-column-start:span some-line}",
25512    );
25513    minify_test(
25514      ".foo { grid-column-end: span 1 some-line }",
25515      ".foo{grid-column-end:span some-line}",
25516    );
25517
25518    minify_test(".foo { grid-row: 1 }", ".foo{grid-row:1}");
25519    minify_test(".foo { grid-row: 1 / auto }", ".foo{grid-row:1}");
25520    minify_test(".foo { grid-row: 1 / 1 }", ".foo{grid-row:1/1}");
25521    minify_test(".foo { grid-row: 1 / 3 }", ".foo{grid-row:1/3}");
25522    minify_test(".foo { grid-row: 1 / span 2 }", ".foo{grid-row:1/span 2}");
25523    minify_test(".foo { grid-row: main-start }", ".foo{grid-row:main-start}");
25524    minify_test(
25525      ".foo { grid-row: main-start / main-end }",
25526      ".foo{grid-row:main-start/main-end}",
25527    );
25528    minify_test(
25529      ".foo { grid-row: main-start / main-start }",
25530      ".foo{grid-row:main-start}",
25531    );
25532    minify_test(".foo { grid-column: 1 / auto }", ".foo{grid-column:1}");
25533
25534    minify_test(".foo { grid-area: a }", ".foo{grid-area:a}");
25535    minify_test(".foo { grid-area: a / a / a / a }", ".foo{grid-area:a}");
25536    minify_test(".foo { grid-area: a / b / a / b }", ".foo{grid-area:a/b}");
25537    minify_test(".foo { grid-area: a / b / c / b }", ".foo{grid-area:a/b/c}");
25538    minify_test(".foo { grid-area: a / b / c / d }", ".foo{grid-area:a/b/c/d}");
25539
25540    minify_test(".foo { grid-area: auto / auto / auto / auto }", ".foo{grid-area:auto}");
25541    minify_test(".foo { grid-area: 1 / auto }", ".foo{grid-area:1}");
25542    minify_test(".foo { grid-area: 1 / 2 / 3 / 4 }", ".foo{grid-area:1/2/3/4}");
25543    minify_test(".foo { grid-area: 1 / 1 / 1 / 1 }", ".foo{grid-area:1/1/1/1}");
25544
25545    test(
25546      r#"
25547        .foo{
25548          grid-template-rows: auto 1fr;
25549          grid-template-columns: auto 1fr auto;
25550          grid-template-areas: none;
25551        }
25552      "#,
25553      indoc! {r#"
25554        .foo {
25555          grid-template: auto 1fr / auto 1fr auto;
25556        }
25557      "#},
25558    );
25559
25560    test(
25561      r#"
25562        .foo{
25563          grid-template-areas: "a a a"
25564                               "b b b";
25565          grid-template-rows: [header-top] auto [header-bottom main-top] 1fr [main-bottom];
25566          grid-template-columns: auto 1fr auto;
25567        }
25568      "#,
25569      indoc! {r#"
25570        .foo {
25571          grid-template: [header-top] "a a a" [header-bottom]
25572                         [main-top] "b b b" 1fr [main-bottom]
25573                         / auto 1fr auto;
25574        }
25575      "#},
25576    );
25577
25578    test(
25579      r#"
25580        .foo{
25581          grid-template-areas: "a a a"
25582                               "b b b";
25583          grid-template-columns: repeat(3, 1fr);
25584          grid-template-rows: auto 1fr;
25585        }
25586      "#,
25587      indoc! {r#"
25588        .foo {
25589          grid-template-rows: auto 1fr;
25590          grid-template-columns: repeat(3, 1fr);
25591          grid-template-areas: "a a a"
25592                               "b b b";
25593        }
25594      "#},
25595    );
25596
25597    test(
25598      r#"
25599        .foo{
25600          grid-template-areas: "a a a"
25601                               "b b b";
25602          grid-template-columns: auto 1fr auto;
25603          grid-template-rows: repeat(2, 1fr);
25604        }
25605      "#,
25606      indoc! {r#"
25607        .foo {
25608          grid-template-rows: repeat(2, 1fr);
25609          grid-template-columns: auto 1fr auto;
25610          grid-template-areas: "a a a"
25611                               "b b b";
25612        }
25613      "#},
25614    );
25615
25616    test(
25617      r#"
25618        .foo{
25619          grid-template-areas: ". a a ."
25620                               ". b b .";
25621          grid-template-rows: auto 1fr;
25622          grid-template-columns: 10px 1fr 1fr 10px;
25623        }
25624      "#,
25625      indoc! {r#"
25626        .foo {
25627          grid-template: ". a a ."
25628                         ". b b ." 1fr
25629                         / 10px 1fr 1fr 10px;
25630        }
25631      "#},
25632    );
25633
25634    test(
25635      r#"
25636        .foo{
25637          grid-template-areas: none;
25638          grid-template-columns: auto 1fr auto;
25639          grid-template-rows: repeat(2, 1fr);
25640        }
25641      "#,
25642      indoc! {r#"
25643        .foo {
25644          grid-template: repeat(2, 1fr) / auto 1fr auto;
25645        }
25646      "#},
25647    );
25648
25649    test(
25650      r#"
25651        .foo{
25652          grid-template-areas: none;
25653          grid-template-columns: none;
25654          grid-template-rows: none;
25655        }
25656      "#,
25657      indoc! {r#"
25658        .foo {
25659          grid-template: none;
25660        }
25661      "#},
25662    );
25663
25664    test(
25665      r#"
25666        .foo{
25667          grid-template-areas: "a a a"
25668                               "b b b";
25669          grid-template-rows: [header-top] auto [header-bottom main-top] 1fr [main-bottom];
25670          grid-template-columns: auto 1fr auto;
25671          grid-auto-flow: row;
25672          grid-auto-rows: auto;
25673          grid-auto-columns: auto;
25674        }
25675      "#,
25676      indoc! {r#"
25677        .foo {
25678          grid: [header-top] "a a a" [header-bottom]
25679                [main-top] "b b b" 1fr [main-bottom]
25680                / auto 1fr auto;
25681        }
25682      "#},
25683    );
25684
25685    test(
25686      r#"
25687        .foo{
25688          grid-template-areas: none;
25689          grid-template-columns: auto 1fr auto;
25690          grid-template-rows: repeat(2, 1fr);
25691          grid-auto-flow: row;
25692          grid-auto-rows: auto;
25693          grid-auto-columns: auto;
25694        }
25695      "#,
25696      indoc! {r#"
25697        .foo {
25698          grid: repeat(2, 1fr) / auto 1fr auto;
25699        }
25700      "#},
25701    );
25702
25703    test(
25704      r#"
25705        .foo{
25706          grid-template-areas: none;
25707          grid-template-columns: none;
25708          grid-template-rows: none;
25709          grid-auto-flow: row;
25710          grid-auto-rows: auto;
25711          grid-auto-columns: auto;
25712        }
25713      "#,
25714      indoc! {r#"
25715        .foo {
25716          grid: none;
25717        }
25718      "#},
25719    );
25720
25721    test(
25722      r#"
25723        .foo{
25724          grid-template-areas: "a a a"
25725                               "b b b";
25726          grid-template-rows: [header-top] auto [header-bottom main-top] 1fr [main-bottom];
25727          grid-template-columns: auto 1fr auto;
25728          grid-auto-flow: column;
25729          grid-auto-rows: 1fr;
25730          grid-auto-columns: 1fr;
25731        }
25732      "#,
25733      indoc! {r#"
25734        .foo {
25735          grid-template: [header-top] "a a a" [header-bottom]
25736                         [main-top] "b b b" 1fr [main-bottom]
25737                         / auto 1fr auto;
25738          grid-auto-rows: 1fr;
25739          grid-auto-columns: 1fr;
25740          grid-auto-flow: column;
25741        }
25742      "#},
25743    );
25744
25745    test(
25746      r#"
25747        .foo{
25748          grid-template-rows: auto 1fr;
25749          grid-template-columns: auto 1fr auto;
25750          grid-template-areas: none;
25751          grid-auto-flow: row;
25752          grid-auto-rows: auto;
25753          grid-auto-columns: auto;
25754        }
25755      "#,
25756      indoc! {r#"
25757        .foo {
25758          grid: auto 1fr / auto 1fr auto;
25759        }
25760      "#},
25761    );
25762
25763    test(
25764      r#"
25765        .foo{
25766          grid-template-rows: auto 1fr;
25767          grid-template-columns: auto 1fr auto;
25768          grid-template-areas: none;
25769          grid-auto-flow: column;
25770          grid-auto-rows: 1fr;
25771          grid-auto-columns: 1fr;
25772        }
25773      "#,
25774      indoc! {r#"
25775        .foo {
25776          grid-template: auto 1fr / auto 1fr auto;
25777          grid-auto-rows: 1fr;
25778          grid-auto-columns: 1fr;
25779          grid-auto-flow: column;
25780        }
25781      "#},
25782    );
25783
25784    test(
25785      r#"
25786        .foo{
25787          grid-template-rows: none;
25788          grid-template-columns: auto 1fr auto;
25789          grid-template-areas: none;
25790          grid-auto-flow: column;
25791          grid-auto-rows: 1fr;
25792          grid-auto-columns: 1fr;
25793        }
25794      "#,
25795      indoc! {r#"
25796        .foo {
25797          grid-template: none / auto 1fr auto;
25798          grid-auto-rows: 1fr;
25799          grid-auto-columns: 1fr;
25800          grid-auto-flow: column;
25801        }
25802      "#},
25803    );
25804
25805    test(
25806      r#"
25807        .foo{
25808          grid-template-rows: none;
25809          grid-template-columns: auto 1fr auto;
25810          grid-template-areas: none;
25811          grid-auto-flow: row;
25812          grid-auto-rows: 1fr;
25813          grid-auto-columns: auto;
25814        }
25815      "#,
25816      indoc! {r#"
25817        .foo {
25818          grid: auto-flow 1fr / auto 1fr auto;
25819        }
25820      "#},
25821    );
25822
25823    test(
25824      r#"
25825        .foo{
25826          grid-template-rows: none;
25827          grid-template-columns: auto 1fr auto;
25828          grid-template-areas: none;
25829          grid-auto-flow: row dense;
25830          grid-auto-rows: 1fr;
25831          grid-auto-columns: auto;
25832        }
25833      "#,
25834      indoc! {r#"
25835        .foo {
25836          grid: auto-flow dense 1fr / auto 1fr auto;
25837        }
25838      "#},
25839    );
25840
25841    test(
25842      r#"
25843        .foo{
25844          grid-template-rows: auto 1fr auto;
25845          grid-template-columns: none;
25846          grid-template-areas: none;
25847          grid-auto-flow: column;
25848          grid-auto-rows: auto;
25849          grid-auto-columns: 1fr;
25850        }
25851      "#,
25852      indoc! {r#"
25853        .foo {
25854          grid: auto 1fr auto / auto-flow 1fr;
25855        }
25856      "#},
25857    );
25858
25859    test(
25860      r#"
25861        .foo{
25862          grid-template-rows: auto 1fr auto;
25863          grid-template-columns: none;
25864          grid-template-areas: none;
25865          grid-auto-flow: column dense;
25866          grid-auto-rows: auto;
25867          grid-auto-columns: 1fr;
25868        }
25869      "#,
25870      indoc! {r#"
25871        .foo {
25872          grid: auto 1fr auto / auto-flow dense 1fr;
25873        }
25874      "#},
25875    );
25876
25877    test(
25878      r#"
25879        .foo{
25880          grid-template-rows: auto 1fr auto;
25881          grid-template-columns: none;
25882          grid-template-areas: none;
25883          grid-auto-flow: var(--auto-flow);
25884          grid-auto-rows: auto;
25885          grid-auto-columns: 1fr;
25886        }
25887      "#,
25888      indoc! {r#"
25889        .foo {
25890          grid-template: auto 1fr auto / none;
25891          grid-auto-flow: var(--auto-flow);
25892          grid-auto-rows: auto;
25893          grid-auto-columns: 1fr;
25894        }
25895      "#},
25896    );
25897
25898    test(
25899      r#"
25900        .foo{
25901          grid: auto 1fr auto / auto-flow dense 1fr;
25902          grid-template-rows: 1fr 1fr 1fr;
25903        }
25904      "#,
25905      indoc! {r#"
25906        .foo {
25907          grid: 1fr 1fr 1fr / auto-flow dense 1fr;
25908        }
25909      "#},
25910    );
25911
25912    test(
25913      r#"
25914        .foo{
25915          grid-row-start: a;
25916          grid-row-end: a;
25917          grid-column-start: a;
25918          grid-column-end: a;
25919        }
25920      "#,
25921      indoc! {r#"
25922        .foo {
25923          grid-area: a;
25924        }
25925      "#},
25926    );
25927
25928    test(
25929      r#"
25930        .foo{
25931          grid-row-start: 1;
25932          grid-row-end: 2;
25933          grid-column-start: 3;
25934          grid-column-end: 4;
25935        }
25936      "#,
25937      indoc! {r#"
25938        .foo {
25939          grid-area: 1 / 3 / 2 / 4;
25940        }
25941      "#},
25942    );
25943
25944    test(
25945      r#"
25946        .foo{
25947          grid-row-start: a;
25948          grid-row-end: a;
25949        }
25950      "#,
25951      indoc! {r#"
25952        .foo {
25953          grid-row: a;
25954        }
25955      "#},
25956    );
25957
25958    test(
25959      r#"
25960        .foo{
25961          grid-column-start: a;
25962          grid-column-end: a;
25963        }
25964      "#,
25965      indoc! {r#"
25966        .foo {
25967          grid-column: a;
25968        }
25969      "#},
25970    );
25971  }
25972
25973  #[test]
25974  fn test_moz_document() {
25975    minify_test(
25976      r#"
25977      @-moz-document url-prefix() {
25978        h1 {
25979          color: yellow;
25980        }
25981      }
25982    "#,
25983      "@-moz-document url-prefix(){h1{color:#ff0}}",
25984    );
25985    minify_test(
25986      r#"
25987      @-moz-document url-prefix("") {
25988        h1 {
25989          color: yellow;
25990        }
25991      }
25992    "#,
25993      "@-moz-document url-prefix(){h1{color:#ff0}}",
25994    );
25995    error_test(
25996      "@-moz-document url-prefix(foo) {}",
25997      ParserError::UnexpectedToken(crate::properties::custom::Token::Ident("foo".into())),
25998    );
25999    error_test(
26000      "@-moz-document url-prefix(\"foo\") {}",
26001      ParserError::UnexpectedToken(crate::properties::custom::Token::String("foo".into())),
26002    );
26003  }
26004
26005  #[test]
26006  fn test_custom_properties() {
26007    minify_test(".foo { --test: ; }", ".foo{--test: }");
26008    minify_test(".foo { --test:  ; }", ".foo{--test: }");
26009    minify_test(".foo { --test: foo; }", ".foo{--test:foo}");
26010    minify_test(".foo { --test:  foo; }", ".foo{--test:foo}");
26011    minify_test(".foo { --test: foo ; }", ".foo{--test:foo}");
26012    minify_test(".foo { --test: foo  ; }", ".foo{--test:foo}");
26013    minify_test(".foo { --test:foo; }", ".foo{--test:foo}");
26014    minify_test(".foo { --test:foo ; }", ".foo{--test:foo}");
26015    minify_test(".foo { --test: var(--foo, 20px); }", ".foo{--test:var(--foo,20px)}");
26016    minify_test(
26017      ".foo { transition: var(--foo, 20px),\nvar(--bar, 40px); }",
26018      ".foo{transition:var(--foo,20px), var(--bar,40px)}",
26019    );
26020    minify_test(
26021      ".foo { background: var(--color) var(--image); }",
26022      ".foo{background:var(--color) var(--image)}",
26023    );
26024    minify_test(
26025      ".foo { height: calc(var(--spectrum-global-dimension-size-300) / 2);",
26026      ".foo{height:calc(var(--spectrum-global-dimension-size-300) / 2)}",
26027    );
26028    minify_test(
26029      ".foo { color: var(--color, rgb(255, 255, 0)); }",
26030      ".foo{color:var(--color,#ff0)}",
26031    );
26032    minify_test(
26033      ".foo { color: var(--color, #ffff00); }",
26034      ".foo{color:var(--color,#ff0)}",
26035    );
26036    minify_test(
26037      ".foo { color: var(--color, rgb(var(--red), var(--green), 0)); }",
26038      ".foo{color:var(--color,rgb(var(--red), var(--green), 0))}",
26039    );
26040    minify_test(".foo { --test: .5s; }", ".foo{--test:.5s}");
26041    minify_test(".foo { --theme-sizes-1\\/12: 2 }", ".foo{--theme-sizes-1\\/12:2}");
26042    minify_test(".foo { --test: 0px; }", ".foo{--test:0px}");
26043    test(
26044      ".foo { transform: var(--bar, ) }",
26045      indoc! {r#"
26046      .foo {
26047        transform: var(--bar, );
26048      }
26049      "#},
26050    );
26051    test(
26052      ".foo { transform: env(--bar, ) }",
26053      indoc! {r#"
26054      .foo {
26055        transform: env(--bar, );
26056      }
26057      "#},
26058    );
26059
26060    // Test attr() function with type() syntax - minified
26061    minify_test(
26062      ".foo { background-color: attr(data-color type(<color>)); }",
26063      ".foo{background-color:attr(data-color type(<color>))}",
26064    );
26065    minify_test(
26066      ".foo { width: attr(data-width type(<length>), 100px); }",
26067      ".foo{width:attr(data-width type(<length>), 100px)}",
26068    );
26069
26070    minify_test(".foo { width: attr( data-foo    % ); }", ".foo{width:attr(data-foo %)}");
26071
26072    // <attr-args> = attr( <declaration-value>, <declaration-value>? )
26073    // Like var(), a bare comma can be used with nothing following it, indicating that the second <declaration-value> was passed, just as an empty sequence.
26074    // Spec: https://drafts.csswg.org/css-values-5/#funcdef-attr
26075    minify_test(
26076      ".foo { width: attr( data-foo    %, ); }",
26077      ".foo{width:attr(data-foo %,)}",
26078    );
26079
26080    minify_test(
26081      ".foo { width: attr( data-foo    px ); }",
26082      ".foo{width:attr(data-foo px)}",
26083    );
26084
26085    minify_test(
26086      ".foo { width: attr(data-foo    number ); }",
26087      ".foo{width:attr(data-foo number)}",
26088    );
26089
26090    minify_test(
26091      ".foo { width: attr(data-foo    raw-string); }",
26092      ".foo{width:attr(data-foo raw-string)}",
26093    );
26094
26095    // Test attr() function with type() syntax - non-minified (issue with extra spaces)
26096    test(
26097      ".foo { background-color: attr(data-color type(<color>)); }",
26098      ".foo {\n  background-color: attr(data-color type(<color>));\n}\n",
26099    );
26100    test(
26101      ".foo { width: attr(data-width type(<length>), 100px); }",
26102      ".foo {\n  width: attr(data-width type(<length>), 100px);\n}\n",
26103    );
26104
26105    prefix_test(
26106      r#"
26107      .foo {
26108        --custom: lab(40% 56.6 39);
26109      }
26110    "#,
26111      indoc! {r#"
26112      .foo {
26113        --custom: #b32323;
26114      }
26115
26116      @supports (color: lab(0% 0 0)) {
26117        .foo {
26118          --custom: lab(40% 56.6 39);
26119        }
26120      }
26121    "#},
26122      Browsers {
26123        chrome: Some(90 << 16),
26124        ..Browsers::default()
26125      },
26126    );
26127
26128    prefix_test(
26129      r#"
26130      @supports (color: lab(0% 0 0)) {
26131        .foo {
26132          --custom: lab(40% 56.6 39);
26133        }
26134      }
26135    "#,
26136      indoc! {r#"
26137      @supports (color: lab(0% 0 0)) {
26138        .foo {
26139          --custom: lab(40% 56.6 39);
26140        }
26141      }
26142    "#},
26143      Browsers {
26144        chrome: Some(90 << 16),
26145        ..Browsers::default()
26146      },
26147    );
26148
26149    prefix_test(
26150      r#"
26151      .foo {
26152        --custom: lab(40% 56.6 39) !important;
26153      }
26154    "#,
26155      indoc! {r#"
26156      .foo {
26157        --custom: #b32323 !important;
26158      }
26159
26160      @supports (color: lab(0% 0 0)) {
26161        .foo {
26162          --custom: lab(40% 56.6 39) !important;
26163        }
26164      }
26165    "#},
26166      Browsers {
26167        chrome: Some(90 << 16),
26168        ..Browsers::default()
26169      },
26170    );
26171
26172    prefix_test(
26173      r#"
26174      @supports (color: lab(0% 0 0)) {
26175        .foo {
26176          --custom: lab(40% 56.6 39) !important;
26177        }
26178      }
26179    "#,
26180      indoc! {r#"
26181      @supports (color: lab(0% 0 0)) {
26182        .foo {
26183          --custom: lab(40% 56.6 39) !important;
26184        }
26185      }
26186    "#},
26187      Browsers {
26188        chrome: Some(90 << 16),
26189        ..Browsers::default()
26190      },
26191    );
26192
26193    prefix_test(
26194      r#"
26195      .foo {
26196        --custom: lab(40% 56.6 39);
26197      }
26198    "#,
26199      indoc! {r#"
26200      .foo {
26201        --custom: #b32323;
26202      }
26203
26204      @supports (color: color(display-p3 0 0 0)) {
26205        .foo {
26206          --custom: color(display-p3 .643308 .192455 .167712);
26207        }
26208      }
26209
26210      @supports (color: lab(0% 0 0)) {
26211        .foo {
26212          --custom: lab(40% 56.6 39);
26213        }
26214      }
26215    "#},
26216      Browsers {
26217        chrome: Some(90 << 16),
26218        safari: Some(14 << 16),
26219        ..Browsers::default()
26220      },
26221    );
26222
26223    prefix_test(
26224      r#"
26225      @supports (color: color(display-p3 0 0 0)) {
26226        .foo {
26227          --custom: color(display-p3 .643308 .192455 .167712);
26228        }
26229      }
26230
26231      @supports (color: lab(0% 0 0)) {
26232        .foo {
26233          --custom: lab(40% 56.6 39);
26234        }
26235      }
26236    "#,
26237      indoc! {r#"
26238      @supports (color: color(display-p3 0 0 0)) {
26239        .foo {
26240          --custom: color(display-p3 .643308 .192455 .167712);
26241        }
26242      }
26243
26244      @supports (color: lab(0% 0 0)) {
26245        .foo {
26246          --custom: lab(40% 56.6 39);
26247        }
26248      }
26249    "#},
26250      Browsers {
26251        chrome: Some(90 << 16),
26252        safari: Some(14 << 16),
26253        ..Browsers::default()
26254      },
26255    );
26256
26257    prefix_test(
26258      r#"
26259      .foo {
26260        --custom: lab(40% 56.6 39);
26261      }
26262    "#,
26263      indoc! {r#"
26264      .foo {
26265        --custom: color(display-p3 .643308 .192455 .167712);
26266      }
26267
26268      @supports (color: lab(0% 0 0)) {
26269        .foo {
26270          --custom: lab(40% 56.6 39);
26271        }
26272      }
26273    "#},
26274      Browsers {
26275        safari: Some(14 << 16),
26276        ..Browsers::default()
26277      },
26278    );
26279
26280    prefix_test(
26281      r#"
26282      .foo {
26283        --custom: lab(40% 56.6 39);
26284      }
26285    "#,
26286      indoc! {r#"
26287      .foo {
26288        --custom: lab(40% 56.6 39);
26289      }
26290    "#},
26291      Browsers {
26292        safari: Some(15 << 16),
26293        ..Browsers::default()
26294      },
26295    );
26296
26297    prefix_test(
26298      r#"
26299      .foo {
26300        --custom: oklab(59.686% 0.1009 0.1192);
26301      }
26302    "#,
26303      indoc! {r#"
26304      .foo {
26305        --custom: lab(52.2319% 40.1449 59.9171);
26306      }
26307    "#},
26308      Browsers {
26309        safari: Some(15 << 16),
26310        ..Browsers::default()
26311      },
26312    );
26313
26314    prefix_test(
26315      r#"
26316      .foo {
26317        --custom: oklab(59.686% 0.1009 0.1192);
26318      }
26319    "#,
26320      indoc! {r#"
26321      .foo {
26322        --custom: color(display-p3 .724144 .386777 .148795);
26323      }
26324
26325      @supports (color: lab(0% 0 0)) {
26326        .foo {
26327          --custom: lab(52.2319% 40.1449 59.9171);
26328        }
26329      }
26330    "#},
26331      Browsers {
26332        safari: Some(14 << 16),
26333        ..Browsers::default()
26334      },
26335    );
26336
26337    prefix_test(
26338      r#"
26339      .foo {
26340        --custom: oklab(59.686% 0.1009 0.1192);
26341      }
26342    "#,
26343      indoc! {r#"
26344      .foo {
26345        --custom: #c65d07;
26346      }
26347
26348      @supports (color: color(display-p3 0 0 0)) {
26349        .foo {
26350          --custom: color(display-p3 .724144 .386777 .148795);
26351        }
26352      }
26353
26354      @supports (color: lab(0% 0 0)) {
26355        .foo {
26356          --custom: lab(52.2319% 40.1449 59.9171);
26357        }
26358      }
26359    "#},
26360      Browsers {
26361        safari: Some(14 << 16),
26362        chrome: Some(90 << 16),
26363        ..Browsers::default()
26364      },
26365    );
26366
26367    prefix_test(
26368      r#"
26369      .foo {
26370        --foo: oklab(59.686% 0.1009 0.1192);
26371        --bar: lab(40% 56.6 39);
26372      }
26373    "#,
26374      indoc! {r#"
26375      .foo {
26376        --foo: #c65d07;
26377        --bar: #b32323;
26378      }
26379
26380      @supports (color: color(display-p3 0 0 0)) {
26381        .foo {
26382          --foo: color(display-p3 .724144 .386777 .148795);
26383          --bar: color(display-p3 .643308 .192455 .167712);
26384        }
26385      }
26386
26387      @supports (color: lab(0% 0 0)) {
26388        .foo {
26389          --foo: lab(52.2319% 40.1449 59.9171);
26390          --bar: lab(40% 56.6 39);
26391        }
26392      }
26393    "#},
26394      Browsers {
26395        safari: Some(14 << 16),
26396        chrome: Some(90 << 16),
26397        ..Browsers::default()
26398      },
26399    );
26400
26401    prefix_test(
26402      r#"
26403      .foo {
26404        --foo: color(display-p3 0 1 0);
26405      }
26406    "#,
26407      indoc! {r#"
26408      .foo {
26409        --foo: #00fb29;
26410      }
26411
26412      @supports (color: color(display-p3 0 0 0)) {
26413        .foo {
26414          --foo: color(display-p3 0 1 0);
26415        }
26416      }
26417    "#},
26418      Browsers {
26419        safari: Some(14 << 16),
26420        chrome: Some(90 << 16),
26421        ..Browsers::default()
26422      },
26423    );
26424
26425    prefix_test(
26426      r#"
26427      @supports (color: color(display-p3 0 0 0)) {
26428        .foo {
26429          --foo: color(display-p3 0 1 0);
26430        }
26431      }
26432    "#,
26433      indoc! {r#"
26434      @supports (color: color(display-p3 0 0 0)) {
26435        .foo {
26436          --foo: color(display-p3 0 1 0);
26437        }
26438      }
26439    "#},
26440      Browsers {
26441        safari: Some(14 << 16),
26442        chrome: Some(90 << 16),
26443        ..Browsers::default()
26444      },
26445    );
26446
26447    prefix_test(
26448      r#"
26449      .foo {
26450        --foo: color(display-p3 0 1 0);
26451      }
26452    "#,
26453      indoc! {r#"
26454      .foo {
26455        --foo: color(display-p3 0 1 0);
26456      }
26457    "#},
26458      Browsers {
26459        safari: Some(14 << 16),
26460        ..Browsers::default()
26461      },
26462    );
26463
26464    prefix_test(
26465      r#"
26466      .foo {
26467        --foo: color(display-p3 0 1 0);
26468      }
26469    "#,
26470      indoc! {r#"
26471      .foo {
26472        --foo: #00fb29;
26473      }
26474
26475      @supports (color: color(display-p3 0 0 0)) {
26476        .foo {
26477          --foo: color(display-p3 0 1 0);
26478        }
26479      }
26480    "#},
26481      Browsers {
26482        safari: Some(15 << 16),
26483        chrome: Some(90 << 16),
26484        ..Browsers::default()
26485      },
26486    );
26487
26488    prefix_test(
26489      r#"
26490      .foo {
26491        --foo: color(display-p3 0 1 0);
26492      }
26493    "#,
26494      indoc! {r#"
26495      .foo {
26496        --foo: #00fb29;
26497      }
26498
26499      @supports (color: color(display-p3 0 0 0)) {
26500        .foo {
26501          --foo: color(display-p3 0 1 0);
26502        }
26503      }
26504    "#},
26505      Browsers {
26506        chrome: Some(90 << 16),
26507        ..Browsers::default()
26508      },
26509    );
26510
26511    prefix_test(
26512      r#"
26513      .foo {
26514        text-decoration: underline;
26515      }
26516
26517      .foo {
26518        --custom: lab(40% 56.6 39);
26519      }
26520    "#,
26521      indoc! {r#"
26522      .foo {
26523        --custom: #b32323;
26524        text-decoration: underline;
26525      }
26526
26527      @supports (color: lab(0% 0 0)) {
26528        .foo {
26529          --custom: lab(40% 56.6 39);
26530        }
26531      }
26532    "#},
26533      Browsers {
26534        chrome: Some(90 << 16),
26535        ..Browsers::default()
26536      },
26537    );
26538
26539    prefix_test(
26540      r#"
26541      .foo {
26542        --custom: lab(40% 56.6 39);
26543      }
26544
26545      .foo {
26546        text-decoration: underline;
26547      }
26548    "#,
26549      indoc! {r#"
26550      .foo {
26551        --custom: #b32323;
26552      }
26553
26554      @supports (color: lab(0% 0 0)) {
26555        .foo {
26556          --custom: lab(40% 56.6 39);
26557        }
26558      }
26559
26560      .foo {
26561        text-decoration: underline;
26562      }
26563    "#},
26564      Browsers {
26565        chrome: Some(90 << 16),
26566        ..Browsers::default()
26567      },
26568    );
26569
26570    prefix_test(
26571      r#"
26572      @keyframes foo {
26573        from {
26574          --custom: lab(40% 56.6 39);
26575        }
26576
26577        to {
26578          --custom: lch(50.998% 135.363 338);
26579        }
26580      }
26581    "#,
26582      indoc! {r#"
26583      @keyframes foo {
26584        from {
26585          --custom: #b32323;
26586        }
26587
26588        to {
26589          --custom: #f000c0;
26590        }
26591      }
26592
26593      @supports (color: lab(0% 0 0)) {
26594        @keyframes foo {
26595          from {
26596            --custom: lab(40% 56.6 39);
26597          }
26598
26599          to {
26600            --custom: lab(50.998% 125.506 -50.7078);
26601          }
26602        }
26603      }
26604    "#},
26605      Browsers {
26606        chrome: Some(90 << 16),
26607        ..Browsers::default()
26608      },
26609    );
26610
26611    prefix_test(
26612      r#"
26613      @supports (color: lab(0% 0 0)) {
26614        @keyframes foo {
26615          from {
26616            --custom: lab(40% 56.6 39);
26617          }
26618
26619          to {
26620            --custom: lab(50.998% 125.506 -50.7078);
26621          }
26622        }
26623      }
26624    "#,
26625      indoc! {r#"
26626      @supports (color: lab(0% 0 0)) {
26627        @keyframes foo {
26628          from {
26629            --custom: lab(40% 56.6 39);
26630          }
26631
26632          to {
26633            --custom: lab(50.998% 125.506 -50.7078);
26634          }
26635        }
26636      }
26637    "#},
26638      Browsers {
26639        chrome: Some(90 << 16),
26640        ..Browsers::default()
26641      },
26642    );
26643
26644    prefix_test(
26645      r#"
26646      @keyframes foo {
26647        from {
26648          --custom: lab(40% 56.6 39);
26649        }
26650
26651        to {
26652          --custom: lch(50.998% 135.363 338);
26653        }
26654      }
26655    "#,
26656      indoc! {r#"
26657      @keyframes foo {
26658        from {
26659          --custom: #b32323;
26660        }
26661
26662        to {
26663          --custom: #f000c0;
26664        }
26665      }
26666
26667      @supports (color: color(display-p3 0 0 0)) {
26668        @keyframes foo {
26669          from {
26670            --custom: color(display-p3 .643308 .192455 .167712);
26671          }
26672
26673          to {
26674            --custom: color(display-p3 .972962 -.362078 .804206);
26675          }
26676        }
26677      }
26678
26679      @supports (color: lab(0% 0 0)) {
26680        @keyframes foo {
26681          from {
26682            --custom: lab(40% 56.6 39);
26683          }
26684
26685          to {
26686            --custom: lab(50.998% 125.506 -50.7078);
26687          }
26688        }
26689      }
26690    "#},
26691      Browsers {
26692        chrome: Some(90 << 16),
26693        safari: Some(14 << 16),
26694        ..Browsers::default()
26695      },
26696    );
26697
26698    prefix_test(
26699      r#"
26700      @supports (color: color(display-p3 0 0 0)) {
26701        @keyframes foo {
26702          from {
26703            --custom: color(display-p3 .643308 .192455 .167712);
26704          }
26705
26706          to {
26707            --custom: color(display-p3 .972962 -.362078 .804206);
26708          }
26709        }
26710      }
26711
26712      @supports (color: lab(0% 0 0)) {
26713        @keyframes foo {
26714          from {
26715            --custom: lab(40% 56.6 39);
26716          }
26717
26718          to {
26719            --custom: lab(50.998% 125.506 -50.7078);
26720          }
26721        }
26722      }
26723    "#,
26724      indoc! {r#"
26725      @supports (color: color(display-p3 0 0 0)) {
26726        @keyframes foo {
26727          from {
26728            --custom: color(display-p3 .643308 .192455 .167712);
26729          }
26730
26731          to {
26732            --custom: color(display-p3 .972962 -.362078 .804206);
26733          }
26734        }
26735      }
26736
26737      @supports (color: lab(0% 0 0)) {
26738        @keyframes foo {
26739          from {
26740            --custom: lab(40% 56.6 39);
26741          }
26742
26743          to {
26744            --custom: lab(50.998% 125.506 -50.7078);
26745          }
26746        }
26747      }
26748    "#},
26749      Browsers {
26750        chrome: Some(90 << 16),
26751        safari: Some(14 << 16),
26752        ..Browsers::default()
26753      },
26754    );
26755
26756    prefix_test(
26757      r#"
26758      @keyframes foo {
26759        from {
26760          --custom: #ff0;
26761          opacity: 0;
26762        }
26763
26764        to {
26765          --custom: lch(50.998% 135.363 338);
26766          opacity: 1;
26767        }
26768      }
26769    "#,
26770      indoc! {r#"
26771      @keyframes foo {
26772        from {
26773          --custom: #ff0;
26774          opacity: 0;
26775        }
26776
26777        to {
26778          --custom: #f000c0;
26779          opacity: 1;
26780        }
26781      }
26782
26783      @supports (color: lab(0% 0 0)) {
26784        @keyframes foo {
26785          from {
26786            --custom: #ff0;
26787            opacity: 0;
26788          }
26789
26790          to {
26791            --custom: lab(50.998% 125.506 -50.7078);
26792            opacity: 1;
26793          }
26794        }
26795      }
26796    "#},
26797      Browsers {
26798        chrome: Some(90 << 16),
26799        ..Browsers::default()
26800      },
26801    );
26802
26803    prefix_test(
26804      r#"
26805      @keyframes foo {
26806        from {
26807          text-decoration: var(--foo) lab(29.2345% 39.3825 20.0664);
26808        }
26809      }
26810    "#,
26811      indoc! {r#"
26812      @keyframes foo {
26813        from {
26814          text-decoration: var(--foo) #7d2329;
26815        }
26816      }
26817
26818      @supports (color: lab(0% 0 0)) {
26819        @keyframes foo {
26820          from {
26821            text-decoration: var(--foo) lab(29.2345% 39.3825 20.0664);
26822          }
26823        }
26824      }
26825    "#},
26826      Browsers {
26827        chrome: Some(90 << 16),
26828        ..Browsers::default()
26829      },
26830    );
26831  }
26832
26833  #[test]
26834  fn test_charset() {
26835    test(
26836      r#"
26837      @charset "UTF-8";
26838
26839      .foo {
26840        color: red;
26841      }
26842
26843      @charset "UTF-8";
26844
26845      .bar {
26846        color: yellow;
26847      }
26848    "#,
26849      indoc! { r#"
26850      .foo {
26851        color: red;
26852      }
26853
26854      .bar {
26855        color: #ff0;
26856      }
26857    "#},
26858    )
26859  }
26860
26861  #[test]
26862  fn test_style_attr() {
26863    attr_test("color: yellow; flex: 1 1 auto", "color: #ff0; flex: auto", false, None);
26864    attr_test("color: yellow; flex: 1 1 auto", "color:#ff0;flex:auto", true, None);
26865    attr_test(
26866      "border-inline-start: 2px solid red",
26867      "border-inline-start: 2px solid red",
26868      false,
26869      Some(Browsers {
26870        safari: Some(12 << 16),
26871        ..Browsers::default()
26872      }),
26873    );
26874    attr_test(
26875      "color: lab(40% 56.6 39);",
26876      "color:#b32323;color:lab(40% 56.6 39)",
26877      true,
26878      Some(Browsers {
26879        safari: Some(8 << 16),
26880        ..Browsers::default()
26881      }),
26882    );
26883    attr_test(
26884      "--foo: lab(40% 56.6 39);",
26885      "--foo:#b32323",
26886      true,
26887      Some(Browsers {
26888        safari: Some(8 << 16),
26889        ..Browsers::default()
26890      }),
26891    );
26892    attr_test(
26893      "text-decoration: var(--foo) lab(40% 56.6 39);",
26894      "text-decoration:var(--foo) #b32323",
26895      true,
26896      Some(Browsers {
26897        chrome: Some(90 << 16),
26898        ..Browsers::default()
26899      }),
26900    );
26901  }
26902
26903  #[test]
26904  fn test_nesting() {
26905    nesting_test(
26906      r#"
26907        .foo {
26908          @apply --mixin;
26909          @apply --mixin-no-args();
26910          @apply --mixin-args(1, 2);
26911          @apply --mixin-with-empty-body {};
26912          @apply --mixin-with-body {
26913            color: red;
26914          }
26915          .bar {
26916            @apply --nested;
26917          }
26918        }
26919      "#,
26920      indoc! {r#"
26921        .foo {
26922          @apply --mixin;
26923          @apply --mixin-no-args();
26924          @apply --mixin-args(1, 2);
26925          @apply --mixin-with-empty-body {
26926            
26927          }
26928          @apply --mixin-with-body {
26929            color: red;
26930          }
26931        }
26932
26933        .foo .bar {
26934          @apply --nested;
26935        }
26936      "#},
26937    );
26938
26939    minify_test(
26940      r#"
26941        .foo {
26942          @apply --mixin;
26943          @apply --mixin-no-args();
26944          @apply --mixin-args(1,2);
26945          @apply --mixin-with-empty-body {};
26946          @apply --mixin-with-body {
26947            color: red;
26948          };
26949          .bar {
26950            @apply --nested;
26951          }
26952        }
26953      "#,
26954      ".foo{@apply --mixin;@apply --mixin-no-args();@apply --mixin-args(1,2);@apply --mixin-with-empty-body{}@apply --mixin-with-body{color: red;}& .bar{@apply --nested;}}",
26955    );
26956
26957    nesting_test(
26958      r#"
26959        .foo {
26960          color: blue;
26961          & > .bar { color: red; }
26962        }
26963      "#,
26964      indoc! {r#"
26965        .foo {
26966          color: #00f;
26967        }
26968
26969        .foo > .bar {
26970          color: red;
26971        }
26972      "#},
26973    );
26974
26975    nesting_test(
26976      r#"
26977        .foo {
26978          color: blue;
26979          &.bar { color: red; }
26980        }
26981      "#,
26982      indoc! {r#"
26983        .foo {
26984          color: #00f;
26985        }
26986
26987        .foo.bar {
26988          color: red;
26989        }
26990      "#},
26991    );
26992
26993    nesting_test(
26994      r#"
26995        .foo, .bar {
26996          color: blue;
26997          & + .baz, &.qux { color: red; }
26998        }
26999      "#,
27000      indoc! {r#"
27001        .foo, .bar {
27002          color: #00f;
27003        }
27004
27005        :is(.foo, .bar) + .baz, :is(.foo, .bar).qux {
27006          color: red;
27007        }
27008      "#},
27009    );
27010
27011    nesting_test(
27012      r#"
27013        .foo {
27014          color: blue;
27015          & .bar & .baz & .qux { color: red; }
27016        }
27017      "#,
27018      indoc! {r#"
27019        .foo {
27020          color: #00f;
27021        }
27022
27023        .foo .bar .foo .baz .foo .qux {
27024          color: red;
27025        }
27026      "#},
27027    );
27028
27029    nesting_test(
27030      r#"
27031        .foo {
27032          color: blue;
27033          & { padding: 2ch; }
27034        }
27035      "#,
27036      indoc! {r#"
27037        .foo {
27038          color: #00f;
27039        }
27040
27041        .foo {
27042          padding: 2ch;
27043        }
27044      "#},
27045    );
27046
27047    nesting_test(
27048      r#"
27049        .foo {
27050          color: blue;
27051          && { padding: 2ch; }
27052        }
27053      "#,
27054      indoc! {r#"
27055        .foo {
27056          color: #00f;
27057        }
27058
27059        .foo.foo {
27060          padding: 2ch;
27061        }
27062      "#},
27063    );
27064
27065    nesting_test(
27066      r#"
27067        .error, .invalid {
27068          &:hover > .baz { color: red; }
27069        }
27070      "#,
27071      indoc! {r#"
27072        :is(.error, .invalid):hover > .baz {
27073          color: red;
27074        }
27075      "#},
27076    );
27077
27078    nesting_test(
27079      r#"
27080        .foo {
27081          &:is(.bar, &.baz) { color: red; }
27082        }
27083      "#,
27084      indoc! {r#"
27085        .foo:is(.bar, .foo.baz) {
27086          color: red;
27087        }
27088      "#},
27089    );
27090
27091    nesting_test(
27092      r#"
27093        figure {
27094          margin: 0;
27095
27096          & > figcaption {
27097            background: hsl(0 0% 0% / 50%);
27098
27099            & > p {
27100              font-size: .9rem;
27101            }
27102          }
27103        }
27104      "#,
27105      indoc! {r#"
27106        figure {
27107          margin: 0;
27108        }
27109
27110        figure > figcaption {
27111          background: #00000080;
27112        }
27113
27114        figure > figcaption > p {
27115          font-size: .9rem;
27116        }
27117      "#},
27118    );
27119
27120    nesting_test(
27121      r#"
27122        .foo {
27123          display: grid;
27124
27125          @media (orientation: landscape) {
27126            grid-auto-flow: column;
27127          }
27128        }
27129      "#,
27130      indoc! {r#"
27131        .foo {
27132          display: grid;
27133        }
27134
27135        @media (orientation: landscape) {
27136          .foo {
27137            grid-auto-flow: column;
27138          }
27139        }
27140      "#},
27141    );
27142
27143    nesting_test(
27144      r#"
27145        .foo {
27146          display: grid;
27147
27148          @media (orientation: landscape) {
27149            grid-auto-flow: column;
27150
27151            @media (width > 1024px) {
27152              max-inline-size: 1024px;
27153            }
27154          }
27155        }
27156      "#,
27157      indoc! {r#"
27158        .foo {
27159          display: grid;
27160        }
27161
27162        @media (orientation: landscape) {
27163          .foo {
27164            grid-auto-flow: column;
27165          }
27166
27167          @media not (max-width: 1024px) {
27168            .foo {
27169              max-inline-size: 1024px;
27170            }
27171          }
27172        }
27173      "#},
27174    );
27175
27176    nesting_test(
27177      r#"
27178        .foo {
27179          @media (min-width: 640px) {
27180            color: red !important;
27181          }
27182        }
27183      "#,
27184      indoc! {r#"
27185        @media (min-width: 640px) {
27186          .foo {
27187            color: red !important;
27188          }
27189        }
27190      "#},
27191    );
27192
27193    nesting_test(
27194      r#"
27195        .foo {
27196          display: grid;
27197
27198          @supports (foo: bar) {
27199            grid-auto-flow: column;
27200          }
27201        }
27202      "#,
27203      indoc! {r#"
27204        .foo {
27205          display: grid;
27206        }
27207
27208        @supports (foo: bar) {
27209          .foo {
27210            grid-auto-flow: column;
27211          }
27212        }
27213      "#},
27214    );
27215
27216    nesting_test(
27217      r#"
27218        .foo {
27219          display: grid;
27220
27221          @container (min-width: 100px) {
27222            grid-auto-flow: column;
27223          }
27224        }
27225      "#,
27226      indoc! {r#"
27227        .foo {
27228          display: grid;
27229        }
27230
27231        @container (width >= 100px) {
27232          .foo {
27233            grid-auto-flow: column;
27234          }
27235        }
27236      "#},
27237    );
27238
27239    nesting_test(
27240      r#"
27241        .foo {
27242          display: grid;
27243
27244          @layer test {
27245            grid-auto-flow: column;
27246          }
27247        }
27248      "#,
27249      indoc! {r#"
27250        .foo {
27251          display: grid;
27252        }
27253
27254        @layer test {
27255          .foo {
27256            grid-auto-flow: column;
27257          }
27258        }
27259      "#},
27260    );
27261
27262    nesting_test(
27263      r#"
27264        .foo {
27265          display: grid;
27266
27267          @layer {
27268            grid-auto-flow: column;
27269          }
27270        }
27271      "#,
27272      indoc! {r#"
27273        .foo {
27274          display: grid;
27275        }
27276
27277        @layer {
27278          .foo {
27279            grid-auto-flow: column;
27280          }
27281        }
27282      "#},
27283    );
27284
27285    nesting_test(
27286      r#"
27287        @namespace "http://example.com/foo";
27288        @namespace toto "http://toto.example.org";
27289
27290        .foo {
27291          &div {
27292            color: red;
27293          }
27294
27295          &* {
27296            color: green;
27297          }
27298
27299          &|x {
27300            color: red;
27301          }
27302
27303          &*|x {
27304            color: green;
27305          }
27306
27307          &toto|x {
27308            color: red;
27309          }
27310        }
27311      "#,
27312      indoc! {r#"
27313        @namespace "http://example.com/foo";
27314        @namespace toto "http://toto.example.org";
27315
27316        div.foo {
27317          color: red;
27318        }
27319
27320        *.foo {
27321          color: green;
27322        }
27323
27324        |x.foo {
27325          color: red;
27326        }
27327
27328        *|x.foo {
27329          color: green;
27330        }
27331
27332        toto|x.foo {
27333          color: red;
27334        }
27335      "#},
27336    );
27337
27338    nesting_test(
27339      r#"
27340        .foo {
27341          &article > figure {
27342            color: red;
27343          }
27344        }
27345      "#,
27346      indoc! {r#"
27347        article.foo > figure {
27348          color: red;
27349        }
27350      "#},
27351    );
27352
27353    nesting_test(
27354      r#"
27355        div {
27356          &.bar {
27357            background: green;
27358          }
27359        }
27360      "#,
27361      indoc! {r#"
27362        div.bar {
27363          background: green;
27364        }
27365      "#},
27366    );
27367
27368    nesting_test(
27369      r#"
27370        div > .foo {
27371          &span {
27372            background: green;
27373          }
27374        }
27375      "#,
27376      indoc! {r#"
27377        span:is(div > .foo) {
27378          background: green;
27379        }
27380      "#},
27381    );
27382
27383    nesting_test(
27384      r#"
27385        .foo {
27386          & h1 {
27387            background: green;
27388          }
27389        }
27390      "#,
27391      indoc! {r#"
27392        .foo h1 {
27393          background: green;
27394        }
27395      "#},
27396    );
27397
27398    nesting_test(
27399      r#"
27400        .foo .bar {
27401          &h1 {
27402            background: green;
27403          }
27404        }
27405      "#,
27406      indoc! {r#"
27407        h1:is(.foo .bar) {
27408          background: green;
27409        }
27410      "#},
27411    );
27412
27413    nesting_test(
27414      r#"
27415        .foo.bar {
27416          &h1 {
27417            background: green;
27418          }
27419        }
27420      "#,
27421      indoc! {r#"
27422        h1.foo.bar {
27423          background: green;
27424        }
27425      "#},
27426    );
27427
27428    nesting_test(
27429      r#"
27430        .foo .bar {
27431          &h1 .baz {
27432            background: green;
27433          }
27434        }
27435      "#,
27436      indoc! {r#"
27437        h1:is(.foo .bar) .baz {
27438          background: green;
27439        }
27440      "#},
27441    );
27442
27443    nesting_test(
27444      r#"
27445        .foo .bar {
27446          &.baz {
27447            background: green;
27448          }
27449        }
27450      "#,
27451      indoc! {r#"
27452        .foo .bar.baz {
27453          background: green;
27454        }
27455      "#},
27456    );
27457
27458    nesting_test(
27459      r#"
27460        .foo {
27461          color: red;
27462          @nest .parent & {
27463            color: blue;
27464          }
27465        }
27466      "#,
27467      indoc! {r#"
27468        .foo {
27469          color: red;
27470        }
27471
27472        .parent .foo {
27473          color: #00f;
27474        }
27475      "#},
27476    );
27477
27478    nesting_test(
27479      r#"
27480        .foo {
27481          color: red;
27482          @nest :not(&) {
27483            color: blue;
27484          }
27485        }
27486      "#,
27487      indoc! {r#"
27488        .foo {
27489          color: red;
27490        }
27491
27492        :not(.foo) {
27493          color: #00f;
27494        }
27495      "#},
27496    );
27497
27498    nesting_test(
27499      r#"
27500        .foo {
27501          color: blue;
27502          @nest .bar & {
27503            color: red;
27504            &.baz {
27505              color: green;
27506            }
27507          }
27508        }
27509      "#,
27510      indoc! {r#"
27511        .foo {
27512          color: #00f;
27513        }
27514
27515        .bar .foo {
27516          color: red;
27517        }
27518
27519        .bar .foo.baz {
27520          color: green;
27521        }
27522      "#},
27523    );
27524
27525    nesting_test(
27526      r#"
27527        .foo {
27528          @nest :not(&) {
27529            color: red;
27530          }
27531
27532          & h1 {
27533            background: green;
27534          }
27535        }
27536      "#,
27537      indoc! {r#"
27538        :not(.foo) {
27539          color: red;
27540        }
27541
27542        .foo h1 {
27543          background: green;
27544        }
27545      "#},
27546    );
27547
27548    nesting_test(
27549      r#"
27550        .foo {
27551          & h1 {
27552            background: green;
27553          }
27554
27555          @nest :not(&) {
27556            color: red;
27557          }
27558        }
27559      "#,
27560      indoc! {r#"
27561        .foo h1 {
27562          background: green;
27563        }
27564
27565        :not(.foo) {
27566          color: red;
27567        }
27568      "#},
27569    );
27570
27571    nesting_test(
27572      r#"
27573        .foo .bar {
27574          @nest h1& {
27575            background: green;
27576          }
27577        }
27578      "#,
27579      indoc! {r#"
27580        h1:is(.foo .bar) {
27581          background: green;
27582        }
27583      "#},
27584    );
27585
27586    nesting_test(
27587      r#"
27588        @namespace "http://example.com/foo";
27589        @namespace toto "http://toto.example.org";
27590
27591        div {
27592          @nest .foo& {
27593            color: red;
27594          }
27595        }
27596
27597        * {
27598          @nest .foo& {
27599            color: red;
27600          }
27601        }
27602
27603        |x {
27604          @nest .foo& {
27605            color: red;
27606          }
27607        }
27608
27609        *|x {
27610          @nest .foo& {
27611            color: red;
27612          }
27613        }
27614
27615        toto|x {
27616          @nest .foo& {
27617            color: red;
27618          }
27619        }
27620      "#,
27621      indoc! {r#"
27622        @namespace "http://example.com/foo";
27623        @namespace toto "http://toto.example.org";
27624
27625        .foo:is(div) {
27626          color: red;
27627        }
27628
27629        .foo:is(*) {
27630          color: red;
27631        }
27632
27633        .foo:is(|x) {
27634          color: red;
27635        }
27636
27637        .foo:is(*|x) {
27638          color: red;
27639        }
27640
27641        .foo:is(toto|x) {
27642          color: red;
27643        }
27644      "#},
27645    );
27646
27647    nesting_test(
27648      r#"
27649        .foo .bar {
27650          @nest h1 .baz& {
27651            background: green;
27652          }
27653        }
27654      "#,
27655      indoc! {r#"
27656        h1 .baz:is(.foo .bar) {
27657          background: green;
27658        }
27659      "#},
27660    );
27661
27662    nesting_test(
27663      r#"
27664        .foo .bar {
27665          @nest .baz& {
27666            background: green;
27667          }
27668        }
27669      "#,
27670      indoc! {r#"
27671        .baz:is(.foo .bar) {
27672          background: green;
27673        }
27674      "#},
27675    );
27676
27677    nesting_test(
27678      r#"
27679        .foo .bar {
27680          @nest .baz & {
27681            background: green;
27682          }
27683        }
27684      "#,
27685      indoc! {r#"
27686        .baz :is(.foo .bar) {
27687          background: green;
27688        }
27689      "#},
27690    );
27691
27692    nesting_test(
27693      r#"
27694        .foo {
27695          color: red;
27696          @nest & > .bar {
27697            color: blue;
27698          }
27699        }
27700      "#,
27701      indoc! {r#"
27702        .foo {
27703          color: red;
27704        }
27705
27706        .foo > .bar {
27707          color: #00f;
27708        }
27709      "#},
27710    );
27711
27712    nesting_test(
27713      r#"
27714      .foo {
27715        color: red;
27716        .bar {
27717          color: blue;
27718        }
27719      }
27720      "#,
27721      indoc! {r#"
27722      .foo {
27723        color: red;
27724      }
27725
27726      .foo .bar {
27727        color: #00f;
27728      }
27729      "#},
27730    );
27731
27732    nesting_test(
27733      r#"
27734      .foo {
27735        color: red;
27736        .bar & {
27737          color: blue;
27738        }
27739      }
27740      "#,
27741      indoc! {r#"
27742      .foo {
27743        color: red;
27744      }
27745
27746      .bar .foo {
27747        color: #00f;
27748      }
27749      "#},
27750    );
27751
27752    nesting_test(
27753      r#"
27754      .foo {
27755        color: red;
27756        + .bar + & { color: blue; }
27757      }
27758      "#,
27759      indoc! {r#"
27760      .foo {
27761        color: red;
27762      }
27763
27764      .foo + .bar + .foo {
27765        color: #00f;
27766      }
27767      "#},
27768    );
27769
27770    nesting_test(
27771      r#"
27772      .foo {
27773        color: red;
27774        .bar & {
27775          color: blue;
27776        }
27777      }
27778      "#,
27779      indoc! {r#"
27780      .foo {
27781        color: red;
27782      }
27783
27784      .bar .foo {
27785        color: #00f;
27786      }
27787      "#},
27788    );
27789
27790    nesting_test(
27791      r#"
27792        .foo {
27793          color: red;
27794          .parent & {
27795            color: blue;
27796          }
27797        }
27798      "#,
27799      indoc! {r#"
27800        .foo {
27801          color: red;
27802        }
27803
27804        .parent .foo {
27805          color: #00f;
27806        }
27807      "#},
27808    );
27809
27810    nesting_test(
27811      r#"
27812        .foo {
27813          color: red;
27814          :not(&) {
27815            color: blue;
27816          }
27817        }
27818      "#,
27819      indoc! {r#"
27820        .foo {
27821          color: red;
27822        }
27823
27824        :not(.foo) {
27825          color: #00f;
27826        }
27827      "#},
27828    );
27829
27830    nesting_test(
27831      r#"
27832        .foo {
27833          color: blue;
27834          .bar & {
27835            color: red;
27836            &.baz {
27837              color: green;
27838            }
27839          }
27840        }
27841      "#,
27842      indoc! {r#"
27843        .foo {
27844          color: #00f;
27845        }
27846
27847        .bar .foo {
27848          color: red;
27849        }
27850
27851        .bar .foo.baz {
27852          color: green;
27853        }
27854      "#},
27855    );
27856
27857    nesting_test(
27858      r#"
27859        .foo {
27860          :not(&) {
27861            color: red;
27862          }
27863
27864          & h1 {
27865            background: green;
27866          }
27867        }
27868      "#,
27869      indoc! {r#"
27870        :not(.foo) {
27871          color: red;
27872        }
27873
27874        .foo h1 {
27875          background: green;
27876        }
27877      "#},
27878    );
27879
27880    nesting_test(
27881      r#"
27882        .foo {
27883          & h1 {
27884            background: green;
27885          }
27886
27887          :not(&) {
27888            color: red;
27889          }
27890        }
27891      "#,
27892      indoc! {r#"
27893        .foo h1 {
27894          background: green;
27895        }
27896
27897        :not(.foo) {
27898          color: red;
27899        }
27900      "#},
27901    );
27902
27903    nesting_test(
27904      r#"
27905        .foo .bar {
27906          :is(h1)& {
27907            background: green;
27908          }
27909        }
27910      "#,
27911      indoc! {r#"
27912        :is(h1):is(.foo .bar) {
27913          background: green;
27914        }
27915      "#},
27916    );
27917
27918    nesting_test(
27919      r#"
27920        @namespace "http://example.com/foo";
27921        @namespace toto "http://toto.example.org";
27922
27923        div {
27924          .foo& {
27925            color: red;
27926          }
27927        }
27928
27929        * {
27930          .foo& {
27931            color: red;
27932          }
27933        }
27934
27935        |x {
27936          .foo& {
27937            color: red;
27938          }
27939        }
27940
27941        *|x {
27942          .foo& {
27943            color: red;
27944          }
27945        }
27946
27947        toto|x {
27948          .foo& {
27949            color: red;
27950          }
27951        }
27952      "#,
27953      indoc! {r#"
27954        @namespace "http://example.com/foo";
27955        @namespace toto "http://toto.example.org";
27956
27957        .foo:is(div) {
27958          color: red;
27959        }
27960
27961        .foo:is(*) {
27962          color: red;
27963        }
27964
27965        .foo:is(|x) {
27966          color: red;
27967        }
27968
27969        .foo:is(*|x) {
27970          color: red;
27971        }
27972
27973        .foo:is(toto|x) {
27974          color: red;
27975        }
27976      "#},
27977    );
27978
27979    nesting_test(
27980      r#"
27981        .foo .bar {
27982          :is(h1) .baz& {
27983            background: green;
27984          }
27985        }
27986      "#,
27987      indoc! {r#"
27988        :is(h1) .baz:is(.foo .bar) {
27989          background: green;
27990        }
27991      "#},
27992    );
27993
27994    nesting_test(
27995      r#"
27996        .foo .bar {
27997          .baz& {
27998            background: green;
27999          }
28000        }
28001      "#,
28002      indoc! {r#"
28003        .baz:is(.foo .bar) {
28004          background: green;
28005        }
28006      "#},
28007    );
28008
28009    nesting_test(
28010      r#"
28011        .foo .bar {
28012          .baz & {
28013            background: green;
28014          }
28015        }
28016      "#,
28017      indoc! {r#"
28018        .baz :is(.foo .bar) {
28019          background: green;
28020        }
28021      "#},
28022    );
28023
28024    nesting_test(
28025      r#"
28026        .foo {
28027          .bar {
28028            color: blue;
28029          }
28030          color: red;
28031        }
28032      "#,
28033      indoc! {r#"
28034        .foo .bar {
28035          color: #00f;
28036        }
28037
28038        .foo {
28039          color: red;
28040        }
28041      "#},
28042    );
28043
28044    nesting_test(
28045      r#"
28046        article {
28047          color: green;
28048          & { color: blue; }
28049          color: red;
28050        }
28051      "#,
28052      indoc! {r#"
28053        article {
28054          color: green;
28055        }
28056
28057        article {
28058          color: #00f;
28059        }
28060
28061        article {
28062          color: red;
28063        }
28064      "#},
28065    );
28066
28067    nesting_test(
28068      r#"
28069        & .foo {
28070          color: red;
28071        }
28072      "#,
28073      indoc! {r#"
28074        :scope .foo {
28075          color: red;
28076        }
28077      "#},
28078    );
28079
28080    nesting_test(
28081      r#"
28082        &.foo {
28083          color: red;
28084        }
28085      "#,
28086      indoc! {r#"
28087        :scope.foo {
28088          color: red;
28089        }
28090      "#},
28091    );
28092
28093    nesting_test(
28094      r#"
28095        .foo& {
28096          color: red;
28097        }
28098      "#,
28099      indoc! {r#"
28100        .foo:scope {
28101          color: red;
28102        }
28103      "#},
28104    );
28105
28106    nesting_test(
28107      r#"
28108        &html {
28109          color: red;
28110        }
28111      "#,
28112      indoc! {r#"
28113        html:scope {
28114          color: red;
28115        }
28116      "#},
28117    );
28118
28119    nesting_test(
28120      r#"
28121        .foo {
28122          color: blue;
28123          div {
28124            color: red;
28125          }
28126        }
28127      "#,
28128      indoc! {r#"
28129        .foo {
28130          color: #00f;
28131        }
28132
28133        .foo div {
28134          color: red;
28135        }
28136      "#},
28137    );
28138
28139    nesting_test(
28140      r#"
28141        div {
28142          color: blue;
28143
28144          button:focus {
28145            color: red;
28146          }
28147        }
28148      "#,
28149      indoc! {r#"
28150        div {
28151          color: #00f;
28152        }
28153
28154        div button:focus {
28155          color: red;
28156        }
28157      "#},
28158    );
28159    nesting_test(
28160      r#"
28161        div {
28162          color: blue;
28163
28164          --button:focus {
28165            color: red;
28166          }
28167        }
28168      "#,
28169      indoc! {r#"
28170        div {
28171          color: #00f;
28172          --button: focus {
28173                    color: red;
28174                  };
28175        }
28176      "#},
28177    );
28178    nesting_test(
28179      r#"
28180      .foo {
28181        &::before, &::after {
28182          background: blue;
28183          @media screen {
28184            background: orange;
28185          }
28186        }
28187      }
28188      "#,
28189      indoc! {r#"
28190      .foo:before, .foo:after {
28191        background: #00f;
28192      }
28193
28194      @media screen {
28195        .foo:before, .foo:after {
28196          background: orange;
28197        }
28198      }
28199      "#},
28200    );
28201
28202    nesting_test_no_targets(
28203      r#"
28204        .foo {
28205          color: blue;
28206          @nest .bar & {
28207            color: red;
28208            &.baz {
28209              color: green;
28210            }
28211          }
28212        }
28213      "#,
28214      indoc! {r#"
28215        .foo {
28216          color: #00f;
28217
28218          @nest .bar & {
28219            color: red;
28220
28221            &.baz {
28222              color: green;
28223            }
28224          }
28225        }
28226      "#},
28227    );
28228
28229    nesting_test_no_targets(
28230      r#"
28231        .foo {
28232          color: blue;
28233          &div {
28234            color: red;
28235          }
28236
28237          &span {
28238            color: purple;
28239          }
28240        }
28241      "#,
28242      indoc! {r#"
28243        .foo {
28244          color: #00f;
28245
28246          &div {
28247            color: red;
28248          }
28249
28250          &span {
28251            color: purple;
28252          }
28253        }
28254      "#},
28255    );
28256
28257    nesting_test_no_targets(
28258      r#"
28259        .error, .invalid {
28260          &:hover > .baz { color: red; }
28261        }
28262      "#,
28263      indoc! {r#"
28264        .error, .invalid {
28265          &:hover > .baz {
28266            color: red;
28267          }
28268        }
28269      "#},
28270    );
28271
28272    nesting_test_with_targets(
28273      r#"
28274        .foo {
28275          color: blue;
28276          & > .bar { color: red; }
28277        }
28278      "#,
28279      indoc! {r#"
28280        .foo {
28281          color: #00f;
28282        }
28283
28284        .foo > .bar {
28285          color: red;
28286        }
28287      "#},
28288      Targets {
28289        browsers: Some(Browsers {
28290          chrome: Some(112 << 16),
28291          ..Browsers::default()
28292        }),
28293        include: Features::Nesting,
28294        exclude: Features::empty(),
28295      },
28296    );
28297    nesting_test_with_targets(
28298      r#"
28299        .foo {
28300          color: blue;
28301          & > .bar { color: red; }
28302        }
28303      "#,
28304      indoc! {r#"
28305        .foo {
28306          color: #00f;
28307
28308          & > .bar {
28309            color: red;
28310          }
28311        }
28312      "#},
28313      Targets {
28314        browsers: Some(Browsers {
28315          chrome: Some(50 << 16),
28316          ..Browsers::default()
28317        }),
28318        include: Features::empty(),
28319        exclude: Features::Nesting,
28320      },
28321    );
28322
28323    let mut stylesheet = StyleSheet::parse(
28324      r#"
28325      .foo {
28326        color: blue;
28327        .bar {
28328          color: red;
28329        }
28330      }
28331      "#,
28332      ParserOptions::default(),
28333    )
28334    .unwrap();
28335    stylesheet.minify(MinifyOptions::default()).unwrap();
28336    let res = stylesheet
28337      .to_css(
28338        PrinterOptions {
28339          minify: true,
28340          ..PrinterOptions::default()
28341        },
28342        None::<&mut ()>,
28343      )
28344      .unwrap();
28345    assert_eq!(res.code, ".foo{color:#00f;& .bar{color:red}}");
28346
28347    nesting_test_with_targets(
28348      r#"
28349        .a {
28350          &.b,
28351          &.c {
28352            &.d {
28353              color: red;
28354            }
28355          }
28356        }
28357      "#,
28358      indoc! {r#"
28359        .a.b.d {
28360          color: red;
28361        }
28362
28363        .a.c.d {
28364          color: red;
28365        }
28366      "#},
28367      Targets {
28368        browsers: Some(Browsers {
28369          safari: Some(13 << 16),
28370          ..Browsers::default()
28371        }),
28372        include: Features::Nesting,
28373        exclude: Features::empty(),
28374      },
28375    );
28376
28377    minify_test(
28378      r#"
28379    .foo {
28380      color: red;
28381      .bar {
28382        color: green;
28383      }
28384      color: blue;
28385      .baz {
28386        color: pink;
28387      }
28388    }"#,
28389      ".foo{color:red;& .bar{color:green}color:#00f;& .baz{color:pink}}",
28390    );
28391  }
28392
28393  #[test]
28394  fn test_nesting_error_recovery() {
28395    error_recovery_test(
28396      "
28397    .container {
28398      padding: 3rem;
28399      @media (max-width: --styled-jsx-placeholder-0__) {
28400        .responsive {
28401          color: purple;
28402        }
28403      }
28404    }
28405    ",
28406    );
28407  }
28408
28409  #[test]
28410  fn test_css_variable_error_recovery() {
28411    error_recovery_test("
28412    .container {
28413      --local-var: --styled-jsx-placeholder-0__;
28414      color: var(--text-color);
28415      background: linear-gradient(to right, --styled-jsx-placeholder-1__, --styled-jsx-placeholder-2__);
28416
28417      .item {
28418        transform: translate(calc(var(--x) + --styled-jsx-placeholder-3__px), calc(var(--y) + --styled-jsx-placeholder-4__px));
28419      }
28420
28421      div {
28422        margin: calc(10px + --styled-jsx-placeholder-5__px);
28423      }
28424    }
28425  ");
28426  }
28427
28428  #[test]
28429  fn test_css_modules() {
28430    css_modules_test(
28431      r#"
28432      .foo {
28433        color: red;
28434      }
28435
28436      #id {
28437        animation: 2s test;
28438      }
28439
28440      @keyframes test {
28441        from { color: red }
28442        to { color: yellow }
28443      }
28444
28445      @counter-style circles {
28446        symbols: Ⓐ Ⓑ Ⓒ;
28447      }
28448
28449      ul {
28450        list-style: circles;
28451      }
28452
28453      ol {
28454        list-style-type: none;
28455      }
28456
28457      li {
28458        list-style-type: disc;
28459      }
28460
28461      @keyframes fade {
28462        from { opacity: 0 }
28463        to { opacity: 1 }
28464      }
28465    "#,
28466      indoc! {r#"
28467      .EgL3uq_foo {
28468        color: red;
28469      }
28470
28471      #EgL3uq_id {
28472        animation: 2s EgL3uq_test;
28473      }
28474
28475      @keyframes EgL3uq_test {
28476        from {
28477          color: red;
28478        }
28479
28480        to {
28481          color: #ff0;
28482        }
28483      }
28484
28485      @counter-style EgL3uq_circles {
28486        symbols: Ⓐ Ⓑ Ⓒ;
28487      }
28488
28489      ul {
28490        list-style: EgL3uq_circles;
28491      }
28492
28493      ol {
28494        list-style-type: none;
28495      }
28496
28497      li {
28498        list-style-type: disc;
28499      }
28500
28501      @keyframes EgL3uq_fade {
28502        from {
28503          opacity: 0;
28504        }
28505
28506        to {
28507          opacity: 1;
28508        }
28509      }
28510    "#},
28511      map! {
28512        "foo" => "EgL3uq_foo",
28513        "id" => "EgL3uq_id",
28514        "test" => "EgL3uq_test" referenced: true,
28515        "circles" => "EgL3uq_circles" referenced: true,
28516        "fade" => "EgL3uq_fade"
28517      },
28518      IndexMap::new(),
28519      Default::default(),
28520      false,
28521    );
28522
28523    css_modules_test(
28524      r#"
28525      .foo {
28526        color: red;
28527      }
28528
28529      #id {
28530        animation: 2s test;
28531      }
28532
28533      @keyframes test {
28534        from { color: red }
28535        to { color: yellow }
28536      }
28537    "#,
28538      indoc! {r#"
28539      .EgL3uq_foo {
28540        color: red;
28541      }
28542
28543      #EgL3uq_id {
28544        animation: 2s test;
28545      }
28546
28547      @keyframes test {
28548        from {
28549          color: red;
28550        }
28551
28552        to {
28553          color: #ff0;
28554        }
28555      }
28556    "#},
28557      map! {
28558        "foo" => "EgL3uq_foo",
28559        "id" => "EgL3uq_id"
28560      },
28561      IndexMap::new(),
28562      crate::css_modules::Config {
28563        animation: false,
28564        // custom_idents: false,
28565        ..Default::default()
28566      },
28567      false,
28568    );
28569
28570    css_modules_test(
28571      r#"
28572      @counter-style circles {
28573        symbols: Ⓐ Ⓑ Ⓒ;
28574      }
28575
28576      ul {
28577        list-style: circles;
28578      }
28579
28580      ol {
28581        list-style-type: none;
28582      }
28583
28584      li {
28585        list-style-type: disc;
28586      }
28587    "#,
28588      indoc! {r#"
28589      @counter-style circles {
28590        symbols: Ⓐ Ⓑ Ⓒ;
28591      }
28592
28593      ul {
28594        list-style: circles;
28595      }
28596
28597      ol {
28598        list-style-type: none;
28599      }
28600
28601      li {
28602        list-style-type: disc;
28603      }
28604    "#},
28605      map! {
28606        "circles" => "EgL3uq_circles" referenced: true
28607      },
28608      IndexMap::new(),
28609      crate::css_modules::Config {
28610        custom_idents: false,
28611        ..Default::default()
28612      },
28613      false,
28614    );
28615
28616    css_modules_test(
28617      r#"
28618      body {
28619        grid: [header-top] "a a a" [header-bottom]
28620              [main-top] "b b b" 1fr [main-bottom]
28621              / auto 1fr auto;
28622      }
28623
28624      header {
28625        grid-area: a;
28626      }
28627
28628      main {
28629        grid-row: main-top / main-bottom;
28630      }
28631    "#,
28632      indoc! {r#"
28633      body {
28634        grid: [EgL3uq_header-top] "EgL3uq_a EgL3uq_a EgL3uq_a" [EgL3uq_header-bottom]
28635              [EgL3uq_main-top] "EgL3uq_b EgL3uq_b EgL3uq_b" 1fr [EgL3uq_main-bottom]
28636              / auto 1fr auto;
28637      }
28638
28639      header {
28640        grid-area: EgL3uq_a;
28641      }
28642
28643      main {
28644        grid-row: EgL3uq_main-top / EgL3uq_main-bottom;
28645      }
28646    "#},
28647      map! {
28648        "header-top" => "EgL3uq_header-top",
28649        "header-bottom" => "EgL3uq_header-bottom",
28650        "main-top" => "EgL3uq_main-top",
28651        "main-bottom" => "EgL3uq_main-bottom",
28652        "a" => "EgL3uq_a",
28653        "b" => "EgL3uq_b"
28654      },
28655      IndexMap::new(),
28656      Default::default(),
28657      false,
28658    );
28659
28660    css_modules_test(
28661      r#"
28662        .grid {
28663          grid-template-areas: "foo";
28664        }
28665
28666        .foo {
28667          grid-area: foo;
28668        }
28669
28670        .bar {
28671          grid-column-start: foo-start;
28672        }
28673      "#,
28674      indoc! {r#"
28675        .EgL3uq_grid {
28676          grid-template-areas: "EgL3uq_foo";
28677        }
28678
28679        .EgL3uq_foo {
28680          grid-area: EgL3uq_foo;
28681        }
28682
28683        .EgL3uq_bar {
28684          grid-column-start: EgL3uq_foo-start;
28685        }
28686      "#},
28687      map! {
28688        "foo" => "EgL3uq_foo",
28689        "foo-start" => "EgL3uq_foo-start",
28690        "grid" => "EgL3uq_grid",
28691        "bar" => "EgL3uq_bar"
28692      },
28693      IndexMap::new(),
28694      Default::default(),
28695      false,
28696    );
28697
28698    css_modules_test(
28699      r#"
28700        .grid {
28701          grid-template-areas: "foo";
28702        }
28703
28704        .foo {
28705          grid-area: foo;
28706        }
28707
28708        .bar {
28709          grid-column-start: foo-start;
28710        }
28711      "#,
28712      indoc! {r#"
28713        .EgL3uq_grid {
28714          grid-template-areas: "foo";
28715        }
28716
28717        .EgL3uq_foo {
28718          grid-area: foo;
28719        }
28720
28721        .EgL3uq_bar {
28722          grid-column-start: foo-start;
28723        }
28724      "#},
28725      map! {
28726        "foo" => "EgL3uq_foo",
28727        "grid" => "EgL3uq_grid",
28728        "bar" => "EgL3uq_bar"
28729      },
28730      IndexMap::new(),
28731      crate::css_modules::Config {
28732        grid: false,
28733        ..Default::default()
28734      },
28735      false,
28736    );
28737
28738    css_modules_test(
28739      r#"
28740      test {
28741        transition-property: opacity;
28742      }
28743    "#,
28744      indoc! {r#"
28745      test {
28746        transition-property: opacity;
28747      }
28748    "#},
28749      map! {},
28750      IndexMap::new(),
28751      Default::default(),
28752      false,
28753    );
28754
28755    css_modules_test(
28756      r#"
28757      :global(.foo) {
28758        color: red;
28759      }
28760
28761      :local(.bar) {
28762        color: yellow;
28763      }
28764
28765      .bar :global(.baz) {
28766        color: purple;
28767      }
28768    "#,
28769      indoc! {r#"
28770      .foo {
28771        color: red;
28772      }
28773
28774      .EgL3uq_bar {
28775        color: #ff0;
28776      }
28777
28778      .EgL3uq_bar .baz {
28779        color: purple;
28780      }
28781    "#},
28782      map! {
28783        "bar" => "EgL3uq_bar"
28784      },
28785      IndexMap::new(),
28786      Default::default(),
28787      false,
28788    );
28789
28790    // :global(:local(.hi)) {
28791    //   color: green;
28792    // }
28793
28794    css_modules_test(
28795      r#"
28796      .test {
28797        composes: foo;
28798        background: white;
28799      }
28800
28801      .foo {
28802        color: red;
28803      }
28804    "#,
28805      indoc! {r#"
28806      .EgL3uq_test {
28807        background: #fff;
28808      }
28809
28810      .EgL3uq_foo {
28811        color: red;
28812      }
28813    "#},
28814      map! {
28815        "test" => "EgL3uq_test" "EgL3uq_foo",
28816        "foo" => "EgL3uq_foo"
28817      },
28818      IndexMap::new(),
28819      Default::default(),
28820      false,
28821    );
28822
28823    css_modules_test(
28824      r#"
28825      .a, .b {
28826        composes: foo;
28827        background: white;
28828      }
28829
28830      .foo {
28831        color: red;
28832      }
28833    "#,
28834      indoc! {r#"
28835      .EgL3uq_a, .EgL3uq_b {
28836        background: #fff;
28837      }
28838
28839      .EgL3uq_foo {
28840        color: red;
28841      }
28842    "#},
28843      map! {
28844        "a" => "EgL3uq_a" "EgL3uq_foo",
28845        "b" => "EgL3uq_b" "EgL3uq_foo",
28846        "foo" => "EgL3uq_foo"
28847      },
28848      IndexMap::new(),
28849      Default::default(),
28850      false,
28851    );
28852
28853    css_modules_test(
28854      r#"
28855      .test {
28856        composes: foo bar;
28857        background: white;
28858      }
28859
28860      .foo {
28861        color: red;
28862      }
28863
28864      .bar {
28865        color: yellow;
28866      }
28867    "#,
28868      indoc! {r#"
28869      .EgL3uq_test {
28870        background: #fff;
28871      }
28872
28873      .EgL3uq_foo {
28874        color: red;
28875      }
28876
28877      .EgL3uq_bar {
28878        color: #ff0;
28879      }
28880    "#},
28881      map! {
28882        "test" => "EgL3uq_test" "EgL3uq_foo" "EgL3uq_bar",
28883        "foo" => "EgL3uq_foo",
28884        "bar" => "EgL3uq_bar"
28885      },
28886      IndexMap::new(),
28887      Default::default(),
28888      false,
28889    );
28890
28891    css_modules_test(
28892      r#"
28893      .test {
28894        composes: foo from global;
28895        background: white;
28896      }
28897    "#,
28898      indoc! {r#"
28899      .EgL3uq_test {
28900        background: #fff;
28901      }
28902    "#},
28903      map! {
28904        "test" => "EgL3uq_test" "foo" global: true
28905      },
28906      IndexMap::new(),
28907      Default::default(),
28908      false,
28909    );
28910
28911    css_modules_test(
28912      r#"
28913      .test {
28914        composes: foo bar from global;
28915        background: white;
28916      }
28917    "#,
28918      indoc! {r#"
28919      .EgL3uq_test {
28920        background: #fff;
28921      }
28922    "#},
28923      map! {
28924        "test" => "EgL3uq_test" "foo" global: true "bar" global: true
28925      },
28926      IndexMap::new(),
28927      Default::default(),
28928      false,
28929    );
28930
28931    css_modules_test(
28932      r#"
28933      .test {
28934        composes: foo from "foo.css";
28935        background: white;
28936      }
28937    "#,
28938      indoc! {r#"
28939      .EgL3uq_test {
28940        background: #fff;
28941      }
28942    "#},
28943      map! {
28944        "test" => "EgL3uq_test" "foo" from "foo.css"
28945      },
28946      IndexMap::new(),
28947      Default::default(),
28948      false,
28949    );
28950
28951    css_modules_test(
28952      r#"
28953      .test {
28954        composes: foo bar from "foo.css";
28955        background: white;
28956      }
28957    "#,
28958      indoc! {r#"
28959      .EgL3uq_test {
28960        background: #fff;
28961      }
28962    "#},
28963      map! {
28964        "test" => "EgL3uq_test" "foo" from "foo.css" "bar" from "foo.css"
28965      },
28966      IndexMap::new(),
28967      Default::default(),
28968      false,
28969    );
28970
28971    css_modules_test(
28972      r#"
28973      .test {
28974        composes: foo;
28975        composes: foo from "foo.css";
28976        composes: bar from "bar.css";
28977        background: white;
28978      }
28979
28980      .foo {
28981        color: red;
28982      }
28983    "#,
28984      indoc! {r#"
28985      .EgL3uq_test {
28986        background: #fff;
28987      }
28988
28989      .EgL3uq_foo {
28990        color: red;
28991      }
28992    "#},
28993      map! {
28994        "test" => "EgL3uq_test" "EgL3uq_foo" "foo" from "foo.css" "bar" from "bar.css",
28995        "foo" => "EgL3uq_foo"
28996      },
28997      IndexMap::new(),
28998      Default::default(),
28999      false,
29000    );
29001
29002    css_modules_test(
29003      r#"
29004      .foo {
29005        color: red;
29006      }
29007    "#,
29008      indoc! {r#"
29009      .test-EgL3uq-foo {
29010        color: red;
29011      }
29012    "#},
29013      map! {
29014        "foo" => "test-EgL3uq-foo"
29015      },
29016      IndexMap::new(),
29017      crate::css_modules::Config {
29018        pattern: crate::css_modules::Pattern::parse("test-[hash]-[local]").unwrap(),
29019        ..Default::default()
29020      },
29021      false,
29022    );
29023
29024    let stylesheet = StyleSheet::parse(
29025      r#"
29026        .grid {
29027          grid-template-areas: "foo";
29028        }
29029
29030        .foo {
29031          grid-area: foo;
29032        }
29033
29034        .bar {
29035          grid-column-start: foo-start;
29036        }
29037      "#,
29038      ParserOptions {
29039        css_modules: Some(crate::css_modules::Config {
29040          pattern: crate::css_modules::Pattern::parse("test-[local]-[hash]").unwrap(),
29041          ..Default::default()
29042        }),
29043        ..ParserOptions::default()
29044      },
29045    )
29046    .unwrap();
29047    if let Err(err) = stylesheet.to_css(PrinterOptions::default(), None::<&mut ()>) {
29048      assert_eq!(err.kind, PrinterErrorKind::InvalidCssModulesPatternInGrid);
29049    } else {
29050      unreachable!()
29051    }
29052
29053    css_modules_test(
29054      r#"
29055      @property --foo {
29056        syntax: '<color>';
29057        inherits: false;
29058        initial-value: yellow;
29059      }
29060
29061      .foo {
29062        --foo: red;
29063        color: var(--foo);
29064      }
29065    "#,
29066      indoc! {r#"
29067      @property --foo {
29068        syntax: "<color>";
29069        inherits: false;
29070        initial-value: #ff0;
29071      }
29072
29073      .EgL3uq_foo {
29074        --foo: red;
29075        color: var(--foo);
29076      }
29077    "#},
29078      map! {
29079        "foo" => "EgL3uq_foo"
29080      },
29081      IndexMap::new(),
29082      Default::default(),
29083      false,
29084    );
29085
29086    css_modules_test(
29087      r#"
29088      @property --foo {
29089        syntax: '<color>';
29090        inherits: false;
29091        initial-value: yellow;
29092      }
29093
29094      @font-palette-values --Cooler {
29095        font-family: Bixa;
29096        base-palette: 1;
29097        override-colors: 1 #7EB7E4;
29098      }
29099
29100      .foo {
29101        --foo: red;
29102        --bar: green;
29103        color: var(--foo);
29104        font-palette: --Cooler;
29105      }
29106
29107      .bar {
29108        color: var(--color from "./b.css");
29109      }
29110    "#,
29111      indoc! {r#"
29112      @property --EgL3uq_foo {
29113        syntax: "<color>";
29114        inherits: false;
29115        initial-value: #ff0;
29116      }
29117
29118      @font-palette-values --EgL3uq_Cooler {
29119        font-family: Bixa;
29120        base-palette: 1;
29121        override-colors: 1 #7eb7e4;
29122      }
29123
29124      .EgL3uq_foo {
29125        --EgL3uq_foo: red;
29126        --EgL3uq_bar: green;
29127        color: var(--EgL3uq_foo);
29128        font-palette: --EgL3uq_Cooler;
29129      }
29130
29131      .EgL3uq_bar {
29132        color: var(--ma1CsG);
29133      }
29134    "#},
29135      map! {
29136        "foo" => "EgL3uq_foo",
29137        "--foo" => "--EgL3uq_foo" referenced: true,
29138        "--bar" => "--EgL3uq_bar",
29139        "bar" => "EgL3uq_bar",
29140        "--Cooler" => "--EgL3uq_Cooler" referenced: true
29141      },
29142      IndexMap::from([(
29143        "--ma1CsG".into(),
29144        CssModuleReference::Dependency {
29145          name: "--color".into(),
29146          specifier: "./b.css".into(),
29147        },
29148      )]),
29149      crate::css_modules::Config {
29150        dashed_idents: true,
29151        ..Default::default()
29152      },
29153      false,
29154    );
29155
29156    css_modules_test(
29157      r#"
29158      .test {
29159        animation: rotate var(--duration) linear infinite;
29160      }
29161    "#,
29162      indoc! {r#"
29163      .EgL3uq_test {
29164        animation: EgL3uq_rotate var(--duration) linear infinite;
29165      }
29166    "#},
29167      map! {
29168        "test" => "EgL3uq_test",
29169        "rotate" => "EgL3uq_rotate" referenced: true
29170      },
29171      IndexMap::new(),
29172      Default::default(),
29173      false,
29174    );
29175    css_modules_test(
29176      r#"
29177      .test {
29178        animation: none var(--duration);
29179      }
29180    "#,
29181      indoc! {r#"
29182      .EgL3uq_test {
29183        animation: none var(--duration);
29184      }
29185    "#},
29186      map! {
29187        "test" => "EgL3uq_test"
29188      },
29189      IndexMap::new(),
29190      Default::default(),
29191      false,
29192    );
29193    css_modules_test(
29194      r#"
29195      .test {
29196        animation: var(--animation);
29197      }
29198    "#,
29199      indoc! {r#"
29200      .EgL3uq_test {
29201        animation: var(--animation);
29202      }
29203    "#},
29204      map! {
29205        "test" => "EgL3uq_test"
29206      },
29207      IndexMap::new(),
29208      Default::default(),
29209      false,
29210    );
29211    css_modules_test(
29212      r#"
29213      .test {
29214        animation: rotate var(--duration);
29215      }
29216    "#,
29217      indoc! {r#"
29218      .EgL3uq_test {
29219        animation: rotate var(--duration);
29220      }
29221    "#},
29222      map! {
29223        "test" => "EgL3uq_test"
29224      },
29225      IndexMap::new(),
29226      crate::css_modules::Config {
29227        animation: false,
29228        ..Default::default()
29229      },
29230      false,
29231    );
29232    css_modules_test(
29233      r#"
29234      .test {
29235        animation: "rotate" var(--duration);
29236      }
29237    "#,
29238      indoc! {r#"
29239      .EgL3uq_test {
29240        animation: EgL3uq_rotate var(--duration);
29241      }
29242    "#},
29243      map! {
29244        "test" => "EgL3uq_test",
29245        "rotate" => "EgL3uq_rotate" referenced: true
29246      },
29247      IndexMap::new(),
29248      crate::css_modules::Config { ..Default::default() },
29249      false,
29250    );
29251
29252    css_modules_test(
29253      r#"
29254      .test {
29255        composes: foo bar from "foo.css";
29256        background: white;
29257      }
29258    "#,
29259      indoc! {r#"
29260      ._5h2kwG-test {
29261        background: #fff;
29262      }
29263    "#},
29264      map! {
29265        "test" => "_5h2kwG-test" "foo" from "foo.css" "bar" from "foo.css"
29266      },
29267      IndexMap::new(),
29268      crate::css_modules::Config {
29269        pattern: crate::css_modules::Pattern::parse("[content-hash]-[local]").unwrap(),
29270        ..Default::default()
29271      },
29272      false,
29273    );
29274
29275    css_modules_test(
29276      r#"
29277      .box2 {
29278        @container main (width >= 0) {
29279          background-color: #90ee90;
29280        }
29281      }
29282    "#,
29283      indoc! {r#"
29284      .EgL3uq_box2 {
29285        @container EgL3uq_main (width >= 0) {
29286          background-color: #90ee90;
29287        }
29288      }
29289    "#},
29290      map! {
29291        "main" => "EgL3uq_main",
29292        "box2" => "EgL3uq_box2"
29293      },
29294      IndexMap::new(),
29295      crate::css_modules::Config { ..Default::default() },
29296      false,
29297    );
29298
29299    css_modules_test(
29300      r#"
29301      .box2 {
29302        @container main (width >= 0) {
29303          background-color: #90ee90;
29304        }
29305      }
29306    "#,
29307      indoc! {r#"
29308      .EgL3uq_box2 {
29309        @container main (width >= 0) {
29310          background-color: #90ee90;
29311        }
29312      }
29313    "#},
29314      map! {
29315        "box2" => "EgL3uq_box2"
29316      },
29317      IndexMap::new(),
29318      crate::css_modules::Config {
29319        container: false,
29320        ..Default::default()
29321      },
29322      false,
29323    );
29324
29325    css_modules_test(
29326      ".foo { view-transition-name: bar }",
29327      ".EgL3uq_foo{view-transition-name:EgL3uq_bar}",
29328      map! {
29329        "foo" => "EgL3uq_foo",
29330        "bar" => "EgL3uq_bar"
29331      },
29332      IndexMap::new(),
29333      Default::default(),
29334      true,
29335    );
29336    css_modules_test(
29337      ".foo { view-transition-name: none }",
29338      ".EgL3uq_foo{view-transition-name:none}",
29339      map! {
29340        "foo" => "EgL3uq_foo"
29341      },
29342      IndexMap::new(),
29343      Default::default(),
29344      true,
29345    );
29346    css_modules_test(
29347      ".foo { view-transition-name: auto }",
29348      ".EgL3uq_foo{view-transition-name:auto}",
29349      map! {
29350        "foo" => "EgL3uq_foo"
29351      },
29352      IndexMap::new(),
29353      Default::default(),
29354      true,
29355    );
29356    css_modules_test(
29357      ".foo { view-transition-name: match-element }",
29358      ".EgL3uq_foo{view-transition-name:match-element}",
29359      map! {
29360        "foo" => "EgL3uq_foo"
29361      },
29362      IndexMap::new(),
29363      Default::default(),
29364      true,
29365    );
29366
29367    css_modules_test(
29368      ".foo { view-transition-class: bar baz qux }",
29369      ".EgL3uq_foo{view-transition-class:EgL3uq_bar EgL3uq_baz EgL3uq_qux}",
29370      map! {
29371        "foo" => "EgL3uq_foo",
29372        "bar" => "EgL3uq_bar",
29373        "baz" => "EgL3uq_baz",
29374        "qux" => "EgL3uq_qux"
29375      },
29376      IndexMap::new(),
29377      Default::default(),
29378      true,
29379    );
29380
29381    css_modules_test(
29382      ".foo { view-transition-group: contain }",
29383      ".EgL3uq_foo{view-transition-group:contain}",
29384      map! {
29385        "foo" => "EgL3uq_foo"
29386      },
29387      IndexMap::new(),
29388      Default::default(),
29389      true,
29390    );
29391    css_modules_test(
29392      ".foo { view-transition-group: bar }",
29393      ".EgL3uq_foo{view-transition-group:EgL3uq_bar}",
29394      map! {
29395        "foo" => "EgL3uq_foo",
29396        "bar" => "EgL3uq_bar"
29397      },
29398      IndexMap::new(),
29399      Default::default(),
29400      true,
29401    );
29402
29403    css_modules_test(
29404      "@view-transition { types: foo bar baz }",
29405      "@view-transition{types:EgL3uq_foo EgL3uq_bar EgL3uq_baz}",
29406      map! {
29407        "foo" => "EgL3uq_foo",
29408        "bar" => "EgL3uq_bar",
29409        "baz" => "EgL3uq_baz"
29410      },
29411      IndexMap::new(),
29412      Default::default(),
29413      true,
29414    );
29415
29416    css_modules_test(
29417      ":root:active-view-transition-type(foo, bar) { color: red }",
29418      ":root:active-view-transition-type(EgL3uq_foo,EgL3uq_bar){color:red}",
29419      map! {
29420        "foo" => "EgL3uq_foo",
29421        "bar" => "EgL3uq_bar"
29422      },
29423      IndexMap::new(),
29424      Default::default(),
29425      true,
29426    );
29427
29428    for name in &[
29429      "view-transition-group",
29430      "view-transition-image-pair",
29431      "view-transition-new",
29432      "view-transition-old",
29433    ] {
29434      css_modules_test(
29435        &format!(":root::{}(foo) {{position: fixed}}", name),
29436        &format!(":root::{}(EgL3uq_foo){{position:fixed}}", name),
29437        map! {
29438          "foo" => "EgL3uq_foo"
29439        },
29440        IndexMap::new(),
29441        Default::default(),
29442        true,
29443      );
29444      css_modules_test(
29445        &format!(":root::{}(.bar) {{position: fixed}}", name),
29446        &format!(":root::{}(.EgL3uq_bar){{position:fixed}}", name),
29447        map! {
29448          "bar" => "EgL3uq_bar"
29449        },
29450        IndexMap::new(),
29451        Default::default(),
29452        true,
29453      );
29454      css_modules_test(
29455        &format!(":root::{}(foo.bar.baz) {{position: fixed}}", name),
29456        &format!(":root::{}(EgL3uq_foo.EgL3uq_bar.EgL3uq_baz){{position:fixed}}", name),
29457        map! {
29458          "foo" => "EgL3uq_foo",
29459          "bar" => "EgL3uq_bar",
29460          "baz" => "EgL3uq_baz"
29461        },
29462        IndexMap::new(),
29463        Default::default(),
29464        true,
29465      );
29466
29467      css_modules_test(
29468        ":nth-child(1 of .foo) {width: 20px}",
29469        ":nth-child(1 of .EgL3uq_foo){width:20px}",
29470        map! {
29471          "foo" => "EgL3uq_foo"
29472        },
29473        IndexMap::new(),
29474        Default::default(),
29475        true,
29476      );
29477      css_modules_test(
29478        ":nth-last-child(1 of .foo) {width: 20px}",
29479        ":nth-last-child(1 of .EgL3uq_foo){width:20px}",
29480        map! {
29481          "foo" => "EgL3uq_foo"
29482        },
29483        IndexMap::new(),
29484        Default::default(),
29485        true,
29486      );
29487    }
29488
29489    // Stable hashes between project roots.
29490    fn test_project_root(project_root: &str, filename: &str, hash: &str) {
29491      let stylesheet = StyleSheet::parse(
29492        r#"
29493        .foo {
29494          background: red;
29495        }
29496        "#,
29497        ParserOptions {
29498          filename: filename.into(),
29499          css_modules: Some(Default::default()),
29500          ..ParserOptions::default()
29501        },
29502      )
29503      .unwrap();
29504      let res = stylesheet
29505        .to_css(
29506          PrinterOptions {
29507            project_root: Some(project_root),
29508            ..PrinterOptions::default()
29509          },
29510          None::<&mut ()>,
29511        )
29512        .unwrap();
29513      assert_eq!(
29514        res.code,
29515        format!(
29516          indoc! {r#"
29517      .{}_foo {{
29518        background: red;
29519      }}
29520      "#},
29521          hash
29522        )
29523      );
29524    }
29525
29526    test_project_root("/foo/bar", "/foo/bar/test.css", "EgL3uq");
29527    test_project_root("/foo", "/foo/test.css", "EgL3uq");
29528    test_project_root("/foo/bar", "/foo/bar/baz/test.css", "xLEkNW");
29529    test_project_root("/foo", "/foo/baz/test.css", "xLEkNW");
29530
29531    let mut stylesheet = StyleSheet::parse(
29532      r#"
29533      .foo {
29534        color: red;
29535        .bar {
29536          color: green;
29537        }
29538        composes: test from "foo.css";
29539      }
29540      "#,
29541      ParserOptions {
29542        filename: "test.css".into(),
29543        css_modules: Some(Default::default()),
29544        ..ParserOptions::default()
29545      },
29546    )
29547    .unwrap();
29548    stylesheet.minify(MinifyOptions::default()).unwrap();
29549    let res = stylesheet
29550      .to_css(
29551        PrinterOptions {
29552          targets: Browsers {
29553            chrome: Some(95 << 16),
29554            ..Browsers::default()
29555          }
29556          .into(),
29557          ..Default::default()
29558        },
29559        None::<&mut ()>,
29560      )
29561      .unwrap();
29562    assert_eq!(
29563      res.code,
29564      indoc! {r#"
29565    .EgL3uq_foo {
29566      color: red;
29567    }
29568
29569    .EgL3uq_foo .EgL3uq_bar {
29570      color: green;
29571    }
29572
29573
29574    "#}
29575    );
29576    assert_eq!(
29577      res.exports.unwrap(),
29578      map! {
29579        "foo" => "EgL3uq_foo" "test" from "foo.css",
29580        "bar" => "EgL3uq_bar"
29581      }
29582    );
29583  }
29584
29585  #[test]
29586  fn test_pseudo_replacement() {
29587    let source = r#"
29588      .foo:hover {
29589        color: red;
29590      }
29591
29592      .foo:active {
29593        color: yellow;
29594      }
29595
29596      .foo:focus-visible {
29597        color: purple;
29598      }
29599    "#;
29600
29601    let expected = indoc! { r#"
29602      .foo.is-hovered {
29603        color: red;
29604      }
29605
29606      .foo.is-active {
29607        color: #ff0;
29608      }
29609
29610      .foo.focus-visible {
29611        color: purple;
29612      }
29613    "#};
29614
29615    let stylesheet = StyleSheet::parse(&source, ParserOptions::default()).unwrap();
29616    let res = stylesheet
29617      .to_css(
29618        PrinterOptions {
29619          pseudo_classes: Some(PseudoClasses {
29620            hover: Some("is-hovered"),
29621            active: Some("is-active"),
29622            focus_visible: Some("focus-visible"),
29623            ..PseudoClasses::default()
29624          }),
29625          ..PrinterOptions::default()
29626        },
29627        None::<&mut ()>,
29628      )
29629      .unwrap();
29630    assert_eq!(res.code, expected);
29631
29632    let source = r#"
29633      .foo:hover {
29634        color: red;
29635      }
29636    "#;
29637
29638    let expected = indoc! { r#"
29639      .EgL3uq_foo.EgL3uq_is-hovered {
29640        color: red;
29641      }
29642    "#};
29643
29644    let stylesheet = StyleSheet::parse(
29645      &source,
29646      ParserOptions {
29647        filename: "test.css".into(),
29648        css_modules: Some(Default::default()),
29649        ..ParserOptions::default()
29650      },
29651    )
29652    .unwrap();
29653    let res = stylesheet
29654      .to_css(
29655        PrinterOptions {
29656          pseudo_classes: Some(PseudoClasses {
29657            hover: Some("is-hovered"),
29658            ..PseudoClasses::default()
29659          }),
29660          ..PrinterOptions::default()
29661        },
29662        None::<&mut ()>,
29663      )
29664      .unwrap();
29665    assert_eq!(res.code, expected);
29666  }
29667
29668  #[test]
29669  fn test_unused_symbols() {
29670    let source = r#"
29671      .foo {
29672        color: red;
29673      }
29674
29675      .bar {
29676        color: green;
29677      }
29678
29679      .bar:hover {
29680        color: purple;
29681      }
29682
29683      .bar .baz {
29684        background: red;
29685      }
29686
29687      .baz:is(.bar) {
29688        background: green;
29689      }
29690
29691      #id {
29692        animation: 2s test;
29693      }
29694
29695      #other_id {
29696        color: red;
29697      }
29698
29699      @keyframes test {
29700        from { color: red }
29701        to { color: yellow }
29702      }
29703
29704      @counter-style circles {
29705        symbols: Ⓐ Ⓑ Ⓒ;
29706      }
29707
29708      @keyframes fade {
29709        from { opacity: 0 }
29710        to { opacity: 1 }
29711      }
29712    "#;
29713
29714    let expected = indoc! {r#"
29715      .foo {
29716        color: red;
29717      }
29718
29719      #id {
29720        animation: 2s test;
29721      }
29722
29723      @keyframes test {
29724        from {
29725          color: red;
29726        }
29727
29728        to {
29729          color: #ff0;
29730        }
29731      }
29732    "#};
29733
29734    let mut stylesheet = StyleSheet::parse(&source, ParserOptions::default()).unwrap();
29735    stylesheet
29736      .minify(MinifyOptions {
29737        unused_symbols: vec!["bar", "other_id", "fade", "circles"]
29738          .iter()
29739          .map(|s| String::from(*s))
29740          .collect(),
29741        ..MinifyOptions::default()
29742      })
29743      .unwrap();
29744    let res = stylesheet.to_css(PrinterOptions::default(), None::<&mut ()>).unwrap();
29745    assert_eq!(res.code, expected);
29746
29747    let source = r#"
29748      .foo {
29749        color: red;
29750
29751        &.bar {
29752          color: green;
29753        }
29754      }
29755    "#;
29756
29757    let expected = indoc! {r#"
29758      .foo {
29759        color: red;
29760      }
29761    "#};
29762
29763    let mut stylesheet = StyleSheet::parse(&source, ParserOptions::default()).unwrap();
29764    stylesheet
29765      .minify(MinifyOptions {
29766        unused_symbols: vec!["bar"].iter().map(|s| String::from(*s)).collect(),
29767        ..MinifyOptions::default()
29768      })
29769      .unwrap();
29770    let res = stylesheet.to_css(PrinterOptions::default(), None::<&mut ()>).unwrap();
29771    assert_eq!(res.code, expected);
29772
29773    let source = r#"
29774      .foo {
29775        color: red;
29776
29777        &.bar {
29778          color: purple;
29779        }
29780
29781        @nest &.bar {
29782          color: orange;
29783        }
29784
29785        @nest :not(&) {
29786          color: green;
29787        }
29788
29789        @media (orientation: portrait) {
29790          color: brown;
29791        }
29792      }
29793
29794      .x {
29795        color: purple;
29796
29797        &.y {
29798          color: green;
29799        }
29800      }
29801    "#;
29802
29803    let expected = indoc! {r#"
29804      :not(.foo) {
29805        color: green;
29806      }
29807    "#};
29808
29809    let mut stylesheet = StyleSheet::parse(&source, ParserOptions::default()).unwrap();
29810    stylesheet
29811      .minify(MinifyOptions {
29812        unused_symbols: vec!["foo", "x"].iter().map(|s| String::from(*s)).collect(),
29813        ..MinifyOptions::default()
29814      })
29815      .unwrap();
29816    let res = stylesheet
29817      .to_css(
29818        PrinterOptions {
29819          targets: Browsers {
29820            chrome: Some(95 << 16),
29821            ..Browsers::default()
29822          }
29823          .into(),
29824          ..PrinterOptions::default()
29825        },
29826        None::<&mut ()>,
29827      )
29828      .unwrap();
29829    assert_eq!(res.code, expected);
29830
29831    let source = r#"
29832      @property --EgL3uq_foo {
29833        syntax: "<color>";
29834        inherits: false;
29835        initial-value: #ff0;
29836      }
29837
29838      @font-palette-values --EgL3uq_Cooler {
29839        font-family: Bixa;
29840        base-palette: 1;
29841        override-colors: 1 #7EB7E4;
29842      }
29843
29844      .EgL3uq_foo {
29845        --EgL3uq_foo: red;
29846      }
29847
29848      .EgL3uq_bar {
29849        color: green;
29850      }
29851    "#;
29852
29853    let expected = indoc! {r#"
29854      .EgL3uq_bar {
29855        color: green;
29856      }
29857    "#};
29858
29859    let mut stylesheet = StyleSheet::parse(&source, ParserOptions::default()).unwrap();
29860    stylesheet
29861      .minify(MinifyOptions {
29862        unused_symbols: vec!["--EgL3uq_foo", "--EgL3uq_Cooler"]
29863          .iter()
29864          .map(|s| String::from(*s))
29865          .collect(),
29866        ..MinifyOptions::default()
29867      })
29868      .unwrap();
29869    let res = stylesheet.to_css(PrinterOptions::default(), None::<&mut ()>).unwrap();
29870    assert_eq!(res.code, expected);
29871  }
29872
29873  #[test]
29874  fn test_svg() {
29875    property_range_test(
29876      &["stroke-dasharray"],
29877      &[
29878        ("-1px", None),
29879        ("-1%", None),
29880        ("calc(-1px)", Some("0")),
29881        ("calc(-1px + 2px)", Some("1")),
29882        ("calc(-1%)", Some("calc(-1%)")),
29883      ],
29884    );
29885    property_range_test(&["stroke-dashoffset"], &[("-1px", Some("-1px"))]);
29886    property_range_test(&["stroke-dasharray"], &[("1px -2px", None)]);
29887    property_range_test(
29888      &["stroke-width"],
29889      &[
29890        ("-1px", None),
29891        ("calc(1px - 2px)", Some("0")),
29892        ("calc(-1px + 2px)", Some("1px")),
29893        ("-1%", None),
29894        ("calc(1em - 2px)", Some("calc(1em - 2px)")),
29895        ("calc(-1%)", Some("calc(-1%)")),
29896      ],
29897    );
29898    use crate::properties::svg;
29899
29900    minify_test(".foo { fill: yellow; }", ".foo{fill:#ff0}");
29901    minify_test(".foo { fill: url(#foo); }", ".foo{fill:url(#foo)}");
29902    minify_test(".foo { fill: url(#foo) none; }", ".foo{fill:url(#foo) none}");
29903    minify_test(".foo { fill: url(#foo) yellow; }", ".foo{fill:url(#foo) #ff0}");
29904    minify_test(".foo { fill: none; }", ".foo{fill:none}");
29905    minify_test(".foo { fill: context-fill; }", ".foo{fill:context-fill}");
29906    minify_test(".foo { fill: context-stroke; }", ".foo{fill:context-stroke}");
29907
29908    minify_test(".foo { stroke: yellow; }", ".foo{stroke:#ff0}");
29909    minify_test(".foo { stroke: url(#foo); }", ".foo{stroke:url(#foo)}");
29910    minify_test(".foo { stroke: url(#foo) none; }", ".foo{stroke:url(#foo) none}");
29911    minify_test(".foo { stroke: url(#foo) yellow; }", ".foo{stroke:url(#foo) #ff0}");
29912    minify_test(".foo { stroke: none; }", ".foo{stroke:none}");
29913    minify_test(".foo { stroke: context-fill; }", ".foo{stroke:context-fill}");
29914    minify_test(".foo { stroke: context-stroke; }", ".foo{stroke:context-stroke}");
29915
29916    minify_test(".foo { marker-start: url(#foo); }", ".foo{marker-start:url(#foo)}");
29917
29918    minify_test(".foo { stroke-dasharray: 4 1 2; }", ".foo{stroke-dasharray:4 1 2}");
29919    minify_test(".foo { stroke-dasharray: 4,1,2; }", ".foo{stroke-dasharray:4 1 2}");
29920    minify_test(".foo { stroke-dasharray: 4, 1, 2; }", ".foo{stroke-dasharray:4 1 2}");
29921    minify_test(
29922      ".foo { stroke-dasharray: 4px, 1px, 2px; }",
29923      ".foo{stroke-dasharray:4 1 2}",
29924    );
29925
29926    minify_test(".foo { mask: url('foo.svg'); }", ".foo{mask:url(foo.svg)}");
29927    minify_test(
29928      ".foo { mask: url(masks.svg#star) luminance }",
29929      ".foo{mask:url(masks.svg#star) luminance}",
29930    );
29931    minify_test(
29932      ".foo { mask: url(masks.svg#star) 40px 20px }",
29933      ".foo{mask:url(masks.svg#star) 40px 20px}",
29934    );
29935    minify_test(
29936      ".foo { mask: url(masks.svg#star) 0 0 / 50px 50px }",
29937      ".foo{mask:url(masks.svg#star) 0 0/50px 50px}",
29938    );
29939    minify_test(
29940      ".foo { mask: url(masks.svg#star) repeat-x }",
29941      ".foo{mask:url(masks.svg#star) repeat-x}",
29942    );
29943    minify_test(
29944      ".foo { mask: url(masks.svg#star) stroke-box }",
29945      ".foo{mask:url(masks.svg#star) stroke-box}",
29946    );
29947    minify_test(
29948      ".foo { mask: url(masks.svg#star) stroke-box stroke-box }",
29949      ".foo{mask:url(masks.svg#star) stroke-box}",
29950    );
29951    minify_test(
29952      ".foo { mask: url(masks.svg#star) border-box }",
29953      ".foo{mask:url(masks.svg#star)}",
29954    );
29955    minify_test(
29956      ".foo { mask: url(masks.svg#star) left / 16px repeat-y, url(masks.svg#circle) right / 16px repeat-y }",
29957      ".foo{mask:url(masks.svg#star) 0/16px repeat-y,url(masks.svg#circle) 100%/16px repeat-y}",
29958    );
29959
29960    minify_test(
29961      r#"
29962      .foo {
29963        mask-border: none;
29964      }
29965      "#,
29966      ".foo{mask-border:none}",
29967    );
29968    minify_test(
29969      r#"
29970      .foo {
29971        -webkit-mask-box-image: none;
29972      }
29973      "#,
29974      ".foo{-webkit-mask-box-image:none}",
29975    );
29976    minify_test(
29977      ".foo { mask-border: url('border-mask.png') 25; }",
29978      ".foo{mask-border:url(border-mask.png) 25}",
29979    );
29980    minify_test(
29981      ".foo { mask-border: url('border-mask.png') 25 / 35px / 12px space alpha; }",
29982      ".foo{mask-border:url(border-mask.png) 25/35px/12px space}",
29983    );
29984    minify_test(
29985      ".foo { mask-border: url('border-mask.png') 25 / 35px / 12px space luminance; }",
29986      ".foo{mask-border:url(border-mask.png) 25/35px/12px space luminance}",
29987    );
29988    minify_test(
29989      ".foo { mask-border: url('border-mask.png') luminance 25 / 35px / 12px space; }",
29990      ".foo{mask-border:url(border-mask.png) 25/35px/12px space luminance}",
29991    );
29992
29993    minify_test(
29994      ".foo { clip-path: url('clip.svg#star'); }",
29995      ".foo{clip-path:url(clip.svg#star)}",
29996    );
29997    minify_test(".foo { clip-path: margin-box; }", ".foo{clip-path:margin-box}");
29998    minify_test(
29999      ".foo { clip-path: inset(100px 50px); }",
30000      ".foo{clip-path:inset(100px 50px)}",
30001    );
30002    minify_test(
30003      ".foo { clip-path: inset(100px 50px round 5px); }",
30004      ".foo{clip-path:inset(100px 50px round 5px)}",
30005    );
30006    minify_test(
30007      ".foo { clip-path: inset(100px 50px round 5px 5px 5px 5px); }",
30008      ".foo{clip-path:inset(100px 50px round 5px)}",
30009    );
30010    minify_test(".foo { clip-path: circle(50px); }", ".foo{clip-path:circle(50px)}");
30011    minify_test(
30012      ".foo { clip-path: circle(50px at center center); }",
30013      ".foo{clip-path:circle(50px)}",
30014    );
30015    minify_test(
30016      ".foo { clip-path: circle(50px at 50% 50%); }",
30017      ".foo{clip-path:circle(50px)}",
30018    );
30019    minify_test(
30020      ".foo { clip-path: circle(50px at 0 100px); }",
30021      ".foo{clip-path:circle(50px at 0 100px)}",
30022    );
30023    minify_test(
30024      ".foo { clip-path: circle(closest-side at 0 100px); }",
30025      ".foo{clip-path:circle(at 0 100px)}",
30026    );
30027    minify_test(
30028      ".foo { clip-path: circle(farthest-side at 0 100px); }",
30029      ".foo{clip-path:circle(farthest-side at 0 100px)}",
30030    );
30031    minify_test(
30032      ".foo { clip-path: circle(closest-side at 50% 50%); }",
30033      ".foo{clip-path:circle()}",
30034    );
30035    minify_test(
30036      ".foo { clip-path: ellipse(50px 60px at 0 10% 20%); }",
30037      ".foo{clip-path:ellipse(50px 60px at 0 10% 20%)}",
30038    );
30039    minify_test(
30040      ".foo { clip-path: ellipse(50px 60px at center center); }",
30041      ".foo{clip-path:ellipse(50px 60px)}",
30042    );
30043    minify_test(
30044      ".foo { clip-path: ellipse(closest-side closest-side at 50% 50%); }",
30045      ".foo{clip-path:ellipse()}",
30046    );
30047    minify_test(
30048      ".foo { clip-path: ellipse(closest-side closest-side at 10% 20%); }",
30049      ".foo{clip-path:ellipse(at 10% 20%)}",
30050    );
30051    minify_test(
30052      ".foo { clip-path: ellipse(farthest-side closest-side at 10% 20%); }",
30053      ".foo{clip-path:ellipse(farthest-side closest-side at 10% 20%)}",
30054    );
30055    minify_test(
30056      ".foo { clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); }",
30057      ".foo{clip-path:polygon(50% 0%,100% 50%,50% 100%,0% 50%)}",
30058    );
30059    minify_test(
30060      ".foo { clip-path: polygon(nonzero, 50% 0%, 100% 50%, 50% 100%, 0% 50%); }",
30061      ".foo{clip-path:polygon(50% 0%,100% 50%,50% 100%,0% 50%)}",
30062    );
30063    minify_test(
30064      ".foo { clip-path: polygon(evenodd, 50% 0%, 100% 50%, 50% 100%, 0% 50%); }",
30065      ".foo{clip-path:polygon(evenodd,50% 0%,100% 50%,50% 100%,0% 50%)}",
30066    );
30067    minify_test(
30068      ".foo { clip-path: padding-box circle(50px at 0 100px); }",
30069      ".foo{clip-path:circle(50px at 0 100px) padding-box}",
30070    );
30071    minify_test(
30072      ".foo { clip-path: circle(50px at 0 100px) padding-box; }",
30073      ".foo{clip-path:circle(50px at 0 100px) padding-box}",
30074    );
30075    minify_test(
30076      ".foo { clip-path: circle(50px at 0 100px) border-box; }",
30077      ".foo{clip-path:circle(50px at 0 100px)}",
30078    );
30079
30080    prefix_test(
30081      ".foo { clip-path: circle(50px); }",
30082      indoc! { r#"
30083        .foo {
30084          -webkit-clip-path: circle(50px);
30085          clip-path: circle(50px);
30086        }
30087      "#},
30088      Browsers {
30089        chrome: Some(30 << 16),
30090        ..Browsers::default()
30091      },
30092    );
30093
30094    prefix_test(
30095      ".foo { clip-path: circle(50px); }",
30096      indoc! { r#"
30097        .foo {
30098          clip-path: circle(50px);
30099        }
30100      "#},
30101      Browsers {
30102        chrome: Some(80 << 16),
30103        ..Browsers::default()
30104      },
30105    );
30106
30107    prefix_test(
30108      ".foo { clip-path: circle(50px); }",
30109      indoc! { r#"
30110        .foo {
30111          -webkit-clip-path: circle(50px);
30112          clip-path: circle(50px);
30113        }
30114      "#},
30115      Browsers {
30116        safari: Some(8 << 16),
30117        ..Browsers::default()
30118      },
30119    );
30120
30121    prefix_test(
30122      ".foo { clip-path: circle(50px); }",
30123      indoc! { r#"
30124        .foo {
30125          clip-path: circle(50px);
30126        }
30127      "#},
30128      Browsers {
30129        safari: Some(14 << 16),
30130        ..Browsers::default()
30131      },
30132    );
30133
30134    prefix_test(
30135      ".foo { fill: lch(50.998% 135.363 338) }",
30136      indoc! { r#"
30137        .foo {
30138          fill: #f000c0;
30139          fill: color(display-p3 .972962 -.362078 .804206);
30140          fill: lch(50.998% 135.363 338);
30141        }
30142      "#},
30143      Browsers {
30144        chrome: Some(90 << 16),
30145        safari: Some(14 << 16),
30146        ..Browsers::default()
30147      },
30148    );
30149
30150    prefix_test(
30151      ".foo { stroke: lch(50.998% 135.363 338) }",
30152      indoc! { r#"
30153        .foo {
30154          stroke: #f000c0;
30155          stroke: color(display-p3 .972962 -.362078 .804206);
30156          stroke: lch(50.998% 135.363 338);
30157        }
30158      "#},
30159      Browsers {
30160        chrome: Some(90 << 16),
30161        safari: Some(14 << 16),
30162        ..Browsers::default()
30163      },
30164    );
30165
30166    prefix_test(
30167      ".foo { fill: url(#foo) lch(50.998% 135.363 338) }",
30168      indoc! { r##"
30169        .foo {
30170          fill: url("#foo") #f000c0;
30171          fill: url("#foo") color(display-p3 .972962 -.362078 .804206);
30172          fill: url("#foo") lch(50.998% 135.363 338);
30173        }
30174      "##},
30175      Browsers {
30176        chrome: Some(90 << 16),
30177        safari: Some(14 << 16),
30178        ..Browsers::default()
30179      },
30180    );
30181
30182    prefix_test(
30183      ".foo { fill: var(--url) lch(50.998% 135.363 338) }",
30184      indoc! { r#"
30185        .foo {
30186          fill: var(--url) #f000c0;
30187        }
30188
30189        @supports (color: lab(0% 0 0)) {
30190          .foo {
30191            fill: var(--url) lab(50.998% 125.506 -50.7078);
30192          }
30193        }
30194      "#},
30195      Browsers {
30196        chrome: Some(90 << 16),
30197        ..Browsers::default()
30198      },
30199    );
30200
30201    prefix_test(
30202      r#"
30203        @supports (color: lab(0% 0 0)) {
30204          .foo {
30205            fill: var(--url) lab(50.998% 125.506 -50.7078);
30206          }
30207        }
30208      "#,
30209      indoc! { r#"
30210        @supports (color: lab(0% 0 0)) {
30211          .foo {
30212            fill: var(--url) lab(50.998% 125.506 -50.7078);
30213          }
30214        }
30215      "#},
30216      Browsers {
30217        chrome: Some(90 << 16),
30218        ..Browsers::default()
30219      },
30220    );
30221
30222    prefix_test(
30223      ".foo { mask-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
30224      indoc! { r#"
30225        .foo {
30226          -webkit-mask-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ff0b0c), to(#766eff));
30227          -webkit-mask-image: -webkit-linear-gradient(top, #ff0b0c, #766eff);
30228          -webkit-mask-image: linear-gradient(#ff0b0c, #766eff);
30229          mask-image: linear-gradient(#ff0b0c, #766eff);
30230          -webkit-mask-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
30231          mask-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
30232        }
30233      "#},
30234      Browsers {
30235        chrome: Some(8 << 16),
30236        ..Browsers::default()
30237      },
30238    );
30239
30240    prefix_test(
30241      ".foo { mask-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
30242      indoc! { r#"
30243        .foo {
30244          -webkit-mask-image: linear-gradient(#ff0b0c, #766eff);
30245          mask-image: linear-gradient(#ff0b0c, #766eff);
30246          -webkit-mask-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
30247          mask-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
30248        }
30249      "#},
30250      Browsers {
30251        chrome: Some(95 << 16),
30252        ..Browsers::default()
30253      },
30254    );
30255
30256    prefix_test(
30257      ".foo { mask-image: linear-gradient(red, green) }",
30258      indoc! { r#"
30259        .foo {
30260          -webkit-mask-image: linear-gradient(red, green);
30261          mask-image: linear-gradient(red, green);
30262        }
30263      "#},
30264      Browsers {
30265        chrome: Some(95 << 16),
30266        ..Browsers::default()
30267      },
30268    );
30269
30270    prefix_test(
30271      ".foo { -webkit-mask-image: url(x.svg); mask-image: url(x.svg); }",
30272      indoc! { r#"
30273        .foo {
30274          -webkit-mask-image: url("x.svg");
30275          mask-image: url("x.svg");
30276        }
30277      "#},
30278      Browsers {
30279        chrome: Some(95 << 16),
30280        ..Browsers::default()
30281      },
30282    );
30283
30284    prefix_test(
30285      ".foo { mask: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 40px 20px }",
30286      indoc! { r#"
30287        .foo {
30288          -webkit-mask: -webkit-gradient(linear, 0 0, 0 100%, from(#ff0b0c), to(#766eff)) 40px 20px;
30289          -webkit-mask: -webkit-linear-gradient(top, #ff0b0c, #766eff) 40px 20px;
30290          -webkit-mask: linear-gradient(#ff0b0c, #766eff) 40px 20px;
30291          mask: linear-gradient(#ff0b0c, #766eff) 40px 20px;
30292          -webkit-mask: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 40px 20px;
30293          mask: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 40px 20px;
30294        }
30295      "#},
30296      Browsers {
30297        chrome: Some(8 << 16),
30298        ..Browsers::default()
30299      },
30300    );
30301
30302    prefix_test(
30303      ".foo { mask: -webkit-linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 40px 20px }",
30304      indoc! { r#"
30305        .foo {
30306          -webkit-mask: -webkit-gradient(linear, 0 0, 0 100%, from(#ff0b0c), to(#766eff)) 40px 20px;
30307          -webkit-mask: -webkit-linear-gradient(#ff0b0c, #766eff) 40px 20px;
30308        }
30309      "#},
30310      Browsers {
30311        chrome: Some(8 << 16),
30312        ..Browsers::default()
30313      },
30314    );
30315
30316    prefix_test(
30317      ".foo { mask: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 40px var(--foo) }",
30318      indoc! { r#"
30319        .foo {
30320          -webkit-mask: linear-gradient(#ff0b0c, #766eff) 40px var(--foo);
30321          mask: linear-gradient(#ff0b0c, #766eff) 40px var(--foo);
30322        }
30323
30324        @supports (color: lab(0% 0 0)) {
30325          .foo {
30326            -webkit-mask: linear-gradient(lab(56.208% 94.4644 98.8928), lab(51% 70.4544 -115.586)) 40px var(--foo);
30327            mask: linear-gradient(lab(56.208% 94.4644 98.8928), lab(51% 70.4544 -115.586)) 40px var(--foo);
30328          }
30329        }
30330      "#},
30331      Browsers {
30332        chrome: Some(90 << 16),
30333        ..Browsers::default()
30334      },
30335    );
30336
30337    prefix_test(
30338      r#"
30339        @supports (color: lab(0% 0 0)) {
30340          .foo {
30341            mask: linear-gradient(lab(56.208% 94.4644 98.8928), lab(51% 70.4544 -115.586)) 40px var(--foo);
30342          }
30343        }
30344      "#,
30345      indoc! { r#"
30346        @supports (color: lab(0% 0 0)) {
30347          .foo {
30348            -webkit-mask: linear-gradient(lab(56.208% 94.4644 98.8928), lab(51% 70.4544 -115.586)) 40px var(--foo);
30349            mask: linear-gradient(lab(56.208% 94.4644 98.8928), lab(51% 70.4544 -115.586)) 40px var(--foo);
30350          }
30351        }
30352      "#},
30353      Browsers {
30354        chrome: Some(90 << 16),
30355        ..Browsers::default()
30356      },
30357    );
30358
30359    prefix_test(
30360      ".foo { mask: url(masks.svg#star) luminance }",
30361      indoc! { r#"
30362        .foo {
30363          -webkit-mask: url("masks.svg#star");
30364          -webkit-mask-source-type: luminance;
30365          mask: url("masks.svg#star") luminance;
30366        }
30367    "#},
30368      Browsers {
30369        chrome: Some(90 << 16),
30370        ..Browsers::default()
30371      },
30372    );
30373
30374    prefix_test(
30375      ".foo { mask-image: url(masks.svg#star) }",
30376      indoc! { r#"
30377        .foo {
30378          -webkit-mask-image: url("masks.svg#star");
30379          mask-image: url("masks.svg#star");
30380        }
30381    "#},
30382      Browsers {
30383        chrome: Some(90 << 16),
30384        ..Browsers::default()
30385      },
30386    );
30387
30388    prefix_test(
30389      r#"
30390        .foo {
30391          mask-image: url(masks.svg#star);
30392          mask-position: 25% 75%;
30393          mask-size: cover;
30394          mask-repeat: no-repeat;
30395          mask-clip: padding-box;
30396          mask-origin: content-box;
30397          mask-composite: subtract;
30398          mask-mode: luminance;
30399        }
30400      "#,
30401      indoc! { r#"
30402        .foo {
30403          -webkit-mask: url("masks.svg#star") 25% 75% / cover no-repeat content-box padding-box;
30404          -webkit-mask-composite: source-out;
30405          -webkit-mask-source-type: luminance;
30406          mask: url("masks.svg#star") 25% 75% / cover no-repeat content-box padding-box subtract luminance;
30407        }
30408    "#},
30409      Browsers {
30410        chrome: Some(90 << 16),
30411        ..Browsers::default()
30412      },
30413    );
30414
30415    prefix_test(
30416      r#"
30417        .foo {
30418          mask-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
30419          mask-position: 25% 75%;
30420          mask-size: cover;
30421          mask-repeat: no-repeat;
30422          mask-clip: padding-box;
30423          mask-origin: content-box;
30424          mask-composite: subtract;
30425          mask-mode: luminance;
30426        }
30427      "#,
30428      indoc! { r#"
30429        .foo {
30430          -webkit-mask: linear-gradient(#ff0b0c, #766eff) 25% 75% / cover no-repeat content-box padding-box;
30431          -webkit-mask-composite: source-out;
30432          -webkit-mask-source-type: luminance;
30433          mask: linear-gradient(#ff0b0c, #766eff) 25% 75% / cover no-repeat content-box padding-box subtract luminance;
30434          -webkit-mask: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 25% 75% / cover no-repeat content-box padding-box;
30435          -webkit-mask-composite: source-out;
30436          -webkit-mask-source-type: luminance;
30437          mask: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 25% 75% / cover no-repeat content-box padding-box subtract luminance;
30438        }
30439    "#},
30440      Browsers {
30441        chrome: Some(90 << 16),
30442        ..Browsers::default()
30443      },
30444    );
30445
30446    test(
30447      r#"
30448        .foo {
30449          mask: none center / 100% no-repeat;
30450          mask-image: var(--svg);
30451        }
30452      "#,
30453      indoc! { r#"
30454        .foo {
30455          mask: none center / 100% no-repeat;
30456          mask-image: var(--svg);
30457        }
30458      "#},
30459    );
30460
30461    prefix_test(
30462      r#"
30463        .foo {
30464          mask-composite: subtract;
30465        }
30466      "#,
30467      indoc! { r#"
30468        .foo {
30469          -webkit-mask-composite: source-out;
30470          mask-composite: subtract;
30471        }
30472    "#},
30473      Browsers {
30474        chrome: Some(90 << 16),
30475        ..Browsers::default()
30476      },
30477    );
30478
30479    prefix_test(
30480      r#"
30481        .foo {
30482          mask-mode: luminance;
30483        }
30484      "#,
30485      indoc! { r#"
30486        .foo {
30487          -webkit-mask-source-type: luminance;
30488          mask-mode: luminance;
30489        }
30490    "#},
30491      Browsers {
30492        chrome: Some(90 << 16),
30493        ..Browsers::default()
30494      },
30495    );
30496
30497    prefix_test(
30498      r#"
30499        .foo {
30500          mask-border: url('border-mask.png') 25 / 35px / 12px space luminance;
30501        }
30502      "#,
30503      indoc! { r#"
30504        .foo {
30505          -webkit-mask-box-image: url("border-mask.png") 25 / 35px / 12px space;
30506          mask-border: url("border-mask.png") 25 / 35px / 12px space luminance;
30507        }
30508    "#},
30509      Browsers {
30510        chrome: Some(90 << 16),
30511        ..Browsers::default()
30512      },
30513    );
30514
30515    prefix_test(
30516      r#"
30517        .foo {
30518          mask-border: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 25 / 35px / 12px space luminance;
30519        }
30520      "#,
30521      indoc! { r#"
30522        .foo {
30523          -webkit-mask-box-image: linear-gradient(#ff0b0c, #766eff) 25 / 35px / 12px space;
30524          mask-border: linear-gradient(#ff0b0c, #766eff) 25 / 35px / 12px space luminance;
30525          -webkit-mask-box-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 25 / 35px / 12px space;
30526          mask-border: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 25 / 35px / 12px space luminance;
30527        }
30528    "#},
30529      Browsers {
30530        chrome: Some(90 << 16),
30531        ..Browsers::default()
30532      },
30533    );
30534
30535    prefix_test(
30536      r#"
30537        .foo {
30538          mask-border-source: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
30539        }
30540      "#,
30541      indoc! { r#"
30542        .foo {
30543          -webkit-mask-box-image-source: linear-gradient(#ff0b0c, #766eff);
30544          mask-border-source: linear-gradient(#ff0b0c, #766eff);
30545          -webkit-mask-box-image-source: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
30546          mask-border-source: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
30547        }
30548    "#},
30549      Browsers {
30550        chrome: Some(90 << 16),
30551        ..Browsers::default()
30552      },
30553    );
30554
30555    prefix_test(
30556      r#"
30557        .foo {
30558          mask-border-source: url(foo.png);
30559          mask-border-slice: 10 40 10 40;
30560          mask-border-width: 10px;
30561          mask-border-outset: 0;
30562          mask-border-repeat: round round;
30563          mask-border-mode: luminance;
30564        }
30565      "#,
30566      indoc! { r#"
30567        .foo {
30568          -webkit-mask-box-image: url("foo.png") 10 40 / 10px round;
30569          mask-border: url("foo.png") 10 40 / 10px round luminance;
30570        }
30571    "#},
30572      Browsers {
30573        chrome: Some(90 << 16),
30574        ..Browsers::default()
30575      },
30576    );
30577
30578    prefix_test(
30579      r#"
30580        .foo {
30581          -webkit-mask-box-image-source: url(foo.png);
30582          -webkit-mask-box-image-slice: 10 40 10 40;
30583          -webkit-mask-box-image-width: 10px;
30584          -webkit-mask-box-image-outset: 0;
30585          -webkit-mask-box-image-repeat: round round;
30586        }
30587      "#,
30588      indoc! { r#"
30589        .foo {
30590          -webkit-mask-box-image: url("foo.png") 10 40 / 10px round;
30591        }
30592    "#},
30593      Browsers {
30594        chrome: Some(90 << 16),
30595        ..Browsers::default()
30596      },
30597    );
30598
30599    prefix_test(
30600      r#"
30601        .foo {
30602          mask-border-slice: 10 40 10 40;
30603        }
30604      "#,
30605      indoc! { r#"
30606        .foo {
30607          -webkit-mask-box-image-slice: 10 40;
30608          mask-border-slice: 10 40;
30609        }
30610    "#},
30611      Browsers {
30612        chrome: Some(90 << 16),
30613        ..Browsers::default()
30614      },
30615    );
30616
30617    prefix_test(
30618      r#"
30619        .foo {
30620          mask-border-slice: var(--foo);
30621        }
30622      "#,
30623      indoc! { r#"
30624        .foo {
30625          -webkit-mask-box-image-slice: var(--foo);
30626          mask-border-slice: var(--foo);
30627        }
30628    "#},
30629      Browsers {
30630        chrome: Some(90 << 16),
30631        ..Browsers::default()
30632      },
30633    );
30634
30635    prefix_test(
30636      r#"
30637        .foo {
30638          mask-border: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) var(--foo);
30639        }
30640      "#,
30641      indoc! { r#"
30642        .foo {
30643          -webkit-mask-box-image: linear-gradient(#ff0b0c, #766eff) var(--foo);
30644          mask-border: linear-gradient(#ff0b0c, #766eff) var(--foo);
30645        }
30646
30647        @supports (color: lab(0% 0 0)) {
30648          .foo {
30649            -webkit-mask-box-image: linear-gradient(lab(56.208% 94.4644 98.8928), lab(51% 70.4544 -115.586)) var(--foo);
30650            mask-border: linear-gradient(lab(56.208% 94.4644 98.8928), lab(51% 70.4544 -115.586)) var(--foo);
30651          }
30652        }
30653    "#},
30654      Browsers {
30655        chrome: Some(90 << 16),
30656        ..Browsers::default()
30657      },
30658    );
30659
30660    prefix_test(
30661      r#"
30662        .foo {
30663          transition: mask 200ms;
30664        }
30665      "#,
30666      indoc! { r#"
30667        .foo {
30668          transition: -webkit-mask .2s, mask .2s;
30669        }
30670    "#},
30671      Browsers {
30672        chrome: Some(90 << 16),
30673        ..Browsers::default()
30674      },
30675    );
30676
30677    prefix_test(
30678      r#"
30679        .foo {
30680          transition: mask-border 200ms;
30681        }
30682      "#,
30683      indoc! { r#"
30684        .foo {
30685          transition: -webkit-mask-box-image .2s, mask-border .2s;
30686        }
30687    "#},
30688      Browsers {
30689        chrome: Some(90 << 16),
30690        ..Browsers::default()
30691      },
30692    );
30693
30694    prefix_test(
30695      r#"
30696        .foo {
30697          transition-property: mask;
30698        }
30699      "#,
30700      indoc! { r#"
30701        .foo {
30702          transition-property: -webkit-mask, mask;
30703        }
30704    "#},
30705      Browsers {
30706        chrome: Some(90 << 16),
30707        ..Browsers::default()
30708      },
30709    );
30710
30711    prefix_test(
30712      r#"
30713        .foo {
30714          transition-property: mask-border;
30715        }
30716      "#,
30717      indoc! { r#"
30718        .foo {
30719          transition-property: -webkit-mask-box-image, mask-border;
30720        }
30721    "#},
30722      Browsers {
30723        chrome: Some(90 << 16),
30724        ..Browsers::default()
30725      },
30726    );
30727
30728    prefix_test(
30729      r#"
30730        .foo {
30731          transition-property: mask-composite, mask-mode;
30732        }
30733      "#,
30734      indoc! { r#"
30735        .foo {
30736          transition-property: -webkit-mask-composite, mask-composite, -webkit-mask-source-type, mask-mode;
30737        }
30738    "#},
30739      Browsers {
30740        chrome: Some(90 << 16),
30741        ..Browsers::default()
30742      },
30743    );
30744
30745    let property =
30746      Property::parse_string("text-rendering".into(), "geometricPrecision", ParserOptions::default()).unwrap();
30747    assert_eq!(
30748      property,
30749      Property::TextRendering(svg::TextRendering::GeometricPrecision)
30750    );
30751    let property =
30752      Property::parse_string("shape-rendering".into(), "geometricPrecision", ParserOptions::default()).unwrap();
30753    assert_eq!(
30754      property,
30755      Property::ShapeRendering(svg::ShapeRendering::GeometricPrecision)
30756    );
30757    let property = Property::parse_string("color-interpolation".into(), "sRGB", ParserOptions::default()).unwrap();
30758    assert_eq!(property, Property::ColorInterpolation(svg::ColorInterpolation::SRGB));
30759  }
30760
30761  #[test]
30762  fn test_mask_image_prefix_duplicates() {
30763    let targets = Browsers {
30764      chrome: Some(90 << 16),
30765      ..Browsers::default()
30766    };
30767
30768    for (source, expected) in [
30769      (
30770        ".foo { -webkit-mask-image: var(--image); mask-image: var(--image) }",
30771        indoc! { r#"
30772          .foo {
30773            -webkit-mask-image: var(--image);
30774            mask-image: var(--image);
30775          }
30776        "#},
30777      ),
30778      (
30779        ".foo { mask-image: var(--first); mask-image: var(--second) }",
30780        indoc! { r#"
30781          .foo {
30782            -webkit-mask-image: var(--first);
30783            mask-image: var(--first);
30784            -webkit-mask-image: var(--second);
30785            mask-image: var(--second);
30786          }
30787        "#},
30788      ),
30789      (
30790        ".foo { mask-image: var(--image); mask-position: center; -webkit-mask-image: var(--image) }",
30791        indoc! { r#"
30792          .foo {
30793            -webkit-mask-image: var(--image);
30794            mask-image: var(--image);
30795            -webkit-mask-position: center;
30796            mask-position: center;
30797            -webkit-mask-image: var(--image);
30798          }
30799        "#},
30800      ),
30801      (
30802        ".foo { mask-image: var(--image) !important; -webkit-mask-image: var(--image) }",
30803        indoc! { r#"
30804          .foo {
30805            -webkit-mask-image: var(--image);
30806            -webkit-mask-image: var(--image) !important;
30807            mask-image: var(--image) !important;
30808          }
30809        "#},
30810      ),
30811    ] {
30812      prefix_test(source, expected, targets);
30813      prefix_test(expected, expected, targets);
30814    }
30815
30816    prefix_test(
30817      ".foo { -webkit-mask-image: var(--image); mask-image: var(--image) }",
30818      indoc! { r#"
30819        .foo {
30820          -webkit-mask-image: var(--image);
30821          mask-image: var(--image);
30822        }
30823      "#},
30824      Browsers {
30825        chrome: Some(130 << 16),
30826        ..Browsers::default()
30827      },
30828    );
30829  }
30830
30831  #[test]
30832  fn test_filter() {
30833    property_range_test(
30834      &["filter", "backdrop-filter"],
30835      &[
30836        ("brightness(-1)", None),
30837        ("contrast(-1)", None),
30838        ("grayscale(-1)", None),
30839        ("invert(-1)", None),
30840        ("opacity(-1)", None),
30841        ("saturate(-1)", None),
30842        ("sepia(-1)", None),
30843        ("blur(-1px)", None),
30844        ("blur(calc(-1px))", Some("blur()")),
30845        ("drop-shadow(1px 2px -3px)", None),
30846        ("hue-rotate(-1deg)", Some("hue-rotate(-1deg)")),
30847      ],
30848    );
30849    minify_test(
30850      ".foo { filter: url('filters.svg#filter-id'); }",
30851      ".foo{filter:url(filters.svg#filter-id)}",
30852    );
30853    minify_test(".foo { filter: blur(5px); }", ".foo{filter:blur(5px)}");
30854    minify_test(".foo { filter: blur(0px); }", ".foo{filter:blur()}");
30855    minify_test(".foo { filter: brightness(10%); }", ".foo{filter:brightness(10%)}");
30856    minify_test(".foo { filter: brightness(100%); }", ".foo{filter:brightness()}");
30857    minify_test(
30858      ".foo { filter: drop-shadow(16px 16px 20px yellow); }",
30859      ".foo{filter:drop-shadow(16px 16px 20px #ff0)}",
30860    );
30861    minify_test(
30862      ".foo { filter: contrast(175%) brightness(3%); }",
30863      ".foo{filter:contrast(175%)brightness(3%)}",
30864    );
30865    minify_test(".foo { filter: hue-rotate(0) }", ".foo{filter:hue-rotate()}");
30866
30867    prefix_test(
30868      ".foo { filter: blur(5px) }",
30869      indoc! { r#"
30870        .foo {
30871          -webkit-filter: blur(5px);
30872          filter: blur(5px);
30873        }
30874      "#},
30875      Browsers {
30876        chrome: Some(20 << 16),
30877        ..Browsers::default()
30878      },
30879    );
30880
30881    prefix_test(
30882      ".foo { filter: blur(5px) }",
30883      indoc! { r#"
30884        .foo {
30885          filter: blur(5px);
30886        }
30887      "#},
30888      Browsers {
30889        chrome: Some(80 << 16),
30890        ..Browsers::default()
30891      },
30892    );
30893
30894    prefix_test(
30895      ".foo { backdrop-filter: blur(5px) }",
30896      indoc! { r#"
30897        .foo {
30898          backdrop-filter: blur(5px);
30899        }
30900      "#},
30901      Browsers {
30902        chrome: Some(80 << 16),
30903        ..Browsers::default()
30904      },
30905    );
30906
30907    prefix_test(
30908      ".foo { backdrop-filter: blur(5px) }",
30909      indoc! { r#"
30910        .foo {
30911          -webkit-backdrop-filter: blur(5px);
30912          backdrop-filter: blur(5px);
30913        }
30914      "#},
30915      Browsers {
30916        safari: Some(15 << 16),
30917        ..Browsers::default()
30918      },
30919    );
30920    prefix_test(
30921      r#"
30922      .foo {
30923        -webkit-backdrop-filter: blur(8px);
30924        backdrop-filter: blur(8px);
30925      }
30926      "#,
30927      indoc! {r#"
30928      .foo {
30929        -webkit-backdrop-filter: blur(8px);
30930        backdrop-filter: blur(8px);
30931      }
30932      "#},
30933      Browsers {
30934        safari: Some(16 << 16),
30935        ..Browsers::default()
30936      },
30937    );
30938
30939    prefix_test(
30940      ".foo { filter: var(--foo) }",
30941      indoc! { r#"
30942        .foo {
30943          -webkit-filter: var(--foo);
30944          filter: var(--foo);
30945        }
30946      "#},
30947      Browsers {
30948        chrome: Some(20 << 16),
30949        ..Browsers::default()
30950      },
30951    );
30952
30953    prefix_test(
30954      ".foo { filter: drop-shadow(16px 16px 20px lab(40% 56.6 39)) }",
30955      indoc! { r#"
30956        .foo {
30957          -webkit-filter: drop-shadow(16px 16px 20px #b32323);
30958          filter: drop-shadow(16px 16px 20px #b32323);
30959          filter: drop-shadow(16px 16px 20px lab(40% 56.6 39));
30960        }
30961      "#},
30962      Browsers {
30963        chrome: Some(20 << 16),
30964        ..Browsers::default()
30965      },
30966    );
30967
30968    prefix_test(
30969      ".foo { filter: contrast(175%) drop-shadow(16px 16px 20px lab(40% 56.6 39)) }",
30970      indoc! { r#"
30971        .foo {
30972          filter: contrast(175%) drop-shadow(16px 16px 20px #b32323);
30973          filter: contrast(175%) drop-shadow(16px 16px 20px lab(40% 56.6 39));
30974        }
30975      "#},
30976      Browsers {
30977        chrome: Some(4 << 16),
30978        ..Browsers::default()
30979      },
30980    );
30981
30982    prefix_test(
30983      ".foo { filter: drop-shadow(16px 16px 20px lab(40% 56.6 39)) drop-shadow(16px 16px 20px yellow) }",
30984      indoc! { r#"
30985        .foo {
30986          filter: drop-shadow(16px 16px 20px #b32323) drop-shadow(16px 16px 20px #ff0);
30987          filter: drop-shadow(16px 16px 20px lab(40% 56.6 39)) drop-shadow(16px 16px 20px #ff0);
30988        }
30989      "#},
30990      Browsers {
30991        chrome: Some(4 << 16),
30992        ..Browsers::default()
30993      },
30994    );
30995
30996    prefix_test(
30997      ".foo { filter: var(--foo) drop-shadow(16px 16px 20px lab(40% 56.6 39)) }",
30998      indoc! { r#"
30999        .foo {
31000          filter: var(--foo) drop-shadow(16px 16px 20px #b32323);
31001        }
31002
31003        @supports (color: lab(0% 0 0)) {
31004          .foo {
31005            filter: var(--foo) drop-shadow(16px 16px 20px lab(40% 56.6 39));
31006          }
31007        }
31008      "#},
31009      Browsers {
31010        chrome: Some(4 << 16),
31011        ..Browsers::default()
31012      },
31013    );
31014  }
31015
31016  #[test]
31017  fn test_mix_blend_mode() {
31018    minify_test(".foo { mix-blend-mode: normal }", ".foo{mix-blend-mode:normal}");
31019    minify_test(".foo { mix-blend-mode: multiply }", ".foo{mix-blend-mode:multiply}");
31020    minify_test(".foo { mix-blend-mode: screen }", ".foo{mix-blend-mode:screen}");
31021    minify_test(".foo { mix-blend-mode: overlay }", ".foo{mix-blend-mode:overlay}");
31022    minify_test(".foo { mix-blend-mode: darken }", ".foo{mix-blend-mode:darken}");
31023    minify_test(".foo { mix-blend-mode: lighten }", ".foo{mix-blend-mode:lighten}");
31024    minify_test(
31025      ".foo { mix-blend-mode: color-dodge }",
31026      ".foo{mix-blend-mode:color-dodge}",
31027    );
31028    minify_test(".foo { mix-blend-mode: color-burn }", ".foo{mix-blend-mode:color-burn}");
31029    minify_test(".foo { mix-blend-mode: hard-light }", ".foo{mix-blend-mode:hard-light}");
31030    minify_test(".foo { mix-blend-mode: soft-light }", ".foo{mix-blend-mode:soft-light}");
31031    minify_test(".foo { mix-blend-mode: difference }", ".foo{mix-blend-mode:difference}");
31032    minify_test(".foo { mix-blend-mode: exclusion }", ".foo{mix-blend-mode:exclusion}");
31033    minify_test(".foo { mix-blend-mode: hue }", ".foo{mix-blend-mode:hue}");
31034    minify_test(".foo { mix-blend-mode: saturation }", ".foo{mix-blend-mode:saturation}");
31035    minify_test(".foo { mix-blend-mode: color }", ".foo{mix-blend-mode:color}");
31036    minify_test(".foo { mix-blend-mode: luminosity }", ".foo{mix-blend-mode:luminosity}");
31037    minify_test(
31038      ".foo { mix-blend-mode: plus-darker }",
31039      ".foo{mix-blend-mode:plus-darker}",
31040    );
31041    minify_test(
31042      ".foo { mix-blend-mode: plus-lighter }",
31043      ".foo{mix-blend-mode:plus-lighter}",
31044    );
31045  }
31046
31047  #[test]
31048  fn test_viewport() {
31049    minify_test(
31050      r#"
31051    @viewport {
31052      width: 100vw;
31053    }"#,
31054      "@viewport{width:100vw}",
31055    );
31056    minify_test(
31057      r#"
31058    @-ms-viewport {
31059      width: device-width;
31060    }"#,
31061      "@-ms-viewport{width:device-width}",
31062    );
31063  }
31064
31065  #[test]
31066  fn test_at_scope() {
31067    minify_test(
31068      r#"
31069      @scope {
31070        .foo {
31071          display: flex;
31072        }
31073      }
31074      "#,
31075      "@scope{.foo{display:flex}}",
31076    );
31077    minify_test(
31078      r#"
31079      @scope {
31080        :scope {
31081          display: flex;
31082          color: lightblue;
31083        }
31084      }"#,
31085      "@scope{:scope{color:#add8e6;display:flex}}",
31086    );
31087    minify_test(
31088      r#"
31089      @scope (.light-scheme) {
31090        a { color: yellow; }
31091      }
31092      "#,
31093      "@scope(.light-scheme){a{color:#ff0}}",
31094    );
31095    minify_test(
31096      r#"
31097      @scope (.media-object) to (.content > *) {
31098        a { color: yellow; }
31099      }
31100      "#,
31101      "@scope(.media-object) to (.content>*){a{color:#ff0}}",
31102    );
31103    minify_test(
31104      r#"
31105      @scope to (.content > *) {
31106        a { color: yellow; }
31107      }
31108      "#,
31109      "@scope to (.content>*){a{color:#ff0}}",
31110    );
31111    minify_test(
31112      r#"
31113      @scope (#my-component) {
31114        & { color: yellow; }
31115      }
31116      "#,
31117      "@scope(#my-component){&{color:#ff0}}",
31118    );
31119    minify_test(
31120      r#"
31121      @scope (.parent-scope) {
31122        @scope (:scope > .child-scope) to (:scope .limit) {
31123          .content { color: yellow; }
31124        }
31125      }
31126      "#,
31127      "@scope(.parent-scope){@scope(:scope>.child-scope) to (:scope .limit){.content{color:#ff0}}}",
31128    );
31129    minify_test(
31130      r#"
31131      .foo {
31132        @scope (.bar) {
31133          color: yellow;
31134        }
31135      }
31136      "#,
31137      ".foo{@scope(.bar){color:#ff0}}",
31138    );
31139    nesting_test(
31140      r#"
31141      .foo {
31142        @scope (.bar) {
31143          color: yellow;
31144        }
31145      }
31146      "#,
31147      indoc! {r#"
31148        @scope (.bar) {
31149          color: #ff0;
31150        }
31151      "#},
31152    );
31153    nesting_test(
31154      r#"
31155      .parent {
31156        color: blue;
31157
31158        @scope (& > .scope) to (& .limit) {
31159          & .content {
31160            color: yellow;
31161          }
31162        }
31163      }
31164      "#,
31165      indoc! {r#"
31166        .parent {
31167          color: #00f;
31168        }
31169
31170        @scope (.parent > .scope) to (.parent > .scope .limit) {
31171          :scope .content {
31172            color: #ff0;
31173          }
31174        }
31175      "#},
31176    );
31177  }
31178
31179  #[test]
31180  fn test_custom_media() {
31181    custom_media_test(
31182      r#"
31183      @custom-media --modern (color), (hover);
31184
31185      @media (--modern) and (width > 1024px) {
31186        .a {
31187          color: green;
31188        }
31189      }
31190      "#,
31191      indoc! {r#"
31192      @media ((color) or (hover)) and (width > 1024px) {
31193        .a {
31194          color: green;
31195        }
31196      }
31197      "#},
31198    );
31199
31200    custom_media_test(
31201      r#"
31202      @custom-media --color (color);
31203
31204      @media (--color) and (width > 1024px) {
31205        .a {
31206          color: green;
31207        }
31208      }
31209      "#,
31210      indoc! {r#"
31211      @media (color) and (width > 1024px) {
31212        .a {
31213          color: green;
31214        }
31215      }
31216      "#},
31217    );
31218
31219    custom_media_test(
31220      r#"
31221      @custom-media --a (color);
31222      @custom-media --b (--a);
31223
31224      @media (--b) and (width > 1024px) {
31225        .a {
31226          color: green;
31227        }
31228      }
31229      "#,
31230      indoc! {r#"
31231      @media (color) and (width > 1024px) {
31232        .a {
31233          color: green;
31234        }
31235      }
31236      "#},
31237    );
31238
31239    custom_media_test(
31240      r#"
31241      @custom-media --not-color not (color);
31242
31243      @media not (--not-color) {
31244        .a {
31245          color: green;
31246        }
31247      }
31248      "#,
31249      indoc! {r#"
31250      @media (color) {
31251        .a {
31252          color: green;
31253        }
31254      }
31255      "#},
31256    );
31257
31258    custom_media_test(
31259      r#"
31260      @custom-media --color-print print and (color);
31261
31262      @media (--color-print) {
31263        .a {
31264          color: green;
31265        }
31266      }
31267      "#,
31268      indoc! {r#"
31269      @media print and (color) {
31270        .a {
31271          color: green;
31272        }
31273      }
31274      "#},
31275    );
31276
31277    custom_media_test(
31278      r#"
31279      @custom-media --color-print print and (color);
31280
31281      @media print and (--color-print) {
31282        .a {
31283          color: green;
31284        }
31285      }
31286      "#,
31287      indoc! {r#"
31288      @media print and (color) {
31289        .a {
31290          color: green;
31291        }
31292      }
31293      "#},
31294    );
31295
31296    custom_media_test(
31297      r#"
31298      @custom-media --not-color-print not print and (color);
31299
31300      @media not print and (--not-color-print) {
31301        .a {
31302          color: green;
31303        }
31304      }
31305      "#,
31306      indoc! {r#"
31307      @media not print and (color) {
31308        .a {
31309          color: green;
31310        }
31311      }
31312      "#},
31313    );
31314
31315    custom_media_test(
31316      r#"
31317      @custom-media --print print;
31318
31319      @media (--print) {
31320        .a {
31321          color: green;
31322        }
31323      }
31324      "#,
31325      indoc! {r#"
31326      @media print {
31327        .a {
31328          color: green;
31329        }
31330      }
31331      "#},
31332    );
31333
31334    custom_media_test(
31335      r#"
31336      @custom-media --print print;
31337
31338      @media not (--print) {
31339        .a {
31340          color: green;
31341        }
31342      }
31343      "#,
31344      indoc! {r#"
31345      @media not print {
31346        .a {
31347          color: green;
31348        }
31349      }
31350      "#},
31351    );
31352
31353    custom_media_test(
31354      r#"
31355      @custom-media --print not print;
31356
31357      @media not (--print) {
31358        .a {
31359          color: green;
31360        }
31361      }
31362      "#,
31363      indoc! {r#"
31364      @media print {
31365        .a {
31366          color: green;
31367        }
31368      }
31369      "#},
31370    );
31371
31372    custom_media_test(
31373      r#"
31374      @custom-media --print print;
31375
31376      @media ((--print)) {
31377        .a {
31378          color: green;
31379        }
31380      }
31381      "#,
31382      indoc! {r#"
31383      @media print {
31384        .a {
31385          color: green;
31386        }
31387      }
31388      "#},
31389    );
31390
31391    custom_media_test(
31392      r#"
31393      @custom-media --color (color);
31394      @custom-media --print print;
31395
31396      @media (--print) and (--color) {
31397        .a {
31398          color: green;
31399        }
31400      }
31401      "#,
31402      indoc! {r#"
31403      @media print and (color) {
31404        .a {
31405          color: green;
31406        }
31407      }
31408      "#},
31409    );
31410
31411    custom_media_test(
31412      r#"
31413      @custom-media --color (color);
31414      @custom-media --not-print not print;
31415
31416      @media (--not-print) and (--color) {
31417        .a {
31418          color: green;
31419        }
31420      }
31421      "#,
31422      indoc! {r#"
31423      @media not print and (color) {
31424        .a {
31425          color: green;
31426        }
31427      }
31428      "#},
31429    );
31430
31431    custom_media_test(
31432      r#"
31433      @custom-media --color (color);
31434      @custom-media --screen screen;
31435      @custom-media --print print;
31436
31437      @media (--print) and (--color), (--screen) and (--color) {
31438        .a {
31439          color: green;
31440        }
31441      }
31442      "#,
31443      indoc! {r#"
31444      @media print and (color), screen and (color) {
31445        .a {
31446          color: green;
31447        }
31448      }
31449      "#},
31450    );
31451
31452    custom_media_test(
31453      r#"
31454      @custom-media --color print and (color), print and (script);
31455
31456      @media (--color) {
31457        .a {
31458          color: green;
31459        }
31460      }
31461      "#,
31462      indoc! {r#"
31463      @media print and ((color) or (script)) {
31464        .a {
31465          color: green;
31466        }
31467      }
31468      "#},
31469    );
31470
31471    custom_media_test(
31472      r#"
31473      @custom-media --color (color);
31474      @custom-media --not-color not all and (--color);
31475
31476      @media (--not-color) {
31477        .a {
31478          color: green;
31479        }
31480      }
31481      "#,
31482      indoc! {r#"
31483        @media not all and (color) {
31484          .a {
31485            color: green;
31486          }
31487        }
31488      "#},
31489    );
31490
31491    custom_media_test(
31492      r#"
31493      @custom-media --color (color);
31494
31495      @media not all and (--color) {
31496        .a {
31497          color: green;
31498        }
31499      }
31500      "#,
31501      indoc! {r#"
31502        @media not all and (color) {
31503          .a {
31504            color: green;
31505          }
31506        }
31507      "#},
31508    );
31509
31510    custom_media_test(
31511      r#"
31512      @media (--print) {
31513        .a {
31514          color: green;
31515        }
31516      }
31517
31518      @custom-media --print print;
31519      "#,
31520      indoc! {r#"
31521      @media print {
31522        .a {
31523          color: green;
31524        }
31525      }
31526      "#},
31527    );
31528
31529    custom_media_test(
31530      r#"
31531      @custom-media --not-width not (min-width: 300px);
31532      @media screen and ((prefers-color-scheme: dark) or (--not-width)) {
31533        .foo {
31534          order: 6;
31535        }
31536      }
31537      "#,
31538      indoc! {r#"
31539      @media screen and ((prefers-color-scheme: dark) or ((width < 300px))) {
31540        .foo {
31541          order: 6;
31542        }
31543      }
31544      "#},
31545    );
31546
31547    fn custom_media_error_test(source: &str, err: Error<MinifyErrorKind>) {
31548      let mut stylesheet = StyleSheet::parse(
31549        &source,
31550        ParserOptions {
31551          filename: "test.css".into(),
31552          flags: ParserFlags::CUSTOM_MEDIA,
31553          ..ParserOptions::default()
31554        },
31555      )
31556      .unwrap();
31557      let res = stylesheet.minify(MinifyOptions {
31558        targets: Browsers {
31559          chrome: Some(95 << 16),
31560          ..Browsers::default()
31561        }
31562        .into(),
31563        ..MinifyOptions::default()
31564      });
31565      assert_eq!(res, Err(err))
31566    }
31567
31568    custom_media_error_test(
31569      r#"
31570      @custom-media --color-print print and (color);
31571
31572      @media screen and (--color-print) {
31573        .a {
31574          color: green;
31575        }
31576      }
31577      "#,
31578      Error {
31579        kind: MinifyErrorKind::UnsupportedCustomMediaBooleanLogic {
31580          custom_media_loc: Location {
31581            source_index: 0,
31582            line: 1,
31583            column: 7,
31584          },
31585        },
31586        loc: Some(ErrorLocation {
31587          filename: "test.css".into(),
31588          line: 3,
31589          column: 7,
31590        }),
31591      },
31592    );
31593
31594    custom_media_error_test(
31595      r#"
31596      @custom-media --color-print print and (color);
31597
31598      @media not print and (--color-print) {
31599        .a {
31600          color: green;
31601        }
31602      }
31603      "#,
31604      Error {
31605        kind: MinifyErrorKind::UnsupportedCustomMediaBooleanLogic {
31606          custom_media_loc: Location {
31607            source_index: 0,
31608            line: 1,
31609            column: 7,
31610          },
31611        },
31612        loc: Some(ErrorLocation {
31613          filename: "test.css".into(),
31614          line: 3,
31615          column: 7,
31616        }),
31617      },
31618    );
31619
31620    custom_media_error_test(
31621      r#"
31622      @custom-media --color-print print and (color);
31623      @custom-media --color-screen screen and (color);
31624
31625      @media (--color-print) or (--color-screen) {}
31626      "#,
31627      Error {
31628        kind: MinifyErrorKind::UnsupportedCustomMediaBooleanLogic {
31629          custom_media_loc: Location {
31630            source_index: 0,
31631            line: 2,
31632            column: 7,
31633          },
31634        },
31635        loc: Some(ErrorLocation {
31636          filename: "test.css".into(),
31637          line: 4,
31638          column: 7,
31639        }),
31640      },
31641    );
31642
31643    custom_media_error_test(
31644      r#"
31645      @custom-media --color-print print and (color);
31646      @custom-media --color-screen screen and (color);
31647
31648      @media (--color-print) and (--color-screen) {}
31649      "#,
31650      Error {
31651        kind: MinifyErrorKind::UnsupportedCustomMediaBooleanLogic {
31652          custom_media_loc: Location {
31653            source_index: 0,
31654            line: 2,
31655            column: 7,
31656          },
31657        },
31658        loc: Some(ErrorLocation {
31659          filename: "test.css".into(),
31660          line: 4,
31661          column: 7,
31662        }),
31663      },
31664    );
31665
31666    custom_media_error_test(
31667      r#"
31668      @custom-media --screen screen;
31669      @custom-media --print print;
31670
31671      @media (--print) and (--screen) {}
31672      "#,
31673      Error {
31674        kind: MinifyErrorKind::UnsupportedCustomMediaBooleanLogic {
31675          custom_media_loc: Location {
31676            source_index: 0,
31677            line: 1,
31678            column: 7,
31679          },
31680        },
31681        loc: Some(ErrorLocation {
31682          filename: "test.css".into(),
31683          line: 4,
31684          column: 7,
31685        }),
31686      },
31687    );
31688
31689    custom_media_error_test(
31690      r#"
31691      @custom-media --not-print not print and (color);
31692      @custom-media --not-screen not screen and (color);
31693
31694      @media ((script) or ((--not-print) and (--not-screen))) {
31695        .a {
31696          color: green;
31697        }
31698      }
31699      "#,
31700      Error {
31701        kind: MinifyErrorKind::UnsupportedCustomMediaBooleanLogic {
31702          custom_media_loc: Location {
31703            source_index: 0,
31704            line: 2,
31705            column: 7,
31706          },
31707        },
31708        loc: Some(ErrorLocation {
31709          filename: "test.css".into(),
31710          line: 4,
31711          column: 7,
31712        }),
31713      },
31714    );
31715
31716    custom_media_error_test(
31717      r#"
31718      @custom-media --color screen and (color), print and (color);
31719
31720      @media (--color) {
31721        .a {
31722          color: green;
31723        }
31724      }
31725      "#,
31726      Error {
31727        kind: MinifyErrorKind::UnsupportedCustomMediaBooleanLogic {
31728          custom_media_loc: Location {
31729            source_index: 0,
31730            line: 1,
31731            column: 7,
31732          },
31733        },
31734        loc: Some(ErrorLocation {
31735          filename: "test.css".into(),
31736          line: 3,
31737          column: 7,
31738        }),
31739      },
31740    );
31741
31742    custom_media_error_test(
31743      r#"
31744      @media (--not-defined) {
31745        .a {
31746          color: green;
31747        }
31748      }
31749      "#,
31750      Error {
31751        kind: MinifyErrorKind::CustomMediaNotDefined {
31752          name: "--not-defined".into(),
31753        },
31754        loc: Some(ErrorLocation {
31755          filename: "test.css".into(),
31756          line: 1,
31757          column: 7,
31758        }),
31759      },
31760    );
31761
31762    custom_media_error_test(
31763      r#"
31764      @custom-media --circular-mq-a (--circular-mq-b);
31765      @custom-media --circular-mq-b (--circular-mq-a);
31766
31767      @media (--circular-mq-a) {
31768        body {
31769          order: 3;
31770        }
31771      }
31772      "#,
31773      Error {
31774        kind: MinifyErrorKind::CircularCustomMedia {
31775          name: "--circular-mq-a".into(),
31776        },
31777        loc: Some(ErrorLocation {
31778          filename: "test.css".into(),
31779          line: 4,
31780          column: 7,
31781        }),
31782      },
31783    );
31784  }
31785
31786  #[test]
31787  fn test_dependencies() {
31788    fn dep_test(source: &str, expected: &str, deps: Vec<(&str, &str)>) {
31789      let mut stylesheet = StyleSheet::parse(
31790        &source,
31791        ParserOptions {
31792          filename: "test.css".into(),
31793          ..ParserOptions::default()
31794        },
31795      )
31796      .unwrap();
31797      stylesheet.minify(MinifyOptions::default()).unwrap();
31798      let res = stylesheet
31799        .to_css(
31800          PrinterOptions {
31801            analyze_dependencies: Some(Default::default()),
31802            minify: true,
31803            ..PrinterOptions::default()
31804          },
31805          None::<&mut ()>,
31806        )
31807        .unwrap();
31808      assert_eq!(res.code, expected);
31809      let dependencies = res.dependencies.unwrap();
31810      assert_eq!(dependencies.len(), deps.len());
31811      for (i, (url, placeholder)) in deps.into_iter().enumerate() {
31812        match &dependencies[i] {
31813          Dependency::Url(dep) => {
31814            assert_eq!(dep.url, url);
31815            assert_eq!(dep.placeholder, placeholder);
31816          }
31817          Dependency::Import(dep) => {
31818            assert_eq!(dep.url, url);
31819            assert_eq!(dep.placeholder, placeholder);
31820          }
31821        }
31822      }
31823    }
31824
31825    fn dep_error_test(source: &str, error: PrinterErrorKind) {
31826      let stylesheet = StyleSheet::parse(&source, ParserOptions::default()).unwrap();
31827      let res = stylesheet.to_css(
31828        PrinterOptions {
31829          analyze_dependencies: Some(Default::default()),
31830          ..PrinterOptions::default()
31831        },
31832        None::<&mut ()>,
31833      );
31834      match res {
31835        Err(e) => assert_eq!(e.kind, error),
31836        _ => unreachable!(),
31837      }
31838    }
31839
31840    dep_test(
31841      ".foo { background: image-set('./img12x.png', './img21x.png' 2x)}",
31842      ".foo{background:image-set(\"hXFI8W\" 1x,\"5TkpBa\" 2x)}",
31843      vec![("./img12x.png", "hXFI8W"), ("./img21x.png", "5TkpBa")],
31844    );
31845
31846    dep_test(
31847      ".foo { background: image-set(url(./img12x.png), url('./img21x.png') 2x)}",
31848      ".foo{background:image-set(\"hXFI8W\" 1x,\"5TkpBa\" 2x)}",
31849      vec![("./img12x.png", "hXFI8W"), ("./img21x.png", "5TkpBa")],
31850    );
31851
31852    dep_test(
31853      ".foo { --test: url(/foo.png) }",
31854      ".foo{--test:url(\"lDnnrG\")}",
31855      vec![("/foo.png", "lDnnrG")],
31856    );
31857
31858    dep_test(
31859      ".foo { --test: url(\"/foo.png\") }",
31860      ".foo{--test:url(\"lDnnrG\")}",
31861      vec![("/foo.png", "lDnnrG")],
31862    );
31863
31864    dep_test(
31865      ".foo { --test: url(\"http://example.com/foo.png\") }",
31866      ".foo{--test:url(\"3X1zSW\")}",
31867      vec![("http://example.com/foo.png", "3X1zSW")],
31868    );
31869
31870    dep_test(
31871      ".foo { --test: url(\"data:image/svg+xml;utf8,<svg></svg>\") }",
31872      ".foo{--test:url(\"-vl-rG\")}",
31873      vec![("data:image/svg+xml;utf8,<svg></svg>", "-vl-rG")],
31874    );
31875
31876    dep_test(
31877      ".foo { background: url(\"foo.png\") var(--test) }",
31878      ".foo{background:url(\"Vwkwkq\") var(--test)}",
31879      vec![("foo.png", "Vwkwkq")],
31880    );
31881
31882    dep_error_test(
31883      ".foo { --test: url(\"foo.png\") }",
31884      PrinterErrorKind::AmbiguousUrlInCustomProperty { url: "foo.png".into() },
31885    );
31886
31887    dep_error_test(
31888      ".foo { --test: url(foo.png) }",
31889      PrinterErrorKind::AmbiguousUrlInCustomProperty { url: "foo.png".into() },
31890    );
31891
31892    dep_error_test(
31893      ".foo { --test: url(./foo.png) }",
31894      PrinterErrorKind::AmbiguousUrlInCustomProperty {
31895        url: "./foo.png".into(),
31896      },
31897    );
31898
31899    dep_test(
31900      ".foo { behavior: url(#foo) }",
31901      ".foo{behavior:url(\"Zn9-2q\")}",
31902      vec![("#foo", "Zn9-2q")],
31903    );
31904
31905    dep_test(
31906      ".foo { --foo: url(#foo) }",
31907      ".foo{--foo:url(\"Zn9-2q\")}",
31908      vec![("#foo", "Zn9-2q")],
31909    );
31910
31911    dep_test(
31912      "@import \"test.css\"; .foo { color: red }",
31913      "@import \"hHsogW\";.foo{color:red}",
31914      vec![("test.css", "hHsogW")],
31915    );
31916  }
31917
31918  #[test]
31919  fn test_api() {
31920    let stylesheet = StyleSheet::parse(".foo:hover { color: red }", ParserOptions::default()).unwrap();
31921    match &stylesheet.rules.0[0] {
31922      CssRule::Style(s) => {
31923        assert_eq!(&s.selectors.to_string(), ".foo:hover");
31924      }
31925      _ => unreachable!(),
31926    }
31927
31928    let color = CssColor::parse_string("#f0f").unwrap();
31929    assert_eq!(color.to_css_string(PrinterOptions::default()).unwrap(), "#f0f");
31930
31931    let rule = CssRule::parse_string(".foo { color: red }", ParserOptions::default()).unwrap();
31932    assert_eq!(
31933      rule.to_css_string(PrinterOptions::default()).unwrap(),
31934      indoc! {r#"
31935    .foo {
31936      color: red;
31937    }"#}
31938    );
31939
31940    let property = Property::parse_string("color".into(), "#f0f", ParserOptions::default()).unwrap();
31941    assert_eq!(
31942      property.to_css_string(false, PrinterOptions::default()).unwrap(),
31943      "color: #f0f"
31944    );
31945    assert_eq!(
31946      property.to_css_string(true, PrinterOptions::default()).unwrap(),
31947      "color: #f0f !important"
31948    );
31949
31950    let code = indoc! { r#"
31951      .foo {
31952        color: green;
31953      }
31954
31955      .bar {
31956        color: red;
31957        background: pink;
31958      }
31959
31960      @media print {
31961        .baz {
31962          color: green;
31963        }
31964      }
31965    "#};
31966    let stylesheet = StyleSheet::parse(code, ParserOptions::default()).unwrap();
31967    if let CssRule::Style(style) = &stylesheet.rules.0[1] {
31968      let (key, val) = style.property_location(code, 0).unwrap();
31969      assert_eq!(
31970        key,
31971        SourceLocation { line: 5, column: 3 }..SourceLocation { line: 5, column: 8 }
31972      );
31973      assert_eq!(
31974        val,
31975        SourceLocation { line: 5, column: 10 }..SourceLocation { line: 5, column: 13 }
31976      );
31977    }
31978
31979    if let CssRule::Style(style) = &stylesheet.rules.0[1] {
31980      let (key, val) = style.property_location(code, 1).unwrap();
31981      assert_eq!(
31982        key,
31983        SourceLocation { line: 6, column: 3 }..SourceLocation { line: 6, column: 13 }
31984      );
31985      assert_eq!(
31986        val,
31987        SourceLocation { line: 6, column: 15 }..SourceLocation { line: 6, column: 19 }
31988      );
31989    }
31990    if let CssRule::Media(media) = &stylesheet.rules.0[2] {
31991      if let CssRule::Style(style) = &media.rules.0[0] {
31992        let (key, val) = style.property_location(code, 0).unwrap();
31993        assert_eq!(
31994          key,
31995          SourceLocation { line: 11, column: 5 }..SourceLocation { line: 11, column: 10 }
31996        );
31997        assert_eq!(
31998          val,
31999          SourceLocation { line: 11, column: 12 }..SourceLocation { line: 11, column: 17 }
32000        );
32001      }
32002    }
32003
32004    let mut property = Property::Transform(Default::default(), VendorPrefix::WebKit);
32005    property.set_prefix(VendorPrefix::None);
32006    assert_eq!(property, Property::Transform(Default::default(), VendorPrefix::None));
32007    property.set_prefix(VendorPrefix::Moz);
32008    assert_eq!(property, Property::Transform(Default::default(), VendorPrefix::Moz));
32009    property.set_prefix(VendorPrefix::WebKit | VendorPrefix::Moz);
32010    assert_eq!(
32011      property,
32012      Property::Transform(Default::default(), VendorPrefix::WebKit | VendorPrefix::Moz)
32013    );
32014
32015    let mut property = Property::TextDecorationLine(Default::default(), VendorPrefix::None);
32016    property.set_prefix(VendorPrefix::Ms);
32017    assert_eq!(
32018      property,
32019      Property::TextDecorationLine(Default::default(), VendorPrefix::None)
32020    );
32021    property.set_prefix(VendorPrefix::WebKit | VendorPrefix::Moz | VendorPrefix::Ms);
32022    assert_eq!(
32023      property,
32024      Property::TextDecorationLine(Default::default(), VendorPrefix::WebKit | VendorPrefix::Moz)
32025    );
32026
32027    let mut property = Property::AccentColor(Default::default());
32028    property.set_prefix(VendorPrefix::WebKit);
32029    assert_eq!(property, Property::AccentColor(Default::default()));
32030  }
32031
32032  #[cfg(feature = "substitute_variables")]
32033  #[test]
32034  fn test_substitute_vars() {
32035    use crate::properties::custom::TokenList;
32036    use crate::traits::ParseWithOptions;
32037
32038    fn test(property: Property, vars: HashMap<&str, &str>, expected: &str) {
32039      if let Property::Unparsed(unparsed) = property {
32040        let vars = vars
32041          .into_iter()
32042          .map(|(k, v)| {
32043            (
32044              k,
32045              TokenList::parse_string_with_options(v, ParserOptions::default()).unwrap(),
32046            )
32047          })
32048          .collect();
32049        let substituted = unparsed.substitute_variables(&vars).unwrap();
32050        assert_eq!(
32051          substituted.to_css_string(false, PrinterOptions::default()).unwrap(),
32052          expected
32053        );
32054      } else {
32055        panic!("Not an unparsed property");
32056      }
32057    }
32058
32059    let property = Property::parse_string("color".into(), "var(--test)", ParserOptions::default()).unwrap();
32060    test(property, HashMap::from([("--test", "yellow")]), "color: #ff0");
32061
32062    let property =
32063      Property::parse_string("color".into(), "var(--test, var(--foo))", ParserOptions::default()).unwrap();
32064    test(property, HashMap::from([("--foo", "yellow")]), "color: #ff0");
32065    let property = Property::parse_string(
32066      "color".into(),
32067      "var(--test, var(--foo, yellow))",
32068      ParserOptions::default(),
32069    )
32070    .unwrap();
32071    test(property, HashMap::new(), "color: #ff0");
32072
32073    let property =
32074      Property::parse_string("width".into(), "calc(var(--a) + var(--b))", ParserOptions::default()).unwrap();
32075    test(property, HashMap::from([("--a", "2px"), ("--b", "4px")]), "width: 6px");
32076
32077    let property = Property::parse_string("color".into(), "var(--a)", ParserOptions::default()).unwrap();
32078    test(
32079      property,
32080      HashMap::from([("--a", "var(--b)"), ("--b", "yellow")]),
32081      "color: #ff0",
32082    );
32083
32084    let property = Property::parse_string("color".into(), "var(--a)", ParserOptions::default()).unwrap();
32085    test(
32086      property,
32087      HashMap::from([("--a", "var(--b)"), ("--b", "var(--c)"), ("--c", "var(--a)")]),
32088      "color: var(--a)",
32089    );
32090  }
32091
32092  #[test]
32093  fn test_layer() {
32094    minify_test("@layer foo;", "@layer foo;");
32095    minify_test("@layer foo, bar;", "@layer foo,bar;");
32096    minify_test("@layer foo.bar;", "@layer foo.bar;");
32097    minify_test("@layer foo.bar, baz;", "@layer foo.bar,baz;");
32098
32099    minify_test(
32100      r#"
32101      @layer foo {
32102        .bar {
32103          color: red;
32104        }
32105      }
32106    "#,
32107      "@layer foo{.bar{color:red}}",
32108    );
32109    minify_test(
32110      r#"
32111      @layer foo.bar {
32112        .bar {
32113          color: red;
32114        }
32115      }
32116    "#,
32117      "@layer foo.bar{.bar{color:red}}",
32118    );
32119    minify_test(r#"
32120      @layer base {
32121        p { max-width: 70ch; }
32122      }
32123
32124      @layer framework {
32125        @layer base {
32126          p { margin-block: 0.75em; }
32127        }
32128
32129        @layer theme {
32130          p { color: #222; }
32131        }
32132      }
32133    "#, "@layer base{p{max-width:70ch}}@layer framework{@layer base{p{margin-block:.75em}}@layer theme{p{color:#222}}}");
32134    minify_test(
32135      r#"
32136      @layer {
32137        .bar {
32138          color: red;
32139        }
32140      }
32141    "#,
32142      "@layer{.bar{color:red}}",
32143    );
32144    minify_test(
32145      r#"
32146      @layer foo\20 bar, baz;
32147    "#,
32148      "@layer foo\\ bar,baz;",
32149    );
32150    minify_test(
32151      r#"
32152      @layer one.two\20 three\#four\.five {
32153        .bar {
32154          color: red;
32155        }
32156      }
32157    "#,
32158      "@layer one.two\\ three\\#four\\.five{.bar{color:red}}",
32159    );
32160
32161    error_test("@layer;", ParserError::UnexpectedToken(Token::Semicolon));
32162    error_test("@layer foo, bar {};", ParserError::AtRuleBodyInvalid);
32163    minify_test("@import 'test.css' layer;", "@import \"test.css\" layer;");
32164    minify_test("@import 'test.css' layer(foo);", "@import \"test.css\" layer(foo);");
32165    minify_test(
32166      "@import 'test.css' layer(foo.bar);",
32167      "@import \"test.css\" layer(foo.bar);",
32168    );
32169    minify_test(
32170      "@import 'test.css' layer(foo\\20 bar);",
32171      "@import \"test.css\" layer(foo\\ bar);",
32172    );
32173    error_test(
32174      "@import 'test.css' layer(foo, bar) {};",
32175      ParserError::UnexpectedToken(Token::Comma),
32176    );
32177    minify_test(
32178      r#"
32179      @layer one {
32180        body {
32181          background: red;
32182        }
32183      }
32184
32185      body {
32186        background: red;
32187      }
32188
32189      @layer two {
32190        body {
32191          background: green;
32192        }
32193      }
32194
32195      @layer one {
32196        body {
32197          background: yellow;
32198        }
32199      }
32200      "#,
32201      "@layer one{body{background:#ff0}}body{background:red}@layer two{body{background:green}}",
32202    );
32203  }
32204
32205  #[test]
32206  fn test_property() {
32207    minify_test(
32208      r#"
32209      @property --property-name {
32210        syntax: '<color>';
32211        inherits: false;
32212        initial-value: yellow;
32213      }
32214    "#,
32215      "@property --property-name{syntax:\"<color>\";inherits:false;initial-value:#ff0}",
32216    );
32217
32218    test(
32219      r#"
32220      @property --property-name {
32221        syntax: '*';
32222        inherits: false;
32223        initial-value: ;
32224      }
32225    "#,
32226      indoc! {r#"
32227      @property --property-name {
32228        syntax: "*";
32229        inherits: false;
32230        initial-value: ;
32231      }
32232    "#},
32233    );
32234
32235    minify_test(
32236      r#"
32237      @property --property-name {
32238        syntax: '*';
32239        inherits: false;
32240        initial-value: ;
32241      }
32242    "#,
32243      "@property --property-name{syntax:\"*\";inherits:false;initial-value:}",
32244    );
32245
32246    test(
32247      r#"
32248      @property --property-name {
32249        syntax: '*';
32250        inherits: false;
32251        initial-value:;
32252      }
32253    "#,
32254      indoc! {r#"
32255      @property --property-name {
32256        syntax: "*";
32257        inherits: false;
32258        initial-value: ;
32259      }
32260    "#},
32261    );
32262
32263    minify_test(
32264      r#"
32265      @property --property-name {
32266        syntax: '*';
32267        inherits: false;
32268        initial-value:;
32269      }
32270    "#,
32271      "@property --property-name{syntax:\"*\";inherits:false;initial-value:}",
32272    );
32273    minify_test(
32274      r#"
32275      @property --property-name {
32276        syntax: '*';
32277        inherits: false;
32278        initial-value: foo bar;
32279      }
32280    "#,
32281      "@property --property-name{syntax:\"*\";inherits:false;initial-value:foo bar}",
32282    );
32283
32284    minify_test(
32285      r#"
32286      @property --property-name {
32287        syntax: '<length>';
32288        inherits: true;
32289        initial-value: 25px;
32290      }
32291    "#,
32292      "@property --property-name{syntax:\"<length>\";inherits:true;initial-value:25px}",
32293    );
32294
32295    minify_test(
32296      r#"
32297      @property --property-name {
32298        syntax: '<string>';
32299        inherits: true;
32300        initial-value: "hi";
32301      }
32302    "#,
32303      "@property --property-name{syntax:\"<string>\";inherits:true;initial-value:\"hi\"}",
32304    );
32305
32306    error_test(
32307      r#"
32308      @property --property-name {
32309        syntax: '<color>';
32310        inherits: false;
32311        initial-value: 25px;
32312      }
32313    "#,
32314      ParserError::UnexpectedToken(crate::properties::custom::Token::Dimension {
32315        has_sign: false,
32316        value: 25.0,
32317        int_value: Some(25),
32318        unit: "px".into(),
32319      }),
32320    );
32321
32322    error_test(
32323      r#"
32324      @property --property-name {
32325        syntax: '<length>';
32326        inherits: false;
32327        initial-value: var(--some-value);
32328      }
32329    "#,
32330      ParserError::UnexpectedToken(crate::properties::custom::Token::Function("var".into())),
32331    );
32332
32333    error_test(
32334      r#"
32335      @property --property-name {
32336        syntax: '<color>';
32337        inherits: false;
32338      }
32339    "#,
32340      ParserError::AtRuleBodyInvalid,
32341    );
32342
32343    minify_test(
32344      r#"
32345      @property --property-name {
32346        syntax: '*';
32347        inherits: false;
32348      }
32349    "#,
32350      "@property --property-name{syntax:\"*\";inherits:false}",
32351    );
32352
32353    error_test(
32354      r#"
32355      @property --property-name {
32356        syntax: '*';
32357      }
32358    "#,
32359      ParserError::AtRuleBodyInvalid,
32360    );
32361
32362    error_test(
32363      r#"
32364      @property --property-name {
32365        inherits: false;
32366      }
32367    "#,
32368      ParserError::AtRuleBodyInvalid,
32369    );
32370
32371    error_test(
32372      r#"
32373      @property property-name {
32374        syntax: '*';
32375        inherits: false;
32376      }
32377    "#,
32378      ParserError::UnexpectedToken(crate::properties::custom::Token::Ident("property-name".into())),
32379    );
32380
32381    minify_test(
32382      r#"
32383      @property --property-name {
32384        syntax: 'custom | <color>';
32385        inherits: false;
32386        initial-value: yellow;
32387      }
32388    "#,
32389      "@property --property-name{syntax:\"custom|<color>\";inherits:false;initial-value:#ff0}",
32390    );
32391
32392    // TODO: Re-enable with a better solution
32393    //       See: https://github.com/parcel-bundler/lightningcss/issues/288
32394    // minify_test(r#"
32395    //   @property --property-name {
32396    //     syntax: '<transform-list>';
32397    //     inherits: false;
32398    //     initial-value: translate(200px,300px) translate(100px,200px) scale(2);
32399    //   }
32400    // "#, "@property --property-name{syntax:\"<transform-list>\";inherits:false;initial-value:matrix(2,0,0,2,300,500)}");
32401
32402    minify_test(
32403      r#"
32404      @property --property-name {
32405        syntax: '<time>';
32406        inherits: false;
32407        initial-value: 1000ms;
32408      }
32409    "#,
32410      "@property --property-name{syntax:\"<time>\";inherits:false;initial-value:1s}",
32411    );
32412
32413    minify_test(
32414      r#"
32415      @property --property-name {
32416        syntax: '<url>';
32417        inherits: false;
32418        initial-value: url("foo.png");
32419      }
32420    "#,
32421      "@property --property-name{syntax:\"<url>\";inherits:false;initial-value:url(foo.png)}",
32422    );
32423
32424    minify_test(
32425      r#"
32426      @property --property-name {
32427        syntax: '<image>';
32428        inherits: false;
32429        initial-value: linear-gradient(yellow, blue);
32430      }
32431    "#,
32432      "@property --property-name{syntax:\"<image>\";inherits:false;initial-value:linear-gradient(#ff0,#00f)}",
32433    );
32434
32435    minify_test(
32436      r#"
32437      @property --property-name {
32438        initial-value: linear-gradient(yellow, blue);
32439        inherits: false;
32440        syntax: '<image>';
32441      }
32442    "#,
32443      "@property --property-name{syntax:\"<image>\";inherits:false;initial-value:linear-gradient(#ff0,#00f)}",
32444    );
32445
32446    test(
32447      r#"
32448      @property --property-name {
32449        syntax: '<length>|none';
32450        inherits: false;
32451        initial-value: none;
32452      }
32453    "#,
32454      indoc! {r#"
32455      @property --property-name {
32456        syntax: "<length> | none";
32457        inherits: false;
32458        initial-value: none;
32459      }
32460    "#},
32461    );
32462
32463    minify_test(
32464      r#"
32465      @property --property-name {
32466        syntax: '<color>#';
32467        inherits: false;
32468        initial-value: yellow, blue;
32469      }
32470    "#,
32471      "@property --property-name{syntax:\"<color>#\";inherits:false;initial-value:#ff0,#00f}",
32472    );
32473    minify_test(
32474      r#"
32475      @property --property-name {
32476        syntax: '<color>+';
32477        inherits: false;
32478        initial-value: yellow blue;
32479      }
32480    "#,
32481      "@property --property-name{syntax:\"<color>+\";inherits:false;initial-value:#ff0 #00f}",
32482    );
32483    minify_test(
32484      r#"
32485      @property --property-name {
32486        syntax: '<color>';
32487        inherits: false;
32488        initial-value: yellow;
32489      }
32490      .foo {
32491        color: var(--property-name)
32492      }
32493      @property --property-name {
32494        syntax: '<color>';
32495        inherits: true;
32496        initial-value: blue;
32497      }
32498    "#,
32499      "@property --property-name{syntax:\"<color>\";inherits:true;initial-value:#00f}.foo{color:var(--property-name)}",
32500    );
32501
32502    test(
32503      r#"
32504      @media (width < 800px) {
32505        @property --property-name {
32506          syntax: '*';
32507          inherits: false;
32508        }
32509      }
32510    "#,
32511      indoc! {r#"
32512        @media (width < 800px) {
32513          @property --property-name {
32514            syntax: "*";
32515            inherits: false
32516          }
32517        }
32518    "#},
32519    );
32520
32521    test(
32522      r#"
32523      @layer foo {
32524        @property --property-name {
32525          syntax: '*';
32526          inherits: false;
32527        }
32528      }
32529    "#,
32530      indoc! {r#"
32531        @layer foo {
32532          @property --property-name {
32533            syntax: "*";
32534            inherits: false
32535          }
32536        }
32537    "#},
32538    );
32539  }
32540
32541  #[test]
32542  fn test_quoting_unquoting_urls() {
32543    // Single quotes avoid escaping the double quotes in SVG attributes.
32544    minify_test(
32545      r#"
32546      .foo {
32547        background-image: url('data:image/svg+xml,<svg width="1" height="1"></svg>');
32548      }
32549      "#,
32550      r#".foo{background-image:url('data:image/svg+xml,<svg width="1" height="1"></svg>')}"#,
32551    );
32552
32553    // Keep double quotes when they are shorter or tied with single quotes.
32554    minify_test(
32555      r#"
32556      .foo {
32557        background-image: url("a 'b' c"), url('a "b" \'c\''), url('a "b" \'c');
32558      }
32559      "#,
32560      r#".foo{background-image:url("a 'b' c"),url("a \"b\" 'c'"),url('a "b" \'c')}"#,
32561    );
32562
32563    // Unquoted output still wins ties, including an empty URL.
32564    minify_test(
32565      r#"
32566      .foo {
32567        background-image: url('"'), url('""'), url('"""'), url('');
32568      }
32569      "#,
32570      r#".foo{background-image:url(\"),url(\"\"),url('"""'),url()}"#,
32571    );
32572
32573    // Escaped quotes and backslashes are parsed before choosing the quote style.
32574    minify_test(
32575      r#"
32576      .foo {
32577        background-image: url("a \\\"b\\\" \\c"), url('a "b" \\\'c');
32578      }
32579      "#,
32580      r#".foo{background-image:url('a \\"b\\" \\c'),url('a "b" \\\'c')}"#,
32581    );
32582
32583    // Preserve control characters and hex escape terminators before hex digits and spaces.
32584    minify_test(
32585      r#"
32586      .foo {
32587        background-image: url('"a"\a f\d  \c a\1 b\7f c\9 "é😀"');
32588      }
32589      "#,
32590      r#".foo{background-image:url('"a"\a f\d  \c a\1 b\7f c\9 "é😀"')}"#,
32591    );
32592
32593    minify_test(
32594      r#"
32595      .foo {
32596        background-image: url('"a" \
32597b\0 c');
32598      }
32599      "#,
32600      r#".foo{background-image:url('"a" b�c')}"#,
32601    );
32602
32603    // Keep the existing double-quoted output when not minifying.
32604    test(
32605      r#"
32606      .foo {
32607        background-image: url('a "b" c');
32608      }
32609      "#,
32610      ".foo {\n  background-image: url(\"a \\\"b\\\" c\");\n}\n",
32611    );
32612
32613    // Quotes remain double quotes when not minifying
32614    test(
32615      r#".foo {
32616      background-image: url("0123abcd");
32617    }"#,
32618      r#".foo {
32619  background-image: url("0123abcd");
32620}
32621"#,
32622    );
32623
32624    // Quotes removed when minifying
32625    minify_test(
32626      r#".foo {
32627      background-image: url("0123abcd");
32628    }"#,
32629      r#".foo{background-image:url(0123abcd)}"#,
32630    );
32631
32632    // Doubles quotes added if not present when not minifying
32633    test(
32634      r#".foo {
32635      background-image: url(0123abcd);
32636    }"#,
32637      r#".foo {
32638  background-image: url("0123abcd");
32639}
32640"#,
32641    );
32642
32643    // No quotes changed if not present when not minifying
32644    minify_test(
32645      r#".foo {
32646      background-image: url(0123abcd);
32647    }"#,
32648      r#".foo{background-image:url(0123abcd)}"#,
32649    );
32650  }
32651
32652  #[test]
32653  fn test_url_quote_roundtrip() {
32654    use crate::values::url::Url;
32655
32656    // Exercise escape boundaries on both sides of quotes, including a literal
32657    // backslash followed by a hex digit and non-ASCII text.
32658    let parts = [
32659      "\"", "'", "\\", "\n", "\r", "\x0c", "\x01", "\x7f", "\t", " ", "f", "é😀", "(", ")",
32660    ];
32661    for a in parts {
32662      for b in parts {
32663        for c in parts {
32664          let value = format!("\"\"{a}{b}{c}\"\"");
32665          let url = Url {
32666            url: value.as_str().into(),
32667            loc: crate::dependencies::Location { line: 1, column: 1 },
32668          };
32669          let serialized = url
32670            .to_css_string(PrinterOptions {
32671              minify: true,
32672              ..Default::default()
32673            })
32674            .unwrap();
32675          assert_eq!(Url::parse_string(&serialized).unwrap(), url);
32676        }
32677      }
32678    }
32679  }
32680
32681  #[test]
32682  fn test_url_quoting_dependencies() {
32683    let stylesheet = StyleSheet::parse(
32684      r#"
32685      .foo {
32686        background-image: url('a "b" c');
32687      }
32688      "#,
32689      ParserOptions::default(),
32690    )
32691    .unwrap();
32692    let result = stylesheet
32693      .to_css(
32694        PrinterOptions {
32695          minify: true,
32696          analyze_dependencies: Some(Default::default()),
32697          ..Default::default()
32698        },
32699        None::<&mut ()>,
32700      )
32701      .unwrap();
32702    let dependencies = result.dependencies.unwrap();
32703    assert_eq!(dependencies.len(), 1);
32704    let Dependency::Url(dep) = &dependencies[0] else {
32705      panic!("expected URL dependency")
32706    };
32707    assert_eq!(dep.url, r#"a "b" c"#);
32708    assert_eq!(
32709      result.code,
32710      format!(".foo{{background-image:url(\"{}\")}}", dep.placeholder)
32711    );
32712  }
32713
32714  #[test]
32715  #[cfg(feature = "sourcemap")]
32716  fn test_url_quoting_source_map() {
32717    let stylesheet = StyleSheet::parse(
32718      r#"
32719      .foo {
32720        background-image: url('"a" \a b');
32721      }
32722      .bar {
32723        color: red;
32724      }
32725      "#,
32726      ParserOptions::default(),
32727    )
32728    .unwrap();
32729    let mut sm = parcel_sourcemap::SourceMap::new("/");
32730    let result = stylesheet
32731      .to_css(
32732        PrinterOptions {
32733          minify: true,
32734          ..Default::default()
32735        },
32736        Some(&mut sm),
32737      )
32738      .unwrap();
32739    let column = result.code.find(".bar").unwrap() as u32;
32740    let mapping = sm.find_closest_mapping(0, column).unwrap();
32741    assert_eq!(mapping.generated_column, column);
32742    assert_eq!(mapping.original.unwrap().original_line, 4);
32743  }
32744
32745  #[test]
32746  fn test_zindex() {
32747    minify_test(".foo { z-index: 2 }", ".foo{z-index:2}");
32748    minify_test(".foo { z-index: -2 }", ".foo{z-index:-2}");
32749    minify_test(".foo { z-index: 999999 }", ".foo{z-index:999999}");
32750    minify_test(".foo { z-index: 9999999 }", ".foo{z-index:9999999}");
32751    minify_test(".foo { z-index: -9999999 }", ".foo{z-index:-9999999}");
32752  }
32753
32754  #[derive(Default)]
32755  struct TestSourceMap {
32756    sources: Vec<String>,
32757    names: Vec<String>,
32758    sources_content: Vec<(u32, String)>,
32759    mappings: Vec<(u32, u32, Option<OriginalLocation>)>,
32760  }
32761
32762  impl SourceMap for TestSourceMap {
32763    fn add_source(&mut self, source: &str) -> u32 {
32764      if let Some(index) = self.sources.iter().position(|s| s == source) {
32765        index as u32
32766      } else {
32767        self.sources.push(source.to_owned());
32768        (self.sources.len() - 1) as u32
32769      }
32770    }
32771
32772    fn add_name(&mut self, name: &str) -> u32 {
32773      if let Some(index) = self.names.iter().position(|s| s == name) {
32774        index as u32
32775      } else {
32776        self.names.push(name.to_owned());
32777        (self.names.len() - 1) as u32
32778      }
32779    }
32780
32781    fn set_source_content(&mut self, source_index: u32, source_content: &str) {
32782      self.sources_content.push((source_index, source_content.to_owned()));
32783    }
32784
32785    fn add_mapping(&mut self, generated_line: u32, generated_column: u32, original: Option<OriginalLocation>) {
32786      self.mappings.push((generated_line, generated_column, original));
32787    }
32788
32789    fn from_data_url(_source_root: &str, _data_url: &str) -> Option<Self> {
32790      None
32791    }
32792
32793    fn find_closest_mapping(&mut self, line: u32, column: u32) -> Option<OriginalLocation> {
32794      self
32795        .mappings
32796        .iter()
32797        .rev()
32798        .find(|(generated_line, generated_column, _)| (*generated_line, *generated_column) <= (line, column))
32799        .and_then(|(_, _, original)| *original)
32800    }
32801
32802    fn get_source(&self, source_index: u32) -> Option<&str> {
32803      self.sources.get(source_index as usize).map(String::as_str)
32804    }
32805
32806    fn get_name(&self, name_index: u32) -> Option<&str> {
32807      self.names.get(name_index as usize).map(String::as_str)
32808    }
32809
32810    fn get_source_content(&self, source_index: u32) -> Option<&str> {
32811      self
32812        .sources_content
32813        .iter()
32814        .find(|(index, _)| *index == source_index)
32815        .map(|(_, content)| content.as_str())
32816    }
32817  }
32818
32819  #[test]
32820  fn test_custom_source_map_remapped_content() {
32821    use crate::printer::Printer;
32822
32823    for content in [None, Some(""), Some(".original { color: red }")] {
32824      let original = OriginalLocation {
32825        original_line: 10,
32826        original_column: 5,
32827        source: 0,
32828        name: Some(0),
32829      };
32830      let input_map = || TestSourceMap {
32831        sources: vec!["original.scss".into()],
32832        names: vec!["original".into()],
32833        sources_content: content.map(|content| vec![(0, content.into())]).unwrap_or_default(),
32834        mappings: vec![(0, 0, Some(original))],
32835      };
32836      let mut output = TestSourceMap::default();
32837      // Ensure the cache uses output indices, which may differ from input indices.
32838      output.add_source("existing.css");
32839      let mut css = String::new();
32840      let mut printer = Printer::new(&mut css, PrinterOptions::default()).with_source_map(Some(&mut output));
32841      printer.source_maps = vec![Some(input_map()), Some(input_map())];
32842      for source_index in [0, 1] {
32843        for line in 0..100 {
32844          printer.add_mapping(Location {
32845            source_index,
32846            line,
32847            column: 1,
32848          });
32849        }
32850      }
32851      drop(printer);
32852
32853      assert_eq!(output.sources, vec!["existing.css", "original.scss"]);
32854      assert_eq!(output.names, vec!["original"]);
32855      assert_eq!(
32856        output.sources_content,
32857        content.map(|content| vec![(1, content.into())]).unwrap_or_default()
32858      );
32859      assert_eq!(output.mappings.len(), 200);
32860      assert!(output
32861        .mappings
32862        .iter()
32863        .all(|(_, _, location)| *location == Some(OriginalLocation { source: 1, ..original })));
32864    }
32865  }
32866
32867  #[test]
32868  fn test_custom_source_map() {
32869    let mut stylesheet = StyleSheet::parse(".foo { color: red }", ParserOptions::default()).unwrap();
32870    stylesheet.minify(MinifyOptions::default()).unwrap();
32871
32872    let mut source_map = TestSourceMap::default();
32873    let result = stylesheet
32874      .to_css(
32875        PrinterOptions {
32876          minify: true,
32877          ..PrinterOptions::default()
32878        },
32879        Some(&mut source_map),
32880      )
32881      .unwrap();
32882
32883    assert_eq!(result.code, ".foo{color:red}");
32884    assert_eq!(
32885      source_map.mappings.first(),
32886      Some(&(
32887        0,
32888        0,
32889        Some(OriginalLocation {
32890          original_line: 0,
32891          original_column: 0,
32892          source: 0,
32893          name: None,
32894        })
32895      ))
32896    );
32897  }
32898
32899  #[test]
32900  #[cfg(feature = "sourcemap")]
32901  fn test_input_source_map() {
32902    let source = r#".imported {
32903      content: "yay, file support!";
32904    }
32905
32906    .selector {
32907      margin: 1em;
32908      background-color: #f60;
32909    }
32910
32911    .selector .nested {
32912      margin: 0.5em;
32913    }
32914
32915    /*# sourceMappingURL=data:application/json;base64,ewoJInZlcnNpb24iOiAzLAoJInNvdXJjZVJvb3QiOiAicm9vdCIsCgkiZmlsZSI6ICJzdGRvdXQiLAoJInNvdXJjZXMiOiBbCgkJInN0ZGluIiwKCQkic2Fzcy9fdmFyaWFibGVzLnNjc3MiLAoJCSJzYXNzL19kZW1vLnNjc3MiCgldLAoJInNvdXJjZXNDb250ZW50IjogWwoJCSJAaW1wb3J0IFwiX3ZhcmlhYmxlc1wiO1xuQGltcG9ydCBcIl9kZW1vXCI7XG5cbi5zZWxlY3RvciB7XG4gIG1hcmdpbjogJHNpemU7XG4gIGJhY2tncm91bmQtY29sb3I6ICRicmFuZENvbG9yO1xuXG4gIC5uZXN0ZWQge1xuICAgIG1hcmdpbjogJHNpemUgLyAyO1xuICB9XG59IiwKCQkiJGJyYW5kQ29sb3I6ICNmNjA7XG4kc2l6ZTogMWVtOyIsCgkJIi5pbXBvcnRlZCB7XG4gIGNvbnRlbnQ6IFwieWF5LCBmaWxlIHN1cHBvcnQhXCI7XG59IgoJXSwKCSJtYXBwaW5ncyI6ICJBRUFBLFNBQVMsQ0FBQztFQUNSLE9BQU8sRUFBRSxvQkFBcUI7Q0FDL0I7O0FGQ0QsU0FBUyxDQUFDO0VBQ1IsTUFBTSxFQ0hELEdBQUc7RURJUixnQkFBZ0IsRUNMTCxJQUFJO0NEVWhCOztBQVBELFNBQVMsQ0FJUCxPQUFPLENBQUM7RUFDTixNQUFNLEVDUEgsS0FBRztDRFFQIiwKCSJuYW1lcyI6IFtdCn0= */"#;
32916
32917    let mut stylesheet = StyleSheet::parse(&source, ParserOptions::default()).unwrap();
32918    stylesheet.minify(MinifyOptions::default()).unwrap();
32919    let mut sm = parcel_sourcemap::SourceMap::new("/");
32920    stylesheet
32921      .to_css(
32922        PrinterOptions {
32923          minify: true,
32924          ..PrinterOptions::default()
32925        },
32926        Some(&mut sm),
32927      )
32928      .unwrap();
32929    let map = sm.to_json(None).unwrap();
32930    assert_eq!(
32931      map,
32932      r#"{"version":3,"sourceRoot":null,"mappings":"AAAA,uCCGA,2CAAA","sources":["sass/_demo.scss","stdin"],"sourcesContent":[".imported {\n  content: \"yay, file support!\";\n}","@import \"_variables\";\n@import \"_demo\";\n\n.selector {\n  margin: $size;\n  background-color: $brandColor;\n\n  .nested {\n    margin: $size / 2;\n  }\n}"],"names":[]}"#
32933    );
32934  }
32935
32936  #[test]
32937  #[cfg(feature = "sourcemap")]
32938  fn test_source_maps_with_license_comments() {
32939    let source = r#"/*! a single line comment */
32940    /*!
32941      a comment
32942      containing
32943      multiple
32944      lines
32945    */
32946    .a {
32947      display: flex;
32948    }
32949
32950    .b {
32951      display: hidden;
32952    }
32953    "#;
32954
32955    let mut sm = parcel_sourcemap::SourceMap::new("/");
32956    let source_index = sm.add_source("input.css");
32957    sm.set_source_content(source_index as usize, source).unwrap();
32958
32959    let mut stylesheet = StyleSheet::parse(
32960      &source,
32961      ParserOptions {
32962        source_index,
32963        ..Default::default()
32964      },
32965    )
32966    .unwrap();
32967    stylesheet.minify(MinifyOptions::default()).unwrap();
32968    stylesheet
32969      .to_css(
32970        PrinterOptions {
32971          minify: true,
32972          ..PrinterOptions::default()
32973        },
32974        Some(&mut sm),
32975      )
32976      .unwrap();
32977    let map = sm.to_json(None).unwrap();
32978    assert_eq!(
32979      map,
32980      r#"{"version":3,"sourceRoot":null,"mappings":";;;;;;;AAOI,gBAIA","sources":["input.css"],"sourcesContent":["/*! a single line comment */\n    /*!\n      a comment\n      containing\n      multiple\n      lines\n    */\n    .a {\n      display: flex;\n    }\n\n    .b {\n      display: hidden;\n    }\n    "],"names":[]}"#
32981    );
32982  }
32983
32984  #[test]
32985  fn test_error_recovery() {
32986    use std::sync::{Arc, RwLock};
32987    let warnings = Some(Arc::new(RwLock::new(Vec::new())));
32988    test_with_options(
32989      r#"
32990      h1(>h1) {
32991        color: red;
32992      }
32993
32994      .foo {
32995        color: red;
32996      }
32997
32998      .clearfix {
32999        *zoom: 1;
33000        background: red;
33001      }
33002
33003      @media (hover) {
33004        h1(>h1) {
33005          color: red;
33006        }
33007
33008        .bar {
33009          color: red;
33010        }
33011      }
33012
33013      input:placeholder {
33014        color: red;
33015      }
33016
33017      input::hover {
33018        color: red;
33019      }
33020    "#,
33021      indoc! { r#"
33022      .foo {
33023        color: red;
33024      }
33025
33026      .clearfix {
33027        background: red;
33028      }
33029
33030      @media (hover) {
33031        .bar {
33032          color: red;
33033        }
33034      }
33035
33036      input:placeholder {
33037        color: red;
33038      }
33039
33040      input::hover {
33041        color: red;
33042      }
33043    "#},
33044      ParserOptions {
33045        filename: "test.css".into(),
33046        error_recovery: true,
33047        warnings: warnings.clone(),
33048        ..ParserOptions::default()
33049      },
33050    );
33051    let w = warnings.unwrap();
33052    let warnings = w.read().unwrap();
33053    assert_eq!(
33054      *warnings,
33055      vec![
33056        Error {
33057          kind: ParserError::SelectorError(SelectorError::EmptySelector),
33058          loc: Some(ErrorLocation {
33059            filename: "test.css".into(),
33060            line: 1,
33061            column: 7
33062          })
33063        },
33064        Error {
33065          kind: ParserError::UnexpectedToken(Token::Semicolon),
33066          loc: Some(ErrorLocation {
33067            filename: "test.css".into(),
33068            line: 10,
33069            column: 17
33070          })
33071        },
33072        Error {
33073          kind: ParserError::SelectorError(SelectorError::EmptySelector),
33074          loc: Some(ErrorLocation {
33075            filename: "test.css".into(),
33076            line: 15,
33077            column: 9
33078          })
33079        },
33080        Error {
33081          kind: ParserError::SelectorError(SelectorError::UnsupportedPseudoClass("placeholder".into())),
33082          loc: Some(ErrorLocation {
33083            filename: "test.css".into(),
33084            line: 24,
33085            column: 13,
33086          }),
33087        },
33088        Error {
33089          kind: ParserError::SelectorError(SelectorError::UnsupportedPseudoElement("hover".into())),
33090          loc: Some(ErrorLocation {
33091            filename: "test.css".into(),
33092            line: 28,
33093            column: 13,
33094          }),
33095        },
33096      ]
33097    )
33098  }
33099
33100  #[test]
33101  fn test_invalid() {
33102    error_test(
33103      ".a{color: hsla(120, 62.32%;}",
33104      ParserError::UnexpectedToken(Token::CloseCurlyBracket),
33105    );
33106    error_test(
33107      ".a{--foo: url(foo\\) b\\)ar)}",
33108      ParserError::UnexpectedToken(Token::BadUrl("foo\\) b\\)ar".into())),
33109    );
33110  }
33111
33112  #[test]
33113  fn test_container_queries() {
33114    // name only (no condition) - new syntax
33115    minify_test(
33116      r#"
33117      @container foo {
33118        .inner {
33119          background: green;
33120        }
33121      }
33122    "#,
33123      "@container foo{.inner{background:green}}",
33124    );
33125
33126    // with name
33127    minify_test(
33128      r#"
33129      @container my-layout (inline-size > 45em) {
33130        .foo {
33131          color: red;
33132        }
33133      }
33134    "#,
33135      "@container my-layout (inline-size>45em){.foo{color:red}}",
33136    );
33137
33138    minify_test(
33139      r#"
33140      @container my-layout ( not (width > 500px) ) {
33141        .foo {
33142          color: red;
33143        }
33144      }
33145    "#,
33146      "@container my-layout not (width>500px){.foo{color:red}}",
33147    );
33148
33149    minify_test(
33150      r#"
33151      @container my-layout not (width > 500px) {
33152        .foo {
33153          color: red;
33154        }
33155      }
33156    "#,
33157      "@container my-layout not (width>500px){.foo{color:red}}",
33158    );
33159
33160    minify_test(
33161      r#"
33162      @container not (width > 500px) {
33163        .foo {
33164          color: red;
33165        }
33166      }
33167    "#,
33168      "@container not (width>500px){.foo{color:red}}",
33169    );
33170
33171    minify_test(
33172      r#"
33173      @container my-layout ((width: 100px) and (not (height: 100px))) {
33174        .foo {
33175          color: red;
33176        }
33177      }
33178    "#,
33179      "@container my-layout (width:100px) and (not (height:100px)){.foo{color:red}}",
33180    );
33181
33182    minify_test(
33183      r#"
33184      @container my-layout (width = max(10px, 10em)) {
33185        .foo {
33186          color: red;
33187        }
33188      }
33189    "#,
33190      "@container my-layout (width=max(10px,10em)){.foo{color:red}}",
33191    );
33192
33193    // without name
33194    minify_test(
33195      r#"
33196      @container (inline-size > 45em) {
33197        .foo {
33198          color: red;
33199        }
33200      }
33201    "#,
33202      "@container (inline-size>45em){.foo{color:red}}",
33203    );
33204
33205    minify_test(
33206      r#"
33207      @container (inline-size > 45em) and (inline-size < 100em) {
33208        .foo {
33209          color: red;
33210        }
33211      }
33212    "#,
33213      "@container (inline-size>45em) and (inline-size<100em){.foo{color:red}}",
33214    );
33215
33216    // calc()
33217    minify_test(
33218      r#"
33219      @container (width > calc(100vw - 50px)) {
33220        .foo {
33221          color: red;
33222        }
33223      }
33224    "#,
33225      "@container (width>calc(100vw - 50px)){.foo{color:red}}",
33226    );
33227
33228    minify_test(
33229      r#"
33230      @container (calc(100vh - 50px) <= height ) {
33231        .foo {
33232          color: red;
33233        }
33234      }
33235    "#,
33236      "@container (height>=calc(100vh - 50px)){.foo{color:red}}",
33237    );
33238
33239    // merge adjacent
33240    minify_test(
33241      r#"
33242      @container my-layout (inline-size > 45em) {
33243        .foo {
33244          color: red;
33245        }
33246      }
33247
33248      @container my-layout (inline-size > 45em) {
33249        .foo {
33250          background: yellow;
33251        }
33252
33253        .bar {
33254          color: white;
33255        }
33256      }
33257    "#,
33258      "@container my-layout (inline-size>45em){.foo{color:red;background:#ff0}.bar{color:#fff}}",
33259    );
33260
33261    minify_test(
33262      r#"
33263    .foo {
33264      container-name: foo bar;
33265      container-type: size;
33266    }
33267    "#,
33268      ".foo{container:foo bar/size}",
33269    );
33270    minify_test(
33271      r#"
33272    .foo {
33273      container-name: foo bar;
33274      container-type: normal;
33275    }
33276    "#,
33277      ".foo{container:foo bar}",
33278    );
33279    minify_test(
33280      ".foo{ container-type: inline-size }",
33281      ".foo{container-type:inline-size}",
33282    );
33283    minify_test(".foo{ container-name: none; }", ".foo{container-name:none}");
33284    minify_test(".foo{ container-name: foo; }", ".foo{container-name:foo}");
33285    minify_test(".foo{ container: foo / normal; }", ".foo{container:foo}");
33286    minify_test(
33287      ".foo{ container: foo / inline-size; }",
33288      ".foo{container:foo/inline-size}",
33289    );
33290    minify_test(".foo { width: calc(1cqw + 2cqw) }", ".foo{width:3cqw}");
33291    minify_test(".foo { width: calc(1cqh + 2cqh) }", ".foo{width:3cqh}");
33292    minify_test(".foo { width: calc(1cqi + 2cqi) }", ".foo{width:3cqi}");
33293    minify_test(".foo { width: calc(1cqb + 2cqb) }", ".foo{width:3cqb}");
33294    minify_test(".foo { width: calc(1cqmin + 2cqmin) }", ".foo{width:3cqmin}");
33295    minify_test(".foo { width: calc(1cqmax + 2cqmax) }", ".foo{width:3cqmax}");
33296
33297    // Unlike in @media, there is no need to convert the range syntax in @container,
33298    // because browsers all support this syntax.
33299    prefix_test(
33300      r#"
33301      @container (width > 100px) {
33302        .foo { padding: 5px; }
33303      }
33304      "#,
33305      indoc! { r#"
33306        @container (width > 100px) {
33307          .foo {
33308            padding: 5px;
33309          }
33310        }
33311      "#},
33312      Browsers {
33313        chrome: Some(105 << 16),
33314        ..Browsers::default()
33315      },
33316    );
33317    prefix_test(
33318      r#"
33319      @container (min-width: 100px) {
33320        .foo { padding: 5px; }
33321      }
33322      "#,
33323      indoc! { r#"
33324        @container (width >= 100px) {
33325          .foo {
33326            padding: 5px;
33327          }
33328        }
33329      "#},
33330      Browsers {
33331        chrome: Some(105 << 16),
33332        ..Browsers::default()
33333      },
33334    );
33335
33336    minify_test(
33337      r#"
33338      @container style(--responsive: true) {
33339        .foo {
33340          color: red;
33341        }
33342      }
33343    "#,
33344      "@container style(--responsive:true){.foo{color:red}}",
33345    );
33346    minify_test(
33347      r#"
33348      @container style(--responsive: true) and style(color: yellow) {
33349        .foo {
33350          color: red;
33351        }
33352      }
33353    "#,
33354      "@container style(--responsive:true) and style(color:#ff0){.foo{color:red}}",
33355    );
33356    minify_test(
33357      r#"
33358      @container not style(--responsive: true) {
33359        .foo {
33360          color: red;
33361        }
33362      }
33363    "#,
33364      "@container not style(--responsive:true){.foo{color:red}}",
33365    );
33366    minify_test(
33367      r#"
33368      @container (inline-size > 45em) and style(--responsive: true) {
33369        .foo {
33370          color: red;
33371        }
33372      }
33373    "#,
33374      "@container (inline-size>45em) and style(--responsive:true){.foo{color:red}}",
33375    );
33376    minify_test(
33377      r#"
33378      @container style((accent-color: yellow) or (--bar: 10px)) {
33379        .foo {
33380          color: red;
33381        }
33382      }
33383    "#,
33384      "@container style((accent-color:#ff0) or (--bar:10px)){.foo{color:red}}",
33385    );
33386    minify_test(
33387      r#"
33388      @container style(not ((width: calc(10px + 20px)) and ((--bar: url(x))))) {
33389        .foo {
33390          color: red;
33391        }
33392      }
33393    "#,
33394      "@container style(not ((width:30px) and (--bar:url(x)))){.foo{color:red}}",
33395    );
33396    minify_test(
33397      r#"
33398      @container style(color: yellow !important) {
33399        .foo {
33400          color: red;
33401        }
33402      }
33403    "#,
33404      "@container style(color:yellow){.foo{color:red}}",
33405    );
33406    minify_test(
33407      r#"
33408      @container style(--foo:) {
33409        .foo {
33410          color: red;
33411        }
33412      }
33413    "#,
33414      "@container style(--foo:){.foo{color:red}}",
33415    );
33416    minify_test(
33417      r#"
33418      @container style(--foo: ) {
33419        .foo {
33420          color: red;
33421        }
33422      }
33423    "#,
33424      "@container style(--foo:){.foo{color:red}}",
33425    );
33426    minify_test(
33427      r#"
33428      @container style(--my-prop: foo - bar ()) {
33429        .foo {
33430          color: red;
33431        }
33432      }
33433    "#,
33434      "@container style(--my-prop:foo - bar ()){.foo{color:red}}",
33435    );
33436    minify_test(
33437      r#"
33438      @container style(--test) {
33439        .foo {
33440          color: red;
33441        }
33442      }
33443    "#,
33444      "@container style(--test){.foo{color:red}}",
33445    );
33446    minify_test(
33447      r#"
33448      @container style(width) {
33449        .foo {
33450          color: red;
33451        }
33452      }
33453    "#,
33454      "@container style(width){.foo{color:red}}",
33455    );
33456    minify_test(
33457      r#"
33458      @container scroll-state(scrollable: top) {
33459        .foo {
33460          color: red;
33461        }
33462      }
33463    "#,
33464      "@container scroll-state(scrollable:top){.foo{color:red}}",
33465    );
33466    minify_test(
33467      r#"
33468      @container scroll-state((stuck: top) and (stuck: left)) {
33469        .foo {
33470          color: red;
33471        }
33472      }
33473    "#,
33474      "@container scroll-state((stuck:top) and (stuck:left)){.foo{color:red}}",
33475    );
33476    minify_test(
33477      r#"
33478      @container scroll-state(not ((scrollable: bottom) and (scrollable: right))) {
33479        .foo {
33480          color: red;
33481        }
33482      }
33483    "#,
33484      "@container scroll-state(not ((scrollable:bottom) and (scrollable:right))){.foo{color:red}}",
33485    );
33486    minify_test(
33487      r#"
33488      @container (scroll-state(scrollable: inline-end)) {
33489        .foo {
33490          color: red;
33491        }
33492      }
33493    "#,
33494      "@container scroll-state(scrollable:inline-end){.foo{color:red}}",
33495    );
33496    minify_test(
33497      r#"
33498      @container not scroll-state(scrollable: top) {
33499        .foo {
33500          color: red;
33501        }
33502      }
33503    "#,
33504      "@container not scroll-state(scrollable:top){.foo{color:red}}",
33505    );
33506
33507    // Disallow 'none', 'not', 'and', 'or' as a `<container-name>`
33508    // https://github.com/w3c/csswg-drafts/issues/7203#issuecomment-1144257312
33509    // https://chromium-review.googlesource.com/c/chromium/src/+/3698402
33510    error_test(
33511      "@container none (width < 100vw) {}",
33512      ParserError::UnexpectedToken(crate::properties::custom::Token::Ident("none".into())),
33513    );
33514
33515    error_test(
33516      "@container and (width < 100vw) {}",
33517      ParserError::UnexpectedToken(crate::properties::custom::Token::Ident("and".into())),
33518    );
33519
33520    error_test(
33521      "@container or (width < 100vw) {}",
33522      ParserError::UnexpectedToken(crate::properties::custom::Token::Ident("or".into())),
33523    );
33524
33525    // Disallow CSS wide keywords as a `<container-name>`
33526    error_test(
33527      "@container revert-layer (width < 100vw) {}",
33528      ParserError::UnexpectedToken(crate::properties::custom::Token::Ident("revert-layer".into())),
33529    );
33530
33531    error_test(
33532      "@container initial (width < 100vw) {}",
33533      ParserError::UnexpectedToken(crate::properties::custom::Token::Ident("initial".into())),
33534    );
33535
33536    // <ident> contains spaces
33537    // https://github.com/web-platform-tests/wpt/blob/39f0da08fbbe33d0582a35749b6dbf8bd067a52d/css/css-contain/container-queries/at-container-parsing.html#L160-L178
33538    error_test(
33539      "@container foo bar (width < 100vw) {}",
33540      ParserError::UnexpectedToken(crate::properties::custom::Token::Ident("bar".into())),
33541    );
33542
33543    error_test("@container (inline-size <= foo) {}", ParserError::InvalidMediaQuery);
33544    error_test("@container (orientation <= 10px) {}", ParserError::InvalidMediaQuery);
33545
33546    error_test(
33547      "@container style(style(--foo: bar)) {}",
33548      ParserError::UnexpectedToken(crate::properties::custom::Token::Function("style".into())),
33549    );
33550    error_test(
33551      "@container scroll-state(scroll-state(scrollable: top)) {}",
33552      ParserError::InvalidMediaQuery,
33553    );
33554    error_test(
33555      "@container unknown(foo) {}",
33556      ParserError::UnexpectedToken(crate::properties::custom::Token::Function("unknown".into())),
33557    );
33558
33559    // empty container (no name and no condition) should error
33560    error_test("@container {}", ParserError::EndOfInput);
33561
33562    // empty brackets should return a clearer error message
33563    error_test("@container () {}", ParserError::EmptyBracketInCondition);
33564
33565    // invalid condition after a name should error
33566    error_test("@container foo () {}", ParserError::EmptyBracketInCondition);
33567    error_test(
33568      "@container foo bar {}",
33569      ParserError::UnexpectedToken(crate::properties::custom::Token::Ident("bar".into())),
33570    );
33571
33572    error_recovery_test("@container unknown(foo) {}");
33573  }
33574
33575  #[test]
33576  fn test_css_modules_value_rule() {
33577    css_modules_error_test(
33578      "@value compact: (max-width: 37.4375em);",
33579      ParserError::DeprecatedCssModulesValueRule,
33580    );
33581  }
33582
33583  #[test]
33584  fn test_unknown_at_rules() {
33585    minify_test("@foo;", "@foo;");
33586    minify_test("@foo bar;", "@foo bar;");
33587    minify_test("@foo (bar: baz);", "@foo (bar: baz);");
33588    test(
33589      r#"@foo test {
33590      div {
33591        color: red;
33592      }
33593    }"#,
33594      indoc! { r#"@foo test {
33595      div {
33596            color: red;
33597          }
33598    }
33599    "#},
33600    );
33601    minify_test(
33602      r#"@foo test {
33603      div {
33604        color: red;
33605      }
33606    }"#,
33607      "@foo test{div { color: red; }}",
33608    );
33609    minify_test(
33610      r#"@foo test {
33611        foo: bar;
33612      }"#,
33613      "@foo test{foo: bar;}",
33614    );
33615    test(
33616      r#"@foo {
33617        foo: bar;
33618      }"#,
33619      indoc! {r#"
33620      @foo {
33621        foo: bar;
33622      }
33623      "#},
33624    );
33625    minify_test(
33626      r#"@foo {
33627        foo: bar;
33628      }"#,
33629      "@foo{foo: bar;}",
33630    );
33631  }
33632
33633  #[test]
33634  fn test_resolution() {
33635    use crate::values::resolution::Resolution;
33636
33637    for source in ["-1dpi", "-1dpcm", "-1dppx", "-1x"] {
33638      non_negative_test::<Resolution>(source, None);
33639      assert!(Resolution::parse_string(source).is_ok());
33640    }
33641    non_negative_test::<Resolution>("0dpi", Some("0dpi"));
33642    non_negative_test::<Resolution>("10dpcm", Some("10dpcm"));
33643
33644    prefix_test(
33645      r#"
33646      @media (resolution: 1dppx) {
33647        body {
33648          background: red;
33649        }
33650      }
33651      "#,
33652      indoc! { r#"
33653      @media (resolution: 1dppx) {
33654        body {
33655          background: red;
33656        }
33657      }
33658      "#},
33659      Browsers {
33660        chrome: Some(50 << 16),
33661        ..Browsers::default()
33662      },
33663    );
33664
33665    prefix_test(
33666      r#"
33667      @media (resolution: 1dppx) {
33668        body {
33669          background: red;
33670        }
33671      }
33672      "#,
33673      indoc! { r#"
33674      @media (resolution: 1x) {
33675        body {
33676          background: red;
33677        }
33678      }
33679      "#},
33680      Browsers {
33681        chrome: Some(95 << 16),
33682        ..Browsers::default()
33683      },
33684    );
33685  }
33686
33687  #[test]
33688  fn test_environment() {
33689    minify_test(
33690      r#"
33691      @media (max-width: env(--branding-small)) {
33692        body {
33693          padding: env(--branding-padding);
33694        }
33695      }
33696    "#,
33697      "@media (width<=env(--branding-small)){body{padding:env(--branding-padding)}}",
33698    );
33699
33700    minify_test(
33701      r#"
33702      @media (max-width: env(--branding-small 1)) {
33703        body {
33704          padding: env(--branding-padding 2);
33705        }
33706      }
33707    "#,
33708      "@media (width<=env(--branding-small 1)){body{padding:env(--branding-padding 2)}}",
33709    );
33710
33711    minify_test(
33712      r#"
33713      @media (max-width: env(--branding-small 1, 20px)) {
33714        body {
33715          padding: env(--branding-padding 2, 20px);
33716        }
33717      }
33718    "#,
33719      "@media (width<=env(--branding-small 1,20px)){body{padding:env(--branding-padding 2,20px)}}",
33720    );
33721
33722    minify_test(
33723      r#"
33724      @media (max-width: env(safe-area-inset-top)) {
33725        body {
33726          padding: env(safe-area-inset-top);
33727        }
33728      }
33729    "#,
33730      "@media (width<=env(safe-area-inset-top)){body{padding:env(safe-area-inset-top)}}",
33731    );
33732
33733    minify_test(
33734      r#"
33735      @media (max-width: env(unknown)) {
33736        body {
33737          padding: env(unknown);
33738        }
33739      }
33740    "#,
33741      "@media (width<=env(unknown)){body{padding:env(unknown)}}",
33742    );
33743
33744    prefix_test(
33745      r#"
33746      .foo {
33747        color: env(--brand-color, color(display-p3 0 1 0));
33748      }
33749    "#,
33750      indoc! {r#"
33751      .foo {
33752        color: env(--brand-color, #00fb29);
33753      }
33754
33755      @supports (color: color(display-p3 0 0 0)) {
33756        .foo {
33757          color: env(--brand-color, color(display-p3 0 1 0));
33758        }
33759      }
33760    "#},
33761      Browsers {
33762        safari: Some(15 << 16),
33763        chrome: Some(90 << 16),
33764        ..Browsers::default()
33765      },
33766    );
33767
33768    prefix_test(
33769      r#"
33770      @supports (color: color(display-p3 0 0 0)) {
33771        .foo {
33772          color: env(--brand-color, color(display-p3 0 1 0));
33773        }
33774      }
33775    "#,
33776      indoc! {r#"
33777      @supports (color: color(display-p3 0 0 0)) {
33778        .foo {
33779          color: env(--brand-color, color(display-p3 0 1 0));
33780        }
33781      }
33782    "#},
33783      Browsers {
33784        safari: Some(15 << 16),
33785        chrome: Some(90 << 16),
33786        ..Browsers::default()
33787      },
33788    );
33789
33790    css_modules_test(
33791      r#"
33792      @media (max-width: env(--branding-small)) {
33793        .foo {
33794          color: env(--brand-color);
33795        }
33796      }
33797    "#,
33798      indoc! {r#"
33799      @media (width <= env(--EgL3uq_branding-small)) {
33800        .EgL3uq_foo {
33801          color: env(--EgL3uq_brand-color);
33802        }
33803      }
33804    "#},
33805      map! {
33806        "foo" => "EgL3uq_foo",
33807        "--brand-color" => "--EgL3uq_brand-color" referenced: true,
33808        "--branding-small" => "--EgL3uq_branding-small" referenced: true
33809      },
33810      IndexMap::new(),
33811      crate::css_modules::Config {
33812        dashed_idents: true,
33813        ..Default::default()
33814      },
33815      false,
33816    );
33817  }
33818
33819  #[test]
33820  fn test_license_comments() {
33821    minify_test(
33822      r#"
33823      /*! Copyright 2023 Someone awesome */
33824      /* Some other comment */
33825      .foo {
33826        color: red;
33827      }
33828    "#,
33829      indoc! {r#"
33830      /*! Copyright 2023 Someone awesome */
33831      .foo{color:red}"#},
33832    );
33833
33834    minify_test(
33835      r#"
33836      /*! Copyright 2023 Someone awesome */
33837      /*! Copyright 2023 Someone else */
33838      .foo {
33839        color: red;
33840      }
33841    "#,
33842      indoc! {r#"
33843      /*! Copyright 2023 Someone awesome */
33844      /*! Copyright 2023 Someone else */
33845      .foo{color:red}"#},
33846    );
33847  }
33848
33849  #[test]
33850  fn test_starting_style() {
33851    minify_test(
33852      r#"
33853      @starting-style {
33854        h1 {
33855          background: yellow;
33856        }
33857      }
33858      "#,
33859      "@starting-style{h1{background:#ff0}}",
33860    );
33861    minify_test("@starting-style {}", "");
33862
33863    nesting_test(
33864      r#"
33865      h1 {
33866        background: red;
33867        @starting-style {
33868          background: yellow;
33869        }
33870      }
33871      "#,
33872      indoc! {r#"
33873      h1 {
33874        background: red;
33875      }
33876
33877      @starting-style {
33878        h1 {
33879          background: #ff0;
33880        }
33881      }
33882      "#},
33883    );
33884  }
33885
33886  #[test]
33887  fn test_color_scheme() {
33888    minify_test(".foo { color-scheme: normal; }", ".foo{color-scheme:normal}");
33889    minify_test(".foo { color-scheme: light; }", ".foo{color-scheme:light}");
33890    minify_test(".foo { color-scheme: dark; }", ".foo{color-scheme:dark}");
33891    minify_test(".foo { color-scheme: light dark; }", ".foo{color-scheme:light dark}");
33892    minify_test(".foo { color-scheme: dark light; }", ".foo{color-scheme:light dark}");
33893    minify_test(".foo { color-scheme: only light; }", ".foo{color-scheme:light only}");
33894    minify_test(".foo { color-scheme: only dark; }", ".foo{color-scheme:dark only}");
33895    minify_test(".foo { color-scheme: inherit; }", ".foo{color-scheme:inherit}");
33896    minify_test(":root { color-scheme: unset; }", ":root{color-scheme:unset}");
33897    minify_test(".foo { color-scheme: unknow; }", ".foo{color-scheme:unknow}");
33898    minify_test(".foo { color-scheme: only; }", ".foo{color-scheme:only}");
33899    minify_test(".foo { color-scheme: dark foo; }", ".foo{color-scheme:dark foo}");
33900    minify_test(".foo { color-scheme: normal dark; }", ".foo{color-scheme:normal dark}");
33901    minify_test(
33902      ".foo { color-scheme: dark light only; }",
33903      ".foo{color-scheme:light dark only}",
33904    );
33905    minify_test(
33906      ".foo { color-scheme: foo bar light; }",
33907      ".foo{color-scheme:foo bar light}",
33908    );
33909    minify_test(
33910      ".foo { color-scheme: only foo dark bar; }",
33911      ".foo{color-scheme:only foo dark bar}",
33912    );
33913    prefix_test(
33914      ".foo { color-scheme: dark; }",
33915      indoc! { r#"
33916      .foo {
33917        --lightningcss-light: ;
33918        --lightningcss-dark: initial;
33919        color-scheme: dark;
33920      }
33921      "#},
33922      Browsers {
33923        chrome: Some(90 << 16),
33924        ..Browsers::default()
33925      },
33926    );
33927    prefix_test(
33928      ".foo { color-scheme: light; }",
33929      indoc! { r#"
33930      .foo {
33931        --lightningcss-light: initial;
33932        --lightningcss-dark: ;
33933        color-scheme: light;
33934      }
33935      "#},
33936      Browsers {
33937        chrome: Some(90 << 16),
33938        ..Browsers::default()
33939      },
33940    );
33941    prefix_test(
33942      ".foo { color-scheme: light dark; }",
33943      indoc! { r#"
33944      .foo {
33945        --lightningcss-light: initial;
33946        --lightningcss-dark: ;
33947        color-scheme: light dark;
33948      }
33949
33950      @media (prefers-color-scheme: dark) {
33951        .foo {
33952          --lightningcss-light: ;
33953          --lightningcss-dark: initial;
33954        }
33955      }
33956      "#},
33957      Browsers {
33958        chrome: Some(90 << 16),
33959        ..Browsers::default()
33960      },
33961    );
33962    prefix_test(
33963      ".foo { color-scheme: light dark; }",
33964      indoc! { r#"
33965      .foo {
33966        color-scheme: light dark;
33967      }
33968      "#},
33969      Browsers {
33970        firefox: Some(120 << 16),
33971        ..Browsers::default()
33972      },
33973    );
33974
33975    minify_test(
33976      ".foo { color: light-dark(yellow, red); }",
33977      ".foo{color:light-dark(#ff0,red)}",
33978    );
33979    minify_test(
33980      ".foo { color: light-dark(light-dark(yellow, red), light-dark(yellow, red)); }",
33981      ".foo{color:light-dark(#ff0,red)}",
33982    );
33983    minify_test(
33984      ".foo { color: light-dark(rgb(0, 0, 255), hsl(120deg, 50%, 50%)); }",
33985      ".foo{color:light-dark(#00f,#40bf40)}",
33986    );
33987    prefix_test(
33988      ".foo { color: light-dark(oklch(40% 0.1268735435 34.568626), oklab(59.686% 0.1009 0.1192)); }",
33989      indoc! { r#"
33990      .foo {
33991        color: var(--lightningcss-light, #7e250f) var(--lightningcss-dark, #c65d07);
33992        color: var(--lightningcss-light, lab(29.2661% 38.2437 35.3889)) var(--lightningcss-dark, lab(52.2319% 40.1449 59.9171));
33993      }
33994      "#},
33995      Browsers {
33996        chrome: Some(90 << 16),
33997        ..Browsers::default()
33998      },
33999    );
34000    prefix_test(
34001      ".foo { color: light-dark(oklch(40% 0.1268735435 34.568626), oklab(59.686% 0.1009 0.1192)); }",
34002      indoc! { r#"
34003      .foo {
34004        color: light-dark(oklch(40% .126874 34.5686), oklab(59.686% .1009 .1192));
34005      }
34006      "#},
34007      Browsers {
34008        firefox: Some(120 << 16),
34009        ..Browsers::default()
34010      },
34011    );
34012    prefix_test(
34013      r#"
34014      .foo {
34015        box-shadow:
34016            oklch(100% 0 0deg / 50%) 0 0.63rem 0.94rem -0.19rem,
34017            currentColor 0 0.44rem 0.8rem -0.58rem;
34018      }
34019    "#,
34020      indoc! { r#"
34021      .foo {
34022        box-shadow: 0 .63rem .94rem -.19rem #ffffff80, 0 .44rem .8rem -.58rem;
34023        box-shadow: 0 .63rem .94rem -.19rem lab(100% 0 0 / .5), 0 .44rem .8rem -.58rem;
34024      }
34025      "#},
34026      Browsers {
34027        chrome: Some(95 << 16),
34028        ..Browsers::default()
34029      },
34030    );
34031    prefix_test(
34032      r#"
34033      .foo {
34034        box-shadow:
34035            oklch(100% 0 0deg / 50%) 0 0.63rem 0.94rem -0.19rem,
34036            currentColor 0 0.44rem 0.8rem -0.58rem;
34037      }
34038    "#,
34039      indoc! { r#"
34040      .foo {
34041        box-shadow: 0 .63rem .94rem -.19rem color(display-p3 1 1 1 / .5), 0 .44rem .8rem -.58rem;
34042        box-shadow: 0 .63rem .94rem -.19rem lab(100% 0 0 / .5), 0 .44rem .8rem -.58rem;
34043      }
34044      "#},
34045      Browsers {
34046        safari: Some(14 << 16),
34047        ..Browsers::default()
34048      },
34049    );
34050
34051    prefix_test(
34052      ".foo { color: light-dark(var(--light), var(--dark)); }",
34053      indoc! { r#"
34054      .foo {
34055        color: var(--lightningcss-light, var(--light)) var(--lightningcss-dark, var(--dark));
34056      }
34057      "#},
34058      Browsers {
34059        chrome: Some(90 << 16),
34060        ..Browsers::default()
34061      },
34062    );
34063    prefix_test(
34064      ".foo { color: rgb(from light-dark(yellow, red) r g b / 10%); }",
34065      indoc! { r#"
34066      .foo {
34067        color: var(--lightningcss-light, #ffff001a) var(--lightningcss-dark, #ff00001a);
34068      }
34069      "#},
34070      Browsers {
34071        chrome: Some(90 << 16),
34072        ..Browsers::default()
34073      },
34074    );
34075    prefix_test(
34076      ".foo { color: alpha(from light-dark(yellow, red) / 10%); }",
34077      indoc! { r#"
34078      .foo {
34079        color: var(--lightningcss-light, #ffff001a) var(--lightningcss-dark, #ff00001a);
34080      }
34081      "#},
34082      Browsers {
34083        chrome: Some(90 << 16),
34084        ..Browsers::default()
34085      },
34086    );
34087    prefix_test(
34088      ".foo { color: rgb(from light-dark(yellow, red) r g b / var(--alpha)); }",
34089      indoc! { r#"
34090      .foo {
34091        color: var(--lightningcss-light, rgb(255 255 0 / var(--alpha))) var(--lightningcss-dark, rgb(255 0 0 / var(--alpha)));
34092      }
34093      "#},
34094      Browsers {
34095        chrome: Some(90 << 16),
34096        ..Browsers::default()
34097      },
34098    );
34099    prefix_test(
34100      ".foo { color: color(from light-dark(yellow, red) srgb r g b / 10%); }",
34101      indoc! { r#"
34102      .foo {
34103        color: var(--lightningcss-light, #ffff001a) var(--lightningcss-dark, #ff00001a);
34104        color: var(--lightningcss-light, color(srgb 1 1 0 / .1)) var(--lightningcss-dark, color(srgb 1 0 0 / .1));
34105      }
34106      "#},
34107      Browsers {
34108        chrome: Some(90 << 16),
34109        ..Browsers::default()
34110      },
34111    );
34112    prefix_test(
34113      ".foo { color: color-mix(in srgb, light-dark(yellow, red), light-dark(red, pink)); }",
34114      indoc! { r#"
34115      .foo {
34116        color: var(--lightningcss-light, #ff8000) var(--lightningcss-dark, #ff6066);
34117      }
34118      "#},
34119      Browsers {
34120        chrome: Some(90 << 16),
34121        ..Browsers::default()
34122      },
34123    );
34124    nesting_test_with_targets(
34125      r#"
34126        .foo { color-scheme: light; }
34127        .bar { color: light-dark(red, green); }
34128      "#,
34129      indoc! {r#"
34130        .foo {
34131          color-scheme: light;
34132        }
34133
34134        .bar {
34135          color: light-dark(red, green);
34136        }
34137      "#},
34138      Targets {
34139        browsers: Some(Browsers {
34140          safari: Some(13 << 16),
34141          ..Browsers::default()
34142        }),
34143        include: Features::empty(),
34144        exclude: Features::LightDark,
34145      },
34146    );
34147  }
34148
34149  #[test]
34150  fn test_print_color_adjust() {
34151    prefix_test(
34152      ".foo { print-color-adjust: exact; }",
34153      indoc! { r#"
34154      .foo {
34155        -webkit-print-color-adjust: exact;
34156        print-color-adjust: exact;
34157      }
34158      "#},
34159      Browsers {
34160        chrome: Some(135 << 16),
34161        ..Browsers::default()
34162      },
34163    );
34164    prefix_test(
34165      ".foo { print-color-adjust: exact; }",
34166      indoc! { r#"
34167      .foo {
34168        print-color-adjust: exact;
34169      }
34170      "#},
34171      Browsers {
34172        chrome: Some(137 << 16),
34173        ..Browsers::default()
34174      },
34175    );
34176  }
34177
34178  #[test]
34179  fn test_all() {
34180    minify_test(".foo { all: initial; all: initial }", ".foo{all:initial}");
34181    minify_test(".foo { all: initial; all: revert }", ".foo{all:revert}");
34182    minify_test(".foo { background: red; all: revert-layer }", ".foo{all:revert-layer}");
34183    minify_test(
34184      ".foo { background: red; all: revert-layer; background: green }",
34185      ".foo{all:revert-layer;background:green}",
34186    );
34187    minify_test(
34188      ".foo { --test: red; all: revert-layer }",
34189      ".foo{--test:red;all:revert-layer}",
34190    );
34191    minify_test(
34192      ".foo { unicode-bidi: embed; all: revert-layer }",
34193      ".foo{all:revert-layer;unicode-bidi:embed}",
34194    );
34195    minify_test(
34196      ".foo { direction: rtl; all: revert-layer }",
34197      ".foo{all:revert-layer;direction:rtl}",
34198    );
34199    minify_test(
34200      ".foo { direction: rtl; all: revert-layer; direction: ltr }",
34201      ".foo{all:revert-layer;direction:ltr}",
34202    );
34203    minify_test(".foo { background: var(--foo); all: unset; }", ".foo{all:unset}");
34204    minify_test(
34205      ".foo { all: unset; background: var(--foo); }",
34206      ".foo{all:unset;background:var(--foo)}",
34207    );
34208    minify_test(
34209      ".foo {--bar:currentcolor; --foo:1.1em; all:unset}",
34210      ".foo{--bar:currentcolor;--foo:1.1em;all:unset}",
34211    );
34212  }
34213
34214  #[test]
34215  fn test_view_transition() {
34216    minify_test(
34217      "@view-transition { navigation: auto }",
34218      "@view-transition{navigation:auto}",
34219    );
34220    minify_test(
34221      "@view-transition { navigation: auto; types: none; }",
34222      "@view-transition{navigation:auto;types:none}",
34223    );
34224    minify_test(
34225      "@view-transition { navigation: auto; types: foo bar; }",
34226      "@view-transition{navigation:auto;types:foo bar}",
34227    );
34228    minify_test(
34229      "@layer { @view-transition { navigation: auto; types: foo bar; } }",
34230      "@layer{@view-transition{navigation:auto;types:foo bar}}",
34231    );
34232  }
34233
34234  #[test]
34235  fn test_skip_generating_unnecessary_fallbacks() {
34236    prefix_test(
34237      r#"
34238      @supports (color: lab(0% 0 0)) and (color: color(display-p3 0 0 0)) {
34239        .foo {
34240          color: lab(40% 56.6 39);
34241        }
34242
34243        .bar {
34244          color: color(display-p3 .643308 .192455 .167712);
34245        }
34246      }
34247      "#,
34248      indoc! {r#"
34249      @supports (color: lab(0% 0 0)) and (color: color(display-p3 0 0 0)) {
34250        .foo {
34251          color: lab(40% 56.6 39);
34252        }
34253
34254        .bar {
34255          color: color(display-p3 .643308 .192455 .167712);
34256        }
34257      }
34258      "#},
34259      Browsers {
34260        chrome: Some(4 << 16),
34261        ..Browsers::default()
34262      },
34263    );
34264
34265    prefix_test(
34266      r#"
34267      @supports (color: lab(40% 56.6 39)) {
34268        .foo {
34269          color: lab(40% 56.6 39);
34270        }
34271      }
34272      "#,
34273      indoc! {r#"
34274      @supports (color: lab(40% 56.6 39)) {
34275        .foo {
34276          color: lab(40% 56.6 39);
34277        }
34278      }
34279      "#},
34280      Browsers {
34281        chrome: Some(4 << 16),
34282        ..Browsers::default()
34283      },
34284    );
34285
34286    prefix_test(
34287      r#"
34288      @supports (background-color: lab(40% 56.6 39)) {
34289        .foo {
34290          background-color: lab(40% 56.6 39);
34291        }
34292      }
34293      "#,
34294      indoc! {r#"
34295      @supports (background-color: lab(40% 56.6 39)) {
34296        .foo {
34297          background-color: lab(40% 56.6 39);
34298        }
34299      }
34300      "#},
34301      Browsers {
34302        chrome: Some(4 << 16),
34303        ..Browsers::default()
34304      },
34305    );
34306
34307    prefix_test(
34308      r#"
34309      @supports (color: light-dark(#f00, #00f)) {
34310        .foo {
34311          color: light-dark(#ff0, #0ff);
34312        }
34313      }
34314      "#,
34315      indoc! {r#"
34316      @supports (color: light-dark(#f00, #00f)) {
34317        .foo {
34318          color: light-dark(#ff0, #0ff);
34319        }
34320      }
34321      "#},
34322      Browsers {
34323        chrome: Some(4 << 16),
34324        ..Browsers::default()
34325      },
34326    );
34327
34328    // NOTE: fallback for lab is not necessary
34329    prefix_test(
34330      r#"
34331      @supports (color: lab(0% 0 0)) and (not (color: color(display-p3 0 0 0))) {
34332        .foo {
34333          color: lab(40% 56.6 39);
34334        }
34335
34336        .bar {
34337          color: color(display-p3 .643308 .192455 .167712);
34338        }
34339      }
34340      "#,
34341      indoc! {r#"
34342      @supports (color: lab(0% 0 0)) and (not (color: color(display-p3 0 0 0))) {
34343        .foo {
34344          color: #b32323;
34345          color: lab(40% 56.6 39);
34346        }
34347
34348        .bar {
34349          color: #b32323;
34350          color: color(display-p3 .643308 .192455 .167712);
34351        }
34352      }
34353      "#},
34354      Browsers {
34355        chrome: Some(4 << 16),
34356        ..Browsers::default()
34357      },
34358    );
34359
34360    prefix_test(
34361      r#"
34362      @supports (color: lab(0% 0 0)) or (color: color(display-p3 0 0 0)) {
34363        .foo {
34364          color: lab(40% 56.6 39);
34365        }
34366
34367        .bar {
34368          color: color(display-p3 .643308 .192455 .167712);
34369        }
34370      }
34371      "#,
34372      indoc! {r#"
34373      @supports (color: lab(0% 0 0)) or (color: color(display-p3 0 0 0)) {
34374        .foo {
34375          color: #b32323;
34376          color: lab(40% 56.6 39);
34377        }
34378
34379        .bar {
34380          color: #b32323;
34381          color: color(display-p3 .643308 .192455 .167712);
34382        }
34383      }
34384      "#},
34385      Browsers {
34386        chrome: Some(4 << 16),
34387        ..Browsers::default()
34388      },
34389    );
34390  }
34391}