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  #[cfg(feature = "custom_sourcemap")]
60  use crate::printer::{OriginalLocation, SourceMap};
61  use crate::properties::custom::Token;
62  use crate::properties::Property;
63  use crate::rules::CssRule;
64  use crate::rules::Location;
65  use crate::stylesheet::*;
66  use crate::targets::{Browsers, Features, Targets};
67  use crate::test_helpers::panic_with_test_error;
68  use crate::traits::{Parse, ToCss};
69  use crate::values::color::CssColor;
70  use crate::vendor_prefix::VendorPrefix;
71  use cssparser::SourceLocation;
72  use indexmap::IndexMap;
73  use indoc::indoc;
74  use pretty_assertions::assert_eq;
75  use std::collections::HashMap;
76  use std::sync::{Arc, RwLock};
77
78  #[track_caller]
79  fn test(source: &str, expected: &str) {
80    test_with_options(source, expected, ParserOptions::default())
81  }
82
83  #[track_caller]
84  fn non_negative_test<'i, T: crate::traits::ParseNumeric<'i> + ToCss>(source: &'i str, expected: Option<&str>) {
85    use crate::values::number::NonNegative;
86
87    let result = NonNegative::<T>::parse_string(source);
88    match expected {
89      Some(expected) => {
90        let value = result.unwrap();
91        assert_eq!(
92          value.to_css_string(PrinterOptions::default()).unwrap(),
93          expected,
94          "{}",
95          source
96        );
97      }
98      None => assert!(result.is_err(), "expected {} to be invalid", source),
99    }
100  }
101
102  // Invalid known properties are preserved as unparsed declarations for browser validation.
103  #[track_caller]
104  fn property_range_test(names: &[&str], cases: &[(&str, Option<&str>)]) {
105    for name in names {
106      for (source, expected) in cases {
107        let value = Property::parse_string((*name).into(), source, ParserOptions::default()).unwrap();
108        if let Some(expected) = expected {
109          assert!(
110            !matches!(value, Property::Unparsed(_) | Property::Custom(_)),
111            "{name}: {source}"
112          );
113          assert_eq!(
114            value
115              .value_to_css_string(PrinterOptions {
116                minify: true,
117                ..PrinterOptions::default()
118              })
119              .unwrap(),
120            *expected,
121            "{name}: {source}"
122          );
123        } else {
124          assert!(
125            matches!(value, Property::Unparsed(_)),
126            "expected {name}: {source} to be invalid, got {value:?}"
127          );
128        }
129      }
130    }
131  }
132
133  #[track_caller]
134  fn test_with_options<'i>(source: &'i str, expected: &'i str, options: ParserOptions<'i>) {
135    let mut stylesheet = match StyleSheet::parse(&source, options) {
136      Ok(stylesheet) => stylesheet,
137      Err(e) => panic_with_test_error("test_with_options", "parse", source, e),
138    };
139    if let Err(e) = stylesheet.minify(MinifyOptions::default()) {
140      panic_with_test_error("test_with_options", "minify", source, e);
141    }
142    let res = match stylesheet.to_css(PrinterOptions::default()) {
143      Ok(res) => res,
144      Err(e) => panic_with_test_error("test_with_options", "print", source, e),
145    };
146    assert_eq!(res.code, expected);
147  }
148
149  #[track_caller]
150  fn test_with_printer_options<'i>(source: &'i str, expected: &'i str, options: PrinterOptions<'i>) {
151    let mut stylesheet = match StyleSheet::parse(&source, ParserOptions::default()) {
152      Ok(stylesheet) => stylesheet,
153      Err(e) => panic_with_test_error("test_with_printer_options", "parse", source, e),
154    };
155    if let Err(e) = stylesheet.minify(MinifyOptions::default()) {
156      panic_with_test_error("test_with_printer_options", "minify", source, e);
157    }
158    let res = match stylesheet.to_css(options) {
159      Ok(res) => res,
160      Err(e) => panic_with_test_error("test_with_printer_options", "print", source, e),
161    };
162    assert_eq!(res.code, expected);
163  }
164
165  #[track_caller]
166  fn minify_test(source: &str, expected: &str) {
167    minify_test_with_options(source, expected, ParserOptions::default())
168  }
169
170  #[track_caller]
171  fn minify_test_with_options<'i>(source: &'i str, expected: &'i str, options: ParserOptions<'i>) {
172    minify_test_with_options_and_browsers(source, expected, options, None)
173  }
174
175  #[track_caller]
176  fn minify_test_with_options_and_browsers<'i>(
177    source: &'i str,
178    expected: &'i str,
179    options: ParserOptions<'i>,
180    browsers: Option<Browsers>,
181  ) {
182    let targets = browsers.into();
183    let mut stylesheet = match StyleSheet::parse(&source, options) {
184      Ok(stylesheet) => stylesheet,
185      Err(e) => panic_with_test_error("minify_test_with_options", "parse", source, e),
186    };
187    if let Err(e) = stylesheet.minify(MinifyOptions {
188      targets,
189      ..MinifyOptions::default()
190    }) {
191      panic_with_test_error("minify_test_with_options", "minify", source, e);
192    }
193    let res = match stylesheet.to_css(PrinterOptions {
194      minify: true,
195      targets,
196      ..PrinterOptions::default()
197    }) {
198      Ok(res) => res,
199      Err(e) => panic_with_test_error("minify_test_with_options", "print", source, e),
200    };
201    assert_eq!(res.code, expected);
202  }
203
204  #[track_caller]
205  fn minify_error_test_with_options<'i>(source: &'i str, error: MinifyErrorKind, options: ParserOptions<'i>) {
206    let mut stylesheet = match StyleSheet::parse(&source, options) {
207      Ok(stylesheet) => stylesheet,
208      Err(e) => panic_with_test_error("minify_error_test_with_options", "parse", source, e),
209    };
210    match stylesheet.minify(MinifyOptions::default()) {
211      Err(e) => assert_eq!(e.kind, error),
212      Ok(()) => panic!(
213        "minify_error_test_with_options: expected minify error {:?}, but minification succeeded.\nsource:\n{source}",
214        error
215      ),
216    }
217  }
218
219  #[track_caller]
220  fn prefix_test(source: &str, expected: &str, targets: Browsers) {
221    let mut stylesheet = match StyleSheet::parse(&source, ParserOptions::default()) {
222      Ok(stylesheet) => stylesheet,
223      Err(e) => panic_with_test_error("prefix_test", "parse", source, e),
224    };
225    if let Err(e) = stylesheet.minify(MinifyOptions {
226      targets: targets.into(),
227      ..MinifyOptions::default()
228    }) {
229      panic_with_test_error("prefix_test", "minify", source, e);
230    }
231    let res = match stylesheet.to_css(PrinterOptions {
232      targets: targets.into(),
233      ..PrinterOptions::default()
234    }) {
235      Ok(res) => res,
236      Err(e) => panic_with_test_error("prefix_test", "print", source, e),
237    };
238    assert_eq!(res.code, expected);
239  }
240
241  #[track_caller]
242  fn attr_test(source: &str, expected: &str, minify: bool, targets: Option<Browsers>) {
243    let mut attr = match StyleAttribute::parse(source, ParserOptions::default()) {
244      Ok(attr) => attr,
245      Err(e) => panic_with_test_error("attr_test", "parse", source, e),
246    };
247    attr.minify(MinifyOptions {
248      targets: targets.into(),
249      ..MinifyOptions::default()
250    });
251    let res = match attr.to_css(PrinterOptions {
252      targets: targets.into(),
253      minify,
254      ..PrinterOptions::default()
255    }) {
256      Ok(res) => res,
257      Err(e) => panic_with_test_error("attr_test", "print", source, e),
258    };
259    assert_eq!(res.code, expected);
260  }
261
262  #[track_caller]
263  fn nesting_test(source: &str, expected: &str) {
264    nesting_test_with_targets(
265      source,
266      expected,
267      Browsers {
268        chrome: Some(95 << 16),
269        ..Browsers::default()
270      }
271      .into(),
272    );
273  }
274
275  #[track_caller]
276  fn nesting_test_with_targets(source: &str, expected: &str, targets: Targets) {
277    let mut stylesheet = match StyleSheet::parse(&source, ParserOptions::default()) {
278      Ok(stylesheet) => stylesheet,
279      Err(e) => panic_with_test_error("nesting_test_with_targets", "parse", source, e),
280    };
281    if let Err(e) = stylesheet.minify(MinifyOptions {
282      targets,
283      ..MinifyOptions::default()
284    }) {
285      panic_with_test_error("nesting_test_with_targets", "minify", source, e);
286    }
287    let res = match stylesheet.to_css(PrinterOptions {
288      targets,
289      ..PrinterOptions::default()
290    }) {
291      Ok(res) => res,
292      Err(e) => panic_with_test_error("nesting_test_with_targets", "print", source, e),
293    };
294    assert_eq!(res.code, expected);
295  }
296
297  #[track_caller]
298  fn nesting_test_no_targets(source: &str, expected: &str) {
299    let mut stylesheet = match StyleSheet::parse(&source, ParserOptions::default()) {
300      Ok(stylesheet) => stylesheet,
301      Err(e) => panic_with_test_error("nesting_test_no_targets", "parse", source, e),
302    };
303    if let Err(e) = stylesheet.minify(MinifyOptions::default()) {
304      panic_with_test_error("nesting_test_no_targets", "minify", source, e);
305    }
306    let res = match stylesheet.to_css(PrinterOptions::default()) {
307      Ok(res) => res,
308      Err(e) => panic_with_test_error("nesting_test_no_targets", "print", source, e),
309    };
310    assert_eq!(res.code, expected);
311  }
312
313  #[test]
314  fn test_css_module_order() {
315    // Exports and references are in source order, which determines e.g. dependency order.
316    let mut stylesheet = StyleSheet::parse(
317      r#"
318      .zebra { color: var(--z from "./z.css"); }
319      .apple { color: var(--a from "./a.css"); }
320      .mango { composes: m from "./m.css"; }
321    "#,
322      ParserOptions {
323        filename: "test.css".into(),
324        css_modules: Some(crate::css_modules::Config {
325          dashed_idents: true,
326          ..Default::default()
327        }),
328        ..ParserOptions::default()
329      },
330    )
331    .unwrap();
332    stylesheet.minify(MinifyOptions::default()).unwrap();
333    let res = stylesheet.to_css(PrinterOptions::default()).unwrap();
334    let exports: Vec<String> = res.exports.unwrap().into_keys().collect();
335    assert_eq!(exports, ["zebra", "apple", "mango"]);
336    let references: Vec<String> = res
337      .references
338      .unwrap()
339      .into_values()
340      .map(|reference| match reference {
341        CssModuleReference::Dependency { specifier, .. } => specifier,
342        _ => unreachable!(),
343      })
344      .collect();
345    assert_eq!(references, ["./z.css", "./a.css"]);
346  }
347
348  #[track_caller]
349  fn css_modules_test<'i>(
350    source: &'i str,
351    expected: &str,
352    expected_exports: CssModuleExports,
353    expected_references: CssModuleReferences,
354    config: crate::css_modules::Config,
355    minify: bool,
356  ) {
357    let mut stylesheet = match StyleSheet::parse(
358      &source,
359      ParserOptions {
360        filename: "test.css".into(),
361        css_modules: Some(config),
362        ..ParserOptions::default()
363      },
364    ) {
365      Ok(stylesheet) => stylesheet,
366      Err(e) => panic_with_test_error("css_modules_test", "parse", source, e),
367    };
368    if let Err(e) = stylesheet.minify(MinifyOptions::default()) {
369      panic_with_test_error("css_modules_test", "minify", source, e);
370    }
371    let res = match stylesheet.to_css(PrinterOptions {
372      minify,
373      ..Default::default()
374    }) {
375      Ok(res) => res,
376      Err(e) => panic_with_test_error("css_modules_test", "print", source, e),
377    };
378    assert_eq!(res.code, expected);
379    match res.exports {
380      Some(exports) => assert_eq!(exports, expected_exports),
381      None => panic!("css_modules_test: expected CSS module exports, but got None.\nsource:\n{source}"),
382    }
383    match res.references {
384      Some(references) => assert_eq!(references, expected_references),
385      None => panic!("css_modules_test: expected CSS module references, but got None.\nsource:\n{source}"),
386    }
387  }
388
389  #[track_caller]
390  fn custom_media_test(source: &str, expected: &str) {
391    let mut stylesheet = match StyleSheet::parse(
392      &source,
393      ParserOptions {
394        flags: ParserFlags::CUSTOM_MEDIA,
395        ..ParserOptions::default()
396      },
397    ) {
398      Ok(stylesheet) => stylesheet,
399      Err(e) => panic_with_test_error("custom_media_test", "parse", source, e),
400    };
401    if let Err(e) = stylesheet.minify(MinifyOptions {
402      targets: Browsers {
403        chrome: Some(95 << 16),
404        ..Browsers::default()
405      }
406      .into(),
407      ..MinifyOptions::default()
408    }) {
409      panic_with_test_error("custom_media_test", "minify", source, e);
410    }
411    let res = match stylesheet.to_css(PrinterOptions::default()) {
412      Ok(res) => res,
413      Err(e) => panic_with_test_error("custom_media_test", "print", source, e),
414    };
415    assert_eq!(res.code, expected);
416  }
417
418  fn error_test(source: &str, error: ParserError) {
419    let res = StyleSheet::parse(&source, ParserOptions::default());
420    match res {
421      Ok(_) => unreachable!(),
422      Err(e) => assert_eq!(e.kind, error),
423    }
424  }
425
426  fn error_test_with_options<'i>(source: &'i str, error: ParserError<'i>, options: ParserOptions<'i>) {
427    let res = StyleSheet::parse(&source, options);
428    match res {
429      Ok(_) => unreachable!(),
430      Err(e) => assert_eq!(e.kind, error),
431    }
432  }
433
434  fn error_recovery_test(source: &str) -> Vec<Error<ParserError<'_>>> {
435    let warnings = Arc::new(RwLock::default());
436    {
437      let res = StyleSheet::parse(
438        &source,
439        ParserOptions {
440          error_recovery: true,
441          warnings: Some(warnings.clone()),
442          ..Default::default()
443        },
444      );
445      match res {
446        Ok(..) => {}
447        Err(e) => unreachable!("parser error should be recovered, but got {e:?}"),
448      }
449    }
450    let warnings = match Arc::into_inner(warnings) {
451      Some(warnings) => warnings,
452      None => panic!("error_recovery_test: expected a single Arc owner for warnings"),
453    };
454    match warnings.into_inner() {
455      Ok(warnings) => warnings,
456      Err(e) => panic!("error_recovery_test: warnings lock is poisoned: {e}"),
457    }
458  }
459
460  fn css_modules_error_test(source: &str, error: ParserError) {
461    let res = StyleSheet::parse(
462      &source,
463      ParserOptions {
464        css_modules: Some(Default::default()),
465        ..Default::default()
466      },
467    );
468    match res {
469      Ok(_) => unreachable!(),
470      Err(e) => assert_eq!(e.kind, error),
471    }
472  }
473
474  macro_rules! map(
475    { $($key:expr => $name:literal $(referenced: $referenced: literal)? $($value:literal $(global: $global: literal)? $(from $from:literal)?)*),* } => {
476      {
477        #[allow(unused_mut)]
478        let mut m = IndexMap::new();
479        $(
480          #[allow(unused_mut)]
481          let mut v = Vec::new();
482          #[allow(unused_macros)]
483          macro_rules! insert {
484            ($local:literal from $specifier:literal) => {
485              v.push(CssModuleReference::Dependency {
486                name: $local.into(),
487                specifier: $specifier.into()
488              });
489            };
490            ($local:literal global: $is_global: literal) => {
491              v.push(CssModuleReference::Global {
492                name: $local.into()
493              });
494            };
495            ($local:literal) => {
496              v.push(CssModuleReference::Local {
497                name: $local.into()
498              });
499            };
500          }
501          $(
502            insert!($value $(global: $global)? $(from $from)?);
503          )*
504
505          macro_rules! is_referenced {
506            ($ref: literal) => {
507              $ref
508            };
509            () => {
510              false
511            };
512          }
513
514          m.insert($key.into(), CssModuleExport {
515            name: $name.into(),
516            composes: v,
517            is_referenced: is_referenced!($($referenced)?)
518          });
519        )*
520        m
521      }
522    };
523  );
524
525  #[test]
526  pub fn test_border_spacing() {
527    property_range_test(
528      &["border-spacing"],
529      &[
530        ("-1px", None),
531        ("calc(1px - 2px)", Some("0")),
532        ("calc(-1px + 2px)", Some("1px")),
533        ("1px -1px", None),
534      ],
535    );
536    minify_test(
537      r#"
538      .foo {
539        border-spacing: 0px;
540      }
541    "#,
542      indoc! {".foo{border-spacing:0}"
543      },
544    );
545    minify_test(
546      r#"
547      .foo {
548        border-spacing: 0px 0px;
549      }
550    "#,
551      indoc! {".foo{border-spacing:0}"
552      },
553    );
554
555    minify_test(
556      r#"
557      .foo {
558        border-spacing: 12px   0px;
559      }
560    "#,
561      indoc! {".foo{border-spacing:12px 0}"
562      },
563    );
564
565    minify_test(
566      r#"
567      .foo {
568        border-spacing: calc(3px * 2) calc(5px * 0);
569      }
570    "#,
571      indoc! {".foo{border-spacing:6px 0}"
572      },
573    );
574
575    minify_test(
576      r#"
577      .foo {
578        border-spacing: calc(3px * 2) max(0px, 8px);
579      }
580    "#,
581      indoc! {".foo{border-spacing:6px 8px}"
582      },
583    );
584
585    // TODO: The `<length>` in border-spacing cannot have a negative value,
586    // we may need to implement NonNegativeLength like Servo does.
587    // Servo Code: https://github.com/servo/servo/blob/08bc2d53579c9ab85415d4363888881b91df073b/components/style/values/specified/length.rs#L875
588    // CSSWG issue: https://lists.w3.org/Archives/Public/www-style/2008Sep/0161.html
589    // `border-spacing = <length> <length>?`
590    minify_test(
591      r#"
592      .foo {
593        border-spacing: -20px;
594      }
595    "#,
596      indoc! {".foo{border-spacing:-20px}"
597      },
598    );
599  }
600
601  #[test]
602  pub fn test_math_fn() {
603    use crate::values::angle::Angle;
604    use crate::values::length::Length;
605    use crate::values::number::{CSSInteger, CSSNumber};
606    use crate::values::percentage::{NumberOrPercentage, Percentage};
607
608    for source in ["-1", "-0.5"] {
609      non_negative_test::<CSSNumber>(source, None);
610      assert!(CSSNumber::parse_string(source).is_ok());
611    }
612    for (source, expected) in [
613      ("0", "0"),
614      ("-0", "0"),
615      ("calc(-5)", "0"),
616      ("calc(-5 + 10)", "5"),
617      ("calc(-5 * -2)", "10"),
618      ("min(-5, 10)", "0"),
619      ("max(-5, -10)", "0"),
620      ("clamp(-10, -5, -1)", "0"),
621      ("calc(min(-5, -10) + 20)", "10"),
622    ] {
623      non_negative_test::<CSSNumber>(source, Some(expected));
624      non_negative_test::<NumberOrPercentage>(source, Some(expected));
625    }
626    non_negative_test::<CSSInteger>("-1", None);
627    non_negative_test::<CSSInteger>("0", Some("0"));
628    non_negative_test::<CSSInteger>("2147483647", Some("2147483647"));
629    non_negative_test::<CSSInteger>("1.5", None);
630    for (source, expected) in [
631      ("-5%", None),
632      ("-0%", Some("-0%")),
633      ("calc(-5%)", Some("0%")),
634      ("calc(-5% + 10%)", Some("5%")),
635      ("min(-5%, 10%)", Some("0%")),
636      ("calc(min(-5%, -10%) + 20%)", Some("10%")),
637    ] {
638      non_negative_test::<Percentage>(source, expected);
639      non_negative_test::<NumberOrPercentage>(source, expected);
640    }
641    non_negative_test::<Percentage>("calc(1)", None);
642    non_negative_test::<Percentage>("calc(1px)", None);
643    assert_eq!(Percentage::parse_string("calc(-5%)").unwrap().0, -0.05);
644    for (source, expected) in [
645      ("-5deg", None),
646      ("calc(-5deg)", Some("0deg")),
647      ("calc(-5deg + 10deg)", Some("5deg")),
648      ("min(-5deg, 10deg)", Some("0deg")),
649      ("calc(1)", None),
650    ] {
651      non_negative_test::<Angle>(source, expected);
652    }
653    for (source, expected) in [
654      ("min(-5px, 10px)", "0"),
655      ("max(-5px, -10px)", "0"),
656      ("clamp(-10px, -5px, -1px)", "0"),
657      ("calc(min(-5px, -10px) + 20px)", "10px"),
658    ] {
659      non_negative_test::<Length>(source, Some(expected));
660    }
661
662    // max()
663    minify_test(
664      r#"
665      .foo {
666        color: rgb(max(255, 100), 0, 0);
667      }
668    "#,
669      indoc! {".foo{color:red}"
670      },
671    );
672    // min()
673    minify_test(
674      r#"
675      .foo {
676        color: rgb(min(255, 500), 0, 0);
677      }
678    "#,
679      indoc! {".foo{color:red}"
680      },
681    );
682    // abs()
683    minify_test(
684      r#"
685      .foo {
686        color: rgb(abs(-255), 0, 0);
687      }
688    "#,
689      indoc! {".foo{color:red}"
690      },
691    );
692    // clamp()
693    minify_test(
694      r#"
695      .foo {
696        flex: clamp(1, 5.20, 20);
697        color: rgb(clamp(0, 255, 300), 0, 0);
698      }
699    "#,
700      indoc! {".foo{color:red;flex:5.2}"
701      },
702    );
703    // round()
704    minify_test(
705      r#"
706      .round-color {
707        color: rgb(round(down, 255.6, 1), 0, 0);
708      }
709    "#,
710      indoc! {".round-color{color:red}"
711      },
712    );
713    // hypot()
714    minify_test(
715      r#"
716      .hypot-color {
717        color: rgb(hypot(255, 0), 0, 0);
718      }
719    "#,
720      indoc! {".hypot-color{color:red}"
721      },
722    );
723    // sign(), sign(50) = 1
724    minify_test(
725      r#"
726      .sign-color {
727        color: rgb(sign(50), 0, 0);
728      }
729    "#,
730      indoc! {".sign-color{color:#010000}"
731      },
732    );
733    // rem(), rem(21, 2) = 1
734    minify_test(
735      r#"
736      .rem-color {
737        color: rgb(rem(21, 2), 0, 0);
738      }
739    "#,
740      indoc! {".rem-color{color:#010000}"
741      },
742    );
743    // max() in width
744    minify_test(
745      r#"
746      .foo {
747        width: max(200px,   5px);
748      }
749    "#,
750      indoc! {".foo{width:200px}"
751      },
752    );
753    // max() in opacity
754    minify_test(
755      r#"
756      .foo {
757        opacity: max(1, 0.2);
758        filter: invert(min(1, 0.5));
759      }
760    "#,
761      indoc! {".foo{opacity:1;filter:invert(.5)}"
762      },
763    );
764    // TODO: support calc in Integer
765    // minify_test(
766    //   r#"
767    //   .foo {
768    //     z-index: max(100,    20);
769    //   }
770    // "#,
771    //   indoc! {".foo{z-index:100}"
772    //   },
773    // );
774  }
775
776  #[test]
777  pub fn test_border() {
778    property_range_test(
779      &["border-width", "border-left-width", "outline-width"],
780      &[
781        ("-1px", None),
782        ("calc(1px - 2px)", Some("0")),
783        ("calc(-1px + 2px)", Some("1px")),
784      ],
785    );
786    test(
787      r#"
788      .foo {
789        border-left: 2px solid red;
790        border-right: 2px solid red;
791        border-bottom: 2px solid red;
792        border-top: 2px solid red;
793      }
794    "#,
795      indoc! {r#"
796      .foo {
797        border: 2px solid red;
798      }
799    "#
800      },
801    );
802
803    test(
804      r#"
805      .foo {
806        border-left-color: red;
807        border-right-color: red;
808        border-bottom-color: red;
809        border-top-color: red;
810      }
811    "#,
812      indoc! {r#"
813      .foo {
814        border-color: red;
815      }
816    "#
817      },
818    );
819
820    test(
821      r#"
822      .foo {
823        border-left-width: thin;
824        border-right-width: thin;
825        border-bottom-width: thin;
826        border-top-width: thin;
827      }
828    "#,
829      indoc! {r#"
830      .foo {
831        border-width: thin;
832      }
833    "#
834      },
835    );
836
837    test(
838      r#"
839      .foo {
840        border-left-style: dotted;
841        border-right-style: dotted;
842        border-bottom-style: dotted;
843        border-top-style: dotted;
844      }
845    "#,
846      indoc! {r#"
847      .foo {
848        border-style: dotted;
849      }
850    "#
851      },
852    );
853
854    test(
855      r#"
856      .foo {
857        border-left-width: thin;
858        border-left-style: dotted;
859        border-left-color: red;
860      }
861    "#,
862      indoc! {r#"
863      .foo {
864        border-left: thin dotted red;
865      }
866    "#
867      },
868    );
869
870    test(
871      r#"
872      .foo {
873        border-left-width: thick;
874        border-left: thin dotted red;
875      }
876    "#,
877      indoc! {r#"
878      .foo {
879        border-left: thin dotted red;
880      }
881    "#
882      },
883    );
884
885    test(
886      r#"
887      .foo {
888        border-left-width: thick;
889        border: thin dotted red;
890      }
891    "#,
892      indoc! {r#"
893      .foo {
894        border: thin dotted red;
895      }
896    "#
897      },
898    );
899
900    test(
901      r#"
902      .foo {
903        border: thin dotted red;
904        border-right-width: thick;
905      }
906    "#,
907      indoc! {r#"
908      .foo {
909        border: thin dotted red;
910        border-right-width: thick;
911      }
912    "#
913      },
914    );
915
916    test(
917      r#"
918      .foo {
919        border: thin dotted red;
920        border-right: thick dotted red;
921      }
922    "#,
923      indoc! {r#"
924      .foo {
925        border: thin dotted red;
926        border-right-width: thick;
927      }
928    "#
929      },
930    );
931
932    test(
933      r#"
934      .foo {
935        border: thin dotted red;
936        border-right-width: thick;
937        border-right-style: solid;
938      }
939    "#,
940      indoc! {r#"
941      .foo {
942        border: thin dotted red;
943        border-right: thick solid red;
944      }
945    "#
946      },
947    );
948
949    test(
950      r#"
951      .foo {
952        border-top: thin dotted red;
953        border-block-start: thick solid green;
954      }
955    "#,
956      indoc! {r#"
957      .foo {
958        border-top: thin dotted red;
959        border-block-start: thick solid green;
960      }
961    "#
962      },
963    );
964
965    test(
966      r#"
967      .foo {
968        border: thin dotted red;
969        border-block-start-width: thick;
970        border-left-width: medium;
971      }
972    "#,
973      indoc! {r#"
974      .foo {
975        border: thin dotted red;
976        border-block-start-width: thick;
977        border-left-width: medium;
978      }
979    "#
980      },
981    );
982
983    test(
984      r#"
985      .foo {
986        border-block-start: thin dotted red;
987        border-inline-end: thin dotted red;
988      }
989    "#,
990      indoc! {r#"
991      .foo {
992        border-block-start: thin dotted red;
993        border-inline-end: thin dotted red;
994      }
995    "#
996      },
997    );
998
999    test(
1000      r#"
1001      .foo {
1002        border-block-start-width: thin;
1003        border-block-start-style: dotted;
1004        border-block-start-color: red;
1005        border-inline-end: thin dotted red;
1006      }
1007    "#,
1008      indoc! {r#"
1009      .foo {
1010        border-block-start: thin dotted red;
1011        border-inline-end: thin dotted red;
1012      }
1013    "#
1014      },
1015    );
1016
1017    test(
1018      r#"
1019      .foo {
1020        border-block-start: thin dotted red;
1021        border-block-end: thin dotted red;
1022      }
1023    "#,
1024      indoc! {r#"
1025      .foo {
1026        border-block: thin dotted red;
1027      }
1028    "#
1029      },
1030    );
1031
1032    minify_test(
1033      r#"
1034      .foo {
1035        border: none;
1036      }
1037    "#,
1038      indoc! {".foo{border:none}"
1039      },
1040    );
1041
1042    minify_test(".foo { border-width: 0 0 1px; }", ".foo{border-width:0 0 1px}");
1043    test(
1044      r#"
1045      .foo {
1046        border-block-width: 1px;
1047        border-inline-width: 1px;
1048      }
1049    "#,
1050      indoc! {r#"
1051      .foo {
1052        border-width: 1px;
1053      }
1054    "#
1055      },
1056    );
1057    test(
1058      r#"
1059      .foo {
1060        border-block-start-width: 1px;
1061        border-block-end-width: 1px;
1062        border-inline-start-width: 1px;
1063        border-inline-end-width: 1px;
1064      }
1065    "#,
1066      indoc! {r#"
1067      .foo {
1068        border-width: 1px;
1069      }
1070    "#
1071      },
1072    );
1073    test(
1074      r#"
1075      .foo {
1076        border-block-start-width: 1px;
1077        border-block-end-width: 1px;
1078        border-inline-start-width: 2px;
1079        border-inline-end-width: 2px;
1080      }
1081    "#,
1082      indoc! {r#"
1083      .foo {
1084        border-block-width: 1px;
1085        border-inline-width: 2px;
1086      }
1087    "#
1088      },
1089    );
1090    test(
1091      r#"
1092      .foo {
1093        border-block-start-width: 1px;
1094        border-block-end-width: 1px;
1095        border-inline-start-width: 2px;
1096        border-inline-end-width: 3px;
1097      }
1098    "#,
1099      indoc! {r#"
1100      .foo {
1101        border-block-width: 1px;
1102        border-inline-width: 2px 3px;
1103      }
1104    "#
1105      },
1106    );
1107
1108    minify_test(
1109      ".foo { border-bottom: 1px solid var(--spectrum-global-color-gray-200)}",
1110      ".foo{border-bottom:1px solid var(--spectrum-global-color-gray-200)}",
1111    );
1112    test(
1113      r#"
1114      .foo {
1115        border-width: 0;
1116        border-bottom: var(--test, 1px) solid;
1117      }
1118    "#,
1119      indoc! {r#"
1120      .foo {
1121        border-width: 0;
1122        border-bottom: var(--test, 1px) solid;
1123      }
1124    "#
1125      },
1126    );
1127
1128    test(
1129      r#"
1130      .foo {
1131        border: 1px solid black;
1132        border-width: 1px 1px 0 0;
1133      }
1134    "#,
1135      indoc! {r#"
1136      .foo {
1137        border: 1px solid #000;
1138        border-width: 1px 1px 0 0;
1139      }
1140    "#},
1141    );
1142
1143    test(
1144      r#"
1145      .foo {
1146        border-top: 1px solid black;
1147        border-bottom: 1px solid black;
1148        border-left: 2px solid black;
1149        border-right: 2px solid black;
1150      }
1151    "#,
1152      indoc! {r#"
1153      .foo {
1154        border: 1px solid #000;
1155        border-width: 1px 2px;
1156      }
1157    "#},
1158    );
1159
1160    test(
1161      r#"
1162      .foo {
1163        border-top: 1px solid black;
1164        border-bottom: 1px solid black;
1165        border-left: 2px solid black;
1166        border-right: 1px solid black;
1167      }
1168    "#,
1169      indoc! {r#"
1170      .foo {
1171        border: 1px solid #000;
1172        border-left-width: 2px;
1173      }
1174    "#},
1175    );
1176
1177    test(
1178      r#"
1179      .foo {
1180        border-top: 1px solid black;
1181        border-bottom: 1px solid black;
1182        border-left: 1px solid red;
1183        border-right: 1px solid red;
1184      }
1185    "#,
1186      indoc! {r#"
1187      .foo {
1188        border: 1px solid #000;
1189        border-color: #000 red;
1190      }
1191    "#},
1192    );
1193
1194    test(
1195      r#"
1196      .foo {
1197        border-block-start: 1px solid black;
1198        border-block-end: 1px solid black;
1199        border-inline-start: 1px solid red;
1200        border-inline-end: 1px solid red;
1201      }
1202    "#,
1203      indoc! {r#"
1204      .foo {
1205        border: 1px solid #000;
1206        border-inline-color: red;
1207      }
1208    "#},
1209    );
1210
1211    test(
1212      r#"
1213      .foo {
1214        border-block-start: 1px solid black;
1215        border-block-end: 1px solid black;
1216        border-inline-start: 2px solid black;
1217        border-inline-end: 2px solid black;
1218      }
1219    "#,
1220      indoc! {r#"
1221      .foo {
1222        border: 1px solid #000;
1223        border-inline-width: 2px;
1224      }
1225    "#},
1226    );
1227
1228    test(
1229      r#"
1230      .foo {
1231        border-block-start: 1px solid black;
1232        border-block-end: 1px solid black;
1233        border-inline-start: 2px solid red;
1234        border-inline-end: 2px solid red;
1235      }
1236    "#,
1237      indoc! {r#"
1238      .foo {
1239        border: 1px solid #000;
1240        border-inline: 2px solid red;
1241      }
1242    "#},
1243    );
1244
1245    test(
1246      r#"
1247      .foo {
1248        border-block-start: 1px solid black;
1249        border-block-end: 1px solid black;
1250        border-inline-start: 2px solid red;
1251        border-inline-end: 3px solid red;
1252      }
1253    "#,
1254      indoc! {r#"
1255      .foo {
1256        border: 1px solid #000;
1257        border-inline-start: 2px solid red;
1258        border-inline-end: 3px solid red;
1259      }
1260    "#},
1261    );
1262
1263    test(
1264      r#"
1265      .foo {
1266        border-block-start: 2px solid black;
1267        border-block-end: 1px solid black;
1268        border-inline-start: 2px solid red;
1269        border-inline-end: 2px solid red;
1270      }
1271    "#,
1272      indoc! {r#"
1273      .foo {
1274        border: 2px solid red;
1275        border-block-start-color: #000;
1276        border-block-end: 1px solid #000;
1277      }
1278    "#},
1279    );
1280
1281    test(
1282      r#"
1283      .foo {
1284        border-block-start: 2px solid red;
1285        border-block-end: 1px solid red;
1286        border-inline-start: 2px solid red;
1287        border-inline-end: 2px solid red;
1288      }
1289    "#,
1290      indoc! {r#"
1291      .foo {
1292        border: 2px solid red;
1293        border-block-end-width: 1px;
1294      }
1295    "#},
1296    );
1297
1298    test(
1299      r#"
1300      .foo {
1301        border-block-start: 2px solid red;
1302        border-block-end: 2px solid red;
1303        border-inline-start: 2px solid red;
1304        border-inline-end: 1px solid red;
1305      }
1306    "#,
1307      indoc! {r#"
1308      .foo {
1309        border: 2px solid red;
1310        border-inline-end-width: 1px;
1311      }
1312    "#},
1313    );
1314
1315    test(
1316      r#"
1317      .foo {
1318        border: 1px solid currentColor;
1319      }
1320    "#,
1321      indoc! {r#"
1322      .foo {
1323        border: 1px solid;
1324      }
1325    "#
1326      },
1327    );
1328
1329    minify_test(
1330      r#"
1331      .foo {
1332        border: 1px solid currentColor;
1333      }
1334    "#,
1335      ".foo{border:1px solid}",
1336    );
1337
1338    prefix_test(
1339      r#"
1340      .foo {
1341        border-block: 2px solid red;
1342      }
1343    "#,
1344      indoc! {r#"
1345      .foo {
1346        border-top: 2px solid red;
1347        border-bottom: 2px solid red;
1348      }
1349    "#
1350      },
1351      Browsers {
1352        safari: Some(8 << 16),
1353        ..Browsers::default()
1354      },
1355    );
1356
1357    prefix_test(
1358      r#"
1359      .foo {
1360        border-block-start: 2px solid red;
1361      }
1362    "#,
1363      indoc! {r#"
1364      .foo {
1365        border-top: 2px solid red;
1366      }
1367    "#
1368      },
1369      Browsers {
1370        safari: Some(8 << 16),
1371        ..Browsers::default()
1372      },
1373    );
1374
1375    prefix_test(
1376      r#"
1377      .foo {
1378        border-block-end: 2px solid red;
1379      }
1380    "#,
1381      indoc! {r#"
1382      .foo {
1383        border-bottom: 2px solid red;
1384      }
1385    "#
1386      },
1387      Browsers {
1388        safari: Some(8 << 16),
1389        ..Browsers::default()
1390      },
1391    );
1392
1393    prefix_test(
1394      r#"
1395      .foo {
1396        border-inline: 2px solid red;
1397      }
1398    "#,
1399      indoc! {r#"
1400      .foo {
1401        border-left: 2px solid red;
1402        border-right: 2px solid red;
1403      }
1404    "#
1405      },
1406      Browsers {
1407        safari: Some(8 << 16),
1408        ..Browsers::default()
1409      },
1410    );
1411
1412    prefix_test(
1413      r#"
1414      .foo {
1415        border-block-width: 2px;
1416      }
1417    "#,
1418      indoc! {r#"
1419      .foo {
1420        border-block-start-width: 2px;
1421        border-block-end-width: 2px;
1422      }
1423    "#
1424      },
1425      Browsers {
1426        safari: Some(13 << 16),
1427        ..Browsers::default()
1428      },
1429    );
1430
1431    prefix_test(
1432      r#"
1433      .foo {
1434        border-block-width: 2px;
1435      }
1436    "#,
1437      indoc! {r#"
1438      .foo {
1439        border-block-width: 2px;
1440      }
1441    "#
1442      },
1443      Browsers {
1444        safari: Some(15 << 16),
1445        ..Browsers::default()
1446      },
1447    );
1448
1449    prefix_test(
1450      r#"
1451      .foo {
1452        border-inline-start: 2px solid red;
1453      }
1454    "#,
1455      indoc! {r#"
1456      .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))) {
1457        border-left: 2px solid red;
1458      }
1459
1460      .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))) {
1461        border-left: 2px solid red;
1462      }
1463
1464      .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)) {
1465        border-right: 2px solid red;
1466      }
1467
1468      .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)) {
1469        border-right: 2px solid red;
1470      }
1471    "#
1472      },
1473      Browsers {
1474        safari: Some(8 << 16),
1475        ..Browsers::default()
1476      },
1477    );
1478
1479    prefix_test(
1480      r#"
1481      .foo {
1482        border-inline-start-width: 2px;
1483      }
1484    "#,
1485      indoc! {r#"
1486      .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))) {
1487        border-left-width: 2px;
1488      }
1489
1490      .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))) {
1491        border-left-width: 2px;
1492      }
1493
1494      .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)) {
1495        border-right-width: 2px;
1496      }
1497
1498      .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)) {
1499        border-right-width: 2px;
1500      }
1501    "#
1502      },
1503      Browsers {
1504        safari: Some(8 << 16),
1505        ..Browsers::default()
1506      },
1507    );
1508
1509    prefix_test(
1510      r#"
1511      .foo {
1512        border-inline-end: 2px solid red;
1513      }
1514    "#,
1515      indoc! {r#"
1516      .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))) {
1517        border-right: 2px solid red;
1518      }
1519
1520      .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))) {
1521        border-right: 2px solid red;
1522      }
1523
1524      .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)) {
1525        border-left: 2px solid red;
1526      }
1527
1528      .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)) {
1529        border-left: 2px solid red;
1530      }
1531    "#
1532      },
1533      Browsers {
1534        safari: Some(8 << 16),
1535        ..Browsers::default()
1536      },
1537    );
1538
1539    prefix_test(
1540      r#"
1541      .foo {
1542        border-inline-start: 2px solid red;
1543        border-inline-end: 5px solid green;
1544      }
1545    "#,
1546      indoc! {r#"
1547      .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))) {
1548        border-left: 2px solid red;
1549        border-right: 5px solid green;
1550      }
1551
1552      .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))) {
1553        border-left: 2px solid red;
1554        border-right: 5px solid green;
1555      }
1556
1557      .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)) {
1558        border-left: 5px solid green;
1559        border-right: 2px solid red;
1560      }
1561
1562      .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)) {
1563        border-left: 5px solid green;
1564        border-right: 2px solid red;
1565      }
1566    "#
1567      },
1568      Browsers {
1569        safari: Some(8 << 16),
1570        ..Browsers::default()
1571      },
1572    );
1573
1574    prefix_test(
1575      r#"
1576      .foo {
1577        border-inline-start: 2px solid red;
1578        border-inline-end: 5px solid green;
1579      }
1580
1581      .bar {
1582        border-inline-start: 1px dotted gray;
1583        border-inline-end: 1px solid black;
1584      }
1585    "#,
1586      indoc! {r#"
1587      .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))) {
1588        border-left: 2px solid red;
1589        border-right: 5px solid green;
1590      }
1591
1592      .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))) {
1593        border-left: 2px solid red;
1594        border-right: 5px solid green;
1595      }
1596
1597      .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)) {
1598        border-left: 5px solid green;
1599        border-right: 2px solid red;
1600      }
1601
1602      .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)) {
1603        border-left: 5px solid green;
1604        border-right: 2px solid red;
1605      }
1606
1607      .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))) {
1608        border-left: 1px dotted gray;
1609        border-right: 1px solid #000;
1610      }
1611
1612      .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))) {
1613        border-left: 1px dotted gray;
1614        border-right: 1px solid #000;
1615      }
1616
1617      .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)) {
1618        border-left: 1px solid #000;
1619        border-right: 1px dotted gray;
1620      }
1621
1622      .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)) {
1623        border-left: 1px solid #000;
1624        border-right: 1px dotted gray;
1625      }
1626    "#
1627      },
1628      Browsers {
1629        safari: Some(8 << 16),
1630        ..Browsers::default()
1631      },
1632    );
1633
1634    prefix_test(
1635      r#"
1636      .foo {
1637        border-inline-width: 2px;
1638      }
1639    "#,
1640      indoc! {r#"
1641      .foo {
1642        border-left-width: 2px;
1643        border-right-width: 2px;
1644      }
1645    "#
1646      },
1647      Browsers {
1648        safari: Some(8 << 16),
1649        ..Browsers::default()
1650      },
1651    );
1652
1653    prefix_test(
1654      r#"
1655      .foo {
1656        border-inline-width: 2px;
1657      }
1658    "#,
1659      indoc! {r#"
1660      .foo {
1661        border-left-width: 2px;
1662        border-right-width: 2px;
1663      }
1664    "#
1665      },
1666      Browsers {
1667        safari: Some(8 << 16),
1668        ..Browsers::default()
1669      },
1670    );
1671
1672    prefix_test(
1673      r#"
1674      .foo {
1675        border-inline-style: solid;
1676      }
1677    "#,
1678      indoc! {r#"
1679      .foo {
1680        border-left-style: solid;
1681        border-right-style: solid;
1682      }
1683    "#
1684      },
1685      Browsers {
1686        safari: Some(8 << 16),
1687        ..Browsers::default()
1688      },
1689    );
1690
1691    prefix_test(
1692      r#"
1693      .foo {
1694        border-inline-color: red;
1695      }
1696    "#,
1697      indoc! {r#"
1698      .foo {
1699        border-left-color: red;
1700        border-right-color: red;
1701      }
1702    "#
1703      },
1704      Browsers {
1705        safari: Some(8 << 16),
1706        ..Browsers::default()
1707      },
1708    );
1709
1710    prefix_test(
1711      r#"
1712      .foo {
1713        border-inline-end: var(--test);
1714      }
1715    "#,
1716      indoc! {r#"
1717      .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))) {
1718        border-right: var(--test);
1719      }
1720
1721      .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))) {
1722        border-right: var(--test);
1723      }
1724
1725      .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)) {
1726        border-left: var(--test);
1727      }
1728
1729      .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)) {
1730        border-left: var(--test);
1731      }
1732    "#
1733      },
1734      Browsers {
1735        safari: Some(8 << 16),
1736        ..Browsers::default()
1737      },
1738    );
1739
1740    prefix_test(
1741      r#"
1742      .foo {
1743        border-inline-start: var(--start);
1744        border-inline-end: var(--end);
1745      }
1746    "#,
1747      indoc! {r#"
1748      .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))) {
1749        border-left: var(--start);
1750        border-right: var(--end);
1751      }
1752
1753      .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))) {
1754        border-left: var(--start);
1755        border-right: var(--end);
1756      }
1757
1758      .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)) {
1759        border-right: var(--start);
1760        border-left: var(--end);
1761      }
1762
1763      .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)) {
1764        border-right: var(--start);
1765        border-left: var(--end);
1766      }
1767    "#
1768      },
1769      Browsers {
1770        safari: Some(8 << 16),
1771        ..Browsers::default()
1772      },
1773    );
1774
1775    for prop in &[
1776      "border-inline-start-color",
1777      "border-inline-end-color",
1778      "border-block-start-color",
1779      "border-block-end-color",
1780      "border-top-color",
1781      "border-bottom-color",
1782      "border-left-color",
1783      "border-right-color",
1784      "border-color",
1785      "border-block-color",
1786      "border-inline-color",
1787    ] {
1788      prefix_test(
1789        &format!(
1790          r#"
1791        .foo {{
1792          {}: lab(40% 56.6 39);
1793        }}
1794      "#,
1795          prop
1796        ),
1797        &format!(
1798          indoc! {r#"
1799        .foo {{
1800          {}: #b32323;
1801          {}: lab(40% 56.6 39);
1802        }}
1803      "#},
1804          prop, prop
1805        ),
1806        Browsers {
1807          chrome: Some(90 << 16),
1808          ..Browsers::default()
1809        },
1810      );
1811    }
1812
1813    for prop in &[
1814      "border",
1815      "border-inline",
1816      "border-block",
1817      "border-left",
1818      "border-right",
1819      "border-top",
1820      "border-bottom",
1821      "border-block-start",
1822      "border-block-end",
1823      "border-inline-start",
1824      "border-inline-end",
1825    ] {
1826      prefix_test(
1827        &format!(
1828          r#"
1829        .foo {{
1830          {}: 2px solid lab(40% 56.6 39);
1831        }}
1832      "#,
1833          prop
1834        ),
1835        &format!(
1836          indoc! {r#"
1837        .foo {{
1838          {}: 2px solid #b32323;
1839          {}: 2px solid lab(40% 56.6 39);
1840        }}
1841      "#},
1842          prop, prop
1843        ),
1844        Browsers {
1845          chrome: Some(90 << 16),
1846          ..Browsers::default()
1847        },
1848      );
1849    }
1850
1851    for prop in &[
1852      "border",
1853      "border-inline",
1854      "border-block",
1855      "border-left",
1856      "border-right",
1857      "border-top",
1858      "border-bottom",
1859      "border-block-start",
1860      "border-block-end",
1861      "border-inline-start",
1862      "border-inline-end",
1863    ] {
1864      prefix_test(
1865        &format!(
1866          r#"
1867        .foo {{
1868          {}: var(--border-width) solid lab(40% 56.6 39);
1869        }}
1870      "#,
1871          prop
1872        ),
1873        &format!(
1874          indoc! {r#"
1875        .foo {{
1876          {}: var(--border-width) solid #b32323;
1877        }}
1878
1879        @supports (color: lab(0% 0 0)) {{
1880          .foo {{
1881            {}: var(--border-width) solid lab(40% 56.6 39);
1882          }}
1883        }}
1884      "#},
1885          prop, prop
1886        ),
1887        Browsers {
1888          chrome: Some(90 << 16),
1889          ..Browsers::default()
1890        },
1891      );
1892
1893      prefix_test(
1894        &format!(
1895          r#"
1896        @supports (color: lab(0% 0 0)) {{
1897          .foo {{
1898            {}: var(--border-width) solid lab(40% 56.6 39);
1899          }}
1900        }}
1901      "#,
1902          prop
1903        ),
1904        &format!(
1905          indoc! {r#"
1906        @supports (color: lab(0% 0 0)) {{
1907          .foo {{
1908            {}: var(--border-width) solid lab(40% 56.6 39);
1909          }}
1910        }}
1911      "#},
1912          prop,
1913        ),
1914        Browsers {
1915          chrome: Some(90 << 16),
1916          ..Browsers::default()
1917        },
1918      );
1919    }
1920
1921    prefix_test(
1922      r#"
1923      .foo {
1924        border-inline-start-color: lab(40% 56.6 39);
1925      }
1926    "#,
1927      indoc! {r#"
1928      .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))) {
1929        border-left-color: #b32323;
1930        border-left-color: lab(40% 56.6 39);
1931      }
1932
1933      .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))) {
1934        border-left-color: #b32323;
1935        border-left-color: lab(40% 56.6 39);
1936      }
1937
1938      .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)) {
1939        border-right-color: #b32323;
1940        border-right-color: lab(40% 56.6 39);
1941      }
1942
1943      .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)) {
1944        border-right-color: #b32323;
1945        border-right-color: lab(40% 56.6 39);
1946      }
1947    "#},
1948      Browsers {
1949        safari: Some(8 << 16),
1950        ..Browsers::default()
1951      },
1952    );
1953
1954    prefix_test(
1955      r#"
1956      .foo {
1957        border-inline-end-color: lab(40% 56.6 39);
1958      }
1959    "#,
1960      indoc! {r#"
1961      .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))) {
1962        border-right-color: #b32323;
1963        border-right-color: lab(40% 56.6 39);
1964      }
1965
1966      .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))) {
1967        border-right-color: #b32323;
1968        border-right-color: lab(40% 56.6 39);
1969      }
1970
1971      .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)) {
1972        border-left-color: #b32323;
1973        border-left-color: lab(40% 56.6 39);
1974      }
1975
1976      .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)) {
1977        border-left-color: #b32323;
1978        border-left-color: lab(40% 56.6 39);
1979      }
1980    "#},
1981      Browsers {
1982        safari: Some(8 << 16),
1983        ..Browsers::default()
1984      },
1985    );
1986
1987    prefix_test(
1988      r#"
1989      .foo {
1990        border-inline-start-color: lab(40% 56.6 39);
1991        border-inline-end-color: lch(50.998% 135.363 338);
1992      }
1993    "#,
1994      indoc! {r#"
1995      .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))) {
1996        border-left-color: #b32323;
1997        border-left-color: lab(40% 56.6 39);
1998        border-right-color: #f000c0;
1999        border-right-color: lch(50.998% 135.363 338);
2000      }
2001
2002      .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))) {
2003        border-left-color: #b32323;
2004        border-left-color: lab(40% 56.6 39);
2005        border-right-color: #f000c0;
2006        border-right-color: lch(50.998% 135.363 338);
2007      }
2008
2009      .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)) {
2010        border-left-color: #f000c0;
2011        border-left-color: lch(50.998% 135.363 338);
2012        border-right-color: #b32323;
2013        border-right-color: lab(40% 56.6 39);
2014      }
2015
2016      .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)) {
2017        border-left-color: #f000c0;
2018        border-left-color: lch(50.998% 135.363 338);
2019        border-right-color: #b32323;
2020        border-right-color: lab(40% 56.6 39);
2021      }
2022    "#},
2023      Browsers {
2024        safari: Some(8 << 16),
2025        ..Browsers::default()
2026      },
2027    );
2028
2029    prefix_test(
2030      r#"
2031      .foo {
2032        border-inline-start-color: lab(40% 56.6 39);
2033        border-inline-end-color: lch(50.998% 135.363 338);
2034      }
2035    "#,
2036      indoc! {r#"
2037      .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))) {
2038        border-left-color: #b32323;
2039        border-left-color: color(display-p3 .643308 .192455 .167712);
2040        border-left-color: lab(40% 56.6 39);
2041        border-right-color: #f000c0;
2042        border-right-color: color(display-p3 .972962 -.362078 .804206);
2043        border-right-color: lch(50.998% 135.363 338);
2044      }
2045
2046      .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)) {
2047        border-left-color: #f000c0;
2048        border-left-color: color(display-p3 .972962 -.362078 .804206);
2049        border-left-color: lch(50.998% 135.363 338);
2050        border-right-color: #b32323;
2051        border-right-color: color(display-p3 .643308 .192455 .167712);
2052        border-right-color: lab(40% 56.6 39);
2053      }
2054    "#},
2055      Browsers {
2056        chrome: Some(8 << 16),
2057        safari: Some(14 << 16),
2058        ..Browsers::default()
2059      },
2060    );
2061
2062    prefix_test(
2063      r#"
2064      .foo {
2065        border-inline-start: 2px solid lab(40% 56.6 39);
2066      }
2067    "#,
2068      indoc! {r#"
2069      .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))) {
2070        border-left: 2px solid #b32323;
2071        border-left: 2px solid lab(40% 56.6 39);
2072      }
2073
2074      .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))) {
2075        border-left: 2px solid #b32323;
2076        border-left: 2px solid lab(40% 56.6 39);
2077      }
2078
2079      .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)) {
2080        border-right: 2px solid #b32323;
2081        border-right: 2px solid lab(40% 56.6 39);
2082      }
2083
2084      .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)) {
2085        border-right: 2px solid #b32323;
2086        border-right: 2px solid lab(40% 56.6 39);
2087      }
2088    "#},
2089      Browsers {
2090        safari: Some(8 << 16),
2091        ..Browsers::default()
2092      },
2093    );
2094
2095    prefix_test(
2096      r#"
2097      .foo {
2098        border-inline-end: 2px solid lab(40% 56.6 39);
2099      }
2100    "#,
2101      indoc! {r#"
2102      .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))) {
2103        border-right: 2px solid #b32323;
2104        border-right: 2px solid lab(40% 56.6 39);
2105      }
2106
2107      .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))) {
2108        border-right: 2px solid #b32323;
2109        border-right: 2px solid lab(40% 56.6 39);
2110      }
2111
2112      .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)) {
2113        border-left: 2px solid #b32323;
2114        border-left: 2px solid lab(40% 56.6 39);
2115      }
2116
2117      .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)) {
2118        border-left: 2px solid #b32323;
2119        border-left: 2px solid lab(40% 56.6 39);
2120      }
2121    "#},
2122      Browsers {
2123        safari: Some(8 << 16),
2124        ..Browsers::default()
2125      },
2126    );
2127
2128    prefix_test(
2129      r#"
2130      .foo {
2131        border-inline-end: var(--border-width) solid lab(40% 56.6 39);
2132      }
2133    "#,
2134      indoc! {r#"
2135      .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))) {
2136        border-right: var(--border-width) solid #b32323;
2137      }
2138
2139      .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))) {
2140        border-right: var(--border-width) solid #b32323;
2141      }
2142
2143      @supports (color: lab(0% 0 0)) {
2144        .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))) {
2145          border-right: var(--border-width) solid lab(40% 56.6 39);
2146        }
2147      }
2148
2149      .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)) {
2150        border-left: var(--border-width) solid #b32323;
2151      }
2152
2153      .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)) {
2154        border-left: var(--border-width) solid #b32323;
2155      }
2156
2157      @supports (color: lab(0% 0 0)) {
2158        .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)) {
2159          border-left: var(--border-width) solid lab(40% 56.6 39);
2160        }
2161      }
2162    "#},
2163      Browsers {
2164        safari: Some(8 << 16),
2165        ..Browsers::default()
2166      },
2167    );
2168
2169    prefix_test(
2170      r#"
2171      .foo {
2172        border-inline-start: 2px solid red;
2173        border-inline-end: 2px solid red;
2174      }
2175    "#,
2176      indoc! {r#"
2177      .foo {
2178        border-inline-start: 2px solid red;
2179        border-inline-end: 2px solid red;
2180      }
2181    "#
2182      },
2183      Browsers {
2184        safari: Some(13 << 16),
2185        ..Browsers::default()
2186      },
2187    );
2188
2189    prefix_test(
2190      r#"
2191      .foo {
2192        border-inline-start: 2px solid red;
2193        border-inline-end: 2px solid red;
2194      }
2195    "#,
2196      indoc! {r#"
2197      .foo {
2198        border-inline: 2px solid red;
2199      }
2200    "#
2201      },
2202      Browsers {
2203        safari: Some(15 << 16),
2204        ..Browsers::default()
2205      },
2206    );
2207
2208    prefix_test(
2209      r#"
2210      .foo {
2211        border-width: 22px;
2212        border-width: max(2cqw, 22px);
2213      }
2214    "#,
2215      indoc! {r#"
2216      .foo {
2217        border-width: 22px;
2218        border-width: max(2cqw, 22px);
2219      }
2220    "#
2221      },
2222      Browsers {
2223        safari: Some(14 << 16),
2224        ..Browsers::default()
2225      },
2226    );
2227    prefix_test(
2228      r#"
2229      .foo {
2230        border-width: 22px;
2231        border-width: max(2cqw, 22px);
2232      }
2233    "#,
2234      indoc! {r#"
2235      .foo {
2236        border-width: max(2cqw, 22px);
2237      }
2238    "#
2239      },
2240      Browsers {
2241        safari: Some(16 << 16),
2242        ..Browsers::default()
2243      },
2244    );
2245    prefix_test(
2246      r#"
2247      .foo {
2248        border-color: #4263eb;
2249        border-color: color(display-p3 0 .5 1);
2250      }
2251    "#,
2252      indoc! {r#"
2253      .foo {
2254        border-color: #4263eb;
2255        border-color: color(display-p3 0 .5 1);
2256      }
2257    "#
2258      },
2259      Browsers {
2260        chrome: Some(99 << 16),
2261        ..Browsers::default()
2262      },
2263    );
2264    prefix_test(
2265      r#"
2266      .foo {
2267        border-color: #4263eb;
2268        border-color: color(display-p3 0 .5 1);
2269      }
2270    "#,
2271      indoc! {r#"
2272      .foo {
2273        border-color: color(display-p3 0 .5 1);
2274      }
2275    "#
2276      },
2277      Browsers {
2278        safari: Some(16 << 16),
2279        ..Browsers::default()
2280      },
2281    );
2282    prefix_test(
2283      r#"
2284      .foo {
2285        border: 1px solid #4263eb;
2286        border-color: color(display-p3 0 .5 1);
2287      }
2288    "#,
2289      indoc! {r#"
2290      .foo {
2291        border: 1px solid #4263eb;
2292        border-color: color(display-p3 0 .5 1);
2293      }
2294    "#
2295      },
2296      Browsers {
2297        chrome: Some(99 << 16),
2298        ..Browsers::default()
2299      },
2300    );
2301    prefix_test(
2302      r#"
2303      .foo {
2304        border: 1px solid #4263eb;
2305        border-color: color(display-p3 0 .5 1);
2306      }
2307    "#,
2308      indoc! {r#"
2309      .foo {
2310        border: 1px solid color(display-p3 0 .5 1);
2311      }
2312    "#
2313      },
2314      Browsers {
2315        safari: Some(16 << 16),
2316        ..Browsers::default()
2317      },
2318    );
2319    prefix_test(
2320      r#"
2321      .foo {
2322        border-color: var(--fallback);
2323        border-color: color(display-p3 0 .5 1);
2324      }
2325    "#,
2326      indoc! {r#"
2327      .foo {
2328        border-color: var(--fallback);
2329        border-color: color(display-p3 0 .5 1);
2330      }
2331    "#
2332      },
2333      Browsers {
2334        chrome: Some(99 << 16),
2335        ..Browsers::default()
2336      },
2337    );
2338  }
2339
2340  #[test]
2341  pub fn test_border_image() {
2342    minify_test(
2343      r#"
2344      .foo {
2345        border-image: none;
2346      }
2347      "#,
2348      ".foo{border-image:none}",
2349    );
2350
2351    test(
2352      r#"
2353      .foo {
2354        border-image: none;
2355      }
2356      "#,
2357      indoc! {r#"
2358      .foo {
2359        border-image: none;
2360      }
2361      "#},
2362    );
2363
2364    minify_test(
2365      r#"
2366      .foo {
2367        border-image: none 100% / 1 / 0 stretch;
2368      }
2369      "#,
2370      ".foo{border-image:none}",
2371    );
2372
2373    minify_test(
2374      r#"
2375      .foo {
2376        border-image-source: none;
2377        border-image-slice: 100%;
2378        border-image-width: 1;
2379        border-image-outset: 0;
2380        border-image-repeat: stretch;
2381      }
2382      "#,
2383      ".foo{border-image:none}",
2384    );
2385
2386    minify_test(
2387      r#"
2388      .foo {
2389        -webkit-border-image: none;
2390        border-image: none !important;
2391      }
2392      "#,
2393      ".foo{-webkit-border-image:none;border-image:none!important}",
2394    );
2395
2396    minify_test(
2397      r#"
2398      .foo {
2399        border-image: url(border.png) 1;
2400      }
2401      .foo.active {
2402        border-image: none;
2403      }
2404      "#,
2405      ".foo{border-image:url(border.png) 1}.foo.active{border-image:none}",
2406    );
2407
2408    property_range_test(
2409      &[
2410        "border-image-outset",
2411        "mask-border-outset",
2412        "-webkit-mask-box-image-outset",
2413      ],
2414      &[
2415        ("-1px", None),
2416        ("calc(1px - 2px)", Some("0")),
2417        ("calc(-1px + 2px)", Some("1px")),
2418        ("-1", None),
2419        ("calc(1 - 2)", Some("0")),
2420        ("calc(-1 + 2)", Some("1")),
2421      ],
2422    );
2423    property_range_test(
2424      &["border-image-width", "mask-border-width"],
2425      &[
2426        ("-1px", None),
2427        ("calc(1px - 2px)", Some("0")),
2428        ("calc(-1px + 2px)", Some("1px")),
2429        ("-1%", None),
2430        ("calc(1em - 2px)", Some("calc(1em - 2px)")),
2431        ("calc(-1%)", Some("calc(-1%)")),
2432        ("-1", None),
2433        ("calc(1 - 2)", Some("0")),
2434        ("calc(-1 + 2)", Some("1")),
2435        ("auto", Some("auto")),
2436      ],
2437    );
2438    property_range_test(
2439      &["border-image-slice", "mask-border-slice"],
2440      &[
2441        ("-1", None),
2442        ("calc(1 - 2)", Some("0")),
2443        ("calc(-1 + 2)", Some("1")),
2444        ("-1%", None),
2445      ],
2446    );
2447    test(
2448      r#"
2449      .foo {
2450        border-image: url(test.png) 60;
2451      }
2452    "#,
2453      indoc! {r#"
2454      .foo {
2455        border-image: url("test.png") 60;
2456      }
2457    "#
2458      },
2459    );
2460
2461    test(
2462      r#"
2463      .foo {
2464        border-image: url(test.png) 60;
2465        border-image-source: url(foo.png);
2466      }
2467    "#,
2468      indoc! {r#"
2469      .foo {
2470        border-image: url("foo.png") 60;
2471      }
2472    "#
2473      },
2474    );
2475
2476    test(
2477      r#"
2478      .foo {
2479        border-image-source: url(foo.png);
2480        border-image-slice: 10 40 10 40 fill;
2481        border-image-width: 10px;
2482        border-image-outset: 0;
2483        border-image-repeat: round round;
2484      }
2485    "#,
2486      indoc! {r#"
2487      .foo {
2488        border-image: url("foo.png") 10 40 fill / 10px round;
2489      }
2490    "#
2491      },
2492    );
2493
2494    test(
2495      r#"
2496      .foo {
2497        border-image: url(foo.png) 60;
2498        border-image-source: var(--test);
2499      }
2500    "#,
2501      indoc! {r#"
2502      .foo {
2503        border-image: url("foo.png") 60;
2504        border-image-source: var(--test);
2505      }
2506    "#
2507      },
2508    );
2509
2510    test(
2511      r#"
2512      .foo {
2513        -webkit-border-image: url("test.png") 60;
2514      }
2515    "#,
2516      indoc! {r#"
2517      .foo {
2518        -webkit-border-image: url("test.png") 60;
2519      }
2520    "#
2521      },
2522    );
2523
2524    test(
2525      r#"
2526      .foo {
2527        -webkit-border-image: url("test.png") 60;
2528        border-image: url("test.png") 60;
2529      }
2530    "#,
2531      indoc! {r#"
2532      .foo {
2533        -webkit-border-image: url("test.png") 60;
2534        border-image: url("test.png") 60;
2535      }
2536    "#
2537      },
2538    );
2539
2540    test(
2541      r#"
2542      .foo {
2543        -webkit-border-image: url("test.png") 60;
2544        border-image-source: url(foo.png);
2545      }
2546    "#,
2547      indoc! {r#"
2548      .foo {
2549        -webkit-border-image: url("test.png") 60;
2550        border-image-source: url("foo.png");
2551      }
2552    "#
2553      },
2554    );
2555
2556    test(
2557      r#"
2558      .foo {
2559        border: 1px solid red;
2560        border-image: url(test.png) 60;
2561      }
2562    "#,
2563      indoc! {r#"
2564      .foo {
2565        border: 1px solid red;
2566        border-image: url("test.png") 60;
2567      }
2568    "#
2569      },
2570    );
2571
2572    test(
2573      r#"
2574      .foo {
2575        border-image: url(test.png) 60;
2576        border: 1px solid red;
2577      }
2578    "#,
2579      indoc! {r#"
2580      .foo {
2581        border: 1px solid red;
2582      }
2583    "#
2584      },
2585    );
2586
2587    test(
2588      r#"
2589      .foo {
2590        border: 1px solid red;
2591        border-image: var(--border-image);
2592      }
2593    "#,
2594      indoc! {r#"
2595      .foo {
2596        border: 1px solid red;
2597        border-image: var(--border-image);
2598      }
2599    "#
2600      },
2601    );
2602
2603    prefix_test(
2604      r#"
2605      .foo {
2606        border-image: url("test.png") 60;
2607      }
2608    "#,
2609      indoc! {r#"
2610      .foo {
2611        -webkit-border-image: url("test.png") 60;
2612        -moz-border-image: url("test.png") 60;
2613        -o-border-image: url("test.png") 60;
2614        border-image: url("test.png") 60;
2615      }
2616    "#
2617      },
2618      Browsers {
2619        safari: Some(4 << 16),
2620        firefox: Some(4 << 16),
2621        opera: Some(12 << 16),
2622        ..Browsers::default()
2623      },
2624    );
2625
2626    prefix_test(
2627      r#"
2628      .foo {
2629        border-image: url(foo.png) 10 40 fill / 10px round;
2630      }
2631    "#,
2632      indoc! {r#"
2633      .foo {
2634        border-image: url("foo.png") 10 40 fill / 10px round;
2635      }
2636    "#
2637      },
2638      Browsers {
2639        safari: Some(4 << 16),
2640        firefox: Some(4 << 16),
2641        opera: Some(12 << 16),
2642        ..Browsers::default()
2643      },
2644    );
2645
2646    prefix_test(
2647      r#"
2648      .foo {
2649        border-image: var(--test) 60;
2650      }
2651    "#,
2652      indoc! {r#"
2653      .foo {
2654        -webkit-border-image: var(--test) 60;
2655        -moz-border-image: var(--test) 60;
2656        -o-border-image: var(--test) 60;
2657        border-image: var(--test) 60;
2658      }
2659    "#
2660      },
2661      Browsers {
2662        safari: Some(4 << 16),
2663        firefox: Some(4 << 16),
2664        opera: Some(12 << 16),
2665        ..Browsers::default()
2666      },
2667    );
2668
2669    prefix_test(
2670      r#"
2671      .foo {
2672        -webkit-border-image: url(foo.png) 60;
2673        -moz-border-image: url(foo.png) 60;
2674        -o-border-image: url(foo.png) 60;
2675        border-image: url(foo.png) 60;
2676      }
2677    "#,
2678      indoc! {r#"
2679      .foo {
2680        border-image: url("foo.png") 60;
2681      }
2682    "#
2683      },
2684      Browsers {
2685        chrome: Some(15 << 16),
2686        ..Browsers::default()
2687      },
2688    );
2689
2690    prefix_test(
2691      r#"
2692      .foo {
2693        border-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 60;
2694      }
2695    "#,
2696      indoc! {r#"
2697      .foo {
2698        -webkit-border-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ff0b0c), to(#766eff)) 60;
2699        -webkit-border-image: -webkit-linear-gradient(top, #ff0b0c, #766eff) 60;
2700        border-image: linear-gradient(#ff0b0c, #766eff) 60;
2701        border-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 60;
2702      }
2703    "#
2704      },
2705      Browsers {
2706        chrome: Some(8 << 16),
2707        ..Browsers::default()
2708      },
2709    );
2710
2711    prefix_test(
2712      r#"
2713      .foo {
2714        border-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 60;
2715      }
2716    "#,
2717      indoc! {r#"
2718      .foo {
2719        -webkit-border-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ff0b0c), to(#766eff)) 60;
2720        -webkit-border-image: -webkit-linear-gradient(top, #ff0b0c, #766eff) 60;
2721        -moz-border-image: -moz-linear-gradient(top, #ff0b0c, #766eff) 60;
2722        border-image: linear-gradient(#ff0b0c, #766eff) 60;
2723        border-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 60;
2724      }
2725    "#
2726      },
2727      Browsers {
2728        chrome: Some(8 << 16),
2729        firefox: Some(4 << 16),
2730        ..Browsers::default()
2731      },
2732    );
2733
2734    prefix_test(
2735      r#"
2736      .foo {
2737        border-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 60;
2738      }
2739    "#,
2740      indoc! {r#"
2741      .foo {
2742        border-image: -webkit-linear-gradient(top, #ff0b0c, #766eff) 60;
2743        border-image: -moz-linear-gradient(top, #ff0b0c, #766eff) 60;
2744        border-image: linear-gradient(#ff0b0c, #766eff) 60;
2745        border-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 60;
2746      }
2747    "#
2748      },
2749      Browsers {
2750        chrome: Some(15 << 16),
2751        firefox: Some(15 << 16),
2752        ..Browsers::default()
2753      },
2754    );
2755
2756    prefix_test(
2757      r#"
2758      .foo {
2759        border-image-source: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
2760      }
2761    "#,
2762      indoc! {r#"
2763      .foo {
2764        border-image-source: -webkit-linear-gradient(top, #ff0b0c, #766eff);
2765        border-image-source: linear-gradient(#ff0b0c, #766eff);
2766        border-image-source: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
2767      }
2768    "#
2769      },
2770      Browsers {
2771        chrome: Some(15 << 16),
2772        ..Browsers::default()
2773      },
2774    );
2775
2776    prefix_test(
2777      r#"
2778      .foo {
2779        border-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) var(--foo);
2780      }
2781    "#,
2782      indoc! {r#"
2783      .foo {
2784        border-image: linear-gradient(#ff0b0c, #766eff) var(--foo);
2785      }
2786
2787      @supports (color: lab(0% 0 0)) {
2788        .foo {
2789          border-image: linear-gradient(lab(56.208% 94.4644 98.8928), lab(51% 70.4544 -115.586)) var(--foo);
2790        }
2791      }
2792    "#
2793      },
2794      Browsers {
2795        chrome: Some(90 << 16),
2796        ..Browsers::default()
2797      },
2798    );
2799
2800    prefix_test(
2801      r#"
2802      .foo {
2803        border-image-source: linear-gradient(red, green);
2804        border-image-source: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
2805      }
2806    "#,
2807      indoc! {r#"
2808      .foo {
2809        border-image-source: linear-gradient(red, green);
2810        border-image-source: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
2811      }
2812    "#
2813      },
2814      Browsers {
2815        chrome: Some(95 << 16),
2816        ..Browsers::default()
2817      },
2818    );
2819
2820    prefix_test(
2821      r#"
2822      .foo {
2823        border-image-source: linear-gradient(red, green);
2824        border-image-source: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
2825      }
2826    "#,
2827      indoc! {r#"
2828      .foo {
2829        border-image-source: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
2830      }
2831    "#
2832      },
2833      Browsers {
2834        chrome: Some(112 << 16),
2835        ..Browsers::default()
2836      },
2837    );
2838
2839    prefix_test(
2840      r#"
2841      .foo {
2842        border-image: linear-gradient(red, green);
2843        border-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
2844      }
2845    "#,
2846      indoc! {r#"
2847      .foo {
2848        border-image: linear-gradient(red, green);
2849        border-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
2850      }
2851    "#
2852      },
2853      Browsers {
2854        chrome: Some(95 << 16),
2855        ..Browsers::default()
2856      },
2857    );
2858
2859    prefix_test(
2860      r#"
2861      .foo {
2862        border-image: var(--fallback);
2863        border-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
2864      }
2865    "#,
2866      indoc! {r#"
2867      .foo {
2868        border-image: var(--fallback);
2869        border-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
2870      }
2871    "#
2872      },
2873      Browsers {
2874        chrome: Some(95 << 16),
2875        ..Browsers::default()
2876      },
2877    );
2878
2879    prefix_test(
2880      r#"
2881      .foo {
2882        border-image: url("fallback.png") 10 40 fill / 10px;
2883        border-image: url("main.png") 10 40 fill / 10px space;
2884      }
2885    "#,
2886      indoc! {r#"
2887      .foo {
2888        border-image: url("fallback.png") 10 40 fill / 10px;
2889        border-image: url("main.png") 10 40 fill / 10px space;
2890      }
2891    "#
2892      },
2893      Browsers {
2894        chrome: Some(50 << 16),
2895        ..Browsers::default()
2896      },
2897    );
2898
2899    prefix_test(
2900      r#"
2901      .foo {
2902        border-image: url("fallback.png") 10 40 fill / 10px;
2903        border-image: url("main.png") 10 40 fill / 10px space;
2904      }
2905    "#,
2906      indoc! {r#"
2907      .foo {
2908        border-image: url("main.png") 10 40 fill / 10px space;
2909      }
2910    "#
2911      },
2912      Browsers {
2913        chrome: Some(56 << 16),
2914        ..Browsers::default()
2915      },
2916    );
2917
2918    minify_test(".foo { border: none green }", ".foo{border:green}");
2919  }
2920
2921  #[test]
2922  pub fn test_border_radius() {
2923    property_range_test(
2924      &["border-radius", "border-top-left-radius", "border-start-start-radius"],
2925      &[
2926        ("-1px", None),
2927        ("calc(1px - 2px)", Some("0")),
2928        ("calc(-1px + 2px)", Some("1px")),
2929        ("-1%", None),
2930        ("calc(1em - 2px)", Some("calc(1em - 2px)")),
2931        ("calc(-1%)", Some("calc(-1%)")),
2932      ],
2933    );
2934    test(
2935      r#"
2936      .foo {
2937        border-radius: 10px 100px 10px 100px;
2938      }
2939    "#,
2940      indoc! {r#"
2941      .foo {
2942        border-radius: 10px 100px;
2943      }
2944    "#
2945      },
2946    );
2947
2948    test(
2949      r#"
2950      .foo {
2951        border-radius: 10px 100px 10px 100px / 120px 120px;
2952      }
2953    "#,
2954      indoc! {r#"
2955      .foo {
2956        border-radius: 10px 100px / 120px;
2957      }
2958    "#
2959      },
2960    );
2961
2962    test(
2963      r#"
2964      .foo {
2965        border-top-left-radius: 10px 120px;
2966        border-top-right-radius: 100px 120px;
2967        border-bottom-right-radius: 100px 120px;
2968        border-bottom-left-radius: 10px 120px;
2969      }
2970    "#,
2971      indoc! {r#"
2972      .foo {
2973        border-radius: 10px 100px 100px 10px / 120px;
2974      }
2975    "#
2976      },
2977    );
2978
2979    test(
2980      r#"
2981      .foo {
2982        border-top-left-radius: 4px 2px;
2983        border-top-right-radius: 3px 4px;
2984        border-bottom-right-radius: 6px 2px;
2985        border-bottom-left-radius: 3px 4px;
2986      }
2987    "#,
2988      indoc! {r#"
2989      .foo {
2990        border-radius: 4px 3px 6px / 2px 4px;
2991      }
2992    "#
2993      },
2994    );
2995
2996    test(
2997      r#"
2998      .foo {
2999        border-top-left-radius: 1% 2%;
3000        border-top-right-radius: 3% 4%;
3001        border-bottom-right-radius: 5% 6%;
3002        border-bottom-left-radius: 7% 8%;
3003      }
3004    "#,
3005      indoc! {r#"
3006      .foo {
3007        border-radius: 1% 3% 5% 7% / 2% 4% 6% 8%;
3008      }
3009    "#
3010      },
3011    );
3012
3013    test(
3014      r#"
3015      .foo {
3016        border-radius: 10px 100px 10px 100px / 120px 120px;
3017        border-start-start-radius: 10px;
3018      }
3019    "#,
3020      indoc! {r#"
3021      .foo {
3022        border-radius: 10px 100px / 120px;
3023        border-start-start-radius: 10px;
3024      }
3025    "#
3026      },
3027    );
3028
3029    test(
3030      r#"
3031      .foo {
3032        border-start-start-radius: 10px;
3033        border-radius: 10px 100px 10px 100px / 120px 120px;
3034      }
3035    "#,
3036      indoc! {r#"
3037      .foo {
3038        border-radius: 10px 100px / 120px;
3039      }
3040    "#
3041      },
3042    );
3043
3044    test(
3045      r#"
3046      .foo {
3047        border-top-left-radius: 10px 120px;
3048        border-top-right-radius: 100px 120px;
3049        border-start-start-radius: 10px;
3050        border-bottom-right-radius: 100px 120px;
3051        border-bottom-left-radius: 10px 120px;
3052      }
3053    "#,
3054      indoc! {r#"
3055      .foo {
3056        border-top-left-radius: 10px 120px;
3057        border-top-right-radius: 100px 120px;
3058        border-start-start-radius: 10px;
3059        border-bottom-right-radius: 100px 120px;
3060        border-bottom-left-radius: 10px 120px;
3061      }
3062    "#
3063      },
3064    );
3065
3066    test(
3067      r#"
3068      .foo {
3069        border-radius: 10px;
3070        border-top-left-radius: 20px;
3071      }
3072    "#,
3073      indoc! {r#"
3074      .foo {
3075        border-radius: 20px 10px 10px;
3076      }
3077    "#
3078      },
3079    );
3080
3081    test(
3082      r#"
3083      .foo {
3084        border-radius: 10px;
3085        border-top-left-radius: var(--test);
3086      }
3087    "#,
3088      indoc! {r#"
3089      .foo {
3090        border-radius: 10px;
3091        border-top-left-radius: var(--test);
3092      }
3093    "#
3094      },
3095    );
3096
3097    test(
3098      r#"
3099      .foo {
3100        -webkit-border-radius: 10px 100px 10px 100px;
3101        -moz-border-radius: 10px 100px 10px 100px;
3102        border-radius: 10px 100px 10px 100px;
3103      }
3104    "#,
3105      indoc! {r#"
3106      .foo {
3107        -webkit-border-radius: 10px 100px;
3108        -moz-border-radius: 10px 100px;
3109        border-radius: 10px 100px;
3110      }
3111    "#
3112      },
3113    );
3114
3115    test(
3116      r#"
3117      .foo {
3118        -webkit-border-radius: 10px 100px 10px 100px;
3119        -moz-border-radius: 20px;
3120        border-radius: 30px;
3121      }
3122    "#,
3123      indoc! {r#"
3124      .foo {
3125        -webkit-border-radius: 10px 100px;
3126        -moz-border-radius: 20px;
3127        border-radius: 30px;
3128      }
3129    "#
3130      },
3131    );
3132
3133    test(
3134      r#"
3135      .foo {
3136        -webkit-border-top-left-radius: 10px;
3137        -moz-border-top-left-radius: 10px;
3138        border-top-left-radius: 10px;
3139      }
3140    "#,
3141      indoc! {r#"
3142      .foo {
3143        -webkit-border-top-left-radius: 10px;
3144        -moz-border-top-left-radius: 10px;
3145        border-top-left-radius: 10px;
3146      }
3147    "#
3148      },
3149    );
3150
3151    prefix_test(
3152      r#"
3153      .foo {
3154        border-radius: 30px;
3155      }
3156    "#,
3157      indoc! {r#"
3158      .foo {
3159        -webkit-border-radius: 30px;
3160        -moz-border-radius: 30px;
3161        border-radius: 30px;
3162      }
3163    "#
3164      },
3165      Browsers {
3166        safari: Some(4 << 16),
3167        firefox: Some(3 << 16),
3168        ..Browsers::default()
3169      },
3170    );
3171
3172    prefix_test(
3173      r#"
3174      .foo {
3175        border-top-left-radius: 30px;
3176      }
3177    "#,
3178      indoc! {r#"
3179      .foo {
3180        -webkit-border-top-left-radius: 30px;
3181        -moz-border-top-left-radius: 30px;
3182        border-top-left-radius: 30px;
3183      }
3184    "#
3185      },
3186      Browsers {
3187        safari: Some(4 << 16),
3188        firefox: Some(3 << 16),
3189        ..Browsers::default()
3190      },
3191    );
3192
3193    prefix_test(
3194      r#"
3195      .foo {
3196        -webkit-border-radius: 30px;
3197        -moz-border-radius: 30px;
3198        border-radius: 30px;
3199      }
3200    "#,
3201      indoc! {r#"
3202      .foo {
3203        border-radius: 30px;
3204      }
3205    "#
3206      },
3207      Browsers {
3208        safari: Some(14 << 16),
3209        firefox: Some(46 << 16),
3210        ..Browsers::default()
3211      },
3212    );
3213
3214    prefix_test(
3215      r#"
3216      .foo {
3217        -webkit-border-top-left-radius: 30px;
3218        -moz-border-top-left-radius: 30px;
3219        border-top-left-radius: 30px;
3220      }
3221    "#,
3222      indoc! {r#"
3223      .foo {
3224        border-top-left-radius: 30px;
3225      }
3226    "#
3227      },
3228      Browsers {
3229        safari: Some(14 << 16),
3230        firefox: Some(46 << 16),
3231        ..Browsers::default()
3232      },
3233    );
3234
3235    prefix_test(
3236      r#"
3237      .foo {
3238        -webkit-border-radius: 30px;
3239        -moz-border-radius: 30px;
3240      }
3241    "#,
3242      indoc! {r#"
3243      .foo {
3244        -webkit-border-radius: 30px;
3245        -moz-border-radius: 30px;
3246      }
3247    "#
3248      },
3249      Browsers {
3250        safari: Some(14 << 16),
3251        firefox: Some(46 << 16),
3252        ..Browsers::default()
3253      },
3254    );
3255
3256    prefix_test(
3257      r#"
3258      .foo {
3259        -webkit-border-top-left-radius: 30px;
3260        -moz-border-top-right-radius: 30px;
3261        border-bottom-right-radius: 30px;
3262        border-bottom-left-radius: 30px;
3263      }
3264    "#,
3265      indoc! {r#"
3266      .foo {
3267        -webkit-border-top-left-radius: 30px;
3268        -moz-border-top-right-radius: 30px;
3269        border-bottom-right-radius: 30px;
3270        border-bottom-left-radius: 30px;
3271      }
3272    "#
3273      },
3274      Browsers {
3275        safari: Some(14 << 16),
3276        firefox: Some(46 << 16),
3277        ..Browsers::default()
3278      },
3279    );
3280
3281    prefix_test(
3282      r#"
3283      .foo {
3284        border-radius: var(--test);
3285      }
3286    "#,
3287      indoc! {r#"
3288      .foo {
3289        -webkit-border-radius: var(--test);
3290        -moz-border-radius: var(--test);
3291        border-radius: var(--test);
3292      }
3293    "#
3294      },
3295      Browsers {
3296        safari: Some(4 << 16),
3297        firefox: Some(3 << 16),
3298        ..Browsers::default()
3299      },
3300    );
3301
3302    prefix_test(
3303      r#"
3304      .foo {
3305        border-start-start-radius: 5px;
3306      }
3307    "#,
3308      indoc! {r#"
3309      .foo:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
3310        border-top-left-radius: 5px;
3311      }
3312
3313      .foo:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
3314        border-top-right-radius: 5px;
3315      }
3316    "#
3317      },
3318      Browsers {
3319        safari: Some(12 << 16),
3320        ..Browsers::default()
3321      },
3322    );
3323
3324    prefix_test(
3325      r#"
3326      .foo {
3327        border-start-start-radius: 5px;
3328        border-start-end-radius: 10px;
3329      }
3330    "#,
3331      indoc! {r#"
3332      .foo:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
3333        border-top-left-radius: 5px;
3334        border-top-right-radius: 10px;
3335      }
3336
3337      .foo:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
3338        border-top-left-radius: 10px;
3339        border-top-right-radius: 5px;
3340      }
3341    "#
3342      },
3343      Browsers {
3344        safari: Some(12 << 16),
3345        ..Browsers::default()
3346      },
3347    );
3348
3349    prefix_test(
3350      r#"
3351      .foo {
3352        border-end-end-radius: 10px;
3353        border-end-start-radius: 5px;
3354      }
3355    "#,
3356      indoc! {r#"
3357      .foo:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
3358        border-bottom-right-radius: 10px;
3359        border-bottom-left-radius: 5px;
3360      }
3361
3362      .foo:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
3363        border-bottom-right-radius: 5px;
3364        border-bottom-left-radius: 10px;
3365      }
3366    "#
3367      },
3368      Browsers {
3369        safari: Some(12 << 16),
3370        ..Browsers::default()
3371      },
3372    );
3373
3374    prefix_test(
3375      r#"
3376      .foo {
3377        border-start-start-radius: var(--radius);
3378      }
3379    "#,
3380      indoc! {r#"
3381      .foo:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
3382        border-top-left-radius: var(--radius);
3383      }
3384
3385      .foo:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
3386        border-top-right-radius: var(--radius);
3387      }
3388    "#
3389      },
3390      Browsers {
3391        safari: Some(12 << 16),
3392        ..Browsers::default()
3393      },
3394    );
3395
3396    prefix_test(
3397      r#"
3398      .foo {
3399        border-start-start-radius: var(--start);
3400        border-start-end-radius: var(--end);
3401      }
3402    "#,
3403      indoc! {r#"
3404      .foo:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
3405        border-top-left-radius: var(--start);
3406        border-top-right-radius: var(--end);
3407      }
3408
3409      .foo:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
3410        border-top-right-radius: var(--start);
3411        border-top-left-radius: var(--end);
3412      }
3413    "#
3414      },
3415      Browsers {
3416        safari: Some(12 << 16),
3417        ..Browsers::default()
3418      },
3419    );
3420  }
3421
3422  #[test]
3423  pub fn test_outline() {
3424    test(
3425      r#"
3426      .foo {
3427        outline-width: 2px;
3428        outline-style: solid;
3429        outline-color: blue;
3430      }
3431    "#,
3432      indoc! {r#"
3433      .foo {
3434        outline: 2px solid #00f;
3435      }
3436    "#
3437      },
3438    );
3439
3440    test(
3441      r#"
3442      .foo {
3443        outline: 2px solid blue;
3444      }
3445    "#,
3446      indoc! {r#"
3447      .foo {
3448        outline: 2px solid #00f;
3449      }
3450    "#
3451      },
3452    );
3453
3454    test(
3455      r#"
3456      .foo {
3457        outline: 2px solid red;
3458        outline-color: blue;
3459      }
3460    "#,
3461      indoc! {r#"
3462      .foo {
3463        outline: 2px solid #00f;
3464      }
3465    "#
3466      },
3467    );
3468
3469    test(
3470      r#"
3471      .foo {
3472        outline: 2px solid yellow;
3473        outline-color: var(--color);
3474      }
3475    "#,
3476      indoc! {r#"
3477      .foo {
3478        outline: 2px solid #ff0;
3479        outline-color: var(--color);
3480      }
3481    "#
3482      },
3483    );
3484
3485    prefix_test(
3486      ".foo { outline-color: lab(40% 56.6 39) }",
3487      indoc! { r#"
3488        .foo {
3489          outline-color: #b32323;
3490          outline-color: lab(40% 56.6 39);
3491        }
3492      "#},
3493      Browsers {
3494        chrome: Some(90 << 16),
3495        ..Browsers::default()
3496      },
3497    );
3498
3499    prefix_test(
3500      ".foo { outline: 2px solid lab(40% 56.6 39) }",
3501      indoc! { r#"
3502        .foo {
3503          outline: 2px solid #b32323;
3504          outline: 2px solid lab(40% 56.6 39);
3505        }
3506      "#},
3507      Browsers {
3508        chrome: Some(90 << 16),
3509        ..Browsers::default()
3510      },
3511    );
3512
3513    prefix_test(
3514      ".foo { outline: var(--width) solid lab(40% 56.6 39) }",
3515      indoc! { r#"
3516        .foo {
3517          outline: var(--width) solid #b32323;
3518        }
3519
3520        @supports (color: lab(0% 0 0)) {
3521          .foo {
3522            outline: var(--width) solid lab(40% 56.6 39);
3523          }
3524        }
3525      "#},
3526      Browsers {
3527        chrome: Some(90 << 16),
3528        ..Browsers::default()
3529      },
3530    );
3531  }
3532
3533  #[test]
3534  pub fn test_margin() {
3535    property_range_test(&["margin", "inset", "scroll-margin"], &[("-1px", Some("-1px"))]);
3536    test(
3537      r#"
3538      .foo {
3539        margin-left: 10px;
3540        margin-right: 10px;
3541        margin-top: 20px;
3542        margin-bottom: 20px;
3543      }
3544    "#,
3545      indoc! {r#"
3546      .foo {
3547        margin: 20px 10px;
3548      }
3549    "#
3550      },
3551    );
3552
3553    test(
3554      r#"
3555      .foo {
3556        margin-block-start: 15px;
3557        margin-block-end: 15px;
3558      }
3559    "#,
3560      indoc! {r#"
3561      .foo {
3562        margin-block: 15px;
3563      }
3564    "#
3565      },
3566    );
3567
3568    test(
3569      r#"
3570      .foo {
3571        margin-left: 10px;
3572        margin-right: 10px;
3573        margin-inline-start: 15px;
3574        margin-inline-end: 15px;
3575        margin-top: 20px;
3576        margin-bottom: 20px;
3577
3578      }
3579    "#,
3580      indoc! {r#"
3581      .foo {
3582        margin-left: 10px;
3583        margin-right: 10px;
3584        margin-inline: 15px;
3585        margin-top: 20px;
3586        margin-bottom: 20px;
3587      }
3588    "#
3589      },
3590    );
3591
3592    test(
3593      r#"
3594      .foo {
3595        margin: 10px;
3596        margin-top: 20px;
3597      }
3598    "#,
3599      indoc! {r#"
3600      .foo {
3601        margin: 20px 10px 10px;
3602      }
3603    "#
3604      },
3605    );
3606
3607    test(
3608      r#"
3609      .foo {
3610        margin: 10px;
3611        margin-top: var(--top);
3612      }
3613    "#,
3614      indoc! {r#"
3615      .foo {
3616        margin: 10px;
3617        margin-top: var(--top);
3618      }
3619    "#
3620      },
3621    );
3622
3623    prefix_test(
3624      r#"
3625      .foo {
3626        margin-inline-start: 2px;
3627      }
3628    "#,
3629      indoc! {r#"
3630      .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))) {
3631        margin-left: 2px;
3632      }
3633
3634      .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))) {
3635        margin-left: 2px;
3636      }
3637
3638      .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)) {
3639        margin-right: 2px;
3640      }
3641
3642      .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)) {
3643        margin-right: 2px;
3644      }
3645    "#
3646      },
3647      Browsers {
3648        safari: Some(8 << 16),
3649        ..Browsers::default()
3650      },
3651    );
3652
3653    prefix_test(
3654      r#"
3655      .foo {
3656        margin-inline-start: 2px;
3657        margin-inline-end: 4px;
3658      }
3659    "#,
3660      indoc! {r#"
3661      .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))) {
3662        margin-left: 2px;
3663        margin-right: 4px;
3664      }
3665
3666      .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))) {
3667        margin-left: 2px;
3668        margin-right: 4px;
3669      }
3670
3671      .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)) {
3672        margin-left: 4px;
3673        margin-right: 2px;
3674      }
3675
3676      .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)) {
3677        margin-left: 4px;
3678        margin-right: 2px;
3679      }
3680    "#
3681      },
3682      Browsers {
3683        safari: Some(8 << 16),
3684        ..Browsers::default()
3685      },
3686    );
3687
3688    prefix_test(
3689      r#"
3690      .foo {
3691        margin-inline: 2px;
3692      }
3693    "#,
3694      indoc! {r#"
3695      .foo {
3696        margin-left: 2px;
3697        margin-right: 2px;
3698      }
3699    "#
3700      },
3701      Browsers {
3702        safari: Some(8 << 16),
3703        ..Browsers::default()
3704      },
3705    );
3706
3707    prefix_test(
3708      r#"
3709      .foo {
3710        margin-block-start: 2px;
3711      }
3712    "#,
3713      indoc! {r#"
3714      .foo {
3715        margin-top: 2px;
3716      }
3717    "#
3718      },
3719      Browsers {
3720        safari: Some(8 << 16),
3721        ..Browsers::default()
3722      },
3723    );
3724
3725    prefix_test(
3726      r#"
3727      .foo {
3728        margin-block-end: 2px;
3729      }
3730    "#,
3731      indoc! {r#"
3732      .foo {
3733        margin-bottom: 2px;
3734      }
3735    "#
3736      },
3737      Browsers {
3738        safari: Some(8 << 16),
3739        ..Browsers::default()
3740      },
3741    );
3742
3743    prefix_test(
3744      r#"
3745      .foo {
3746        margin-inline-start: 2px;
3747        margin-inline-end: 2px;
3748      }
3749    "#,
3750      indoc! {r#"
3751      .foo {
3752        margin-inline-start: 2px;
3753        margin-inline-end: 2px;
3754      }
3755    "#
3756      },
3757      Browsers {
3758        safari: Some(13 << 16),
3759        ..Browsers::default()
3760      },
3761    );
3762
3763    prefix_test(
3764      r#"
3765      .foo {
3766        margin-inline: 2px;
3767      }
3768    "#,
3769      indoc! {r#"
3770      .foo {
3771        margin-inline-start: 2px;
3772        margin-inline-end: 2px;
3773      }
3774    "#
3775      },
3776      Browsers {
3777        safari: Some(13 << 16),
3778        ..Browsers::default()
3779      },
3780    );
3781
3782    prefix_test(
3783      r#"
3784      .foo {
3785        margin-inline-start: 2px;
3786        margin-inline-end: 2px;
3787      }
3788    "#,
3789      indoc! {r#"
3790      .foo {
3791        margin-inline: 2px;
3792      }
3793    "#
3794      },
3795      Browsers {
3796        safari: Some(15 << 16),
3797        ..Browsers::default()
3798      },
3799    );
3800
3801    prefix_test(
3802      r#"
3803      .foo {
3804        margin-inline: 2px;
3805      }
3806    "#,
3807      indoc! {r#"
3808      .foo {
3809        margin-inline: 2px;
3810      }
3811    "#
3812      },
3813      Browsers {
3814        safari: Some(15 << 16),
3815        ..Browsers::default()
3816      },
3817    );
3818  }
3819
3820  #[test]
3821  fn test_length() {
3822    use crate::values::length::{Length, LengthOrNumber, LengthPercentage, LengthPercentageOrAuto, LengthValue};
3823    use crate::values::number::NonNegative;
3824
3825    for source in ["-1px", "-1em", "-1vw", "-1"] {
3826      non_negative_test::<LengthValue>(source, None);
3827      non_negative_test::<Length>(source, None);
3828      non_negative_test::<LengthPercentage>(source, None);
3829      non_negative_test::<LengthPercentageOrAuto>(source, None);
3830      non_negative_test::<LengthOrNumber>(source, None);
3831      assert!(Length::parse_string(source).is_ok());
3832    }
3833    for source in ["0", "-0", "-0px"] {
3834      non_negative_test::<LengthValue>(source, Some("0"));
3835      non_negative_test::<Length>(source, Some("0"));
3836    }
3837    non_negative_test::<LengthValue>("2em", Some("2em"));
3838    non_negative_test::<LengthPercentage>("-1%", None);
3839    non_negative_test::<LengthPercentage>("10%", Some("10%"));
3840    non_negative_test::<LengthPercentageOrAuto>("auto", Some("auto"));
3841    non_negative_test::<LengthPercentageOrAuto>("-1%", None);
3842    non_negative_test::<LengthOrNumber>("2", Some("2"));
3843    non_negative_test::<LengthOrNumber>("2px", Some("2px"));
3844    non_negative_test::<LengthOrNumber>("calc(-2)", Some("0"));
3845    non_negative_test::<LengthOrNumber>("calc(-2px)", Some("0"));
3846
3847    // Backtracking a rejected range must leave the input available to another parser.
3848    let mut input = cssparser::ParserInput::new("-1px");
3849    let mut parser = cssparser::Parser::new(&mut input);
3850    assert!(parser.try_parse(NonNegative::<Length>::parse).is_err());
3851    assert_eq!(Length::parse(&mut parser).unwrap(), Length::px(-1.0));
3852
3853    for prop in &[
3854      "margin-right",
3855      "margin",
3856      "padding-right",
3857      "padding",
3858      "width",
3859      "height",
3860      "min-height",
3861      "max-height",
3862      "line-height",
3863      "border-radius",
3864    ] {
3865      prefix_test(
3866        &format!(
3867          r#"
3868        .foo {{
3869          {}: 22px;
3870          {}: max(4%, 22px);
3871        }}
3872      "#,
3873          prop, prop
3874        ),
3875        &format!(
3876          indoc! {r#"
3877        .foo {{
3878          {}: 22px;
3879          {}: max(4%, 22px);
3880        }}
3881      "#
3882          },
3883          prop, prop
3884        ),
3885        Browsers {
3886          safari: Some(10 << 16),
3887          ..Browsers::default()
3888        },
3889      );
3890
3891      prefix_test(
3892        &format!(
3893          r#"
3894        .foo {{
3895          {}: 22px;
3896          {}: max(4%, 22px);
3897        }}
3898      "#,
3899          prop, prop
3900        ),
3901        &format!(
3902          indoc! {r#"
3903        .foo {{
3904          {}: max(4%, 22px);
3905        }}
3906      "#
3907          },
3908          prop
3909        ),
3910        Browsers {
3911          safari: Some(14 << 16),
3912          ..Browsers::default()
3913        },
3914      );
3915
3916      prefix_test(
3917        &format!(
3918          r#"
3919        .foo {{
3920          {}: 22px;
3921          {}: max(2cqw, 22px);
3922        }}
3923      "#,
3924          prop, prop
3925        ),
3926        &format!(
3927          indoc! {r#"
3928        .foo {{
3929          {}: 22px;
3930          {}: max(2cqw, 22px);
3931        }}
3932      "#
3933          },
3934          prop, prop
3935        ),
3936        Browsers {
3937          safari: Some(14 << 16),
3938          ..Browsers::default()
3939        },
3940      );
3941      prefix_test(
3942        &format!(
3943          r#"
3944        .foo {{
3945          {}: 22px;
3946          {}: max(2cqw, 22px);
3947        }}
3948      "#,
3949          prop, prop
3950        ),
3951        &format!(
3952          indoc! {r#"
3953        .foo {{
3954          {}: max(2cqw, 22px);
3955        }}
3956      "#
3957          },
3958          prop
3959        ),
3960        Browsers {
3961          safari: Some(16 << 16),
3962          ..Browsers::default()
3963        },
3964      );
3965    }
3966  }
3967
3968  #[test]
3969  pub fn test_padding() {
3970    property_range_test(
3971      &[
3972        "padding",
3973        "padding-inline",
3974        "padding-block",
3975        "padding-top",
3976        "padding-inline-start",
3977      ],
3978      &[
3979        ("-1px", None),
3980        ("calc(1px - 2px)", Some("0")),
3981        ("calc(-1px + 2px)", Some("1px")),
3982        ("-1%", None),
3983        ("calc(1em - 2px)", Some("calc(1em - 2px)")),
3984        ("calc(-1%)", Some("calc(-1%)")),
3985        ("auto", None),
3986        ("1px -1px", None),
3987      ],
3988    );
3989    test(
3990      r#"
3991      .foo {
3992        padding-left: 10px;
3993        padding-right: 10px;
3994        padding-top: 20px;
3995        padding-bottom: 20px;
3996      }
3997    "#,
3998      indoc! {r#"
3999      .foo {
4000        padding: 20px 10px;
4001      }
4002    "#
4003      },
4004    );
4005
4006    test(
4007      r#"
4008      .foo {
4009        padding-block-start: 15px;
4010        padding-block-end: 15px;
4011      }
4012    "#,
4013      indoc! {r#"
4014      .foo {
4015        padding-block: 15px;
4016      }
4017    "#
4018      },
4019    );
4020
4021    test(
4022      r#"
4023      .foo {
4024        padding-left: 10px;
4025        padding-right: 10px;
4026        padding-inline-start: 15px;
4027        padding-inline-end: 15px;
4028        padding-top: 20px;
4029        padding-bottom: 20px;
4030
4031      }
4032    "#,
4033      indoc! {r#"
4034      .foo {
4035        padding-left: 10px;
4036        padding-right: 10px;
4037        padding-inline: 15px;
4038        padding-top: 20px;
4039        padding-bottom: 20px;
4040      }
4041    "#
4042      },
4043    );
4044
4045    prefix_test(
4046      r#"
4047      .foo {
4048        padding-inline-start: 2px;
4049      }
4050    "#,
4051      indoc! {r#"
4052      .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))) {
4053        padding-left: 2px;
4054      }
4055
4056      .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))) {
4057        padding-left: 2px;
4058      }
4059
4060      .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)) {
4061        padding-right: 2px;
4062      }
4063
4064      .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)) {
4065        padding-right: 2px;
4066      }
4067    "#
4068      },
4069      Browsers {
4070        safari: Some(8 << 16),
4071        ..Browsers::default()
4072      },
4073    );
4074
4075    prefix_test(
4076      r#"
4077      .foo {
4078        padding-inline-start: 2px;
4079        padding-inline-end: 4px;
4080      }
4081    "#,
4082      indoc! {r#"
4083      .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))) {
4084        padding-left: 2px;
4085        padding-right: 4px;
4086      }
4087
4088      .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))) {
4089        padding-left: 2px;
4090        padding-right: 4px;
4091      }
4092
4093      .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)) {
4094        padding-left: 4px;
4095        padding-right: 2px;
4096      }
4097
4098      .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)) {
4099        padding-left: 4px;
4100        padding-right: 2px;
4101      }
4102    "#
4103      },
4104      Browsers {
4105        safari: Some(8 << 16),
4106        ..Browsers::default()
4107      },
4108    );
4109
4110    prefix_test(
4111      r#"
4112      .foo {
4113        padding-inline-start: var(--padding);
4114      }
4115    "#,
4116      indoc! {r#"
4117      .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))) {
4118        padding-left: var(--padding);
4119      }
4120
4121      .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))) {
4122        padding-left: var(--padding);
4123      }
4124
4125      .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)) {
4126        padding-right: var(--padding);
4127      }
4128
4129      .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)) {
4130        padding-right: var(--padding);
4131      }
4132    "#
4133      },
4134      Browsers {
4135        safari: Some(8 << 16),
4136        ..Browsers::default()
4137      },
4138    );
4139
4140    prefix_test(
4141      r#"
4142      .foo {
4143        padding-inline: 2px;
4144      }
4145    "#,
4146      indoc! {r#"
4147      .foo {
4148        padding-left: 2px;
4149        padding-right: 2px;
4150      }
4151    "#
4152      },
4153      Browsers {
4154        safari: Some(8 << 16),
4155        ..Browsers::default()
4156      },
4157    );
4158
4159    prefix_test(
4160      r#"
4161      .foo {
4162        padding-block-start: 2px;
4163      }
4164    "#,
4165      indoc! {r#"
4166      .foo {
4167        padding-top: 2px;
4168      }
4169    "#
4170      },
4171      Browsers {
4172        safari: Some(8 << 16),
4173        ..Browsers::default()
4174      },
4175    );
4176
4177    prefix_test(
4178      r#"
4179      .foo {
4180        padding-block-end: 2px;
4181      }
4182    "#,
4183      indoc! {r#"
4184      .foo {
4185        padding-bottom: 2px;
4186      }
4187    "#
4188      },
4189      Browsers {
4190        safari: Some(8 << 16),
4191        ..Browsers::default()
4192      },
4193    );
4194
4195    prefix_test(
4196      r#"
4197      .foo {
4198        padding-top: 1px;
4199        padding-left: 2px;
4200        padding-bottom: 3px;
4201        padding-right: 4px;
4202      }
4203    "#,
4204      indoc! {r#"
4205      .foo {
4206        padding: 1px 4px 3px 2px;
4207      }
4208    "#},
4209      Browsers {
4210        safari: Some(8 << 16),
4211        ..Browsers::default()
4212      },
4213    );
4214
4215    prefix_test(
4216      r#"
4217      .foo {
4218        padding-inline-start: 2px;
4219        padding-inline-end: 2px;
4220      }
4221    "#,
4222      indoc! {r#"
4223      .foo {
4224        padding-inline-start: 2px;
4225        padding-inline-end: 2px;
4226      }
4227    "#
4228      },
4229      Browsers {
4230        safari: Some(13 << 16),
4231        ..Browsers::default()
4232      },
4233    );
4234
4235    prefix_test(
4236      r#"
4237      .foo {
4238        padding-inline-start: 2px;
4239        padding-inline-end: 2px;
4240      }
4241    "#,
4242      indoc! {r#"
4243      .foo {
4244        padding-inline: 2px;
4245      }
4246    "#
4247      },
4248      Browsers {
4249        safari: Some(15 << 16),
4250        ..Browsers::default()
4251      },
4252    );
4253  }
4254
4255  #[test]
4256  fn test_scroll_padding() {
4257    property_range_test(
4258      &["scroll-padding", "scroll-padding-inline", "scroll-padding-top"],
4259      &[
4260        ("-1px", None),
4261        ("calc(1px - 2px)", Some("0")),
4262        ("calc(-1px + 2px)", Some("1px")),
4263        ("-1%", None),
4264        ("calc(1em - 2px)", Some("calc(1em - 2px)")),
4265        ("calc(-1%)", Some("calc(-1%)")),
4266        ("auto", Some("auto")),
4267      ],
4268    );
4269    prefix_test(
4270      r#"
4271      .foo {
4272        scroll-padding-inline: 2px;
4273      }
4274    "#,
4275      indoc! {r#"
4276      .foo {
4277        scroll-padding-inline: 2px;
4278      }
4279    "#
4280      },
4281      Browsers {
4282        safari: Some(8 << 16),
4283        ..Browsers::default()
4284      },
4285    );
4286  }
4287
4288  #[test]
4289  fn test_size() {
4290    minify_test(".foo { width: 10px; width: -1px }", ".foo{width:10px;width:-1px}");
4291    // `include: VendorPrefixes` asks for every prefix, but stretch only has
4292    // -webkit- and -moz- forms (#1371).
4293    for prop in ["height", "max-height"] {
4294      let source = format!(".foo {{ {}: stretch }}", prop);
4295      let targets = Targets {
4296        browsers: None,
4297        include: Features::VendorPrefixes,
4298        exclude: Features::empty(),
4299      };
4300      let mut stylesheet = StyleSheet::parse(&source, ParserOptions::default()).unwrap();
4301      stylesheet
4302        .minify(MinifyOptions {
4303          targets,
4304          ..MinifyOptions::default()
4305        })
4306        .unwrap();
4307      let res = stylesheet
4308        .to_css(PrinterOptions {
4309          targets,
4310          ..PrinterOptions::default()
4311        })
4312        .unwrap();
4313      assert_eq!(
4314        res.code,
4315        format!(
4316          ".foo {{\n  {0}: -webkit-fill-available;\n  {0}: -moz-available;\n  {0}: stretch;\n}}\n",
4317          prop
4318        )
4319      );
4320    }
4321    property_range_test(
4322      &["aspect-ratio"],
4323      &[
4324        ("-1 / 2", None),
4325        ("1 / -2", None),
4326        ("calc(-1) / 2", Some("0/2")),
4327        ("0 / 0", Some("0/0")),
4328      ],
4329    );
4330    property_range_test(
4331      &["width", "max-height"],
4332      &[
4333        ("fit-content(-1px)", None),
4334        ("fit-content(calc(-1px))", Some("fit-content(0)")),
4335      ],
4336    );
4337    property_range_test(
4338      &[
4339        "width",
4340        "height",
4341        "min-width",
4342        "max-width",
4343        "min-height",
4344        "max-height",
4345        "block-size",
4346        "inline-size",
4347        "min-block-size",
4348        "max-inline-size",
4349      ],
4350      &[
4351        ("-1px", None),
4352        ("calc(1px - 2px)", Some("0")),
4353        ("calc(-1px + 2px)", Some("1px")),
4354        ("-1%", None),
4355        ("calc(1em - 2px)", Some("calc(1em - 2px)")),
4356        ("calc(-1%)", Some("calc(-1%)")),
4357      ],
4358    );
4359    prefix_test(
4360      r#"
4361      .foo {
4362        block-size: 25px;
4363        inline-size: 25px;
4364        min-block-size: 25px;
4365        min-inline-size: 25px;
4366      }
4367    "#,
4368      indoc! {r#"
4369      .foo {
4370        height: 25px;
4371        min-height: 25px;
4372        width: 25px;
4373        min-width: 25px;
4374      }
4375    "#},
4376      Browsers {
4377        safari: Some(8 << 16),
4378        ..Browsers::default()
4379      },
4380    );
4381
4382    prefix_test(
4383      r#"
4384      .foo {
4385        block-size: 25px;
4386        min-block-size: 25px;
4387        inline-size: 25px;
4388        min-inline-size: 25px;
4389      }
4390    "#,
4391      indoc! {r#"
4392      .foo {
4393        block-size: 25px;
4394        min-block-size: 25px;
4395        inline-size: 25px;
4396        min-inline-size: 25px;
4397      }
4398    "#},
4399      Browsers {
4400        safari: Some(14 << 16),
4401        ..Browsers::default()
4402      },
4403    );
4404
4405    prefix_test(
4406      r#"
4407      .foo {
4408        block-size: var(--size);
4409        min-block-size: var(--size);
4410        inline-size: var(--size);
4411        min-inline-size: var(--size);
4412      }
4413    "#,
4414      indoc! {r#"
4415      .foo {
4416        height: var(--size);
4417        min-height: var(--size);
4418        width: var(--size);
4419        min-width: var(--size);
4420      }
4421    "#},
4422      Browsers {
4423        safari: Some(8 << 16),
4424        ..Browsers::default()
4425      },
4426    );
4427
4428    for (in_prop, out_prop) in [
4429      ("width", "width"),
4430      ("height", "height"),
4431      ("block-size", "height"),
4432      ("inline-size", "width"),
4433      ("min-width", "min-width"),
4434      ("min-height", "min-height"),
4435      ("min-block-size", "min-height"),
4436      ("min-inline-size", "min-width"),
4437      ("max-width", "max-width"),
4438      ("max-height", "max-height"),
4439      ("max-block-size", "max-height"),
4440      ("max-inline-size", "max-width"),
4441    ] {
4442      prefix_test(
4443        &format!(
4444          r#"
4445        .foo {{
4446          {}: stretch;
4447        }}
4448      "#,
4449          in_prop
4450        ),
4451        &format!(
4452          indoc! {r#"
4453        .foo {{
4454          {}: -webkit-fill-available;
4455          {}: -moz-available;
4456          {}: stretch;
4457        }}
4458      "#},
4459          out_prop, out_prop, out_prop
4460        ),
4461        Browsers {
4462          safari: Some(8 << 16),
4463          firefox: Some(4 << 16),
4464          ..Browsers::default()
4465        },
4466      );
4467
4468      prefix_test(
4469        &format!(
4470          r#"
4471        .foo {{
4472          {}: -webkit-fill-available;
4473        }}
4474      "#,
4475          in_prop
4476        ),
4477        &format!(
4478          indoc! {r#"
4479        .foo {{
4480          {}: -webkit-fill-available;
4481        }}
4482      "#},
4483          out_prop
4484        ),
4485        Browsers {
4486          safari: Some(8 << 16),
4487          firefox: Some(4 << 16),
4488          ..Browsers::default()
4489        },
4490      );
4491
4492      prefix_test(
4493        &format!(
4494          r#"
4495        .foo {{
4496          {}: 100vw;
4497          {}: -webkit-fill-available;
4498        }}
4499      "#,
4500          in_prop, in_prop
4501        ),
4502        &format!(
4503          indoc! {r#"
4504        .foo {{
4505          {}: 100vw;
4506          {}: -webkit-fill-available;
4507        }}
4508      "#},
4509          out_prop, out_prop
4510        ),
4511        Browsers {
4512          safari: Some(8 << 16),
4513          firefox: Some(4 << 16),
4514          ..Browsers::default()
4515        },
4516      );
4517
4518      prefix_test(
4519        &format!(
4520          r#"
4521        .foo {{
4522          {}: fit-content;
4523        }}
4524      "#,
4525          in_prop
4526        ),
4527        &format!(
4528          indoc! {r#"
4529        .foo {{
4530          {}: -webkit-fit-content;
4531          {}: -moz-fit-content;
4532          {}: fit-content;
4533        }}
4534      "#},
4535          out_prop, out_prop, out_prop
4536        ),
4537        Browsers {
4538          safari: Some(8 << 16),
4539          firefox: Some(4 << 16),
4540          ..Browsers::default()
4541        },
4542      );
4543
4544      prefix_test(
4545        &format!(
4546          r#"
4547        .foo {{
4548          {}: fit-content(50%);
4549        }}
4550      "#,
4551          in_prop
4552        ),
4553        &format!(
4554          indoc! {r#"
4555        .foo {{
4556          {}: fit-content(50%);
4557        }}
4558      "#},
4559          out_prop
4560        ),
4561        Browsers {
4562          safari: Some(8 << 16),
4563          firefox: Some(4 << 16),
4564          ..Browsers::default()
4565        },
4566      );
4567
4568      prefix_test(
4569        &format!(
4570          r#"
4571        .foo {{
4572          {}: min-content;
4573        }}
4574      "#,
4575          in_prop
4576        ),
4577        &format!(
4578          indoc! {r#"
4579        .foo {{
4580          {}: -webkit-min-content;
4581          {}: -moz-min-content;
4582          {}: min-content;
4583        }}
4584      "#},
4585          out_prop, out_prop, out_prop
4586        ),
4587        Browsers {
4588          safari: Some(8 << 16),
4589          firefox: Some(4 << 16),
4590          ..Browsers::default()
4591        },
4592      );
4593
4594      prefix_test(
4595        &format!(
4596          r#"
4597        .foo {{
4598          {}: max-content;
4599        }}
4600      "#,
4601          in_prop
4602        ),
4603        &format!(
4604          indoc! {r#"
4605        .foo {{
4606          {}: -webkit-max-content;
4607          {}: -moz-max-content;
4608          {}: max-content;
4609        }}
4610      "#},
4611          out_prop, out_prop, out_prop
4612        ),
4613        Browsers {
4614          safari: Some(8 << 16),
4615          firefox: Some(4 << 16),
4616          ..Browsers::default()
4617        },
4618      );
4619
4620      prefix_test(
4621        &format!(
4622          r#"
4623        .foo {{
4624          {}: 100%;
4625          {}: max-content;
4626        }}
4627      "#,
4628          in_prop, in_prop
4629        ),
4630        &format!(
4631          indoc! {r#"
4632        .foo {{
4633          {}: 100%;
4634          {}: max-content;
4635        }}
4636      "#},
4637          out_prop, out_prop
4638        ),
4639        Browsers {
4640          safari: Some(8 << 16),
4641          firefox: Some(4 << 16),
4642          ..Browsers::default()
4643        },
4644      );
4645
4646      prefix_test(
4647        &format!(
4648          r#"
4649        .foo {{
4650          {}: var(--fallback);
4651          {}: max-content;
4652        }}
4653      "#,
4654          in_prop, in_prop
4655        ),
4656        &format!(
4657          indoc! {r#"
4658        .foo {{
4659          {}: var(--fallback);
4660          {}: max-content;
4661        }}
4662      "#},
4663          out_prop, out_prop
4664        ),
4665        Browsers {
4666          safari: Some(8 << 16),
4667          firefox: Some(4 << 16),
4668          ..Browsers::default()
4669        },
4670      );
4671    }
4672
4673    minify_test(".foo { aspect-ratio: auto }", ".foo{aspect-ratio:auto}");
4674    minify_test(".foo { aspect-ratio: 2 / 3 }", ".foo{aspect-ratio:2/3}");
4675    minify_test(".foo { aspect-ratio: auto 2 / 3 }", ".foo{aspect-ratio:auto 2/3}");
4676    minify_test(".foo { aspect-ratio: 2 / 3 auto }", ".foo{aspect-ratio:auto 2/3}");
4677
4678    minify_test(
4679      ".foo { width: 200px; width: var(--foo); }",
4680      ".foo{width:200px;width:var(--foo)}",
4681    );
4682    minify_test(
4683      ".foo { width: var(--foo); width: 200px; }",
4684      ".foo{width:var(--foo);width:200px}",
4685    );
4686  }
4687
4688  #[test]
4689  pub fn test_background() {
4690    property_range_test(
4691      &["background-size", "mask-size"],
4692      &[
4693        ("-1px", None),
4694        ("calc(1px - 2px)", Some("0")),
4695        ("calc(-1px + 2px)", Some("1px")),
4696        ("-1%", None),
4697        ("calc(1em - 2px)", Some("calc(1em - 2px)")),
4698        ("calc(-1%)", Some("calc(-1%)")),
4699        ("auto", Some("auto")),
4700        ("1px -1px", None),
4701      ],
4702    );
4703    test(
4704      r#"
4705      .foo {
4706        background: url(img.png);
4707        background-position-x: 20px;
4708        background-position-y: 10px;
4709        background-size: 50px 100px;
4710        background-repeat: repeat no-repeat;
4711      }
4712    "#,
4713      indoc! {r#"
4714      .foo {
4715        background: url("img.png") 20px 10px / 50px 100px repeat-x;
4716      }
4717    "#
4718      },
4719    );
4720
4721    test(
4722      r#"
4723      .foo {
4724        background-color: red;
4725        background-position: 0% 0%;
4726        background-size: auto;
4727        background-repeat: repeat;
4728        background-clip: border-box;
4729        background-origin: padding-box;
4730        background-attachment: scroll;
4731        background-image: none
4732      }
4733    "#,
4734      indoc! {r#"
4735      .foo {
4736        background: red;
4737      }
4738    "#
4739      },
4740    );
4741
4742    test(
4743      r#"
4744      .foo {
4745        background-color: gray;
4746        background-position: 40% 50%;
4747        background-size: 10em auto;
4748        background-repeat: round;
4749        background-clip: border-box;
4750        background-origin: border-box;
4751        background-attachment: fixed;
4752        background-image: url('chess.png');
4753      }
4754    "#,
4755      indoc! {r#"
4756      .foo {
4757        background: gray url("chess.png") 40% / 10em round fixed border-box;
4758      }
4759    "#
4760      },
4761    );
4762
4763    test(
4764      r#"
4765      .foo {
4766        background: url(img.png), url(test.jpg) gray;
4767        background-position-x: right 20px, 10px;
4768        background-position-y: top 20px, 15px;
4769        background-size: 50px 50px, auto;
4770        background-repeat: repeat no-repeat, no-repeat;
4771      }
4772    "#,
4773      indoc! {r#"
4774      .foo {
4775        background: url("img.png") right 20px top 20px / 50px 50px repeat-x, gray url("test.jpg") 10px 15px no-repeat;
4776      }
4777    "#
4778      },
4779    );
4780
4781    minify_test(
4782      r#"
4783      .foo {
4784        background-position: center center;
4785      }
4786    "#,
4787      indoc! {".foo{background-position:50%}"
4788      },
4789    );
4790
4791    test(
4792      r#"
4793      .foo {
4794        background: url(img.png) gray;
4795        background-clip: content-box;
4796        -webkit-background-clip: text;
4797      }
4798    "#,
4799      indoc! {r#"
4800      .foo {
4801        background: gray url("img.png") padding-box content-box;
4802        -webkit-background-clip: text;
4803      }
4804    "#
4805      },
4806    );
4807
4808    test(
4809      r#"
4810      .foo {
4811        background: url(img.png) gray;
4812        -webkit-background-clip: text;
4813        background-clip: content-box;
4814      }
4815    "#,
4816      indoc! {r#"
4817      .foo {
4818        background: gray url("img.png");
4819        -webkit-background-clip: text;
4820        background-clip: content-box;
4821      }
4822    "#
4823      },
4824    );
4825
4826    test(
4827      r#"
4828      .foo {
4829        background: url(img.png) gray;
4830        background-position: var(--pos);
4831      }
4832    "#,
4833      indoc! {r#"
4834      .foo {
4835        background: gray url("img.png");
4836        background-position: var(--pos);
4837      }
4838    "#
4839      },
4840    );
4841
4842    minify_test(
4843      ".foo { background-position: bottom left }",
4844      ".foo{background-position:0 100%}",
4845    );
4846    minify_test(
4847      ".foo { background-position: left 10px center }",
4848      ".foo{background-position:10px}",
4849    );
4850    minify_test(
4851      ".foo { background-position: right 10px center }",
4852      ".foo{background-position:right 10px center}",
4853    );
4854    minify_test(
4855      ".foo { background-position: center top 10px }",
4856      ".foo{background-position:50% 10px}",
4857    );
4858    minify_test(
4859      ".foo { background-position: center bottom 10px }",
4860      ".foo{background-position:center bottom 10px}",
4861    );
4862    minify_test(
4863      ".foo { background-position: center 10px }",
4864      ".foo{background-position:50% 10px}",
4865    );
4866    minify_test(
4867      ".foo { background-position: right 10px top 20px }",
4868      ".foo{background-position:right 10px top 20px}",
4869    );
4870    minify_test(
4871      ".foo { background-position: left 10px top 20px }",
4872      ".foo{background-position:10px 20px}",
4873    );
4874    minify_test(
4875      ".foo { background-position: left 10px bottom 20px }",
4876      ".foo{background-position:left 10px bottom 20px}",
4877    );
4878    minify_test(
4879      ".foo { background-position: left 10px top }",
4880      ".foo{background-position:10px 0}",
4881    );
4882    minify_test(
4883      ".foo { background-position: bottom right }",
4884      ".foo{background-position:100% 100%}",
4885    );
4886    minify_test(
4887      ".foo { background-position: center top }",
4888      ".foo{background-position:top}",
4889    );
4890    minify_test(
4891      ".foo { background-position: center bottom }",
4892      ".foo{background-position:bottom}",
4893    );
4894    minify_test(
4895      ".foo { background-position: left center }",
4896      ".foo{background-position:0}",
4897    );
4898    minify_test(
4899      ".foo { background-position: right center }",
4900      ".foo{background-position:100%}",
4901    );
4902    minify_test(
4903      ".foo { background-position: 20px center }",
4904      ".foo{background-position:20px}",
4905    );
4906
4907    minify_test(
4908      ".foo { background: url('img-sprite.png') no-repeat bottom right }",
4909      ".foo{background:url(img-sprite.png) 100% 100% no-repeat}",
4910    );
4911    minify_test(".foo { background: transparent }", ".foo{background:0 0}");
4912
4913    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\")}");
4914
4915    test(
4916      r#"
4917      .foo {
4918        background: url(img.png);
4919        background-clip: text;
4920      }
4921    "#,
4922      indoc! {r#"
4923      .foo {
4924        background: url("img.png") text;
4925      }
4926    "#
4927      },
4928    );
4929
4930    prefix_test(
4931      r#"
4932      .foo {
4933        background: url(img.png);
4934        background-clip: text;
4935      }
4936    "#,
4937      indoc! {r#"
4938      .foo {
4939        background: url("img.png");
4940        -webkit-background-clip: text;
4941        background-clip: text;
4942      }
4943    "#
4944      },
4945      Browsers {
4946        safari: Some(8 << 16),
4947        ..Browsers::default()
4948      },
4949    );
4950
4951    prefix_test(
4952      r#"
4953      .foo {
4954        background: url(img.png);
4955        background-clip: text;
4956      }
4957    "#,
4958      indoc! {r#"
4959      .foo {
4960        background: url("img.png") text;
4961      }
4962    "#
4963      },
4964      Browsers {
4965        safari: Some(14 << 16),
4966        ..Browsers::default()
4967      },
4968    );
4969
4970    prefix_test(
4971      r#"
4972      .foo {
4973        background: url(img.png) text;
4974      }
4975    "#,
4976      indoc! {r#"
4977      .foo {
4978        background: url("img.png");
4979        -webkit-background-clip: text;
4980        background-clip: text;
4981      }
4982    "#
4983      },
4984      Browsers {
4985        chrome: Some(45 << 16),
4986        ..Browsers::default()
4987      },
4988    );
4989
4990    prefix_test(
4991      r#"
4992      .foo {
4993        background: url(img.png);
4994        -webkit-background-clip: text;
4995      }
4996    "#,
4997      indoc! {r#"
4998      .foo {
4999        background: url("img.png");
5000        -webkit-background-clip: text;
5001      }
5002    "#
5003      },
5004      Browsers {
5005        chrome: Some(45 << 16),
5006        ..Browsers::default()
5007      },
5008    );
5009
5010    prefix_test(
5011      r#"
5012      .foo {
5013        background: url(img.png);
5014        background-clip: text;
5015      }
5016    "#,
5017      indoc! {r#"
5018      .foo {
5019        background: url("img.png");
5020        -webkit-background-clip: text;
5021        background-clip: text;
5022      }
5023    "#
5024      },
5025      Browsers {
5026        safari: Some(14 << 16),
5027        chrome: Some(95 << 16),
5028        ..Browsers::default()
5029      },
5030    );
5031
5032    prefix_test(
5033      r#"
5034      .foo {
5035        background-image: url(img.png);
5036        background-clip: text;
5037      }
5038    "#,
5039      indoc! {r#"
5040      .foo {
5041        background-image: url("img.png");
5042        -webkit-background-clip: text;
5043        background-clip: text;
5044      }
5045    "#
5046      },
5047      Browsers {
5048        safari: Some(8 << 16),
5049        ..Browsers::default()
5050      },
5051    );
5052
5053    prefix_test(
5054      r#"
5055      .foo {
5056        -webkit-background-clip: text;
5057        background-clip: text;
5058      }
5059    "#,
5060      indoc! {r#"
5061      .foo {
5062        -webkit-background-clip: text;
5063        background-clip: text;
5064      }
5065    "#
5066      },
5067      Browsers {
5068        chrome: Some(45 << 16),
5069        ..Browsers::default()
5070      },
5071    );
5072
5073    prefix_test(
5074      r#"
5075      .foo {
5076        background-image: url(img.png);
5077        background-clip: text;
5078      }
5079    "#,
5080      indoc! {r#"
5081      .foo {
5082        background-image: url("img.png");
5083        background-clip: text;
5084      }
5085    "#
5086      },
5087      Browsers {
5088        safari: Some(14 << 16),
5089        ..Browsers::default()
5090      },
5091    );
5092
5093    minify_test(".foo { background: none center }", ".foo{background:50%}");
5094    minify_test(".foo { background: none }", ".foo{background:0 0}");
5095
5096    prefix_test(
5097      r#"
5098      .foo {
5099        background: lab(51.5117% 43.3777 -29.0443);
5100      }
5101    "#,
5102      indoc! {r#"
5103      .foo {
5104        background: #af5cae;
5105        background: lab(51.5117% 43.3777 -29.0443);
5106      }
5107    "#
5108      },
5109      Browsers {
5110        chrome: Some(95 << 16),
5111        safari: Some(15 << 16),
5112        ..Browsers::default()
5113      },
5114    );
5115
5116    prefix_test(
5117      r#"
5118      .foo {
5119        background: lab(51.5117% 43.3777 -29.0443) url(foo.png);
5120      }
5121    "#,
5122      indoc! {r#"
5123      .foo {
5124        background: #af5cae url("foo.png");
5125        background: lab(51.5117% 43.3777 -29.0443) url("foo.png");
5126      }
5127    "#
5128      },
5129      Browsers {
5130        chrome: Some(95 << 16),
5131        safari: Some(15 << 16),
5132        ..Browsers::default()
5133      },
5134    );
5135
5136    prefix_test(
5137      r#"
5138      .foo {
5139        background: lab(51.5117% 43.3777 -29.0443) linear-gradient(lab(52.2319% 40.1449 59.9171), lab(47.7776% -34.2947 -7.65904));
5140      }
5141    "#,
5142      indoc! {r#"
5143      .foo {
5144        background: #af5cae linear-gradient(#c65d07, #00817d);
5145        background: lab(51.5117% 43.3777 -29.0443) linear-gradient(lab(52.2319% 40.1449 59.9171), lab(47.7776% -34.2947 -7.65904));
5146      }
5147    "#
5148      },
5149      Browsers {
5150        chrome: Some(95 << 16),
5151        safari: Some(15 << 16),
5152        ..Browsers::default()
5153      },
5154    );
5155
5156    test(
5157      ".foo { background: calc(var(--v) / 0.3)",
5158      indoc! {r#"
5159      .foo {
5160        background: calc(var(--v) / .3);
5161      }
5162    "#},
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: #4263eb;
5175        background-color: color(display-p3 0 .5 1);
5176      }
5177    "#
5178      },
5179      Browsers {
5180        chrome: Some(99 << 16),
5181        ..Browsers::default()
5182      },
5183    );
5184    prefix_test(
5185      r#"
5186      .foo {
5187        background-color: #4263eb;
5188        background-color: color(display-p3 0 .5 1);
5189      }
5190    "#,
5191      indoc! {r#"
5192      .foo {
5193        background-color: color(display-p3 0 .5 1);
5194      }
5195    "#
5196      },
5197      Browsers {
5198        safari: Some(16 << 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(red, green);
5212        background-image: linear-gradient(lch(50% 132 50), lch(50% 130 150));
5213      }
5214    "#
5215      },
5216      Browsers {
5217        chrome: Some(99 << 16),
5218        ..Browsers::default()
5219      },
5220    );
5221    prefix_test(
5222      r#"
5223      .foo {
5224        background-image: linear-gradient(red, green);
5225        background-image: linear-gradient(lch(50% 132 50), lch(50% 130 150));
5226      }
5227    "#,
5228      indoc! {r#"
5229      .foo {
5230        background-image: linear-gradient(lch(50% 132 50), lch(50% 130 150));
5231      }
5232    "#
5233      },
5234      Browsers {
5235        safari: Some(16 << 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: #4263eb;
5249        background: color(display-p3 0 .5 1);
5250      }
5251    "#
5252      },
5253      Browsers {
5254        chrome: Some(99 << 16),
5255        ..Browsers::default()
5256      },
5257    );
5258    prefix_test(
5259      r#"
5260      .foo {
5261        background: #4263eb;
5262        background: color(display-p3 0 .5 1);
5263      }
5264    "#,
5265      indoc! {r#"
5266      .foo {
5267        background: color(display-p3 0 .5 1);
5268      }
5269    "#
5270      },
5271      Browsers {
5272        safari: Some(16 << 16),
5273        ..Browsers::default()
5274      },
5275    );
5276    prefix_test(
5277      r#"
5278      .foo {
5279        background: linear-gradient(red, green);
5280        background: linear-gradient(lch(50% 132 50), lch(50% 130 150));
5281      }
5282    "#,
5283      indoc! {r#"
5284      .foo {
5285        background: linear-gradient(red, green);
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: red;
5299        background: linear-gradient(lch(50% 132 50), lch(50% 130 150));
5300      }
5301    "#,
5302      indoc! {r#"
5303      .foo {
5304        background: red;
5305        background: linear-gradient(lch(50% 132 50), lch(50% 130 150));
5306      }
5307    "#
5308      },
5309      Browsers {
5310        chrome: Some(99 << 16),
5311        ..Browsers::default()
5312      },
5313    );
5314    prefix_test(
5315      r#"
5316      .foo {
5317        background: linear-gradient(red, green);
5318        background: linear-gradient(lch(50% 132 50), lch(50% 130 150));
5319      }
5320    "#,
5321      indoc! {r#"
5322      .foo {
5323        background: linear-gradient(lch(50% 132 50), lch(50% 130 150));
5324      }
5325    "#
5326      },
5327      Browsers {
5328        safari: Some(16 << 16),
5329        ..Browsers::default()
5330      },
5331    );
5332    prefix_test(
5333      r#"
5334      .foo {
5335        background: var(--fallback);
5336        background: linear-gradient(lch(50% 132 50), lch(50% 130 150));
5337      }
5338    "#,
5339      indoc! {r#"
5340      .foo {
5341        background: var(--fallback);
5342        background: linear-gradient(lch(50% 132 50), lch(50% 130 150));
5343      }
5344    "#
5345      },
5346      Browsers {
5347        chrome: Some(99 << 16),
5348        ..Browsers::default()
5349      },
5350    );
5351    prefix_test(
5352      r#"
5353      .foo {
5354        background: red url(foo.png);
5355        background: lch(50% 132 50) url(foo.png);
5356      }
5357    "#,
5358      indoc! {r#"
5359      .foo {
5360        background: red url("foo.png");
5361        background: lch(50% 132 50) url("foo.png");
5362      }
5363    "#
5364      },
5365      Browsers {
5366        chrome: Some(99 << 16),
5367        ..Browsers::default()
5368      },
5369    );
5370  }
5371
5372  #[test]
5373  pub fn test_flex() {
5374    property_range_test(&["flex"], &[("-1", None), ("1 -1", None), ("1 1 -1px", None)]);
5375    property_range_test(
5376      &["flex-basis", "-ms-flex-preferred-size"],
5377      &[
5378        ("-1px", None),
5379        ("calc(1px - 2px)", Some("0")),
5380        ("calc(-1px + 2px)", Some("1px")),
5381        ("-1%", None),
5382        ("calc(1em - 2px)", Some("calc(1em - 2px)")),
5383        ("calc(-1%)", Some("calc(-1%)")),
5384      ],
5385    );
5386    property_range_test(
5387      &[
5388        "flex-grow",
5389        "flex-shrink",
5390        "-webkit-box-flex",
5391        "-ms-flex-positive",
5392        "-ms-flex-negative",
5393      ],
5394      &[("-1", None), ("calc(1 - 2)", Some("0")), ("calc(-1 + 2)", Some("1"))],
5395    );
5396    test(
5397      r#"
5398      .foo {
5399        flex-direction: column;
5400        flex-wrap: wrap;
5401      }
5402    "#,
5403      indoc! {r#"
5404      .foo {
5405        flex-flow: column wrap;
5406      }
5407    "#
5408      },
5409    );
5410
5411    test(
5412      r#"
5413      .foo {
5414        flex-direction: row;
5415        flex-wrap: wrap;
5416      }
5417    "#,
5418      indoc! {r#"
5419      .foo {
5420        flex-flow: wrap;
5421      }
5422    "#
5423      },
5424    );
5425
5426    test(
5427      r#"
5428      .foo {
5429        flex-direction: row;
5430        flex-wrap: nowrap;
5431      }
5432    "#,
5433      indoc! {r#"
5434      .foo {
5435        flex-flow: row;
5436      }
5437    "#
5438      },
5439    );
5440
5441    test(
5442      r#"
5443      .foo {
5444        flex-direction: column;
5445        flex-wrap: nowrap;
5446      }
5447    "#,
5448      indoc! {r#"
5449      .foo {
5450        flex-flow: column;
5451      }
5452    "#
5453      },
5454    );
5455
5456    test(
5457      r#"
5458      .foo {
5459        flex-grow: 1;
5460        flex-shrink: 1;
5461        flex-basis: 0%;
5462      }
5463    "#,
5464      indoc! {r#"
5465      .foo {
5466        flex: 1;
5467      }
5468    "#
5469      },
5470    );
5471
5472    test(
5473      r#"
5474      .foo {
5475        flex-grow: 1;
5476        flex-shrink: 1;
5477        flex-basis: 0;
5478      }
5479    "#,
5480      indoc! {r#"
5481      .foo {
5482        flex: 1 1 0;
5483      }
5484    "#
5485      },
5486    );
5487
5488    test(
5489      r#"
5490      .foo {
5491        flex-grow: 1;
5492        flex-shrink: 1;
5493        flex-basis: 0px;
5494      }
5495    "#,
5496      indoc! {r#"
5497      .foo {
5498        flex: 1 1 0;
5499      }
5500    "#
5501      },
5502    );
5503
5504    test(
5505      r#"
5506      .foo {
5507        flex-grow: 1;
5508        flex-shrink: 2;
5509        flex-basis: 0%;
5510      }
5511    "#,
5512      indoc! {r#"
5513      .foo {
5514        flex: 1 2;
5515      }
5516    "#
5517      },
5518    );
5519
5520    test(
5521      r#"
5522      .foo {
5523        flex-grow: 2;
5524        flex-shrink: 1;
5525        flex-basis: 0%;
5526      }
5527    "#,
5528      indoc! {r#"
5529      .foo {
5530        flex: 2;
5531      }
5532    "#
5533      },
5534    );
5535
5536    test(
5537      r#"
5538      .foo {
5539        flex-grow: 2;
5540        flex-shrink: 2;
5541        flex-basis: 0%;
5542      }
5543    "#,
5544      indoc! {r#"
5545      .foo {
5546        flex: 2 2;
5547      }
5548    "#
5549      },
5550    );
5551
5552    test(
5553      r#"
5554      .foo {
5555        flex-grow: 1;
5556        flex-shrink: 1;
5557        flex-basis: 10px;
5558      }
5559    "#,
5560      indoc! {r#"
5561      .foo {
5562        flex: 10px;
5563      }
5564    "#
5565      },
5566    );
5567
5568    test(
5569      r#"
5570      .foo {
5571        flex-grow: 2;
5572        flex-shrink: 1;
5573        flex-basis: 10px;
5574      }
5575    "#,
5576      indoc! {r#"
5577      .foo {
5578        flex: 2 10px;
5579      }
5580    "#
5581      },
5582    );
5583
5584    test(
5585      r#"
5586      .foo {
5587        flex-grow: 1;
5588        flex-shrink: 0;
5589        flex-basis: 0%;
5590      }
5591    "#,
5592      indoc! {r#"
5593      .foo {
5594        flex: 1 0;
5595      }
5596    "#
5597      },
5598    );
5599
5600    test(
5601      r#"
5602      .foo {
5603        flex-grow: 1;
5604        flex-shrink: 0;
5605        flex-basis: auto;
5606      }
5607    "#,
5608      indoc! {r#"
5609      .foo {
5610        flex: 1 0 auto;
5611      }
5612    "#
5613      },
5614    );
5615
5616    test(
5617      r#"
5618      .foo {
5619        flex-grow: 1;
5620        flex-shrink: 1;
5621        flex-basis: auto;
5622      }
5623    "#,
5624      indoc! {r#"
5625      .foo {
5626        flex: auto;
5627      }
5628    "#
5629      },
5630    );
5631
5632    test(
5633      r#"
5634      .foo {
5635        flex: 0 0;
5636        flex-grow: 1;
5637      }
5638    "#,
5639      indoc! {r#"
5640      .foo {
5641        flex: 1 0;
5642      }
5643    "#
5644      },
5645    );
5646
5647    test(
5648      r#"
5649      .foo {
5650        flex: 0 0;
5651        flex-grow: var(--grow);
5652      }
5653    "#,
5654      indoc! {r#"
5655      .foo {
5656        flex: 0 0;
5657        flex-grow: var(--grow);
5658      }
5659    "#
5660      },
5661    );
5662
5663    test(
5664      r#"
5665      .foo {
5666        align-content: center;
5667        justify-content: center;
5668      }
5669    "#,
5670      indoc! {r#"
5671      .foo {
5672        place-content: center;
5673      }
5674    "#
5675      },
5676    );
5677
5678    test(
5679      r#"
5680      .foo {
5681        align-content: first baseline;
5682        justify-content: safe right;
5683      }
5684    "#,
5685      indoc! {r#"
5686      .foo {
5687        place-content: baseline safe right;
5688      }
5689    "#
5690      },
5691    );
5692
5693    test(
5694      r#"
5695      .foo {
5696        place-content: first baseline unsafe left;
5697      }
5698    "#,
5699      indoc! {r#"
5700      .foo {
5701        place-content: baseline unsafe left;
5702      }
5703    "#
5704      },
5705    );
5706
5707    test(
5708      r#"
5709      .foo {
5710        place-content: center center;
5711      }
5712    "#,
5713      indoc! {r#"
5714      .foo {
5715        place-content: center;
5716      }
5717    "#
5718      },
5719    );
5720
5721    test(
5722      r#"
5723      .foo {
5724        align-self: center;
5725        justify-self: center;
5726      }
5727    "#,
5728      indoc! {r#"
5729      .foo {
5730        place-self: center;
5731      }
5732    "#
5733      },
5734    );
5735
5736    test(
5737      r#"
5738      .foo {
5739        align-self: center;
5740        justify-self: unsafe left;
5741      }
5742    "#,
5743      indoc! {r#"
5744      .foo {
5745        place-self: center unsafe left;
5746      }
5747    "#
5748      },
5749    );
5750
5751    test(
5752      r#"
5753      .foo {
5754        align-items: center;
5755        justify-items: center;
5756      }
5757    "#,
5758      indoc! {r#"
5759      .foo {
5760        place-items: center;
5761      }
5762    "#
5763      },
5764    );
5765
5766    test(
5767      r#"
5768      .foo {
5769        align-items: center;
5770        justify-items: legacy left;
5771      }
5772    "#,
5773      indoc! {r#"
5774      .foo {
5775        place-items: center legacy left;
5776      }
5777    "#
5778      },
5779    );
5780
5781    test(
5782      r#"
5783      .foo {
5784        place-items: center;
5785        justify-items: var(--justify);
5786      }
5787    "#,
5788      indoc! {r#"
5789      .foo {
5790        place-items: center;
5791        justify-items: var(--justify);
5792      }
5793    "#
5794      },
5795    );
5796
5797    test(
5798      r#"
5799      .foo {
5800        row-gap: 10px;
5801        column-gap: 20px;
5802      }
5803    "#,
5804      indoc! {r#"
5805      .foo {
5806        gap: 10px 20px;
5807      }
5808    "#
5809      },
5810    );
5811
5812    test(
5813      r#"
5814      .foo {
5815        row-gap: 10px;
5816        column-gap: 10px;
5817      }
5818    "#,
5819      indoc! {r#"
5820      .foo {
5821        gap: 10px;
5822      }
5823    "#
5824      },
5825    );
5826
5827    test(
5828      r#"
5829      .foo {
5830        gap: 10px;
5831        column-gap: 20px;
5832      }
5833    "#,
5834      indoc! {r#"
5835      .foo {
5836        gap: 10px 20px;
5837      }
5838    "#
5839      },
5840    );
5841
5842    test(
5843      r#"
5844      .foo {
5845        column-gap: 20px;
5846        gap: 10px;
5847      }
5848    "#,
5849      indoc! {r#"
5850      .foo {
5851        gap: 10px;
5852      }
5853    "#
5854      },
5855    );
5856
5857    test(
5858      r#"
5859      .foo {
5860        row-gap: normal;
5861        column-gap: 20px;
5862      }
5863    "#,
5864      indoc! {r#"
5865      .foo {
5866        gap: normal 20px;
5867      }
5868    "#
5869      },
5870    );
5871
5872    test(
5873      r#"
5874      .foo {
5875        -webkit-flex-grow: 1;
5876        -webkit-flex-shrink: 1;
5877        -webkit-flex-basis: auto;
5878      }
5879    "#,
5880      indoc! {r#"
5881      .foo {
5882        -webkit-flex: auto;
5883      }
5884    "#
5885      },
5886    );
5887    test(
5888      r#"
5889      .foo {
5890        -webkit-flex-grow: 1;
5891        -webkit-flex-shrink: 1;
5892        -webkit-flex-basis: auto;
5893        flex-grow: 1;
5894        flex-shrink: 1;
5895        flex-basis: auto;
5896      }
5897    "#,
5898      indoc! {r#"
5899      .foo {
5900        -webkit-flex: auto;
5901        flex: auto;
5902      }
5903    "#
5904      },
5905    );
5906    prefix_test(
5907      r#"
5908      .foo {
5909        -webkit-box-orient: horizontal;
5910        -webkit-box-direction: normal;
5911        flex-direction: row;
5912      }
5913    "#,
5914      indoc! {r#"
5915      .foo {
5916        -webkit-box-orient: horizontal;
5917        -webkit-box-direction: normal;
5918        -webkit-flex-direction: row;
5919        flex-direction: row;
5920      }
5921    "#},
5922      Browsers {
5923        safari: Some(4 << 16),
5924        ..Browsers::default()
5925      },
5926    );
5927    prefix_test(
5928      r#"
5929      .foo {
5930        flex-direction: row;
5931      }
5932    "#,
5933      indoc! {r#"
5934      .foo {
5935        -webkit-box-orient: horizontal;
5936        -moz-box-orient: horizontal;
5937        -webkit-box-direction: normal;
5938        -moz-box-direction: normal;
5939        -webkit-flex-direction: row;
5940        -ms-flex-direction: row;
5941        flex-direction: row;
5942      }
5943    "#},
5944      Browsers {
5945        safari: Some(4 << 16),
5946        firefox: Some(4 << 16),
5947        ie: Some(10 << 16),
5948        ..Browsers::default()
5949      },
5950    );
5951    prefix_test(
5952      r#"
5953      .foo {
5954        -webkit-box-orient: horizontal;
5955        -webkit-box-direction: normal;
5956        -moz-box-orient: horizontal;
5957        -moz-box-direction: normal;
5958        -webkit-flex-direction: row;
5959        -ms-flex-direction: row;
5960        flex-direction: row;
5961      }
5962    "#,
5963      indoc! {r#"
5964      .foo {
5965        flex-direction: row;
5966      }
5967    "#},
5968      Browsers {
5969        safari: Some(14 << 16),
5970        ..Browsers::default()
5971      },
5972    );
5973    prefix_test(
5974      r#"
5975      .foo {
5976        flex-wrap: wrap;
5977      }
5978    "#,
5979      indoc! {r#"
5980      .foo {
5981        -webkit-box-lines: multiple;
5982        -moz-box-lines: multiple;
5983        -webkit-flex-wrap: wrap;
5984        -ms-flex-wrap: wrap;
5985        flex-wrap: wrap;
5986      }
5987    "#},
5988      Browsers {
5989        safari: Some(4 << 16),
5990        firefox: Some(4 << 16),
5991        ie: Some(10 << 16),
5992        ..Browsers::default()
5993      },
5994    );
5995    prefix_test(
5996      r#"
5997      .foo {
5998        -webkit-box-lines: multiple;
5999        -moz-box-lines: multiple;
6000        -webkit-flex-wrap: wrap;
6001        -ms-flex-wrap: wrap;
6002        flex-wrap: wrap;
6003      }
6004    "#,
6005      indoc! {r#"
6006      .foo {
6007        flex-wrap: wrap;
6008      }
6009    "#},
6010      Browsers {
6011        safari: Some(11 << 16),
6012        ..Browsers::default()
6013      },
6014    );
6015    prefix_test(
6016      r#"
6017      .foo {
6018        flex-flow: row wrap;
6019      }
6020    "#,
6021      indoc! {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      Browsers {
6033        safari: Some(4 << 16),
6034        firefox: Some(4 << 16),
6035        ie: Some(10 << 16),
6036        ..Browsers::default()
6037      },
6038    );
6039    prefix_test(
6040      r#"
6041      .foo {
6042        -webkit-box-orient: horizontal;
6043        -moz-box-orient: horizontal;
6044        -webkit-box-direction: normal;
6045        -moz-box-direction: normal;
6046        -webkit-flex-flow: wrap;
6047        -ms-flex-flow: wrap;
6048        flex-flow: wrap;
6049      }
6050    "#,
6051      indoc! {r#"
6052      .foo {
6053        flex-flow: wrap;
6054      }
6055    "#},
6056      Browsers {
6057        safari: Some(11 << 16),
6058        ..Browsers::default()
6059      },
6060    );
6061    prefix_test(
6062      r#"
6063      .foo {
6064        flex-grow: 1;
6065      }
6066    "#,
6067      indoc! {r#"
6068      .foo {
6069        -webkit-box-flex: 1;
6070        -moz-box-flex: 1;
6071        -ms-flex-positive: 1;
6072        -webkit-flex-grow: 1;
6073        flex-grow: 1;
6074      }
6075    "#},
6076      Browsers {
6077        safari: Some(4 << 16),
6078        firefox: Some(4 << 16),
6079        ie: Some(10 << 16),
6080        ..Browsers::default()
6081      },
6082    );
6083    prefix_test(
6084      r#"
6085      .foo {
6086        -webkit-box-flex: 1;
6087        -moz-box-flex: 1;
6088        -ms-flex-positive: 1;
6089        -webkit-flex-grow: 1;
6090        flex-grow: 1;
6091      }
6092    "#,
6093      indoc! {r#"
6094      .foo {
6095        flex-grow: 1;
6096      }
6097    "#},
6098      Browsers {
6099        safari: Some(11 << 16),
6100        ..Browsers::default()
6101      },
6102    );
6103    prefix_test(
6104      r#"
6105      .foo {
6106        flex-shrink: 1;
6107      }
6108    "#,
6109      indoc! {r#"
6110      .foo {
6111        -ms-flex-negative: 1;
6112        -webkit-flex-shrink: 1;
6113        flex-shrink: 1;
6114      }
6115    "#},
6116      Browsers {
6117        safari: Some(4 << 16),
6118        firefox: Some(4 << 16),
6119        ie: Some(10 << 16),
6120        ..Browsers::default()
6121      },
6122    );
6123    prefix_test(
6124      r#"
6125      .foo {
6126        -ms-flex-negative: 1;
6127        -webkit-flex-shrink: 1;
6128        flex-shrink: 1;
6129      }
6130    "#,
6131      indoc! {r#"
6132      .foo {
6133        flex-shrink: 1;
6134      }
6135    "#},
6136      Browsers {
6137        safari: Some(11 << 16),
6138        ..Browsers::default()
6139      },
6140    );
6141    prefix_test(
6142      r#"
6143      .foo {
6144        flex-basis: 1px;
6145      }
6146    "#,
6147      indoc! {r#"
6148      .foo {
6149        -ms-flex-preferred-size: 1px;
6150        -webkit-flex-basis: 1px;
6151        flex-basis: 1px;
6152      }
6153    "#},
6154      Browsers {
6155        safari: Some(4 << 16),
6156        firefox: Some(4 << 16),
6157        ie: Some(10 << 16),
6158        ..Browsers::default()
6159      },
6160    );
6161    prefix_test(
6162      r#"
6163      .foo {
6164        -ms-flex-preferred-size: 1px;
6165        -webkit-flex-basis: 1px;
6166        flex-basis: 1px;
6167      }
6168    "#,
6169      indoc! {r#"
6170      .foo {
6171        flex-basis: 1px;
6172      }
6173    "#},
6174      Browsers {
6175        safari: Some(11 << 16),
6176        ..Browsers::default()
6177      },
6178    );
6179    prefix_test(
6180      r#"
6181      .foo {
6182        flex: 1;
6183      }
6184    "#,
6185      indoc! {r#"
6186      .foo {
6187        -webkit-box-flex: 1;
6188        -moz-box-flex: 1;
6189        -webkit-flex: 1;
6190        -ms-flex: 1;
6191        flex: 1;
6192      }
6193    "#},
6194      Browsers {
6195        safari: Some(4 << 16),
6196        firefox: Some(4 << 16),
6197        ie: Some(10 << 16),
6198        ..Browsers::default()
6199      },
6200    );
6201    prefix_test(
6202      r#"
6203      .foo {
6204        -webkit-box-flex: 1;
6205        -moz-box-flex: 1;
6206        -webkit-flex: 1;
6207        -ms-flex: 1;
6208        flex: 1;
6209      }
6210    "#,
6211      indoc! {r#"
6212      .foo {
6213        flex: 1;
6214      }
6215    "#},
6216      Browsers {
6217        safari: Some(11 << 16),
6218        ..Browsers::default()
6219      },
6220    );
6221    prefix_test(
6222      r#"
6223      .foo {
6224        align-content: space-between;
6225      }
6226    "#,
6227      indoc! {r#"
6228      .foo {
6229        -ms-flex-line-pack: justify;
6230        -webkit-align-content: space-between;
6231        align-content: space-between;
6232      }
6233    "#},
6234      Browsers {
6235        safari: Some(4 << 16),
6236        firefox: Some(4 << 16),
6237        ie: Some(10 << 16),
6238        ..Browsers::default()
6239      },
6240    );
6241    prefix_test(
6242      r#"
6243      .foo {
6244        -ms-flex-line-pack: justify;
6245        -webkit-align-content: space-between;
6246        align-content: space-between;
6247      }
6248    "#,
6249      indoc! {r#"
6250      .foo {
6251        align-content: space-between;
6252      }
6253    "#},
6254      Browsers {
6255        safari: Some(11 << 16),
6256        ..Browsers::default()
6257      },
6258    );
6259    prefix_test(
6260      r#"
6261      .foo {
6262        justify-content: space-between;
6263      }
6264    "#,
6265      indoc! {r#"
6266      .foo {
6267        -webkit-box-pack: justify;
6268        -moz-box-pack: justify;
6269        -ms-flex-pack: justify;
6270        -webkit-justify-content: space-between;
6271        justify-content: space-between;
6272      }
6273    "#},
6274      Browsers {
6275        safari: Some(4 << 16),
6276        firefox: Some(4 << 16),
6277        ie: Some(10 << 16),
6278        ..Browsers::default()
6279      },
6280    );
6281    prefix_test(
6282      r#"
6283      .foo {
6284        -webkit-box-pack: justify;
6285        -moz-box-pack: justify;
6286        -ms-flex-pack: justify;
6287        -webkit-justify-content: space-between;
6288        justify-content: space-between;
6289      }
6290    "#,
6291      indoc! {r#"
6292      .foo {
6293        justify-content: space-between;
6294      }
6295    "#},
6296      Browsers {
6297        safari: Some(11 << 16),
6298        ..Browsers::default()
6299      },
6300    );
6301    prefix_test(
6302      r#"
6303      .foo {
6304        place-content: space-between flex-end;
6305      }
6306    "#,
6307      indoc! {r#"
6308      .foo {
6309        -ms-flex-line-pack: justify;
6310        -webkit-box-pack: end;
6311        -moz-box-pack: end;
6312        -ms-flex-pack: end;
6313        -webkit-align-content: space-between;
6314        align-content: space-between;
6315        -webkit-justify-content: flex-end;
6316        justify-content: flex-end;
6317      }
6318    "#},
6319      Browsers {
6320        safari: Some(4 << 16),
6321        firefox: Some(4 << 16),
6322        ie: Some(10 << 16),
6323        ..Browsers::default()
6324      },
6325    );
6326    prefix_test(
6327      r#"
6328      .foo {
6329        -ms-flex-line-pack: justify;
6330        -webkit-box-pack: end;
6331        -moz-box-pack: end;
6332        -ms-flex-pack: end;
6333        -webkit-align-content: space-between;
6334        -webkit-justify-content: flex-end;
6335        place-content: space-between flex-end;
6336      }
6337    "#,
6338      indoc! {r#"
6339      .foo {
6340        place-content: space-between flex-end;
6341      }
6342    "#},
6343      Browsers {
6344        safari: Some(11 << 16),
6345        ..Browsers::default()
6346      },
6347    );
6348    prefix_test(
6349      r#"
6350      .foo {
6351        place-content: space-between flex-end;
6352      }
6353    "#,
6354      indoc! {r#"
6355      .foo {
6356        align-content: space-between;
6357        justify-content: flex-end;
6358      }
6359    "#},
6360      Browsers {
6361        chrome: Some(30 << 16),
6362        ..Browsers::default()
6363      },
6364    );
6365    prefix_test(
6366      r#"
6367      .foo {
6368        place-content: space-between flex-end;
6369      }
6370    "#,
6371      indoc! {r#"
6372      .foo {
6373        place-content: space-between flex-end;
6374      }
6375    "#},
6376      Browsers {
6377        chrome: Some(60 << 16),
6378        ..Browsers::default()
6379      },
6380    );
6381    prefix_test(
6382      r#"
6383      .foo {
6384        align-self: flex-end;
6385      }
6386    "#,
6387      indoc! {r#"
6388      .foo {
6389        -ms-flex-item-align: end;
6390        -webkit-align-self: flex-end;
6391        align-self: flex-end;
6392      }
6393    "#},
6394      Browsers {
6395        safari: Some(4 << 16),
6396        firefox: Some(4 << 16),
6397        ie: Some(10 << 16),
6398        ..Browsers::default()
6399      },
6400    );
6401    prefix_test(
6402      r#"
6403      .foo {
6404        -ms-flex-item-align: end;
6405        -webkit-align-self: flex-end;
6406        align-self: flex-end;
6407      }
6408    "#,
6409      indoc! {r#"
6410      .foo {
6411        align-self: flex-end;
6412      }
6413    "#},
6414      Browsers {
6415        safari: Some(11 << 16),
6416        ..Browsers::default()
6417      },
6418    );
6419    prefix_test(
6420      r#"
6421      .foo {
6422        place-self: center flex-end;
6423      }
6424    "#,
6425      indoc! {r#"
6426      .foo {
6427        -ms-flex-item-align: center;
6428        -webkit-align-self: center;
6429        align-self: center;
6430        justify-self: flex-end;
6431      }
6432    "#},
6433      Browsers {
6434        safari: Some(4 << 16),
6435        firefox: Some(4 << 16),
6436        ie: Some(10 << 16),
6437        ..Browsers::default()
6438      },
6439    );
6440    prefix_test(
6441      r#"
6442      .foo {
6443        -ms-flex-item-align: center;
6444        -webkit-align-self: center;
6445        place-self: center flex-end;
6446      }
6447    "#,
6448      indoc! {r#"
6449      .foo {
6450        place-self: center flex-end;
6451      }
6452    "#},
6453      Browsers {
6454        safari: Some(11 << 16),
6455        ..Browsers::default()
6456      },
6457    );
6458    prefix_test(
6459      r#"
6460      .foo {
6461        place-self: center flex-end;
6462      }
6463    "#,
6464      indoc! {r#"
6465      .foo {
6466        align-self: center;
6467        justify-self: flex-end;
6468      }
6469    "#},
6470      Browsers {
6471        chrome: Some(57 << 16),
6472        ..Browsers::default()
6473      },
6474    );
6475    prefix_test(
6476      r#"
6477      .foo {
6478        place-self: center flex-end;
6479      }
6480    "#,
6481      indoc! {r#"
6482      .foo {
6483        place-self: center flex-end;
6484      }
6485    "#},
6486      Browsers {
6487        chrome: Some(59 << 16),
6488        ..Browsers::default()
6489      },
6490    );
6491    prefix_test(
6492      r#"
6493      .foo {
6494        align-items: flex-end;
6495      }
6496    "#,
6497      indoc! {r#"
6498      .foo {
6499        -webkit-box-align: end;
6500        -moz-box-align: end;
6501        -ms-flex-align: end;
6502        -webkit-align-items: flex-end;
6503        align-items: flex-end;
6504      }
6505    "#},
6506      Browsers {
6507        safari: Some(4 << 16),
6508        firefox: Some(4 << 16),
6509        ie: Some(10 << 16),
6510        ..Browsers::default()
6511      },
6512    );
6513    prefix_test(
6514      r#"
6515      .foo {
6516        -webkit-box-align: end;
6517        -moz-box-align: end;
6518        -ms-flex-align: end;
6519        -webkit-align-items: flex-end;
6520        align-items: flex-end;
6521      }
6522    "#,
6523      indoc! {r#"
6524      .foo {
6525        align-items: flex-end;
6526      }
6527    "#},
6528      Browsers {
6529        safari: Some(11 << 16),
6530        ..Browsers::default()
6531      },
6532    );
6533    prefix_test(
6534      r#"
6535      .foo {
6536        place-items: flex-end center;
6537      }
6538    "#,
6539      indoc! {r#"
6540      .foo {
6541        -webkit-box-align: end;
6542        -moz-box-align: end;
6543        -ms-flex-align: end;
6544        -webkit-align-items: flex-end;
6545        align-items: flex-end;
6546        justify-items: center;
6547      }
6548    "#},
6549      Browsers {
6550        safari: Some(4 << 16),
6551        firefox: Some(4 << 16),
6552        ie: Some(10 << 16),
6553        ..Browsers::default()
6554      },
6555    );
6556    prefix_test(
6557      r#"
6558      .foo {
6559        -webkit-box-align: end;
6560        -moz-box-align: end;
6561        -ms-flex-align: end;
6562        -webkit-align-items: flex-end;
6563        place-items: flex-end center;
6564      }
6565    "#,
6566      indoc! {r#"
6567      .foo {
6568        place-items: flex-end center;
6569      }
6570    "#},
6571      Browsers {
6572        safari: Some(11 << 16),
6573        ..Browsers::default()
6574      },
6575    );
6576    prefix_test(
6577      r#"
6578      .foo {
6579        place-items: flex-end center;
6580      }
6581    "#,
6582      indoc! {r#"
6583      .foo {
6584        align-items: flex-end;
6585        justify-items: center;
6586      }
6587    "#},
6588      Browsers {
6589        safari: Some(10 << 16),
6590        ..Browsers::default()
6591      },
6592    );
6593    prefix_test(
6594      r#"
6595      .foo {
6596        order: 1;
6597      }
6598    "#,
6599      indoc! {r#"
6600      .foo {
6601        -webkit-box-ordinal-group: 1;
6602        -moz-box-ordinal-group: 1;
6603        -ms-flex-order: 1;
6604        -webkit-order: 1;
6605        order: 1;
6606      }
6607    "#},
6608      Browsers {
6609        safari: Some(4 << 16),
6610        firefox: Some(4 << 16),
6611        ie: Some(10 << 16),
6612        ..Browsers::default()
6613      },
6614    );
6615    prefix_test(
6616      r#"
6617      .foo {
6618        -webkit-box-ordinal-group: 1;
6619        -moz-box-ordinal-group: 1;
6620        -ms-flex-order: 1;
6621        -webkit-order: 1;
6622        order: 1;
6623      }
6624    "#,
6625      indoc! {r#"
6626      .foo {
6627        order: 1;
6628      }
6629    "#},
6630      Browsers {
6631        safari: Some(11 << 16),
6632        ..Browsers::default()
6633      },
6634    );
6635    prefix_test(
6636      r#"
6637      .foo {
6638        -ms-flex: 0 0 8%;
6639        flex: 0 0 5%;
6640      }
6641    "#,
6642      indoc! {r#"
6643      .foo {
6644        -ms-flex: 0 0 8%;
6645        flex: 0 0 5%;
6646      }
6647    "#},
6648      Browsers {
6649        safari: Some(11 << 16),
6650        ..Browsers::default()
6651      },
6652    );
6653  }
6654
6655  #[test]
6656  fn test_font() {
6657    property_range_test(&["font-stretch"], &[("-1%", None), ("calc(-1%)", Some("0%"))]);
6658    property_range_test(
6659      &["line-height"],
6660      &[("-1", None), ("calc(1 - 2)", Some("0")), ("calc(-1 + 2)", Some("1"))],
6661    );
6662    property_range_test(
6663      &["font-size", "line-height"],
6664      &[
6665        ("-1px", None),
6666        ("calc(1px - 2px)", Some("0")),
6667        ("calc(-1px + 2px)", Some("1px")),
6668        ("-1%", None),
6669        ("calc(1em - 2px)", Some("calc(1em - 2px)")),
6670        ("calc(-1%)", Some("calc(-1%)")),
6671      ],
6672    );
6673    test(
6674      r#"
6675      .foo {
6676        font-family: "Helvetica", "Times New Roman", sans-serif;
6677        font-size: 12px;
6678        font-weight: bold;
6679        font-style: italic;
6680        font-stretch: expanded;
6681        font-variant-caps: small-caps;
6682        line-height: 1.2em;
6683      }
6684    "#,
6685      indoc! {r#"
6686      .foo {
6687        font: italic small-caps bold expanded 12px / 1.2em Helvetica, Times New Roman, sans-serif;
6688      }
6689    "#
6690      },
6691    );
6692
6693    minify_test(
6694      r#"
6695      .foo {
6696        font-family: "Helvetica", "Times New Roman", sans-serif;
6697        font-size: 12px;
6698        font-weight: bold;
6699        font-style: italic;
6700        font-stretch: expanded;
6701        font-variant-caps: small-caps;
6702        line-height: 1.2em;
6703      }
6704    "#,
6705      indoc! {".foo{font:italic small-caps 700 125% 12px/1.2em Helvetica,Times New Roman,sans-serif}"
6706      },
6707    );
6708
6709    test(
6710      r#"
6711      .foo {
6712        font: 12px "Helvetica", "Times New Roman", sans-serif;
6713        line-height: 1.2em;
6714      }
6715    "#,
6716      indoc! {r#"
6717      .foo {
6718        font: 12px / 1.2em Helvetica, Times New Roman, sans-serif;
6719      }
6720    "#
6721      },
6722    );
6723
6724    test(
6725      r#"
6726      .foo {
6727        font: 12px "Helvetica", "Times New Roman", sans-serif;
6728        line-height: var(--lh);
6729      }
6730    "#,
6731      indoc! {r#"
6732      .foo {
6733        font: 12px Helvetica, Times New Roman, sans-serif;
6734        line-height: var(--lh);
6735      }
6736    "#
6737      },
6738    );
6739
6740    minify_test(
6741      r#"
6742      .foo {
6743        font-family: "Helvetica", "Times New Roman", sans-serif;
6744        font-size: 12px;
6745        font-stretch: expanded;
6746      }
6747    "#,
6748      indoc! {".foo{font-family:Helvetica,Times New Roman,sans-serif;font-size:12px;font-stretch:125%}"
6749      },
6750    );
6751
6752    test(
6753      r#"
6754      .foo {
6755        font-family: "Helvetica", "Times New Roman", sans-serif;
6756        font-size: 12px;
6757        font-weight: bold;
6758        font-style: italic;
6759        font-stretch: expanded;
6760        font-variant-caps: all-small-caps;
6761        line-height: 1.2em;
6762      }
6763    "#,
6764      indoc! {r#"
6765      .foo {
6766        font: italic bold expanded 12px / 1.2em Helvetica, Times New Roman, sans-serif;
6767        font-variant-caps: all-small-caps;
6768      }
6769    "#
6770      },
6771    );
6772
6773    minify_test(
6774      ".foo { font: normal normal 600 9px/normal Charcoal; }",
6775      ".foo{font:600 9px Charcoal}",
6776    );
6777    minify_test(
6778      ".foo { font: normal normal 500 medium/normal Charcoal; }",
6779      ".foo{font:500 medium Charcoal}",
6780    );
6781    minify_test(
6782      ".foo { font: normal normal 400 medium Charcoal; }",
6783      ".foo{font:400 medium Charcoal}",
6784    );
6785    minify_test(
6786      ".foo { font: normal normal 500 medium/10px Charcoal; }",
6787      ".foo{font:500 medium/10px Charcoal}",
6788    );
6789    minify_test(
6790      ".foo { font-family: 'sans-serif'; }",
6791      ".foo{font-family:\"sans-serif\"}",
6792    );
6793    minify_test(".foo { font-family: sans-serif; }", ".foo{font-family:sans-serif}");
6794    minify_test(".foo { font-family: 'default'; }", ".foo{font-family:\"default\"}");
6795    minify_test(".foo { font-family: default; }", ".foo{font-family:default}");
6796    minify_test(".foo { font-family: 'inherit'; }", ".foo{font-family:\"inherit\"}");
6797    minify_test(".foo { font-family: inherit; }", ".foo{font-family:inherit}");
6798    minify_test(".foo { font-family: inherit test; }", ".foo{font-family:inherit test}");
6799    minify_test(
6800      ".foo { font-family: 'inherit test'; }",
6801      ".foo{font-family:inherit test}",
6802    );
6803    minify_test(".foo { font-family: revert; }", ".foo{font-family:revert}");
6804    minify_test(".foo { font-family: 'revert'; }", ".foo{font-family:\"revert\"}");
6805    minify_test(".foo { font-family: revert-layer; }", ".foo{font-family:revert-layer}");
6806    minify_test(
6807      ".foo { font-family: revert-layer, serif; }",
6808      ".foo{font-family:revert-layer,serif}",
6809    );
6810    minify_test(
6811      ".foo { font-family: 'revert', sans-serif; }",
6812      ".foo{font-family:\"revert\",sans-serif}",
6813    );
6814    minify_test(
6815      ".foo { font-family: 'revert', foo, sans-serif; }",
6816      ".foo{font-family:\"revert\",foo,sans-serif}",
6817    );
6818    minify_test(".foo { font-family: ''; }", ".foo{font-family:\"\"}");
6819
6820    // font-family in @font-face
6821    minify_test(
6822      "@font-face { font-family: 'revert'; }",
6823      "@font-face{font-family:\"revert\"}",
6824    );
6825    minify_test(
6826      "@font-face { font-family: 'revert-layer'; }",
6827      "@font-face{font-family:\"revert-layer\"}",
6828    );
6829
6830    prefix_test(
6831      r#"
6832      .foo {
6833        font-family: Helvetica, system-ui, sans-serif;
6834      }
6835    "#,
6836      indoc! {r#"
6837      .foo {
6838        font-family: Helvetica, system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Noto Sans, Ubuntu, Cantarell, Helvetica Neue, sans-serif;
6839      }
6840    "#
6841      },
6842      Browsers {
6843        safari: Some(8 << 16),
6844        ..Browsers::default()
6845      },
6846    );
6847
6848    prefix_test(
6849      r#"
6850      .foo {
6851        font: 100%/1.5 Helvetica, system-ui, sans-serif;
6852      }
6853    "#,
6854      indoc! {r#"
6855      .foo {
6856        font: 100% / 1.5 Helvetica, system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Noto Sans, Ubuntu, Cantarell, Helvetica Neue, sans-serif;
6857      }
6858    "#
6859      },
6860      Browsers {
6861        safari: Some(8 << 16),
6862        ..Browsers::default()
6863      },
6864    );
6865
6866    prefix_test(
6867      r#"
6868      .foo {
6869        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";
6870      }
6871    "#,
6872      indoc! {r#"
6873      .foo {
6874        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;
6875      }
6876    "#
6877      },
6878      Browsers {
6879        firefox: Some(91 << 16),
6880        ..Browsers::default()
6881      },
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: 22px;
6894        font-size: max(2cqw, 22px);
6895      }
6896    "#
6897      },
6898      Browsers {
6899        safari: Some(14 << 16),
6900        ..Browsers::default()
6901      },
6902    );
6903    prefix_test(
6904      r#"
6905      .foo {
6906        font-size: 22px;
6907        font-size: max(2cqw, 22px);
6908      }
6909    "#,
6910      indoc! {r#"
6911      .foo {
6912        font-size: max(2cqw, 22px);
6913      }
6914    "#
6915      },
6916      Browsers {
6917        safari: Some(16 << 16),
6918        ..Browsers::default()
6919      },
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: 22px;
6932        font-size: xxx-large;
6933      }
6934    "#
6935      },
6936      Browsers {
6937        chrome: Some(70 << 16),
6938        ..Browsers::default()
6939      },
6940    );
6941    prefix_test(
6942      r#"
6943      .foo {
6944        font-size: 22px;
6945        font-size: xxx-large;
6946      }
6947    "#,
6948      indoc! {r#"
6949      .foo {
6950        font-size: xxx-large;
6951      }
6952    "#
6953      },
6954      Browsers {
6955        chrome: Some(80 << 16),
6956        ..Browsers::default()
6957      },
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: 700;
6970        font-weight: 789;
6971      }
6972    "#
6973      },
6974      Browsers {
6975        chrome: Some(60 << 16),
6976        ..Browsers::default()
6977      },
6978    );
6979    prefix_test(
6980      r#"
6981      .foo {
6982        font-weight: 700;
6983        font-weight: 789;
6984      }
6985    "#,
6986      indoc! {r#"
6987      .foo {
6988        font-weight: 789;
6989      }
6990    "#
6991      },
6992      Browsers {
6993        chrome: Some(80 << 16),
6994        ..Browsers::default()
6995      },
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: Helvetica;
7008        font-family: system-ui;
7009      }
7010    "#
7011      },
7012      Browsers {
7013        chrome: Some(50 << 16),
7014        ..Browsers::default()
7015      },
7016    );
7017    prefix_test(
7018      r#"
7019      .foo {
7020        font-family: Helvetica;
7021        font-family: system-ui;
7022      }
7023    "#,
7024      indoc! {r#"
7025      .foo {
7026        font-family: system-ui;
7027      }
7028    "#
7029      },
7030      Browsers {
7031        chrome: Some(80 << 16),
7032        ..Browsers::default()
7033      },
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;
7046        font-style: oblique 40deg;
7047      }
7048    "#
7049      },
7050      Browsers {
7051        firefox: Some(50 << 16),
7052        ..Browsers::default()
7053      },
7054    );
7055    prefix_test(
7056      r#"
7057      .foo {
7058        font-style: oblique;
7059        font-style: oblique 40deg;
7060      }
7061    "#,
7062      indoc! {r#"
7063      .foo {
7064        font-style: oblique 40deg;
7065      }
7066    "#
7067      },
7068      Browsers {
7069        firefox: Some(80 << 16),
7070        ..Browsers::default()
7071      },
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: 22px Helvetica;
7084        font: xxx-large system-ui;
7085      }
7086    "#
7087      },
7088      Browsers {
7089        chrome: Some(70 << 16),
7090        ..Browsers::default()
7091      },
7092    );
7093    prefix_test(
7094      r#"
7095      .foo {
7096        font: 22px Helvetica;
7097        font: xxx-large system-ui;
7098      }
7099    "#,
7100      indoc! {r#"
7101      .foo {
7102        font: xxx-large system-ui;
7103      }
7104    "#
7105      },
7106      Browsers {
7107        chrome: Some(80 << 16),
7108        ..Browsers::default()
7109      },
7110    );
7111
7112    prefix_test(
7113      r#"
7114      .foo {
7115        font: var(--fallback);
7116        font: xxx-large system-ui;
7117      }
7118    "#,
7119      indoc! {r#"
7120      .foo {
7121        font: var(--fallback);
7122        font: xxx-large system-ui;
7123      }
7124    "#
7125      },
7126      Browsers {
7127        chrome: Some(50 << 16),
7128        ..Browsers::default()
7129      },
7130    );
7131  }
7132
7133  #[test]
7134  fn test_vertical_align() {
7135    minify_test(".foo { vertical-align: middle }", ".foo{vertical-align:middle}");
7136    minify_test(".foo { vertical-align: 0.3em }", ".foo{vertical-align:.3em}");
7137  }
7138
7139  #[test]
7140  fn test_selectors() {
7141    minify_test(":nth-col(2n) {width: 20px}", ":nth-col(2n){width:20px}");
7142    minify_test(":nth-col(10n-1) {width: 20px}", ":nth-col(10n-1){width:20px}");
7143    minify_test(":nth-col(-n+2) {width: 20px}", ":nth-col(-n+2){width:20px}");
7144    minify_test(":nth-col(even) {width: 20px}", ":nth-col(2n){width:20px}");
7145    minify_test(":nth-col(odd) {width: 20px}", ":nth-col(odd){width:20px}");
7146    minify_test(":nth-last-col(2n) {width: 20px}", ":nth-last-col(2n){width:20px}");
7147    minify_test(":nth-last-col(10n-1) {width: 20px}", ":nth-last-col(10n-1){width:20px}");
7148    minify_test(":nth-last-col(-n+2) {width: 20px}", ":nth-last-col(-n+2){width:20px}");
7149    minify_test(":nth-last-col(even) {width: 20px}", ":nth-last-col(2n){width:20px}");
7150    minify_test(":nth-last-col(odd) {width: 20px}", ":nth-last-col(odd){width:20px}");
7151    minify_test(":nth-child(odd) {width: 20px}", ":nth-child(odd){width:20px}");
7152    minify_test(":nth-child(2n) {width: 20px}", ":nth-child(2n){width:20px}");
7153    minify_test(":nth-child(2n+1) {width: 20px}", ":nth-child(odd){width:20px}");
7154    minify_test(":first-child {width: 20px}", ":first-child{width:20px}");
7155    minify_test(":nth-child(1) {width: 20px}", ":first-child{width:20px}");
7156    minify_test(":nth-last-child(1) {width: 20px}", ":last-child{width:20px}");
7157    minify_test(":nth-of-type(1) {width: 20px}", ":first-of-type{width:20px}");
7158    minify_test(":nth-last-of-type(1) {width: 20px}", ":last-of-type{width:20px}");
7159    minify_test(
7160      ":nth-child(even of li.important) {width: 20px}",
7161      ":nth-child(2n of li.important){width:20px}",
7162    );
7163    minify_test(
7164      ":nth-child(1 of li.important) {width: 20px}",
7165      ":nth-child(1 of li.important){width:20px}",
7166    );
7167    minify_test(
7168      ":nth-last-child(even of li.important) {width: 20px}",
7169      ":nth-last-child(2n of li.important){width:20px}",
7170    );
7171    minify_test(
7172      ":nth-last-child(1 of li.important) {width: 20px}",
7173      ":nth-last-child(1 of li.important){width:20px}",
7174    );
7175    minify_test(
7176      ":nth-last-child(1 of.important) {width: 20px}",
7177      ":nth-last-child(1 of .important){width:20px}",
7178    );
7179
7180    minify_test("[foo=\"baz\"] {color:red}", "[foo=baz]{color:red}");
7181    minify_test("[foo=\"foo bar\"] {color:red}", "[foo=foo\\ bar]{color:red}");
7182    minify_test("[foo=\"foo bar baz\"] {color:red}", "[foo=\"foo bar baz\"]{color:red}");
7183    minify_test("[foo=\"\"] {color:red}", "[foo=\"\"]{color:red}");
7184    minify_test(
7185      ".test:not([foo=\"bar\"]) {color:red}",
7186      ".test:not([foo=bar]){color:red}",
7187    );
7188    minify_test(".test + .foo {color:red}", ".test+.foo{color:red}");
7189    minify_test(".test ~ .foo {color:red}", ".test~.foo{color:red}");
7190    minify_test(".test .foo {color:red}", ".test .foo{color:red}");
7191    minify_test(
7192      ".custom-range::-webkit-slider-thumb:active {color:red}",
7193      ".custom-range::-webkit-slider-thumb:active{color:red}",
7194    );
7195    minify_test(".test:not(.foo, .bar) {color:red}", ".test:not(.foo,.bar){color:red}");
7196    minify_test(".test:is(.foo, .bar) {color:red}", ".test:is(.foo,.bar){color:red}");
7197    minify_test(
7198      ".test:where(.foo, .bar) {color:red}",
7199      ".test:where(.foo,.bar){color:red}",
7200    );
7201    minify_test(
7202      ".test:where(.foo, .bar) {color:red}",
7203      ".test:where(.foo,.bar){color:red}",
7204    );
7205
7206    // Test scroll navigation controls pseudo-classes
7207    let scroll_navigation_controls_options = ParserOptions {
7208      flags: ParserFlags::SCROLL_NAVIGATION_CONTROLS,
7209      ..ParserOptions::default()
7210    };
7211    minify_test_with_options(
7212      "a:target-current { color: green }",
7213      "a:target-current{color:green}",
7214      scroll_navigation_controls_options.clone(),
7215    );
7216    minify_test_with_options(
7217      "a:target-before { color: green }",
7218      "a:target-before{color:green}",
7219      scroll_navigation_controls_options.clone(),
7220    );
7221    minify_test_with_options(
7222      "a:target-after { color: green }",
7223      "a:target-after{color:green}",
7224      scroll_navigation_controls_options.clone(),
7225    );
7226    minify_test_with_options(
7227      ":is(a:target-before, a:target-after) { color: green }",
7228      ":is(a:target-before,a:target-after){color:green}",
7229      scroll_navigation_controls_options.clone(),
7230    );
7231    minify_test_with_options(
7232      "a:where(:target-before, :target-after) { color: green }",
7233      "a:where(:target-before,:target-after){color:green}",
7234      scroll_navigation_controls_options.clone(),
7235    );
7236    // If the browser does not support it, it will output the `:is()` selector.
7237    minify_test_with_options_and_browsers(
7238      "a:target-before, a:target-after { color: green }",
7239      ":is(a:target-before,a:target-after){color:green}",
7240      scroll_navigation_controls_options.clone(),
7241      Some(Browsers {
7242        chrome: Some(130 << 16),
7243        ..Browsers::default()
7244      }),
7245    );
7246    minify_test_with_options_and_browsers(
7247      "a:target-before, a:target-after { color: green }",
7248      "a:target-before,a:target-after{color:green}",
7249      scroll_navigation_controls_options.clone(),
7250      Some(Browsers {
7251        chrome: Some(150 << 16),
7252        ..Browsers::default()
7253      }),
7254    );
7255
7256    error_test_with_options(
7257      "a::before:target-current { color: green }",
7258      ParserError::SelectorError(SelectorError::InvalidPseudoClassAfterPseudoElement),
7259      ParserOptions {
7260        flags: ParserFlags::SCROLL_NAVIGATION_CONTROLS,
7261        ..ParserOptions::default()
7262      },
7263    );
7264
7265    let warnings = Some(Arc::new(RwLock::new(Vec::new())));
7266    let _ = StyleSheet::parse(
7267      "a:target-current { color: green }",
7268      ParserOptions {
7269        warnings: warnings.clone(),
7270        ..ParserOptions::default()
7271      },
7272    )
7273    .unwrap();
7274    let warnings = Arc::try_unwrap(warnings.unwrap()).unwrap().into_inner().unwrap();
7275    assert_eq!(warnings.len(), 1);
7276    assert_eq!(
7277      warnings[0].kind,
7278      ParserError::SelectorError(SelectorError::UnsupportedPseudoClass("target-current".into()))
7279    );
7280
7281    minify_test(":host {color:red}", ":host{color:red}");
7282    minify_test(":host(.foo) {color:red}", ":host(.foo){color:red}");
7283    minify_test("::slotted(span) {color:red", "::slotted(span){color:red}");
7284    minify_test(
7285      "custom-element::part(foo) {color:red}",
7286      "custom-element::part(foo){color:red}",
7287    );
7288    minify_test(".sm\\:text-5xl { font-size: 3rem }", ".sm\\:text-5xl{font-size:3rem}");
7289    minify_test("a:has(> img) {color:red}", "a:has(>img){color:red}");
7290    minify_test("dt:has(+ dt) {color:red}", "dt:has(+dt){color:red}");
7291    minify_test(
7292      "section:not(:has(h1, h2, h3, h4, h5, h6)) {color:red}",
7293      "section:not(:has(h1,h2,h3,h4,h5,h6)){color:red}",
7294    );
7295    minify_test(
7296      ":has(.sibling ~ .target) {color:red}",
7297      ":has(.sibling~.target){color:red}",
7298    );
7299    minify_test(".x:has(> .a > .b) {color:red}", ".x:has(>.a>.b){color:red}");
7300    minify_test(".x:has(.bar, #foo) {color:red}", ".x:has(.bar,#foo){color:red}");
7301    minify_test(".x:has(span + span) {color:red}", ".x:has(span+span){color:red}");
7302    minify_test("a:has(:visited) {color:red}", "a:has(:visited){color:red}");
7303    for element in [
7304      "-webkit-scrollbar",
7305      "-webkit-scrollbar-button",
7306      "-webkit-scrollbar-track",
7307      "-webkit-scrollbar-track-piece",
7308      "-webkit-scrollbar-thumb",
7309      "-webkit-scrollbar-corner",
7310      "-webkit-resizer",
7311    ] {
7312      for class in [
7313        "enabled",
7314        "disabled",
7315        "hover",
7316        "active",
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        minify_test(
7330          &format!("::{}:{} {{color:red}}", element, class),
7331          &format!("::{}:{}{{color:red}}", element, class),
7332        );
7333      }
7334    }
7335    for class in [
7336      "horizontal",
7337      "vertical",
7338      "decrement",
7339      "increment",
7340      "start",
7341      "end",
7342      "double-button",
7343      "single-button",
7344      "no-button",
7345      "corner-present",
7346      "window-inactive",
7347    ] {
7348      error_test(
7349        &format!(":{} {{color:red}}", class),
7350        ParserError::SelectorError(SelectorError::InvalidPseudoClassBeforeWebKitScrollbar),
7351      );
7352    }
7353    for element in [
7354      "-webkit-scrollbar",
7355      "-webkit-scrollbar-button",
7356      "-webkit-scrollbar-track",
7357      "-webkit-scrollbar-track-piece",
7358      "-webkit-scrollbar-thumb",
7359      "-webkit-scrollbar-corner",
7360      "-webkit-resizer",
7361    ] {
7362      error_test(
7363        &format!("::{}:focus {{color:red}}", element),
7364        ParserError::SelectorError(SelectorError::InvalidPseudoClassAfterWebKitScrollbar),
7365      );
7366    }
7367
7368    error_test(
7369      "a::first-letter:last-child {color:red}",
7370      ParserError::SelectorError(SelectorError::InvalidPseudoClassAfterPseudoElement),
7371    );
7372    minify_test(
7373      "a:last-child::first-letter {color:red}",
7374      "a:last-child:first-letter{color:red}",
7375    );
7376
7377    prefix_test(
7378      ".test:not(.foo, .bar) {color:red}",
7379      indoc! {r#"
7380      .test:not(:-webkit-any(.foo, .bar)) {
7381        color: red;
7382      }
7383
7384      .test:not(:is(.foo, .bar)) {
7385        color: red;
7386      }
7387      "#},
7388      Browsers {
7389        safari: Some(8 << 16),
7390        ..Browsers::default()
7391      },
7392    );
7393    prefix_test(
7394      ".test:not(.foo, .bar) {color:red}",
7395      indoc! {r#"
7396      .test:not(.foo, .bar) {
7397        color: red;
7398      }
7399      "#},
7400      Browsers {
7401        safari: Some(11 << 16),
7402        ..Browsers::default()
7403      },
7404    );
7405
7406    minify_test("a:lang(en) {color:red}", "a:lang(en){color:red}");
7407    minify_test("a:lang(en, fr) {color:red}", "a:lang(en,fr){color:red}");
7408    minify_test("a:lang('en') {color:red}", "a:lang(en){color:red}");
7409    minify_test(
7410      "a:-webkit-any(.foo, .bar) {color:red}",
7411      "a:-webkit-any(.foo,.bar){color:red}",
7412    );
7413    minify_test("a:-moz-any(.foo, .bar) {color:red}", "a:-moz-any(.foo,.bar){color:red}");
7414
7415    prefix_test(
7416      "a:is(.foo, .bar) {color:red}",
7417      indoc! {r#"
7418      a:-webkit-any(.foo, .bar) {
7419        color: red;
7420      }
7421
7422      a:-moz-any(.foo, .bar) {
7423        color: red;
7424      }
7425
7426      a:is(.foo, .bar) {
7427        color: red;
7428      }
7429      "#},
7430      Browsers {
7431        safari: Some(11 << 16),
7432        firefox: Some(50 << 16),
7433        ..Browsers::default()
7434      },
7435    );
7436
7437    prefix_test(
7438      "a:is(.foo > .bar) {color:red}",
7439      indoc! {r#"
7440      a:is(.foo > .bar) {
7441        color: red;
7442      }
7443      "#},
7444      Browsers {
7445        safari: Some(11 << 16),
7446        firefox: Some(50 << 16),
7447        ..Browsers::default()
7448      },
7449    );
7450
7451    prefix_test(
7452      "a:lang(en, fr) {color:red}",
7453      indoc! {r#"
7454      a:-webkit-any(:lang(en), :lang(fr)) {
7455        color: red;
7456      }
7457
7458      a:-moz-any(:lang(en), :lang(fr)) {
7459        color: red;
7460      }
7461
7462      a:is(:lang(en), :lang(fr)) {
7463        color: red;
7464      }
7465      "#},
7466      Browsers {
7467        safari: Some(11 << 16),
7468        firefox: Some(50 << 16),
7469        ..Browsers::default()
7470      },
7471    );
7472
7473    prefix_test(
7474      "a:lang(en, fr) {color:red}",
7475      indoc! {r#"
7476      a:is(:lang(en), :lang(fr)) {
7477        color: red;
7478      }
7479      "#},
7480      Browsers {
7481        safari: Some(14 << 16),
7482        firefox: Some(88 << 16),
7483        ..Browsers::default()
7484      },
7485    );
7486
7487    prefix_test(
7488      "a:lang(en, fr) {color:red}",
7489      indoc! {r#"
7490      a:lang(en, fr) {
7491        color: red;
7492      }
7493      "#},
7494      Browsers {
7495        safari: Some(14 << 16),
7496        ..Browsers::default()
7497      },
7498    );
7499
7500    prefix_test(
7501      "a:dir(rtl) {color:red}",
7502      indoc! {r#"
7503      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)) {
7504        color: red;
7505      }
7506
7507      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)) {
7508        color: red;
7509      }
7510
7511      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)) {
7512        color: red;
7513      }
7514      "#},
7515      Browsers {
7516        safari: Some(11 << 16),
7517        firefox: Some(50 << 16),
7518        ..Browsers::default()
7519      },
7520    );
7521
7522    prefix_test(
7523      "a:dir(ltr) {color:red}",
7524      indoc! {r#"
7525      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))) {
7526        color: red;
7527      }
7528
7529      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))) {
7530        color: red;
7531      }
7532
7533      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))) {
7534        color: red;
7535      }
7536      "#},
7537      Browsers {
7538        safari: Some(11 << 16),
7539        firefox: Some(50 << 16),
7540        ..Browsers::default()
7541      },
7542    );
7543
7544    prefix_test(
7545      "a:dir(rtl) {color:red}",
7546      indoc! {r#"
7547      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)) {
7548        color: red;
7549      }
7550      "#},
7551      Browsers {
7552        safari: Some(14 << 16),
7553        firefox: Some(88 << 16),
7554        ..Browsers::default()
7555      },
7556    );
7557
7558    prefix_test(
7559      "a:dir(ltr) {color:red}",
7560      indoc! {r#"
7561      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)) {
7562        color: red;
7563      }
7564      "#},
7565      Browsers {
7566        safari: Some(14 << 16),
7567        firefox: Some(88 << 16),
7568        ..Browsers::default()
7569      },
7570    );
7571
7572    prefix_test(
7573      "a:dir(rtl) {color:red}",
7574      indoc! {r#"
7575      a:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
7576        color: red;
7577      }
7578      "#},
7579      Browsers {
7580        safari: Some(14 << 16),
7581        ..Browsers::default()
7582      },
7583    );
7584
7585    prefix_test(
7586      "a:dir(ltr) {color:red}",
7587      indoc! {r#"
7588      a:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
7589        color: red;
7590      }
7591      "#},
7592      Browsers {
7593        safari: Some(14 << 16),
7594        ..Browsers::default()
7595      },
7596    );
7597
7598    prefix_test(
7599      "a:is(:dir(rtl)) {color:red}",
7600      indoc! {r#"
7601      a:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
7602        color: red;
7603      }
7604      "#},
7605      Browsers {
7606        safari: Some(14 << 16),
7607        ..Browsers::default()
7608      },
7609    );
7610
7611    prefix_test(
7612      "a:where(:dir(rtl)) {color:red}",
7613      indoc! {r#"
7614      a:where(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
7615        color: red;
7616      }
7617      "#},
7618      Browsers {
7619        safari: Some(14 << 16),
7620        ..Browsers::default()
7621      },
7622    );
7623
7624    prefix_test(
7625      "a:has(:dir(rtl)) {color:red}",
7626      indoc! {r#"
7627      a:has(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
7628        color: red;
7629      }
7630      "#},
7631      Browsers {
7632        safari: Some(14 << 16),
7633        ..Browsers::default()
7634      },
7635    );
7636
7637    prefix_test(
7638      "a:not(:dir(rtl)) {color:red}",
7639      indoc! {r#"
7640      a:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
7641        color: red;
7642      }
7643      "#},
7644      Browsers {
7645        safari: Some(14 << 16),
7646        ..Browsers::default()
7647      },
7648    );
7649
7650    prefix_test(
7651      "a:dir(rtl)::after {color:red}",
7652      indoc! {r#"
7653      a:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi):after {
7654        color: red;
7655      }
7656      "#},
7657      Browsers {
7658        safari: Some(14 << 16),
7659        ..Browsers::default()
7660      },
7661    );
7662
7663    prefix_test(
7664      "a:dir(rtl) div {color:red}",
7665      indoc! {r#"
7666      a:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) div {
7667        color: red;
7668      }
7669      "#},
7670      Browsers {
7671        safari: Some(14 << 16),
7672        ..Browsers::default()
7673      },
7674    );
7675
7676    minify_test(".foo::cue {color: red}", ".foo::cue{color:red}");
7677    minify_test(".foo::cue-region {color: red}", ".foo::cue-region{color:red}");
7678    minify_test(".foo::cue(b) {color: red}", ".foo::cue(b){color:red}");
7679    minify_test(".foo::cue-region(b) {color: red}", ".foo::cue-region(b){color:red}");
7680    minify_test(
7681      "::cue(v[voice='active']) {color: yellow;}",
7682      "::cue(v[voice=active]){color:#ff0}",
7683    );
7684    minify_test(":foo(bar) { color: yellow }", ":foo(bar){color:#ff0}");
7685    minify_test("::foo(bar) { color: yellow }", "::foo(bar){color:#ff0}");
7686    minify_test("::foo(*) { color: yellow }", "::foo(*){color:#ff0}");
7687
7688    minify_test(":is(.foo) { color: yellow }", ".foo{color:#ff0}");
7689    minify_test(":is(#foo) { color: yellow }", "#foo{color:#ff0}");
7690    minify_test("a:is(.foo) { color: yellow }", "a.foo{color:#ff0}");
7691    minify_test("a:is([data-test]) { color: yellow }", "a[data-test]{color:#ff0}");
7692    minify_test(".foo:is(a) { color: yellow }", ".foo:is(a){color:#ff0}");
7693    minify_test(".foo:is(*|a) { color: yellow }", ".foo:is(*|a){color:#ff0}");
7694    minify_test(".foo:is(*) { color: yellow }", ".foo:is(*){color:#ff0}");
7695    minify_test(
7696      "@namespace svg url(http://www.w3.org/2000/svg); .foo:is(svg|a) { color: yellow }",
7697      "@namespace svg \"http://www.w3.org/2000/svg\";.foo:is(svg|a){color:#ff0}",
7698    );
7699    minify_test("a:is(.foo .bar) { color: yellow }", "a:is(.foo .bar){color:#ff0}");
7700    minify_test(":is(.foo, .bar) { color: yellow }", ":is(.foo,.bar){color:#ff0}");
7701    minify_test("a:is(:not(.foo)) { color: yellow }", "a:not(.foo){color:#ff0}");
7702    minify_test("a:is(:first-child) { color: yellow }", "a:first-child{color:#ff0}");
7703    minify_test("a:is(:has(.foo)) { color: yellow }", "a:has(.foo){color:#ff0}");
7704    minify_test("a:is(:is(.foo)) { color: yellow }", "a.foo{color:#ff0}");
7705    minify_test(":host(:hover) {color: red}", ":host(:hover){color:red}");
7706    minify_test("::slotted(:hover) {color: red}", "::slotted(:hover){color:red}");
7707
7708    minify_test(
7709      ":root::view-transition {position: fixed}",
7710      ":root::view-transition{position:fixed}",
7711    );
7712    minify_test(
7713      ":root:active-view-transition {position: fixed}",
7714      ":root:active-view-transition{position:fixed}",
7715    );
7716    minify_test(
7717      ":root:active-view-transition-type(slide-in) {position: fixed}",
7718      ":root:active-view-transition-type(slide-in){position:fixed}",
7719    );
7720    minify_test(
7721      ":root:active-view-transition-type(slide-in, reverse) {position: fixed}",
7722      ":root:active-view-transition-type(slide-in,reverse){position:fixed}",
7723    );
7724
7725    for name in &[
7726      "view-transition-group",
7727      "view-transition-image-pair",
7728      "view-transition-new",
7729      "view-transition-old",
7730    ] {
7731      minify_test(
7732        &format!(":root::{}(*) {{position: fixed}}", name),
7733        &format!(":root::{}(*){{position:fixed}}", name),
7734      );
7735      minify_test(
7736        &format!(":root::{}(*.class) {{position: fixed}}", name),
7737        &format!(":root::{}(*.class){{position:fixed}}", name),
7738      );
7739      minify_test(
7740        &format!(":root::{}(*.class.class) {{position: fixed}}", name),
7741        &format!(":root::{}(*.class.class){{position:fixed}}", name),
7742      );
7743      minify_test(
7744        &format!(":root::{}(foo) {{position: fixed}}", name),
7745        &format!(":root::{}(foo){{position:fixed}}", name),
7746      );
7747      minify_test(
7748        &format!(":root::{}(foo.class) {{position: fixed}}", name),
7749        &format!(":root::{}(foo.class){{position:fixed}}", name),
7750      );
7751      minify_test(
7752        &format!(":root::{}(foo.bar.baz) {{position: fixed}}", name),
7753        &format!(":root::{}(foo.bar.baz){{position:fixed}}", name),
7754      );
7755      minify_test(
7756        &format!(":root::{}(foo):only-child {{position: fixed}}", name),
7757        &format!(":root::{}(foo):only-child{{position:fixed}}", name),
7758      );
7759      minify_test(
7760        &format!(":root::{}(foo.bar.baz):only-child {{position: fixed}}", name),
7761        &format!(":root::{}(foo.bar.baz):only-child{{position:fixed}}", name),
7762      );
7763      minify_test(
7764        &format!(":root::{}(.foo) {{position: fixed}}", name),
7765        &format!(":root::{}(.foo){{position:fixed}}", name),
7766      );
7767      minify_test(
7768        &format!(":root::{}(.foo.bar) {{position: fixed}}", name),
7769        &format!(":root::{}(.foo.bar){{position:fixed}}", name),
7770      );
7771      minify_test(
7772        &format!(":root::{}(  .foo.bar  ) {{position: fixed}}", name),
7773        &format!(":root::{}(.foo.bar){{position:fixed}}", name),
7774      );
7775      error_test(
7776        &format!(":root::{}(foo):first-child {{position: fixed}}", name),
7777        ParserError::SelectorError(SelectorError::InvalidPseudoClassAfterPseudoElement),
7778      );
7779      error_test(
7780        &format!(":root::{}(foo)::before {{position: fixed}}", name),
7781        ParserError::SelectorError(SelectorError::InvalidState),
7782      );
7783      error_test(
7784        &format!(":root::{}(*.*) {{position: fixed}}", name),
7785        ParserError::SelectorError(SelectorError::InvalidState),
7786      );
7787      error_test(
7788        &format!(":root::{}(*. cls) {{position: fixed}}", name),
7789        ParserError::SelectorError(SelectorError::InvalidState),
7790      );
7791      error_test(
7792        &format!(":root::{}(foo .bar) {{position: fixed}}", name),
7793        ParserError::SelectorError(SelectorError::InvalidState),
7794      );
7795      error_test(
7796        &format!(":root::{}(*.cls. c) {{position: fixed}}", name),
7797        ParserError::SelectorError(SelectorError::InvalidState),
7798      );
7799      error_test(
7800        &format!(":root::{}(*.cls>cls) {{position: fixed}}", name),
7801        ParserError::SelectorError(SelectorError::InvalidState),
7802      );
7803      error_test(
7804        &format!(":root::{}(*.cls.foo.*) {{position: fixed}}", name),
7805        ParserError::SelectorError(SelectorError::InvalidState),
7806      );
7807    }
7808    minify_test(
7809      "wa-checkbox:state(disabled) {color:red}",
7810      "wa-checkbox:state(disabled){color:red}",
7811    );
7812    minify_test(
7813      "button:state(checked) {background:blue}",
7814      "button:state(checked){background:#00f}",
7815    );
7816    minify_test(
7817      "input:state(custom-state) {border:1px solid}",
7818      "input:state(custom-state){border:1px solid}",
7819    );
7820    minify_test(
7821      "button:active:not(:state(disabled))::part(control) {border:1px solid}",
7822      "button:active:not(:state(disabled))::part(control){border:1px solid}",
7823    );
7824    // Test nested CSS with :state() selector
7825    nesting_test(
7826      r#"
7827        custom-element {
7828          color: blue;
7829          &:state(loading) {
7830            opacity: 0.5;
7831            & .spinner {
7832              display: block;
7833            }
7834          }
7835          &:state(error) {
7836            border: 2px solid red;
7837          }
7838        }
7839      "#,
7840      indoc! {r#"
7841        custom-element {
7842          color: #00f;
7843        }
7844
7845        custom-element:state(loading) {
7846          opacity: .5;
7847        }
7848
7849        custom-element:state(loading) .spinner {
7850          display: block;
7851        }
7852
7853        custom-element:state(error) {
7854          border: 2px solid red;
7855        }
7856      "#},
7857    );
7858    minify_test(".foo ::deep .bar {width: 20px}", ".foo ::deep .bar{width:20px}");
7859    minify_test(".foo::deep .bar {width: 20px}", ".foo::deep .bar{width:20px}");
7860    minify_test(".foo ::deep.bar {width: 20px}", ".foo ::deep.bar{width:20px}");
7861    minify_test(".foo ::unknown .bar {width: 20px}", ".foo ::unknown .bar{width:20px}");
7862    minify_test(
7863      ".foo ::unknown(foo) .bar {width: 20px}",
7864      ".foo ::unknown(foo) .bar{width:20px}",
7865    );
7866    minify_test(
7867      ".foo ::unknown:only-child {width: 20px}",
7868      ".foo ::unknown:only-child{width:20px}",
7869    );
7870    minify_test(
7871      ".foo ::unknown(.foo) .bar {width: 20px}",
7872      ".foo ::unknown(.foo) .bar{width:20px}",
7873    );
7874    minify_test(
7875      ".foo ::unknown(.foo .bar / .baz) .bar {width: 20px}",
7876      ".foo ::unknown(.foo .bar / .baz) .bar{width:20px}",
7877    );
7878    minify_test(
7879      ".foo ::unknown(something(foo)) .bar {width: 20px}",
7880      ".foo ::unknown(something(foo)) .bar{width:20px}",
7881    );
7882    minify_test(
7883      ".foo ::unknown([abc]) .bar {width: 20px}",
7884      ".foo ::unknown([abc]) .bar{width:20px}",
7885    );
7886
7887    let deep_options = ParserOptions {
7888      flags: ParserFlags::DEEP_SELECTOR_COMBINATOR,
7889      ..ParserOptions::default()
7890    };
7891
7892    error_test(
7893      ".foo >>> .bar {width: 20px}",
7894      ParserError::SelectorError(SelectorError::DanglingCombinator),
7895    );
7896    error_test(
7897      ".foo /deep/ .bar {width: 20px}",
7898      ParserError::SelectorError(SelectorError::DanglingCombinator),
7899    );
7900    minify_test_with_options(
7901      ".foo >>> .bar {width: 20px}",
7902      ".foo>>>.bar{width:20px}",
7903      deep_options.clone(),
7904    );
7905    minify_test_with_options(
7906      ".foo /deep/ .bar {width: 20px}",
7907      ".foo /deep/ .bar{width:20px}",
7908      deep_options.clone(),
7909    );
7910
7911    let pure_css_module_options = ParserOptions {
7912      css_modules: Some(crate::css_modules::Config {
7913        pure: true,
7914        ..Default::default()
7915      }),
7916      ..ParserOptions::default()
7917    };
7918
7919    minify_error_test_with_options(
7920      "div {width: 20px}",
7921      MinifyErrorKind::ImpureCSSModuleSelector,
7922      pure_css_module_options.clone(),
7923    );
7924    minify_error_test_with_options(
7925      ":global(.foo) {width: 20px}",
7926      MinifyErrorKind::ImpureCSSModuleSelector,
7927      pure_css_module_options.clone(),
7928    );
7929    minify_error_test_with_options(
7930      "[foo=bar] {width: 20px}",
7931      MinifyErrorKind::ImpureCSSModuleSelector,
7932      pure_css_module_options.clone(),
7933    );
7934    minify_error_test_with_options(
7935      "div, .foo {width: 20px}",
7936      MinifyErrorKind::ImpureCSSModuleSelector,
7937      pure_css_module_options.clone(),
7938    );
7939    minify_test_with_options(
7940      ":local(.foo) {width: 20px}",
7941      "._8Z4fiW_foo{width:20px}",
7942      pure_css_module_options.clone(),
7943    );
7944    minify_test_with_options(
7945      "div.my-class {color: red;}",
7946      "div._8Z4fiW_my-class{color:red}",
7947      pure_css_module_options.clone(),
7948    );
7949    minify_test_with_options(
7950      "#id {color: red;}",
7951      "#_8Z4fiW_id{color:red}",
7952      pure_css_module_options.clone(),
7953    );
7954    minify_test_with_options(
7955      "a .my-class{color: red;}",
7956      "a ._8Z4fiW_my-class{color:red}",
7957      pure_css_module_options.clone(),
7958    );
7959    minify_test_with_options(
7960      ".my-class a {color: red;}",
7961      "._8Z4fiW_my-class a{color:red}",
7962      pure_css_module_options.clone(),
7963    );
7964    minify_test_with_options(
7965      ".my-class:is(a) {color: red;}",
7966      "._8Z4fiW_my-class:is(a){color:red}",
7967      pure_css_module_options.clone(),
7968    );
7969    minify_test_with_options(
7970      "div:has(.my-class) {color: red;}",
7971      "div:has(._8Z4fiW_my-class){color:red}",
7972      pure_css_module_options.clone(),
7973    );
7974    minify_test_with_options(
7975      ".foo { html &:hover { a_value: some-value; } }",
7976      "._8Z4fiW_foo{html &:hover{a_value:some-value}}",
7977      pure_css_module_options.clone(),
7978    );
7979    minify_test_with_options(
7980      ".foo { span { color: red; } }",
7981      "._8Z4fiW_foo{& span{color:red}}",
7982      pure_css_module_options.clone(),
7983    );
7984    minify_error_test_with_options(
7985      "html { .foo { span { color: red; } } }",
7986      MinifyErrorKind::ImpureCSSModuleSelector,
7987      pure_css_module_options.clone(),
7988    );
7989    minify_test_with_options(
7990      ".foo { div { span { color: red; } } }",
7991      "._8Z4fiW_foo{& div{& span{color:red}}}",
7992      pure_css_module_options.clone(),
7993    );
7994    minify_error_test_with_options(
7995      "@scope (div) { .foo { color: red } }",
7996      MinifyErrorKind::ImpureCSSModuleSelector,
7997      pure_css_module_options.clone(),
7998    );
7999    minify_error_test_with_options(
8000      "@scope (.a) to (div) { .foo { color: red } }",
8001      MinifyErrorKind::ImpureCSSModuleSelector,
8002      pure_css_module_options.clone(),
8003    );
8004    minify_error_test_with_options(
8005      "@scope (.a) to (.b) { div { color: red } }",
8006      MinifyErrorKind::ImpureCSSModuleSelector,
8007      pure_css_module_options.clone(),
8008    );
8009    minify_test_with_options(
8010      "@scope (.a) to (.b) { .foo { color: red } }",
8011      "@scope(._8Z4fiW_a) to (._8Z4fiW_b){._8Z4fiW_foo{color:red}}",
8012      pure_css_module_options.clone(),
8013    );
8014    minify_test_with_options(
8015      "/* cssmodules-pure-no-check */ :global(.foo) { color: red }",
8016      ".foo{color:red}",
8017      pure_css_module_options.clone(),
8018    );
8019    minify_test_with_options(
8020      "/*! some license */ /* cssmodules-pure-no-check */ :global(.foo) { color: red }",
8021      "/*! some license */\n.foo{color:red}",
8022      pure_css_module_options.clone(),
8023    );
8024
8025    error_test(
8026      "input.defaultCheckbox::before h1 {width: 20px}",
8027      ParserError::SelectorError(SelectorError::UnexpectedSelectorAfterPseudoElement(Token::Ident(
8028        "h1".into(),
8029      ))),
8030    );
8031    error_test(
8032      "input.defaultCheckbox::before .my-class {width: 20px}",
8033      ParserError::SelectorError(SelectorError::UnexpectedSelectorAfterPseudoElement(Token::Delim('.'))),
8034    );
8035    error_test(
8036      "input.defaultCheckbox::before.my-class {width: 20px}",
8037      ParserError::SelectorError(SelectorError::UnexpectedSelectorAfterPseudoElement(Token::Delim('.'))),
8038    );
8039    error_test(
8040      "input.defaultCheckbox::before #id {width: 20px}",
8041      ParserError::SelectorError(SelectorError::UnexpectedSelectorAfterPseudoElement(Token::IDHash(
8042        "id".into(),
8043      ))),
8044    );
8045    error_test(
8046      "input.defaultCheckbox::before#id {width: 20px}",
8047      ParserError::SelectorError(SelectorError::UnexpectedSelectorAfterPseudoElement(Token::IDHash(
8048        "id".into(),
8049      ))),
8050    );
8051    error_test(
8052      "input.defaultCheckbox::before [attr] {width: 20px}",
8053      ParserError::SelectorError(SelectorError::UnexpectedSelectorAfterPseudoElement(
8054        Token::SquareBracketBlock,
8055      )),
8056    );
8057    error_test(
8058      "input.defaultCheckbox::before[attr] {width: 20px}",
8059      ParserError::SelectorError(SelectorError::UnexpectedSelectorAfterPseudoElement(
8060        Token::SquareBracketBlock,
8061      )),
8062    );
8063  }
8064
8065  #[test]
8066  fn test_keyframes() {
8067    minify_test(
8068      r#"
8069      @keyframes "test" {
8070        100% {
8071          background: blue
8072        }
8073      }
8074    "#,
8075      "@keyframes test{to{background:#00f}}",
8076    );
8077    minify_test(
8078      r#"
8079      @keyframes test {
8080        100% {
8081          background: blue
8082        }
8083      }
8084    "#,
8085      "@keyframes test{to{background:#00f}}",
8086    );
8087
8088    // named animation range percentages
8089    minify_test(
8090      r#"
8091      @keyframes test {
8092        entry 0% {
8093          background: blue
8094        }
8095        exit 100% {
8096          background: green
8097        }
8098      }
8099    "#,
8100      "@keyframes test{entry 0%{background:#00f}exit 100%{background:green}}",
8101    );
8102
8103    // CSS-wide keywords and `none` cannot remove quotes.
8104    minify_test(
8105      r#"
8106      @keyframes "revert" {
8107        from {
8108          background: green;
8109        }
8110      }
8111    "#,
8112      "@keyframes \"revert\"{0%{background:green}}",
8113    );
8114
8115    minify_test(
8116      r#"
8117      @keyframes "none" {
8118        from {
8119          background: green;
8120        }
8121      }
8122    "#,
8123      "@keyframes \"none\"{0%{background:green}}",
8124    );
8125
8126    // named animation ranges cannot be used with to or from
8127    minify_test(
8128      r#"
8129      @keyframes test {
8130        entry to {
8131          background: blue
8132        }
8133      }
8134    "#,
8135      "@keyframes test{}",
8136    );
8137
8138    // CSS-wide keywords without quotes throws an error.
8139    error_test(
8140      r#"
8141      @keyframes revert {}
8142    "#,
8143      ParserError::UnexpectedToken(Token::Ident("revert".into())),
8144    );
8145
8146    error_test(
8147      r#"
8148      @keyframes revert-layer {}
8149    "#,
8150      ParserError::UnexpectedToken(Token::Ident("revert-layer".into())),
8151    );
8152
8153    error_test(
8154      r#"
8155      @keyframes none {}
8156    "#,
8157      ParserError::UnexpectedToken(Token::Ident("none".into())),
8158    );
8159
8160    error_test(
8161      r#"
8162      @keyframes NONE {}
8163    "#,
8164      ParserError::UnexpectedToken(Token::Ident("NONE".into())),
8165    );
8166
8167    minify_test(
8168      r#"
8169      @-webkit-keyframes test {
8170        from {
8171          background: green;
8172          background-color: red;
8173        }
8174
8175        100% {
8176          background: blue
8177        }
8178      }
8179    "#,
8180      "@-webkit-keyframes test{0%{background:red}to{background:#00f}}",
8181    );
8182    minify_test(
8183      r#"
8184      @-moz-keyframes test {
8185        from {
8186          background: green;
8187          background-color: red;
8188        }
8189
8190        100% {
8191          background: blue
8192        }
8193      }
8194    "#,
8195      "@-moz-keyframes test{0%{background:red}to{background:#00f}}",
8196    );
8197    minify_test(r#"
8198      @-webkit-keyframes test {
8199        from {
8200          background: green;
8201          background-color: red;
8202        }
8203
8204        100% {
8205          background: blue
8206        }
8207      }
8208      @-moz-keyframes test {
8209        from {
8210          background: green;
8211          background-color: red;
8212        }
8213
8214        100% {
8215          background: blue
8216        }
8217      }
8218    "#, "@-webkit-keyframes test{0%{background:red}to{background:#00f}}@-moz-keyframes test{0%{background:red}to{background:#00f}}");
8219
8220    prefix_test(
8221      r#"
8222      @keyframes test {
8223        from {
8224          background: green;
8225        }
8226        to {
8227          background: blue
8228        }
8229      }
8230    "#,
8231      indoc! { r#"
8232      @-webkit-keyframes test {
8233        from {
8234          background: green;
8235        }
8236
8237        to {
8238          background: #00f;
8239        }
8240      }
8241
8242      @-moz-keyframes test {
8243        from {
8244          background: green;
8245        }
8246
8247        to {
8248          background: #00f;
8249        }
8250      }
8251
8252      @keyframes test {
8253        from {
8254          background: green;
8255        }
8256
8257        to {
8258          background: #00f;
8259        }
8260      }
8261    "#},
8262      Browsers {
8263        safari: Some(5 << 16),
8264        firefox: Some(6 << 16),
8265        ..Browsers::default()
8266      },
8267    );
8268    prefix_test(
8269      r#"
8270      @-webkit-keyframes test {
8271        from {
8272          background: green;
8273        }
8274
8275        to {
8276          background: blue;
8277        }
8278      }
8279      @-moz-keyframes test {
8280        from {
8281          background: green;
8282        }
8283
8284        to {
8285          background: blue;
8286        }
8287      }
8288      @keyframes test {
8289        from {
8290          background: green;
8291        }
8292        to {
8293          background: blue
8294        }
8295      }
8296    "#,
8297      indoc! { r#"
8298      @keyframes test {
8299        from {
8300          background: green;
8301        }
8302
8303        to {
8304          background: #00f;
8305        }
8306      }
8307    "#},
8308      Browsers {
8309        safari: Some(10 << 16),
8310        firefox: Some(17 << 16),
8311        ..Browsers::default()
8312      },
8313    );
8314    prefix_test(
8315      r#"
8316      @-webkit-keyframes test1 {
8317        from {
8318          background: green;
8319        }
8320
8321        to {
8322          background: blue;
8323        }
8324      }
8325
8326      @-moz-keyframes test2 {
8327        from {
8328          background: green;
8329        }
8330
8331        to {
8332          background: blue;
8333        }
8334      }
8335
8336      @keyframes test3 {
8337        from {
8338          background: green;
8339        }
8340        to {
8341          background: blue
8342        }
8343      }
8344    "#,
8345      indoc! { r#"
8346      @-webkit-keyframes test1 {
8347        from {
8348          background: green;
8349        }
8350
8351        to {
8352          background: #00f;
8353        }
8354      }
8355
8356      @-moz-keyframes test2 {
8357        from {
8358          background: green;
8359        }
8360
8361        to {
8362          background: #00f;
8363        }
8364      }
8365
8366      @keyframes test3 {
8367        from {
8368          background: green;
8369        }
8370
8371        to {
8372          background: #00f;
8373        }
8374      }
8375    "#},
8376      Browsers {
8377        safari: Some(10 << 16),
8378        firefox: Some(17 << 16),
8379        ..Browsers::default()
8380      },
8381    );
8382    prefix_test(
8383      r#"
8384      @-webkit-keyframes test {
8385        from {
8386          background: green;
8387        }
8388
8389        to {
8390          background: red;
8391        }
8392      }
8393      @-moz-keyframes test {
8394        from {
8395          background: green;
8396        }
8397
8398        to {
8399          background: pink;
8400        }
8401      }
8402      @keyframes test {
8403        from {
8404          background: green;
8405        }
8406        to {
8407          background: blue
8408        }
8409      }
8410    "#,
8411      indoc! { r#"
8412      @-webkit-keyframes test {
8413        from {
8414          background: green;
8415        }
8416
8417        to {
8418          background: red;
8419        }
8420      }
8421
8422      @-moz-keyframes test {
8423        from {
8424          background: green;
8425        }
8426
8427        to {
8428          background: pink;
8429        }
8430      }
8431
8432      @keyframes test {
8433        from {
8434          background: green;
8435        }
8436
8437        to {
8438          background: #00f;
8439        }
8440      }
8441    "#},
8442      Browsers {
8443        safari: Some(10 << 16),
8444        firefox: Some(17 << 16),
8445        ..Browsers::default()
8446      },
8447    );
8448
8449    minify_test(
8450      r#"
8451      @keyframes test {
8452        100% {
8453          background: blue
8454        }
8455      }
8456
8457      @keyframes test {
8458        100% {
8459          background: red
8460        }
8461      }
8462    "#,
8463      "@keyframes test{to{background:red}}",
8464    );
8465    minify_test(
8466      r#"
8467      @keyframes test {
8468        100% {
8469          background: blue
8470        }
8471      }
8472
8473      @-webkit-keyframes test {
8474        100% {
8475          background: red
8476        }
8477      }
8478    "#,
8479      "@keyframes test{to{background:#00f}}@-webkit-keyframes test{to{background:red}}",
8480    );
8481  }
8482
8483  #[test]
8484  fn test_important() {
8485    test(
8486      r#"
8487      .foo {
8488        align-items: center;
8489        justify-items: center !important;
8490      }
8491    "#,
8492      indoc! {r#"
8493      .foo {
8494        align-items: center;
8495        justify-items: center !important;
8496      }
8497    "#},
8498    );
8499
8500    test(
8501      r#"
8502      .foo {
8503        justify-items: center !important;
8504        align-items: center;
8505      }
8506    "#,
8507      indoc! {r#"
8508      .foo {
8509        align-items: center;
8510        justify-items: center !important;
8511      }
8512    "#},
8513    );
8514
8515    minify_test(
8516      r#"
8517      .foo {
8518        font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace !important;
8519      }
8520    "#,
8521      ".foo{font-family:SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace!important}",
8522    );
8523  }
8524
8525  #[test]
8526  fn test_calc() {
8527    use crate::values::length::{Length, LengthPercentage, LengthPercentageOrAuto};
8528    use crate::values::number::NonNegative;
8529
8530    for (source, expected) in [
8531      ("calc(-5px)", "0"),
8532      ("calc(5px - 10px)", "0"),
8533      ("calc(-5px + 10px)", "5px"),
8534      ("calc(-5px * -2)", "10px"),
8535      ("calc(calc(-5px) + 10px)", "5px"),
8536      ("calc(-1em)", "0"),
8537      ("calc(1in - 100px)", "0"),
8538      ("calc(1em - 10px)", "calc(1em - 10px)"),
8539      ("min(-1em, -10px)", "min(-1em, -10px)"),
8540    ] {
8541      non_negative_test::<Length>(source, Some(expected));
8542      non_negative_test::<LengthPercentage>(source, Some(expected));
8543      non_negative_test::<LengthPercentageOrAuto>(source, Some(expected));
8544    }
8545    assert_eq!(Length::parse_string("calc(-5px)").unwrap(), Length::px(-5.0));
8546    for source in ["calc(0)", "calc(-5)", "calc(1s)"] {
8547      non_negative_test::<Length>(source, None);
8548      non_negative_test::<LengthPercentage>(source, None);
8549    }
8550    for (source, expected) in [
8551      ("calc(5%)", "5%"),
8552      ("calc(0%)", "0%"),
8553      ("calc(-5% + 10%)", "5%"),
8554      ("calc(5% - 5%)", "0%"),
8555      ("calc(100px - (100px - 100%))", "100%"),
8556    ] {
8557      non_negative_test::<LengthPercentage>(source, Some(expected));
8558      non_negative_test::<LengthPercentageOrAuto>(source, Some(expected));
8559    }
8560    // Negative percentages and unresolved calculations retain their math boundary.
8561    for source in ["calc(-5%)", "calc(100% - 10px)"] {
8562      non_negative_test::<LengthPercentage>(source, Some(source));
8563      let value = NonNegative::<LengthPercentage>::parse_string(source).unwrap();
8564      let css = value.to_css_string(PrinterOptions::default()).unwrap();
8565      assert_eq!(NonNegative::<LengthPercentage>::parse_string(&css).unwrap(), value);
8566    }
8567
8568    minify_test(".foo { width: calc(20px * 2) }", ".foo{width:40px}");
8569    minify_test(".foo { font-size: calc(100vw / 35) }", ".foo{font-size:2.85714vw}");
8570    minify_test(".foo { width: calc(20px * 2 * 3) }", ".foo{width:120px}");
8571    minify_test(".foo { width: calc(20px + 30px) }", ".foo{width:50px}");
8572    minify_test(".foo { width: calc(20px + 30px + 40px) }", ".foo{width:90px}");
8573    minify_test(".foo { width: calc(100% - 30px) }", ".foo{width:calc(100% - 30px)}");
8574    minify_test(
8575      ".foo { width: calc(100% - 30px + 20px) }",
8576      ".foo{width:calc(100% - 10px)}",
8577    );
8578    minify_test(
8579      ".foo { width: calc(20px + 100% - 30px) }",
8580      ".foo{width:calc(100% - 10px)}",
8581    );
8582    minify_test(
8583      ".foo { width: calc(20px + 100% + 10vw - 30px) }",
8584      ".foo{width:calc(100% - 10px + 10vw)}",
8585    );
8586    minify_test(
8587      ".foo { width: calc(20px + 100% - 30px) }",
8588      ".foo{width:calc(100% - 10px)}",
8589    );
8590    minify_test(
8591      ".foo { width: calc(2 * (100% - 20px)) }",
8592      ".foo{width:calc(200% - 40px)}",
8593    );
8594    minify_test(
8595      ".foo { width: calc((100% - 20px) * 2) }",
8596      ".foo{width:calc(200% - 40px)}",
8597    );
8598    minify_test(".foo { width: calc(100% - 20px * 2) }", ".foo{width:calc(100% - 40px)}");
8599    minify_test(".foo { width: calc(1px + 1px) }", ".foo{width:2px}");
8600    minify_test(".foo { width: calc(100vw / 2) }", ".foo{width:50vw}");
8601    minify_test(".foo { width: calc(50px - (20px - 30px)) }", ".foo{width:60px}");
8602    minify_test(".foo { width: calc(100px - (100px - 100%)) }", ".foo{width:100%}");
8603    minify_test(
8604      ".foo { width: calc(100px + (100px - 100%)) }",
8605      ".foo{width:calc(200px - 100%)}",
8606    );
8607    minify_test(
8608      ".foo { width: calc(1px - (2em + 3%)) }",
8609      ".foo{width:calc(1px + -2em - 3%)}",
8610    ); // TODO: fix sign
8611    minify_test(
8612      ".foo { width: calc((100vw - 50em) / 2) }",
8613      ".foo{width:calc(50vw - 25em)}",
8614    );
8615    minify_test(
8616      ".foo { width: calc(1px - (2em + 4vh + 3%)) }",
8617      ".foo{width:calc(1px + -2em - 4vh - 3%)}",
8618    ); // TODO
8619    minify_test(
8620      ".foo { width: calc(1px + (2em + (3vh + 4px))) }",
8621      ".foo{width:calc(2em + 3vh + 5px)}",
8622    );
8623    minify_test(
8624      ".foo { width: calc(1px - (2em + 4px - 6vh) / 2) }",
8625      ".foo{width:calc(-1em - 1px + 3vh)}",
8626    );
8627    minify_test(
8628      ".foo { width: calc(100% - calc(50% + 25px)) }",
8629      ".foo{width:calc(50% - 25px)}",
8630    );
8631    minify_test(".foo { width: calc(1px/100) }", ".foo{width:.01px}");
8632    minify_test(
8633      ".foo { width: calc(100vw / 2 - 6px + 0px) }",
8634      ".foo{width:calc(50vw - 6px)}",
8635    );
8636    minify_test(".foo { width: calc(1px + 1) }", ".foo{width:calc(1px + 1)}");
8637    minify_test(".foo { width: calc( (1em - calc( 10px + 1em)) / 2) }", ".foo{width:0}");
8638    minify_test(
8639      ".foo { width: calc((100px - 1em) + (-50px + 1em)) }",
8640      ".foo{width:50px}",
8641    );
8642    minify_test(
8643      ".foo { width: calc(100% + (2 * 100px) - ((75.37% - 63.5px) - 900px)) }",
8644      ".foo{width:calc(24.63% + 1163.5px)}",
8645    );
8646    minify_test(
8647      ".foo { width: calc(((((100% + (2 * 30px) + 63.5px) / 0.7537) - (100vw - 60px)) / 2) + 30px) }",
8648      ".foo{width:calc(66.3394% + 141.929px - 50vw)}",
8649    );
8650    minify_test(
8651      ".foo { width: calc(((75.37% - 63.5px) - 900px) + (2 * 100px)) }",
8652      ".foo{width:calc(75.37% - 763.5px)}",
8653    );
8654    minify_test(
8655      ".foo { width: calc((900px - (10% - 63.5px)) + (2 * 100px)) }",
8656      ".foo{width:calc(1163.5px - 10%)}",
8657    );
8658    minify_test(".foo { width: calc(500px/0) }", ".foo{width:calc(500px/0)}");
8659    minify_test(".foo { width: calc(500px/2px) }", ".foo{width:calc(500px/2px)}");
8660    minify_test(".foo { width: calc(100% / 3 * 3) }", ".foo{width:100%}");
8661    minify_test(".foo { width: calc(+100px + +100px) }", ".foo{width:200px}");
8662    minify_test(".foo { width: calc(+100px - +100px) }", ".foo{width:0}");
8663    minify_test(".foo { width: calc(200px * +1) }", ".foo{width:200px}");
8664    minify_test(".foo { width: calc(200px / +1) }", ".foo{width:200px}");
8665    minify_test(".foo { width: calc(1.1e+1px + 1.1e+1px) }", ".foo{width:22px}");
8666    minify_test(".foo { border-width: calc(1px + 2px) }", ".foo{border-width:3px}");
8667    minify_test(
8668      ".foo { border-width: calc(1em + 2px + 2em + 3px) }",
8669      ".foo{border-width:calc(3em + 5px)}",
8670    );
8671
8672    minify_test(
8673      ".foo { border-width: min(1em, 2px) }",
8674      ".foo{border-width:min(1em,2px)}",
8675    );
8676    minify_test(
8677      ".foo { border-width: min(1em + 2em, 2px + 2px) }",
8678      ".foo{border-width:min(3em,4px)}",
8679    );
8680    minify_test(
8681      ".foo { border-width: min(1em + 2px, 2px + 1em) }",
8682      ".foo{border-width:min(1em + 2px,2px + 1em)}",
8683    );
8684    minify_test(
8685      ".foo { border-width: min(1em + 2px + 2px, 2px + 1em + 1px) }",
8686      ".foo{border-width:min(1em + 4px,3px + 1em)}",
8687    );
8688    minify_test(
8689      ".foo { border-width: min(2px + 1px, 3px + 4px) }",
8690      ".foo{border-width:3px}",
8691    );
8692    minify_test(
8693      ".foo { border-width: min(1px, 1em, 2px, 3in) }",
8694      ".foo{border-width:min(1px,1em)}",
8695    );
8696
8697    minify_test(
8698      ".foo { border-width: max(1em, 2px) }",
8699      ".foo{border-width:max(1em,2px)}",
8700    );
8701    minify_test(
8702      ".foo { border-width: max(1em + 2em, 2px + 2px) }",
8703      ".foo{border-width:max(3em,4px)}",
8704    );
8705    minify_test(
8706      ".foo { border-width: max(1em + 2px, 2px + 1em) }",
8707      ".foo{border-width:max(1em + 2px,2px + 1em)}",
8708    );
8709    minify_test(
8710      ".foo { border-width: max(1em + 2px + 2px, 2px + 1em + 1px) }",
8711      ".foo{border-width:max(1em + 4px,3px + 1em)}",
8712    );
8713    minify_test(
8714      ".foo { border-width: max(2px + 1px, 3px + 4px) }",
8715      ".foo{border-width:7px}",
8716    );
8717    minify_test(
8718      ".foo { border-width: max(1px, 1em, 2px, 3in) }",
8719      ".foo{border-width:max(3in,1em)}",
8720    );
8721
8722    minify_test(".foo { border-width: clamp(1px, 2px, 3px) }", ".foo{border-width:2px}");
8723    minify_test(".foo { border-width: clamp(1px, 10px, 3px) }", ".foo{border-width:3px}");
8724    minify_test(".foo { border-width: clamp(5px, 2px, 10px) }", ".foo{border-width:5px}");
8725    minify_test(
8726      ".foo { border-width: clamp(100px, 2px, 10px) }",
8727      ".foo{border-width:100px}",
8728    );
8729    minify_test(
8730      ".foo { border-width: clamp(5px + 5px, 5px + 7px, 10px + 20px) }",
8731      ".foo{border-width:12px}",
8732    );
8733
8734    minify_test(
8735      ".foo { border-width: clamp(1em, 2px, 4vh) }",
8736      ".foo{border-width:clamp(1em,2px,4vh)}",
8737    );
8738    minify_test(
8739      ".foo { border-width: clamp(1em, 2em, 4vh) }",
8740      ".foo{border-width:clamp(1em,2em,4vh)}",
8741    );
8742    minify_test(
8743      ".foo { border-width: clamp(1em, 2vh, 4vh) }",
8744      ".foo{border-width:max(1em,2vh)}",
8745    );
8746    minify_test(
8747      ".foo { border-width: clamp(1px, 1px + 2em, 4px) }",
8748      ".foo{border-width:clamp(1px,1px + 2em,4px)}",
8749    );
8750    minify_test(".foo { border-width: clamp(1px, 2pt, 1in) }", ".foo{border-width:2pt}");
8751    minify_test(
8752      ".foo { width: clamp(-100px, 0px, 50% - 50vw); }",
8753      ".foo{width:clamp(-100px,0px,50% - 50vw)}",
8754    );
8755
8756    minify_test(
8757      ".foo { top: calc(-1 * clamp(1.75rem, 8vw, 4rem)) }",
8758      ".foo{top:calc(-1*clamp(1.75rem,8vw,4rem))}",
8759    );
8760    minify_test(
8761      ".foo { top: calc(-1 * min(1.75rem, 8vw, 4rem)) }",
8762      ".foo{top:calc(-1*min(1.75rem,8vw))}",
8763    );
8764    minify_test(
8765      ".foo { top: calc(-1 * max(1.75rem, 8vw, 4rem)) }",
8766      ".foo{top:calc(-1*max(4rem,8vw))}",
8767    );
8768    minify_test(
8769      ".foo { top: calc(clamp(1.75rem, 8vw, 4rem) * -1) }",
8770      ".foo{top:calc(-1*clamp(1.75rem,8vw,4rem))}",
8771    );
8772    minify_test(
8773      ".foo { top: calc(min(1.75rem, 8vw, 4rem) * -1) }",
8774      ".foo{top:calc(-1*min(1.75rem,8vw))}",
8775    );
8776    minify_test(
8777      ".foo { top: calc(max(1.75rem, 8vw, 4rem) * -1) }",
8778      ".foo{top:calc(-1*max(4rem,8vw))}",
8779    );
8780    minify_test(
8781      ".foo { top: calc(clamp(1.75rem, 8vw, 4rem) / 2) }",
8782      ".foo{top:calc(clamp(1.75rem,8vw,4rem)/2)}",
8783    );
8784    minify_test(
8785      ".foo { top: calc(min(1.75rem, 8vw, 4rem) / 2) }",
8786      ".foo{top:calc(min(1.75rem,8vw)/2)}",
8787    );
8788    minify_test(
8789      ".foo { top: calc(max(1.75rem, 8vw, 4rem) / 2) }",
8790      ".foo{top:calc(max(4rem,8vw)/2)}",
8791    );
8792    minify_test(
8793      ".foo { top: calc(0.5 * clamp(1.75rem, 8vw, 4rem)) }",
8794      ".foo{top:calc(clamp(1.75rem,8vw,4rem)/2)}",
8795    );
8796    minify_test(
8797      ".foo { top: calc(1 * clamp(1.75rem, 8vw, 4rem)) }",
8798      ".foo{top:calc(clamp(1.75rem,8vw,4rem))}",
8799    );
8800    minify_test(
8801      ".foo { top: calc(2 * clamp(1.75rem, 8vw, 4rem) / 2) }",
8802      ".foo{top:calc(clamp(1.75rem,8vw,4rem))}",
8803    );
8804
8805    minify_test(".foo { width: max(0px, 1vw) }", ".foo{width:max(0px,1vw)}");
8806
8807    prefix_test(
8808      ".foo { border-width: clamp(1em, 2px, 4vh) }",
8809      indoc! { r#"
8810        .foo {
8811          border-width: max(1em, min(2px, 4vh));
8812        }
8813      "#},
8814      Browsers {
8815        safari: Some(12 << 16),
8816        ..Browsers::default()
8817      },
8818    );
8819
8820    prefix_test(
8821      ".foo { border-width: clamp(1em, 2px, 4vh) }",
8822      indoc! { r#"
8823        .foo {
8824          border-width: clamp(1em, 2px, 4vh);
8825        }
8826      "#},
8827      Browsers {
8828        safari: Some(14 << 16),
8829        ..Browsers::default()
8830      },
8831    );
8832
8833    minify_test(".foo { width: calc(1vh + 2vh) }", ".foo{width:3vh}");
8834    minify_test(".foo { width: calc(1dvh + 2dvh) }", ".foo{width:3dvh}");
8835    minify_test(".foo { width: calc(1lvh + 2lvh) }", ".foo{width:3lvh}");
8836    minify_test(".foo { width: calc(1svh + 2svh) }", ".foo{width:3svh}");
8837    minify_test(".foo { width: calc(1sVmin + 2Svmin) }", ".foo{width:3svmin}");
8838    minify_test(".foo { width: calc(1ic + 2ic) }", ".foo{width:3ic}");
8839    minify_test(".foo { width: calc(1ric + 2ric) }", ".foo{width:3ric}");
8840    minify_test(".foo { width: calc(1cap + 2cap) }", ".foo{width:3cap}");
8841    minify_test(".foo { width: calc(1lh + 2lh) }", ".foo{width:3lh}");
8842    minify_test(".foo { width: calc(1x + 2x) }", ".foo{width:calc(1x + 2x)}");
8843    minify_test(
8844      ".foo { left: calc(50% - 100px + clamp(0px, calc(50vw - 50px), 100px)) }",
8845      ".foo{left:calc(50% - 100px + clamp(0px,50vw - 50px,100px))}",
8846    );
8847    minify_test(
8848      ".foo { left: calc(10px + min(10px, 1rem) + max(2px, 1vw)) }",
8849      ".foo{left:calc(10px + min(10px,1rem) + max(2px,1vw))}",
8850    );
8851    minify_test(".foo { width: round(22px, 5px) }", ".foo{width:20px}");
8852    minify_test(".foo { width: round(nearest, 22px, 5px) }", ".foo{width:20px}");
8853    minify_test(".foo { width: round(down, 22px, 5px) }", ".foo{width:20px}");
8854    minify_test(".foo { width: round(to-zero, 22px, 5px) }", ".foo{width:20px}");
8855    minify_test(".foo { width: round(up, 22px, 5px) }", ".foo{width:25px}");
8856    minify_test(".foo { width: round(23px, 5px) }", ".foo{width:25px}");
8857    minify_test(".foo { width: round(nearest, 23px, 5px) }", ".foo{width:25px}");
8858    minify_test(".foo { width: round(down, 23px, 5px) }", ".foo{width:20px}");
8859    minify_test(".foo { width: round(to-zero, 23px, 5px) }", ".foo{width:20px}");
8860    minify_test(".foo { width: round(up, 23px, 5px) }", ".foo{width:25px}");
8861    minify_test(".foo { width: round(22px, 5vw) }", ".foo{width:round(22px,5vw)}");
8862    minify_test(".foo { rotate: round(22deg, 5deg) }", ".foo{rotate:20deg}");
8863    minify_test(".foo { rotate: round(22deg, 5deg) }", ".foo{rotate:20deg}");
8864    minify_test(
8865      ".foo { transition-duration: round(22ms, 5ms) }",
8866      ".foo{transition-duration:20ms}",
8867    );
8868    minify_test(".foo { margin: round(to-zero, -23px, 5px) }", ".foo{margin:-20px}");
8869    minify_test(".foo { margin: round(nearest, -23px, 5px) }", ".foo{margin:-25px}");
8870    minify_test(".foo { margin: calc(10px * round(22, 5)) }", ".foo{margin:200px}");
8871    minify_test(".foo { width: rem(18px, 5px) }", ".foo{width:3px}");
8872    minify_test(".foo { width: rem(-18px, 5px) }", ".foo{width:0}");
8873    minify_test(".foo { width: rem(18px, 5vw) }", ".foo{width:rem(18px,5vw)}");
8874    minify_test(".foo { rotate: rem(-140deg, -90deg) }", ".foo{rotate:-50deg}");
8875    minify_test(".foo { rotate: rem(140deg, -90deg) }", ".foo{rotate:50deg}");
8876    minify_test(".foo { width: calc(10px * rem(18, 5)) }", ".foo{width:30px}");
8877    minify_test(".foo { width: mod(18px, 5px) }", ".foo{width:3px}");
8878    minify_test(".foo { width: mod(-18px, 5px) }", ".foo{width:2px}");
8879    minify_test(".foo { rotate: mod(-140deg, -90deg) }", ".foo{rotate:-50deg}");
8880    minify_test(".foo { rotate: mod(140deg, -90deg) }", ".foo{rotate:-40deg}");
8881    minify_test(".foo { width: mod(18px, 5vw) }", ".foo{width:mod(18px,5vw)}");
8882    minify_test(
8883      ".foo { transform: rotateX(mod(140deg, -90deg)) rotateY(rem(140deg, -90deg)) }",
8884      ".foo{transform:rotateX(-40deg)rotateY(50deg)}",
8885    );
8886    minify_test(".foo { width: calc(10px * mod(18, 5)) }", ".foo{width:30px}");
8887
8888    minify_test(
8889      ".foo { width: calc(100% - 30px - 0) }",
8890      ".foo{width:calc(100% - 30px - 0)}",
8891    );
8892    minify_test(
8893      ".foo { width: calc(100% - 30px - 1 - 2) }",
8894      ".foo{width:calc(100% - 30px - 3)}",
8895    );
8896    minify_test(
8897      ".foo { width: calc(1 - 2 - 100% - 30px) }",
8898      ".foo{width:calc(-1 - 100% - 30px)}",
8899    );
8900    minify_test(
8901      ".foo { width: calc(2 * min(1px, 1vmin) - min(1px, 1vmin)); }",
8902      ".foo{width:calc(2*min(1px,1vmin) - min(1px,1vmin))}",
8903    );
8904    minify_test(
8905      ".foo { width: calc(100% - clamp(1.125rem, 1.25vw, 1.2375rem) - clamp(1.125rem, 1.25vw, 1.2375rem)); }",
8906      ".foo{width:calc(100% - clamp(1.125rem,1.25vw,1.2375rem) - clamp(1.125rem,1.25vw,1.2375rem))}",
8907    );
8908    minify_test(
8909      ".foo { width: calc(100% - 2 (2 * var(--card-margin))); }",
8910      ".foo{width:calc(100% - 2 (2 * var(--card-margin)))}",
8911    );
8912
8913    test(
8914      indoc! {r#"
8915    .test {
8916      width: calc(var(--test) + 2px);
8917      width: calc(var(--test) - 2px);
8918    }
8919    "#},
8920      indoc! {r#"
8921    .test {
8922      width: calc(var(--test) + 2px);
8923      width: calc(var(--test) - 2px);
8924    }
8925    "#},
8926    );
8927  }
8928
8929  #[test]
8930  fn test_trig() {
8931    minify_test(".foo { width: calc(2px * pi); }", ".foo{width:6.28319px}");
8932    minify_test(".foo { width: calc(2px / pi); }", ".foo{width:.63662px}");
8933    // minify_test(
8934    //   ".foo { width: calc(2px * infinity); }",
8935    //   ".foo{width:calc(2px*infinity)}",
8936    // );
8937    // minify_test(
8938    //   ".foo { width: calc(2px * -infinity); }",
8939    //   ".foo{width:calc(2px*-infinity)}",
8940    // );
8941    minify_test(".foo { width: calc(100px * sin(45deg))", ".foo{width:70.7107px}");
8942    minify_test(".foo { width: calc(100px * sin(.125turn))", ".foo{width:70.7107px}");
8943    minify_test(
8944      ".foo { width: calc(100px * sin(3.14159265 / 4))",
8945      ".foo{width:70.7107px}",
8946    );
8947    minify_test(".foo { width: calc(100px * sin(pi / 4))", ".foo{width:70.7107px}");
8948    minify_test(
8949      ".foo { width: calc(100px * sin(22deg + 23deg))",
8950      ".foo{width:70.7107px}",
8951    );
8952
8953    minify_test(".foo { width: calc(2px * cos(45deg))", ".foo{width:1.41421px}");
8954    minify_test(".foo { width: calc(2px * tan(45deg))", ".foo{width:2px}");
8955
8956    minify_test(".foo { rotate: asin(sin(45deg))", ".foo{rotate:45deg}");
8957    minify_test(".foo { rotate: asin(1)", ".foo{rotate:90deg}");
8958    minify_test(".foo { rotate: asin(-1)", ".foo{rotate:-90deg}");
8959    minify_test(".foo { rotate: asin(0.5)", ".foo{rotate:30deg}");
8960    minify_test(".foo { rotate: asin(45deg)", ".foo{rotate:asin(45deg)}"); // invalid
8961    minify_test(".foo { rotate: asin(-20)", ".foo{rotate:asin(-20)}"); // evaluates to NaN
8962    minify_test(".foo { width: asin(sin(45deg))", ".foo{width:asin(sin(45deg))}"); // invalid
8963
8964    minify_test(".foo { rotate: acos(cos(45deg))", ".foo{rotate:45deg}");
8965    minify_test(".foo { rotate: acos(-1)", ".foo{rotate:180deg}");
8966    minify_test(".foo { rotate: acos(0)", ".foo{rotate:90deg}");
8967    minify_test(".foo { rotate: acos(1)", ".foo{rotate:0deg}");
8968    minify_test(".foo { rotate: acos(45deg)", ".foo{rotate:acos(45deg)}"); // invalid
8969    minify_test(".foo { rotate: acos(-20)", ".foo{rotate:acos(-20)}"); // evaluates to NaN
8970
8971    minify_test(".foo { rotate: atan(tan(45deg))", ".foo{rotate:45deg}");
8972    minify_test(".foo { rotate: atan(1)", ".foo{rotate:45deg}");
8973    minify_test(".foo { rotate: atan(0)", ".foo{rotate:0deg}");
8974    minify_test(".foo { rotate: atan(45deg)", ".foo{rotate:atan(45deg)}"); // invalid
8975
8976    minify_test(".foo { rotate: atan2(1px, -1px)", ".foo{rotate:135deg}");
8977    minify_test(".foo { rotate: atan2(1vw, -1vw)", ".foo{rotate:135deg}");
8978    minify_test(".foo { rotate: atan2(1, -1)", ".foo{rotate:135deg}");
8979    minify_test(".foo { rotate: atan2(1ms, -1ms)", ".foo{rotate:135deg}");
8980    minify_test(".foo { rotate: atan2(1%, -1%)", ".foo{rotate:135deg}");
8981    minify_test(".foo { rotate: atan2(1deg, -1deg)", ".foo{rotate:135deg}");
8982    minify_test(".foo { rotate: atan2(1cm, 1mm)", ".foo{rotate:84.2894deg}");
8983    minify_test(".foo { rotate: atan2(0, -1)", ".foo{rotate:180deg}");
8984    minify_test(".foo { rotate: atan2(-1, 1)", ".foo{rotate:-45deg}");
8985    // incompatible units
8986    minify_test(".foo { rotate: atan2(1px, -1vw)", ".foo{rotate:atan2(1px, -1vw)}");
8987
8988    minify_test(".foo { transform: rotate(acos(1)) }", ".foo{transform:rotate(0)}");
8989    minify_test(".foo { transform: rotate(atan(0)) }", ".foo{transform:rotate(0)}");
8990  }
8991
8992  #[test]
8993  fn test_exp() {
8994    minify_test(".foo { width: hypot()", ".foo{width:hypot()}");
8995    minify_test(".foo { width: hypot(1px)", ".foo{width:1px}");
8996    minify_test(".foo { width: hypot(1px, 2px)", ".foo{width:2.23607px}");
8997    minify_test(".foo { width: hypot(1px, 2px, 3px)", ".foo{width:3.74166px}");
8998    minify_test(".foo { width: hypot(1px, 2vw)", ".foo{width:hypot(1px,2vw)}");
8999    minify_test(".foo { width: hypot(1px, 2px, 3vw)", ".foo{width:hypot(1px,2px,3vw)}");
9000    minify_test(".foo { width: calc(100px * hypot(3, 4))", ".foo{width:500px}");
9001    minify_test(".foo { width: calc(1px * pow(2, sqrt(100))", ".foo{width:1024px}");
9002    minify_test(".foo { width: calc(100px * pow(2, pow(2, 2)", ".foo{width:1600px}");
9003    minify_test(".foo { width: calc(1px * log(1))", ".foo{width:0}");
9004    minify_test(".foo { width: calc(1px * log(10, 10))", ".foo{width:1px}");
9005    minify_test(".foo { width: calc(1px * exp(0))", ".foo{width:1px}");
9006    minify_test(".foo { width: calc(1px * log(e))", ".foo{width:1px}");
9007    minify_test(".foo { width: calc(1px * (e - exp(1)))", ".foo{width:0}");
9008    minify_test(
9009      ".foo { width: calc(1px * (exp(log(1) + exp(0)*2))",
9010      ".foo{width:7.38906px}",
9011    );
9012  }
9013
9014  #[test]
9015  fn test_sign() {
9016    minify_test(".foo { width: abs(1px)", ".foo{width:1px}");
9017    minify_test(".foo { width: abs(-1px)", ".foo{width:1px}");
9018    minify_test(".foo { width: abs(1%)", ".foo{width:abs(1%)}"); // spec says percentages must be against resolved value
9019
9020    minify_test(".foo { width: calc(10px * sign(-1vw)", ".foo{width:0}");
9021    minify_test(
9022      ".foo { width: calc(10px * sign(1%)",
9023      ".foo{width:calc(10px * sign(1%))}",
9024    );
9025  }
9026
9027  #[test]
9028  fn test_box_shadow() {
9029    property_range_test(
9030      &["box-shadow"],
9031      &[
9032        ("1px 2px -3px", None),
9033        ("1px 2px -3px 4px", None),
9034        ("1px 2px 0 -4px", Some("1px 2px 0 -4px")),
9035        ("1px 2px calc(-3px)", Some("1px 2px")),
9036      ],
9037    );
9038    minify_test(
9039      ".foo { box-shadow: 64px 64px 12px 40px rgba(0,0,0,0.4) }",
9040      ".foo{box-shadow:64px 64px 12px 40px #0006}",
9041    );
9042    minify_test(
9043      ".foo { box-shadow: 12px 12px 0px 8px rgba(0,0,0,0.4) inset }",
9044      ".foo{box-shadow:inset 12px 12px 0 8px #0006}",
9045    );
9046    minify_test(
9047      ".foo { box-shadow: inset 12px 12px 0px 8px rgba(0,0,0,0.4) }",
9048      ".foo{box-shadow:inset 12px 12px 0 8px #0006}",
9049    );
9050    minify_test(
9051      ".foo { box-shadow: 12px 12px 8px 0px rgba(0,0,0,0.4) }",
9052      ".foo{box-shadow:12px 12px 8px #0006}",
9053    );
9054    minify_test(
9055      ".foo { box-shadow: 12px 12px 0px 0px rgba(0,0,0,0.4) }",
9056      ".foo{box-shadow:12px 12px #0006}",
9057    );
9058    minify_test(
9059      ".foo { box-shadow: 64px 64px 12px 40px rgba(0,0,0,0.4), 12px 12px 0px 8px rgba(0,0,0,0.4) inset }",
9060      ".foo{box-shadow:64px 64px 12px 40px #0006,inset 12px 12px 0 8px #0006}",
9061    );
9062
9063    prefix_test(
9064      ".foo { box-shadow: 12px 12px lab(40% 56.6 39) }",
9065      indoc! { r#"
9066        .foo {
9067          box-shadow: 12px 12px #b32323;
9068          box-shadow: 12px 12px lab(40% 56.6 39);
9069        }
9070      "#},
9071      Browsers {
9072        chrome: Some(90 << 16),
9073        ..Browsers::default()
9074      },
9075    );
9076
9077    prefix_test(
9078      ".foo { box-shadow: 12px 12px lab(40% 56.6 39) }",
9079      indoc! { r#"
9080        .foo {
9081          -webkit-box-shadow: 12px 12px #b32323;
9082          box-shadow: 12px 12px #b32323;
9083          box-shadow: 12px 12px lab(40% 56.6 39);
9084        }
9085      "#},
9086      Browsers {
9087        chrome: Some(4 << 16),
9088        ..Browsers::default()
9089      },
9090    );
9091
9092    prefix_test(
9093      ".foo { box-shadow: 12px 12px lab(40% 56.6 39), 12px 12px yellow }",
9094      indoc! { r#"
9095        .foo {
9096          -webkit-box-shadow: 12px 12px #b32323, 12px 12px #ff0;
9097          box-shadow: 12px 12px #b32323, 12px 12px #ff0;
9098          box-shadow: 12px 12px lab(40% 56.6 39), 12px 12px #ff0;
9099        }
9100      "#},
9101      Browsers {
9102        chrome: Some(4 << 16),
9103        ..Browsers::default()
9104      },
9105    );
9106
9107    prefix_test(
9108      ".foo { -webkit-box-shadow: 12px 12px #0006 }",
9109      indoc! { r#"
9110        .foo {
9111          -webkit-box-shadow: 12px 12px rgba(0, 0, 0, .4);
9112        }
9113      "#},
9114      Browsers {
9115        chrome: Some(4 << 16),
9116        ..Browsers::default()
9117      },
9118    );
9119
9120    prefix_test(
9121      ".foo {
9122        -webkit-box-shadow: 12px 12px #0006;
9123        -moz-box-shadow: 12px 12px #0009;
9124      }",
9125      indoc! { r#"
9126        .foo {
9127          -webkit-box-shadow: 12px 12px rgba(0, 0, 0, .4);
9128          -moz-box-shadow: 12px 12px rgba(0, 0, 0, .6);
9129        }
9130      "#},
9131      Browsers {
9132        chrome: Some(4 << 16),
9133        ..Browsers::default()
9134      },
9135    );
9136
9137    prefix_test(
9138      ".foo {
9139        -webkit-box-shadow: 12px 12px #0006;
9140        -moz-box-shadow: 12px 12px #0006;
9141        box-shadow: 12px 12px #0006;
9142      }",
9143      indoc! { r#"
9144        .foo {
9145          box-shadow: 12px 12px #0006;
9146        }
9147      "#},
9148      Browsers {
9149        chrome: Some(95 << 16),
9150        ..Browsers::default()
9151      },
9152    );
9153
9154    prefix_test(
9155      ".foo { box-shadow: var(--foo) 12px lab(40% 56.6 39) }",
9156      indoc! { r#"
9157        .foo {
9158          box-shadow: var(--foo) 12px #b32323;
9159        }
9160
9161        @supports (color: lab(0% 0 0)) {
9162          .foo {
9163            box-shadow: var(--foo) 12px lab(40% 56.6 39);
9164          }
9165        }
9166      "#},
9167      Browsers {
9168        chrome: Some(90 << 16),
9169        ..Browsers::default()
9170      },
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 22px red;
9183        box-shadow: 0 0 max(2cqw, 22px) red;
9184      }
9185    "#
9186      },
9187      Browsers {
9188        safari: Some(14 << 16),
9189        ..Browsers::default()
9190      },
9191    );
9192    prefix_test(
9193      r#"
9194      .foo {
9195        box-shadow: 0px 0px 22px red;
9196        box-shadow: 0px 0px max(2cqw, 22px) red;
9197      }
9198    "#,
9199      indoc! {r#"
9200      .foo {
9201        box-shadow: 0 0 max(2cqw, 22px) red;
9202      }
9203    "#
9204      },
9205      Browsers {
9206        safari: Some(16 << 16),
9207        ..Browsers::default()
9208      },
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 red;
9221        box-shadow: 0 0 22px lab(40% 56.6 39);
9222      }
9223    "#
9224      },
9225      Browsers {
9226        safari: Some(14 << 16),
9227        ..Browsers::default()
9228      },
9229    );
9230    prefix_test(
9231      r#"
9232      .foo {
9233        box-shadow: 0px 0px 22px red;
9234        box-shadow: 0px 0px 22px lab(40% 56.6 39);
9235      }
9236    "#,
9237      indoc! {r#"
9238      .foo {
9239        box-shadow: 0 0 22px lab(40% 56.6 39);
9240      }
9241    "#
9242      },
9243      Browsers {
9244        safari: Some(16 << 16),
9245        ..Browsers::default()
9246      },
9247    );
9248
9249    prefix_test(
9250      r#"
9251      .foo {
9252        box-shadow: var(--fallback);
9253        box-shadow: 0px 0px 22px lab(40% 56.6 39);
9254      }
9255    "#,
9256      indoc! {r#"
9257      .foo {
9258        box-shadow: var(--fallback);
9259        box-shadow: 0 0 22px lab(40% 56.6 39);
9260      }
9261    "#
9262      },
9263      Browsers {
9264        safari: Some(16 << 16),
9265        ..Browsers::default()
9266      },
9267    );
9268  }
9269
9270  #[test]
9271  fn test_selector_compatibility() {
9272    fn selectors(source: &str) -> crate::selector::SelectorList<'_> {
9273      let stylesheet = StyleSheet::parse(
9274        source,
9275        ParserOptions {
9276          flags: ParserFlags::SCROLL_NAVIGATION_CONTROLS,
9277          ..ParserOptions::default()
9278        },
9279      )
9280      .unwrap();
9281      match &stylesheet.rules.0[0] {
9282        CssRule::Style(rule) => rule.selectors.clone(),
9283        _ => unreachable!(),
9284      }
9285    }
9286
9287    let target_current = selectors("a:target-current { color: green }");
9288    assert!(!crate::selector::is_compatible(
9289      &target_current.0,
9290      Browsers {
9291        chrome: Some(134 << 16),
9292        ..Browsers::default()
9293      }
9294      .into()
9295    ));
9296    assert!(crate::selector::is_compatible(
9297      &target_current.0,
9298      Browsers {
9299        chrome: Some(135 << 16),
9300        ..Browsers::default()
9301      }
9302      .into()
9303    ));
9304
9305    let target_before = selectors("a:target-before { color: green }");
9306    assert!(!crate::selector::is_compatible(
9307      &target_before.0,
9308      Browsers {
9309        chrome: Some(141 << 16),
9310        ..Browsers::default()
9311      }
9312      .into()
9313    ));
9314    assert!(crate::selector::is_compatible(
9315      &target_before.0,
9316      Browsers {
9317        chrome: Some(142 << 16),
9318        ..Browsers::default()
9319      }
9320      .into()
9321    ));
9322
9323    let target_after = selectors("a:target-after { color: green }");
9324    assert!(crate::selector::is_compatible(
9325      &target_after.0,
9326      Browsers {
9327        chrome: Some(142 << 16),
9328        ..Browsers::default()
9329      }
9330      .into()
9331    ));
9332  }
9333
9334  #[test]
9335  fn test_media() {
9336    minify_test(
9337      "@media (min-width: 240px) { .foo { color: chartreuse }}",
9338      "@media (width>=240px){.foo{color:#7fff00}}",
9339    );
9340    minify_test(
9341      "@media (width < 240px) { .foo { color: chartreuse }}",
9342      "@media (width<240px){.foo{color:#7fff00}}",
9343    );
9344    minify_test(
9345      "@media (width <= 240px) { .foo { color: chartreuse }}",
9346      "@media (width<=240px){.foo{color:#7fff00}}",
9347    );
9348    minify_test(
9349      "@media (width > 240px) { .foo { color: chartreuse }}",
9350      "@media (width>240px){.foo{color:#7fff00}}",
9351    );
9352    minify_test(
9353      "@media (width >= 240px) { .foo { color: chartreuse }}",
9354      "@media (width>=240px){.foo{color:#7fff00}}",
9355    );
9356    minify_test(
9357      "@media (240px < width) { .foo { color: chartreuse }}",
9358      "@media (width>240px){.foo{color:#7fff00}}",
9359    );
9360    minify_test(
9361      "@media (240px <= width) { .foo { color: chartreuse }}",
9362      "@media (width>=240px){.foo{color:#7fff00}}",
9363    );
9364    minify_test(
9365      "@media (240px > width) { .foo { color: chartreuse }}",
9366      "@media (width<240px){.foo{color:#7fff00}}",
9367    );
9368    minify_test(
9369      "@media (240px >= width) { .foo { color: chartreuse }}",
9370      "@media (width<=240px){.foo{color:#7fff00}}",
9371    );
9372    minify_test(
9373      "@media (100px < width < 200px) { .foo { color: chartreuse }}",
9374      "@media (100px<width<200px){.foo{color:#7fff00}}",
9375    );
9376    minify_test(
9377      "@media (100px <= width <= 200px) { .foo { color: chartreuse }}",
9378      "@media (100px<=width<=200px){.foo{color:#7fff00}}",
9379    );
9380    minify_test(
9381      "@media (min-width: 30em) and (max-width: 50em) { .foo { color: chartreuse }}",
9382      "@media (width>=30em) and (width<=50em){.foo{color:#7fff00}}",
9383    );
9384    minify_test(
9385      "@media screen, print { .foo { color: chartreuse }}",
9386      "@media screen,print{.foo{color:#7fff00}}",
9387    );
9388    minify_test(
9389      "@media (hover: hover) { .foo { color: chartreuse }}",
9390      "@media (hover:hover){.foo{color:#7fff00}}",
9391    );
9392    minify_test(
9393      "@media (hover) { .foo { color: chartreuse }}",
9394      "@media (hover){.foo{color:#7fff00}}",
9395    );
9396    minify_test(
9397      "@media (aspect-ratio: 11/5) { .foo { color: chartreuse }}",
9398      "@media (aspect-ratio:11/5){.foo{color:#7fff00}}",
9399    );
9400    minify_test(
9401      "@media (aspect-ratio: 2/1) { .foo { color: chartreuse }}",
9402      "@media (aspect-ratio:2){.foo{color:#7fff00}}",
9403    );
9404    minify_test(
9405      "@media (aspect-ratio: 2) { .foo { color: chartreuse }}",
9406      "@media (aspect-ratio:2){.foo{color:#7fff00}}",
9407    );
9408    minify_test(
9409      "@media not screen and (color) { .foo { color: chartreuse }}",
9410      "@media not screen and (color){.foo{color:#7fff00}}",
9411    );
9412    minify_test(
9413      "@media only screen and (color) { .foo { color: chartreuse }}",
9414      "@media only screen and (color){.foo{color:#7fff00}}",
9415    );
9416    minify_test(
9417      "@media (update: slow) or (hover: none) { .foo { color: chartreuse }}",
9418      "@media (update:slow) or (hover:none){.foo{color:#7fff00}}",
9419    );
9420    minify_test(
9421      "@media (width < 600px) and (height < 600px) { .foo { color: chartreuse }}",
9422      "@media (width<600px) and (height<600px){.foo{color:#7fff00}}",
9423    );
9424    minify_test(
9425      "@media (not (color)) or (hover) { .foo { color: chartreuse }}",
9426      "@media (not (color)) or (hover){.foo{color:#7fff00}}",
9427    );
9428    error_test(
9429      "@media (example, all,), speech { .foo { color: chartreuse }}",
9430      ParserError::UnexpectedToken(Token::Comma),
9431    );
9432    error_test(
9433      "@media &test, speech { .foo { color: chartreuse }}",
9434      ParserError::UnexpectedToken(Token::Delim('&')),
9435    );
9436    error_test(
9437      "@media &test { .foo { color: chartreuse }}",
9438      ParserError::UnexpectedToken(Token::Delim('&')),
9439    );
9440    minify_test(
9441      "@media (min-width: calc(200px + 40px)) { .foo { color: chartreuse }}",
9442      "@media (width>=240px){.foo{color:#7fff00}}",
9443    );
9444    minify_test(
9445      "@media (min-width: calc(1em + 5px)) { .foo { color: chartreuse }}",
9446      "@media (width>=calc(1em + 5px)){.foo{color:#7fff00}}",
9447    );
9448    minify_test("@media { .foo { color: chartreuse }}", ".foo{color:#7fff00}");
9449    minify_test("@media all { .foo { color: chartreuse }}", ".foo{color:#7fff00}");
9450    minify_test(
9451      "@media not (((color) or (hover))) { .foo { color: chartreuse }}",
9452      "@media not ((color) or (hover)){.foo{color:#7fff00}}",
9453    );
9454    minify_test(
9455      "@media (hover) and ((color) and (test)) { .foo { color: chartreuse }}",
9456      "@media (hover) and (color) and (test){.foo{color:#7fff00}}",
9457    );
9458    minify_test(
9459      "@media (grid: 1) { .foo { color: chartreuse }}",
9460      "@media (grid:1){.foo{color:#7fff00}}",
9461    );
9462    minify_test(
9463      "@media (width >= calc(2px + 4px)) { .foo { color: chartreuse }}",
9464      "@media (width>=6px){.foo{color:#7fff00}}",
9465    );
9466
9467    prefix_test(
9468      r#"
9469        @media (width >= 240px) {
9470          .foo {
9471            color: chartreuse;
9472          }
9473        }
9474      "#,
9475      indoc! { r#"
9476        @media (min-width: 240px) {
9477          .foo {
9478            color: #7fff00;
9479          }
9480        }
9481      "#},
9482      Browsers {
9483        firefox: Some(60 << 16),
9484        ..Browsers::default()
9485      },
9486    );
9487
9488    prefix_test(
9489      r#"
9490        @media (width >= 240px) {
9491          .foo {
9492            color: chartreuse;
9493          }
9494        }
9495      "#,
9496      indoc! { r#"
9497        @media (width >= 240px) {
9498          .foo {
9499            color: #7fff00;
9500          }
9501        }
9502      "#},
9503      Browsers {
9504        firefox: Some(64 << 16),
9505        ..Browsers::default()
9506      },
9507    );
9508
9509    prefix_test(
9510      r#"
9511        @media (color > 2) {
9512          .foo {
9513            color: chartreuse;
9514          }
9515        }
9516      "#,
9517      indoc! { r#"
9518        @media not (max-color: 2) {
9519          .foo {
9520            color: #7fff00;
9521          }
9522        }
9523      "#},
9524      Browsers {
9525        firefox: Some(60 << 16),
9526        ..Browsers::default()
9527      },
9528    );
9529
9530    prefix_test(
9531      r#"
9532        @media (color < 2) {
9533          .foo {
9534            color: chartreuse;
9535          }
9536        }
9537      "#,
9538      indoc! { r#"
9539        @media not (min-color: 2) {
9540          .foo {
9541            color: #7fff00;
9542          }
9543        }
9544      "#},
9545      Browsers {
9546        firefox: Some(60 << 16),
9547        ..Browsers::default()
9548      },
9549    );
9550
9551    prefix_test(
9552      r#"
9553        @media (width > 240px) {
9554          .foo {
9555            color: chartreuse;
9556          }
9557        }
9558      "#,
9559      indoc! { r#"
9560        @media not (max-width: 240px) {
9561          .foo {
9562            color: #7fff00;
9563          }
9564        }
9565      "#},
9566      Browsers {
9567        firefox: Some(60 << 16),
9568        ..Browsers::default()
9569      },
9570    );
9571
9572    prefix_test(
9573      r#"
9574        @media (width <= 240px) {
9575          .foo {
9576            color: chartreuse;
9577          }
9578        }
9579      "#,
9580      indoc! { r#"
9581        @media (max-width: 240px) {
9582          .foo {
9583            color: #7fff00;
9584          }
9585        }
9586      "#},
9587      Browsers {
9588        firefox: Some(60 << 16),
9589        ..Browsers::default()
9590      },
9591    );
9592
9593    prefix_test(
9594      r#"
9595        @media (width <= 240px) {
9596          .foo {
9597            color: chartreuse;
9598          }
9599        }
9600      "#,
9601      indoc! { r#"
9602        @media (width <= 240px) {
9603          .foo {
9604            color: #7fff00;
9605          }
9606        }
9607      "#},
9608      Browsers {
9609        firefox: Some(64 << 16),
9610        ..Browsers::default()
9611      },
9612    );
9613
9614    prefix_test(
9615      r#"
9616        @media (width < 240px) {
9617          .foo {
9618            color: chartreuse;
9619          }
9620        }
9621      "#,
9622      indoc! { r#"
9623        @media not (min-width: 240px) {
9624          .foo {
9625            color: #7fff00;
9626          }
9627        }
9628      "#},
9629      Browsers {
9630        firefox: Some(60 << 16),
9631        ..Browsers::default()
9632      },
9633    );
9634
9635    prefix_test(
9636      r#"
9637        @media not (width < 240px) {
9638          .foo {
9639            color: chartreuse;
9640          }
9641        }
9642      "#,
9643      indoc! { r#"
9644        @media (min-width: 240px) {
9645          .foo {
9646            color: #7fff00;
9647          }
9648        }
9649      "#},
9650      Browsers {
9651        firefox: Some(60 << 16),
9652        ..Browsers::default()
9653      },
9654    );
9655
9656    test(
9657      r#"
9658        @media not (width < 240px) {
9659          .foo {
9660            color: chartreuse;
9661          }
9662        }
9663      "#,
9664      indoc! { r#"
9665        @media (width >= 240px) {
9666          .foo {
9667            color: #7fff00;
9668          }
9669        }
9670      "#},
9671    );
9672
9673    prefix_test(
9674      r#"
9675        @media (width < 240px) and (hover) {
9676          .foo {
9677            color: chartreuse;
9678          }
9679        }
9680      "#,
9681      indoc! { r#"
9682        @media (not (min-width: 240px)) and (hover) {
9683          .foo {
9684            color: #7fff00;
9685          }
9686        }
9687      "#},
9688      Browsers {
9689        firefox: Some(60 << 16),
9690        ..Browsers::default()
9691      },
9692    );
9693
9694    prefix_test(
9695      r#"
9696        @media (100px <= width <= 200px) {
9697          .foo {
9698            color: chartreuse;
9699          }
9700        }
9701      "#,
9702      indoc! { r#"
9703        @media (min-width: 100px) and (max-width: 200px) {
9704          .foo {
9705            color: #7fff00;
9706          }
9707        }
9708      "#},
9709      Browsers {
9710        firefox: Some(85 << 16),
9711        ..Browsers::default()
9712      },
9713    );
9714
9715    prefix_test(
9716      r#"
9717        @media not (100px <= width <= 200px) {
9718          .foo {
9719            color: chartreuse;
9720          }
9721        }
9722      "#,
9723      indoc! { r#"
9724        @media not ((min-width: 100px) and (max-width: 200px)) {
9725          .foo {
9726            color: #7fff00;
9727          }
9728        }
9729      "#},
9730      Browsers {
9731        firefox: Some(85 << 16),
9732        ..Browsers::default()
9733      },
9734    );
9735
9736    prefix_test(
9737      r#"
9738        @media (hover) and (100px <= width <= 200px) {
9739          .foo {
9740            color: chartreuse;
9741          }
9742        }
9743      "#,
9744      indoc! { r#"
9745        @media (hover) and (min-width: 100px) and (max-width: 200px) {
9746          .foo {
9747            color: #7fff00;
9748          }
9749        }
9750      "#},
9751      Browsers {
9752        firefox: Some(85 << 16),
9753        ..Browsers::default()
9754      },
9755    );
9756
9757    prefix_test(
9758      r#"
9759        @media (hover) or (100px <= width <= 200px) {
9760          .foo {
9761            color: chartreuse;
9762          }
9763        }
9764      "#,
9765      indoc! { r#"
9766        @media (hover) or ((min-width: 100px) and (max-width: 200px)) {
9767          .foo {
9768            color: #7fff00;
9769          }
9770        }
9771      "#},
9772      Browsers {
9773        firefox: Some(85 << 16),
9774        ..Browsers::default()
9775      },
9776    );
9777
9778    prefix_test(
9779      r#"
9780        @media (100px < width < 200px) {
9781          .foo {
9782            color: chartreuse;
9783          }
9784        }
9785      "#,
9786      indoc! { r#"
9787        @media (not (max-width: 100px)) and (not (min-width: 200px)) {
9788          .foo {
9789            color: #7fff00;
9790          }
9791        }
9792      "#},
9793      Browsers {
9794        firefox: Some(85 << 16),
9795        ..Browsers::default()
9796      },
9797    );
9798
9799    prefix_test(
9800      r#"
9801        @media not (100px < width < 200px) {
9802          .foo {
9803            color: chartreuse;
9804          }
9805        }
9806      "#,
9807      indoc! { r#"
9808        @media not ((not (max-width: 100px)) and (not (min-width: 200px))) {
9809          .foo {
9810            color: #7fff00;
9811          }
9812        }
9813      "#},
9814      Browsers {
9815        firefox: Some(85 << 16),
9816        ..Browsers::default()
9817      },
9818    );
9819
9820    prefix_test(
9821      r#"
9822        @media (200px >= width >= 100px) {
9823          .foo {
9824            color: chartreuse;
9825          }
9826        }
9827      "#,
9828      indoc! { r#"
9829        @media (max-width: 200px) and (min-width: 100px) {
9830          .foo {
9831            color: #7fff00;
9832          }
9833        }
9834      "#},
9835      Browsers {
9836        firefox: Some(85 << 16),
9837        ..Browsers::default()
9838      },
9839    );
9840
9841    test(
9842      r#"
9843      @media not all {
9844        .a {
9845          color: green;
9846        }
9847      }
9848      "#,
9849      "\n",
9850    );
9851
9852    prefix_test(
9853      r#"
9854      @media (width > calc(1px + 1rem)) {
9855        .foo { color: yellow; }
9856      }
9857      "#,
9858      indoc! { r#"
9859        @media not (max-width: calc(1px + 1rem)) {
9860          .foo {
9861            color: #ff0;
9862          }
9863        }
9864      "#},
9865      Browsers {
9866        chrome: Some(85 << 16),
9867        ..Browsers::default()
9868      },
9869    );
9870    prefix_test(
9871      r#"
9872      @media (width > max(10px, 1rem)) {
9873        .foo { color: yellow; }
9874      }
9875      "#,
9876      indoc! { r#"
9877        @media not (max-width: max(10px, 1rem)) {
9878          .foo {
9879            color: #ff0;
9880          }
9881        }
9882      "#},
9883      Browsers {
9884        chrome: Some(85 << 16),
9885        ..Browsers::default()
9886      },
9887    );
9888    prefix_test(
9889      r#"
9890      @media (width > 0) {
9891        .foo { color: yellow; }
9892      }
9893      "#,
9894      indoc! { r#"
9895        @media not (max-width: 0) {
9896          .foo {
9897            color: #ff0;
9898          }
9899        }
9900      "#},
9901      Browsers {
9902        chrome: Some(85 << 16),
9903        ..Browsers::default()
9904      },
9905    );
9906    prefix_test(
9907      r#"
9908      @media (min-resolution: 2dppx) {
9909        .foo { color: yellow; }
9910      }
9911      "#,
9912      indoc! { r#"
9913        @media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 2dppx) {
9914          .foo {
9915            color: #ff0;
9916          }
9917        }
9918      "#},
9919      Browsers {
9920        safari: Some(15 << 16),
9921        ..Browsers::default()
9922      },
9923    );
9924    prefix_test(
9925      r#"
9926      @media (min-resolution: 2dppx) {
9927        .foo { color: yellow; }
9928      }
9929      "#,
9930      indoc! { r#"
9931        @media (min--moz-device-pixel-ratio: 2), (min-resolution: 2dppx) {
9932          .foo {
9933            color: #ff0;
9934          }
9935        }
9936      "#},
9937      Browsers {
9938        firefox: Some(10 << 16),
9939        ..Browsers::default()
9940      },
9941    );
9942    prefix_test(
9943      r#"
9944      @media (resolution > 2dppx) {
9945        .foo { color: yellow; }
9946      }
9947      "#,
9948      indoc! { r#"
9949        @media not (-webkit-max-device-pixel-ratio: 2), not (max-resolution: 2dppx) {
9950          .foo {
9951            color: #ff0;
9952          }
9953        }
9954      "#},
9955      Browsers {
9956        safari: Some(15 << 16),
9957        ..Browsers::default()
9958      },
9959    );
9960    prefix_test(
9961      r#"
9962      @media (resolution >= 300dpi) {
9963        .foo { color: yellow; }
9964      }
9965      "#,
9966      indoc! { r#"
9967        @media (-webkit-min-device-pixel-ratio: 3.125), (min-resolution: 300dpi) {
9968          .foo {
9969            color: #ff0;
9970          }
9971        }
9972      "#},
9973      Browsers {
9974        safari: Some(15 << 16),
9975        ..Browsers::default()
9976      },
9977    );
9978    prefix_test(
9979      r#"
9980      @media (min-resolution: 113.38dpcm) {
9981        .foo { color: yellow; }
9982      }
9983      "#,
9984      indoc! { r#"
9985        @media (-webkit-min-device-pixel-ratio: 2.99985), (min--moz-device-pixel-ratio: 2.99985), (min-resolution: 113.38dpcm) {
9986          .foo {
9987            color: #ff0;
9988          }
9989        }
9990      "#},
9991      Browsers {
9992        safari: Some(15 << 16),
9993        firefox: Some(10 << 16),
9994        ..Browsers::default()
9995      },
9996    );
9997    prefix_test(
9998      r#"
9999      @media (color) and (min-resolution: 2dppx) {
10000        .foo { color: yellow; }
10001      }
10002      "#,
10003      indoc! { r#"
10004        @media (color) and (-webkit-min-device-pixel-ratio: 2), (color) and (min-resolution: 2dppx) {
10005          .foo {
10006            color: #ff0;
10007          }
10008        }
10009      "#},
10010      Browsers {
10011        safari: Some(15 << 16),
10012        ..Browsers::default()
10013      },
10014    );
10015    prefix_test(
10016      r#"
10017      @media (min-resolution: 2dppx),
10018             (min-resolution: 192dpi) {
10019        .foo { color: yellow; }
10020      }
10021      "#,
10022      indoc! { r#"
10023        @media (-webkit-min-device-pixel-ratio: 2), (min--moz-device-pixel-ratio: 2), (min-resolution: 2dppx), (min-resolution: 192dpi) {
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    prefix_test(
10036      r#"
10037      @media only screen and (min-resolution: 124.8dpi) {
10038        .foo { color: yellow; }
10039      }
10040      "#,
10041      indoc! { r#"
10042        @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) {
10043          .foo {
10044            color: #ff0;
10045          }
10046        }
10047      "#},
10048      Browsers {
10049        safari: Some(15 << 16),
10050        firefox: Some(10 << 16),
10051        ..Browsers::default()
10052      },
10053    );
10054
10055    test_with_printer_options(
10056      r#"
10057        @media (width < 256px) or (hover: none) {
10058          .foo {
10059            color: #fff;
10060          }
10061        }
10062      "#,
10063      indoc! { r#"
10064        @media (not (min-width: 256px)) or (hover: none) {
10065          .foo {
10066            color: #fff;
10067          }
10068        }
10069      "#},
10070      PrinterOptions {
10071        targets: Targets {
10072          browsers: None,
10073          include: Features::MediaRangeSyntax,
10074          exclude: Features::empty(),
10075        },
10076        ..Default::default()
10077      },
10078    );
10079
10080    error_test(
10081      "@media (min-width: hi) { .foo { color: chartreuse }}",
10082      ParserError::InvalidMediaQuery,
10083    );
10084    error_test(
10085      "@media (width >= hi) { .foo { color: chartreuse }}",
10086      ParserError::InvalidMediaQuery,
10087    );
10088    error_test(
10089      "@media (width >= 2/1) { .foo { color: chartreuse }}",
10090      ParserError::UnexpectedToken(Token::Delim('/')),
10091    );
10092    error_test(
10093      "@media (600px <= min-height) { .foo { color: chartreuse }}",
10094      ParserError::InvalidMediaQuery,
10095    );
10096    error_test(
10097      "@media (scan >= 1) { .foo { color: chartreuse }}",
10098      ParserError::InvalidMediaQuery,
10099    );
10100    error_test(
10101      "@media (min-scan: interlace) { .foo { color: chartreuse }}",
10102      ParserError::InvalidMediaQuery,
10103    );
10104    error_test(
10105      "@media (1px <= width <= bar) { .foo { color: chartreuse }}",
10106      ParserError::InvalidMediaQuery,
10107    );
10108    error_test(
10109      "@media (1px <= min-width <= 2px) { .foo { color: chartreuse }}",
10110      ParserError::InvalidMediaQuery,
10111    );
10112    error_test(
10113      "@media (1px <= scan <= 2px) { .foo { color: chartreuse }}",
10114      ParserError::InvalidMediaQuery,
10115    );
10116    error_test(
10117      "@media (grid: 10) { .foo { color: chartreuse }}",
10118      ParserError::InvalidMediaQuery,
10119    );
10120    error_test(
10121      "@media (prefers-color-scheme = dark) { .foo { color: chartreuse }}",
10122      ParserError::InvalidMediaQuery,
10123    );
10124    error_test(
10125      "@media unknown(foo) {}",
10126      ParserError::UnexpectedToken(crate::properties::custom::Token::Function("unknown".into())),
10127    );
10128
10129    // empty brackets should return a clearer error message
10130    error_test("@media () {}", ParserError::EmptyBracketInCondition);
10131    error_test("@media screen and () {}", ParserError::EmptyBracketInCondition);
10132
10133    error_recovery_test("@media unknown(foo) {}");
10134  }
10135
10136  #[test]
10137  fn test_merge_layers() {
10138    test(
10139      r#"
10140      @layer foo {
10141        .foo {
10142          color: red;
10143        }
10144      }
10145      @layer foo {
10146        .foo {
10147          background: #fff;
10148        }
10149
10150        .baz {
10151          color: #fff;
10152        }
10153      }
10154      "#,
10155      indoc! {r#"
10156      @layer foo {
10157        .foo {
10158          color: red;
10159          background: #fff;
10160        }
10161
10162        .baz {
10163          color: #fff;
10164        }
10165      }
10166    "#},
10167    );
10168    test(
10169      r#"
10170      @layer a {}
10171      @layer b {}
10172
10173      @layer b {
10174        foo {
10175          color: red;
10176        }
10177      }
10178
10179      @layer a {
10180        bar {
10181          color: yellow;
10182        }
10183      }
10184      "#,
10185      indoc! {r#"
10186      @layer a {
10187        bar {
10188          color: #ff0;
10189        }
10190      }
10191
10192      @layer b {
10193        foo {
10194          color: red;
10195        }
10196      }
10197    "#},
10198    );
10199
10200    test(
10201      r#"
10202      @layer a {}
10203      @layer b {}
10204
10205      @layer b {
10206        foo {
10207          color: red;
10208        }
10209      }
10210      "#,
10211      indoc! {r#"
10212      @layer a;
10213
10214      @layer b {
10215        foo {
10216          color: red;
10217        }
10218      }
10219    "#},
10220    );
10221
10222    test(
10223      r#"
10224      @layer a;
10225      @layer b;
10226      @layer c;
10227      "#,
10228      indoc! {r#"
10229      @layer a, b, c;
10230    "#},
10231    );
10232
10233    test(
10234      r#"
10235      @layer a {}
10236      @layer b {}
10237      @layer c {}
10238      "#,
10239      indoc! {r#"
10240      @layer a, b, c;
10241    "#},
10242    );
10243
10244    test(
10245      r#"
10246      @layer a;
10247      @layer b {
10248        .foo {
10249          color: red;
10250        }
10251      }
10252      @layer c {}
10253      "#,
10254      indoc! {r#"
10255      @layer a;
10256
10257      @layer b {
10258        .foo {
10259          color: red;
10260        }
10261      }
10262
10263      @layer c;
10264    "#},
10265    );
10266
10267    test(
10268      r#"
10269      @layer a, b;
10270      @layer c {}
10271
10272      @layer d {
10273        foo {
10274          color: red;
10275        }
10276      }
10277      "#,
10278      indoc! {r#"
10279      @layer a, b, c;
10280
10281      @layer d {
10282        foo {
10283          color: red;
10284        }
10285      }
10286    "#},
10287    );
10288
10289    test(
10290      r#"
10291      @layer a;
10292      @layer b;
10293      @import "a.css" layer(x);
10294      @layer c;
10295
10296      @layer d {
10297        foo {
10298          color: red;
10299        }
10300      }
10301      "#,
10302      indoc! {r#"
10303      @layer a, b;
10304      @import "a.css" layer(x);
10305      @layer c;
10306
10307      @layer d {
10308        foo {
10309          color: red;
10310        }
10311      }
10312    "#},
10313    );
10314
10315    test(
10316      r#"
10317      @layer a, b, c;
10318
10319      @layer a {
10320        foo {
10321          color: red;
10322        }
10323      }
10324      "#,
10325      indoc! {r#"
10326      @layer a {
10327        foo {
10328          color: red;
10329        }
10330      }
10331
10332      @layer b, c;
10333    "#},
10334    );
10335
10336    test(
10337      r#"
10338      @layer a;
10339      @import "foo.css";
10340
10341      @layer a {
10342        foo {
10343          color: red;
10344        }
10345      }
10346      "#,
10347      indoc! {r#"
10348      @layer a;
10349      @import "foo.css";
10350
10351      @layer a {
10352        foo {
10353          color: red;
10354        }
10355      }
10356    "#},
10357    );
10358  }
10359
10360  #[test]
10361  fn test_duplicate_rules_preserve_importance() {
10362    minify_test(
10363      ".x { --c: first !important } @layer a { .y { --c: middle } } .x { --c: last }",
10364      ".x{--c:first!important}@layer a{.y{--c:middle}}.x{--c:last}",
10365    );
10366    minify_test(
10367      ".x { color: red !important } .y { color: green } .x { color: blue }",
10368      ".x{color:red!important}.y{color:green}.x{color:#00f}",
10369    );
10370  }
10371
10372  #[test]
10373  fn test_merge_common_custom_properties() {
10374    test(
10375      r#"
10376      html {
10377        --foreground: #000;
10378        --foreground-rgb: 0,0,0;
10379        --background: #fff;
10380      }
10381
10382      html[data-theme="dark"] {
10383        --foreground: #000;
10384        --foreground-rgb: 0,0,0;
10385        --background: #222;
10386      }
10387      "#,
10388      indoc! {r#"
10389      html {
10390        --background: #fff;
10391      }
10392
10393      html, html[data-theme="dark"] {
10394        --foreground: #000;
10395        --foreground-rgb: 0,0,0;
10396      }
10397
10398      html[data-theme="dark"] {
10399        --background: #222;
10400      }
10401      "#},
10402    );
10403
10404    // Either original rule may become empty after extraction.
10405    test(
10406      r#"
10407      .a {
10408        --shared: long-value;
10409      }
10410
10411      .b {
10412        --shared: long-value;
10413        color: red;
10414      }
10415      "#,
10416      indoc! {r#"
10417      .a, .b {
10418        --shared: long-value;
10419      }
10420
10421      .b {
10422        color: red;
10423      }
10424      "#},
10425    );
10426
10427    test(
10428      r#"
10429      .a {
10430        --shared: long-value;
10431        color: red;
10432      }
10433
10434      .b {
10435        --shared: long-value;
10436      }
10437      "#,
10438      indoc! {r#"
10439      .a {
10440        color: red;
10441      }
10442
10443      .a, .b {
10444        --shared: long-value;
10445      }
10446      "#},
10447    );
10448
10449    // Shared declarations retain their importance.
10450    test(
10451      r#"
10452      .a {
10453        --shared: long-value !important;
10454        color: red;
10455      }
10456
10457      .b {
10458        --shared: long-value !important;
10459        color: blue;
10460      }
10461      "#,
10462      indoc! {r#"
10463      .a {
10464        color: red;
10465      }
10466
10467      .a, .b {
10468        --shared: long-value !important;
10469      }
10470
10471      .b {
10472        color: #00f;
10473      }
10474      "#},
10475    );
10476
10477    // Variable references do not depend on declaration order.
10478    test(
10479      r#"
10480      .a {
10481        --shared: var(--color);
10482        --color: red;
10483      }
10484
10485      .b {
10486        --color: blue;
10487        --shared: var(--color);
10488      }
10489      "#,
10490      indoc! {r#"
10491      .a {
10492        --color: red;
10493      }
10494
10495      .a, .b {
10496        --shared: var(--color);
10497      }
10498
10499      .b {
10500        --color: blue;
10501      }
10502      "#},
10503    );
10504
10505    // The all shorthand does not reset custom properties.
10506    test(
10507      r#"
10508      .a {
10509        all: initial;
10510        --shared: long-value;
10511      }
10512
10513      .b {
10514        all: unset;
10515        --shared: long-value;
10516      }
10517      "#,
10518      indoc! {r#"
10519      .a {
10520        all: initial;
10521      }
10522
10523      .a, .b {
10524        --shared: long-value;
10525      }
10526
10527      .b {
10528        all: unset;
10529      }
10530      "#},
10531    );
10532
10533    // Rules can share declarations within the same conditional block.
10534    test(
10535      r#"
10536      @media print {
10537        .a {
10538          --shared: long-value;
10539          color: red;
10540        }
10541
10542        .b {
10543          --shared: long-value;
10544          color: blue;
10545        }
10546      }
10547      "#,
10548      indoc! {r#"
10549      @media print {
10550        .a {
10551          color: red;
10552        }
10553
10554        .a, .b {
10555          --shared: long-value;
10556        }
10557
10558        .b {
10559          color: #00f;
10560        }
10561      }
10562      "#},
10563    );
10564
10565    // Factor when the serialized declaration saves one byte over the extra selectors.
10566    test(
10567      r#"
10568      .a {
10569        --x: ab;
10570        color: red;
10571      }
10572
10573      .b {
10574        --x: ab;
10575        color: green;
10576      }
10577      "#,
10578      indoc! {r#"
10579      .a {
10580        color: red;
10581      }
10582
10583      .a, .b {
10584        --x: ab;
10585      }
10586
10587      .b {
10588        color: green;
10589      }
10590      "#},
10591    );
10592  }
10593
10594  #[test]
10595  fn test_merge_common_custom_properties_boundaries() {
10596    for source in [
10597      // Names are case-sensitive.
10598      indoc! {r#"
10599      .a {
10600        --shared: long-value;
10601        color: red;
10602      }
10603
10604      .b {
10605        --SHARED: long-value;
10606        color: green;
10607      }
10608      "#},
10609      // Values must match.
10610      indoc! {r#"
10611      .a {
10612        --shared: long-value;
10613        color: red;
10614      }
10615
10616      .b {
10617        --shared: other-value;
10618        color: green;
10619      }
10620      "#},
10621      // Importance must match.
10622      indoc! {r#"
10623      .a {
10624        color: red;
10625        --shared: long-value !important;
10626      }
10627
10628      .b {
10629        --shared: long-value;
10630        color: green;
10631      }
10632      "#},
10633      // Repeated selectors would cost more than the shared declaration.
10634      indoc! {r#"
10635      .long-selector-a {
10636        --x: 0;
10637        color: red;
10638      }
10639
10640      .long-selector-b {
10641        --x: 0;
10642        color: green;
10643      }
10644      "#},
10645      // A tie is left unchanged.
10646      indoc! {r#"
10647      .a {
10648        --x: 0;
10649        color: red;
10650      }
10651
10652      .b {
10653        --x: 0;
10654        color: green;
10655      }
10656      "#},
10657      // Do not move declarations across intervening rules.
10658      indoc! {r#"
10659      .a {
10660        --shared: long-value;
10661        color: red;
10662      }
10663
10664      .c {
10665        --shared: override;
10666      }
10667
10668      .b {
10669        --shared: long-value;
10670        color: green;
10671      }
10672      "#},
10673      // Do not move declarations across conditional boundaries.
10674      indoc! {r#"
10675      .a {
10676        --shared: long-value;
10677        color: red;
10678      }
10679
10680      @media print {
10681        .b {
10682          --shared: long-value;
10683          color: green;
10684        }
10685      }
10686      "#},
10687      // Ordinary declarations may have shorthand interactions.
10688      indoc! {r#"
10689      .a {
10690        color: red;
10691        padding-top: 20px;
10692      }
10693
10694      .b {
10695        color: green;
10696        padding-top: 20px;
10697      }
10698      "#},
10699    ] {
10700      test(source, source);
10701    }
10702
10703    // Unsupported selectors must not invalidate the other rule in a selector list.
10704    let source = indoc! {r#"
10705    .a {
10706      --shared: long-value;
10707      color: red;
10708    }
10709
10710    .b:has(.c) {
10711      --shared: long-value;
10712      color: green;
10713    }
10714    "#};
10715    prefix_test(
10716      source,
10717      source,
10718      Browsers {
10719        chrome: Some(90 << 16),
10720        ..Browsers::default()
10721      },
10722    );
10723
10724    // CSS Modules can change selector and variable lengths when printing.
10725    let source = indoc! {r#"
10726    html {
10727      --shared: long-value;
10728      color: red;
10729    }
10730
10731    body {
10732      --shared: long-value;
10733      color: green;
10734    }
10735    "#};
10736    test_with_options(
10737      source,
10738      source,
10739      ParserOptions {
10740        css_modules: Some(Default::default()),
10741        ..ParserOptions::default()
10742      },
10743    );
10744
10745    // Nested selectors can expand to much longer selector lists when lowered.
10746    for source in [
10747      indoc! {r#"
10748      .parent {
10749        &.a {
10750          --shared: long-value;
10751          color: red;
10752        }
10753
10754        &.b {
10755          --shared: long-value;
10756          color: green;
10757        }
10758      }
10759      "#},
10760      indoc! {r#"
10761      .parent {
10762        :is(&, .a) {
10763          --shared: long-value;
10764          color: red;
10765        }
10766
10767        :is(&, .b) {
10768          --shared: long-value;
10769          color: green;
10770        }
10771      }
10772      "#},
10773    ] {
10774      test(source, source);
10775    }
10776  }
10777
10778  #[test]
10779  fn test_merge_common_custom_properties_revisit() {
10780    // Adapted from cssnano's "should revisit a predecessor after replacing an adjacent pair".
10781    let expected = indoc! {r#"
10782      .a, .b {
10783        --x: 1;
10784        --color: red;
10785      }
10786
10787      .b {
10788        --background: blue;
10789      }
10790    "#};
10791    test(
10792      r#"
10793      .a, .b {
10794        --x: 1;
10795      }
10796
10797      .a {
10798        --color: red;
10799      }
10800
10801      .b {
10802        --color: red;
10803        --background: blue;
10804      }
10805    "#,
10806      expected,
10807    );
10808    // Like cssnano's convergence test, a second pass must not find another merge.
10809    test(expected, expected);
10810
10811    // Extraction can also expose identical blocks of ordinary declarations.
10812    let expected = indoc! {r#"
10813      .a, .b {
10814        color: red;
10815      }
10816
10817      .b, .c {
10818        --shared: long-value;
10819      }
10820
10821      .c {
10822        color: green;
10823      }
10824    "#};
10825    test(
10826      r#"
10827      .a {
10828        color: red;
10829      }
10830
10831      .b {
10832        --shared: long-value;
10833        color: red;
10834      }
10835
10836      .c {
10837        --shared: long-value;
10838        color: green;
10839      }
10840    "#,
10841      expected,
10842    );
10843    test(expected, expected);
10844  }
10845
10846  #[test]
10847  fn test_merge_common_custom_properties_selector_arguments() {
10848    // Extend cssnano's unknown-selector and :host regression cases to nested arguments.
10849    for source in [
10850      indoc! {r#"
10851        .a {
10852          --shared: very-long-shared-value;
10853          color: red;
10854        }
10855
10856        :host(:nonsense) {
10857          --shared: very-long-shared-value;
10858          color: green;
10859        }
10860      "#},
10861      indoc! {r#"
10862        .a {
10863          --shared: very-long-shared-value;
10864          color: red;
10865        }
10866
10867        ::slotted(:nonsense) {
10868          --shared: very-long-shared-value;
10869          color: green;
10870        }
10871      "#},
10872      indoc! {r#"
10873        .a {
10874          --shared: very-long-shared-value;
10875          color: red;
10876        }
10877
10878        ::cue(: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        ::cue(.b .c) {
10890          --shared: very-long-shared-value;
10891          color: green;
10892        }
10893      "#},
10894    ] {
10895      test(source, source);
10896    }
10897  }
10898
10899  #[test]
10900  fn test_merge_common_custom_properties_nested_has() {
10901    // Nesting inside :has() must be detected just like nesting inside :is().
10902    let source = indoc! {r#"
10903      .parent {
10904        :has(&) {
10905          --shared: very-long-shared-value;
10906          color: red;
10907        }
10908
10909        :has(&.b) {
10910          --shared: very-long-shared-value;
10911          color: green;
10912        }
10913      }
10914    "#};
10915    test(source, source);
10916  }
10917
10918  // Cases adapted from cssnano/postcss-merge-rules (MIT), with declarations
10919  // changed to custom properties where appropriate:
10920  // https://github.com/cssnano/cssnano/blob/13b2373173ce49c78b8a2015d8c3f6b025ccfc3e/packages/postcss-merge-rules/test/index.js
10921  //
10922  // Copyright (c) Ben Briggs <beneb.info@gmail.com> (https://beneb.info)
10923  //
10924  // Permission is hereby granted, free of charge, to any person
10925  // obtaining a copy of this software and associated documentation
10926  // files (the "Software"), to deal in the Software without
10927  // restriction, including without limitation the rights to use,
10928  // copy, modify, merge, publish, distribute, sublicense, and/or sell
10929  // copies of the Software, and to permit persons to whom the
10930  // Software is furnished to do so, subject to the following
10931  // conditions:
10932  //
10933  // The above copyright notice and this permission notice shall be
10934  // included in all copies or substantial portions of the Software.
10935  //
10936  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10937  // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
10938  // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
10939  // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
10940  // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
10941  // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
10942  // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
10943  // OTHER DEALINGS IN THE SOFTWARE.
10944  #[test]
10945  fn test_merge_common_custom_properties_cssnano() {
10946    // Different declaration order (cssnano test/index.js:40).
10947    test(
10948      r#"
10949      h1 {
10950        --color: red;
10951        --line-height: 1.5;
10952        --font-size: 2em;
10953      }
10954
10955      h2 {
10956        --font-size: 2em;
10957        --color: red;
10958        --line-height: 1.5;
10959      }
10960    "#,
10961      indoc! {r#"
10962      h1, h2 {
10963        --color: red;
10964        --line-height: 1.5;
10965        --font-size: 2em;
10966      }
10967    "#},
10968    );
10969
10970    // Partial merging across three rules (cssnano test/index.js:194).
10971    test(
10972      r#"
10973      h1 {
10974        --color: red;
10975        --text-decoration: underline;
10976      }
10977
10978      h2 {
10979        --text-decoration: underline;
10980        --color: green;
10981      }
10982
10983      h3 {
10984        --font-weight: bold;
10985        --color: green;
10986      }
10987    "#,
10988      indoc! {r#"
10989      h1 {
10990        --color: red;
10991      }
10992
10993      h1, h2 {
10994        --text-decoration: underline;
10995      }
10996
10997      h2, h3 {
10998        --color: green;
10999      }
11000
11001      h3 {
11002        --font-weight: bold;
11003      }
11004    "#},
11005    );
11006
11007    // The middle rule becomes empty (cssnano test/index.js:226).
11008    test(
11009      r#"
11010      .test-1 {
11011        --margin-top: 10px;
11012        --margin-bottom: 20px;
11013      }
11014
11015      .test-2 {
11016        --margin-top: 10px;
11017      }
11018
11019      .another-test {
11020        --margin-top: 10px;
11021        --margin-bottom: 30px;
11022      }
11023    "#,
11024      indoc! {r#"
11025      .test-1 {
11026        --margin-bottom: 20px;
11027      }
11028
11029      .test-1, .test-2, .another-test {
11030        --margin-top: 10px;
11031      }
11032
11033      .another-test {
11034        --margin-bottom: 30px;
11035      }
11036    "#},
11037    );
11038
11039    // Repeated declarations are already deduplicated by Lightning CSS (cssnano test/index.js:478).
11040    test(
11041      r#"
11042      h1 {
11043        --display: block;
11044        --display: block;
11045      }
11046
11047      h2 {
11048        --display: block;
11049        --display: block;
11050      }
11051    "#,
11052      indoc! {r#"
11053      h1, h2 {
11054        --display: block;
11055      }
11056    "#},
11057    );
11058
11059    // An overridden value must not be extracted (cssnano test/index.js:510).
11060    test(
11061      r#"
11062      .a {
11063        --font-family: Arial;
11064        --font-family: Helvetica;
11065      }
11066
11067      .b {
11068        --font-family: Arial;
11069      }
11070    "#,
11071      indoc! {r#"
11072      .a {
11073        --font-family: Helvetica;
11074      }
11075
11076      .b {
11077        --font-family: Arial;
11078      }
11079    "#},
11080    );
11081
11082    // Only the final matching value survives (cssnano test/index.js:646).
11083    test(
11084      r#"
11085      .a {
11086        --margin-left: 2px;
11087        color: red;
11088      }
11089
11090      .b {
11091        --margin-left: 2px;
11092        --margin-left: 1px;
11093        --margin-left: 2px;
11094      }
11095    "#,
11096      indoc! {r#"
11097      .a {
11098        color: red;
11099      }
11100
11101      .a, .b {
11102        --margin-left: 2px;
11103      }
11104    "#},
11105    );
11106
11107    // Custom properties with related-looking names are independent (cssnano test/propertyRelations.js).
11108    test(
11109      r#"
11110      .a {
11111        --font: serif;
11112        --font-size: 12px;
11113        color: red;
11114      }
11115
11116      .b {
11117        --font: serif;
11118        --font-size: 18px;
11119        color: green;
11120      }
11121    "#,
11122      indoc! {r#"
11123      .a {
11124        --font-size: 12px;
11125        color: red;
11126      }
11127
11128      .a, .b {
11129        --font: serif;
11130      }
11131
11132      .b {
11133        --font-size: 18px;
11134        color: green;
11135      }
11136    "#},
11137    );
11138
11139    // A predecessor merge preserves normal and important overrides independently.
11140    test(
11141      r#"
11142      .a, .b {
11143        --color: black;
11144        --fallback: stable;
11145        --color: green !important;
11146      }
11147
11148      .a {
11149        --color: red;
11150        --shared: long-value;
11151      }
11152
11153      .b {
11154        --color: red;
11155        --shared: long-value;
11156        --background: blue;
11157      }
11158    "#,
11159      indoc! {r#"
11160      .a, .b {
11161        --color: red;
11162        --fallback: stable;
11163        --shared: long-value;
11164        --color: green !important;
11165      }
11166
11167      .b {
11168        --background: blue;
11169      }
11170    "#},
11171    );
11172
11173    // Logical and physical declarations retain their order (cssnano test/index.js:1261).
11174    test(
11175      r#"
11176      .a {
11177        --shared: long-value;
11178        margin-inline-start: 1px;
11179        margin-top: 2px;
11180      }
11181
11182      .b {
11183        --shared: long-value;
11184        margin-inline-start: 3px;
11185        margin-top: 4px;
11186      }
11187    "#,
11188      indoc! {r#"
11189      .a {
11190        margin-inline-start: 1px;
11191        margin-top: 2px;
11192      }
11193
11194      .a, .b {
11195        --shared: long-value;
11196      }
11197
11198      .b {
11199        margin-inline-start: 3px;
11200        margin-top: 4px;
11201      }
11202    "#},
11203    );
11204
11205    // A forgiving selector argument may contain unsupported selectors.
11206    test(
11207      r#"
11208      .a {
11209        --shared: very-very-long-shared-value;
11210        color: red;
11211      }
11212
11213      :is(:nonsense, .b) {
11214        --shared: very-very-long-shared-value;
11215        color: green;
11216      }
11217    "#,
11218      indoc! {r#"
11219      .a {
11220        color: red;
11221      }
11222
11223      .a, :is(:nonsense, .b) {
11224        --shared: very-very-long-shared-value;
11225      }
11226
11227      :is(:nonsense, .b) {
11228        color: green;
11229      }
11230    "#},
11231    );
11232  }
11233
11234  #[test]
11235  fn test_merge_common_custom_properties_cssnano_boundaries() {
11236    for source in [
11237      // The selector cost exceeds the saving (cssnano test/index.js:303).
11238      indoc! {r#"
11239      .test0 {
11240        --color: red;
11241        --border: none;
11242        --margin: 0;
11243      }
11244
11245      .longlonglonglong {
11246        --color: green;
11247        --border: none;
11248        --margin: 0;
11249      }
11250    "#},
11251      // Different container queries (cssnano test/index.js:164).
11252      indoc! {r#"
11253      @container (width >= 200px) {
11254        .mobile {
11255          --display: none;
11256        }
11257      }
11258
11259      @container (width <= 100px) {
11260        .notMobile {
11261          --display: none;
11262        }
11263      }
11264    "#},
11265      // Different nested contexts (cssnano test/index.js:1004).
11266      indoc! {r#"
11267      @media (width >= 48rem) {
11268        .wrapper {
11269          --display: block;
11270        }
11271      }
11272
11273      @supports (display: flex) {
11274        @media (width >= 48rem) {
11275          .wrapper {
11276            --display: flex;
11277          }
11278        }
11279      }
11280    "#},
11281      // Keyframes use a separate rule type (cssnano test/index.js:662).
11282      indoc! {r#"
11283      @keyframes foo {
11284        0% {
11285          --shared: long-value;
11286          --opacity: 0;
11287        }
11288
11289        to {
11290          --shared: long-value;
11291          --opacity: 1;
11292        }
11293      }
11294    "#},
11295      // Different cascade layers must not share rules.
11296      indoc! {r#"
11297      @layer base {
11298        .a {
11299          --shared: long-value;
11300          color: red;
11301        }
11302      }
11303
11304      @layer theme {
11305        .b {
11306          --shared: long-value;
11307          color: green;
11308        }
11309      }
11310    "#},
11311      // Mixed vendor pseudo selectors (cssnano test/index.js:325).
11312      indoc! {r#"
11313      code :-ms-placeholder-shown {
11314        --shared: very-long-shared-value;
11315        color: red;
11316      }
11317
11318      code::-moz-placeholder {
11319        --shared: very-long-shared-value;
11320        color: green;
11321      }
11322    "#},
11323      // Unknown and known selectors (cssnano test/index.js:878).
11324      indoc! {r#"
11325      p {
11326        --shared: long-value;
11327        color: red;
11328      }
11329
11330      :nonsense {
11331        --shared: long-value;
11332        color: green;
11333      }
11334    "#},
11335    ] {
11336      test(source, source);
11337    }
11338  }
11339
11340  #[test]
11341  fn test_merge_rules() {
11342    test(
11343      r#"
11344      .foo {
11345        color: red;
11346      }
11347      .bar {
11348        color: red;
11349      }
11350    "#,
11351      indoc! {r#"
11352      .foo, .bar {
11353        color: red;
11354      }
11355    "#},
11356    );
11357    test(
11358      r#"
11359      .foo {
11360        color: red;
11361      }
11362      .foo {
11363        background: green;
11364      }
11365    "#,
11366      indoc! {r#"
11367      .foo {
11368        color: red;
11369        background: green;
11370      }
11371    "#},
11372    );
11373    test(
11374      r#"
11375      .foo {
11376        color: red;
11377      }
11378      .foo {
11379        background: green !important;
11380      }
11381    "#,
11382      indoc! {r#"
11383      .foo {
11384        color: red;
11385        background: green !important;
11386      }
11387    "#},
11388    );
11389    test(
11390      r#"
11391      .foo {
11392        background: red;
11393      }
11394      .foo {
11395        background: green;
11396      }
11397    "#,
11398      indoc! {r#"
11399      .foo {
11400        background: green;
11401      }
11402    "#},
11403    );
11404    test(
11405      r#"
11406      .foo {
11407        --foo: red;
11408        --foo: purple;
11409      }
11410      .foo {
11411        --foo: green;
11412      }
11413    "#,
11414      indoc! {r#"
11415      .foo {
11416        --foo: green;
11417      }
11418    "#},
11419    );
11420    test(
11421      r#"
11422      .foo {
11423        color: red;
11424      }
11425
11426      .bar {
11427        background: green;
11428      }
11429    "#,
11430      indoc! {r#"
11431      .foo {
11432        color: red;
11433      }
11434
11435      .bar {
11436        background: green;
11437      }
11438    "#},
11439    );
11440    test(
11441      r#"
11442      .foo {
11443        color: red;
11444      }
11445
11446      .baz {
11447        color: blue;
11448      }
11449
11450      .bar {
11451        color: red;
11452      }
11453    "#,
11454      indoc! {r#"
11455      .foo {
11456        color: red;
11457      }
11458
11459      .baz {
11460        color: #00f;
11461      }
11462
11463      .bar {
11464        color: red;
11465      }
11466    "#},
11467    );
11468    test(
11469      r#"
11470      .foo {
11471        background: red;
11472      }
11473      .bar {
11474        background: red;
11475      }
11476      .foo {
11477        color: green;
11478      }
11479      .bar {
11480        color: green;
11481      }
11482    "#,
11483      indoc! {r#"
11484      .foo, .bar {
11485        color: green;
11486        background: red;
11487      }
11488    "#},
11489    );
11490    test(
11491      r#"
11492      .foo, .bar {
11493        background: red;
11494      }
11495      .foo {
11496        color: green;
11497      }
11498      .bar {
11499        color: green;
11500      }
11501    "#,
11502      indoc! {r#"
11503      .foo, .bar {
11504        color: green;
11505        background: red;
11506      }
11507    "#},
11508    );
11509    test(
11510      r#"
11511      .foo {
11512        background: red;
11513      }
11514      .foo {
11515        color: green;
11516      }
11517      .bar {
11518        background: red;
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="bar"] {
11534        color: red;
11535      }
11536      .bar {
11537        color: red;
11538      }
11539    "#,
11540      indoc! {r#"
11541      [foo="bar"], .bar {
11542        color: red;
11543      }
11544    "#},
11545    );
11546    test(
11547      r#"
11548      .a {
11549        color: red;
11550      }
11551      .b {
11552        color: green;
11553      }
11554      .a {
11555        color: red;
11556      }
11557    "#,
11558      indoc! {r#"
11559      .b {
11560        color: green;
11561      }
11562
11563      .a {
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: pink;
11578      }
11579    "#,
11580      indoc! {r#"
11581      .b {
11582        color: green;
11583      }
11584
11585      .a {
11586        color: pink;
11587      }
11588    "#},
11589    );
11590    test(
11591      r#"
11592      .a:foo(#000) {
11593        color: red;
11594      }
11595      .b {
11596        color: green;
11597      }
11598      .a:foo(#ff0) {
11599        color: pink;
11600      }
11601    "#,
11602      indoc! {r#"
11603      .a:foo(#000) {
11604        color: red;
11605      }
11606
11607      .b {
11608        color: green;
11609      }
11610
11611      .a:foo(#ff0) {
11612        color: pink;
11613      }
11614    "#},
11615    );
11616    test(
11617      r#"
11618      .a {
11619        border-radius: 10px;
11620      }
11621      .b {
11622        color: green;
11623      }
11624      .a {
11625        border-radius: 10px;
11626      }
11627    "#,
11628      indoc! {r#"
11629      .b {
11630        color: green;
11631      }
11632
11633      .a {
11634        border-radius: 10px;
11635      }
11636    "#},
11637    );
11638    test(
11639      r#"
11640      .a {
11641        border-radius: 10px;
11642      }
11643      .b {
11644        color: green;
11645      }
11646      .a {
11647        -webkit-border-radius: 10px;
11648      }
11649    "#,
11650      indoc! {r#"
11651      .a {
11652        border-radius: 10px;
11653      }
11654
11655      .b {
11656        color: green;
11657      }
11658
11659      .a {
11660        -webkit-border-radius: 10px;
11661      }
11662    "#},
11663    );
11664    test(
11665      r#"
11666      .a {
11667        border-radius: 10px;
11668      }
11669      .b {
11670        color: green;
11671      }
11672      .a {
11673        border-radius: var(--foo);
11674      }
11675    "#,
11676      indoc! {r#"
11677      .b {
11678        color: green;
11679      }
11680
11681      .a {
11682        border-radius: var(--foo);
11683      }
11684    "#},
11685    );
11686    test(
11687      r#"
11688      .a {
11689        border-radius: 10px;
11690      }
11691      .b {
11692        color: green;
11693      }
11694      .c {
11695        border-radius: 20px;
11696      }
11697    "#,
11698      indoc! {r#"
11699      .a {
11700        border-radius: 10px;
11701      }
11702
11703      .b {
11704        color: green;
11705      }
11706
11707      .c {
11708        border-radius: 20px;
11709      }
11710    "#},
11711    );
11712    test(
11713      r#"
11714      @media print {
11715        .a {
11716          color: red;
11717        }
11718        .b {
11719          color: green;
11720        }
11721        .a {
11722          color: red;
11723        }
11724      }
11725    "#,
11726      indoc! {r#"
11727      @media print {
11728        .b {
11729          color: green;
11730        }
11731
11732        .a {
11733          color: red;
11734        }
11735      }
11736    "#},
11737    );
11738    test(
11739      r#"
11740      .a {
11741        border-radius: 10px;
11742      }
11743      .b {
11744        color: green;
11745      }
11746      .a {
11747        border-radius: 20px;
11748        color: pink;
11749      }
11750    "#,
11751      indoc! {r#"
11752      .a {
11753        border-radius: 10px;
11754      }
11755
11756      .b {
11757        color: green;
11758      }
11759
11760      .a {
11761        color: pink;
11762        border-radius: 20px;
11763      }
11764    "#},
11765    );
11766    test(
11767      r#"
11768      .a {
11769        color: red;
11770      }
11771      .b {
11772        color: green;
11773      }
11774      .a {
11775        color: red;
11776      }
11777      .b {
11778        color: green;
11779      }
11780    "#,
11781      indoc! {r#"
11782      .a {
11783        color: red;
11784      }
11785
11786      .b {
11787        color: green;
11788      }
11789    "#},
11790    );
11791
11792    prefix_test(
11793      r#"
11794      [foo="bar"] {
11795        color: red;
11796      }
11797      .bar {
11798        color: red;
11799      }
11800    "#,
11801      indoc! {r#"
11802      [foo="bar"] {
11803        color: red;
11804      }
11805
11806      .bar {
11807        color: red;
11808      }
11809    "#},
11810      Browsers {
11811        ie: Some(6 << 16),
11812        ..Browsers::default()
11813      },
11814    );
11815
11816    prefix_test(
11817      r#"
11818      [foo="bar"] {
11819        color: red;
11820      }
11821      .bar {
11822        color: red;
11823      }
11824    "#,
11825      indoc! {r#"
11826      [foo="bar"], .bar {
11827        color: red;
11828      }
11829    "#},
11830      Browsers {
11831        ie: Some(10 << 16),
11832        ..Browsers::default()
11833      },
11834    );
11835
11836    test(
11837      r#"
11838      .foo:-moz-read-only {
11839        color: red;
11840      }
11841    "#,
11842      indoc! {r#"
11843      .foo:-moz-read-only {
11844        color: red;
11845      }
11846    "#},
11847    );
11848
11849    test(
11850      r#"
11851      .foo:-moz-read-only {
11852        color: red;
11853      }
11854
11855      .foo:read-only {
11856        color: red;
11857      }
11858    "#,
11859      indoc! {r#"
11860      .foo:-moz-read-only {
11861        color: red;
11862      }
11863
11864      .foo:read-only {
11865        color: red;
11866      }
11867    "#},
11868    );
11869
11870    prefix_test(
11871      r#"
11872      .foo:-moz-read-only {
11873        color: red;
11874      }
11875
11876      .foo:read-only {
11877        color: red;
11878      }
11879    "#,
11880      indoc! {r#"
11881      .foo:read-only {
11882        color: red;
11883      }
11884    "#},
11885      Browsers {
11886        firefox: Some(85 << 16),
11887        ..Browsers::default()
11888      },
11889    );
11890
11891    prefix_test(
11892      r#"
11893      .foo:-moz-read-only {
11894        color: red;
11895      }
11896
11897      .bar {
11898        color: yellow;
11899      }
11900
11901      .foo:read-only {
11902        color: red;
11903      }
11904    "#,
11905      indoc! {r#"
11906      .foo:-moz-read-only {
11907        color: red;
11908      }
11909
11910      .bar {
11911        color: #ff0;
11912      }
11913
11914      .foo:read-only {
11915        color: red;
11916      }
11917    "#},
11918      Browsers {
11919        firefox: Some(85 << 16),
11920        ..Browsers::default()
11921      },
11922    );
11923
11924    prefix_test(
11925      r#"
11926      .foo:-moz-read-only {
11927        color: red;
11928      }
11929
11930      .foo:read-only {
11931        color: red;
11932      }
11933    "#,
11934      indoc! {r#"
11935      .foo:-moz-read-only {
11936        color: red;
11937      }
11938
11939      .foo:read-only {
11940        color: red;
11941      }
11942    "#},
11943      Browsers {
11944        firefox: Some(36 << 16),
11945        ..Browsers::default()
11946      },
11947    );
11948
11949    prefix_test(
11950      r#"
11951      .foo:read-only {
11952        color: red;
11953      }
11954    "#,
11955      indoc! {r#"
11956      .foo:-moz-read-only {
11957        color: red;
11958      }
11959
11960      .foo:read-only {
11961        color: red;
11962      }
11963    "#},
11964      Browsers {
11965        firefox: Some(36 << 16),
11966        ..Browsers::default()
11967      },
11968    );
11969
11970    prefix_test(
11971      r#"
11972      .foo:-webkit-full-screen {
11973        color: red;
11974      }
11975      .foo:-moz-full-screen {
11976        color: red;
11977      }
11978      .foo:-ms-fullscreen {
11979        color: red;
11980      }
11981      .foo:fullscreen {
11982        color: red;
11983      }
11984    "#,
11985      indoc! {r#"
11986      .foo:fullscreen {
11987        color: red;
11988      }
11989    "#},
11990      Browsers {
11991        chrome: Some(96 << 16),
11992        ..Browsers::default()
11993      },
11994    );
11995
11996    prefix_test(
11997      r#"
11998      .foo:fullscreen {
11999        color: red;
12000      }
12001    "#,
12002      indoc! {r#"
12003      .foo:-webkit-full-screen {
12004        color: red;
12005      }
12006
12007      .foo:-moz-full-screen {
12008        color: red;
12009      }
12010
12011      .foo:-ms-fullscreen {
12012        color: red;
12013      }
12014
12015      .foo:fullscreen {
12016        color: red;
12017      }
12018    "#},
12019      Browsers {
12020        chrome: Some(45 << 16),
12021        firefox: Some(45 << 16),
12022        ie: Some(11 << 16),
12023        ..Browsers::default()
12024      },
12025    );
12026
12027    prefix_test(
12028      r#"
12029      .foo::placeholder {
12030        color: red;
12031      }
12032    "#,
12033      indoc! {r#"
12034      .foo::-webkit-input-placeholder {
12035        color: red;
12036      }
12037
12038      .foo::-moz-placeholder {
12039        color: red;
12040      }
12041
12042      .foo::-ms-input-placeholder {
12043        color: red;
12044      }
12045
12046      .foo::placeholder {
12047        color: red;
12048      }
12049    "#},
12050      Browsers {
12051        chrome: Some(45 << 16),
12052        firefox: Some(45 << 16),
12053        ie: Some(11 << 16),
12054        ..Browsers::default()
12055      },
12056    );
12057
12058    prefix_test(
12059      r#"
12060      .foo::file-selector-button {
12061        color: red;
12062      }
12063    "#,
12064      indoc! {r#"
12065      .foo::-webkit-file-upload-button {
12066        color: red;
12067      }
12068
12069      .foo::-ms-browse {
12070        color: red;
12071      }
12072
12073      .foo::file-selector-button {
12074        color: red;
12075      }
12076    "#},
12077      Browsers {
12078        chrome: Some(84 << 16),
12079        ie: Some(10 << 16),
12080        ..Browsers::default()
12081      },
12082    );
12083
12084    prefix_test(
12085      r#"
12086      .foo::file-selector-button {
12087        margin-inline-start: 2px;
12088      }
12089    "#,
12090      indoc! {r#"
12091      .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 {
12092        margin-left: 2px;
12093      }
12094
12095      .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 {
12096        margin-left: 2px;
12097      }
12098
12099      .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 {
12100        margin-left: 2px;
12101      }
12102
12103      .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 {
12104        margin-right: 2px;
12105      }
12106
12107      .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 {
12108        margin-right: 2px;
12109      }
12110
12111      .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 {
12112        margin-right: 2px;
12113      }
12114    "#},
12115      Browsers {
12116        chrome: Some(84 << 16),
12117        ie: Some(10 << 16),
12118        ..Browsers::default()
12119      },
12120    );
12121
12122    prefix_test(
12123      r#"
12124      .foo:placeholder-shown .bar { color: red; }
12125      .foo:autofill .baz { color: red; }
12126      "#,
12127      indoc! {r#"
12128      .foo:placeholder-shown .bar {
12129        color: red;
12130      }
12131
12132      .foo:-webkit-autofill .baz {
12133        color: red;
12134      }
12135
12136      .foo:autofill .baz {
12137        color: red;
12138      }
12139      "#},
12140      Browsers {
12141        chrome: Some(103 << 16),
12142        ..Browsers::default()
12143      },
12144    );
12145
12146    prefix_test(
12147      r#"
12148      .foo:placeholder-shown .bar,.foo:autofill .baz{color:red}
12149      "#,
12150      indoc! {r#"
12151      :-webkit-any(.foo:placeholder-shown .bar, .foo:-webkit-autofill .baz) {
12152        color: red;
12153      }
12154
12155      :is(.foo:placeholder-shown .bar, .foo:autofill .baz) {
12156        color: red;
12157      }
12158      "#},
12159      Browsers {
12160        chrome: Some(103 << 16),
12161        ..Browsers::default()
12162      },
12163    );
12164
12165    prefix_test(
12166      r#"
12167      .foo:placeholder-shown .bar, .foo:-webkit-autofill .baz {
12168        color: red;
12169      }
12170
12171      .foo:placeholder-shown .bar, .foo:autofill .baz {
12172        color: red;
12173      }
12174      "#,
12175      indoc! {r#"
12176      :-webkit-any(.foo:placeholder-shown .bar, .foo:-webkit-autofill .baz) {
12177        color: red;
12178      }
12179
12180      :is(.foo:placeholder-shown .bar, .foo:autofill .baz) {
12181        color: red;
12182      }
12183      "#},
12184      Browsers {
12185        chrome: Some(103 << 16),
12186        ..Browsers::default()
12187      },
12188    );
12189
12190    test(
12191      r#"
12192      .foo:placeholder-shown .bar, .foo:-webkit-autofill .baz {
12193        color: red;
12194      }
12195
12196      .foo:placeholder-shown .bar, .foo:autofill .baz {
12197        color: red;
12198      }
12199      "#,
12200      indoc! {r#"
12201      .foo:placeholder-shown .bar, .foo:-webkit-autofill .baz {
12202        color: red;
12203      }
12204
12205      .foo:placeholder-shown .bar, .foo:autofill .baz {
12206        color: red;
12207      }
12208      "#},
12209    );
12210
12211    prefix_test(
12212      r#"
12213      :hover, :focus-visible {
12214        color: red;
12215      }
12216      "#,
12217      indoc! {r#"
12218      :hover {
12219        color: red;
12220      }
12221
12222      :focus-visible {
12223        color: red;
12224      }
12225      "#},
12226      Browsers {
12227        safari: Some(13 << 16),
12228        ..Browsers::default()
12229      },
12230    );
12231
12232    prefix_test(
12233      r#"
12234      .foo {
12235        color: red;
12236      }
12237
12238      :hover, :focus-visible {
12239        color: red;
12240      }
12241      "#,
12242      indoc! {r#"
12243      .foo, :hover {
12244        color: red;
12245      }
12246
12247      :focus-visible {
12248        color: red;
12249      }
12250      "#},
12251      Browsers {
12252        safari: Some(13 << 16),
12253        ..Browsers::default()
12254      },
12255    );
12256
12257    prefix_test(
12258      r#"
12259      :hover, :focus-visible {
12260        margin-inline-start: 24px;
12261      }
12262      "#,
12263      indoc! {r#"
12264      :hover:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
12265        margin-left: 24px;
12266      }
12267
12268      :hover:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
12269        margin-right: 24px;
12270      }
12271
12272      :focus-visible:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
12273        margin-left: 24px;
12274      }
12275
12276      :focus-visible:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
12277        margin-right: 24px;
12278      }
12279      "#},
12280      Browsers {
12281        safari: Some(11 << 16),
12282        ..Browsers::default()
12283      },
12284    );
12285
12286    prefix_test(
12287      r#"
12288      :focus-within, :focus-visible {
12289        color: red;
12290      }
12291      "#,
12292      indoc! {r#"
12293      :focus-within {
12294        color: red;
12295      }
12296
12297      :focus-visible {
12298        color: red;
12299      }
12300      "#},
12301      Browsers {
12302        safari: Some(9 << 16),
12303        ..Browsers::default()
12304      },
12305    );
12306
12307    prefix_test(
12308      r#"
12309      :hover, :focus-visible {
12310        color: red;
12311      }
12312      "#,
12313      indoc! {r#"
12314      :is(:hover, :focus-visible) {
12315        color: red;
12316      }
12317      "#},
12318      Browsers {
12319        safari: Some(14 << 16),
12320        ..Browsers::default()
12321      },
12322    );
12323
12324    prefix_test(
12325      r#"
12326      a::after:hover, a::after:focus-visible {
12327        color: red;
12328      }
12329      "#,
12330      indoc! {r#"
12331      a:after:hover {
12332        color: red;
12333      }
12334
12335      a:after:focus-visible {
12336        color: red;
12337      }
12338      "#},
12339      Browsers {
12340        safari: Some(14 << 16),
12341        ..Browsers::default()
12342      },
12343    );
12344
12345    prefix_test(
12346      r#"
12347      a:not(:hover), a:not(:focus-visible) {
12348        color: red;
12349      }
12350      "#,
12351      indoc! {r#"
12352      :is(a:not(:hover), a:not(:focus-visible)) {
12353        color: red;
12354      }
12355      "#},
12356      Browsers {
12357        safari: Some(14 << 16),
12358        ..Browsers::default()
12359      },
12360    );
12361
12362    prefix_test(
12363      r#"
12364      a:has(:hover), a:has(:focus-visible) {
12365        color: red;
12366      }
12367      "#,
12368      indoc! {r#"
12369      :is(a:has(:hover), a:has(:focus-visible)) {
12370        color: red;
12371      }
12372      "#},
12373      Browsers {
12374        safari: Some(14 << 16),
12375        ..Browsers::default()
12376      },
12377    );
12378
12379    prefix_test(
12380      r#"
12381      .foo.foo:hover, .bar:focus-visible {
12382        color: red;
12383      }
12384      "#,
12385      indoc! {r#"
12386      .foo.foo:hover {
12387        color: red;
12388      }
12389
12390      .bar:focus-visible {
12391        color: red;
12392      }
12393      "#},
12394      Browsers {
12395        safari: Some(14 << 16),
12396        ..Browsers::default()
12397      },
12398    );
12399
12400    prefix_test(
12401      r#"
12402      a::unknown-a, a::unknown-b {
12403        color: red;
12404      }
12405      "#,
12406      indoc! {r#"
12407      a::unknown-a {
12408        color: red;
12409      }
12410
12411      a::unknown-b {
12412        color: red;
12413      }
12414      "#},
12415      Browsers {
12416        safari: Some(14 << 16),
12417        ..Browsers::default()
12418      },
12419    );
12420
12421    nesting_test_with_targets(
12422      r#"
12423      .foo {
12424        padding-inline-start: 3px;
12425
12426        .bar {
12427          padding-inline-start: 5px;
12428        }
12429      }
12430      "#,
12431      indoc! {r#"
12432      .foo:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
12433        padding-left: 3px;
12434      }
12435
12436      .foo:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
12437        padding-right: 3px;
12438      }
12439
12440      .foo .bar:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
12441        padding-left: 5px;
12442      }
12443
12444      .foo .bar:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
12445        padding-right: 5px;
12446      }
12447      "#},
12448      Browsers {
12449        safari: Some(12 << 16),
12450        ..Browsers::default()
12451      }
12452      .into(),
12453    );
12454
12455    prefix_test(
12456      r#"
12457      .foo::part(header), .foo::part(body) {
12458        display: none
12459      }
12460      "#,
12461      indoc! {r#"
12462      .foo::part(header), .foo::part(body) {
12463        display: none;
12464      }
12465      "#},
12466      Browsers {
12467        safari: Some(14 << 16),
12468        ..Browsers::default()
12469      },
12470    );
12471
12472    prefix_test(
12473      r#"
12474      .foo :is(.bar) {
12475        color: red;
12476      }
12477      "#,
12478      indoc! {r#"
12479        .foo .bar {
12480          color: red;
12481        }
12482      "#},
12483      Browsers {
12484        chrome: Some(87 << 16),
12485        ..Browsers::default()
12486      },
12487    );
12488
12489    prefix_test(
12490      r#"
12491      .foo :is(.bar), .bar :is(.baz) {
12492        color: red;
12493      }
12494      "#,
12495      indoc! {r#"
12496        .foo .bar, .bar .baz {
12497          color: red;
12498        }
12499      "#},
12500      Browsers {
12501        chrome: Some(87 << 16),
12502        ..Browsers::default()
12503      },
12504    );
12505
12506    prefix_test(
12507      r#"
12508      .foo :is(.bar:focus-visible), .bar :is(.baz:hover) {
12509        color: red;
12510      }
12511      "#,
12512      indoc! {r#"
12513        .bar .baz:hover {
12514          color: red;
12515        }
12516
12517        .foo .bar:focus-visible {
12518          color: red;
12519        }
12520      "#},
12521      Browsers {
12522        chrome: Some(85 << 16),
12523        ..Browsers::default()
12524      },
12525    );
12526
12527    prefix_test(
12528      r#"
12529      *,
12530      ::before,
12531      ::after,
12532      ::backdrop {
12533        padding: 5px;
12534      }
12535      "#,
12536      indoc! {r#"
12537        *, :before, :after {
12538          padding: 5px;
12539        }
12540
12541        ::-webkit-backdrop {
12542          padding: 5px;
12543        }
12544
12545        ::backdrop {
12546          padding: 5px;
12547        }
12548      "#},
12549      Browsers {
12550        chrome: Some(33 << 16),
12551        ..Browsers::default()
12552      },
12553    );
12554
12555    test(
12556      r#"
12557      .foo:-webkit-any(.bar, .baz):after {
12558        color: red;
12559      }
12560
12561      .foo:is(.bar, .baz):after {
12562        color: red;
12563      }
12564      "#,
12565      indoc! {r#"
12566        .foo:-webkit-any(.bar, .baz):after {
12567          color: red;
12568        }
12569
12570        .foo:is(.bar, .baz):after {
12571          color: red;
12572        }
12573      "#},
12574    );
12575
12576    prefix_test(
12577      r#"
12578      .foo:-webkit-any(.bar, .baz):after {
12579        color: red;
12580      }
12581
12582      .foo:is(.bar, .baz):after {
12583        color: red;
12584      }
12585      "#,
12586      indoc! {r#"
12587        .foo:is(.bar, .baz):after {
12588          color: red;
12589        }
12590      "#},
12591      Browsers {
12592        safari: Some(16 << 16),
12593        ..Browsers::default()
12594      },
12595    );
12596
12597    prefix_test(
12598      r#"
12599      .foo:-webkit-any(.bar):after {
12600        color: red;
12601      }
12602
12603      .foo:is(.bar, .baz):after {
12604        color: red;
12605      }
12606      "#,
12607      indoc! {r#"
12608        .foo:-webkit-any(.bar):after {
12609          color: red;
12610        }
12611
12612        .foo:is(.bar, .baz):after {
12613          color: red;
12614        }
12615      "#},
12616      Browsers {
12617        safari: Some(16 << 16),
12618        ..Browsers::default()
12619      },
12620    );
12621
12622    prefix_test(
12623      r#"
12624      .foo:-webkit-any(.bar, .baz):after {
12625        color: red;
12626      }
12627
12628      .foo:is(.bar, .baz):after {
12629        color: red;
12630      }
12631      "#,
12632      indoc! {r#"
12633        .foo:-webkit-any(.bar, .baz):after {
12634          color: red;
12635        }
12636
12637        .foo:is(.bar, .baz):after {
12638          color: red;
12639        }
12640      "#},
12641      Browsers {
12642        safari: Some(12 << 16),
12643        ..Browsers::default()
12644      },
12645    );
12646
12647    prefix_test(
12648      r#"
12649      .foo:-webkit-any(.bar, .baz):after {
12650        color: red;
12651      }
12652
12653      .foo:-moz-any(.bar, .baz):after {
12654        color: red;
12655      }
12656      "#,
12657      indoc! {r#"
12658        .foo:-webkit-any(.bar, .baz):after {
12659          color: red;
12660        }
12661
12662        .foo:-moz-any(.bar, .baz):after {
12663          color: red;
12664        }
12665      "#},
12666      Browsers {
12667        safari: Some(12 << 16),
12668        firefox: Some(67 << 16),
12669        ..Browsers::default()
12670      },
12671    );
12672
12673    prefix_test(
12674      r#"
12675      .a {
12676        padding-inline: var(--foo);
12677      }
12678
12679      .a:-webkit-any(.b, .c) {
12680        padding-inline: var(--foo);
12681      }
12682      "#,
12683      indoc! {r#"
12684        .a {
12685          padding-inline: var(--foo);
12686        }
12687
12688        .a:-webkit-any(.b, .c) {
12689          padding-inline: var(--foo);
12690        }
12691      "#},
12692      Browsers {
12693        safari: Some(12 << 16),
12694        ..Browsers::default()
12695      },
12696    );
12697  }
12698
12699  #[test]
12700  fn test_merge_media_rules() {
12701    test(
12702      r#"
12703      @media (hover) {
12704        .foo {
12705          color: red;
12706        }
12707      }
12708      @media (hover) {
12709        .foo {
12710          background: #fff;
12711        }
12712
12713        .baz {
12714          color: #fff;
12715        }
12716      }
12717      "#,
12718      indoc! {r#"
12719      @media (hover) {
12720        .foo {
12721          color: red;
12722          background: #fff;
12723        }
12724
12725        .baz {
12726          color: #fff;
12727        }
12728      }
12729    "#},
12730    );
12731
12732    test(
12733      r#"
12734      @media (hover) {
12735        .foo {
12736          color: red;
12737        }
12738      }
12739      @media (min-width: 250px) {
12740        .foo {
12741          background: #fff;
12742        }
12743
12744        .baz {
12745          color: #fff;
12746        }
12747      }
12748      "#,
12749      indoc! {r#"
12750      @media (hover) {
12751        .foo {
12752          color: red;
12753        }
12754      }
12755
12756      @media (width >= 250px) {
12757        .foo {
12758          background: #fff;
12759        }
12760
12761        .baz {
12762          color: #fff;
12763        }
12764      }
12765    "#},
12766    );
12767  }
12768
12769  #[test]
12770  fn test_merge_supports() {
12771    test(
12772      r#"
12773      @supports (flex: 1) {
12774        .foo {
12775          color: red;
12776        }
12777      }
12778      @supports (flex: 1) {
12779        .foo {
12780          background: #fff;
12781        }
12782
12783        .baz {
12784          color: #fff;
12785        }
12786      }
12787      "#,
12788      indoc! {r#"
12789      @supports (flex: 1) {
12790        .foo {
12791          color: red;
12792          background: #fff;
12793        }
12794
12795        .baz {
12796          color: #fff;
12797        }
12798      }
12799    "#},
12800    );
12801
12802    test(
12803      r#"
12804      @supports (flex: 1) {
12805        .foo {
12806          color: red;
12807        }
12808      }
12809      @supports (display: grid) {
12810        .foo {
12811          background: #fff;
12812        }
12813
12814        .baz {
12815          color: #fff;
12816        }
12817      }
12818      "#,
12819      indoc! {r#"
12820      @supports (flex: 1) {
12821        .foo {
12822          color: red;
12823        }
12824      }
12825
12826      @supports (display: grid) {
12827        .foo {
12828          background: #fff;
12829        }
12830
12831        .baz {
12832          color: #fff;
12833        }
12834      }
12835    "#},
12836    );
12837  }
12838
12839  #[test]
12840  fn test_opacity() {
12841    minify_test(".foo { opacity: 0 }", ".foo{opacity:0}");
12842    minify_test(".foo { opacity: 0% }", ".foo{opacity:0}");
12843    minify_test(".foo { opacity: 0.5 }", ".foo{opacity:.5}");
12844    minify_test(".foo { opacity: 50% }", ".foo{opacity:.5}");
12845    minify_test(".foo { opacity: 1 }", ".foo{opacity:1}");
12846    minify_test(".foo { opacity: 100% }", ".foo{opacity:1}");
12847  }
12848
12849  #[test]
12850  fn test_transitions() {
12851    property_range_test(&["transition-delay"], &[("-1s", Some("-1s"))]);
12852    property_range_test(
12853      &["transition"],
12854      &[("opacity -1s", None), ("opacity 1s -1s", Some("opacity 1s -1s"))],
12855    );
12856    property_range_test(
12857      &["transition-duration"],
12858      &[("-1s", None), ("calc(1s - 2s)", Some("0s"))],
12859    );
12860    use crate::values::time::Time;
12861
12862    for (source, expected) in [
12863      ("-1s", None),
12864      ("-1ms", None),
12865      ("0s", Some("0s")),
12866      ("calc(-1s)", Some("0s")),
12867      ("calc(500ms - 1s)", Some("0s")),
12868      ("calc(-1s + 1500ms)", Some(".5s")),
12869      ("calc(min(-1s, -2s) + 3s)", Some("1s")),
12870      ("calc(1px)", None),
12871      ("calc(1)", None),
12872    ] {
12873      non_negative_test::<Time>(source, expected);
12874    }
12875    assert!(Time::parse_string("-1s").is_ok());
12876
12877    minify_test(".foo { transition-duration: 500ms }", ".foo{transition-duration:.5s}");
12878    minify_test(".foo { transition-duration: .5s }", ".foo{transition-duration:.5s}");
12879    minify_test(".foo { transition-duration: 99ms }", ".foo{transition-duration:99ms}");
12880    minify_test(".foo { transition-duration: .099s }", ".foo{transition-duration:99ms}");
12881    minify_test(".foo { transition-duration: 2000ms }", ".foo{transition-duration:2s}");
12882    minify_test(".foo { transition-duration: 2s }", ".foo{transition-duration:2s}");
12883    minify_test(
12884      ".foo { transition-duration: calc(1s - 50ms) }",
12885      ".foo{transition-duration:.95s}",
12886    );
12887    minify_test(
12888      ".foo { transition-duration: calc(1s - 50ms + 2s) }",
12889      ".foo{transition-duration:2.95s}",
12890    );
12891    minify_test(
12892      ".foo { transition-duration: calc((1s - 50ms) * 2) }",
12893      ".foo{transition-duration:1.9s}",
12894    );
12895    minify_test(
12896      ".foo { transition-duration: calc(2 * (1s - 50ms)) }",
12897      ".foo{transition-duration:1.9s}",
12898    );
12899    minify_test(
12900      ".foo { transition-duration: calc((2s + 50ms) - (1s - 50ms)) }",
12901      ".foo{transition-duration:1.1s}",
12902    );
12903    minify_test(
12904      ".foo { transition-duration: 500ms, 50ms }",
12905      ".foo{transition-duration:.5s,50ms}",
12906    );
12907    minify_test(".foo { transition-delay: 500ms }", ".foo{transition-delay:.5s}");
12908    minify_test(
12909      ".foo { transition-property: background }",
12910      ".foo{transition-property:background}",
12911    );
12912    minify_test(
12913      ".foo { transition-property: background, opacity }",
12914      ".foo{transition-property:background,opacity}",
12915    );
12916    minify_test(
12917      ".foo { transition-timing-function: linear }",
12918      ".foo{transition-timing-function:linear}",
12919    );
12920    minify_test(
12921      ".foo { transition-timing-function: ease }",
12922      ".foo{transition-timing-function:ease}",
12923    );
12924    minify_test(
12925      ".foo { transition-timing-function: ease-in }",
12926      ".foo{transition-timing-function:ease-in}",
12927    );
12928    minify_test(
12929      ".foo { transition-timing-function: ease-out }",
12930      ".foo{transition-timing-function:ease-out}",
12931    );
12932    minify_test(
12933      ".foo { transition-timing-function: ease-in-out }",
12934      ".foo{transition-timing-function:ease-in-out}",
12935    );
12936    minify_test(
12937      ".foo { transition-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1) }",
12938      ".foo{transition-timing-function:ease}",
12939    );
12940    minify_test(
12941      ".foo { transition-timing-function: cubic-bezier(0.42, 0, 1, 1) }",
12942      ".foo{transition-timing-function:ease-in}",
12943    );
12944    minify_test(
12945      ".foo { transition-timing-function: cubic-bezier(0, 0, 0.58, 1) }",
12946      ".foo{transition-timing-function:ease-out}",
12947    );
12948    minify_test(
12949      ".foo { transition-timing-function: cubic-bezier(0.42, 0, 0.58, 1) }",
12950      ".foo{transition-timing-function:ease-in-out}",
12951    );
12952    minify_test(
12953      ".foo { transition-timing-function: cubic-bezier(0.58, 0.2, 0.11, 1.2) }",
12954      ".foo{transition-timing-function:cubic-bezier(.58,.2,.11,1.2)}",
12955    );
12956    minify_test(
12957      ".foo { transition-timing-function: step-start }",
12958      ".foo{transition-timing-function:step-start}",
12959    );
12960    minify_test(
12961      ".foo { transition-timing-function: step-end }",
12962      ".foo{transition-timing-function:step-end}",
12963    );
12964    minify_test(
12965      ".foo { transition-timing-function: steps(1, start) }",
12966      ".foo{transition-timing-function:step-start}",
12967    );
12968    minify_test(
12969      ".foo { transition-timing-function: steps(1, jump-start) }",
12970      ".foo{transition-timing-function:step-start}",
12971    );
12972    minify_test(
12973      ".foo { transition-timing-function: steps(1, end) }",
12974      ".foo{transition-timing-function:step-end}",
12975    );
12976    minify_test(
12977      ".foo { transition-timing-function: steps(1, jump-end) }",
12978      ".foo{transition-timing-function:step-end}",
12979    );
12980    minify_test(
12981      ".foo { transition-timing-function: steps(5, jump-start) }",
12982      ".foo{transition-timing-function:steps(5,start)}",
12983    );
12984    minify_test(
12985      ".foo { transition-timing-function: steps(5, jump-end) }",
12986      ".foo{transition-timing-function:steps(5,end)}",
12987    );
12988    minify_test(
12989      ".foo { transition-timing-function: steps(5, jump-both) }",
12990      ".foo{transition-timing-function:steps(5,jump-both)}",
12991    );
12992    minify_test(
12993      ".foo { transition-timing-function: ease-in-out, cubic-bezier(0.42, 0, 1, 1) }",
12994      ".foo{transition-timing-function:ease-in-out,ease-in}",
12995    );
12996    minify_test(
12997      ".foo { transition-timing-function: cubic-bezier(0.42, 0, 1, 1), cubic-bezier(0.58, 0.2, 0.11, 1.2) }",
12998      ".foo{transition-timing-function:ease-in,cubic-bezier(.58,.2,.11,1.2)}",
12999    );
13000    minify_test(
13001      ".foo { transition-timing-function: step-start, steps(5, jump-start) }",
13002      ".foo{transition-timing-function:step-start,steps(5,start)}",
13003    );
13004    minify_test(".foo { transition: width 2s ease }", ".foo{transition:width 2s}");
13005    minify_test(
13006      ".foo { transition: width 2s ease, height 1000ms cubic-bezier(0.25, 0.1, 0.25, 1) }",
13007      ".foo{transition:width 2s,height 1s}",
13008    );
13009    minify_test(".foo { transition: width 2s 1s }", ".foo{transition:width 2s 1s}");
13010    minify_test(".foo { transition: width 2s ease 1s }", ".foo{transition:width 2s 1s}");
13011    minify_test(
13012      ".foo { transition: ease-in 1s width 4s }",
13013      ".foo{transition:width 1s ease-in 4s}",
13014    );
13015    minify_test(".foo { transition: opacity 0s .6s }", ".foo{transition:opacity 0s .6s}");
13016    test(
13017      r#"
13018      .foo {
13019        transition-property: opacity;
13020        transition-duration: 0.09s;
13021        transition-timing-function: ease-in-out;
13022        transition-delay: 500ms;
13023      }
13024    "#,
13025      indoc! {r#"
13026      .foo {
13027        transition: opacity 90ms ease-in-out .5s;
13028      }
13029    "#},
13030    );
13031    test(
13032      r#"
13033      .foo {
13034        transition: opacity 2s;
13035        transition-timing-function: ease;
13036        transition-delay: 500ms;
13037      }
13038    "#,
13039      indoc! {r#"
13040      .foo {
13041        transition: opacity 2s .5s;
13042      }
13043    "#},
13044    );
13045    test(
13046      r#"
13047      .foo {
13048        transition: opacity 500ms;
13049        transition-timing-function: var(--ease);
13050      }
13051    "#,
13052      indoc! {r#"
13053      .foo {
13054        transition: opacity .5s;
13055        transition-timing-function: var(--ease);
13056      }
13057    "#},
13058    );
13059    test(
13060      r#"
13061      .foo {
13062        transition-property: opacity;
13063        transition-duration: 0.09s;
13064        transition-timing-function: ease-in-out;
13065        transition-delay: 500ms;
13066        transition: color 2s;
13067      }
13068    "#,
13069      indoc! {r#"
13070      .foo {
13071        transition: color 2s;
13072      }
13073    "#},
13074    );
13075    test(
13076      r#"
13077      .foo {
13078        transition-property: opacity, color;
13079        transition-duration: 2s, 4s;
13080        transition-timing-function: ease-in-out, ease-in;
13081        transition-delay: 500ms, 0s;
13082      }
13083    "#,
13084      indoc! {r#"
13085      .foo {
13086        transition: opacity 2s ease-in-out .5s, color 4s ease-in;
13087      }
13088    "#},
13089    );
13090    test(
13091      r#"
13092      .foo {
13093        transition-property: opacity, color;
13094        transition-duration: 2s;
13095        transition-timing-function: ease-in-out;
13096        transition-delay: 500ms;
13097      }
13098    "#,
13099      indoc! {r#"
13100      .foo {
13101        transition: opacity 2s ease-in-out .5s, color 2s ease-in-out .5s;
13102      }
13103    "#},
13104    );
13105    test(
13106      r#"
13107      .foo {
13108        transition-property: opacity, color, width, height;
13109        transition-duration: 2s, 4s;
13110        transition-timing-function: ease;
13111        transition-delay: 0s;
13112      }
13113    "#,
13114      indoc! {r#"
13115      .foo {
13116        transition: opacity 2s, color 4s, width 2s, height 4s;
13117      }
13118    "#},
13119    );
13120
13121    test(
13122      r#"
13123      .foo {
13124        -webkit-transition-property: opacity, color;
13125        -webkit-transition-duration: 2s, 4s;
13126        -webkit-transition-timing-function: ease-in-out, ease-in;
13127        -webkit-transition-delay: 500ms, 0s;
13128      }
13129    "#,
13130      indoc! {r#"
13131      .foo {
13132        -webkit-transition: opacity 2s ease-in-out .5s, color 4s ease-in;
13133      }
13134    "#},
13135    );
13136
13137    test(
13138      r#"
13139      .foo {
13140        -webkit-transition-property: opacity, color;
13141        -webkit-transition-duration: 2s, 4s;
13142        -webkit-transition-timing-function: ease-in-out, ease-in;
13143        -webkit-transition-delay: 500ms, 0s;
13144        -moz-transition-property: opacity, color;
13145        -moz-transition-duration: 2s, 4s;
13146        -moz-transition-timing-function: ease-in-out, ease-in;
13147        -moz-transition-delay: 500ms, 0s;
13148        transition-property: opacity, color;
13149        transition-duration: 2s, 4s;
13150        transition-timing-function: ease-in-out, ease-in;
13151        transition-delay: 500ms, 0s;
13152      }
13153    "#,
13154      indoc! {r#"
13155      .foo {
13156        -webkit-transition: opacity 2s ease-in-out .5s, color 4s ease-in;
13157        -moz-transition: opacity 2s ease-in-out .5s, color 4s ease-in;
13158        transition: opacity 2s ease-in-out .5s, color 4s ease-in;
13159      }
13160    "#},
13161    );
13162
13163    test(
13164      r#"
13165      .foo {
13166        -webkit-transition-property: opacity, color;
13167        -moz-transition-property: opacity, color;
13168        transition-property: opacity, color;
13169        -webkit-transition-duration: 2s, 4s;
13170        -moz-transition-duration: 2s, 4s;
13171        transition-duration: 2s, 4s;
13172        -webkit-transition-timing-function: ease-in-out, ease-in;
13173        transition-timing-function: ease-in-out, ease-in;
13174        -moz-transition-timing-function: ease-in-out, ease-in;
13175        -webkit-transition-delay: 500ms, 0s;
13176        -moz-transition-delay: 500ms, 0s;
13177        transition-delay: 500ms, 0s;
13178      }
13179    "#,
13180      indoc! {r#"
13181      .foo {
13182        -webkit-transition: opacity 2s ease-in-out .5s, color 4s ease-in;
13183        -moz-transition: opacity 2s ease-in-out .5s, color 4s ease-in;
13184        transition: opacity 2s ease-in-out .5s, color 4s ease-in;
13185      }
13186    "#},
13187    );
13188
13189    test(
13190      r#"
13191      .foo {
13192        -webkit-transition-property: opacity;
13193        -moz-transition-property: color;
13194        transition-property: opacity, color;
13195        -webkit-transition-duration: 2s;
13196        -moz-transition-duration: 4s;
13197        transition-duration: 2s, 4s;
13198        -webkit-transition-timing-function: ease-in-out;
13199        -moz-transition-timing-function: ease-in-out;
13200        transition-timing-function: ease-in-out, ease-in;
13201        -webkit-transition-delay: 500ms;
13202        -moz-transition-delay: 0s;
13203        transition-delay: 500ms, 0s;
13204      }
13205    "#,
13206      indoc! {r#"
13207      .foo {
13208        -webkit-transition-property: opacity;
13209        -moz-transition-property: color;
13210        transition-property: opacity, color;
13211        -webkit-transition-duration: 2s;
13212        -moz-transition-duration: 4s;
13213        transition-duration: 2s, 4s;
13214        -webkit-transition-timing-function: ease-in-out;
13215        -moz-transition-timing-function: ease-in-out;
13216        -webkit-transition-delay: .5s;
13217        transition-timing-function: ease-in-out, ease-in;
13218        -moz-transition-delay: 0s;
13219        transition-delay: .5s, 0s;
13220      }
13221    "#},
13222    );
13223
13224    test(
13225      r#"
13226      .foo {
13227        -webkit-transition-property: opacity;
13228        transition-property: opacity, color;
13229        -moz-transition-property: color;
13230        -webkit-transition-duration: 2s;
13231        transition-duration: 2s, 4s;
13232        -moz-transition-duration: 4s;
13233        -webkit-transition-timing-function: ease-in-out;
13234        transition-timing-function: ease-in-out, ease-in;
13235        -moz-transition-timing-function: ease-in-out;
13236        -webkit-transition-delay: 500ms;
13237        transition-delay: 500ms, 0s;
13238        -moz-transition-delay: 0s;
13239      }
13240    "#,
13241      indoc! {r#"
13242      .foo {
13243        -webkit-transition-property: opacity;
13244        transition-property: opacity, color;
13245        -moz-transition-property: color;
13246        -webkit-transition-duration: 2s;
13247        transition-duration: 2s, 4s;
13248        -moz-transition-duration: 4s;
13249        -webkit-transition-timing-function: ease-in-out;
13250        transition-timing-function: ease-in-out, ease-in;
13251        -webkit-transition-delay: .5s;
13252        -moz-transition-timing-function: ease-in-out;
13253        transition-delay: .5s, 0s;
13254        -moz-transition-delay: 0s;
13255      }
13256    "#},
13257    );
13258
13259    test(
13260      r#"
13261      .foo {
13262        transition: opacity 2s;
13263        -webkit-transition-duration: 2s;
13264      }
13265    "#,
13266      indoc! {r#"
13267      .foo {
13268        transition: opacity 2s;
13269        -webkit-transition-duration: 2s;
13270      }
13271    "#},
13272    );
13273
13274    prefix_test(
13275      r#"
13276      .foo {
13277        transition-property: margin-inline-start;
13278      }
13279    "#,
13280      indoc! {r#"
13281      .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))) {
13282        transition-property: margin-left;
13283      }
13284
13285      .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))) {
13286        transition-property: margin-left;
13287      }
13288
13289      .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)) {
13290        transition-property: margin-right;
13291      }
13292
13293      .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)) {
13294        transition-property: margin-right;
13295      }
13296    "#
13297      },
13298      Browsers {
13299        safari: Some(8 << 16),
13300        ..Browsers::default()
13301      },
13302    );
13303
13304    prefix_test(
13305      r#"
13306      .foo {
13307        transition-property: margin-inline-start, padding-inline-start;
13308      }
13309    "#,
13310      indoc! {r#"
13311      .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))) {
13312        transition-property: margin-left, padding-left;
13313      }
13314
13315      .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))) {
13316        transition-property: margin-left, padding-left;
13317      }
13318
13319      .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)) {
13320        transition-property: margin-right, padding-right;
13321      }
13322
13323      .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)) {
13324        transition-property: margin-right, padding-right;
13325      }
13326    "#
13327      },
13328      Browsers {
13329        safari: Some(8 << 16),
13330        ..Browsers::default()
13331      },
13332    );
13333
13334    prefix_test(
13335      r#"
13336      .foo {
13337        transition-property: margin-inline-start, opacity, padding-inline-start, color;
13338      }
13339    "#,
13340      indoc! {r#"
13341      .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))) {
13342        transition-property: margin-left, opacity, padding-left, color;
13343      }
13344
13345      .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))) {
13346        transition-property: margin-left, opacity, padding-left, color;
13347      }
13348
13349      .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)) {
13350        transition-property: margin-right, opacity, padding-right, color;
13351      }
13352
13353      .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)) {
13354        transition-property: margin-right, opacity, padding-right, color;
13355      }
13356    "#
13357      },
13358      Browsers {
13359        safari: Some(8 << 16),
13360        ..Browsers::default()
13361      },
13362    );
13363
13364    prefix_test(
13365      r#"
13366      .foo {
13367        transition-property: margin-block;
13368      }
13369    "#,
13370      indoc! {r#"
13371      .foo {
13372        transition-property: margin-top, margin-bottom;
13373      }
13374    "#
13375      },
13376      Browsers {
13377        safari: Some(8 << 16),
13378        ..Browsers::default()
13379      },
13380    );
13381
13382    prefix_test(
13383      r#"
13384      .foo {
13385        transition: margin-inline-start 2s;
13386      }
13387    "#,
13388      indoc! {r#"
13389      .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))) {
13390        transition: margin-left 2s;
13391      }
13392
13393      .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))) {
13394        transition: margin-left 2s;
13395      }
13396
13397      .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)) {
13398        transition: margin-right 2s;
13399      }
13400
13401      .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)) {
13402        transition: margin-right 2s;
13403      }
13404    "#
13405      },
13406      Browsers {
13407        safari: Some(8 << 16),
13408        ..Browsers::default()
13409      },
13410    );
13411
13412    prefix_test(
13413      r#"
13414      .foo {
13415        transition: margin-inline-start 2s, padding-inline-start 2s;
13416      }
13417    "#,
13418      indoc! {r#"
13419      .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))) {
13420        transition: margin-left 2s, padding-left 2s;
13421      }
13422
13423      .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))) {
13424        transition: margin-left 2s, padding-left 2s;
13425      }
13426
13427      .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)) {
13428        transition: margin-right 2s, padding-right 2s;
13429      }
13430
13431      .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)) {
13432        transition: margin-right 2s, padding-right 2s;
13433      }
13434    "#
13435      },
13436      Browsers {
13437        safari: Some(8 << 16),
13438        ..Browsers::default()
13439      },
13440    );
13441
13442    prefix_test(
13443      r#"
13444      .foo {
13445        transition: margin-block-start 2s;
13446      }
13447    "#,
13448      indoc! {r#"
13449      .foo {
13450        transition: margin-top 2s;
13451      }
13452    "#
13453      },
13454      Browsers {
13455        safari: Some(8 << 16),
13456        ..Browsers::default()
13457      },
13458    );
13459
13460    prefix_test(
13461      r#"
13462      .foo {
13463        transition: transform;
13464      }
13465    "#,
13466      indoc! {r#"
13467      .foo {
13468        -webkit-transition: -webkit-transform, transform;
13469        transition: -webkit-transform, transform;
13470      }
13471    "#
13472      },
13473      Browsers {
13474        safari: Some(6 << 16),
13475        ..Browsers::default()
13476      },
13477    );
13478
13479    prefix_test(
13480      r#"
13481      .foo {
13482        transition: border-start-start-radius;
13483      }
13484    "#,
13485      indoc! {r#"
13486      .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))) {
13487        -webkit-transition: -webkit-border-top-left-radius, border-top-left-radius;
13488        transition: -webkit-border-top-left-radius, border-top-left-radius;
13489      }
13490
13491      .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)) {
13492        -webkit-transition: -webkit-border-top-right-radius, border-top-right-radius;
13493        transition: -webkit-border-top-right-radius, border-top-right-radius;
13494      }
13495    "#
13496      },
13497      Browsers {
13498        safari: Some(4 << 16),
13499        ..Browsers::default()
13500      },
13501    );
13502
13503    prefix_test(
13504      r#"
13505      .foo {
13506        transition: border-start-start-radius;
13507      }
13508    "#,
13509      indoc! {r#"
13510      .foo:not(:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi)) {
13511        transition: border-top-left-radius;
13512      }
13513
13514      .foo:lang(ae, ar, arc, bcc, bqi, ckb, dv, fa, glk, he, ku, mzn, nqo, pnb, ps, sd, ug, ur, yi) {
13515        transition: border-top-right-radius;
13516      }
13517    "#
13518      },
13519      Browsers {
13520        safari: Some(12 << 16),
13521        ..Browsers::default()
13522      },
13523    );
13524
13525    test(
13526      r#"
13527      .foo {
13528        -webkit-transition: background 200ms;
13529        -moz-transition: background 200ms;
13530        transition: background 230ms;
13531      }
13532    "#,
13533      indoc! {r#"
13534      .foo {
13535        -webkit-transition: background .2s;
13536        -moz-transition: background .2s;
13537        transition: background .23s;
13538      }
13539    "#},
13540    );
13541
13542    prefix_test(
13543      r#"
13544      .foo {
13545        -webkit-transition: background 200ms;
13546        -moz-transition: background 200ms;
13547        transition: background 230ms;
13548      }
13549    "#,
13550      indoc! {r#"
13551      .foo {
13552        -webkit-transition: background .2s;
13553        -moz-transition: background .2s;
13554        transition: background .23s;
13555      }
13556    "#},
13557      Browsers {
13558        chrome: Some(95 << 16),
13559        ..Browsers::default()
13560      },
13561    );
13562    prefix_test(
13563      r#"
13564       .foo {
13565         transition-property: -webkit-backdrop-filter, backdrop-filter;
13566       }
13567       .bar {
13568         transition-property: backdrop-filter;
13569       }
13570       .baz {
13571         transition-property: -webkit-backdrop-filter;
13572       }
13573     "#,
13574      indoc! {r#"
13575       .foo, .bar {
13576         transition-property: -webkit-backdrop-filter, backdrop-filter;
13577       }
13578
13579       .baz {
13580         transition-property: -webkit-backdrop-filter;
13581       }
13582     "#
13583      },
13584      Browsers {
13585        safari: Some(15 << 16),
13586        ..Browsers::default()
13587      },
13588    );
13589    prefix_test(
13590      r#"
13591       .foo {
13592         transition-property: -webkit-border-radius, -webkit-border-radius, -moz-border-radius;
13593       }
13594     "#,
13595      indoc! {r#"
13596       .foo {
13597         transition-property: -webkit-border-radius, -moz-border-radius;
13598       }
13599     "#
13600      },
13601      Browsers {
13602        safari: Some(15 << 16),
13603        ..Browsers::default()
13604      },
13605    );
13606    prefix_test(
13607      r#"
13608       .foo {
13609         transition: -webkit-backdrop-filter, backdrop-filter;
13610       }
13611       .bar {
13612         transition: backdrop-filter;
13613       }
13614       .baz {
13615         transition: -webkit-backdrop-filter;
13616       }
13617     "#,
13618      indoc! {r#"
13619       .foo, .bar {
13620         transition: -webkit-backdrop-filter, backdrop-filter;
13621       }
13622
13623       .baz {
13624         transition: -webkit-backdrop-filter;
13625       }
13626     "#
13627      },
13628      Browsers {
13629        safari: Some(15 << 16),
13630        ..Browsers::default()
13631      },
13632    );
13633  }
13634
13635  #[test]
13636  fn test_animation() {
13637    property_range_test(&["animation-delay"], &[("-1s", Some("-1s"))]);
13638    property_range_test(
13639      &["animation"],
13640      &[
13641        ("test -1s", None),
13642        ("test 1s -1s", Some("1s -1s test")),
13643        ("test 1s -1", None),
13644      ],
13645    );
13646    property_range_test(
13647      &["animation-iteration-count"],
13648      &[("-1", None), ("calc(1 - 2)", Some("0")), ("calc(-1 + 2)", Some("1"))],
13649    );
13650    property_range_test(&["animation-duration"], &[("-1s", None), ("calc(-1s)", Some("0s"))]);
13651    minify_test(".foo { animation-name: test }", ".foo{animation-name:test}");
13652    minify_test(".foo { animation-name: \"test\" }", ".foo{animation-name:test}");
13653    minify_test(".foo { animation-name: foo, bar }", ".foo{animation-name:foo,bar}");
13654    minify_test(".foo { animation-name: \"none\" }", ".foo{animation-name:\"none\"}");
13655    minify_test(
13656      ".foo { animation-name: \"none\", foo }",
13657      ".foo{animation-name:\"none\",foo}",
13658    );
13659    let name = crate::properties::animation::AnimationName::parse_string("default");
13660    assert!(matches!(name, Err(..)));
13661
13662    minify_test(".foo { animation-name: none }", ".foo{animation-name:none}");
13663    minify_test(".foo { animation-name: none, none }", ".foo{animation-name:none,none}");
13664
13665    // Test CSS-wide keywords
13666    minify_test(".foo { animation-name: unset }", ".foo{animation-name:unset}");
13667    minify_test(".foo { animation-name: \"unset\" }", ".foo{animation-name:\"unset\"}");
13668    minify_test(".foo { animation-name: \"revert\" }", ".foo{animation-name:\"revert\"}");
13669    minify_test(
13670      ".foo { animation-name: \"unset\", \"revert\"}",
13671      ".foo{animation-name:\"unset\",\"revert\"}",
13672    );
13673    minify_test(
13674      ".foo { animation-name: foo, \"revert\"}",
13675      ".foo{animation-name:foo,\"revert\"}",
13676    );
13677    minify_test(
13678      ".foo { animation-name: \"string\", \"revert\"}",
13679      ".foo{animation-name:string,\"revert\"}",
13680    );
13681    minify_test(
13682      ".foo { animation-name: \"string\", foo, \"revert\"}",
13683      ".foo{animation-name:string,foo,\"revert\"}",
13684    );
13685    minify_test(
13686      ".foo { animation-name: \"default\" }",
13687      ".foo{animation-name:\"default\"}",
13688    );
13689    minify_test(".foo { animation-duration: 100ms }", ".foo{animation-duration:.1s}");
13690    minify_test(
13691      ".foo { animation-duration: 100ms, 2000ms }",
13692      ".foo{animation-duration:.1s,2s}",
13693    );
13694    minify_test(
13695      ".foo { animation-timing-function: ease }",
13696      ".foo{animation-timing-function:ease}",
13697    );
13698    minify_test(
13699      ".foo { animation-timing-function: cubic-bezier(0.42, 0, 1, 1) }",
13700      ".foo{animation-timing-function:ease-in}",
13701    );
13702    minify_test(
13703      ".foo { animation-timing-function: ease, cubic-bezier(0.42, 0, 1, 1) }",
13704      ".foo{animation-timing-function:ease,ease-in}",
13705    );
13706    minify_test(
13707      ".foo { animation-iteration-count: 5 }",
13708      ".foo{animation-iteration-count:5}",
13709    );
13710    minify_test(
13711      ".foo { animation-iteration-count: 2.5 }",
13712      ".foo{animation-iteration-count:2.5}",
13713    );
13714    minify_test(
13715      ".foo { animation-iteration-count: 2.0 }",
13716      ".foo{animation-iteration-count:2}",
13717    );
13718    minify_test(
13719      ".foo { animation-iteration-count: infinite }",
13720      ".foo{animation-iteration-count:infinite}",
13721    );
13722    minify_test(
13723      ".foo { animation-iteration-count: 1, infinite }",
13724      ".foo{animation-iteration-count:1,infinite}",
13725    );
13726    minify_test(
13727      ".foo { animation-direction: reverse }",
13728      ".foo{animation-direction:reverse}",
13729    );
13730    minify_test(
13731      ".foo { animation-direction: alternate, reverse }",
13732      ".foo{animation-direction:alternate,reverse}",
13733    );
13734    minify_test(
13735      ".foo { animation-play-state: paused }",
13736      ".foo{animation-play-state:paused}",
13737    );
13738    minify_test(
13739      ".foo { animation-play-state: running, paused }",
13740      ".foo{animation-play-state:running,paused}",
13741    );
13742    minify_test(".foo { animation-delay: 100ms }", ".foo{animation-delay:.1s}");
13743    minify_test(
13744      ".foo { animation-delay: 100ms, 2000ms }",
13745      ".foo{animation-delay:.1s,2s}",
13746    );
13747    minify_test(
13748      ".foo { animation-fill-mode: forwards }",
13749      ".foo{animation-fill-mode:forwards}",
13750    );
13751    minify_test(
13752      ".foo { animation-fill-mode: Backwards,forwards }",
13753      ".foo{animation-fill-mode:backwards,forwards}",
13754    );
13755    minify_test(".foo { animation: none }", ".foo{animation:none}");
13756    minify_test(".foo { animation: \"none\" }", ".foo{animation:\"none\"}");
13757    minify_test(".foo { animation: \"None\" }", ".foo{animation:\"None\"}");
13758    minify_test(".foo { animation: \"none\", none }", ".foo{animation:\"none\",none}");
13759    minify_test(".foo { animation: none, none }", ".foo{animation:none,none}");
13760    minify_test(".foo { animation: \"none\" none }", ".foo{animation:\"none\"}");
13761    minify_test(".foo { animation: none none }", ".foo{animation:none}");
13762
13763    // Test animation-name + animation-fill-mode
13764    minify_test(
13765      ".foo { animation: 2s both \"none\"}",
13766      ".foo{animation:2s both \"none\"}",
13767    );
13768    minify_test(
13769      ".foo { animation: both \"none\" 2s}",
13770      ".foo{animation:2s both \"none\"}",
13771    );
13772    minify_test(".foo { animation: \"none\" 2s none}", ".foo{animation:2s \"none\"}");
13773    minify_test(".foo { animation: none \"none\" 2s}", ".foo{animation:2s \"none\"}");
13774    minify_test(
13775      ".foo { animation: none, \"none\" 2s forwards}",
13776      ".foo{animation:none,2s forwards \"none\"}",
13777    );
13778
13779    minify_test(".foo { animation: \"unset\" }", ".foo{animation:\"unset\"}");
13780    minify_test(".foo { animation: \"string\" .5s }", ".foo{animation:.5s string}");
13781    minify_test(".foo { animation: \"unset\" .5s }", ".foo{animation:.5s \"unset\"}");
13782    minify_test(
13783      ".foo { animation: none, \"unset\" .5s}",
13784      ".foo{animation:none,.5s \"unset\"}",
13785    );
13786    minify_test(
13787      ".foo { animation: \"unset\" 0s 3s infinite, none }",
13788      ".foo{animation:0s 3s infinite \"unset\",none}",
13789    );
13790
13791    minify_test(".foo { animation: \"infinite\" 2s 1 }", ".foo{animation:2s 1 infinite}");
13792    minify_test(".foo { animation: \"paused\" 2s }", ".foo{animation:2s running paused}");
13793    minify_test(
13794      ".foo { animation: \"forwards\" 2s }",
13795      ".foo{animation:2s none forwards}",
13796    );
13797    minify_test(
13798      ".foo { animation: \"reverse\" 2s }",
13799      ".foo{animation:2s normal reverse}",
13800    );
13801    minify_test(
13802      ".foo { animation: \"reverse\" 2s alternate }",
13803      ".foo{animation:2s alternate reverse}",
13804    );
13805
13806    minify_test(
13807      ".foo { animation: 3s ease-in 1s infinite reverse both running slidein }",
13808      ".foo{animation:3s ease-in 1s infinite reverse both slidein}",
13809    );
13810    minify_test(
13811      ".foo { animation: 3s slidein paused ease 1s 1 reverse both }",
13812      ".foo{animation:3s 1s reverse both paused slidein}",
13813    );
13814    minify_test(".foo { animation: 3s ease ease }", ".foo{animation:3s ease ease}");
13815    minify_test(
13816      ".foo { animation: 3s cubic-bezier(0.25, 0.1, 0.25, 1) foo }",
13817      ".foo{animation:3s foo}",
13818    );
13819    minify_test(
13820      ".foo { animation: foo 0s 3s infinite }",
13821      ".foo{animation:0s 3s infinite foo}",
13822    );
13823    minify_test(".foo { animation: foo 3s --test }", ".foo{animation:3s foo --test}");
13824    minify_test(".foo { animation: foo 3s scroll() }", ".foo{animation:3s foo scroll()}");
13825    minify_test(
13826      ".foo { animation: foo 3s scroll(block) }",
13827      ".foo{animation:3s foo scroll()}",
13828    );
13829    minify_test(
13830      ".foo { animation: foo 3s scroll(root inline) }",
13831      ".foo{animation:3s foo scroll(root inline)}",
13832    );
13833    minify_test(
13834      ".foo { animation: foo 3s scroll(inline root) }",
13835      ".foo{animation:3s foo scroll(root inline)}",
13836    );
13837    minify_test(
13838      ".foo { animation: foo 3s scroll(inline nearest) }",
13839      ".foo{animation:3s foo scroll(inline)}",
13840    );
13841    minify_test(
13842      ".foo { animation: foo 3s view(block) }",
13843      ".foo{animation:3s foo view()}",
13844    );
13845    minify_test(
13846      ".foo { animation: foo 3s view(inline) }",
13847      ".foo{animation:3s foo view(inline)}",
13848    );
13849    minify_test(
13850      ".foo { animation: foo 3s view(inline 10px 10px) }",
13851      ".foo{animation:3s foo view(inline 10px)}",
13852    );
13853    minify_test(
13854      ".foo { animation: foo 3s view(inline 10px 12px) }",
13855      ".foo{animation:3s foo view(inline 10px 12px)}",
13856    );
13857    minify_test(
13858      ".foo { animation: foo 3s view(inline auto auto) }",
13859      ".foo{animation:3s foo view(inline)}",
13860    );
13861    minify_test(".foo { animation: foo 3s auto }", ".foo{animation:3s foo}");
13862    minify_test(".foo { animation-composition: add }", ".foo{animation-composition:add}");
13863    test(
13864      r#"
13865      .foo {
13866        animation-name: foo;
13867        animation-duration: 0.09s;
13868        animation-timing-function: ease-in-out;
13869        animation-iteration-count: 2;
13870        animation-direction: alternate;
13871        animation-play-state: running;
13872        animation-delay: 100ms;
13873        animation-fill-mode: forwards;
13874        animation-timeline: auto;
13875      }
13876    "#,
13877      indoc! {r#"
13878      .foo {
13879        animation: 90ms ease-in-out .1s 2 alternate forwards foo;
13880      }
13881    "#},
13882    );
13883    test(
13884      r#"
13885      .foo {
13886        animation-name: foo, bar;
13887        animation-duration: 0.09s, 200ms;
13888        animation-timing-function: ease-in-out, ease;
13889        animation-iteration-count: 2, 1;
13890        animation-direction: alternate, normal;
13891        animation-play-state: running, paused;
13892        animation-delay: 100ms, 0s;
13893        animation-fill-mode: forwards, none;
13894        animation-timeline: auto, auto;
13895      }
13896    "#,
13897      indoc! {r#"
13898      .foo {
13899        animation: 90ms ease-in-out .1s 2 alternate forwards foo, .2s paused bar;
13900      }
13901    "#},
13902    );
13903    test(
13904      r#"
13905      .foo {
13906        animation: bar 200ms;
13907        animation-timing-function: ease-in-out;
13908      }
13909    "#,
13910      indoc! {r#"
13911      .foo {
13912        animation: .2s ease-in-out bar;
13913      }
13914    "#},
13915    );
13916    test(
13917      r#"
13918      .foo {
13919        animation: bar 200ms;
13920        animation-timing-function: var(--ease);
13921      }
13922    "#,
13923      indoc! {r#"
13924      .foo {
13925        animation: .2s bar;
13926        animation-timing-function: var(--ease);
13927      }
13928    "#},
13929    );
13930    test(
13931      r#"
13932      .foo {
13933        animation-name: foo, bar;
13934        animation-duration: 0.09s;
13935        animation-timing-function: ease-in-out;
13936        animation-iteration-count: 2;
13937        animation-direction: alternate;
13938        animation-play-state: running;
13939        animation-delay: 100ms;
13940        animation-fill-mode: forwards;
13941        animation-timeline: auto;
13942      }
13943    "#,
13944      indoc! {r#"
13945      .foo {
13946        animation-name: foo, bar;
13947        animation-duration: 90ms;
13948        animation-timing-function: ease-in-out;
13949        animation-iteration-count: 2;
13950        animation-direction: alternate;
13951        animation-play-state: running;
13952        animation-delay: .1s;
13953        animation-fill-mode: forwards;
13954        animation-timeline: auto;
13955      }
13956    "#},
13957    );
13958    test(
13959      r#"
13960      .foo {
13961        animation-name: foo;
13962        animation-duration: 0.09s;
13963        animation-timing-function: ease-in-out;
13964        animation-iteration-count: 2;
13965        animation-direction: alternate;
13966        animation-play-state: running;
13967        animation-delay: 100ms;
13968        animation-fill-mode: forwards;
13969        animation-timeline: scroll();
13970      }
13971    "#,
13972      indoc! {r#"
13973      .foo {
13974        animation: 90ms ease-in-out .1s 2 alternate forwards foo scroll();
13975      }
13976    "#},
13977    );
13978    test(
13979      r#"
13980      .foo {
13981        animation-name: foo;
13982        animation-duration: 0.09s;
13983        animation-timing-function: ease-in-out;
13984        animation-iteration-count: 2;
13985        animation-direction: alternate;
13986        animation-play-state: running;
13987        animation-delay: 100ms;
13988        animation-fill-mode: forwards;
13989        animation-timeline: scroll(), view();
13990      }
13991    "#,
13992      indoc! {r#"
13993      .foo {
13994        animation-name: foo;
13995        animation-duration: 90ms;
13996        animation-timing-function: ease-in-out;
13997        animation-iteration-count: 2;
13998        animation-direction: alternate;
13999        animation-play-state: running;
14000        animation-delay: .1s;
14001        animation-fill-mode: forwards;
14002        animation-timeline: scroll(), view();
14003      }
14004    "#},
14005    );
14006    test(
14007      r#"
14008      .foo {
14009        -webkit-animation-name: foo;
14010        -webkit-animation-duration: 0.09s;
14011        -webkit-animation-timing-function: ease-in-out;
14012        -webkit-animation-iteration-count: 2;
14013        -webkit-animation-direction: alternate;
14014        -webkit-animation-play-state: running;
14015        -webkit-animation-delay: 100ms;
14016        -webkit-animation-fill-mode: forwards;
14017      }
14018    "#,
14019      indoc! {r#"
14020      .foo {
14021        -webkit-animation: 90ms ease-in-out .1s 2 alternate forwards foo;
14022      }
14023    "#},
14024    );
14025    test(
14026      r#"
14027      .foo {
14028        -moz-animation: bar 200ms;
14029        -moz-animation-timing-function: ease-in-out;
14030      }
14031    "#,
14032      indoc! {r#"
14033      .foo {
14034        -moz-animation: .2s ease-in-out bar;
14035      }
14036    "#},
14037    );
14038    test(
14039      r#"
14040      .foo {
14041        -webkit-animation: bar 200ms;
14042        -webkit-animation-timing-function: ease-in-out;
14043        -moz-animation: bar 200ms;
14044        -moz-animation-timing-function: ease-in-out;
14045      }
14046    "#,
14047      indoc! {r#"
14048      .foo {
14049        -webkit-animation: .2s ease-in-out bar;
14050        -moz-animation: .2s ease-in-out bar;
14051      }
14052    "#},
14053    );
14054
14055    prefix_test(
14056      r#"
14057      .foo {
14058        animation: .2s ease-in-out bar;
14059      }
14060    "#,
14061      indoc! {r#"
14062      .foo {
14063        -webkit-animation: .2s ease-in-out bar;
14064        -moz-animation: .2s ease-in-out bar;
14065        animation: .2s ease-in-out bar;
14066      }
14067    "#},
14068      Browsers {
14069        firefox: Some(6 << 16),
14070        safari: Some(6 << 16),
14071        ..Browsers::default()
14072      },
14073    );
14074
14075    prefix_test(
14076      r#"
14077      .foo {
14078        -webkit-animation: .2s ease-in-out bar;
14079        -moz-animation: .2s ease-in-out bar;
14080        animation: .2s ease-in-out bar;
14081      }
14082    "#,
14083      indoc! {r#"
14084      .foo {
14085        animation: .2s ease-in-out bar;
14086      }
14087    "#},
14088      Browsers {
14089        firefox: Some(20 << 16),
14090        safari: Some(14 << 16),
14091        ..Browsers::default()
14092      },
14093    );
14094    prefix_test(
14095      r#"
14096      .foo {
14097        animation: 200ms var(--ease) bar;
14098      }
14099    "#,
14100      indoc! {r#"
14101      .foo {
14102        -webkit-animation: .2s var(--ease) bar;
14103        -moz-animation: .2s var(--ease) bar;
14104        animation: .2s var(--ease) bar;
14105      }
14106    "#},
14107      Browsers {
14108        firefox: Some(6 << 16),
14109        safari: Some(6 << 16),
14110        ..Browsers::default()
14111      },
14112    );
14113
14114    prefix_test(
14115      r#"
14116      .foo {
14117        animation: .2s ease-in-out bar scroll();
14118      }
14119    "#,
14120      indoc! {r#"
14121      .foo {
14122        animation: .2s ease-in-out bar;
14123        animation-timeline: scroll();
14124      }
14125    "#},
14126      Browsers {
14127        safari: Some(16 << 16),
14128        ..Browsers::default()
14129      },
14130    );
14131    prefix_test(
14132      r#"
14133      .foo {
14134        animation: .2s ease-in-out bar scroll();
14135      }
14136    "#,
14137      indoc! {r#"
14138      .foo {
14139        animation: .2s ease-in-out bar scroll();
14140      }
14141    "#},
14142      Browsers {
14143        chrome: Some(120 << 16),
14144        ..Browsers::default()
14145      },
14146    );
14147    prefix_test(
14148      r#"
14149      .foo {
14150        animation: .2s ease-in-out bar scroll();
14151      }
14152    "#,
14153      indoc! {r#"
14154      .foo {
14155        -webkit-animation: .2s ease-in-out bar;
14156        animation: .2s ease-in-out bar;
14157        animation-timeline: scroll();
14158      }
14159    "#},
14160      Browsers {
14161        safari: Some(6 << 16),
14162        ..Browsers::default()
14163      },
14164    );
14165
14166    minify_test(
14167      ".foo { animation-range-start: entry 10% }",
14168      ".foo{animation-range-start:entry 10%}",
14169    );
14170    minify_test(
14171      ".foo { animation-range-start: entry 0% }",
14172      ".foo{animation-range-start:entry}",
14173    );
14174    minify_test(
14175      ".foo { animation-range-start: entry }",
14176      ".foo{animation-range-start:entry}",
14177    );
14178    minify_test(".foo { animation-range-start: 50% }", ".foo{animation-range-start:50%}");
14179    minify_test(
14180      ".foo { animation-range-end: exit 10% }",
14181      ".foo{animation-range-end:exit 10%}",
14182    );
14183    minify_test(
14184      ".foo { animation-range-end: exit 100% }",
14185      ".foo{animation-range-end:exit}",
14186    );
14187    minify_test(".foo { animation-range-end: exit }", ".foo{animation-range-end:exit}");
14188    minify_test(".foo { animation-range-end: 50% }", ".foo{animation-range-end:50%}");
14189    minify_test(
14190      ".foo { animation-range: entry 10% exit 90% }",
14191      ".foo{animation-range:entry 10% exit 90%}",
14192    );
14193    minify_test(
14194      ".foo { animation-range: entry 0% exit 100% }",
14195      ".foo{animation-range:entry exit}",
14196    );
14197    minify_test(".foo { animation-range: entry }", ".foo{animation-range:entry}");
14198    minify_test(
14199      ".foo { animation-range: entry 0% entry 100% }",
14200      ".foo{animation-range:entry}",
14201    );
14202    minify_test(".foo { animation-range: 50% normal }", ".foo{animation-range:50%}");
14203    minify_test(
14204      ".foo { animation-range: normal normal }",
14205      ".foo{animation-range:normal}",
14206    );
14207    test(
14208      r#"
14209      .foo {
14210        animation-range-start: entry 10%;
14211        animation-range-end: exit 90%;
14212      }
14213      "#,
14214      indoc! {r#"
14215      .foo {
14216        animation-range: entry 10% exit 90%;
14217      }
14218      "#},
14219    );
14220    test(
14221      r#"
14222      .foo {
14223        animation-range-start: entry 0%;
14224        animation-range-end: entry 100%;
14225      }
14226      "#,
14227      indoc! {r#"
14228      .foo {
14229        animation-range: entry;
14230      }
14231      "#},
14232    );
14233    test(
14234      r#"
14235      .foo {
14236        animation-range-start: entry 0%;
14237        animation-range-end: exit 100%;
14238      }
14239      "#,
14240      indoc! {r#"
14241      .foo {
14242        animation-range: entry exit;
14243      }
14244      "#},
14245    );
14246    test(
14247      r#"
14248      .foo {
14249        animation-range-start: 10%;
14250        animation-range-end: normal;
14251      }
14252      "#,
14253      indoc! {r#"
14254      .foo {
14255        animation-range: 10%;
14256      }
14257      "#},
14258    );
14259    test(
14260      r#"
14261      .foo {
14262        animation-range-start: 10%;
14263        animation-range-end: 90%;
14264      }
14265      "#,
14266      indoc! {r#"
14267      .foo {
14268        animation-range: 10% 90%;
14269      }
14270      "#},
14271    );
14272    test(
14273      r#"
14274      .foo {
14275        animation-range-start: entry 10%;
14276        animation-range-end: exit 100%;
14277      }
14278      "#,
14279      indoc! {r#"
14280      .foo {
14281        animation-range: entry 10% exit;
14282      }
14283      "#},
14284    );
14285    test(
14286      r#"
14287      .foo {
14288        animation-range-start: 10%;
14289        animation-range-end: exit 90%;
14290      }
14291      "#,
14292      indoc! {r#"
14293      .foo {
14294        animation-range: 10% exit 90%;
14295      }
14296      "#},
14297    );
14298    test(
14299      r#"
14300      .foo {
14301        animation-range-start: entry 10%;
14302        animation-range-end: 90%;
14303      }
14304      "#,
14305      indoc! {r#"
14306      .foo {
14307        animation-range: entry 10% 90%;
14308      }
14309      "#},
14310    );
14311    test(
14312      r#"
14313      .foo {
14314        animation-range: entry;
14315        animation-range-end: 90%;
14316      }
14317      "#,
14318      indoc! {r#"
14319      .foo {
14320        animation-range: entry 90%;
14321      }
14322      "#},
14323    );
14324    test(
14325      r#"
14326      .foo {
14327        animation-range: entry;
14328        animation-range-end: var(--end);
14329      }
14330      "#,
14331      indoc! {r#"
14332      .foo {
14333        animation-range: entry;
14334        animation-range-end: var(--end);
14335      }
14336      "#},
14337    );
14338    test(
14339      r#"
14340      .foo {
14341        animation-range-start: entry 10%, entry 50%;
14342        animation-range-end: exit 90%;
14343      }
14344      "#,
14345      indoc! {r#"
14346      .foo {
14347        animation-range-start: entry 10%, entry 50%;
14348        animation-range-end: exit 90%;
14349      }
14350      "#},
14351    );
14352    test(
14353      r#"
14354      .foo {
14355        animation-range-start: entry 10%, entry 50%;
14356        animation-range-end: exit 90%, exit 100%;
14357      }
14358      "#,
14359      indoc! {r#"
14360      .foo {
14361        animation-range: entry 10% exit 90%, entry 50% exit;
14362      }
14363      "#},
14364    );
14365    test(
14366      r#"
14367      .foo {
14368        animation-range: entry;
14369        animation-range-end: 90%;
14370        animation: spin 100ms;
14371      }
14372      "#,
14373      indoc! {r#"
14374      .foo {
14375        animation: .1s spin;
14376      }
14377      "#},
14378    );
14379    test(
14380      r#"
14381      .foo {
14382        animation: spin 100ms;
14383        animation-range: entry;
14384        animation-range-end: 90%;
14385      }
14386      "#,
14387      indoc! {r#"
14388      .foo {
14389        animation: .1s spin;
14390        animation-range: entry 90%;
14391      }
14392      "#},
14393    );
14394    test(
14395      r#"
14396      .foo {
14397        animation-range: entry;
14398        animation-range-end: 90%;
14399        animation: var(--animation) 100ms;
14400      }
14401      "#,
14402      indoc! {r#"
14403      .foo {
14404        animation: var(--animation) .1s;
14405      }
14406      "#},
14407    );
14408  }
14409
14410  #[test]
14411  fn test_transform() {
14412    property_range_test(
14413      &["transform"],
14414      &[
14415        ("perspective(-1px)", None),
14416        ("perspective(calc(-1px))", Some("perspective(0)")),
14417        ("translateX(-1px)", Some("translate(-1px)")),
14418      ],
14419    );
14420    property_range_test(
14421      &["perspective"],
14422      &[
14423        ("-1px", None),
14424        ("calc(1px - 2px)", Some("0")),
14425        ("calc(-1px + 2px)", Some("1px")),
14426      ],
14427    );
14428    test(
14429      ".foo { transform: perspective(500px)translate3d(10px, 0, 20px)rotateY(30deg) }",
14430      indoc! {r#"
14431      .foo {
14432        transform: perspective(500px) translate3d(10px, 0, 20px) rotateY(30deg);
14433      }
14434      "#},
14435    );
14436    test(
14437      ".foo { transform: translate3d(12px,50%,3em)scale(2,.5) }",
14438      indoc! {r#"
14439      .foo {
14440        transform: translate3d(12px, 50%, 3em) scale(2, .5);
14441      }
14442      "#},
14443    );
14444    test(
14445      ".foo { transform:matrix(1,2,-1,1,80,80) }",
14446      indoc! {r#"
14447      .foo {
14448        transform: matrix(1, 2, -1, 1, 80, 80);
14449      }
14450      "#},
14451    );
14452
14453    minify_test(
14454      ".foo { transform: scale(  0.5 )translateX(10px ) }",
14455      ".foo{transform:scale(.5)translate(10px)}",
14456    );
14457    minify_test(
14458      ".foo { transform: translate(2px, 3px)",
14459      ".foo{transform:translate(2px,3px)}",
14460    );
14461    minify_test(
14462      ".foo { transform: translate(2px, 0px)",
14463      ".foo{transform:translate(2px)}",
14464    );
14465    minify_test(
14466      ".foo { transform: translate(0px, 2px)",
14467      ".foo{transform:translateY(2px)}",
14468    );
14469    minify_test(".foo { transform: translateX(2px)", ".foo{transform:translate(2px)}");
14470    minify_test(".foo { transform: translateY(2px)", ".foo{transform:translateY(2px)}");
14471    minify_test(".foo { transform: translateZ(2px)", ".foo{transform:translateZ(2px)}");
14472    minify_test(
14473      ".foo { transform: translate3d(2px, 3px, 4px)",
14474      ".foo{transform:translate3d(2px,3px,4px)}",
14475    );
14476    minify_test(
14477      ".foo { transform: translate3d(10%, 20%, 4px)",
14478      ".foo{transform:translate3d(10%,20%,4px)}",
14479    );
14480    minify_test(
14481      ".foo { transform: translate3d(2px, 0px, 0px)",
14482      ".foo{transform:translate(2px)}",
14483    );
14484    minify_test(
14485      ".foo { transform: translate3d(0px, 2px, 0px)",
14486      ".foo{transform:translateY(2px)}",
14487    );
14488    minify_test(
14489      ".foo { transform: translate3d(0px, 0px, 2px)",
14490      ".foo{transform:translateZ(2px)}",
14491    );
14492    minify_test(
14493      ".foo { transform: translate3d(2px, 3px, 0px)",
14494      ".foo{transform:translate(2px,3px)}",
14495    );
14496    minify_test(".foo { transform: scale(2, 3)", ".foo{transform:scale(2,3)}");
14497    minify_test(".foo { transform: scale(10%, 20%)", ".foo{transform:scale(.1,.2)}");
14498    minify_test(".foo { transform: scale(2, 2)", ".foo{transform:scale(2)}");
14499    minify_test(".foo { transform: scale(2, 1)", ".foo{transform:scaleX(2)}");
14500    minify_test(".foo { transform: scale(1, 2)", ".foo{transform:scaleY(2)}");
14501    minify_test(".foo { transform: scaleX(2)", ".foo{transform:scaleX(2)}");
14502    minify_test(".foo { transform: scaleY(2)", ".foo{transform:scaleY(2)}");
14503    minify_test(".foo { transform: scaleZ(2)", ".foo{transform:scaleZ(2)}");
14504    minify_test(".foo { transform: scale3d(2, 3, 4)", ".foo{transform:scale3d(2,3,4)}");
14505    minify_test(".foo { transform: scale3d(2, 1, 1)", ".foo{transform:scaleX(2)}");
14506    minify_test(".foo { transform: scale3d(1, 2, 1)", ".foo{transform:scaleY(2)}");
14507    minify_test(".foo { transform: scale3d(1, 1, 2)", ".foo{transform:scaleZ(2)}");
14508    minify_test(".foo { transform: scale3d(2, 2, 1)", ".foo{transform:scale(2)}");
14509
14510    // transform: scale(), Convert <percentage> to <number>
14511    test(
14512      ".foo { transform: scale3d(50%, 1, 200%) }",
14513      indoc! {r#"
14514      .foo {
14515        transform: scale3d(.5, 1, 2);
14516      }
14517      "#},
14518    );
14519    minify_test(".foo { transform: scale(1%) }", ".foo{transform:scale(.01)}");
14520    minify_test(".foo { transform: scale(0%) }", ".foo{transform:scale(0)}");
14521    minify_test(".foo { transform: scale(0.0%) }", ".foo{transform:scale(0)}");
14522    minify_test(".foo { transform: scale(-0%) }", ".foo{transform:scale(0)}");
14523    minify_test(".foo { transform: scale(-0) }", ".foo{transform:scale(0)}");
14524    minify_test(".foo { transform: scale(-0.0) }", ".foo{transform:scale(0)}");
14525    minify_test(".foo { transform: scale(100%) }", ".foo{transform:scale(1)}");
14526    minify_test(".foo { transform: scale(-100%) }", ".foo{transform:scale(-1)}");
14527    minify_test(".foo { transform: scale(68%) }", ".foo{transform:scale(.68)}");
14528    minify_test(".foo { transform: scale(5.96%) }", ".foo{transform:scale(.0596)}");
14529    // Match WPT coverage for repeated and multi-value percentages.
14530    minify_test(".foo { transform: scale(100%, 100%) }", ".foo{transform:scale(1)}");
14531    minify_test(".foo { transform: scale3d(100%, 100%, 1) }", ".foo{transform:scale(1)}");
14532    minify_test(".foo { transform: scale(-100%, -100%) }", ".foo{transform:scale(-1)}");
14533    minify_test(
14534      ".foo { transform: scale3d(-100%, -100%, 1) }",
14535      ".foo{transform:scale(-1)}",
14536    );
14537    minify_test(".foo { transform: scale(100%, 200%) }", ".foo{transform:scaleY(2)}");
14538    minify_test(
14539      ".foo { transform: scale3d(100%, 200%, 1) }",
14540      ".foo{transform:scaleY(2)}",
14541    );
14542    minify_test(
14543      ".foo { transform: scale3d(100%, 100%, 0%) }",
14544      ".foo{transform:scaleZ(0)}",
14545    );
14546    minify_test(
14547      ".foo { transform: scale3d(100%, 100%, 100%) }",
14548      ".foo{transform:scale(1)}",
14549    );
14550    minify_test(
14551      ".foo { transform: scale3d(-0%, -0%, -0%) }",
14552      ".foo{transform:scale3d(0,0,0)}",
14553    );
14554    // Additional edge cases: mixed inputs and computed percentages.
14555    minify_test(".foo { transform: scale(2, 100%) }", ".foo{transform:scaleX(2)}");
14556    minify_test(".foo { transform: scale(2, -50%) }", ".foo{transform:scale(2,-.5)}");
14557    minify_test(".foo { transform: scale(-90%, -1) }", ".foo{transform:scale(-.9,-1)}");
14558    minify_test(
14559      ".foo { transform: scale(calc(10% + 20%)) }",
14560      ".foo{transform:scale(.3)}",
14561    );
14562    minify_test(
14563      ".foo { transform: scale(calc(150% - 50%), 200%) }",
14564      ".foo{transform:scaleY(2)}",
14565    );
14566    minify_test(
14567      ".foo { transform: scale(200%, calc(50% - 80%)) }",
14568      ".foo{transform:scale(2,-.3)}",
14569    );
14570    // TODO: For infinite decimals, please do not attempt to resolve calc
14571    // Expected: calc(1 / 3)
14572    // https://github.com/parcel-bundler/lightningcss/issues/12
14573    minify_test(
14574      ".foo { transform: scale(calc(100% / 3)) }",
14575      ".foo{transform:scale(.333333)}",
14576    );
14577    // Transform::ScaleX/Y/Z
14578    minify_test(".foo { transform: scaleX(10%) }", ".foo{transform:scaleX(.1)}");
14579    minify_test(".foo { transform: scaleY(20%) }", ".foo{transform:scaleY(.2)}");
14580    minify_test(".foo { transform: scaleZ(30%) }", ".foo{transform:scaleZ(.3)}");
14581    minify_test(".foo { transform: scaleX(0%) }", ".foo{transform:scaleX(0)}");
14582    minify_test(".foo { transform: scaleX(-0%) }", ".foo{transform:scaleX(0)}");
14583    minify_test(
14584      ".foo { transform: scaleX(calc(10% + 20%)) }",
14585      ".foo{transform:scaleX(.3)}",
14586    );
14587    minify_test(
14588      ".foo { transform: scaleX(calc(180% - 20%)) }",
14589      ".foo{transform:scaleX(1.6)}",
14590    );
14591    minify_test(
14592      ".foo { transform: scaleX(calc(50% - 80%)) }",
14593      ".foo{transform:scaleX(-.3)}",
14594    );
14595
14596    minify_test(".foo { transform: rotate(20deg)", ".foo{transform:rotate(20deg)}");
14597    minify_test(".foo { transform: rotateX(20deg)", ".foo{transform:rotateX(20deg)}");
14598    minify_test(".foo { transform: rotateY(20deg)", ".foo{transform:rotateY(20deg)}");
14599    minify_test(".foo { transform: rotateZ(20deg)", ".foo{transform:rotate(20deg)}");
14600    minify_test(".foo { transform: rotate(360deg)", ".foo{transform:rotate(360deg)}");
14601    minify_test(
14602      ".foo { transform: rotate3d(2, 3, 4, 20deg)",
14603      ".foo{transform:rotate3d(2,3,4,20deg)}",
14604    );
14605    minify_test(
14606      ".foo { transform: rotate3d(1, 0, 0, 20deg)",
14607      ".foo{transform:rotateX(20deg)}",
14608    );
14609    minify_test(
14610      ".foo { transform: rotate3d(0, 1, 0, 20deg)",
14611      ".foo{transform:rotateY(20deg)}",
14612    );
14613    minify_test(
14614      ".foo { transform: rotate3d(0, 0, 1, 20deg)",
14615      ".foo{transform:rotate(20deg)}",
14616    );
14617    minify_test(".foo { transform: rotate(405deg)}", ".foo{transform:rotate(405deg)}");
14618    minify_test(".foo { transform: rotateX(405deg)}", ".foo{transform:rotateX(405deg)}");
14619    minify_test(".foo { transform: rotateY(405deg)}", ".foo{transform:rotateY(405deg)}");
14620    minify_test(".foo { transform: rotate(-200deg)}", ".foo{transform:rotate(-200deg)}");
14621    minify_test(".foo { transform: rotate(0)", ".foo{transform:rotate(0)}");
14622    minify_test(".foo { transform: rotate(0deg)", ".foo{transform:rotate(0)}");
14623    minify_test(
14624      ".foo { transform: rotateX(-200deg)}",
14625      ".foo{transform:rotateX(-200deg)}",
14626    );
14627    minify_test(
14628      ".foo { transform: rotateY(-200deg)}",
14629      ".foo{transform:rotateY(-200deg)}",
14630    );
14631    minify_test(
14632      ".foo { transform: rotate3d(1, 1, 0, -200deg)",
14633      ".foo{transform:rotate3d(1,1,0,-200deg)}",
14634    );
14635    minify_test(".foo { transform: skew(20deg)", ".foo{transform:skew(20deg)}");
14636    minify_test(".foo { transform: skew(20deg, 0deg)", ".foo{transform:skew(20deg)}");
14637    minify_test(".foo { transform: skew(0deg, 20deg)", ".foo{transform:skewY(20deg)}");
14638    minify_test(".foo { transform: skewX(20deg)", ".foo{transform:skew(20deg)}");
14639    minify_test(".foo { transform: skewY(20deg)", ".foo{transform:skewY(20deg)}");
14640    minify_test(
14641      ".foo { transform: perspective(10px)",
14642      ".foo{transform:perspective(10px)}",
14643    );
14644    minify_test(
14645      ".foo { transform: matrix(1, 2, -1, 1, 80, 80)",
14646      ".foo{transform:matrix(1,2,-1,1,80,80)}",
14647    );
14648    minify_test(
14649      ".foo { transform: matrix3d(1, 0, 0, 0, 0, 1, 6, 0, 0, 0, 1, 0, 50, 100, 0, 1.1)",
14650      ".foo{transform:matrix3d(1,0,0,0,0,1,6,0,0,0,1,0,50,100,0,1.1)}",
14651    );
14652    // TODO: Re-enable with a better solution
14653    //       See: https://github.com/parcel-bundler/lightningcss/issues/288
14654    // minify_test(
14655    //   ".foo{transform:translate(100px,200px) rotate(45deg) skew(10deg) scale(2)}",
14656    //   ".foo{transform:matrix(1.41421,1.41421,-1.16485,1.66358,100,200)}",
14657    // );
14658    // minify_test(
14659    //   ".foo{transform:translate(200px,300px) translate(100px,200px) scale(2)}",
14660    //   ".foo{transform:matrix(2,0,0,2,300,500)}",
14661    // );
14662    minify_test(
14663      ".foo{transform:translate(100px,200px) rotate(45deg)}",
14664      ".foo{transform:translate(100px,200px)rotate(45deg)}",
14665    );
14666    minify_test(
14667      ".foo{transform:rotate3d(1, 1, 1, 45deg) translate3d(100px, 100px, 10px)}",
14668      ".foo{transform:rotate3d(1,1,1,45deg)translate3d(100px,100px,10px)}",
14669    );
14670    // TODO: Re-enable with a better solution
14671    //       See: https://github.com/parcel-bundler/lightningcss/issues/288
14672    // minify_test(
14673    //   ".foo{transform:translate3d(100px, 100px, 10px) skew(10deg) scale3d(2, 3, 4)}",
14674    //   ".foo{transform:matrix3d(2,0,0,0,.528981,3,0,0,0,0,4,0,100,100,10,1)}",
14675    // );
14676    // minify_test(
14677    //   ".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)}",
14678    //   ".foo{transform:translate3d(100px,100px,10px)rotate3d(1,1,1,45deg)}"
14679    // );
14680    // minify_test(
14681    //   ".foo{transform:matrix3d(1, 0, 0, 0, 0, 0.7071067811865476, 0.7071067811865475, 0, 0, -0.7071067811865475, 0.7071067811865476, 0, 100, 100, 10, 1)}",
14682    //   ".foo{transform:translate3d(100px,100px,10px)rotateX(45deg)}"
14683    // );
14684    // minify_test(
14685    //   ".foo{transform:translate3d(100px, 200px, 10px) translate(100px, 100px)}",
14686    //   ".foo{transform:translate3d(200px,300px,10px)}",
14687    // );
14688    // minify_test(
14689    //   ".foo{transform:rotate(45deg) rotate(45deg)}",
14690    //   ".foo{transform:rotate(90deg)}",
14691    // );
14692    // minify_test(
14693    //   ".foo{transform:matrix(0.7071067811865476, 0.7071067811865475, -0.7071067811865475, 0.7071067811865476, 100, 100)}",
14694    //   ".foo{transform:translate(100px,100px)rotate(45deg)}"
14695    // );
14696    // minify_test(
14697    //   ".foo{transform:translateX(2in) translateX(50px)}",
14698    //   ".foo{transform:translate(242px)}",
14699    // );
14700    minify_test(
14701      ".foo{transform:translateX(calc(2in + 50px))}",
14702      ".foo{transform:translate(242px)}",
14703    );
14704    minify_test(".foo{transform:translateX(50%)}", ".foo{transform:translate(50%)}");
14705    minify_test(
14706      ".foo{transform:translateX(calc(50% - 100px + 20px))}",
14707      ".foo{transform:translate(calc(50% - 80px))}",
14708    );
14709    minify_test(
14710      ".foo{transform:rotate(calc(10deg + 20deg))}",
14711      ".foo{transform:rotate(30deg)}",
14712    );
14713    minify_test(
14714      ".foo{transform:rotate(calc(10deg + 0.349066rad))}",
14715      ".foo{transform:rotate(30deg)}",
14716    );
14717    minify_test(
14718      ".foo{transform:rotate(calc(10deg + 1.5turn))}",
14719      ".foo{transform:rotate(550deg)}",
14720    );
14721    minify_test(
14722      ".foo{transform:rotate(calc(10deg * 2))}",
14723      ".foo{transform:rotate(20deg)}",
14724    );
14725    minify_test(
14726      ".foo{transform:rotate(calc(-10deg * 2))}",
14727      ".foo{transform:rotate(-20deg)}",
14728    );
14729    minify_test(
14730      ".foo{transform:rotate(calc(10deg + var(--test)))}",
14731      ".foo{transform:rotate(calc(10deg + var(--test)))}",
14732    );
14733    minify_test(".foo { transform: scale(calc(.1 + .2))", ".foo{transform:scale(.3)}");
14734
14735    minify_test(
14736      ".foo { -webkit-transform: scale(calc(10% + 20%))",
14737      ".foo{-webkit-transform:scale(.3)}",
14738    );
14739
14740    minify_test(".foo { translate: 1px 2px 3px }", ".foo{translate:1px 2px 3px}");
14741    minify_test(".foo { translate: 1px 0px 0px }", ".foo{translate:1px}");
14742    minify_test(".foo { translate: 1px 2px 0px }", ".foo{translate:1px 2px}");
14743    minify_test(".foo { translate: 1px 0px 2px }", ".foo{translate:1px 0 2px}");
14744    minify_test(".foo { translate: none }", ".foo{translate:none}");
14745    minify_test(".foo { rotate: none }", ".foo{rotate:none}");
14746    minify_test(".foo { rotate: 0deg }", ".foo{rotate:0deg}");
14747    minify_test(".foo { rotate: -0deg }", ".foo{rotate:0deg}");
14748    minify_test(".foo { rotate: 10deg }", ".foo{rotate:10deg}");
14749    minify_test(".foo { rotate: z 10deg }", ".foo{rotate:10deg}");
14750    minify_test(".foo { rotate: 0 0 1 10deg }", ".foo{rotate:10deg}");
14751    minify_test(".foo { rotate: x 10deg }", ".foo{rotate:x 10deg}");
14752    minify_test(".foo { rotate: 1 0 0 10deg }", ".foo{rotate:x 10deg}");
14753    minify_test(".foo { rotate: 2 0 0 10deg }", ".foo{rotate:x 10deg}");
14754    minify_test(".foo { rotate: 0 2 0 10deg }", ".foo{rotate:y 10deg}");
14755    minify_test(".foo { rotate: 0 0 2 10deg }", ".foo{rotate:10deg}");
14756    minify_test(".foo { rotate: 0 0 5.3 10deg }", ".foo{rotate:10deg}");
14757    minify_test(".foo { rotate: 0 0 1 0deg }", ".foo{rotate:0deg}");
14758    minify_test(".foo { rotate: 10deg 0 0 -1 }", ".foo{rotate:-10deg}");
14759    minify_test(".foo { rotate: 10deg 0 0 -233 }", ".foo{rotate:-10deg}");
14760    minify_test(".foo { rotate: -1 0 0 0deg }", ".foo{rotate:x 0deg}");
14761    minify_test(".foo { rotate: 0deg 0 0 1 }", ".foo{rotate:0deg}");
14762    minify_test(".foo { rotate: 0deg 0 0 -1 }", ".foo{rotate:0deg}");
14763    minify_test(".foo { rotate: 0 1 0 10deg }", ".foo{rotate:y 10deg}");
14764    minify_test(".foo { rotate: x 0rad }", ".foo{rotate:x 0deg}");
14765    // TODO: In minify mode, convert units to the shortest form.
14766    // minify_test(".foo { rotate: y 0turn }", ".foo{rotate:y 0deg}");
14767    minify_test(".foo { rotate: z 0deg }", ".foo{rotate:0deg}");
14768    minify_test(".foo { rotate: 10deg y }", ".foo{rotate:y 10deg}");
14769    minify_test(".foo { rotate: 1 1 1 10deg }", ".foo{rotate:1 1 1 10deg}");
14770    minify_test(".foo { scale: 1 }", ".foo{scale:1}");
14771    minify_test(".foo { scale: 1 1 }", ".foo{scale:1}");
14772    minify_test(".foo { scale: 1 1 1 }", ".foo{scale:1}");
14773    minify_test(".foo { scale: none }", ".foo{scale:none}");
14774    minify_test(".foo { scale: 1 0 }", ".foo{scale:1 0}");
14775    minify_test(".foo { scale: 1 0 1 }", ".foo{scale:1 0}");
14776    minify_test(".foo { scale: 1 0 0 }", ".foo{scale:1 0 0}");
14777
14778    // scale, Convert <percentage> to <number>
14779    test(
14780      ".foo { scale: 50% 1 200% }",
14781      indoc! {r#"
14782      .foo {
14783        scale: .5 1 2;
14784      }
14785      "#},
14786    );
14787    minify_test(".foo { scale: 1% }", ".foo{scale:.01}");
14788    minify_test(".foo { scale: 0% }", ".foo{scale:0}");
14789    minify_test(".foo { scale: 0.0% }", ".foo{scale:0}");
14790    minify_test(".foo { scale: -0% }", ".foo{scale:0}");
14791    minify_test(".foo { scale: -0 }", ".foo{scale:0}");
14792    minify_test(".foo { scale: -0.0 }", ".foo{scale:0}");
14793    minify_test(".foo { scale: 100% }", ".foo{scale:1}");
14794    minify_test(".foo { scale: -100% }", ".foo{scale:-1}");
14795    minify_test(".foo { scale: 68% }", ".foo{scale:.68}");
14796    minify_test(".foo { scale: 5.96% }", ".foo{scale:.0596}");
14797    // Match WPT coverage for repeated and multi-value percentages.
14798    minify_test(".foo { scale: 100% 100% }", ".foo{scale:1}");
14799    minify_test(".foo { scale: 100% 100% 1 }", ".foo{scale:1}");
14800    minify_test(".foo { scale: -100% -100% }", ".foo{scale:-1}");
14801    minify_test(".foo { scale: -100% -100% 1 }", ".foo{scale:-1}");
14802    minify_test(".foo { scale: 100% 200% }", ".foo{scale:1 2}");
14803    minify_test(".foo { scale: 100% 200% 1 }", ".foo{scale:1 2}");
14804    minify_test(".foo { scale: 100% 100% 0% }", ".foo{scale:1 1 0}");
14805    minify_test(".foo { scale: 100% 100% 100% }", ".foo{scale:1}");
14806    minify_test(".foo { scale: -0% -0% -0% }", ".foo{scale:0 0 0}");
14807    // Additional edge cases: mixed inputs and computed percentages.
14808    minify_test(".foo { scale: 2 100% }", ".foo{scale:2 1}");
14809    minify_test(".foo { scale: 2 -50% }", ".foo{scale:2 -.5}");
14810    minify_test(".foo { scale: -90% -1 }", ".foo{scale:-.9 -1}");
14811    minify_test(".foo { scale: calc(10% + 20%) }", ".foo{scale:.3}");
14812    minify_test(".foo { scale: calc(150% - 50%) 200% }", ".foo{scale:1 2}");
14813    minify_test(".foo { scale: 200% calc(50% - 80%) }", ".foo{scale:2 -.3}");
14814    // TODO: For infinite decimals, please do not attempt to resolve calc
14815    // Expected: calc(1 / 3)
14816    // https://github.com/parcel-bundler/lightningcss/issues/12
14817    minify_test(".foo { scale: calc(100% / 3) }", ".foo{scale:.333333}");
14818
14819    assert_eq!(
14820      Property::Scale(crate::properties::transform::Scale::XYZ {
14821        x: crate::values::percentage::NumberOrPercentage::Percentage(crate::values::percentage::Percentage(0.5)),
14822        y: crate::values::percentage::NumberOrPercentage::Percentage(crate::values::percentage::Percentage(2.0)),
14823        z: crate::values::percentage::NumberOrPercentage::Percentage(crate::values::percentage::Percentage(1.0)),
14824      })
14825      .to_css_string(
14826        false,
14827        PrinterOptions {
14828          minify: true,
14829          ..PrinterOptions::default()
14830        },
14831      )
14832      .unwrap(),
14833      "scale:.5 2"
14834    );
14835    assert_eq!(
14836      Property::Transform(
14837        crate::properties::transform::TransformList(vec![crate::properties::transform::Transform::ScaleX(
14838          crate::values::percentage::NumberOrPercentage::Percentage(crate::values::percentage::Percentage(0.1)),
14839        )]),
14840        VendorPrefix::None,
14841      )
14842      .to_css_string(
14843        false,
14844        PrinterOptions {
14845          minify: true,
14846          ..PrinterOptions::default()
14847        },
14848      )
14849      .unwrap(),
14850      "transform:scaleX(.1)"
14851    );
14852
14853    minify_test(
14854      r#"
14855      .foo {
14856        transform: scale(3);
14857        scale: 0.5;
14858      }
14859      "#,
14860      ".foo{transform:scale(3);scale:.5}",
14861    );
14862    minify_test(
14863      r#"
14864      .foo {
14865        scale: 0.5;
14866        transform: scale(3);
14867      }
14868      "#,
14869      ".foo{transform:scale(3);scale:.5}",
14870    );
14871
14872    prefix_test(
14873      r#"
14874      .foo {
14875        transform: scale(0.5);
14876      }
14877    "#,
14878      indoc! {r#"
14879      .foo {
14880        -webkit-transform: scale(.5);
14881        -moz-transform: scale(.5);
14882        transform: scale(.5);
14883      }
14884    "#},
14885      Browsers {
14886        firefox: Some(6 << 16),
14887        safari: Some(6 << 16),
14888        ..Browsers::default()
14889      },
14890    );
14891
14892    prefix_test(
14893      r#"
14894      .foo {
14895        transform: var(--transform);
14896      }
14897    "#,
14898      indoc! {r#"
14899      .foo {
14900        -webkit-transform: var(--transform);
14901        -moz-transform: var(--transform);
14902        transform: var(--transform);
14903      }
14904    "#},
14905      Browsers {
14906        firefox: Some(6 << 16),
14907        safari: Some(6 << 16),
14908        ..Browsers::default()
14909      },
14910    );
14911
14912    test(
14913      r#"
14914      .foo {
14915        transform: translateX(-50%);
14916        transform: translateX(20px);
14917      }
14918      "#,
14919      indoc! {r#"
14920      .foo {
14921        transform: translateX(20px);
14922      }
14923      "#},
14924    );
14925  }
14926
14927  #[test]
14928  fn test_individual_transforms() {
14929    for (property, value, identity) in [
14930      ("translate", "10px", "0"),
14931      ("rotate", "30deg", "0deg"),
14932      ("scale", "2", "1"),
14933    ] {
14934      // `transform` is not a shorthand that resets the individual properties.
14935      for (transform, individual) in [("scale(3)", value), ("none", "none"), ("none", identity)] {
14936        let expected = format!(
14937          indoc! {r#"
14938          .box {{
14939            transform: {transform};
14940            {property}: {individual};
14941          }}
14942          "#},
14943          transform = transform,
14944          property = property,
14945          individual = individual,
14946        );
14947        test(
14948          &format!(
14949            r#"
14950            .box {{
14951              transform: {transform};
14952              {property}: {individual};
14953            }}
14954            "#,
14955          ),
14956          &expected,
14957        );
14958        test(
14959          &format!(
14960            r#"
14961            .box {{
14962              {property}: {individual};
14963              transform: {transform};
14964            }}
14965            "#,
14966          ),
14967          &expected,
14968        );
14969      }
14970    }
14971
14972    test(
14973      r#"
14974      .box {
14975        transform: translateX(5px);
14976        scale: 2;
14977        rotate: 30deg;
14978        translate: 10px;
14979        transform: scale(3);
14980        translate: 20px 30px;
14981        rotate: x 40deg;
14982        scale: 4 5;
14983      }
14984      "#,
14985      indoc! {r#"
14986      .box {
14987        transform: scale(3);
14988        translate: 20px 30px;
14989        rotate: x 40deg;
14990        scale: 4 5;
14991      }
14992      "#},
14993    );
14994
14995    test(
14996      r#"
14997      .base {
14998        translate: 10px;
14999        rotate: 30deg;
15000        scale: 2;
15001      }
15002
15003      .base.reset {
15004        transform: none;
15005        translate: none;
15006        rotate: none;
15007        scale: none;
15008      }
15009
15010      .base.identity {
15011        translate: 0;
15012        rotate: 0deg;
15013        scale: 1;
15014        transform: none;
15015      }
15016      "#,
15017      indoc! {r#"
15018      .base {
15019        translate: 10px;
15020        rotate: 30deg;
15021        scale: 2;
15022      }
15023
15024      .base.reset {
15025        transform: none;
15026        translate: none;
15027        rotate: none;
15028        scale: none;
15029      }
15030
15031      .base.identity {
15032        transform: none;
15033        translate: 0;
15034        rotate: 0deg;
15035        scale: 1;
15036      }
15037      "#},
15038    );
15039
15040    test(
15041      r#"
15042      .box {
15043        transform: scale(2) !important;
15044        translate: 10px;
15045        rotate: 30deg !important;
15046        scale: 3;
15047        translate: 20px !important;
15048        transform: none;
15049        translate: 30px !important;
15050      }
15051      "#,
15052      indoc! {r#"
15053      .box {
15054        transform: none;
15055        translate: 10px;
15056        scale: 3;
15057        transform: scale(2) !important;
15058        translate: 30px !important;
15059        rotate: 30deg !important;
15060      }
15061      "#},
15062    );
15063
15064    test(
15065      r#"
15066      .box {
15067        transform: rotate(10deg);
15068        translate: 10px;
15069        translate: var(--shift);
15070        rotate: 20deg;
15071        transform: var(--motion);
15072        scale: 2;
15073        scale: var(--zoom);
15074        transform: translateX(2px);
15075      }
15076      "#,
15077      indoc! {r#"
15078      .box {
15079        transform: rotate(10deg);
15080        translate: 10px;
15081        translate: var(--shift);
15082        rotate: 20deg;
15083        transform: var(--motion);
15084        scale: 2;
15085        scale: var(--zoom);
15086        transform: translateX(2px);
15087      }
15088      "#},
15089    );
15090
15091    test(
15092      r#"
15093      .box {
15094        -webkit-transform: scale(2);
15095        translate: 10px;
15096        transform: scale(3);
15097        rotate: 30deg;
15098      }
15099      "#,
15100      indoc! {r#"
15101      .box {
15102        -webkit-transform: scale(2);
15103        translate: 10px;
15104        transform: scale(3);
15105        rotate: 30deg;
15106      }
15107      "#},
15108    );
15109
15110    prefix_test(
15111      r#"
15112      .box {
15113        translate: 10px;
15114        transform: scale(2);
15115        rotate: none;
15116        scale: 1;
15117      }
15118      "#,
15119      indoc! {r#"
15120      .box {
15121        -webkit-transform: scale(2);
15122        -moz-transform: scale(2);
15123        transform: scale(2);
15124        translate: 10px;
15125        rotate: none;
15126        scale: 1;
15127      }
15128      "#},
15129      Browsers {
15130        firefox: Some(6 << 16),
15131        safari: Some(6 << 16),
15132        ..Browsers::default()
15133      },
15134    );
15135  }
15136
15137  #[test]
15138  fn test_zero_translate3d() {
15139    minify_test(
15140      indoc! {"
15141        .foo {
15142          transform: translate3d(0, 0, 0);
15143        }
15144      "},
15145      ".foo{transform:translate(0)}",
15146    );
15147    minify_test(
15148      indoc! {"
15149        .foo {
15150          transform: translate3d(0px, -0%, 0em);
15151        }
15152      "},
15153      ".foo{transform:translate(0)}",
15154    );
15155    minify_test(
15156      indoc! {"
15157        .foo {
15158          transform: translate3d(0%, 0px, -0px);
15159        }
15160      "},
15161      ".foo{transform:translate(0%)}",
15162    );
15163    minify_test(
15164      indoc! {"
15165        .foo {
15166          transform: translate3d(calc(1px - 1px), 0, 0) rotate(30deg);
15167        }
15168      "},
15169      ".foo{transform:translate(0)rotate(30deg)}",
15170    );
15171    minify_test(
15172      indoc! {"
15173        .foo {
15174          -webkit-transform: translate3d(0, 0, 0);
15175        }
15176      "},
15177      ".foo{-webkit-transform:translate(0)}",
15178    );
15179    minify_test(
15180      indoc! {"
15181        .foo {
15182          transform: translate3d(0, 0, var(--z));
15183        }
15184      "},
15185      ".foo{transform:translate3d(0, 0, var(--z))}",
15186    );
15187    test(
15188      indoc! {"
15189        .foo {
15190          transform: translate3d(0, 0, 0);
15191        }
15192      "},
15193      indoc! {"
15194        .foo {
15195          transform: translate3d(0, 0, 0);
15196        }
15197      "},
15198    );
15199  }
15200
15201  #[test]
15202  pub fn test_gradients() {
15203    property_range_test(&["clip-path"], &[("circle(-1px)", None), ("ellipse(1px -2%)", None)]);
15204    property_range_test(
15205      &["background-image"],
15206      &[
15207        ("radial-gradient(-1px, red, blue)", None),
15208        ("radial-gradient(1px -2%, red, blue)", None),
15209      ],
15210    );
15211    minify_test(
15212      ".foo { background: linear-gradient(yellow, blue) }",
15213      ".foo{background:linear-gradient(#ff0,#00f)}",
15214    );
15215    minify_test(
15216      ".foo { background: linear-gradient(to bottom, yellow, blue); }",
15217      ".foo{background:linear-gradient(#ff0,#00f)}",
15218    );
15219    minify_test(
15220      ".foo { background: linear-gradient(180deg, yellow, blue); }",
15221      ".foo{background:linear-gradient(#ff0,#00f)}",
15222    );
15223    minify_test(
15224      ".foo { background: linear-gradient(0.5turn, yellow, blue); }",
15225      ".foo{background:linear-gradient(#ff0,#00f)}",
15226    );
15227    minify_test(
15228      ".foo { background: linear-gradient(yellow 10%, blue 20%) }",
15229      ".foo{background:linear-gradient(#ff0 10%,#00f 20%)}",
15230    );
15231    minify_test(
15232      ".foo { background: linear-gradient(to top, blue, yellow); }",
15233      ".foo{background:linear-gradient(#ff0,#00f)}",
15234    );
15235    minify_test(
15236      ".foo { background: linear-gradient(to top, blue 10%, yellow 20%); }",
15237      ".foo{background:linear-gradient(#ff0 80%,#00f 90%)}",
15238    );
15239    minify_test(
15240      ".foo { background: linear-gradient(to top, blue 10px, yellow 20px); }",
15241      ".foo{background:linear-gradient(0deg,#00f 10px,#ff0 20px)}",
15242    );
15243    minify_test(
15244      ".foo { background: linear-gradient(135deg, yellow, blue); }",
15245      ".foo{background:linear-gradient(135deg,#ff0,#00f)}",
15246    );
15247    minify_test(
15248      ".foo { background: linear-gradient(-1.42109e-14deg, rgba(10, 132, 255, 0.14) 0%, rgba(112, 183, 255, 0.14) 100%); }",
15249      ".foo{background:linear-gradient(-1.42109e-14deg,#0a84ff24 0%,#70b7ff24 100%)}",
15250    );
15251    minify_test(
15252      ".foo { background: linear-gradient(yellow, blue 20%, #0f0); }",
15253      ".foo{background:linear-gradient(#ff0,#00f 20%,#0f0)}",
15254    );
15255    minify_test(
15256      ".foo { background: linear-gradient(to top right, red, white, blue) }",
15257      ".foo{background:linear-gradient(to top right,red,#fff,#00f)}",
15258    );
15259    minify_test(
15260      ".foo { background: linear-gradient(yellow, blue calc(10% * 2), #0f0); }",
15261      ".foo{background:linear-gradient(#ff0,#00f 20%,#0f0)}",
15262    );
15263    minify_test(
15264      ".foo { background: linear-gradient(yellow, 20%, blue); }",
15265      ".foo{background:linear-gradient(#ff0,20%,#00f)}",
15266    );
15267    minify_test(
15268      ".foo { background: linear-gradient(yellow, 50%, blue); }",
15269      ".foo{background:linear-gradient(#ff0,#00f)}",
15270    );
15271    minify_test(
15272      ".foo { background: linear-gradient(yellow, 20px, blue); }",
15273      ".foo{background:linear-gradient(#ff0,20px,#00f)}",
15274    );
15275    minify_test(
15276      ".foo { background: linear-gradient(yellow, 50px, blue); }",
15277      ".foo{background:linear-gradient(#ff0,50px,#00f)}",
15278    );
15279    minify_test(
15280      ".foo { background: linear-gradient(yellow, 50px, blue); }",
15281      ".foo{background:linear-gradient(#ff0,50px,#00f)}",
15282    );
15283    minify_test(
15284      ".foo { background: linear-gradient(yellow, red 30% 40%, blue); }",
15285      ".foo{background:linear-gradient(#ff0,red 30% 40%,#00f)}",
15286    );
15287    minify_test(
15288      ".foo { background: linear-gradient(yellow, red 30%, red 40%, blue); }",
15289      ".foo{background:linear-gradient(#ff0,red 30% 40%,#00f)}",
15290    );
15291    minify_test(
15292      ".foo { background: linear-gradient(0, yellow, blue); }",
15293      ".foo{background:linear-gradient(#00f,#ff0)}",
15294    );
15295    minify_test(
15296      ".foo { background: -webkit-linear-gradient(yellow, blue) }",
15297      ".foo{background:-webkit-linear-gradient(#ff0,#00f)}",
15298    );
15299    minify_test(
15300      ".foo { background: -webkit-linear-gradient(bottom, yellow, blue); }",
15301      ".foo{background:-webkit-linear-gradient(#ff0,#00f)}",
15302    );
15303    minify_test(
15304      ".foo { background: -webkit-linear-gradient(top right, red, white, blue) }",
15305      ".foo{background:-webkit-linear-gradient(top right,red,#fff,#00f)}",
15306    );
15307    minify_test(
15308      ".foo { background: -moz-linear-gradient(yellow, blue) }",
15309      ".foo{background:-moz-linear-gradient(#ff0,#00f)}",
15310    );
15311    minify_test(
15312      ".foo { background: -moz-linear-gradient(bottom, yellow, blue); }",
15313      ".foo{background:-moz-linear-gradient(#ff0,#00f)}",
15314    );
15315    minify_test(
15316      ".foo { background: -moz-linear-gradient(top right, red, white, blue) }",
15317      ".foo{background:-moz-linear-gradient(top right,red,#fff,#00f)}",
15318    );
15319    minify_test(
15320      ".foo { background: -o-linear-gradient(yellow, blue) }",
15321      ".foo{background:-o-linear-gradient(#ff0,#00f)}",
15322    );
15323    minify_test(
15324      ".foo { background: -o-linear-gradient(bottom, yellow, blue); }",
15325      ".foo{background:-o-linear-gradient(#ff0,#00f)}",
15326    );
15327    minify_test(
15328      ".foo { background: -o-linear-gradient(top right, red, white, blue) }",
15329      ".foo{background:-o-linear-gradient(top right,red,#fff,#00f)}",
15330    );
15331    minify_test(
15332      ".foo { background: -webkit-gradient(linear, left top, left bottom, from(blue), to(yellow)) }",
15333      ".foo{background:-webkit-gradient(linear,0 0,0 100%,from(#00f),to(#ff0))}",
15334    );
15335    minify_test(
15336      ".foo { background: -webkit-gradient(linear, left top, left bottom, from(blue), color-stop(50%, red), to(yellow)) }",
15337      ".foo{background:-webkit-gradient(linear,0 0,0 100%,from(#00f),color-stop(.5,red),to(#ff0))}"
15338    );
15339    minify_test(
15340      ".foo { background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, blue), color-stop(50%, red), color-stop(100%, yellow)) }",
15341      ".foo{background:-webkit-gradient(linear,0 0,0 100%,from(#00f),color-stop(.5,red),to(#ff0))}"
15342    );
15343    minify_test(
15344      ".foo { background: repeating-linear-gradient(yellow 10px, blue 50px) }",
15345      ".foo{background:repeating-linear-gradient(#ff0 10px,#00f 50px)}",
15346    );
15347    minify_test(
15348      ".foo { background: -webkit-repeating-linear-gradient(yellow 10px, blue 50px) }",
15349      ".foo{background:-webkit-repeating-linear-gradient(#ff0 10px,#00f 50px)}",
15350    );
15351    minify_test(
15352      ".foo { background: -moz-repeating-linear-gradient(yellow 10px, blue 50px) }",
15353      ".foo{background:-moz-repeating-linear-gradient(#ff0 10px,#00f 50px)}",
15354    );
15355    minify_test(
15356      ".foo { background: -o-repeating-linear-gradient(yellow 10px, blue 50px) }",
15357      ".foo{background:-o-repeating-linear-gradient(#ff0 10px,#00f 50px)}",
15358    );
15359    minify_test(
15360      ".foo { background: radial-gradient(yellow, blue) }",
15361      ".foo{background:radial-gradient(#ff0,#00f)}",
15362    );
15363    minify_test(
15364      ".foo { background: radial-gradient(at top left, yellow, blue) }",
15365      ".foo{background:radial-gradient(at 0 0,#ff0,#00f)}",
15366    );
15367    minify_test(
15368      ".foo { background: radial-gradient(5em circle at top left, yellow, blue) }",
15369      ".foo{background:radial-gradient(5em at 0 0,#ff0,#00f)}",
15370    );
15371    minify_test(
15372      ".foo { background: radial-gradient(circle at 100%, #333, #333 50%, #eee 75%, #333 75%) }",
15373      ".foo{background:radial-gradient(circle at 100%,#333,#333 50%,#eee 75%,#333 75%)}",
15374    );
15375    minify_test(
15376      ".foo { background: radial-gradient(farthest-corner circle at 100% 50%, #333, #333 50%, #eee 75%, #333 75%) }",
15377      ".foo{background:radial-gradient(circle at 100%,#333,#333 50%,#eee 75%,#333 75%)}"
15378    );
15379    minify_test(
15380      ".foo { background: radial-gradient(farthest-corner circle at 50% 50%, #333, #333 50%, #eee 75%, #333 75%) }",
15381      ".foo{background:radial-gradient(circle,#333,#333 50%,#eee 75%,#333 75%)}"
15382    );
15383    minify_test(
15384      ".foo { background: radial-gradient(ellipse at top, #e66465, transparent) }",
15385      ".foo{background:radial-gradient(at top,#e66465,#0000)}",
15386    );
15387    minify_test(
15388      ".foo { background: radial-gradient(20px, yellow, blue) }",
15389      ".foo{background:radial-gradient(20px,#ff0,#00f)}",
15390    );
15391    minify_test(
15392      ".foo { background: radial-gradient(circle 20px, yellow, blue) }",
15393      ".foo{background:radial-gradient(20px,#ff0,#00f)}",
15394    );
15395    minify_test(
15396      ".foo { background: radial-gradient(20px 40px, yellow, blue) }",
15397      ".foo{background:radial-gradient(20px 40px,#ff0,#00f)}",
15398    );
15399    minify_test(
15400      ".foo { background: radial-gradient(ellipse 20px 40px, yellow, blue) }",
15401      ".foo{background:radial-gradient(20px 40px,#ff0,#00f)}",
15402    );
15403    minify_test(
15404      ".foo { background: radial-gradient(ellipse calc(20px + 10px) 40px, yellow, blue) }",
15405      ".foo{background:radial-gradient(30px 40px,#ff0,#00f)}",
15406    );
15407    minify_test(
15408      ".foo { background: radial-gradient(circle farthest-side, yellow, blue) }",
15409      ".foo{background:radial-gradient(circle farthest-side,#ff0,#00f)}",
15410    );
15411    minify_test(
15412      ".foo { background: radial-gradient(farthest-side circle, yellow, blue) }",
15413      ".foo{background:radial-gradient(circle farthest-side,#ff0,#00f)}",
15414    );
15415    minify_test(
15416      ".foo { background: radial-gradient(ellipse farthest-side, yellow, blue) }",
15417      ".foo{background:radial-gradient(farthest-side,#ff0,#00f)}",
15418    );
15419    minify_test(
15420      ".foo { background: radial-gradient(farthest-side ellipse, yellow, blue) }",
15421      ".foo{background:radial-gradient(farthest-side,#ff0,#00f)}",
15422    );
15423    minify_test(
15424      ".foo { background: -webkit-radial-gradient(yellow, blue) }",
15425      ".foo{background:-webkit-radial-gradient(#ff0,#00f)}",
15426    );
15427    minify_test(
15428      ".foo { background: -moz-radial-gradient(yellow, blue) }",
15429      ".foo{background:-moz-radial-gradient(#ff0,#00f)}",
15430    );
15431    minify_test(
15432      ".foo { background: -o-radial-gradient(yellow, blue) }",
15433      ".foo{background:-o-radial-gradient(#ff0,#00f)}",
15434    );
15435    minify_test(
15436      ".foo { background: repeating-radial-gradient(circle 20px, yellow, blue) }",
15437      ".foo{background:repeating-radial-gradient(20px,#ff0,#00f)}",
15438    );
15439    minify_test(
15440      ".foo { background: -webkit-repeating-radial-gradient(circle 20px, yellow, blue) }",
15441      ".foo{background:-webkit-repeating-radial-gradient(20px,#ff0,#00f)}",
15442    );
15443    minify_test(
15444      ".foo { background: -moz-repeating-radial-gradient(circle 20px, yellow, blue) }",
15445      ".foo{background:-moz-repeating-radial-gradient(20px,#ff0,#00f)}",
15446    );
15447    minify_test(
15448      ".foo { background: -o-repeating-radial-gradient(circle 20px, yellow, blue) }",
15449      ".foo{background:-o-repeating-radial-gradient(20px,#ff0,#00f)}",
15450    );
15451    minify_test(
15452      ".foo { background: -webkit-gradient(radial, center center, 0, center center, 100, from(blue), to(yellow)) }",
15453      ".foo{background:-webkit-gradient(radial,50% 50%,0,50% 50%,100,from(#00f),to(#ff0))}"
15454    );
15455    minify_test(
15456      ".foo { background: conic-gradient(#f06, gold) }",
15457      ".foo{background:conic-gradient(#f06,gold)}",
15458    );
15459    minify_test(
15460      ".foo { background: conic-gradient(at 50% 50%, #f06, gold) }",
15461      ".foo{background:conic-gradient(#f06,gold)}",
15462    );
15463    minify_test(
15464      ".foo { background: conic-gradient(from 0deg, #f06, gold) }",
15465      ".foo{background:conic-gradient(#f06,gold)}",
15466    );
15467    minify_test(
15468      ".foo { background: conic-gradient(from 0, #f06, gold) }",
15469      ".foo{background:conic-gradient(#f06,gold)}",
15470    );
15471    minify_test(
15472      ".foo { background: conic-gradient(from 0deg at center, #f06, gold) }",
15473      ".foo{background:conic-gradient(#f06,gold)}",
15474    );
15475    minify_test(
15476      ".foo { background: conic-gradient(white -50%, black 150%) }",
15477      ".foo{background:conic-gradient(#fff -50%,#000 150%)}",
15478    );
15479    minify_test(
15480      ".foo { background: conic-gradient(white -180deg, black 540deg) }",
15481      ".foo{background:conic-gradient(#fff -180deg,#000 540deg)}",
15482    );
15483    minify_test(
15484      ".foo { background: conic-gradient(from 45deg, white, black, white) }",
15485      ".foo{background:conic-gradient(from 45deg,#fff,#000,#fff)}",
15486    );
15487    minify_test(
15488      ".foo { background: repeating-conic-gradient(from 45deg, white, black, white) }",
15489      ".foo{background:repeating-conic-gradient(from 45deg,#fff,#000,#fff)}",
15490    );
15491    minify_test(
15492      ".foo { background: repeating-conic-gradient(black 0deg 25%, white 0deg 50%) }",
15493      ".foo{background:repeating-conic-gradient(#000 0deg 25%,#fff 0deg 50%)}",
15494    );
15495
15496    test(
15497      r#"
15498        .foo {
15499          background: -webkit-gradient(linear, left top, left bottom, from(red), to(blue));
15500          background: -webkit-linear-gradient(red, blue);
15501          background: -moz-linear-gradient(red, blue);
15502          background: -o-linear-gradient(red, blue);
15503          background: linear-gradient(red, blue);
15504        }
15505      "#,
15506      indoc! {r#"
15507        .foo {
15508          background: -webkit-gradient(linear, left top, left bottom, from(red), to(#00f));
15509          background: -webkit-linear-gradient(red, #00f);
15510          background: -moz-linear-gradient(red, #00f);
15511          background: -o-linear-gradient(red, #00f);
15512          background: linear-gradient(red, #00f);
15513        }
15514      "#},
15515    );
15516
15517    prefix_test(
15518      r#"
15519      .foo {
15520        background: -webkit-gradient(linear, left top, left bottom, from(red), to(blue));
15521        background: -webkit-linear-gradient(red, blue);
15522        background: -moz-linear-gradient(red, blue);
15523        background: -o-linear-gradient(red, blue);
15524        background: linear-gradient(red, blue);
15525      }
15526      "#,
15527      indoc! {r#"
15528      .foo {
15529        background: linear-gradient(red, #00f);
15530      }
15531      "#},
15532      Browsers {
15533        chrome: Some(95 << 16),
15534        ..Browsers::default()
15535      },
15536    );
15537    prefix_test(
15538      r#"
15539      .foo {
15540        background: -webkit-gradient(linear, left top, left bottom, from(red), to(blue));
15541        background: -webkit-linear-gradient(red, blue);
15542        background: -moz-linear-gradient(red, blue);
15543        background: -o-linear-gradient(red, blue);
15544      }
15545      "#,
15546      indoc! {r#"
15547      .foo {
15548        background: -webkit-gradient(linear, left top, left bottom, from(red), to(#00f));
15549        background: -webkit-linear-gradient(red, #00f);
15550        background: -moz-linear-gradient(red, #00f);
15551        background: -o-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-image: linear-gradient(red, blue);
15563      }
15564      "#,
15565      indoc! {r#"
15566      .foo {
15567        background-image: -webkit-gradient(linear, 0 0, 0 100%, from(red), to(#00f));
15568        background-image: -webkit-linear-gradient(top, red, #00f);
15569        background-image: linear-gradient(red, #00f);
15570      }
15571      "#},
15572      Browsers {
15573        chrome: Some(8 << 16),
15574        ..Browsers::default()
15575      },
15576    );
15577    prefix_test(
15578      r#"
15579      .foo {
15580        background-image: linear-gradient(to right, red, blue);
15581      }
15582      "#,
15583      indoc! {r#"
15584      .foo {
15585        background-image: -webkit-gradient(linear, 0 0, 100% 0, from(red), to(#00f));
15586        background-image: -webkit-linear-gradient(left, red, #00f);
15587        background-image: linear-gradient(to right, red, #00f);
15588      }
15589      "#},
15590      Browsers {
15591        chrome: Some(8 << 16),
15592        ..Browsers::default()
15593      },
15594    );
15595    prefix_test(
15596      r#"
15597      .foo {
15598        background-image: linear-gradient(to top, red, blue);
15599      }
15600      "#,
15601      indoc! {r#"
15602      .foo {
15603        background-image: -webkit-gradient(linear, 0 100%, 0 0, from(red), to(#00f));
15604        background-image: -webkit-linear-gradient(red, #00f);
15605        background-image: linear-gradient(to top, red, #00f);
15606      }
15607      "#},
15608      Browsers {
15609        chrome: Some(8 << 16),
15610        ..Browsers::default()
15611      },
15612    );
15613    prefix_test(
15614      r#"
15615      .foo {
15616        background-image: linear-gradient(to left, red, blue);
15617      }
15618      "#,
15619      indoc! {r#"
15620      .foo {
15621        background-image: -webkit-gradient(linear, 100% 0, 0 0, from(red), to(#00f));
15622        background-image: -webkit-linear-gradient(right, red, #00f);
15623        background-image: linear-gradient(to left, red, #00f);
15624      }
15625      "#},
15626      Browsers {
15627        chrome: Some(8 << 16),
15628        ..Browsers::default()
15629      },
15630    );
15631    prefix_test(
15632      r#"
15633      .foo {
15634        background-image: linear-gradient(to left bottom, red, blue);
15635      }
15636      "#,
15637      indoc! {r#"
15638      .foo {
15639        background-image: -webkit-gradient(linear, 100% 0, 0 100%, from(red), to(#00f));
15640        background-image: -webkit-linear-gradient(top right, red, #00f);
15641        background-image: linear-gradient(to bottom left, red, #00f);
15642      }
15643      "#},
15644      Browsers {
15645        chrome: Some(8 << 16),
15646        ..Browsers::default()
15647      },
15648    );
15649    prefix_test(
15650      r#"
15651      .foo {
15652        background-image: linear-gradient(to top right, red, blue);
15653      }
15654      "#,
15655      indoc! {r#"
15656      .foo {
15657        background-image: -webkit-gradient(linear, 0 100%, 100% 0, from(red), to(#00f));
15658        background-image: -webkit-linear-gradient(bottom left, red, #00f);
15659        background-image: linear-gradient(to top right, red, #00f);
15660      }
15661      "#},
15662      Browsers {
15663        chrome: Some(8 << 16),
15664        ..Browsers::default()
15665      },
15666    );
15667    prefix_test(
15668      r#"
15669      .foo {
15670        background-image: linear-gradient(90deg, red, blue);
15671      }
15672      "#,
15673      indoc! {r#"
15674      .foo {
15675        background-image: -webkit-gradient(linear, 0 0, 100% 0, from(red), to(#00f));
15676        background-image: -webkit-linear-gradient(0deg, red, #00f);
15677        background-image: linear-gradient(90deg, red, #00f);
15678      }
15679      "#},
15680      Browsers {
15681        chrome: Some(8 << 16),
15682        ..Browsers::default()
15683      },
15684    );
15685    prefix_test(
15686      r#"
15687      .foo {
15688        background-image: linear-gradient(45deg, red, blue);
15689      }
15690      "#,
15691      indoc! {r#"
15692      .foo {
15693        background-image: -webkit-linear-gradient(45deg, red, #00f);
15694        background-image: linear-gradient(45deg, red, #00f);
15695      }
15696      "#},
15697      Browsers {
15698        chrome: Some(8 << 16),
15699        ..Browsers::default()
15700      },
15701    );
15702    prefix_test(
15703      r#"
15704      .foo {
15705        background-image: linear-gradient(red, blue);
15706      }
15707      "#,
15708      indoc! {r#"
15709      .foo {
15710        background-image: -webkit-linear-gradient(top, red, #00f);
15711        background-image: linear-gradient(red, #00f);
15712      }
15713      "#},
15714      Browsers {
15715        chrome: Some(10 << 16),
15716        ..Browsers::default()
15717      },
15718    );
15719    prefix_test(
15720      r#"
15721      .foo {
15722        background-image: radial-gradient(20px, red, blue);
15723      }
15724      "#,
15725      indoc! {r#"
15726      .foo {
15727        background-image: -webkit-gradient(radial, center center, 0, center center, 20, from(red), to(#00f));
15728        background-image: -webkit-radial-gradient(20px, red, #00f);
15729        background-image: radial-gradient(20px, red, #00f);
15730      }
15731      "#},
15732      Browsers {
15733        chrome: Some(8 << 16),
15734        ..Browsers::default()
15735      },
15736    );
15737    prefix_test(
15738      r#"
15739      .foo {
15740        background-image: radial-gradient(20px at top left, red, blue);
15741      }
15742      "#,
15743      indoc! {r#"
15744      .foo {
15745        background-image: -webkit-gradient(radial, left top, 0, left top, 20, from(red), to(#00f));
15746        background-image: -webkit-radial-gradient(20px at 0 0, red, #00f);
15747        background-image: radial-gradient(20px at 0 0, red, #00f);
15748      }
15749      "#},
15750      Browsers {
15751        chrome: Some(8 << 16),
15752        ..Browsers::default()
15753      },
15754    );
15755    prefix_test(
15756      r#"
15757      .foo {
15758        background-image: radial-gradient(red, blue);
15759      }
15760      "#,
15761      indoc! {r#"
15762      .foo {
15763        background-image: -webkit-radial-gradient(red, #00f);
15764        background-image: radial-gradient(red, #00f);
15765      }
15766      "#},
15767      Browsers {
15768        chrome: Some(8 << 16),
15769        ..Browsers::default()
15770      },
15771    );
15772    prefix_test(
15773      r#"
15774      .foo {
15775        background-image: -webkit-gradient(radial, left top, 0, left top, 20, from(red), to(#00f));
15776        background-image: -webkit-radial-gradient(20px at 0% 0%, red, #00f);
15777        background-image: radial-gradient(20px at 0% 0%, red, #00f);
15778      }
15779      "#,
15780      indoc! {r#"
15781      .foo {
15782        background-image: radial-gradient(20px at 0 0, red, #00f);
15783      }
15784      "#},
15785      Browsers {
15786        chrome: Some(30 << 16),
15787        ..Browsers::default()
15788      },
15789    );
15790    prefix_test(
15791      r#"
15792      .foo {
15793        background: -webkit-gradient(radial, left top, 0, left top, 20, from(red), to(#00f));
15794        background: -webkit-radial-gradient(20px at 0% 0%, red, #00f);
15795        background: radial-gradient(20px at 0% 0%, red, #00f);
15796      }
15797      "#,
15798      indoc! {r#"
15799      .foo {
15800        background: radial-gradient(20px at 0 0, red, #00f);
15801      }
15802      "#},
15803      Browsers {
15804        chrome: Some(30 << 16),
15805        ..Browsers::default()
15806      },
15807    );
15808    prefix_test(
15809      r#"
15810      .foo {
15811        background: radial-gradient(red, blue);
15812      }
15813      "#,
15814      indoc! {r#"
15815      .foo {
15816        background: -webkit-radial-gradient(red, #00f);
15817        background: radial-gradient(red, #00f);
15818      }
15819      "#},
15820      Browsers {
15821        chrome: Some(8 << 16),
15822        ..Browsers::default()
15823      },
15824    );
15825    prefix_test(
15826      r#"
15827      .foo {
15828        background: radial-gradient(red, blue), linear-gradient(yellow, red), url(bg.jpg);
15829      }
15830      "#,
15831      indoc! {r#"
15832      .foo {
15833        background: -webkit-gradient(linear, 0 0, 0 100%, from(#ff0), to(red)), url("bg.jpg");
15834        background: -webkit-radial-gradient(red, #00f), -webkit-linear-gradient(top, #ff0, red), url("bg.jpg");
15835        background: -moz-radial-gradient(red, #00f), -moz-linear-gradient(top, #ff0, red), url("bg.jpg");
15836        background: -o-radial-gradient(red, #00f), -o-linear-gradient(top, #ff0, red), url("bg.jpg");
15837        background: radial-gradient(red, #00f), linear-gradient(#ff0, red), url("bg.jpg");
15838      }
15839      "#},
15840      Browsers {
15841        chrome: Some(8 << 16),
15842        firefox: Some(4 << 16),
15843        opera: Some(11 << 16 | 5 << 8),
15844        ..Browsers::default()
15845      },
15846    );
15847
15848    prefix_test(
15849      r#"
15850      .foo {
15851        background: linear-gradient(yellow, red 30% 40%, blue);
15852      }
15853      "#,
15854      indoc! {r#"
15855      .foo {
15856        background: linear-gradient(#ff0, red 30%, red 40%, #00f);
15857      }
15858      "#},
15859      Browsers {
15860        chrome: Some(70 << 16),
15861        ..Browsers::default()
15862      },
15863    );
15864
15865    prefix_test(
15866      r#"
15867      .foo {
15868        background: linear-gradient(yellow, red 30% 40%, blue);
15869      }
15870      "#,
15871      indoc! {r#"
15872      .foo {
15873        background: linear-gradient(#ff0, red 30% 40%, #00f);
15874      }
15875      "#},
15876      Browsers {
15877        chrome: Some(71 << 16),
15878        ..Browsers::default()
15879      },
15880    );
15881
15882    prefix_test(
15883      ".foo { background: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
15884      indoc! { r#"
15885        .foo {
15886          background: linear-gradient(#ff0b0c, #766eff);
15887          background: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
15888        }
15889      "#},
15890      Browsers {
15891        chrome: Some(90 << 16),
15892        ..Browsers::default()
15893      },
15894    );
15895
15896    prefix_test(
15897      ".foo { background: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
15898      indoc! { r#"
15899        .foo {
15900          background: linear-gradient(#ff0b0c, #766eff);
15901          background: linear-gradient(color(display-p3 1 .0000153435 -.00000303562), color(display-p3 .440289 .28452 1.23485));
15902          background: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
15903        }
15904      "#},
15905      Browsers {
15906        chrome: Some(90 << 16),
15907        safari: Some(14 << 16),
15908        ..Browsers::default()
15909      },
15910    );
15911
15912    prefix_test(
15913      ".foo { background: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
15914      indoc! { r#"
15915        .foo {
15916          background: -webkit-linear-gradient(top, #ff0b0c, #766eff);
15917          background: linear-gradient(#ff0b0c, #766eff);
15918          background: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
15919        }
15920      "#},
15921      Browsers {
15922        chrome: Some(20 << 16),
15923        ..Browsers::default()
15924      },
15925    );
15926
15927    prefix_test(
15928      ".foo { background: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
15929      indoc! { r#"
15930        .foo {
15931          background: -webkit-gradient(linear, 0 0, 0 100%, from(#ff0b0c), to(#766eff));
15932          background: -webkit-linear-gradient(top, #ff0b0c, #766eff);
15933          background: linear-gradient(#ff0b0c, #766eff);
15934          background: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
15935        }
15936      "#},
15937      Browsers {
15938        chrome: Some(8 << 16),
15939        ..Browsers::default()
15940      },
15941    );
15942
15943    prefix_test(
15944      ".foo { background: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
15945      indoc! { r#"
15946        .foo {
15947          background: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
15948        }
15949      "#},
15950      Browsers {
15951        safari: Some(15 << 16),
15952        ..Browsers::default()
15953      },
15954    );
15955
15956    prefix_test(
15957      ".foo { background-image: linear-gradient(oklab(59.686% 0.1009 0.1192), oklab(54.0% -0.10 -0.02)); }",
15958      indoc! { r#"
15959        .foo {
15960          background-image: linear-gradient(lab(52.2319% 40.1449 59.9171), lab(47.7776% -34.2947 -7.65904));
15961        }
15962      "#},
15963      Browsers {
15964        safari: Some(15 << 16),
15965        ..Browsers::default()
15966      },
15967    );
15968
15969    prefix_test(
15970      ".foo { background-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
15971      indoc! { r#"
15972        .foo {
15973          background-image: linear-gradient(#ff0b0c, #766eff);
15974          background-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
15975        }
15976      "#},
15977      Browsers {
15978        chrome: Some(90 << 16),
15979        ..Browsers::default()
15980      },
15981    );
15982
15983    prefix_test(
15984      ".foo { background-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
15985      indoc! { r#"
15986        .foo {
15987          background-image: linear-gradient(#ff0b0c, #766eff);
15988          background-image: linear-gradient(color(display-p3 1 .0000153435 -.00000303562), color(display-p3 .440289 .28452 1.23485));
15989          background-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
15990        }
15991      "#},
15992      Browsers {
15993        chrome: Some(90 << 16),
15994        safari: Some(14 << 16),
15995        ..Browsers::default()
15996      },
15997    );
15998
15999    prefix_test(
16000      ".foo { background-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
16001      indoc! { r#"
16002        .foo {
16003          background-image: -webkit-linear-gradient(top, #ff0b0c, #766eff);
16004          background-image: linear-gradient(#ff0b0c, #766eff);
16005          background-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
16006        }
16007      "#},
16008      Browsers {
16009        chrome: Some(20 << 16),
16010        ..Browsers::default()
16011      },
16012    );
16013
16014    prefix_test(
16015      ".foo { background-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
16016      indoc! { r#"
16017        .foo {
16018          background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ff0b0c), to(#766eff));
16019          background-image: -webkit-linear-gradient(top, #ff0b0c, #766eff);
16020          background-image: linear-gradient(#ff0b0c, #766eff);
16021          background-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
16022        }
16023      "#},
16024      Browsers {
16025        chrome: Some(8 << 16),
16026        ..Browsers::default()
16027      },
16028    );
16029
16030    prefix_test(
16031      ".foo { background-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
16032      indoc! { r#"
16033        .foo {
16034          background-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
16035        }
16036      "#},
16037      Browsers {
16038        safari: Some(15 << 16),
16039        ..Browsers::default()
16040      },
16041    );
16042
16043    prefix_test(
16044      ".foo { background-image: linear-gradient(oklab(59.686% 0.1009 0.1192), oklab(54.0% -0.10 -0.02)); }",
16045      indoc! { r#"
16046        .foo {
16047          background-image: linear-gradient(lab(52.2319% 40.1449 59.9171), lab(47.7776% -34.2947 -7.65904));
16048        }
16049      "#},
16050      Browsers {
16051        safari: Some(15 << 16),
16052        ..Browsers::default()
16053      },
16054    );
16055
16056    // Test cases from https://github.com/postcss/autoprefixer/blob/541295c0e6dd348db2d3f52772b59cd403c59d29/test/cases/gradient.css
16057    prefix_test(
16058      r#"
16059        a {
16060          background: linear-gradient(350.5deg, white, black), linear-gradient(-130deg, black, white), linear-gradient(45deg, black, white);
16061        }
16062        b {
16063          background-image: linear-gradient(rgba(0,0,0,1), white), linear-gradient(white, black);
16064        }
16065        strong {
16066          background: linear-gradient(to top, transparent, rgba(0, 0, 0, 0.8) 20px, #000 30px, #000) no-repeat;
16067        }
16068        div {
16069          background-image: radial-gradient(to left, white, black), repeating-linear-gradient(to bottom right, black, white), repeating-radial-gradient(to top, aqua, red);
16070        }
16071        .old-radial {
16072          background: radial-gradient(0 50%, ellipse farthest-corner, black, white);
16073        }
16074        .simple1 {
16075          background: linear-gradient(black, white);
16076        }
16077        .simple2 {
16078          background: linear-gradient(to left, black 0%, rgba(0, 0, 0, 0.5)50%, white 100%);
16079        }
16080        .simple3 {
16081          background: linear-gradient(to left, black 50%, white 100%);
16082        }
16083        .simple4 {
16084          background: linear-gradient(to right top, black, white);
16085        }
16086        .direction {
16087          background: linear-gradient(top left, black, rgba(0, 0, 0, 0.5), white);
16088        }
16089        .silent {
16090          background: -webkit-linear-gradient(top left, black, white);
16091        }
16092        .radial {
16093          background: radial-gradient(farthest-side at 0 50%, white, black);
16094        }
16095        .second {
16096          background: red linear-gradient(red, blue);
16097          background: url('logo.png'), linear-gradient(#fff, #000);
16098        }
16099        .px {
16100          background: linear-gradient(black 0, white 100px);
16101        }
16102        .list {
16103          list-style-image: linear-gradient(white, black);
16104        }
16105        .mask {
16106          mask: linear-gradient(white, black);
16107        }
16108        .newline {
16109          background-image:
16110              linear-gradient( white, black ),
16111              linear-gradient( black, white );
16112        }
16113        .convert {
16114          background: linear-gradient(0deg, white, black);
16115          background: linear-gradient(90deg, white, black);
16116          background: linear-gradient(180deg, white, black);
16117          background: linear-gradient(270deg, white, black);
16118        }
16119        .grad {
16120          background: linear-gradient(1grad, white, black);
16121        }
16122        .rad {
16123          background: linear-gradient(1rad, white, black);
16124        }
16125        .turn {
16126          background: linear-gradient(0.3turn, white, black);
16127        }
16128        .norm {
16129          background: linear-gradient(-90deg, white, black);
16130        }
16131        .mask {
16132          mask-image: radial-gradient(circle at 86% 86%, transparent 8px, black 8px);
16133        }
16134        .cover {
16135          background: radial-gradient(ellipse cover at center, white, black);
16136        }
16137        .contain {
16138          background: radial-gradient(contain at center, white, black);
16139        }
16140        .no-div {
16141          background: linear-gradient(black);
16142        }
16143        .background-shorthand {
16144          background: radial-gradient(#FFF, transparent) 0 0 / cover no-repeat #F0F;
16145        }
16146        .background-advanced {
16147          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%),
16148                      radial-gradient(#FFF, transparent),
16149                      url(path/to/image.jpg) 50%/cover;
16150        }
16151        .multiradial {
16152          mask-image: radial-gradient(circle closest-corner at 100% 50%, #000, transparent);
16153        }
16154        .broken {
16155          mask-image: radial-gradient(white, black);
16156        }
16157        .loop {
16158          background-image: url("https://test.com/lol(test.png"), radial-gradient(yellow, black, yellow);
16159        }
16160        .unitless-zero {
16161          background-image: linear-gradient(0, green, blue);
16162          background: repeating-linear-gradient(0, blue, red 33.3%)
16163        }
16164        .zero-grad {
16165          background: linear-gradient(0grad, green, blue);
16166          background-image: repeating-linear-gradient(0grad, blue, red 33.3%)
16167        }
16168        .zero-rad {
16169          background: linear-gradient(0rad, green, blue);
16170        }
16171        .zero-turn {
16172          background: linear-gradient(0turn, green, blue);
16173        }
16174      "#,
16175      indoc! { r#"
16176        a {
16177          background: -webkit-linear-gradient(99.5deg, #fff, #000), -webkit-linear-gradient(220deg, #000, #fff), -webkit-linear-gradient(45deg, #000, #fff);
16178          background: -o-linear-gradient(99.5deg, #fff, #000), -o-linear-gradient(220deg, #000, #fff), -o-linear-gradient(45deg, #000, #fff);
16179          background: linear-gradient(350.5deg, #fff, #000), linear-gradient(-130deg, #000, #fff), linear-gradient(45deg, #000, #fff);
16180        }
16181
16182        b {
16183          background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#000), to(#fff)), -webkit-gradient(linear, 0 0, 0 100%, from(#fff), to(#000));
16184          background-image: -webkit-linear-gradient(top, #000, #fff), -webkit-linear-gradient(top, #fff, #000);
16185          background-image: -o-linear-gradient(top, #000, #fff), -o-linear-gradient(top, #fff, #000);
16186          background-image: linear-gradient(#000, #fff), linear-gradient(#fff, #000);
16187        }
16188
16189        strong {
16190          background: -webkit-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, .8) 20px, #000 30px, #000) no-repeat;
16191          background: -o-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, .8) 20px, #000 30px, #000) no-repeat;
16192          background: linear-gradient(to top, rgba(0, 0, 0, 0), rgba(0, 0, 0, .8) 20px, #000 30px, #000) no-repeat;
16193        }
16194
16195        div {
16196          background-image: radial-gradient(to left, white, black), repeating-linear-gradient(to bottom right, black, white), repeating-radial-gradient(to top, aqua, red);
16197        }
16198
16199        .old-radial {
16200          background: radial-gradient(0 50%, ellipse farthest-corner, black, white);
16201        }
16202
16203        .simple1 {
16204          background: -webkit-gradient(linear, 0 0, 0 100%, from(#000), to(#fff));
16205          background: -webkit-linear-gradient(top, #000, #fff);
16206          background: -o-linear-gradient(top, #000, #fff);
16207          background: linear-gradient(#000, #fff);
16208        }
16209
16210        .simple2 {
16211          background: -webkit-gradient(linear, 100% 0, 0 0, from(#000), color-stop(.5, rgba(0, 0, 0, .5)), to(#fff));
16212          background: -webkit-linear-gradient(right, #000 0%, rgba(0, 0, 0, .5) 50%, #fff 100%);
16213          background: -o-linear-gradient(right, #000 0%, rgba(0, 0, 0, .5) 50%, #fff 100%);
16214          background: linear-gradient(to left, #000 0%, rgba(0, 0, 0, .5) 50%, #fff 100%);
16215        }
16216
16217        .simple3 {
16218          background: -webkit-gradient(linear, 100% 0, 0 0, color-stop(.5, #000), to(#fff));
16219          background: -webkit-linear-gradient(right, #000 50%, #fff 100%);
16220          background: -o-linear-gradient(right, #000 50%, #fff 100%);
16221          background: linear-gradient(to left, #000 50%, #fff 100%);
16222        }
16223
16224        .simple4 {
16225          background: -webkit-gradient(linear, 0 100%, 100% 0, from(#000), to(#fff));
16226          background: -webkit-linear-gradient(bottom left, #000, #fff);
16227          background: -o-linear-gradient(bottom left, #000, #fff);
16228          background: linear-gradient(to top right, #000, #fff);
16229        }
16230
16231        .direction {
16232          background: linear-gradient(top left, black, rgba(0, 0, 0, .5), white);
16233        }
16234
16235        .silent {
16236          background: -webkit-gradient(linear, 100% 100%, 0 0, from(#000), to(#fff));
16237          background: -webkit-linear-gradient(top left, #000, #fff);
16238        }
16239
16240        .radial {
16241          background: -webkit-radial-gradient(farthest-side at 0, #fff, #000);
16242          background: -o-radial-gradient(farthest-side at 0, #fff, #000);
16243          background: radial-gradient(farthest-side at 0, #fff, #000);
16244        }
16245
16246        .second {
16247          background: red -webkit-gradient(linear, 0 0, 0 100%, from(red), to(#00f));
16248          background: red -webkit-linear-gradient(top, red, #00f);
16249          background: red -o-linear-gradient(top, red, #00f);
16250          background: red linear-gradient(red, #00f);
16251          background: url("logo.png"), linear-gradient(#fff, #000);
16252        }
16253
16254        .px {
16255          background: -webkit-linear-gradient(top, #000 0, #fff 100px);
16256          background: -o-linear-gradient(top, #000 0, #fff 100px);
16257          background: linear-gradient(#000 0, #fff 100px);
16258        }
16259
16260        .list {
16261          list-style-image: -webkit-gradient(linear, 0 0, 0 100%, from(#fff), to(#000));
16262          list-style-image: -webkit-linear-gradient(top, #fff, #000);
16263          list-style-image: -o-linear-gradient(top, #fff, #000);
16264          list-style-image: linear-gradient(#fff, #000);
16265        }
16266
16267        .mask {
16268          -webkit-mask: -webkit-gradient(linear, 0 0, 0 100%, from(#fff), to(#000));
16269          -webkit-mask: -webkit-linear-gradient(top, #fff, #000);
16270          -webkit-mask: -o-linear-gradient(top, #fff, #000);
16271          mask: -o-linear-gradient(top, #fff, #000);
16272          -webkit-mask: linear-gradient(#fff, #000);
16273          mask: linear-gradient(#fff, #000);
16274        }
16275
16276        .newline {
16277          background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#fff), to(#000)), -webkit-gradient(linear, 0 0, 0 100%, from(#000), to(#fff));
16278          background-image: -webkit-linear-gradient(top, #fff, #000), -webkit-linear-gradient(top, #000, #fff);
16279          background-image: -o-linear-gradient(top, #fff, #000), -o-linear-gradient(top, #000, #fff);
16280          background-image: linear-gradient(#fff, #000), linear-gradient(#000, #fff);
16281        }
16282
16283        .convert {
16284          background: -webkit-gradient(linear, 0 100%, 0 0, from(#fff), to(#000));
16285          background: -webkit-linear-gradient(90deg, #fff, #000);
16286          background: -o-linear-gradient(90deg, #fff, #000);
16287          background: linear-gradient(0deg, #fff, #000);
16288          background: linear-gradient(90deg, #fff, #000);
16289          background: linear-gradient(#fff, #000);
16290          background: linear-gradient(270deg, #fff, #000);
16291        }
16292
16293        .grad {
16294          background: -webkit-linear-gradient(89.1deg, #fff, #000);
16295          background: -o-linear-gradient(89.1deg, #fff, #000);
16296          background: linear-gradient(1grad, #fff, #000);
16297        }
16298
16299        .rad {
16300          background: -webkit-linear-gradient(32.704deg, #fff, #000);
16301          background: -o-linear-gradient(32.704deg, #fff, #000);
16302          background: linear-gradient(57.2958deg, #fff, #000);
16303        }
16304
16305        .turn {
16306          background: -webkit-linear-gradient(342deg, #fff, #000);
16307          background: -o-linear-gradient(342deg, #fff, #000);
16308          background: linear-gradient(.3turn, #fff, #000);
16309        }
16310
16311        .norm {
16312          background: -webkit-linear-gradient(#fff, #000);
16313          background: -o-linear-gradient(#fff, #000);
16314          background: linear-gradient(-90deg, #fff, #000);
16315        }
16316
16317        .mask {
16318          -webkit-mask-image: -webkit-radial-gradient(circle at 86% 86%, rgba(0, 0, 0, 0) 8px, #000 8px);
16319          -webkit-mask-image: -o-radial-gradient(circle at 86% 86%, rgba(0, 0, 0, 0) 8px, #000 8px);
16320          mask-image: -o-radial-gradient(circle at 86% 86%, rgba(0, 0, 0, 0) 8px, #000 8px);
16321          -webkit-mask-image: radial-gradient(circle at 86% 86%, rgba(0, 0, 0, 0) 8px, #000 8px);
16322          mask-image: radial-gradient(circle at 86% 86%, rgba(0, 0, 0, 0) 8px, #000 8px);
16323        }
16324
16325        .cover {
16326          background: radial-gradient(ellipse cover at center, white, black);
16327        }
16328
16329        .contain {
16330          background: radial-gradient(contain at center, white, black);
16331        }
16332
16333        .no-div {
16334          background: -webkit-gradient(linear, 0 0, 0 100%, from(#000));
16335          background: -webkit-linear-gradient(top, #000);
16336          background: -o-linear-gradient(top, #000);
16337          background: linear-gradient(#000);
16338        }
16339
16340        .background-shorthand {
16341          background: #f0f -webkit-radial-gradient(#fff, rgba(0, 0, 0, 0)) 0 0 / cover no-repeat;
16342          background: #f0f -o-radial-gradient(#fff, rgba(0, 0, 0, 0)) 0 0 / cover no-repeat;
16343          background: #f0f radial-gradient(#fff, rgba(0, 0, 0, 0)) 0 0 / cover no-repeat;
16344        }
16345
16346        .background-advanced {
16347          background: url("path/to/image.jpg") 50% / cover;
16348          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;
16349          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;
16350          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;
16351        }
16352
16353        .multiradial {
16354          -webkit-mask-image: -webkit-radial-gradient(circle closest-corner at 100%, #000, rgba(0, 0, 0, 0));
16355          -webkit-mask-image: -o-radial-gradient(circle closest-corner at 100%, #000, rgba(0, 0, 0, 0));
16356          mask-image: -o-radial-gradient(circle closest-corner at 100%, #000, rgba(0, 0, 0, 0));
16357          -webkit-mask-image: radial-gradient(circle closest-corner at 100%, #000, rgba(0, 0, 0, 0));
16358          mask-image: radial-gradient(circle closest-corner at 100%, #000, rgba(0, 0, 0, 0));
16359        }
16360
16361        .broken {
16362          -webkit-mask-image: -webkit-radial-gradient(#fff, #000);
16363          -webkit-mask-image: -o-radial-gradient(#fff, #000);
16364          mask-image: -o-radial-gradient(#fff, #000);
16365          -webkit-mask-image: radial-gradient(#fff, #000);
16366          mask-image: radial-gradient(#fff, #000);
16367        }
16368
16369        .loop {
16370          background-image: url("https://test.com/lol(test.png");
16371          background-image: url("https://test.com/lol(test.png"), -webkit-radial-gradient(#ff0, #000, #ff0);
16372          background-image: url("https://test.com/lol(test.png"), -o-radial-gradient(#ff0, #000, #ff0);
16373          background-image: url("https://test.com/lol(test.png"), radial-gradient(#ff0, #000, #ff0);
16374        }
16375
16376        .unitless-zero {
16377          background-image: -webkit-gradient(linear, 0 100%, 0 0, from(green), to(#00f));
16378          background-image: -webkit-linear-gradient(90deg, green, #00f);
16379          background-image: -o-linear-gradient(90deg, green, #00f);
16380          background-image: linear-gradient(0deg, green, #00f);
16381          background: repeating-linear-gradient(0deg, #00f, red 33.3%);
16382        }
16383
16384        .zero-grad {
16385          background: -webkit-gradient(linear, 0 100%, 0 0, from(green), to(#00f));
16386          background: -webkit-linear-gradient(90deg, green, #00f);
16387          background: -o-linear-gradient(90deg, green, #00f);
16388          background: linear-gradient(0grad, green, #00f);
16389          background-image: repeating-linear-gradient(0grad, #00f, red 33.3%);
16390        }
16391
16392        .zero-rad, .zero-turn {
16393          background: -webkit-gradient(linear, 0 100%, 0 0, from(green), to(#00f));
16394          background: -webkit-linear-gradient(90deg, green, #00f);
16395          background: -o-linear-gradient(90deg, green, #00f);
16396          background: linear-gradient(0deg, green, #00f);
16397        }
16398      "#},
16399      Browsers {
16400        chrome: Some(25 << 16),
16401        opera: Some(12 << 16),
16402        android: Some(2 << 16 | 3 << 8),
16403        ..Browsers::default()
16404      },
16405    );
16406  }
16407
16408  #[test]
16409  fn test_font_face() {
16410    minify_test(
16411      r#"@font-face {
16412      src: url("test.woff");
16413      font-family: "Helvetica";
16414      font-weight: bold;
16415      font-style: italic;
16416    }"#,
16417      "@font-face{src:url(test.woff);font-family:Helvetica;font-weight:700;font-style:italic}",
16418    );
16419    minify_test("@font-face {src: url(test.woff);}", "@font-face{src:url(test.woff)}");
16420    minify_test("@font-face {src: local(\"Test\");}", "@font-face{src:local(Test)}");
16421    minify_test(
16422      "@font-face {src: local(\"Foo Bar\");}",
16423      "@font-face{src:local(Foo Bar)}",
16424    );
16425    minify_test("@font-face {src: local(Test);}", "@font-face{src:local(Test)}");
16426    minify_test("@font-face {src: local(Foo Bar);}", "@font-face{src:local(Foo Bar)}");
16427
16428    minify_test(
16429      "@font-face {src: url(\"test.woff\") format(woff);}",
16430      "@font-face{src:url(test.woff)format(\"woff\")}",
16431    );
16432    minify_test(
16433      "@font-face {src: url(\"test.ttc\") format(collection), url(test.ttf) format(truetype);}",
16434      "@font-face{src:url(test.ttc)format(\"collection\"),url(test.ttf)format(\"truetype\")}",
16435    );
16436    minify_test(
16437      "@font-face {src: url(\"test.otf\") format(opentype) tech(features-aat);}",
16438      "@font-face{src:url(test.otf)format(\"opentype\")tech(features-aat)}",
16439    );
16440    minify_test(
16441      "@font-face {src: url(\"test.woff\") format(woff) tech(color-colrv1);}",
16442      "@font-face{src:url(test.woff)format(\"woff\")tech(color-colrv1)}",
16443    );
16444    minify_test(
16445      "@font-face {src: url(\"test.woff2\") format(woff2) tech(variations);}",
16446      "@font-face{src:url(test.woff2)format(\"woff2\")tech(variations)}",
16447    );
16448    minify_test(
16449      "@font-face {src: url(\"test.woff\") format(woff) tech(palettes);}",
16450      "@font-face{src:url(test.woff)format(\"woff\")tech(palettes)}",
16451    );
16452    // multiple tech
16453    minify_test(
16454      "@font-face {src: url(\"test.woff\") format(woff) tech(features-opentype, color-sbix);}",
16455      "@font-face{src:url(test.woff)format(\"woff\")tech(features-opentype,color-sbix)}",
16456    );
16457    minify_test(
16458      "@font-face {src: url(\"test.woff\")   format(woff)    tech(incremental, color-svg, features-graphite, features-aat);}",
16459      "@font-face{src:url(test.woff)format(\"woff\")tech(incremental,color-svg,features-graphite,features-aat)}",
16460    );
16461    // format() function must precede tech() if both are present
16462    minify_test(
16463      "@font-face {src: url(\"foo.ttf\") format(opentype) tech(color-colrv1);}",
16464      "@font-face{src:url(foo.ttf)format(\"opentype\")tech(color-colrv1)}",
16465    );
16466    // only have tech is valid
16467    minify_test(
16468      "@font-face {src: url(\"foo.ttf\") tech(color-SVG);}",
16469      "@font-face{src:url(foo.ttf)tech(color-svg)}",
16470    );
16471    // CGQAQ: if tech and format both presence, order is matter, tech before format is invalid
16472    // but now just return raw token, we don't have strict mode yet.
16473    // ref: https://github.com/parcel-bundler/lightningcss/pull/255#issuecomment-1219049998
16474    minify_test(
16475      "@font-face {src: url(\"foo.ttf\") tech(palettes  color-colrv0  variations) format(opentype);}",
16476      "@font-face{src:url(foo.ttf) tech(palettes color-colrv0 variations) format(opentype)}",
16477    );
16478    // TODO(CGQAQ): make this test pass when we have strict mode
16479    // ref: https://github.com/web-platform-tests/wpt/blob/9f8a6ccc41aa725e8f51f4f096f686313bb88d8d/css/css-fonts/parsing/font-face-src-tech.html#L45
16480    // error_test(
16481    //   "@font-face {src: url(\"foo.ttf\") tech(features-opentype) format(opentype);}",
16482    //   ParserError::AtRuleBodyInvalid,
16483    // );
16484    // error_test(
16485    //   "@font-face {src: url(\"foo.ttf\") tech();}",
16486    //   ParserError::AtRuleBodyInvalid,
16487    // );
16488    // error_test(
16489    //   "@font-face {src: url(\"foo.ttf\") tech(\"features-opentype\");}",
16490    //   ParserError::AtRuleBodyInvalid,
16491    // );
16492    // error_test(
16493    //   "@font-face {src: url(\"foo.ttf\") tech(\"color-colrv0\");}",
16494    //   ParserError::AtRuleBodyInvalid,
16495    // );
16496    minify_test(
16497      "@font-face {src: local(\"\") url(\"test.woff\");}",
16498      "@font-face{src:local(\"\") url(test.woff)}",
16499    );
16500    minify_test("@font-face {font-weight: 200 400}", "@font-face{font-weight:200 400}");
16501    minify_test("@font-face {font-weight: 400 400}", "@font-face{font-weight:400}");
16502    minify_test(
16503      "@font-face {font-stretch: 50% 200%}",
16504      "@font-face{font-stretch:50% 200%}",
16505    );
16506    minify_test("@font-face {font-stretch: 50% 50%}", "@font-face{font-stretch:50%}");
16507    minify_test("@font-face {unicode-range: U+26;}", "@font-face{unicode-range:U+26}");
16508    minify_test("@font-face {unicode-range: u+26;}", "@font-face{unicode-range:U+26}");
16509    minify_test(
16510      "@font-face {unicode-range: U+0-7F;}",
16511      "@font-face{unicode-range:U+0-7F}",
16512    );
16513    minify_test(
16514      "@font-face {unicode-range: U+0025-00FF;}",
16515      "@font-face{unicode-range:U+25-FF}",
16516    );
16517    minify_test("@font-face {unicode-range: U+4??;}", "@font-face{unicode-range:U+4??}");
16518    minify_test(
16519      "@font-face {unicode-range: U+400-4FF;}",
16520      "@font-face{unicode-range:U+4??}",
16521    );
16522    minify_test(
16523      "@font-face {unicode-range: U+0025-00FF, U+4??;}",
16524      "@font-face{unicode-range:U+25-FF,U+4??}",
16525    );
16526    minify_test(
16527      "@font-face {unicode-range: U+A5, U+4E00-9FFF, U+30??, U+FF00-FF9F;}",
16528      "@font-face{unicode-range:U+A5,U+4E00-9FFF,U+30??,U+FF00-FF9F}",
16529    );
16530    minify_test(
16531      "@font-face {unicode-range: U+????;}",
16532      "@font-face{unicode-range:U+????}",
16533    );
16534    minify_test(
16535      "@font-face {unicode-range: U+0000-FFFF;}",
16536      "@font-face{unicode-range:U+????}",
16537    );
16538    minify_test(
16539      "@font-face {unicode-range: U+10????;}",
16540      "@font-face{unicode-range:U+10????}",
16541    );
16542    minify_test(
16543      "@font-face {unicode-range: U+100000-10FFFF;}",
16544      "@font-face{unicode-range:U+10????}",
16545    );
16546    minify_test(
16547      "@font-face {unicode-range: U+1e1e?;}",
16548      "@font-face{unicode-range:U+1E1E?}",
16549    );
16550    minify_test(
16551      "@font-face {unicode-range: u+????, U+1????, U+10????;}",
16552      "@font-face{unicode-range:U+????,U+1????,U+10????}",
16553    );
16554    minify_test(r#"
16555      @font-face {
16556        font-family: Inter;
16557        font-style: oblique 0deg 10deg;
16558        font-weight: 100 900;
16559        src: url("../fonts/Inter.var.woff2?v=3.19") format("woff2");
16560        font-display: swap;
16561      }
16562    "#, "@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}");
16563    minify_test(r#"
16564    @font-face {
16565      font-family: Inter;
16566      font-style: oblique 14deg 14deg;
16567      font-weight: 100 900;
16568      src: url("../fonts/Inter.var.woff2?v=3.19") format("woff2");
16569      font-display: swap;
16570    }
16571  "#, "@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}");
16572  }
16573
16574  #[test]
16575  fn test_font_palette_values() {
16576    minify_test(
16577      r#"@font-palette-values --Cooler {
16578      font-family: Bixa;
16579      base-palette: 1;
16580      override-colors: 1 #7EB7E4;
16581    }"#,
16582      "@font-palette-values --Cooler{font-family:Bixa;base-palette:1;override-colors:1 #7eb7e4}",
16583    );
16584    minify_test(
16585      r#"@font-palette-values --Cooler {
16586      font-family: Handover Sans;
16587      base-palette: 3;
16588      override-colors: 1 rgb(43, 12, 9), 3 lime;
16589    }"#,
16590      "@font-palette-values --Cooler{font-family:Handover Sans;base-palette:3;override-colors:1 #2b0c09,3 #0f0}",
16591    );
16592    minify_test(r#"@font-palette-values --Cooler {
16593      font-family: Handover Sans;
16594      base-palette: 3;
16595      override-colors: 1 rgb(43, 12, 9), 3 var(--highlight);
16596    }"#, "@font-palette-values --Cooler{font-family:Handover Sans;base-palette:3;override-colors:1 #2b0c09, 3 var(--highlight)}");
16597    prefix_test(
16598      r#"@font-palette-values --Cooler {
16599      font-family: Handover Sans;
16600      base-palette: 3;
16601      override-colors: 1 rgb(43, 12, 9), 3 lch(50.998% 135.363 338);
16602    }"#,
16603      indoc! {r#"@font-palette-values --Cooler {
16604      font-family: Handover Sans;
16605      base-palette: 3;
16606      override-colors: 1 #2b0c09, 3 #f000c0;
16607      override-colors: 1 #2b0c09, 3 lch(50.998% 135.363 338);
16608    }
16609    "#},
16610      Browsers {
16611        chrome: Some(90 << 16),
16612        ..Browsers::default()
16613      },
16614    );
16615    prefix_test(
16616      r#"@font-palette-values --Cooler {
16617      font-family: Handover Sans;
16618      base-palette: 3;
16619      override-colors: 1 var(--foo), 3 lch(50.998% 135.363 338);
16620    }"#,
16621      indoc! {r#"@font-palette-values --Cooler {
16622      font-family: Handover Sans;
16623      base-palette: 3;
16624      override-colors: 1 var(--foo), 3 #f000c0;
16625    }
16626
16627    @supports (color: lab(0% 0 0)) {
16628      @font-palette-values --Cooler {
16629        font-family: Handover Sans;
16630        base-palette: 3;
16631        override-colors: 1 var(--foo), 3 lab(50.998% 125.506 -50.7078);
16632      }
16633    }
16634    "#},
16635      Browsers {
16636        chrome: Some(90 << 16),
16637        ..Browsers::default()
16638      },
16639    );
16640    prefix_test(
16641      r#"@supports (color: lab(0% 0 0)) {
16642      @font-palette-values --Cooler {
16643        font-family: Handover Sans;
16644        base-palette: 3;
16645        override-colors: 1 var(--foo), 3 lab(50.998% 125.506 -50.7078);
16646      }
16647    }"#,
16648      indoc! {r#"@supports (color: lab(0% 0 0)) {
16649      @font-palette-values --Cooler {
16650        font-family: Handover Sans;
16651        base-palette: 3;
16652        override-colors: 1 var(--foo), 3 lab(50.998% 125.506 -50.7078);
16653      }
16654    }
16655    "#},
16656      Browsers {
16657        chrome: Some(90 << 16),
16658        ..Browsers::default()
16659      },
16660    );
16661    minify_test(".foo { font-palette: --Custom; }", ".foo{font-palette:--Custom}");
16662  }
16663
16664  #[test]
16665  fn test_position_try() {
16666    minify_test(
16667      r#"@position-try --outside-right-to-bottom {
16668        left: anchor(left);
16669        margin: 0;
16670        width: auto;
16671      }"#,
16672      "@position-try --outside-right-to-bottom{left:anchor(left);margin:0;width:auto}",
16673    );
16674    test(
16675      r#"@position-try --foo {
16676  top: anchor(bottom);
16677  left: anchor(right);
16678}"#,
16679      indoc! {r#"
16680        @position-try --foo {
16681          top: anchor(bottom);
16682          left: anchor(right);
16683        }
16684      "#},
16685    );
16686    // Nested inside @supports
16687    minify_test(
16688      r#"@supports (anchor-name: --foo) {
16689        @position-try --bar {
16690          top: anchor(bottom);
16691        }
16692      }"#,
16693      "@supports (anchor-name:--foo){@position-try --bar{top:anchor(bottom)}}",
16694    );
16695  }
16696
16697  #[test]
16698  fn test_font_feature_values() {
16699    // https://github.com/clagnut/TODS/blob/e693d52ad411507b960cf01a9734265e3efab102/tods.css#L116-L142
16700    minify_test(
16701      r#"
16702@font-feature-values "Fancy Font Name" {
16703  @styleset { cursive: 1; swoopy: 7 16; }
16704  @character-variant { ampersand: 1; capital-q: 2; }
16705  @stylistic { two-story-g: 1; straight-y: 2; }
16706  @swash { swishy: 1; flowing: 2; }
16707  @ornaments { clover: 1; fleuron: 2; }
16708  @annotation { circled: 1; boxed: 2; }
16709}
16710    "#,
16711      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}}"#,
16712    );
16713
16714    // https://github.com/Sorixelle/srxl.me/blob/4eb4f4a15cb2d21356df24c096d6a819cfdc1a99/public/fonts/inter/inter.css#L201-L222
16715    minify_test(
16716      r#"
16717@font-feature-values "Inter", "Inter var", "Inter var experimental" {
16718  @styleset {
16719    open-digits: 1;
16720    disambiguation: 2;
16721    curved-r: 3;
16722    disambiguation-without-zero: 4;
16723  }
16724
16725  @character-variant {
16726    alt-one: 1;
16727    open-four: 2;
16728    open-six: 3;
16729    open-nine: 4;
16730    lower-l-with-tail: 5;
16731    curved-lower-r: 6;
16732    german-double-s: 7;
16733    upper-i-with-serif: 8;
16734    flat-top-three: 9;
16735    upper-g-with-spur: 10;
16736    single-storey-a: 11;
16737  }
16738}
16739      "#,
16740      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}}"#,
16741    );
16742
16743    // https://github.com/MihailJP/Inconsolata-LGC/blob/7c53cf455787096c93d82d9a51018f12ec39a6e9/Inconsolata-LGC.css#L65-L91
16744    minify_test(
16745      r#"
16746@font-feature-values "Inconsolata LGC" {
16747	@styleset {
16748		alternative-umlaut: 1;
16749	}
16750	@character-variant {
16751		zero-plain: 1 1;
16752		zero-dotted: 1 2;
16753		zero-longslash: 1 3;
16754		r-with-serif: 2 1;
16755		eng-descender: 3 1;
16756		eng-uppercase: 3 2;
16757		dollar-open: 4 1;
16758		dollar-oldstyle: 4 2;
16759		dollar-cifrao: 4 2;
16760		ezh-no-descender: 5 1;
16761		ezh-reversed-sigma: 5 2;
16762		triangle-text-form: 6 1;
16763		el-with-hook-old: 7 1;
16764		qa-enlarged-lowercase: 8 1;
16765		qa-reversed-p: 8 2;
16766		che-with-hook: 9 1;
16767		che-with-hook-alt: 9 2;
16768		ge-with-hook: 10 1;
16769		ge-with-hook-alt: 10 2;
16770		ge-with-stroke-and-descender: 11 1;
16771	}
16772}
16773    "#,
16774      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}}"#,
16775    );
16776
16777    minify_test(
16778      r#"
16779      @font-feature-values "Fancy Font Name" {
16780        @styleset { cursive: 1; swoopy: 7 16; }
16781        @character-variant { ampersand: 1; capital-q: 2; }
16782      }
16783      "#,
16784      r#"@font-feature-values Fancy Font Name{@styleset{cursive:1;swoopy:7 16}@character-variant{ampersand:1;capital-q:2}}"#,
16785    );
16786    minify_test(
16787      r#"
16788      @font-feature-values foo {
16789          @swash { pretty: 0; pretty: 1; cool: 2; }
16790      }
16791      "#,
16792      "@font-feature-values foo{@swash{pretty:1;cool:2}}",
16793    );
16794    minify_test(
16795      r#"
16796      @font-feature-values foo {
16797          @swash { pretty: 1; }
16798          @swash { cool: 2; }
16799      }
16800      "#,
16801      "@font-feature-values foo{@swash{pretty:1;cool:2}}",
16802    );
16803    minify_test(
16804      r#"
16805      @font-feature-values foo {
16806          @swash { pretty: 1; }
16807      }
16808      @font-feature-values foo {
16809          @swash { cool: 2; }
16810      }
16811      "#,
16812      "@font-feature-values foo{@swash{pretty:1;cool:2}}",
16813    );
16814  }
16815
16816  #[test]
16817  fn test_page_rule() {
16818    minify_test("@page {margin: 0.5cm}", "@page{margin:.5cm}");
16819    minify_test("@page :left {margin: 0.5cm}", "@page:left{margin:.5cm}");
16820    minify_test("@page :right {margin: 0.5cm}", "@page:right{margin:.5cm}");
16821    minify_test(
16822      "@page LandscapeTable {margin: 0.5cm}",
16823      "@page LandscapeTable{margin:.5cm}",
16824    );
16825    minify_test(
16826      "@page CompanyLetterHead:first {margin: 0.5cm}",
16827      "@page CompanyLetterHead:first{margin:.5cm}",
16828    );
16829    minify_test("@page:first {margin: 0.5cm}", "@page:first{margin:.5cm}");
16830    minify_test("@page :blank:first {margin: 0.5cm}", "@page:blank:first{margin:.5cm}");
16831    minify_test("@page toc, index {margin: 0.5cm}", "@page toc,index{margin:.5cm}");
16832    minify_test(
16833      r#"
16834    @page :right {
16835      @bottom-left {
16836        margin: 10pt;
16837      }
16838    }
16839    "#,
16840      "@page:right{@bottom-left{margin:10pt}}",
16841    );
16842    minify_test(
16843      r#"
16844    @page :right {
16845      margin: 1in;
16846
16847      @bottom-left {
16848        margin: 10pt;
16849      }
16850    }
16851    "#,
16852      "@page:right{margin:1in;@bottom-left{margin:10pt}}",
16853    );
16854
16855    test(
16856      r#"
16857    @page :right {
16858      @bottom-left {
16859        margin: 10pt;
16860      }
16861    }
16862    "#,
16863      indoc! {r#"
16864      @page :right {
16865        @bottom-left {
16866          margin: 10pt;
16867        }
16868      }
16869      "#},
16870    );
16871
16872    test(
16873      r#"
16874    @page :right {
16875      margin: 1in;
16876
16877      @bottom-left-corner { content: "Foo"; }
16878      @bottom-right-corner { content: "Bar"; }
16879    }
16880    "#,
16881      indoc! {r#"
16882      @page :right {
16883        margin: 1in;
16884
16885        @bottom-left-corner {
16886          content: "Foo";
16887        }
16888
16889        @bottom-right-corner {
16890          content: "Bar";
16891        }
16892      }
16893      "#},
16894    );
16895
16896    error_test(
16897      r#"
16898      @page {
16899        @foo {
16900          margin: 1in;
16901        }
16902      }
16903      "#,
16904      ParserError::AtRuleInvalid("foo".into()),
16905    );
16906
16907    error_test(
16908      r#"
16909      @page {
16910        @top-left-corner {
16911          @bottom-left {
16912            margin: 1in;
16913          }
16914        }
16915      }
16916      "#,
16917      ParserError::AtRuleInvalid("bottom-left".into()),
16918    );
16919  }
16920
16921  #[test]
16922  fn test_supports_rule() {
16923    test(
16924      r#"
16925      @supports (foo: bar) {
16926        .test {
16927          foo: bar;
16928        }
16929      }
16930    "#,
16931      indoc! { r#"
16932      @supports (foo: bar) {
16933        .test {
16934          foo: bar;
16935        }
16936      }
16937    "#},
16938    );
16939    test(
16940      r#"
16941      @supports not (foo: bar) {
16942        .test {
16943          foo: bar;
16944        }
16945      }
16946    "#,
16947      indoc! { r#"
16948      @supports not (foo: bar) {
16949        .test {
16950          foo: bar;
16951        }
16952      }
16953    "#},
16954    );
16955    test(
16956      r#"
16957      @supports (foo: bar) or (bar: baz) {
16958        .test {
16959          foo: bar;
16960        }
16961      }
16962    "#,
16963      indoc! { r#"
16964      @supports (foo: bar) or (bar: baz) {
16965        .test {
16966          foo: bar;
16967        }
16968      }
16969    "#},
16970    );
16971    test(
16972      r#"
16973      @supports (((foo: bar) or (bar: baz))) {
16974        .test {
16975          foo: bar;
16976        }
16977      }
16978    "#,
16979      indoc! { r#"
16980      @supports (foo: bar) or (bar: baz) {
16981        .test {
16982          foo: bar;
16983        }
16984      }
16985    "#},
16986    );
16987    test(
16988      r#"
16989      @supports (foo: bar) and (bar: baz) {
16990        .test {
16991          foo: bar;
16992        }
16993      }
16994    "#,
16995      indoc! { r#"
16996      @supports (foo: bar) and (bar: baz) {
16997        .test {
16998          foo: bar;
16999        }
17000      }
17001    "#},
17002    );
17003    test(
17004      r#"
17005      @supports (((foo: bar) and (bar: baz))) {
17006        .test {
17007          foo: bar;
17008        }
17009      }
17010    "#,
17011      indoc! { r#"
17012      @supports (foo: bar) and (bar: baz) {
17013        .test {
17014          foo: bar;
17015        }
17016      }
17017    "#},
17018    );
17019    test(
17020      r#"
17021      @supports (foo: bar) and (((bar: baz) or (test: foo))) {
17022        .test {
17023          foo: bar;
17024        }
17025      }
17026    "#,
17027      indoc! { r#"
17028      @supports (foo: bar) and ((bar: baz) or (test: foo)) {
17029        .test {
17030          foo: bar;
17031        }
17032      }
17033    "#},
17034    );
17035    test(
17036      r#"
17037      @supports not (((foo: bar) and (bar: baz))) {
17038        .test {
17039          foo: bar;
17040        }
17041      }
17042    "#,
17043      indoc! { r#"
17044      @supports not ((foo: bar) and (bar: baz)) {
17045        .test {
17046          foo: bar;
17047        }
17048      }
17049    "#},
17050    );
17051    test(
17052      r#"
17053      @supports selector(a > b) {
17054        .test {
17055          foo: bar;
17056        }
17057      }
17058    "#,
17059      indoc! { r#"
17060      @supports selector(a > b) {
17061        .test {
17062          foo: bar;
17063        }
17064      }
17065    "#},
17066    );
17067    test(
17068      r#"
17069      @supports unknown(test) {
17070        .test {
17071          foo: bar;
17072        }
17073      }
17074    "#,
17075      indoc! { r#"
17076      @supports unknown(test) {
17077        .test {
17078          foo: bar;
17079        }
17080      }
17081    "#},
17082    );
17083    test(
17084      r#"
17085      @supports (unknown) {
17086        .test {
17087          foo: bar;
17088        }
17089      }
17090    "#,
17091      indoc! { r#"
17092      @supports (unknown) {
17093        .test {
17094          foo: bar;
17095        }
17096      }
17097    "#},
17098    );
17099    test(
17100      r#"
17101      @supports (display: grid) and (not (display: inline-grid)) {
17102        .test {
17103          foo: bar;
17104        }
17105      }
17106    "#,
17107      indoc! { r#"
17108      @supports (display: grid) and (not (display: inline-grid)) {
17109        .test {
17110          foo: bar;
17111        }
17112      }
17113    "#},
17114    );
17115    prefix_test(
17116      r#"
17117      @supports (backdrop-filter: blur(10px)) {
17118        div {
17119          backdrop-filter: blur(10px);
17120        }
17121      }
17122    "#,
17123      indoc! { r#"
17124      @supports ((-webkit-backdrop-filter: blur(10px)) or (backdrop-filter: blur(10px))) {
17125        div {
17126          -webkit-backdrop-filter: blur(10px);
17127          backdrop-filter: blur(10px);
17128        }
17129      }
17130    "#},
17131      Browsers {
17132        safari: Some(14 << 16),
17133        ..Default::default()
17134      },
17135    );
17136    prefix_test(
17137      r#"
17138      @supports ((-webkit-backdrop-filter: blur(10px)) or (backdrop-filter: blur(10px))) {
17139        div {
17140          backdrop-filter: blur(10px);
17141        }
17142      }
17143    "#,
17144      indoc! { r#"
17145      @supports ((-webkit-backdrop-filter: blur(10px)) or (backdrop-filter: blur(10px))) {
17146        div {
17147          -webkit-backdrop-filter: blur(10px);
17148          backdrop-filter: blur(10px);
17149        }
17150      }
17151    "#},
17152      Browsers {
17153        safari: Some(14 << 16),
17154        ..Default::default()
17155      },
17156    );
17157    prefix_test(
17158      r#"
17159      @supports ((-webkit-backdrop-filter: blur(20px)) or (backdrop-filter: blur(10px))) {
17160        div {
17161          backdrop-filter: blur(10px);
17162        }
17163      }
17164    "#,
17165      indoc! { r#"
17166      @supports ((-webkit-backdrop-filter: blur(20px))) or ((-webkit-backdrop-filter: blur(10px)) or (backdrop-filter: blur(10px))) {
17167        div {
17168          -webkit-backdrop-filter: blur(10px);
17169          backdrop-filter: blur(10px);
17170        }
17171      }
17172    "#},
17173      Browsers {
17174        safari: Some(14 << 16),
17175        ..Default::default()
17176      },
17177    );
17178    prefix_test(
17179      r#"
17180      @supports ((-webkit-backdrop-filter: blur(10px)) or (backdrop-filter: blur(10px))) {
17181        div {
17182          backdrop-filter: blur(10px);
17183        }
17184      }
17185    "#,
17186      indoc! { r#"
17187      @supports (backdrop-filter: blur(10px)) {
17188        div {
17189          backdrop-filter: blur(10px);
17190        }
17191      }
17192    "#},
17193      Browsers {
17194        chrome: Some(80 << 16),
17195        ..Default::default()
17196      },
17197    );
17198    minify_test(
17199      r#"
17200      @supports (width: calc(10px * 2)) {
17201        .test {
17202          width: calc(10px * 2);
17203        }
17204      }
17205    "#,
17206      "@supports (width:calc(10px * 2)){.test{width:20px}}",
17207    );
17208    minify_test(
17209      r#"
17210      @supports (color: hsl(0deg, 0%, 0%)) {
17211        .test {
17212          color: hsl(0deg, 0%, 0%);
17213        }
17214      }
17215    "#,
17216      "@supports (color:hsl(0deg, 0%, 0%)){.test{color:#000}}",
17217    );
17218  }
17219
17220  #[test]
17221  fn test_counter_style() {
17222    test(
17223      r#"
17224      @counter-style circled-alpha {
17225        system: fixed;
17226        symbols: Ⓐ Ⓑ Ⓒ;
17227        suffix: " ";
17228      }
17229    "#,
17230      indoc! { r#"
17231      @counter-style circled-alpha {
17232        system: fixed;
17233        symbols: Ⓐ Ⓑ Ⓒ;
17234        suffix: " ";
17235      }
17236    "#},
17237    );
17238  }
17239
17240  #[test]
17241  fn test_namespace() {
17242    minify_test(
17243      "@namespace url(http://toto.example.org);",
17244      "@namespace \"http://toto.example.org\";",
17245    );
17246    minify_test(
17247      "@namespace \"http://toto.example.org\";",
17248      "@namespace \"http://toto.example.org\";",
17249    );
17250    minify_test(
17251      "@namespace toto \"http://toto.example.org\";",
17252      "@namespace toto \"http://toto.example.org\";",
17253    );
17254    minify_test(
17255      "@namespace toto url(http://toto.example.org);",
17256      "@namespace toto \"http://toto.example.org\";",
17257    );
17258
17259    test(
17260      r#"
17261      @namespace "http://example.com/foo";
17262
17263      x {
17264        color: red;
17265      }
17266    "#,
17267      indoc! {r#"
17268      @namespace "http://example.com/foo";
17269
17270      x {
17271        color: red;
17272      }
17273    "#},
17274    );
17275
17276    test(
17277      r#"
17278      @namespace toto "http://toto.example.org";
17279
17280      toto|x {
17281        color: red;
17282      }
17283
17284      [toto|att=val] {
17285        color: blue
17286      }
17287    "#,
17288      indoc! {r#"
17289      @namespace toto "http://toto.example.org";
17290
17291      toto|x {
17292        color: red;
17293      }
17294
17295      [toto|att="val"] {
17296        color: #00f;
17297      }
17298    "#},
17299    );
17300
17301    test(
17302      r#"
17303      @namespace "http://example.com/foo";
17304
17305      |x {
17306        color: red;
17307      }
17308
17309      [|att=val] {
17310        color: blue
17311      }
17312    "#,
17313      indoc! {r#"
17314      @namespace "http://example.com/foo";
17315
17316      |x {
17317        color: red;
17318      }
17319
17320      [att="val"] {
17321        color: #00f;
17322      }
17323    "#},
17324    );
17325
17326    test(
17327      r#"
17328      @namespace "http://example.com/foo";
17329
17330      *|x {
17331        color: red;
17332      }
17333
17334      [*|att=val] {
17335        color: blue
17336      }
17337    "#,
17338      indoc! {r#"
17339      @namespace "http://example.com/foo";
17340
17341      *|x {
17342        color: red;
17343      }
17344
17345      [*|att="val"] {
17346        color: #00f;
17347      }
17348    "#},
17349    );
17350
17351    error_test(
17352      ".foo { color: red } @namespace \"http://example.com/foo\";",
17353      ParserError::UnexpectedNamespaceRule,
17354    );
17355  }
17356
17357  #[test]
17358  fn test_import() {
17359    minify_test("@import url(foo.css);", "@import \"foo.css\";");
17360    minify_test("@import \"foo.css\";", "@import \"foo.css\";");
17361    minify_test("@import url(foo.css) print;", "@import \"foo.css\" print;");
17362    minify_test("@import \"foo.css\" print;", "@import \"foo.css\" print;");
17363    minify_test(
17364      "@import \"foo.css\" screen and (orientation: landscape);",
17365      "@import \"foo.css\" screen and (orientation:landscape);",
17366    );
17367    minify_test(
17368      "@import url(foo.css) supports(display: flex);",
17369      "@import \"foo.css\" supports(display:flex);",
17370    );
17371    minify_test(
17372      "@import url(foo.css) supports(display: flex) print;",
17373      "@import \"foo.css\" supports(display:flex) print;",
17374    );
17375    minify_test(
17376      "@import url(foo.css) supports(not (display: flex));",
17377      "@import \"foo.css\" supports(not (display:flex));",
17378    );
17379    minify_test(
17380      "@import url(foo.css) supports((display: flex));",
17381      "@import \"foo.css\" supports(display:flex);",
17382    );
17383    minify_test("@charset \"UTF-8\"; @import url(foo.css);", "@import \"foo.css\";");
17384    minify_test("@layer foo; @import url(foo.css);", "@layer foo;@import \"foo.css\";");
17385    error_test(
17386      ".foo { color: red } @import url(bar.css);",
17387      ParserError::UnexpectedImportRule,
17388    );
17389    error_test(
17390      "@namespace \"http://example.com/foo\"; @import url(bar.css);",
17391      ParserError::UnexpectedImportRule,
17392    );
17393    error_test(
17394      "@media print { .foo { color: red }} @import url(bar.css);",
17395      ParserError::UnexpectedImportRule,
17396    );
17397    error_test(
17398      "@layer foo; @import url(foo.css); @layer bar; @import url(bar.css)",
17399      ParserError::UnexpectedImportRule,
17400    );
17401    let warnings = error_recovery_test("@import './actual-styles.css';");
17402    assert_eq!(warnings, vec![]);
17403  }
17404
17405  #[test]
17406  fn test_prefixes() {
17407    prefix_test(
17408      r#"
17409      .foo {
17410        -webkit-transition: opacity 200ms;
17411        -moz-transition: opacity 200ms;
17412        transition: opacity 200ms;
17413      }
17414      "#,
17415      indoc! {r#"
17416      .foo {
17417        transition: opacity .2s;
17418      }
17419      "#},
17420      Browsers {
17421        chrome: Some(95 << 16),
17422        ..Browsers::default()
17423      },
17424    );
17425
17426    prefix_test(
17427      ".foo{transition:opacity 200ms}",
17428      indoc! {r#"
17429      .foo {
17430        -webkit-transition: opacity .2s;
17431        -moz-transition: opacity .2s;
17432        transition: opacity .2s;
17433      }
17434      "#},
17435      Browsers {
17436        safari: Some(5 << 16),
17437        firefox: Some(14 << 16),
17438        ..Browsers::default()
17439      },
17440    );
17441  }
17442
17443  #[test]
17444  fn test_display() {
17445    minify_test(".foo { display: block }", ".foo{display:block}");
17446    minify_test(".foo { display: block flow }", ".foo{display:block}");
17447    minify_test(".foo { display: flow-root }", ".foo{display:flow-root}");
17448    minify_test(".foo { display: block flow-root }", ".foo{display:flow-root}");
17449    minify_test(".foo { display: inline }", ".foo{display:inline}");
17450    minify_test(".foo { display: inline flow }", ".foo{display:inline}");
17451    minify_test(".foo { display: inline-block }", ".foo{display:inline-block}");
17452    minify_test(".foo { display: inline flow-root }", ".foo{display:inline-block}");
17453    minify_test(".foo { display: run-in }", ".foo{display:run-in}");
17454    minify_test(".foo { display: run-in flow }", ".foo{display:run-in}");
17455    minify_test(".foo { display: list-item }", ".foo{display:list-item}");
17456    minify_test(".foo { display: block flow list-item }", ".foo{display:list-item}");
17457    minify_test(".foo { display: inline list-item }", ".foo{display:inline list-item}");
17458    minify_test(
17459      ".foo { display: inline flow list-item }",
17460      ".foo{display:inline list-item}",
17461    );
17462    minify_test(".foo { display: flex }", ".foo{display:flex}");
17463    minify_test(".foo { display: block flex }", ".foo{display:flex}");
17464    minify_test(".foo { display: inline-flex }", ".foo{display:inline-flex}");
17465    minify_test(".foo { display: inline flex }", ".foo{display:inline-flex}");
17466    minify_test(".foo { display: grid }", ".foo{display:grid}");
17467    minify_test(".foo { display: block grid }", ".foo{display:grid}");
17468    minify_test(".foo { display: inline-grid }", ".foo{display:inline-grid}");
17469    minify_test(".foo { display: inline grid }", ".foo{display:inline-grid}");
17470    minify_test(".foo { display: ruby }", ".foo{display:ruby}");
17471    minify_test(".foo { display: inline ruby }", ".foo{display:ruby}");
17472    minify_test(".foo { display: block ruby }", ".foo{display:block ruby}");
17473    minify_test(".foo { display: table }", ".foo{display:table}");
17474    minify_test(".foo { display: block table }", ".foo{display:table}");
17475    minify_test(".foo { display: inline-table }", ".foo{display:inline-table}");
17476    minify_test(".foo { display: inline table }", ".foo{display:inline-table}");
17477    minify_test(".foo { display: table-row-group }", ".foo{display:table-row-group}");
17478    minify_test(".foo { display: contents }", ".foo{display:contents}");
17479    minify_test(".foo { display: none }", ".foo{display:none}");
17480    minify_test(".foo { display: -webkit-flex }", ".foo{display:-webkit-flex}");
17481    minify_test(".foo { display: -ms-flexbox }", ".foo{display:-ms-flexbox}");
17482    minify_test(".foo { display: -webkit-box }", ".foo{display:-webkit-box}");
17483    minify_test(".foo { display: -moz-box }", ".foo{display:-moz-box}");
17484    minify_test(
17485      ".foo { display: -webkit-flex; display: -moz-box; display: flex }",
17486      ".foo{display:-webkit-flex;display:-moz-box;display:flex}",
17487    );
17488    minify_test(
17489      ".foo { display: -webkit-flex; display: flex; display: -moz-box }",
17490      ".foo{display:-webkit-flex;display:flex;display:-moz-box}",
17491    );
17492    minify_test(".foo { display: flex; display: grid }", ".foo{display:grid}");
17493    minify_test(
17494      ".foo { display: -webkit-inline-flex; display: -moz-inline-box; display: inline-flex }",
17495      ".foo{display:-webkit-inline-flex;display:-moz-inline-box;display:inline-flex}",
17496    );
17497    minify_test(
17498      ".foo { display: flex; display: var(--grid); }",
17499      ".foo{display:flex;display:var(--grid)}",
17500    );
17501    prefix_test(
17502      ".foo{ display: flex }",
17503      indoc! {r#"
17504      .foo {
17505        display: -webkit-box;
17506        display: -moz-box;
17507        display: -webkit-flex;
17508        display: -ms-flexbox;
17509        display: flex;
17510      }
17511      "#},
17512      Browsers {
17513        safari: Some(4 << 16),
17514        firefox: Some(14 << 16),
17515        ie: Some(10 << 16),
17516        ..Browsers::default()
17517      },
17518    );
17519    prefix_test(
17520      ".foo{ display: flex; display: -webkit-box; }",
17521      indoc! {r#"
17522      .foo {
17523        display: -webkit-box;
17524      }
17525      "#},
17526      Browsers {
17527        safari: Some(4 << 16),
17528        firefox: Some(14 << 16),
17529        ie: Some(10 << 16),
17530        ..Browsers::default()
17531      },
17532    );
17533    prefix_test(
17534      ".foo{ display: -webkit-box; display: flex; }",
17535      indoc! {r#"
17536      .foo {
17537        display: -webkit-box;
17538        display: -moz-box;
17539        display: -webkit-flex;
17540        display: -ms-flexbox;
17541        display: flex;
17542      }
17543      "#},
17544      Browsers {
17545        safari: Some(4 << 16),
17546        firefox: Some(14 << 16),
17547        ie: Some(10 << 16),
17548        ..Browsers::default()
17549      },
17550    );
17551    prefix_test(
17552      r#"
17553      .foo {
17554        display: -webkit-box;
17555        display: -moz-box;
17556        display: -webkit-flex;
17557        display: -ms-flexbox;
17558        display: flex;
17559      }
17560      "#,
17561      indoc! {r#"
17562      .foo {
17563        display: flex;
17564      }
17565      "#},
17566      Browsers {
17567        safari: Some(14 << 16),
17568        ..Browsers::default()
17569      },
17570    );
17571    prefix_test(
17572      r#"
17573      .foo {
17574        display: -webkit-box;
17575        display: flex;
17576        display: -moz-box;
17577        display: -webkit-flex;
17578        display: -ms-flexbox;
17579      }
17580      "#,
17581      indoc! {r#"
17582      .foo {
17583        display: -moz-box;
17584        display: -webkit-flex;
17585        display: -ms-flexbox;
17586      }
17587      "#},
17588      Browsers {
17589        safari: Some(14 << 16),
17590        ..Browsers::default()
17591      },
17592    );
17593    prefix_test(
17594      ".foo{ display: inline-flex }",
17595      indoc! {r#"
17596      .foo {
17597        display: -webkit-inline-box;
17598        display: -moz-inline-box;
17599        display: -webkit-inline-flex;
17600        display: -ms-inline-flexbox;
17601        display: inline-flex;
17602      }
17603      "#},
17604      Browsers {
17605        safari: Some(4 << 16),
17606        firefox: Some(14 << 16),
17607        ie: Some(10 << 16),
17608        ..Browsers::default()
17609      },
17610    );
17611    prefix_test(
17612      r#"
17613      .foo {
17614        display: -webkit-inline-box;
17615        display: -moz-inline-box;
17616        display: -webkit-inline-flex;
17617        display: -ms-inline-flexbox;
17618        display: inline-flex;
17619      }
17620      "#,
17621      indoc! {r#"
17622      .foo {
17623        display: inline-flex;
17624      }
17625      "#},
17626      Browsers {
17627        safari: Some(14 << 16),
17628        ..Browsers::default()
17629      },
17630    );
17631  }
17632
17633  #[test]
17634  fn test_visibility() {
17635    minify_test(".foo { visibility: visible }", ".foo{visibility:visible}");
17636    minify_test(".foo { visibility: hidden }", ".foo{visibility:hidden}");
17637    minify_test(".foo { visibility: collapse }", ".foo{visibility:collapse}");
17638    minify_test(".foo { visibility: Visible }", ".foo{visibility:visible}");
17639  }
17640
17641  #[test]
17642  fn test_text_transform() {
17643    minify_test(".foo { text-transform: uppercase }", ".foo{text-transform:uppercase}");
17644    minify_test(".foo { text-transform: lowercase }", ".foo{text-transform:lowercase}");
17645    minify_test(".foo { text-transform: capitalize }", ".foo{text-transform:capitalize}");
17646    minify_test(".foo { text-transform: none }", ".foo{text-transform:none}");
17647    minify_test(".foo { text-transform: full-width }", ".foo{text-transform:full-width}");
17648    minify_test(
17649      ".foo { text-transform: full-size-kana }",
17650      ".foo{text-transform:full-size-kana}",
17651    );
17652    minify_test(
17653      ".foo { text-transform: uppercase full-width }",
17654      ".foo{text-transform:uppercase full-width}",
17655    );
17656    minify_test(
17657      ".foo { text-transform: full-width uppercase }",
17658      ".foo{text-transform:uppercase full-width}",
17659    );
17660    minify_test(
17661      ".foo { text-transform: uppercase full-width full-size-kana }",
17662      ".foo{text-transform:uppercase full-width full-size-kana}",
17663    );
17664    minify_test(
17665      ".foo { text-transform: full-width uppercase full-size-kana }",
17666      ".foo{text-transform:uppercase full-width full-size-kana}",
17667    );
17668  }
17669
17670  #[test]
17671  fn test_whitespace() {
17672    minify_test(".foo { white-space: normal }", ".foo{white-space:normal}");
17673    minify_test(".foo { white-space: pre }", ".foo{white-space:pre}");
17674    minify_test(".foo { white-space: nowrap }", ".foo{white-space:nowrap}");
17675    minify_test(".foo { white-space: pre-wrap }", ".foo{white-space:pre-wrap}");
17676    minify_test(".foo { white-space: break-spaces }", ".foo{white-space:break-spaces}");
17677    minify_test(".foo { white-space: pre-line }", ".foo{white-space:pre-line}");
17678    minify_test(".foo { white-space: NoWrAp }", ".foo{white-space:nowrap}");
17679  }
17680
17681  #[test]
17682  fn test_tab_size() {
17683    property_range_test(
17684      &["tab-size"],
17685      &[
17686        ("-1px", None),
17687        ("calc(1px - 2px)", Some("0")),
17688        ("calc(-1px + 2px)", Some("1px")),
17689        ("-1", None),
17690        ("calc(1 - 2)", Some("0")),
17691        ("calc(-1 + 2)", Some("1")),
17692      ],
17693    );
17694    minify_test(".foo { tab-size: 8 }", ".foo{tab-size:8}");
17695    minify_test(".foo { tab-size: 4px }", ".foo{tab-size:4px}");
17696    minify_test(".foo { -moz-tab-size: 4px }", ".foo{-moz-tab-size:4px}");
17697    minify_test(".foo { -o-tab-size: 4px }", ".foo{-o-tab-size:4px}");
17698    prefix_test(
17699      ".foo{ tab-size: 4 }",
17700      indoc! {r#"
17701      .foo {
17702        -moz-tab-size: 4;
17703        -o-tab-size: 4;
17704        tab-size: 4;
17705      }
17706      "#},
17707      Browsers {
17708        safari: Some(8 << 16),
17709        firefox: Some(50 << 16),
17710        opera: Some(12 << 16),
17711        ..Browsers::default()
17712      },
17713    );
17714    prefix_test(
17715      r#"
17716      .foo {
17717        -moz-tab-size: 4;
17718        -o-tab-size: 4;
17719        tab-size: 4;
17720      }
17721      "#,
17722      indoc! {r#"
17723      .foo {
17724        tab-size: 4;
17725      }
17726      "#},
17727      Browsers {
17728        safari: Some(8 << 16),
17729        firefox: Some(94 << 16),
17730        opera: Some(30 << 16),
17731        ..Browsers::default()
17732      },
17733    );
17734  }
17735
17736  #[test]
17737  fn test_word_break() {
17738    minify_test(".foo { word-break: normal }", ".foo{word-break:normal}");
17739    minify_test(".foo { word-break: keep-all }", ".foo{word-break:keep-all}");
17740    minify_test(".foo { word-break: break-all }", ".foo{word-break:break-all}");
17741    minify_test(".foo { word-break: break-word }", ".foo{word-break:break-word}");
17742  }
17743
17744  #[test]
17745  fn test_line_break() {
17746    minify_test(".foo { line-break: auto }", ".foo{line-break:auto}");
17747    minify_test(".foo { line-break: Loose }", ".foo{line-break:loose}");
17748    minify_test(".foo { line-break: anywhere }", ".foo{line-break:anywhere}");
17749  }
17750
17751  #[test]
17752  fn test_wrap() {
17753    minify_test(".foo { overflow-wrap: nOrmal }", ".foo{overflow-wrap:normal}");
17754    minify_test(".foo { overflow-wrap: break-Word }", ".foo{overflow-wrap:break-word}");
17755    minify_test(".foo { overflow-wrap: Anywhere }", ".foo{overflow-wrap:anywhere}");
17756    minify_test(".foo { word-wrap: Normal }", ".foo{word-wrap:normal}");
17757    minify_test(".foo { word-wrap: Break-wOrd }", ".foo{word-wrap:break-word}");
17758    minify_test(".foo { word-wrap: Anywhere }", ".foo{word-wrap:anywhere}");
17759  }
17760
17761  #[test]
17762  fn test_hyphens() {
17763    minify_test(".foo { hyphens: manual }", ".foo{hyphens:manual}");
17764    minify_test(".foo { hyphens: auto }", ".foo{hyphens:auto}");
17765    minify_test(".foo { hyphens: none }", ".foo{hyphens:none}");
17766    minify_test(".foo { -webkit-hyphens: manual }", ".foo{-webkit-hyphens:manual}");
17767    minify_test(".foo { -moz-hyphens: manual }", ".foo{-moz-hyphens:manual}");
17768    minify_test(".foo { -ms-hyphens: manual }", ".foo{-ms-hyphens:manual}");
17769    prefix_test(
17770      ".foo{ hyphens: manual }",
17771      indoc! {r#"
17772      .foo {
17773        -webkit-hyphens: manual;
17774        -moz-hyphens: manual;
17775        -ms-hyphens: manual;
17776        hyphens: manual;
17777      }
17778      "#},
17779      Browsers {
17780        safari: Some(14 << 16),
17781        firefox: Some(40 << 16),
17782        ie: Some(10 << 16),
17783        ..Browsers::default()
17784      },
17785    );
17786    prefix_test(
17787      r#"
17788      .foo {
17789        -webkit-hyphens: manual;
17790        -moz-hyphens: manual;
17791        -ms-hyphens: manual;
17792        hyphens: manual;
17793      }
17794      "#,
17795      indoc! {r#"
17796      .foo {
17797        -webkit-hyphens: manual;
17798        hyphens: manual;
17799      }
17800      "#},
17801      Browsers {
17802        safari: Some(14 << 16),
17803        chrome: Some(88 << 16),
17804        firefox: Some(88 << 16),
17805        edge: Some(79 << 16),
17806        ..Browsers::default()
17807      },
17808    );
17809    prefix_test(
17810      r#"
17811      .foo {
17812        -webkit-hyphens: manual;
17813        -moz-hyphens: manual;
17814        -ms-hyphens: manual;
17815        hyphens: manual;
17816      }
17817      "#,
17818      indoc! {r#"
17819      .foo {
17820        hyphens: manual;
17821      }
17822      "#},
17823      Browsers {
17824        chrome: Some(88 << 16),
17825        firefox: Some(88 << 16),
17826        edge: Some(79 << 16),
17827        ..Browsers::default()
17828      },
17829    );
17830  }
17831
17832  #[test]
17833  fn test_text_align() {
17834    minify_test(".foo { text-align: left }", ".foo{text-align:left}");
17835    minify_test(".foo { text-align: Left }", ".foo{text-align:left}");
17836    minify_test(".foo { text-align: END }", ".foo{text-align:end}");
17837    minify_test(".foo { text-align: left }", ".foo{text-align:left}");
17838
17839    prefix_test(
17840      r#"
17841      .foo {
17842        text-align: start;
17843      }
17844    "#,
17845      indoc! {r#"
17846      .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))) {
17847        text-align: left;
17848      }
17849
17850      .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)) {
17851        text-align: right;
17852      }
17853    "#
17854      },
17855      Browsers {
17856        safari: Some(2 << 16),
17857        ..Browsers::default()
17858      },
17859    );
17860
17861    prefix_test(
17862      r#"
17863      .foo {
17864        text-align: end;
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: right;
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: left;
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: start;
17887      }
17888    "#,
17889      indoc! {r#"
17890      .foo {
17891        text-align: start;
17892      }
17893    "#
17894      },
17895      Browsers {
17896        safari: Some(14 << 16),
17897        ..Browsers::default()
17898      },
17899    );
17900
17901    prefix_test(
17902      r#"
17903      .foo > .bar {
17904        text-align: start;
17905      }
17906    "#,
17907      indoc! {r#"
17908      .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))) {
17909        text-align: left;
17910      }
17911
17912      .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)) {
17913        text-align: right;
17914      }
17915    "#
17916      },
17917      Browsers {
17918        safari: Some(2 << 16),
17919        ..Browsers::default()
17920      },
17921    );
17922
17923    prefix_test(
17924      r#"
17925      .foo:after {
17926        text-align: start;
17927      }
17928    "#,
17929      indoc! {r#"
17930      .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 {
17931        text-align: left;
17932      }
17933
17934      .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 {
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:hover {
17948        text-align: start;
17949      }
17950    "#,
17951      indoc! {r#"
17952      .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))) {
17953        text-align: left;
17954      }
17955
17956      .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)) {
17957        text-align: right;
17958      }
17959    "#
17960      },
17961      Browsers {
17962        safari: Some(2 << 16),
17963        ..Browsers::default()
17964      },
17965    );
17966  }
17967
17968  #[test]
17969  fn test_text_align_last() {
17970    minify_test(".foo { text-align-last: left }", ".foo{text-align-last:left}");
17971    minify_test(".foo { text-align-last: justify }", ".foo{text-align-last:justify}");
17972    prefix_test(
17973      ".foo{ text-align-last: left }",
17974      indoc! {r#"
17975      .foo {
17976        -moz-text-align-last: left;
17977        text-align-last: left;
17978      }
17979      "#},
17980      Browsers {
17981        firefox: Some(40 << 16),
17982        ..Browsers::default()
17983      },
17984    );
17985    prefix_test(
17986      r#"
17987      .foo {
17988        -moz-text-align-last: left;
17989        text-align-last: left;
17990      }
17991      "#,
17992      indoc! {r#"
17993      .foo {
17994        text-align-last: left;
17995      }
17996      "#},
17997      Browsers {
17998        firefox: Some(88 << 16),
17999        ..Browsers::default()
18000      },
18001    );
18002  }
18003
18004  #[test]
18005  fn test_text_justify() {
18006    minify_test(".foo { text-justify: auto }", ".foo{text-justify:auto}");
18007    minify_test(".foo { text-justify: inter-word }", ".foo{text-justify:inter-word}");
18008  }
18009
18010  #[test]
18011  fn test_word_spacing() {
18012    minify_test(".foo { word-spacing: normal }", ".foo{word-spacing:normal}");
18013    minify_test(".foo { word-spacing: 3px }", ".foo{word-spacing:3px}");
18014  }
18015
18016  #[test]
18017  fn test_letter_spacing() {
18018    minify_test(".foo { letter-spacing: normal }", ".foo{letter-spacing:normal}");
18019    minify_test(".foo { letter-spacing: 3px }", ".foo{letter-spacing:3px}");
18020  }
18021
18022  #[test]
18023  fn test_text_indent() {
18024    minify_test(".foo { text-indent: 20px }", ".foo{text-indent:20px}");
18025    minify_test(".foo { text-indent: 10% }", ".foo{text-indent:10%}");
18026    minify_test(".foo { text-indent: 3em hanging }", ".foo{text-indent:3em hanging}");
18027    minify_test(".foo { text-indent: 3em each-line }", ".foo{text-indent:3em each-line}");
18028    minify_test(
18029      ".foo { text-indent: 3em hanging each-line }",
18030      ".foo{text-indent:3em hanging each-line}",
18031    );
18032    minify_test(
18033      ".foo { text-indent: 3em each-line hanging }",
18034      ".foo{text-indent:3em hanging each-line}",
18035    );
18036    minify_test(
18037      ".foo { text-indent: each-line 3em hanging }",
18038      ".foo{text-indent:3em hanging each-line}",
18039    );
18040    minify_test(
18041      ".foo { text-indent: each-line hanging 3em }",
18042      ".foo{text-indent:3em hanging each-line}",
18043    );
18044  }
18045
18046  #[test]
18047  fn test_text_size_adjust() {
18048    property_range_test(&["text-size-adjust"], &[("-1%", None), ("calc(-1%)", Some("0%"))]);
18049    minify_test(".foo { text-size-adjust: none }", ".foo{text-size-adjust:none}");
18050    minify_test(".foo { text-size-adjust: auto }", ".foo{text-size-adjust:auto}");
18051    minify_test(".foo { text-size-adjust: 80% }", ".foo{text-size-adjust:80%}");
18052    prefix_test(
18053      r#"
18054      .foo {
18055        text-size-adjust: none;
18056      }
18057    "#,
18058      indoc! {r#"
18059      .foo {
18060        -webkit-text-size-adjust: none;
18061        -moz-text-size-adjust: none;
18062        -ms-text-size-adjust: none;
18063        text-size-adjust: none;
18064      }
18065    "#},
18066      Browsers {
18067        ios_saf: Some(16 << 16),
18068        edge: Some(15 << 16),
18069        firefox: Some(20 << 16),
18070        ..Browsers::default()
18071      },
18072    );
18073    prefix_test(
18074      r#"
18075      .foo {
18076        -webkit-text-size-adjust: none;
18077        -moz-text-size-adjust: none;
18078        -ms-text-size-adjust: none;
18079        text-size-adjust: none;
18080      }
18081    "#,
18082      indoc! {r#"
18083      .foo {
18084        text-size-adjust: none;
18085      }
18086    "#},
18087      Browsers {
18088        chrome: Some(110 << 16),
18089        ..Browsers::default()
18090      },
18091    );
18092  }
18093
18094  #[test]
18095  fn test_text_decoration() {
18096    minify_test(".foo { text-decoration-line: none }", ".foo{text-decoration-line:none}");
18097    minify_test(
18098      ".foo { text-decoration-line: underline }",
18099      ".foo{text-decoration-line:underline}",
18100    );
18101    minify_test(
18102      ".foo { text-decoration-line: overline }",
18103      ".foo{text-decoration-line:overline}",
18104    );
18105    minify_test(
18106      ".foo { text-decoration-line: line-through }",
18107      ".foo{text-decoration-line:line-through}",
18108    );
18109    minify_test(
18110      ".foo { text-decoration-line: blink }",
18111      ".foo{text-decoration-line:blink}",
18112    );
18113    minify_test(
18114      ".foo { text-decoration-line: underline overline }",
18115      ".foo{text-decoration-line:underline overline}",
18116    );
18117    minify_test(
18118      ".foo { text-decoration-line: overline underline }",
18119      ".foo{text-decoration-line:underline overline}",
18120    );
18121    minify_test(
18122      ".foo { text-decoration-line: overline line-through underline }",
18123      ".foo{text-decoration-line:underline overline line-through}",
18124    );
18125    minify_test(
18126      ".foo { text-decoration-line: spelling-error }",
18127      ".foo{text-decoration-line:spelling-error}",
18128    );
18129    minify_test(
18130      ".foo { text-decoration-line: grammar-error }",
18131      ".foo{text-decoration-line:grammar-error}",
18132    );
18133    minify_test(
18134      ".foo { -webkit-text-decoration-line: overline underline }",
18135      ".foo{-webkit-text-decoration-line:underline overline}",
18136    );
18137    minify_test(
18138      ".foo { -moz-text-decoration-line: overline underline }",
18139      ".foo{-moz-text-decoration-line:underline overline}",
18140    );
18141
18142    minify_test(
18143      ".foo { text-decoration-style: solid }",
18144      ".foo{text-decoration-style:solid}",
18145    );
18146    minify_test(
18147      ".foo { text-decoration-style: dotted }",
18148      ".foo{text-decoration-style:dotted}",
18149    );
18150    minify_test(
18151      ".foo { -webkit-text-decoration-style: solid }",
18152      ".foo{-webkit-text-decoration-style:solid}",
18153    );
18154
18155    minify_test(
18156      ".foo { text-decoration-color: yellow }",
18157      ".foo{text-decoration-color:#ff0}",
18158    );
18159    minify_test(
18160      ".foo { -webkit-text-decoration-color: yellow }",
18161      ".foo{-webkit-text-decoration-color:#ff0}",
18162    );
18163
18164    minify_test(".foo { text-decoration: none }", ".foo{text-decoration:none}");
18165    minify_test(
18166      ".foo { text-decoration: underline dotted }",
18167      ".foo{text-decoration:underline dotted}",
18168    );
18169    minify_test(
18170      ".foo { text-decoration: underline dotted yellow }",
18171      ".foo{text-decoration:underline dotted #ff0}",
18172    );
18173    minify_test(
18174      ".foo { text-decoration: yellow dotted underline }",
18175      ".foo{text-decoration:underline dotted #ff0}",
18176    );
18177    minify_test(
18178      ".foo { text-decoration: underline overline dotted yellow }",
18179      ".foo{text-decoration:underline overline dotted #ff0}",
18180    );
18181    minify_test(
18182      ".foo { -webkit-text-decoration: yellow dotted underline }",
18183      ".foo{-webkit-text-decoration:underline dotted #ff0}",
18184    );
18185    minify_test(
18186      ".foo { -moz-text-decoration: yellow dotted underline }",
18187      ".foo{-moz-text-decoration:underline dotted #ff0}",
18188    );
18189
18190    test(
18191      r#"
18192      .foo {
18193        text-decoration-line: underline;
18194        text-decoration-style: dotted;
18195        text-decoration-color: yellow;
18196        text-decoration-thickness: 2px;
18197      }
18198    "#,
18199      indoc! {r#"
18200      .foo {
18201        text-decoration: underline 2px dotted #ff0;
18202      }
18203    "#},
18204    );
18205
18206    test(
18207      r#"
18208      .foo {
18209        text-decoration: underline;
18210        text-decoration-style: dotted;
18211      }
18212    "#,
18213      indoc! {r#"
18214      .foo {
18215        text-decoration: underline dotted;
18216      }
18217    "#},
18218    );
18219
18220    test(
18221      r#"
18222      .foo {
18223        text-decoration: underline;
18224        text-decoration-style: var(--style);
18225      }
18226    "#,
18227      indoc! {r#"
18228      .foo {
18229        text-decoration: underline;
18230        text-decoration-style: var(--style);
18231      }
18232    "#},
18233    );
18234
18235    test(
18236      r#"
18237      .foo {
18238        -webkit-text-decoration: underline;
18239        -webkit-text-decoration-style: dotted;
18240      }
18241    "#,
18242      indoc! {r#"
18243      .foo {
18244        -webkit-text-decoration: underline dotted;
18245      }
18246    "#},
18247    );
18248
18249    prefix_test(
18250      r#"
18251      .foo {
18252        text-decoration: underline dotted;
18253      }
18254    "#,
18255      indoc! {r#"
18256      .foo {
18257        -webkit-text-decoration: underline dotted;
18258        text-decoration: underline dotted;
18259      }
18260    "#},
18261      Browsers {
18262        safari: Some(8 << 16),
18263        firefox: Some(30 << 16),
18264        ..Browsers::default()
18265      },
18266    );
18267
18268    prefix_test(
18269      r#"
18270      .foo {
18271        text-decoration-line: underline;
18272      }
18273    "#,
18274      indoc! {r#"
18275      .foo {
18276        -webkit-text-decoration-line: underline;
18277        -moz-text-decoration-line: underline;
18278        text-decoration-line: underline;
18279      }
18280    "#},
18281      Browsers {
18282        safari: Some(8 << 16),
18283        firefox: Some(30 << 16),
18284        ..Browsers::default()
18285      },
18286    );
18287
18288    prefix_test(
18289      r#"
18290      .foo {
18291        text-decoration-style: dotted;
18292      }
18293    "#,
18294      indoc! {r#"
18295      .foo {
18296        -webkit-text-decoration-style: dotted;
18297        -moz-text-decoration-style: dotted;
18298        text-decoration-style: dotted;
18299      }
18300    "#},
18301      Browsers {
18302        safari: Some(8 << 16),
18303        firefox: Some(30 << 16),
18304        ..Browsers::default()
18305      },
18306    );
18307
18308    prefix_test(
18309      r#"
18310      .foo {
18311        text-decoration-color: yellow;
18312      }
18313    "#,
18314      indoc! {r#"
18315      .foo {
18316        -webkit-text-decoration-color: #ff0;
18317        -moz-text-decoration-color: #ff0;
18318        text-decoration-color: #ff0;
18319      }
18320    "#},
18321      Browsers {
18322        safari: Some(8 << 16),
18323        firefox: Some(30 << 16),
18324        ..Browsers::default()
18325      },
18326    );
18327
18328    prefix_test(
18329      r#"
18330      .foo {
18331        text-decoration: underline;
18332      }
18333    "#,
18334      indoc! {r#"
18335      .foo {
18336        text-decoration: underline;
18337      }
18338    "#},
18339      Browsers {
18340        safari: Some(8 << 16),
18341        firefox: Some(30 << 16),
18342        ..Browsers::default()
18343      },
18344    );
18345
18346    prefix_test(
18347      r#"
18348      .foo {
18349        -webkit-text-decoration: underline dotted;
18350        text-decoration: underline dotted;
18351      }
18352    "#,
18353      indoc! {r#"
18354      .foo {
18355        -webkit-text-decoration: underline dotted;
18356        text-decoration: underline dotted;
18357      }
18358    "#},
18359      Browsers {
18360        safari: Some(14 << 16),
18361        firefox: Some(45 << 16),
18362        ..Browsers::default()
18363      },
18364    );
18365
18366    prefix_test(
18367      r#"
18368      .foo {
18369        text-decoration: double underline;
18370      }
18371    "#,
18372      indoc! {r#"
18373      .foo {
18374        -webkit-text-decoration: underline double;
18375        text-decoration: underline double;
18376      }
18377    "#},
18378      Browsers {
18379        safari: Some(16 << 16),
18380        ..Browsers::default()
18381      },
18382    );
18383
18384    prefix_test(
18385      r#"
18386      .foo {
18387        text-decoration: underline;
18388        text-decoration-style: double;
18389      }
18390    "#,
18391      indoc! {r#"
18392      .foo {
18393        -webkit-text-decoration: underline double;
18394        text-decoration: underline double;
18395      }
18396    "#},
18397      Browsers {
18398        safari: Some(16 << 16),
18399        ..Browsers::default()
18400      },
18401    );
18402
18403    prefix_test(
18404      r#"
18405      .foo {
18406        text-decoration: underline;
18407        text-decoration-color: red;
18408      }
18409    "#,
18410      indoc! {r#"
18411      .foo {
18412        -webkit-text-decoration: underline red;
18413        text-decoration: underline red;
18414      }
18415    "#},
18416      Browsers {
18417        safari: Some(16 << 16),
18418        ..Browsers::default()
18419      },
18420    );
18421
18422    prefix_test(
18423      r#"
18424      .foo {
18425        text-decoration: var(--test);
18426      }
18427    "#,
18428      indoc! {r#"
18429      .foo {
18430        -webkit-text-decoration: var(--test);
18431        text-decoration: var(--test);
18432      }
18433    "#},
18434      Browsers {
18435        safari: Some(8 << 16),
18436        firefox: Some(30 << 16),
18437        ..Browsers::default()
18438      },
18439    );
18440
18441    minify_test(
18442      ".foo { text-decoration-skip-ink: all }",
18443      ".foo{text-decoration-skip-ink:all}",
18444    );
18445    minify_test(
18446      ".foo { -webkit-text-decoration-skip-ink: all }",
18447      ".foo{-webkit-text-decoration-skip-ink:all}",
18448    );
18449
18450    prefix_test(
18451      r#"
18452      .foo {
18453        text-decoration: lch(50.998% 135.363 338) underline;
18454      }
18455    "#,
18456      indoc! {r#"
18457      .foo {
18458        -webkit-text-decoration: underline #f000c0;
18459        text-decoration: underline #f000c0;
18460        -webkit-text-decoration: underline lch(50.998% 135.363 338);
18461        text-decoration: underline lch(50.998% 135.363 338);
18462      }
18463    "#},
18464      Browsers {
18465        safari: Some(8 << 16),
18466        firefox: Some(30 << 16),
18467        ..Browsers::default()
18468      },
18469    );
18470
18471    prefix_test(
18472      r#"
18473      .foo {
18474        text-decoration-color: lch(50.998% 135.363 338);
18475      }
18476    "#,
18477      indoc! {r#"
18478      .foo {
18479        -webkit-text-decoration-color: #f000c0;
18480        -moz-text-decoration-color: #f000c0;
18481        text-decoration-color: #f000c0;
18482        -webkit-text-decoration-color: lch(50.998% 135.363 338);
18483        -moz-text-decoration-color: lch(50.998% 135.363 338);
18484        text-decoration-color: lch(50.998% 135.363 338);
18485      }
18486    "#},
18487      Browsers {
18488        safari: Some(8 << 16),
18489        firefox: Some(30 << 16),
18490        ..Browsers::default()
18491      },
18492    );
18493
18494    prefix_test(
18495      r#"
18496      .foo {
18497        text-decoration: lch(50.998% 135.363 338) var(--style);
18498      }
18499    "#,
18500      indoc! {r#"
18501      .foo {
18502        text-decoration: #f000c0 var(--style);
18503      }
18504
18505      @supports (color: lab(0% 0 0)) {
18506        .foo {
18507          text-decoration: lab(50.998% 125.506 -50.7078) var(--style);
18508        }
18509      }
18510    "#},
18511      Browsers {
18512        chrome: Some(90 << 16),
18513        ..Browsers::default()
18514      },
18515    );
18516
18517    prefix_test(
18518      r#"
18519      @supports (color: lab(0% 0 0)) {
18520        .foo {
18521          text-decoration: lab(50.998% 125.506 -50.7078) var(--style);
18522        }
18523      }
18524    "#,
18525      indoc! {r#"
18526      @supports (color: lab(0% 0 0)) {
18527        .foo {
18528          text-decoration: lab(50.998% 125.506 -50.7078) var(--style);
18529        }
18530      }
18531    "#},
18532      Browsers {
18533        chrome: Some(90 << 16),
18534        ..Browsers::default()
18535      },
18536    );
18537
18538    prefix_test(
18539      r#"
18540      .foo {
18541        text-decoration: underline 10px;
18542      }
18543    "#,
18544      indoc! {r#"
18545      .foo {
18546        text-decoration: underline;
18547        text-decoration-thickness: 10px;
18548      }
18549    "#},
18550      Browsers {
18551        safari: Some(15 << 16),
18552        ..Browsers::default()
18553      },
18554    );
18555
18556    prefix_test(
18557      r#"
18558      .foo {
18559        text-decoration: underline 10px;
18560      }
18561    "#,
18562      indoc! {r#"
18563      .foo {
18564        text-decoration: underline 10px;
18565      }
18566    "#},
18567      Browsers {
18568        chrome: Some(90 << 16),
18569        ..Browsers::default()
18570      },
18571    );
18572
18573    prefix_test(
18574      r#"
18575      .foo {
18576        text-decoration: underline 10%;
18577      }
18578    "#,
18579      indoc! {r#"
18580      .foo {
18581        text-decoration: underline;
18582        text-decoration-thickness: calc(1em / 10);
18583      }
18584    "#},
18585      Browsers {
18586        safari: Some(12 << 16),
18587        ..Browsers::default()
18588      },
18589    );
18590
18591    prefix_test(
18592      r#"
18593      .foo {
18594        text-decoration: underline 10%;
18595      }
18596    "#,
18597      indoc! {r#"
18598      .foo {
18599        text-decoration: underline 10%;
18600      }
18601    "#},
18602      Browsers {
18603        firefox: Some(89 << 16),
18604        ..Browsers::default()
18605      },
18606    );
18607
18608    prefix_test(
18609      r#"
18610      .foo {
18611        text-decoration-thickness: 10%;
18612      }
18613    "#,
18614      indoc! {r#"
18615      .foo {
18616        text-decoration-thickness: calc(1em / 10);
18617      }
18618    "#},
18619      Browsers {
18620        safari: Some(12 << 16),
18621        ..Browsers::default()
18622      },
18623    );
18624
18625    prefix_test(
18626      r#"
18627      .foo {
18628        text-decoration-thickness: 10%;
18629      }
18630    "#,
18631      indoc! {r#"
18632      .foo {
18633        text-decoration-thickness: 10%;
18634      }
18635    "#},
18636      Browsers {
18637        firefox: Some(89 << 16),
18638        ..Browsers::default()
18639      },
18640    );
18641  }
18642
18643  #[test]
18644  fn test_unparsed_text_decoration_prefixes() {
18645    let targets = Browsers {
18646      safari: Some((14 << 16) | (1 << 8)),
18647      ..Browsers::default()
18648    };
18649    let expected = indoc! {"
18650      .link {
18651        -webkit-text-decoration: underline var(--accent);
18652        text-decoration: underline var(--accent);
18653      }
18654    "};
18655
18656    for source in [
18657      indoc! {"
18658        .link {
18659          text-decoration: underline var(--accent);
18660        }
18661      "},
18662      indoc! {"
18663        .link {
18664          -webkit-text-decoration: underline var(--accent);
18665          text-decoration: underline var(--accent);
18666        }
18667      "},
18668      indoc! {"
18669        .link {
18670          text-decoration: underline var(--accent);
18671          -webkit-text-decoration: underline var(--accent);
18672        }
18673      "},
18674      indoc! {"
18675        .link {
18676          -webkit-text-decoration: underline var(--accent);
18677          -webkit-text-decoration: underline var(--accent);
18678          text-decoration: underline var(--accent);
18679        }
18680      "},
18681      indoc! {"
18682        .link {
18683          -webkit-text-decoration: underline var(--accent);
18684          /* An ordinary comment does not prevent deduplication. */
18685          text-decoration: underline var(--accent);
18686        }
18687      "},
18688    ] {
18689      prefix_test(source, expected, targets);
18690    }
18691
18692    // An already-prefixed result must not grow when minified again.
18693    prefix_test(expected, expected, targets);
18694
18695    let important = indoc! {"
18696      .link {
18697        -webkit-text-decoration: underline var(--accent) !important;
18698        text-decoration: underline var(--accent) !important;
18699      }
18700    "};
18701    prefix_test(important, important, targets);
18702
18703    let fallback = indoc! {"
18704      .link {
18705        -webkit-text-decoration: underline var(--accent, red);
18706        text-decoration: underline var(--accent, red);
18707      }
18708    "};
18709    prefix_test(fallback, fallback, targets);
18710
18711    // Explicit prefixes are retained even if the targets do not require them.
18712    prefix_test(
18713      expected,
18714      expected,
18715      Browsers {
18716        chrome: Some(120 << 16),
18717        ..Browsers::default()
18718      },
18719    );
18720    test(expected, expected);
18721  }
18722
18723  #[test]
18724  fn test_unparsed_text_prefix_boundaries() {
18725    let targets = Browsers {
18726      safari: Some((14 << 16) | (1 << 8)),
18727      ..Browsers::default()
18728    };
18729
18730    for source in [
18731      // Different values must retain their vendor-specific fallbacks.
18732      indoc! {"
18733        .link {
18734          -webkit-text-decoration: var(--old);
18735          -webkit-text-decoration: var(--new);
18736          text-decoration: var(--new);
18737        }
18738      "},
18739      // Normal and important declarations must not share prefix state.
18740      indoc! {"
18741        .link {
18742          -webkit-text-decoration: var(--decoration);
18743          -webkit-text-decoration: var(--decoration) !important;
18744          text-decoration: var(--decoration) !important;
18745        }
18746      "},
18747      // An intervening parsed longhand prevents moving the later shorthand.
18748      indoc! {"
18749        .link {
18750          -webkit-text-decoration: var(--decoration);
18751          text-decoration: var(--decoration);
18752          text-decoration-color: red;
18753          -webkit-text-decoration: var(--decoration);
18754          text-decoration: var(--decoration);
18755        }
18756      "},
18757      // An unparsed longhand is also a barrier, even with identical tokens.
18758      indoc! {"
18759        .link {
18760          -webkit-text-decoration: var(--value);
18761          text-decoration: var(--value);
18762          -webkit-text-decoration-color: var(--value);
18763          text-decoration-color: var(--value);
18764          -webkit-text-decoration: var(--value);
18765          text-decoration: var(--value);
18766        }
18767      "},
18768      // Prefix state cannot cross rule or conditional boundaries.
18769      indoc! {"
18770        .link {
18771          -webkit-text-decoration: var(--decoration);
18772          text-decoration: var(--decoration);
18773        }
18774
18775        @media print {
18776          .link {
18777            -webkit-text-decoration: var(--decoration);
18778            text-decoration: var(--decoration);
18779          }
18780        }
18781      "},
18782    ] {
18783      prefix_test(source, source, targets);
18784    }
18785
18786    // Prefix-only input must not acquire an unprefixed declaration.
18787    let prefixed = indoc! {"
18788      .link {
18789        -webkit-text-decoration: var(--decoration);
18790      }
18791    "};
18792    prefix_test(prefixed, prefixed, targets);
18793  }
18794
18795  #[test]
18796  fn test_unparsed_text_longhand_prefixes() {
18797    let source = indoc! {"
18798      .link {
18799        -webkit-text-decoration-line: var(--value);
18800        text-decoration-line: var(--value);
18801        -webkit-text-decoration-style: var(--value);
18802        text-decoration-style: var(--value);
18803        -webkit-text-decoration-color: var(--value);
18804        text-decoration-color: var(--value);
18805        text-decoration-thickness: var(--value);
18806      }
18807    "};
18808    prefix_test(
18809      source,
18810      source,
18811      Browsers {
18812        safari: Some(12 << 16),
18813        ..Browsers::default()
18814      },
18815    );
18816  }
18817
18818  #[test]
18819  fn test_unparsed_text_emphasis_prefixes() {
18820    let targets = Browsers {
18821      chrome: Some(80 << 16),
18822      ..Browsers::default()
18823    };
18824    let source = indoc! {"
18825      .label {
18826        -webkit-text-emphasis: filled var(--mark);
18827        text-emphasis: filled var(--mark);
18828      }
18829    "};
18830    prefix_test(source, source, targets);
18831
18832    let longhands = indoc! {"
18833      .label {
18834        -webkit-text-emphasis-style: var(--value);
18835        text-emphasis-style: var(--value);
18836        -webkit-text-emphasis-color: var(--value);
18837        text-emphasis-color: var(--value);
18838        -webkit-text-emphasis-position: var(--value);
18839        text-emphasis-position: var(--value);
18840      }
18841    "};
18842    prefix_test(longhands, longhands, targets);
18843  }
18844
18845  #[test]
18846  fn test_text_emphasis() {
18847    minify_test(".foo { text-emphasis-style: none }", ".foo{text-emphasis-style:none}");
18848    minify_test(
18849      ".foo { text-emphasis-style: filled }",
18850      ".foo{text-emphasis-style:filled}",
18851    );
18852    minify_test(".foo { text-emphasis-style: open }", ".foo{text-emphasis-style:open}");
18853    minify_test(".foo { text-emphasis-style: dot }", ".foo{text-emphasis-style:dot}");
18854    minify_test(
18855      ".foo { text-emphasis-style: filled dot }",
18856      ".foo{text-emphasis-style:dot}",
18857    );
18858    minify_test(
18859      ".foo { text-emphasis-style: dot filled }",
18860      ".foo{text-emphasis-style:dot}",
18861    );
18862    minify_test(
18863      ".foo { text-emphasis-style: open dot }",
18864      ".foo{text-emphasis-style:open dot}",
18865    );
18866    minify_test(
18867      ".foo { text-emphasis-style: dot open }",
18868      ".foo{text-emphasis-style:open dot}",
18869    );
18870    minify_test(".foo { text-emphasis-style: \"x\" }", ".foo{text-emphasis-style:\"x\"}");
18871
18872    minify_test(".foo { text-emphasis-color: yellow }", ".foo{text-emphasis-color:#ff0}");
18873
18874    minify_test(".foo { text-emphasis: none }", ".foo{text-emphasis:none}");
18875    minify_test(".foo { text-emphasis: filled }", ".foo{text-emphasis:filled}");
18876    minify_test(
18877      ".foo { text-emphasis: filled yellow }",
18878      ".foo{text-emphasis:filled #ff0}",
18879    );
18880    minify_test(
18881      ".foo { text-emphasis: dot filled yellow }",
18882      ".foo{text-emphasis:dot #ff0}",
18883    );
18884
18885    test(
18886      r#"
18887      .foo {
18888        text-emphasis-style: filled;
18889        text-emphasis-color: yellow;
18890      }
18891    "#,
18892      indoc! {r#"
18893      .foo {
18894        text-emphasis: filled #ff0;
18895      }
18896    "#},
18897    );
18898
18899    test(
18900      r#"
18901      .foo {
18902        text-emphasis: filled red;
18903        text-emphasis-color: yellow;
18904      }
18905    "#,
18906      indoc! {r#"
18907      .foo {
18908        text-emphasis: filled #ff0;
18909      }
18910    "#},
18911    );
18912
18913    test(
18914      r#"
18915      .foo {
18916        text-emphasis: filled yellow;
18917        text-emphasis-color: var(--color);
18918      }
18919    "#,
18920      indoc! {r#"
18921      .foo {
18922        text-emphasis: filled #ff0;
18923        text-emphasis-color: var(--color);
18924      }
18925    "#},
18926    );
18927
18928    prefix_test(
18929      r#"
18930      .foo {
18931        text-emphasis-style: filled;
18932      }
18933    "#,
18934      indoc! {r#"
18935      .foo {
18936        -webkit-text-emphasis-style: filled;
18937        text-emphasis-style: filled;
18938      }
18939    "#},
18940      Browsers {
18941        safari: Some(10 << 16),
18942        chrome: Some(30 << 16),
18943        firefox: Some(45 << 16),
18944        ..Browsers::default()
18945      },
18946    );
18947
18948    prefix_test(
18949      r#"
18950      .foo {
18951        -webkit-text-emphasis-style: filled;
18952        text-emphasis-style: filled;
18953      }
18954    "#,
18955      indoc! {r#"
18956      .foo {
18957        text-emphasis-style: filled;
18958      }
18959    "#},
18960      Browsers {
18961        safari: Some(10 << 16),
18962        firefox: Some(45 << 16),
18963        ..Browsers::default()
18964      },
18965    );
18966
18967    minify_test(
18968      ".foo { text-emphasis-position: over }",
18969      ".foo{text-emphasis-position:over}",
18970    );
18971    minify_test(
18972      ".foo { text-emphasis-position: under }",
18973      ".foo{text-emphasis-position:under}",
18974    );
18975    minify_test(
18976      ".foo { text-emphasis-position: over right }",
18977      ".foo{text-emphasis-position:over}",
18978    );
18979    minify_test(
18980      ".foo { text-emphasis-position: over left }",
18981      ".foo{text-emphasis-position:over left}",
18982    );
18983
18984    prefix_test(
18985      r#"
18986      .foo {
18987        text-emphasis-position: over;
18988      }
18989    "#,
18990      indoc! {r#"
18991      .foo {
18992        -webkit-text-emphasis-position: over;
18993        text-emphasis-position: over;
18994      }
18995    "#},
18996      Browsers {
18997        safari: Some(10 << 16),
18998        chrome: Some(30 << 16),
18999        firefox: Some(45 << 16),
19000        ..Browsers::default()
19001      },
19002    );
19003
19004    prefix_test(
19005      r#"
19006      .foo {
19007        text-emphasis-position: over left;
19008      }
19009    "#,
19010      indoc! {r#"
19011      .foo {
19012        text-emphasis-position: over left;
19013      }
19014    "#},
19015      Browsers {
19016        safari: Some(10 << 16),
19017        chrome: Some(30 << 16),
19018        firefox: Some(45 << 16),
19019        ..Browsers::default()
19020      },
19021    );
19022
19023    prefix_test(
19024      r#"
19025      .foo {
19026        text-emphasis-position: var(--test);
19027      }
19028    "#,
19029      indoc! {r#"
19030      .foo {
19031        -webkit-text-emphasis-position: var(--test);
19032        text-emphasis-position: var(--test);
19033      }
19034    "#},
19035      Browsers {
19036        safari: Some(10 << 16),
19037        chrome: Some(30 << 16),
19038        firefox: Some(45 << 16),
19039        ..Browsers::default()
19040      },
19041    );
19042
19043    prefix_test(
19044      r#"
19045      .foo {
19046        text-emphasis: filled lch(50.998% 135.363 338);
19047      }
19048    "#,
19049      indoc! {r#"
19050      .foo {
19051        -webkit-text-emphasis: filled #f000c0;
19052        text-emphasis: filled #f000c0;
19053        -webkit-text-emphasis: filled lch(50.998% 135.363 338);
19054        text-emphasis: filled lch(50.998% 135.363 338);
19055      }
19056    "#},
19057      Browsers {
19058        chrome: Some(25 << 16),
19059        firefox: Some(48 << 16),
19060        ..Browsers::default()
19061      },
19062    );
19063
19064    prefix_test(
19065      r#"
19066      .foo {
19067        text-emphasis-color: lch(50.998% 135.363 338);
19068      }
19069    "#,
19070      indoc! {r#"
19071      .foo {
19072        -webkit-text-emphasis-color: #f000c0;
19073        text-emphasis-color: #f000c0;
19074        -webkit-text-emphasis-color: lch(50.998% 135.363 338);
19075        text-emphasis-color: lch(50.998% 135.363 338);
19076      }
19077    "#},
19078      Browsers {
19079        chrome: Some(25 << 16),
19080        firefox: Some(48 << 16),
19081        ..Browsers::default()
19082      },
19083    );
19084
19085    prefix_test(
19086      r#"
19087      .foo {
19088        text-emphasis: lch(50.998% 135.363 338) var(--style);
19089      }
19090    "#,
19091      indoc! {r#"
19092      .foo {
19093        text-emphasis: #f000c0 var(--style);
19094      }
19095
19096      @supports (color: lab(0% 0 0)) {
19097        .foo {
19098          text-emphasis: lab(50.998% 125.506 -50.7078) var(--style);
19099        }
19100      }
19101    "#},
19102      Browsers {
19103        safari: Some(8 << 16),
19104        ..Browsers::default()
19105      },
19106    );
19107
19108    prefix_test(
19109      r#"
19110      @supports (color: lab(0% 0 0)) {
19111        .foo {
19112          text-emphasis: lab(50.998% 125.506 -50.7078) var(--style);
19113        }
19114      }
19115    "#,
19116      indoc! {r#"
19117      @supports (color: lab(0% 0 0)) {
19118        .foo {
19119          text-emphasis: lab(50.998% 125.506 -50.7078) var(--style);
19120        }
19121      }
19122    "#},
19123      Browsers {
19124        safari: Some(8 << 16),
19125        ..Browsers::default()
19126      },
19127    );
19128  }
19129
19130  #[test]
19131  fn test_text_shadow() {
19132    property_range_test(
19133      &["text-shadow"],
19134      &[
19135        ("1px 2px -3px", None),
19136        ("1px 2px 0 -4px", None),
19137        ("-1px -2px", Some("-1px -2px")),
19138        ("1px 2px calc(-3px)", Some("1px 2px")),
19139      ],
19140    );
19141    minify_test(
19142      ".foo { text-shadow: 1px 1px 2px yellow; }",
19143      ".foo{text-shadow:1px 1px 2px #ff0}",
19144    );
19145    minify_test(
19146      ".foo { text-shadow: 1px 1px 2px 3px yellow; }",
19147      ".foo{text-shadow:1px 1px 2px 3px #ff0}",
19148    );
19149    minify_test(
19150      ".foo { text-shadow: 1px 1px 0 yellow; }",
19151      ".foo{text-shadow:1px 1px #ff0}",
19152    );
19153    minify_test(
19154      ".foo { text-shadow: 1px 1px yellow; }",
19155      ".foo{text-shadow:1px 1px #ff0}",
19156    );
19157    minify_test(
19158      ".foo { text-shadow: 1px 1px yellow, 2px 3px red; }",
19159      ".foo{text-shadow:1px 1px #ff0,2px 3px red}",
19160    );
19161
19162    prefix_test(
19163      ".foo { text-shadow: 12px 12px lab(40% 56.6 39) }",
19164      indoc! { r#"
19165        .foo {
19166          text-shadow: 12px 12px #b32323;
19167          text-shadow: 12px 12px lab(40% 56.6 39);
19168        }
19169      "#},
19170      Browsers {
19171        chrome: Some(4 << 16),
19172        ..Browsers::default()
19173      },
19174    );
19175
19176    prefix_test(
19177      ".foo { text-shadow: 12px 12px lab(40% 56.6 39) }",
19178      indoc! { r#"
19179        .foo {
19180          text-shadow: 12px 12px #b32323;
19181          text-shadow: 12px 12px color(display-p3 .643308 .192455 .167712);
19182          text-shadow: 12px 12px lab(40% 56.6 39);
19183        }
19184      "#},
19185      Browsers {
19186        chrome: Some(90 << 16),
19187        safari: Some(14 << 16),
19188        ..Browsers::default()
19189      },
19190    );
19191
19192    prefix_test(
19193      ".foo { text-shadow: 12px 12px lab(40% 56.6 39), 12px 12px yellow }",
19194      indoc! { r#"
19195        .foo {
19196          text-shadow: 12px 12px #b32323, 12px 12px #ff0;
19197          text-shadow: 12px 12px lab(40% 56.6 39), 12px 12px #ff0;
19198        }
19199      "#},
19200      Browsers {
19201        chrome: Some(4 << 16),
19202        ..Browsers::default()
19203      },
19204    );
19205
19206    prefix_test(
19207      ".foo { text-shadow: var(--foo) 12px lab(40% 56.6 39) }",
19208      indoc! { r#"
19209        .foo {
19210          text-shadow: var(--foo) 12px #b32323;
19211        }
19212
19213        @supports (color: lab(0% 0 0)) {
19214          .foo {
19215            text-shadow: var(--foo) 12px lab(40% 56.6 39);
19216          }
19217        }
19218      "#},
19219      Browsers {
19220        chrome: Some(4 << 16),
19221        ..Browsers::default()
19222      },
19223    );
19224
19225    prefix_test(
19226      r#"
19227        @supports (color: lab(0% 0 0)) {
19228          .foo {
19229            text-shadow: var(--foo) 12px lab(40% 56.6 39);
19230          }
19231        }
19232      "#,
19233      indoc! { r#"
19234        @supports (color: lab(0% 0 0)) {
19235          .foo {
19236            text-shadow: var(--foo) 12px lab(40% 56.6 39);
19237          }
19238        }
19239      "#},
19240      Browsers {
19241        chrome: Some(4 << 16),
19242        ..Browsers::default()
19243      },
19244    );
19245  }
19246
19247  #[test]
19248  fn test_break() {
19249    prefix_test(
19250      r#"
19251      .foo {
19252        box-decoration-break: clone;
19253      }
19254    "#,
19255      indoc! {r#"
19256      .foo {
19257        -webkit-box-decoration-break: clone;
19258        box-decoration-break: clone;
19259      }
19260    "#},
19261      Browsers {
19262        safari: Some(15 << 16),
19263        ..Browsers::default()
19264      },
19265    );
19266
19267    prefix_test(
19268      r#"
19269      .foo {
19270        box-decoration-break: clone;
19271      }
19272    "#,
19273      indoc! {r#"
19274      .foo {
19275        box-decoration-break: clone;
19276      }
19277    "#},
19278      Browsers {
19279        firefox: Some(95 << 16),
19280        ..Browsers::default()
19281      },
19282    );
19283  }
19284
19285  #[test]
19286  fn test_position() {
19287    test(
19288      r#"
19289      .foo {
19290        position: relative;
19291        position: absolute;
19292      }
19293    "#,
19294      indoc! {r#"
19295      .foo {
19296        position: absolute;
19297      }
19298    "#},
19299    );
19300
19301    test(
19302      r#"
19303      .foo {
19304        position: -webkit-sticky;
19305        position: sticky;
19306      }
19307    "#,
19308      indoc! {r#"
19309      .foo {
19310        position: -webkit-sticky;
19311        position: sticky;
19312      }
19313    "#},
19314    );
19315
19316    prefix_test(
19317      r#"
19318      .foo {
19319        position: sticky;
19320      }
19321    "#,
19322      indoc! {r#"
19323      .foo {
19324        position: -webkit-sticky;
19325        position: sticky;
19326      }
19327    "#},
19328      Browsers {
19329        safari: Some(8 << 16),
19330        ..Browsers::default()
19331      },
19332    );
19333
19334    prefix_test(
19335      r#"
19336      .foo {
19337        position: -webkit-sticky;
19338        position: sticky;
19339      }
19340    "#,
19341      indoc! {r#"
19342      .foo {
19343        position: sticky;
19344      }
19345    "#},
19346      Browsers {
19347        safari: Some(13 << 16),
19348        ..Browsers::default()
19349      },
19350    );
19351
19352    test(
19353      r#"
19354      .foo {
19355        top: 0;
19356        left: 0;
19357        bottom: 0;
19358        right: 0;
19359      }
19360    "#,
19361      indoc! {r#"
19362      .foo {
19363        inset: 0;
19364      }
19365    "#},
19366    );
19367
19368    test(
19369      r#"
19370      .foo {
19371        top: 2px;
19372        left: 4px;
19373        bottom: 2px;
19374        right: 4px;
19375      }
19376    "#,
19377      indoc! {r#"
19378      .foo {
19379        inset: 2px 4px;
19380      }
19381    "#},
19382    );
19383
19384    test(
19385      r#"
19386      .foo {
19387        top: 1px;
19388        left: 2px;
19389        bottom: 3px;
19390        right: 4px;
19391      }
19392    "#,
19393      indoc! {r#"
19394      .foo {
19395        inset: 1px 4px 3px 2px;
19396      }
19397    "#},
19398    );
19399
19400    test(
19401      r#"
19402      .foo {
19403        inset-block-start: 2px;
19404        inset-block-end: 2px;
19405        inset-inline-start: 4px;
19406        inset-inline-end: 4px;
19407      }
19408    "#,
19409      indoc! {r#"
19410      .foo {
19411        inset-block: 2px;
19412        inset-inline: 4px;
19413      }
19414    "#},
19415    );
19416
19417    test(
19418      r#"
19419      .foo {
19420        inset-block-start: 2px;
19421        inset-block-end: 3px;
19422        inset-inline-start: 4px;
19423        inset-inline-end: 5px;
19424      }
19425    "#,
19426      indoc! {r#"
19427      .foo {
19428        inset-block: 2px 3px;
19429        inset-inline: 4px 5px;
19430      }
19431    "#},
19432    );
19433
19434    test(
19435      r#"
19436      .foo {
19437        inset-block-start: 2px;
19438        inset-block-end: 3px;
19439        inset: 4px;
19440        inset-inline-start: 4px;
19441        inset-inline-end: 5px;
19442      }
19443    "#,
19444      indoc! {r#"
19445      .foo {
19446        inset: 4px;
19447        inset-inline: 4px 5px;
19448      }
19449    "#},
19450    );
19451
19452    prefix_test(
19453      r#"
19454      .foo {
19455        inset-inline-start: 2px;
19456      }
19457    "#,
19458      indoc! {r#"
19459      .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))) {
19460        left: 2px;
19461      }
19462
19463      .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))) {
19464        left: 2px;
19465      }
19466
19467      .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)) {
19468        right: 2px;
19469      }
19470
19471      .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)) {
19472        right: 2px;
19473      }
19474    "#
19475      },
19476      Browsers {
19477        safari: Some(8 << 16),
19478        ..Browsers::default()
19479      },
19480    );
19481
19482    prefix_test(
19483      r#"
19484      .foo {
19485        inset-inline-start: 2px;
19486        inset-inline-end: 4px;
19487      }
19488    "#,
19489      indoc! {r#"
19490      .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))) {
19491        left: 2px;
19492        right: 4px;
19493      }
19494
19495      .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))) {
19496        left: 2px;
19497        right: 4px;
19498      }
19499
19500      .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)) {
19501        left: 4px;
19502        right: 2px;
19503      }
19504
19505      .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)) {
19506        left: 4px;
19507        right: 2px;
19508      }
19509    "#
19510      },
19511      Browsers {
19512        safari: Some(8 << 16),
19513        ..Browsers::default()
19514      },
19515    );
19516
19517    prefix_test(
19518      r#"
19519      .foo {
19520        inset-inline: 2px;
19521      }
19522    "#,
19523      indoc! {r#"
19524      .foo {
19525        left: 2px;
19526        right: 2px;
19527      }
19528    "#
19529      },
19530      Browsers {
19531        safari: Some(8 << 16),
19532        ..Browsers::default()
19533      },
19534    );
19535
19536    prefix_test(
19537      r#"
19538      .foo {
19539        inset-block-start: 2px;
19540      }
19541    "#,
19542      indoc! {r#"
19543      .foo {
19544        top: 2px;
19545      }
19546    "#
19547      },
19548      Browsers {
19549        safari: Some(8 << 16),
19550        ..Browsers::default()
19551      },
19552    );
19553
19554    prefix_test(
19555      r#"
19556      .foo {
19557        inset-block-end: 2px;
19558      }
19559    "#,
19560      indoc! {r#"
19561      .foo {
19562        bottom: 2px;
19563      }
19564    "#
19565      },
19566      Browsers {
19567        safari: Some(8 << 16),
19568        ..Browsers::default()
19569      },
19570    );
19571
19572    prefix_test(
19573      r#"
19574      .foo {
19575        top: 1px;
19576        left: 2px;
19577        bottom: 3px;
19578        right: 4px;
19579      }
19580    "#,
19581      indoc! {r#"
19582      .foo {
19583        top: 1px;
19584        bottom: 3px;
19585        left: 2px;
19586        right: 4px;
19587      }
19588    "#},
19589      Browsers {
19590        safari: Some(8 << 16),
19591        ..Browsers::default()
19592      },
19593    );
19594  }
19595
19596  #[test]
19597  fn test_overflow() {
19598    minify_test(".foo { overflow: hidden }", ".foo{overflow:hidden}");
19599    minify_test(".foo { overflow: hidden hidden }", ".foo{overflow:hidden}");
19600    minify_test(".foo { overflow: hidden auto }", ".foo{overflow:hidden auto}");
19601
19602    test(
19603      r#"
19604      .foo {
19605        overflow-x: hidden;
19606        overflow-y: auto;
19607      }
19608    "#,
19609      indoc! {r#"
19610      .foo {
19611        overflow: hidden auto;
19612      }
19613    "#},
19614    );
19615
19616    test(
19617      r#"
19618      .foo {
19619        overflow: hidden;
19620        overflow-y: auto;
19621      }
19622    "#,
19623      indoc! {r#"
19624      .foo {
19625        overflow: hidden auto;
19626      }
19627    "#},
19628    );
19629    test(
19630      r#"
19631      .foo {
19632        overflow: hidden;
19633        overflow-y: var(--y);
19634      }
19635    "#,
19636      indoc! {r#"
19637      .foo {
19638        overflow: hidden;
19639        overflow-y: var(--y);
19640      }
19641    "#},
19642    );
19643    prefix_test(
19644      r#"
19645      .foo {
19646        overflow: hidden auto;
19647      }
19648    "#,
19649      indoc! {r#"
19650      .foo {
19651        overflow-x: hidden;
19652        overflow-y: auto;
19653      }
19654    "#},
19655      Browsers {
19656        chrome: Some(67 << 16),
19657        ..Browsers::default()
19658      },
19659    );
19660    prefix_test(
19661      r#"
19662      .foo {
19663        overflow: hidden hidden;
19664      }
19665    "#,
19666      indoc! {r#"
19667      .foo {
19668        overflow: hidden;
19669      }
19670    "#},
19671      Browsers {
19672        chrome: Some(67 << 16),
19673        ..Browsers::default()
19674      },
19675    );
19676    prefix_test(
19677      r#"
19678      .foo {
19679        overflow: hidden auto;
19680      }
19681    "#,
19682      indoc! {r#"
19683      .foo {
19684        overflow: hidden auto;
19685      }
19686    "#},
19687      Browsers {
19688        chrome: Some(68 << 16),
19689        ..Browsers::default()
19690      },
19691    );
19692
19693    minify_test(".foo { text-overflow: ellipsis }", ".foo{text-overflow:ellipsis}");
19694    prefix_test(
19695      r#"
19696      .foo {
19697        text-overflow: ellipsis;
19698      }
19699    "#,
19700      indoc! {r#"
19701      .foo {
19702        -o-text-overflow: ellipsis;
19703        text-overflow: ellipsis;
19704      }
19705    "#},
19706      Browsers {
19707        safari: Some(4 << 16),
19708        opera: Some(10 << 16),
19709        ..Browsers::default()
19710      },
19711    );
19712
19713    prefix_test(
19714      r#"
19715      .foo {
19716        -o-text-overflow: ellipsis;
19717        text-overflow: ellipsis;
19718      }
19719    "#,
19720      indoc! {r#"
19721      .foo {
19722        text-overflow: ellipsis;
19723      }
19724    "#},
19725      Browsers {
19726        safari: Some(4 << 16),
19727        opera: Some(14 << 16),
19728        ..Browsers::default()
19729      },
19730    );
19731  }
19732
19733  #[test]
19734  fn test_ui() {
19735    minify_test(".foo { resize: both }", ".foo{resize:both}");
19736    minify_test(".foo { resize: Horizontal }", ".foo{resize:horizontal}");
19737    minify_test(".foo { cursor: ew-resize }", ".foo{cursor:ew-resize}");
19738    minify_test(
19739      ".foo { cursor: url(\"test.cur\"), ew-resize }",
19740      ".foo{cursor:url(test.cur),ew-resize}",
19741    );
19742    minify_test(
19743      ".foo { cursor: url(\"test.cur\"), url(\"foo.cur\"), ew-resize }",
19744      ".foo{cursor:url(test.cur),url(foo.cur),ew-resize}",
19745    );
19746    minify_test(".foo { caret-color: auto }", ".foo{caret-color:auto}");
19747    minify_test(".foo { caret-color: yellow }", ".foo{caret-color:#ff0}");
19748    minify_test(".foo { caret-shape: block }", ".foo{caret-shape:block}");
19749    minify_test(".foo { caret: yellow block }", ".foo{caret:#ff0 block}");
19750    minify_test(".foo { caret: block yellow }", ".foo{caret:#ff0 block}");
19751    minify_test(".foo { caret: block }", ".foo{caret:block}");
19752    minify_test(".foo { caret: yellow }", ".foo{caret:#ff0}");
19753    minify_test(".foo { caret: auto auto }", ".foo{caret:auto}");
19754    minify_test(".foo { caret: auto }", ".foo{caret:auto}");
19755    minify_test(".foo { caret: yellow auto }", ".foo{caret:#ff0}");
19756    minify_test(".foo { caret: auto block }", ".foo{caret:block}");
19757    minify_test(".foo { user-select: none }", ".foo{user-select:none}");
19758    minify_test(".foo { -webkit-user-select: none }", ".foo{-webkit-user-select:none}");
19759    minify_test(".foo { accent-color: auto }", ".foo{accent-color:auto}");
19760    minify_test(".foo { accent-color: yellow }", ".foo{accent-color:#ff0}");
19761    minify_test(".foo { appearance: None }", ".foo{appearance:none}");
19762    minify_test(
19763      ".foo { -webkit-appearance: textfield }",
19764      ".foo{-webkit-appearance:textfield}",
19765    );
19766
19767    prefix_test(
19768      r#"
19769      .foo {
19770        user-select: none;
19771      }
19772    "#,
19773      indoc! {r#"
19774      .foo {
19775        -webkit-user-select: none;
19776        -moz-user-select: none;
19777        -ms-user-select: none;
19778        user-select: none;
19779      }
19780    "#},
19781      Browsers {
19782        safari: Some(8 << 16),
19783        opera: Some(5 << 16),
19784        firefox: Some(10 << 16),
19785        ie: Some(10 << 16),
19786        ..Browsers::default()
19787      },
19788    );
19789
19790    prefix_test(
19791      r#"
19792      .foo {
19793        -webkit-user-select: none;
19794        -moz-user-select: none;
19795        -ms-user-select: none;
19796        user-select: none;
19797      }
19798    "#,
19799      indoc! {r#"
19800      .foo {
19801        -webkit-user-select: none;
19802        user-select: none;
19803      }
19804    "#},
19805      Browsers {
19806        safari: Some(8 << 16),
19807        opera: Some(80 << 16),
19808        firefox: Some(80 << 16),
19809        edge: Some(80 << 16),
19810        ..Browsers::default()
19811      },
19812    );
19813
19814    prefix_test(
19815      r#"
19816      .foo {
19817        -webkit-user-select: none;
19818        -moz-user-select: none;
19819        -ms-user-select: none;
19820        user-select: none;
19821      }
19822    "#,
19823      indoc! {r#"
19824      .foo {
19825        user-select: none;
19826      }
19827    "#},
19828      Browsers {
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        appearance: none;
19840      }
19841    "#,
19842      indoc! {r#"
19843      .foo {
19844        -webkit-appearance: none;
19845        -moz-appearance: none;
19846        -ms-appearance: none;
19847        appearance: none;
19848      }
19849    "#},
19850      Browsers {
19851        safari: Some(8 << 16),
19852        chrome: Some(80 << 16),
19853        firefox: Some(10 << 16),
19854        ie: Some(11 << 16),
19855        ..Browsers::default()
19856      },
19857    );
19858
19859    prefix_test(
19860      r#"
19861      .foo {
19862        -webkit-appearance: none;
19863        -moz-appearance: none;
19864        -ms-appearance: none;
19865        appearance: none;
19866      }
19867    "#,
19868      indoc! {r#"
19869      .foo {
19870        -webkit-appearance: none;
19871        appearance: none;
19872      }
19873    "#},
19874      Browsers {
19875        safari: Some(15 << 16),
19876        chrome: Some(85 << 16),
19877        firefox: Some(80 << 16),
19878        edge: Some(85 << 16),
19879        ..Browsers::default()
19880      },
19881    );
19882
19883    prefix_test(
19884      r#"
19885      .foo {
19886        -webkit-appearance: none;
19887        -moz-appearance: none;
19888        -ms-appearance: none;
19889        appearance: none;
19890      }
19891    "#,
19892      indoc! {r#"
19893      .foo {
19894        appearance: none;
19895      }
19896    "#},
19897      Browsers {
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      ".foo { caret-color: lch(50.998% 135.363 338) }",
19907      indoc! { r#"
19908        .foo {
19909          caret-color: #f000c0;
19910          caret-color: color(display-p3 .972962 -.362078 .804206);
19911          caret-color: lch(50.998% 135.363 338);
19912        }
19913      "#},
19914      Browsers {
19915        chrome: Some(90 << 16),
19916        safari: Some(14 << 16),
19917        ..Browsers::default()
19918      },
19919    );
19920
19921    prefix_test(
19922      ".foo { caret: lch(50.998% 135.363 338) block }",
19923      indoc! { r#"
19924        .foo {
19925          caret: #f000c0 block;
19926          caret: color(display-p3 .972962 -.362078 .804206) block;
19927          caret: lch(50.998% 135.363 338) block;
19928        }
19929      "#},
19930      Browsers {
19931        chrome: Some(90 << 16),
19932        safari: Some(14 << 16),
19933        ..Browsers::default()
19934      },
19935    );
19936
19937    prefix_test(
19938      ".foo { caret: lch(50.998% 135.363 338) var(--foo) }",
19939      indoc! { r#"
19940        .foo {
19941          caret: #f000c0 var(--foo);
19942        }
19943
19944        @supports (color: lab(0% 0 0)) {
19945          .foo {
19946            caret: lab(50.998% 125.506 -50.7078) var(--foo);
19947          }
19948        }
19949      "#},
19950      Browsers {
19951        chrome: Some(90 << 16),
19952        ..Browsers::default()
19953      },
19954    );
19955
19956    prefix_test(
19957      r#"
19958        @supports (color: lab(0% 0 0)) {
19959          .foo {
19960            caret: lab(50.998% 125.506 -50.7078) var(--foo);
19961          }
19962        }
19963      "#,
19964      indoc! { r#"
19965        @supports (color: lab(0% 0 0)) {
19966          .foo {
19967            caret: lab(50.998% 125.506 -50.7078) var(--foo);
19968          }
19969        }
19970      "#},
19971      Browsers {
19972        chrome: Some(90 << 16),
19973        ..Browsers::default()
19974      },
19975    );
19976  }
19977
19978  #[test]
19979  fn test_list() {
19980    minify_test(".foo { list-style-type: disc; }", ".foo{list-style-type:disc}");
19981    minify_test(".foo { list-style-type: \"★\"; }", ".foo{list-style-type:\"★\"}");
19982    minify_test(
19983      ".foo { list-style-type: symbols(cyclic '○' '●'); }",
19984      ".foo{list-style-type:symbols(cyclic \"○\" \"●\")}",
19985    );
19986    minify_test(
19987      ".foo { list-style-type: symbols('○' '●'); }",
19988      ".foo{list-style-type:symbols(\"○\" \"●\")}",
19989    );
19990    minify_test(
19991      ".foo { list-style-type: symbols(symbolic '○' '●'); }",
19992      ".foo{list-style-type:symbols(\"○\" \"●\")}",
19993    );
19994    minify_test(
19995      ".foo { list-style-type: symbols(symbolic url('ellipse.png')); }",
19996      ".foo{list-style-type:symbols(url(ellipse.png))}",
19997    );
19998    minify_test(
19999      ".foo { list-style-image: url('ellipse.png'); }",
20000      ".foo{list-style-image:url(ellipse.png)}",
20001    );
20002    minify_test(
20003      ".foo { list-style-position: outside; }",
20004      ".foo{list-style-position:outside}",
20005    );
20006    minify_test(
20007      ".foo { list-style: \"★\" url(ellipse.png) outside; }",
20008      ".foo{list-style:url(ellipse.png) \"★\"}",
20009    );
20010    minify_test(".foo { list-style: none; }", ".foo{list-style:none}");
20011    minify_test(".foo { list-style: none none outside; }", ".foo{list-style:none}");
20012    minify_test(".foo { list-style: none none inside; }", ".foo{list-style:inside none}");
20013    minify_test(".foo { list-style: none inside; }", ".foo{list-style:inside none}");
20014    minify_test(".foo { list-style: none disc; }", ".foo{list-style:outside}");
20015    minify_test(".foo { list-style: none inside disc; }", ".foo{list-style:inside}");
20016    minify_test(".foo { list-style: none \"★\"; }", ".foo{list-style:\"★\"}");
20017    minify_test(
20018      ".foo { list-style: none url(foo.png); }",
20019      ".foo{list-style:url(foo.png) none}",
20020    );
20021
20022    test(
20023      r#"
20024      .foo {
20025        list-style-type: disc;
20026        list-style-image: url(ellipse.png);
20027        list-style-position: outside;
20028      }
20029    "#,
20030      indoc! {r#"
20031      .foo {
20032        list-style: url("ellipse.png");
20033      }
20034    "#},
20035    );
20036
20037    test(
20038      r#"
20039      .foo {
20040        list-style: \"★\" url(ellipse.png) outside;
20041        list-style-image: none;
20042      }
20043    "#,
20044      indoc! {r#"
20045      .foo {
20046        list-style: \"★\";
20047      }
20048    "#},
20049    );
20050
20051    test(
20052      r#"
20053      .foo {
20054        list-style: \"★\" url(ellipse.png) outside;
20055        list-style-image: var(--img);
20056      }
20057    "#,
20058      indoc! {r#"
20059      .foo {
20060        list-style: url("ellipse.png") \"★\";
20061        list-style-image: var(--img);
20062      }
20063    "#},
20064    );
20065
20066    prefix_test(
20067      ".foo { list-style-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
20068      indoc! { r#"
20069        .foo {
20070          list-style-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ff0b0c), to(#766eff));
20071          list-style-image: -webkit-linear-gradient(top, #ff0b0c, #766eff);
20072          list-style-image: linear-gradient(#ff0b0c, #766eff);
20073          list-style-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
20074        }
20075      "#},
20076      Browsers {
20077        chrome: Some(8 << 16),
20078        ..Browsers::default()
20079      },
20080    );
20081
20082    prefix_test(
20083      ".foo { list-style: \"★\" linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
20084      indoc! { r#"
20085        .foo {
20086          list-style: linear-gradient(#ff0b0c, #766eff) "★";
20087          list-style: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) "★";
20088        }
20089      "#},
20090      Browsers {
20091        chrome: Some(90 << 16),
20092        ..Browsers::default()
20093      },
20094    );
20095
20096    prefix_test(
20097      ".foo { list-style: var(--foo) linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
20098      indoc! { r#"
20099        .foo {
20100          list-style: var(--foo) linear-gradient(#ff0b0c, #766eff);
20101        }
20102
20103        @supports (color: lab(0% 0 0)) {
20104          .foo {
20105            list-style: var(--foo) linear-gradient(lab(56.208% 94.4644 98.8928), lab(51% 70.4544 -115.586));
20106          }
20107        }
20108      "#},
20109      Browsers {
20110        chrome: Some(90 << 16),
20111        ..Browsers::default()
20112      },
20113    );
20114
20115    prefix_test(
20116      r#"
20117        @supports (color: lab(0% 0 0)) {
20118          .foo {
20119            list-style: var(--foo) linear-gradient(lab(56.208% 94.4644 98.8928), lab(51% 70.4544 -115.586));
20120          }
20121        }
20122      "#,
20123      indoc! { r#"
20124        @supports (color: lab(0% 0 0)) {
20125          .foo {
20126            list-style: var(--foo) linear-gradient(lab(56.208% 94.4644 98.8928), lab(51% 70.4544 -115.586));
20127          }
20128        }
20129      "#},
20130      Browsers {
20131        chrome: Some(90 << 16),
20132        ..Browsers::default()
20133      },
20134    );
20135
20136    test(
20137      r#"
20138      .foo {
20139        list-style: inside;
20140        list-style-type: disc;
20141      }
20142    "#,
20143      indoc! {r#"
20144      .foo {
20145        list-style: inside;
20146      }
20147    "#},
20148    );
20149    test(
20150      r#"
20151      .foo {
20152        list-style: inside;
20153        list-style-type: decimal;
20154      }
20155    "#,
20156      indoc! {r#"
20157      .foo {
20158        list-style: inside decimal;
20159      }
20160    "#},
20161    );
20162  }
20163
20164  #[test]
20165  fn test_image_set() {
20166    // Spec: https://drafts.csswg.org/css-images-4/#image-set-notation
20167    // WPT: https://github.com/web-platform-tests/wpt/blob/master/css/css-images/image-set/image-set-parsing.html
20168    // test image-set(<string>)
20169    minify_test(
20170      ".foo { background: image-set(\"foo.png\" 2x, url(bar.png) 1x) }",
20171      ".foo{background:image-set(\"foo.png\" 2x,\"bar.png\" 1x)}",
20172    );
20173
20174    // test image-set(type(<string>))
20175    minify_test(
20176      ".foo { background: image-set('foo.webp' type('webp'), url(foo.jpg)) }",
20177      ".foo{background:image-set(\"foo.webp\" 1x type(\"webp\"),\"foo.jpg\" 1x)}",
20178    );
20179    minify_test(
20180      ".foo { background: image-set('foo.avif' 2x type('image/avif'), url(foo.png)) }",
20181      ".foo{background:image-set(\"foo.avif\" 2x type(\"image/avif\"),\"foo.png\" 1x)}",
20182    );
20183    minify_test(
20184      ".foo { background: image-set(url('example.png') 3x type('image/png')) }",
20185      ".foo{background:image-set(\"example.png\" 3x type(\"image/png\"))}",
20186    );
20187
20188    minify_test(
20189      ".foo { background: image-set(url(example.png) type('image/png') 1x) }",
20190      ".foo{background:image-set(\"example.png\" 1x type(\"image/png\"))}",
20191    );
20192
20193    minify_test(
20194      ".foo { background: -webkit-image-set(url(\"foo.png\") 2x, url(bar.png) 1x) }",
20195      ".foo{background:-webkit-image-set(url(foo.png) 2x,url(bar.png) 1x)}",
20196    );
20197
20198    test(
20199      r#"
20200      .foo {
20201        background: -webkit-image-set(url("foo.png") 2x, url(bar.png) 1x);
20202        background: image-set(url("foo.png") 2x, url(bar.png) 1x);
20203      }
20204    "#,
20205      indoc! {r#"
20206      .foo {
20207        background: -webkit-image-set(url("foo.png") 2x, url("bar.png") 1x);
20208        background: image-set("foo.png" 2x, "bar.png" 1x);
20209      }
20210    "#},
20211    );
20212
20213    // test image-set(<gradient>)
20214    test(
20215      r#"
20216      .foo {
20217        background: image-set(linear-gradient(cornflowerblue, white) 1x, url("detailed-gradient.png") 3x);
20218      }
20219    "#,
20220      indoc! {r#"
20221      .foo {
20222        background: image-set(linear-gradient(#6495ed, #fff) 1x, "detailed-gradient.png" 3x);
20223      }
20224    "#},
20225    );
20226
20227    prefix_test(
20228      r#"
20229      .foo {
20230        background: image-set(url("foo.png") 2x, url(bar.png) 1x);
20231      }
20232    "#,
20233      indoc! {r#"
20234      .foo {
20235        background: -webkit-image-set(url("foo.png") 2x, url("bar.png") 1x);
20236        background: image-set("foo.png" 2x, "bar.png" 1x);
20237      }
20238    "#},
20239      Browsers {
20240        chrome: Some(85 << 16),
20241        firefox: Some(80 << 16),
20242        ..Browsers::default()
20243      },
20244    );
20245
20246    prefix_test(
20247      r#"
20248      .foo {
20249        background: -webkit-image-set(url("foo.png") 2x, url(bar.png) 1x);
20250        background: image-set(url("foo.png") 2x, url(bar.png) 1x);
20251      }
20252    "#,
20253      indoc! {r#"
20254      .foo {
20255        background: -webkit-image-set(url("foo.png") 2x, url("bar.png") 1x);
20256        background: image-set("foo.png" 2x, "bar.png" 1x);
20257      }
20258    "#},
20259      Browsers {
20260        firefox: Some(80 << 16),
20261        ..Browsers::default()
20262      },
20263    );
20264
20265    prefix_test(
20266      r#"
20267      .foo {
20268        background: -webkit-image-set(url("foo.png") 2x, url(bar.png) 1x);
20269      }
20270    "#,
20271      indoc! {r#"
20272      .foo {
20273        background: -webkit-image-set(url("foo.png") 2x, url("bar.png") 1x);
20274      }
20275    "#},
20276      Browsers {
20277        chrome: Some(95 << 16),
20278        ..Browsers::default()
20279      },
20280    );
20281
20282    for property in &[
20283      "background",
20284      "background-image",
20285      "border-image-source",
20286      "border-image",
20287      "border-image-source",
20288      "-webkit-mask-image",
20289      "-webkit-mask",
20290      "list-style-image",
20291      "list-style",
20292    ] {
20293      prefix_test(
20294        &format!(
20295          r#"
20296        .foo {{
20297          {}: url(foo.png);
20298          {}: image-set(url("foo.png") 2x, url(bar.png) 1x);
20299        }}
20300      "#,
20301          property, property
20302        ),
20303        &format!(
20304          indoc! {r#"
20305        .foo {{
20306          {}: url("foo.png");
20307          {}: image-set("foo.png" 2x, "bar.png" 1x);
20308        }}
20309      "#},
20310          property, property
20311        ),
20312        Browsers {
20313          ie: Some(11 << 16),
20314          chrome: Some(95 << 16),
20315          ..Browsers::default()
20316        },
20317      );
20318
20319      prefix_test(
20320        &format!(
20321          r#"
20322        .foo {{
20323          {}: url(foo.png);
20324          {}: image-set(url("foo.png") 2x, url(bar.png) 1x);
20325        }}
20326      "#,
20327          property, property
20328        ),
20329        &format!(
20330          indoc! {r#"
20331        .foo {{
20332          {}: -webkit-image-set(url("foo.png") 2x, url("bar.png") 1x);
20333          {}: image-set("foo.png" 2x, "bar.png" 1x);
20334        }}
20335      "#},
20336          property, property
20337        ),
20338        Browsers {
20339          chrome: Some(95 << 16),
20340          ..Browsers::default()
20341        },
20342      );
20343    }
20344  }
20345
20346  #[test]
20347  fn test_color() {
20348    minify_test(".foo { color: yellow }", ".foo{color:#ff0}");
20349    minify_test(".foo { color: rgb(255, 255, 0) }", ".foo{color:#ff0}");
20350    minify_test(".foo { color: rgba(255, 255, 0, 1) }", ".foo{color:#ff0}");
20351    minify_test(".foo { color: rgba(255, 255, 0, 0.8) }", ".foo{color:#ff0c}");
20352    minify_test(".foo { color: rgb(128, 128, 128) }", ".foo{color:gray}");
20353    minify_test(".foo { color: rgb(123, 255, 255) }", ".foo{color:#7bffff}");
20354    minify_test(".foo { color: rgba(123, 255, 255, 0.5) }", ".foo{color:#7bffff80}");
20355    minify_test(".foo { color: rgb(123 255 255) }", ".foo{color:#7bffff}");
20356    minify_test(".foo { color: rgb(123 255 255 / .5) }", ".foo{color:#7bffff80}");
20357    minify_test(".foo { color: rgb(123 255 255 / 50%) }", ".foo{color:#7bffff80}");
20358    minify_test(".foo { color: rgb(48% 100% 100% / 50%) }", ".foo{color:#7affff80}");
20359    minify_test(".foo { color: hsl(100deg, 100%, 50%) }", ".foo{color:#5f0}");
20360    minify_test(".foo { color: hsl(100, 100%, 50%) }", ".foo{color:#5f0}");
20361    minify_test(".foo { color: hsl(100 100% 50%) }", ".foo{color:#5f0}");
20362    minify_test(".foo { color: hsl(100 100 50) }", ".foo{color:#5f0}");
20363    minify_test(".foo { color: hsl(100, 100%, 50%, .8) }", ".foo{color:#5f0c}");
20364    minify_test(".foo { color: hsl(100 100% 50% / .8) }", ".foo{color:#5f0c}");
20365    minify_test(".foo { color: hsla(100, 100%, 50%, .8) }", ".foo{color:#5f0c}");
20366    minify_test(".foo { color: hsla(100 100% 50% / .8) }", ".foo{color:#5f0c}");
20367    minify_test(".foo { color: transparent }", ".foo{color:#0000}");
20368    minify_test(".foo { color: currentColor }", ".foo{color:currentColor}");
20369    minify_test(".foo { color: ButtonBorder }", ".foo{color:buttonborder}");
20370    minify_test(".foo { color: hwb(194 0% 0%) }", ".foo{color:#00c4ff}");
20371    minify_test(".foo { color: hwb(194 0% 0% / 50%) }", ".foo{color:#00c4ff80}");
20372    minify_test(".foo { color: hwb(194 0% 50%) }", ".foo{color:#006280}");
20373    minify_test(".foo { color: hwb(194 50% 0%) }", ".foo{color:#80e1ff}");
20374    minify_test(".foo { color: hwb(194 50 0) }", ".foo{color:#80e1ff}");
20375    minify_test(".foo { color: hwb(194 50% 50%) }", ".foo{color:gray}");
20376    minify_test(".foo { color: light-dark(#FFF, #FFF) }", ".foo{color:#fff}");
20377    // minify_test(".foo { color: ActiveText }", ".foo{color:ActiveTet}");
20378    minify_test(
20379      ".foo { color: lab(29.2345% 39.3825 20.0664); }",
20380      ".foo{color:lab(29.2345% 39.3825 20.0664)}",
20381    );
20382    minify_test(
20383      ".foo { color: lab(29.2345 39.3825 20.0664); }",
20384      ".foo{color:lab(29.2345% 39.3825 20.0664)}",
20385    );
20386    minify_test(
20387      ".foo { color: lab(29.2345% 39.3825% 20.0664%); }",
20388      ".foo{color:lab(29.2345% 49.2281 25.083)}",
20389    );
20390    minify_test(
20391      ".foo { color: lab(29.2345% 39.3825 20.0664 / 100%); }",
20392      ".foo{color:lab(29.2345% 39.3825 20.0664)}",
20393    );
20394    minify_test(
20395      ".foo { color: lab(29.2345% 39.3825 20.0664 / 50%); }",
20396      ".foo{color:lab(29.2345% 39.3825 20.0664/.5)}",
20397    );
20398    minify_test(
20399      ".foo { color: lch(29.2345% 44.2 27); }",
20400      ".foo{color:lch(29.2345% 44.2 27)}",
20401    );
20402    minify_test(
20403      ".foo { color: lch(29.2345 44.2 27); }",
20404      ".foo{color:lch(29.2345% 44.2 27)}",
20405    );
20406    minify_test(
20407      ".foo { color: lch(29.2345% 44.2% 27deg); }",
20408      ".foo{color:lch(29.2345% 66.3 27)}",
20409    );
20410    minify_test(
20411      ".foo { color: lch(29.2345% 44.2 45deg); }",
20412      ".foo{color:lch(29.2345% 44.2 45)}",
20413    );
20414    minify_test(
20415      ".foo { color: lch(29.2345% 44.2 .5turn); }",
20416      ".foo{color:lch(29.2345% 44.2 180)}",
20417    );
20418    minify_test(
20419      ".foo { color: lch(29.2345% 44.2 27 / 100%); }",
20420      ".foo{color:lch(29.2345% 44.2 27)}",
20421    );
20422    minify_test(
20423      ".foo { color: lch(29.2345% 44.2 27 / 50%); }",
20424      ".foo{color:lch(29.2345% 44.2 27/.5)}",
20425    );
20426    minify_test(
20427      ".foo { color: oklab(40.101% 0.1147 0.0453); }",
20428      ".foo{color:oklab(40.101% .1147 .0453)}",
20429    );
20430    minify_test(
20431      ".foo { color: oklab(.40101 0.1147 0.0453); }",
20432      ".foo{color:oklab(40.101% .1147 .0453)}",
20433    );
20434    minify_test(
20435      ".foo { color: oklab(40.101% 0.1147% 0.0453%); }",
20436      ".foo{color:oklab(40.101% .0004588 .0001812)}",
20437    );
20438    minify_test(
20439      ".foo { color: oklch(40.101% 0.12332 21.555); }",
20440      ".foo{color:oklch(40.101% .12332 21.555)}",
20441    );
20442    minify_test(
20443      ".foo { color: oklch(.40101 0.12332 21.555); }",
20444      ".foo{color:oklch(40.101% .12332 21.555)}",
20445    );
20446    minify_test(
20447      ".foo { color: oklch(40.101% 0.12332% 21.555); }",
20448      ".foo{color:oklch(40.101% .00049328 21.555)}",
20449    );
20450    minify_test(
20451      ".foo { color: oklch(40.101% 0.12332 .5turn); }",
20452      ".foo{color:oklch(40.101% .12332 180)}",
20453    );
20454    minify_test(
20455      ".foo { color: color(display-p3 1 0.5 0); }",
20456      ".foo{color:color(display-p3 1 .5 0)}",
20457    );
20458    minify_test(
20459      ".foo { color: color(display-p3 100% 50% 0%); }",
20460      ".foo{color:color(display-p3 1 .5 0)}",
20461    );
20462    minify_test(
20463      ".foo { color: color(xyz-d50 0.2005 0.14089 0.4472); }",
20464      ".foo{color:color(xyz-d50 .2005 .14089 .4472)}",
20465    );
20466    minify_test(
20467      ".foo { color: color(xyz-d50 20.05% 14.089% 44.72%); }",
20468      ".foo{color:color(xyz-d50 .2005 .14089 .4472)}",
20469    );
20470    minify_test(
20471      ".foo { color: color(xyz-d65 0.2005 0.14089 0.4472); }",
20472      ".foo{color:color(xyz .2005 .14089 .4472)}",
20473    );
20474    minify_test(
20475      ".foo { color: color(xyz-d65 20.05% 14.089% 44.72%); }",
20476      ".foo{color:color(xyz .2005 .14089 .4472)}",
20477    );
20478    minify_test(
20479      ".foo { color: color(xyz 0.2005 0.14089 0.4472); }",
20480      ".foo{color:color(xyz .2005 .14089 .4472)}",
20481    );
20482    minify_test(
20483      ".foo { color: color(xyz 20.05% 14.089% 44.72%); }",
20484      ".foo{color:color(xyz .2005 .14089 .4472)}",
20485    );
20486    minify_test(
20487      ".foo { color: color(xyz 0.2005 0 0); }",
20488      ".foo{color:color(xyz .2005 0 0)}",
20489    );
20490    minify_test(".foo { color: color(xyz 0 0 0); }", ".foo{color:color(xyz 0 0 0)}");
20491    minify_test(".foo { color: color(xyz 0 1 0); }", ".foo{color:color(xyz 0 1 0)}");
20492    minify_test(
20493      ".foo { color: color(xyz 0 1 0 / 20%); }",
20494      ".foo{color:color(xyz 0 1 0/.2)}",
20495    );
20496    minify_test(
20497      ".foo { color: color(xyz 0 0 0 / 20%); }",
20498      ".foo{color:color(xyz 0 0 0/.2)}",
20499    );
20500    minify_test(
20501      ".foo { color: color(display-p3 100% 50% 0 / 20%); }",
20502      ".foo{color:color(display-p3 1 .5 0/.2)}",
20503    );
20504    minify_test(
20505      ".foo { color: color(display-p3 100% 0 0 / 20%); }",
20506      ".foo{color:color(display-p3 1 0 0/.2)}",
20507    );
20508    minify_test(".foo { color: hsl(none none none) }", ".foo{color:#000}");
20509    minify_test(".foo { color: hwb(none none none) }", ".foo{color:red}");
20510    minify_test(".foo { color: rgb(none none none) }", ".foo{color:#000}");
20511
20512    // If the browser doesn't support `#rrggbbaa` color syntax, it is converted to `transparent`.
20513    attr_test(
20514      "color: rgba(0, 0, 0, 0)",
20515      "color:transparent",
20516      true,
20517      Some(Browsers {
20518        chrome: Some(61 << 16), // Chrome >= 62 supports `#rrggbbaa` color.
20519        ..Browsers::default()
20520      }),
20521    );
20522
20523    attr_test(
20524      "color: #0000",
20525      "color:transparent",
20526      true,
20527      Some(Browsers {
20528        chrome: Some(61 << 16), // Chrome >= 62 supports `#rrggbbaa` color.
20529        ..Browsers::default()
20530      }),
20531    );
20532
20533    attr_test(
20534      "color: transparent",
20535      "color:transparent",
20536      true,
20537      Some(Browsers {
20538        chrome: Some(61 << 16),
20539        ..Browsers::default()
20540      }),
20541    );
20542
20543    attr_test(
20544      "color: rgba(0, 0, 0, 0)",
20545      "color: rgba(0, 0, 0, 0)",
20546      false,
20547      Some(Browsers {
20548        chrome: Some(61 << 16),
20549        ..Browsers::default()
20550      }),
20551    );
20552
20553    attr_test(
20554      "color: rgba(255, 0, 0, 0)",
20555      "color:rgba(255,0,0,0)",
20556      true,
20557      Some(Browsers {
20558        chrome: Some(61 << 16),
20559        ..Browsers::default()
20560      }),
20561    );
20562
20563    attr_test(
20564      "color: rgba(255, 0, 0, 0)",
20565      "color:#f000",
20566      true,
20567      Some(Browsers {
20568        chrome: Some(62 << 16),
20569        ..Browsers::default()
20570      }),
20571    );
20572
20573    prefix_test(
20574      ".foo { color: rgba(123, 456, 789, 0.5) }",
20575      indoc! { r#"
20576        .foo {
20577          color: #7bffff80;
20578        }
20579      "#},
20580      Browsers {
20581        chrome: Some(95 << 16),
20582        ..Browsers::default()
20583      },
20584    );
20585
20586    prefix_test(
20587      ".foo { color: rgba(123, 255, 255, 0.5) }",
20588      indoc! { r#"
20589        .foo {
20590          color: rgba(123, 255, 255, .5);
20591        }
20592      "#},
20593      Browsers {
20594        ie: Some(11 << 16),
20595        ..Browsers::default()
20596      },
20597    );
20598
20599    prefix_test(
20600      ".foo { color: #7bffff80 }",
20601      indoc! { r#"
20602        .foo {
20603          color: rgba(123, 255, 255, .5);
20604        }
20605      "#},
20606      Browsers {
20607        ie: Some(11 << 16),
20608        ..Browsers::default()
20609      },
20610    );
20611
20612    prefix_test(
20613      ".foo { color: rgba(123, 456, 789, 0.5) }",
20614      indoc! { r#"
20615        .foo {
20616          color: rgba(123, 255, 255, .5);
20617        }
20618      "#},
20619      Browsers {
20620        firefox: Some(48 << 16),
20621        safari: Some(10 << 16),
20622        ios_saf: Some(9 << 16),
20623        ..Browsers::default()
20624      },
20625    );
20626
20627    prefix_test(
20628      ".foo { color: rgba(123, 456, 789, 0.5) }",
20629      indoc! { r#"
20630        .foo {
20631          color: #7bffff80;
20632        }
20633      "#},
20634      Browsers {
20635        firefox: Some(49 << 16),
20636        safari: Some(10 << 16),
20637        ios_saf: Some(10 << 16),
20638        ..Browsers::default()
20639      },
20640    );
20641
20642    prefix_test(
20643      ".foo { background-color: lab(40% 56.6 39) }",
20644      indoc! { r#"
20645        .foo {
20646          background-color: #b32323;
20647          background-color: lab(40% 56.6 39);
20648        }
20649      "#},
20650      Browsers {
20651        chrome: Some(90 << 16),
20652        ..Browsers::default()
20653      },
20654    );
20655
20656    prefix_test(
20657      ".foo { background-color: lch(40% 68.735435 34.568626) }",
20658      indoc! { r#"
20659        .foo {
20660          background-color: #b32323;
20661          background-color: lch(40% 68.7354 34.5686);
20662        }
20663      "#},
20664      Browsers {
20665        chrome: Some(90 << 16),
20666        ..Browsers::default()
20667      },
20668    );
20669
20670    prefix_test(
20671      ".foo { background-color: oklab(59.686% 0.1009 0.1192); }",
20672      indoc! { r#"
20673        .foo {
20674          background-color: #c65d07;
20675          background-color: lab(52.2319% 40.1449 59.9171);
20676        }
20677      "#},
20678      Browsers {
20679        chrome: Some(90 << 16),
20680        ..Browsers::default()
20681      },
20682    );
20683
20684    prefix_test(
20685      ".foo { background-color: oklch(40% 0.1268735435 34.568626) }",
20686      indoc! { r#"
20687        .foo {
20688          background-color: #7e250f;
20689          background-color: lab(29.2661% 38.2437 35.3889);
20690        }
20691      "#},
20692      Browsers {
20693        chrome: Some(90 << 16),
20694        ..Browsers::default()
20695      },
20696    );
20697
20698    prefix_test(
20699      ".foo { background-color: lab(40% 56.6 39) }",
20700      indoc! { r#"
20701        .foo {
20702          background-color: lab(40% 56.6 39);
20703        }
20704      "#},
20705      Browsers {
20706        safari: Some(15 << 16),
20707        ..Browsers::default()
20708      },
20709    );
20710
20711    prefix_test(
20712      ".foo { background-color: oklab(59.686% 0.1009 0.1192); }",
20713      indoc! { r#"
20714        .foo {
20715          background-color: #c65d07;
20716          background-color: lab(52.2319% 40.1449 59.9171);
20717        }
20718      "#},
20719      Browsers {
20720        chrome: Some(90 << 16),
20721        safari: Some(15 << 16),
20722        ..Browsers::default()
20723      },
20724    );
20725
20726    prefix_test(
20727      ".foo { background-color: oklab(59.686% 0.1009 0.1192); }",
20728      indoc! { r#"
20729        .foo {
20730          background-color: #c65d07;
20731          background-color: color(display-p3 .724144 .386777 .148795);
20732          background-color: lab(52.2319% 40.1449 59.9171);
20733        }
20734      "#},
20735      Browsers {
20736        chrome: Some(90 << 16),
20737        safari: Some(14 << 16),
20738        ..Browsers::default()
20739      },
20740    );
20741
20742    prefix_test(
20743      ".foo { background-color: lab(40% 56.6 39) }",
20744      indoc! { r#"
20745        .foo {
20746          background-color: #b32323;
20747          background-color: color(display-p3 .643308 .192455 .167712);
20748          background-color: lab(40% 56.6 39);
20749        }
20750      "#},
20751      Browsers {
20752        chrome: Some(90 << 16),
20753        safari: Some(14 << 16),
20754        ..Browsers::default()
20755      },
20756    );
20757
20758    prefix_test(
20759      ".foo { background-color: oklch(59.686% 0.15619 49.7694); }",
20760      indoc! { r#"
20761        .foo {
20762          background-color: #c65d06;
20763          background-color: lab(52.2321% 40.1417 59.9527);
20764        }
20765      "#},
20766      Browsers {
20767        chrome: Some(90 << 16),
20768        safari: Some(15 << 16),
20769        ..Browsers::default()
20770      },
20771    );
20772
20773    prefix_test(
20774      ".foo { background-color: color(sRGB 0.41587 0.503670 0.36664); }",
20775      indoc! { r#"
20776        .foo {
20777          background-color: #6a805d;
20778          background-color: color(srgb .41587 .50367 .36664);
20779        }
20780      "#},
20781      Browsers {
20782        chrome: Some(90 << 16),
20783        ..Browsers::default()
20784      },
20785    );
20786
20787    prefix_test(
20788      ".foo { background-color: color(display-p3 0.43313 0.50108 0.37950); }",
20789      indoc! { r#"
20790        .foo {
20791          background-color: #6a805d;
20792          background-color: color(display-p3 .43313 .50108 .3795);
20793        }
20794      "#},
20795      Browsers {
20796        chrome: Some(90 << 16),
20797        ..Browsers::default()
20798      },
20799    );
20800
20801    prefix_test(
20802      ".foo { background-color: color(display-p3 0.43313 0.50108 0.37950); }",
20803      indoc! { r#"
20804        .foo {
20805          background-color: #6a805d;
20806          background-color: color(display-p3 .43313 .50108 .3795);
20807        }
20808      "#},
20809      Browsers {
20810        chrome: Some(90 << 16),
20811        safari: Some(14 << 16),
20812        ..Browsers::default()
20813      },
20814    );
20815
20816    prefix_test(
20817      ".foo { background-color: color(display-p3 0.43313 0.50108 0.37950); }",
20818      indoc! { r#"
20819        .foo {
20820          background-color: color(display-p3 .43313 .50108 .3795);
20821        }
20822      "#},
20823      Browsers {
20824        safari: Some(14 << 16),
20825        ..Browsers::default()
20826      },
20827    );
20828
20829    prefix_test(
20830      ".foo { background-color: color(display-p3 0.43313 0.50108 0.37950); }",
20831      indoc! { r#"
20832        .foo {
20833          background-color: #6a805d;
20834          background-color: color(display-p3 .43313 .50108 .3795);
20835        }
20836      "#},
20837      Browsers {
20838        chrome: Some(90 << 16),
20839        safari: Some(15 << 16),
20840        ..Browsers::default()
20841      },
20842    );
20843
20844    prefix_test(
20845      ".foo { background-color: color(display-p3 0.43313 0.50108 0.37950); }",
20846      indoc! { r#"
20847        .foo {
20848          background-color: #6a805d;
20849          background-color: color(display-p3 .43313 .50108 .3795);
20850        }
20851      "#},
20852      Browsers {
20853        chrome: Some(90 << 16),
20854        ..Browsers::default()
20855      },
20856    );
20857
20858    prefix_test(
20859      ".foo { background-color: color(a98-rgb 0.44091 0.49971 0.37408); }",
20860      indoc! { r#"
20861        .foo {
20862          background-color: #6a805d;
20863          background-color: color(a98-rgb .44091 .49971 .37408);
20864        }
20865      "#},
20866      Browsers {
20867        chrome: Some(90 << 16),
20868        ..Browsers::default()
20869      },
20870    );
20871
20872    prefix_test(
20873      ".foo { background-color: color(a98-rgb 0.44091 0.49971 0.37408); }",
20874      indoc! { r#"
20875        .foo {
20876          background-color: color(a98-rgb .44091 .49971 .37408);
20877        }
20878      "#},
20879      Browsers {
20880        safari: Some(15 << 16),
20881        ..Browsers::default()
20882      },
20883    );
20884
20885    prefix_test(
20886      ".foo { background-color: color(prophoto-rgb 0.36589 0.41717 0.31333); }",
20887      indoc! { r#"
20888        .foo {
20889          background-color: #6a805d;
20890          background-color: color(prophoto-rgb .36589 .41717 .31333);
20891        }
20892      "#},
20893      Browsers {
20894        chrome: Some(90 << 16),
20895        ..Browsers::default()
20896      },
20897    );
20898
20899    prefix_test(
20900      ".foo { background-color: color(rec2020 0.42210 0.47580 0.35605); }",
20901      indoc! { r#"
20902        .foo {
20903          background-color: #728765;
20904          background-color: color(rec2020 .4221 .4758 .35605);
20905        }
20906      "#},
20907      Browsers {
20908        chrome: Some(90 << 16),
20909        ..Browsers::default()
20910      },
20911    );
20912
20913    prefix_test(
20914      ".foo { background-color: color(xyz-d50 0.2005 0.14089 0.4472); }",
20915      indoc! { r#"
20916        .foo {
20917          background-color: #7654cd;
20918          background-color: color(xyz-d50 .2005 .14089 .4472);
20919        }
20920      "#},
20921      Browsers {
20922        chrome: Some(90 << 16),
20923        ..Browsers::default()
20924      },
20925    );
20926
20927    prefix_test(
20928      ".foo { background-color: color(xyz-d65 0.21661 0.14602 0.59452); }",
20929      indoc! { r#"
20930        .foo {
20931          background-color: #7654cd;
20932          background-color: color(xyz .21661 .14602 .59452);
20933        }
20934      "#},
20935      Browsers {
20936        chrome: Some(90 << 16),
20937        ..Browsers::default()
20938      },
20939    );
20940
20941    prefix_test(
20942      ".foo { background-color: lch(50.998% 135.363 338) }",
20943      indoc! { r#"
20944        .foo {
20945          background-color: #f000c0;
20946          background-color: color(display-p3 .972962 -.362078 .804206);
20947          background-color: lch(50.998% 135.363 338);
20948        }
20949      "#},
20950      Browsers {
20951        chrome: Some(90 << 16),
20952        safari: Some(14 << 16),
20953        ..Browsers::default()
20954      },
20955    );
20956
20957    prefix_test(
20958      ".foo { color: lch(50.998% 135.363 338) }",
20959      indoc! { r#"
20960        .foo {
20961          color: #f000c0;
20962          color: color(display-p3 .972962 -.362078 .804206);
20963          color: lch(50.998% 135.363 338);
20964        }
20965      "#},
20966      Browsers {
20967        chrome: Some(90 << 16),
20968        safari: Some(14 << 16),
20969        ..Browsers::default()
20970      },
20971    );
20972
20973    prefix_test(
20974      ".foo { color: lab(98.2504% -7.697 88.7581) }",
20975      indoc! { r#"
20976        .foo {
20977          color: #fffc44;
20978          color: lab(98.2504% -7.697 88.7581);
20979        }
20980      "#},
20981      Browsers {
20982        chrome: Some(80 << 16),
20983        ..Browsers::default()
20984      },
20985    );
20986
20987    prefix_test(
20988      ".foo { color: color(prophoto-rgb 0.9784 0.9925 0.3037) }",
20989      indoc! { r#"
20990        .foo {
20991          color: #ffff6d;
20992          color: color(prophoto-rgb .9784 .9925 .3037);
20993        }
20994      "#},
20995      Browsers {
20996        chrome: Some(80 << 16),
20997        ..Browsers::default()
20998      },
20999    );
21000
21001    prefix_test(
21002      ".foo { color: lch(94.4698% 111.9227 117.6737deg) }",
21003      indoc! { r#"
21004        .foo {
21005          color: #b0ff00;
21006          color: lch(94.4698% 111.923 117.674);
21007        }
21008      "#},
21009      Browsers {
21010        chrome: Some(80 << 16),
21011        ..Browsers::default()
21012      },
21013    );
21014
21015    prefix_test(
21016      ".foo { color: oklch(99.995% .01 0) }",
21017      indoc! { r#"
21018        .foo {
21019          color: #fffcff;
21020          color: lab(99.8686% 3.37896 .0330329);
21021        }
21022      "#},
21023      Browsers {
21024        chrome: Some(80 << 16),
21025        ..Browsers::default()
21026      },
21027    );
21028
21029    prefix_test(
21030      ".foo { background: var(--image) lch(40% 68.735435 34.568626) }",
21031      indoc! { r#"
21032        .foo {
21033          background: var(--image) #b32323;
21034        }
21035
21036        @supports (color: lab(0% 0 0)) {
21037          .foo {
21038            background: var(--image) lab(40% 56.6 39);
21039          }
21040        }
21041      "#},
21042      Browsers {
21043        chrome: Some(90 << 16),
21044        ..Browsers::default()
21045      },
21046    );
21047
21048    prefix_test(
21049      r#"
21050        @supports (color: lab(0% 0 0)) {
21051          .foo {
21052            background: var(--image) lab(40% 56.6 39);
21053          }
21054        }
21055      "#,
21056      indoc! { r#"
21057        @supports (color: lab(0% 0 0)) {
21058          .foo {
21059            background: var(--image) lab(40% 56.6 39);
21060          }
21061        }
21062      "#},
21063      Browsers {
21064        chrome: Some(90 << 16),
21065        ..Browsers::default()
21066      },
21067    );
21068
21069    prefix_test(
21070      r#"
21071      .foo {
21072        color: red;
21073        color: lab(40% 56.6 39);
21074      }
21075    "#,
21076      indoc! {r#"
21077      .foo {
21078        color: red;
21079        color: lab(40% 56.6 39);
21080      }
21081    "#
21082      },
21083      Browsers {
21084        safari: Some(14 << 16),
21085        ..Browsers::default()
21086      },
21087    );
21088    prefix_test(
21089      r#"
21090      .foo {
21091        color: red;
21092        color: lab(40% 56.6 39);
21093      }
21094    "#,
21095      indoc! {r#"
21096      .foo {
21097        color: lab(40% 56.6 39);
21098      }
21099    "#
21100      },
21101      Browsers {
21102        safari: Some(16 << 16),
21103        ..Browsers::default()
21104      },
21105    );
21106
21107    prefix_test(
21108      r#"
21109      .foo {
21110        color: var(--fallback);
21111        color: lab(40% 56.6 39);
21112      }
21113    "#,
21114      indoc! {r#"
21115      .foo {
21116        color: var(--fallback);
21117        color: lab(40% 56.6 39);
21118      }
21119    "#
21120      },
21121      Browsers {
21122        safari: Some(14 << 16),
21123        ..Browsers::default()
21124      },
21125    );
21126
21127    prefix_test(
21128      r#"
21129      .foo {
21130        color: var(--fallback);
21131        color: lab(40% 56.6 39);
21132      }
21133    "#,
21134      indoc! {r#"
21135      .foo {
21136        color: lab(40% 56.6 39);
21137      }
21138    "#
21139      },
21140      Browsers {
21141        safari: Some(16 << 16),
21142        ..Browsers::default()
21143      },
21144    );
21145
21146    prefix_test(
21147      r#"
21148      .foo {
21149        color: red;
21150        color: var(--foo, lab(40% 56.6 39));
21151      }
21152    "#,
21153      indoc! {r#"
21154      .foo {
21155        color: var(--foo, color(display-p3 .643308 .192455 .167712));
21156      }
21157
21158      @supports (color: lab(0% 0 0)) {
21159        .foo {
21160          color: var(--foo, lab(40% 56.6 39));
21161        }
21162      }
21163    "#
21164      },
21165      Browsers {
21166        safari: Some(14 << 16),
21167        ..Browsers::default()
21168      },
21169    );
21170
21171    prefix_test(
21172      r#"
21173      @supports (color: lab(0% 0 0)) {
21174        .foo {
21175          color: var(--foo, lab(40% 56.6 39));
21176        }
21177      }
21178    "#,
21179      indoc! {r#"
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      .foo {
21196        --a: rgb(0 0 0 / var(--alpha));
21197        --b: rgb(50% 50% 50% / var(--alpha));
21198        --c: rgb(var(--x) 0 0);
21199        --d: rgb(0 var(--x) 0);
21200        --e: rgb(0 0 var(--x));
21201        --f: rgb(var(--x) 0 0 / var(--alpha));
21202        --g: rgb(0 var(--x) 0 / var(--alpha));
21203        --h: rgb(0 0 var(--x) / var(--alpha));
21204        --i: rgb(none 0 0 / var(--alpha));
21205        --j: rgb(from yellow r g b / var(--alpha));
21206      }
21207      "#,
21208      indoc! { r#"
21209        .foo {
21210          --a: rgba(0, 0, 0, var(--alpha));
21211          --b: rgba(128, 128, 128, var(--alpha));
21212          --c: rgb(var(--x) 0 0);
21213          --d: rgb(0 var(--x) 0);
21214          --e: rgb(0 0 var(--x));
21215          --f: rgb(var(--x) 0 0 / var(--alpha));
21216          --g: rgb(0 var(--x) 0 / var(--alpha));
21217          --h: rgb(0 0 var(--x) / var(--alpha));
21218          --i: rgb(none 0 0 / var(--alpha));
21219          --j: rgba(255, 255, 0, var(--alpha));
21220        }
21221      "#},
21222      Browsers {
21223        safari: Some(11 << 16),
21224        ..Browsers::default()
21225      },
21226    );
21227
21228    prefix_test(
21229      r#"
21230      .foo {
21231        --a: rgb(0 0 0 / var(--alpha));
21232        --b: rgb(50% 50% 50% / var(--alpha));
21233        --c: rgb(var(--x) 0 0);
21234        --d: rgb(0 var(--x) 0);
21235        --e: rgb(0 0 var(--x));
21236        --f: rgb(var(--x) 0 0 / var(--alpha));
21237        --g: rgb(0 var(--x) 0 / var(--alpha));
21238        --h: rgb(0 0 var(--x) / var(--alpha));
21239        --i: rgb(none 0 0 / var(--alpha));
21240        --j: rgb(from yellow r g b / var(--alpha));
21241      }
21242      "#,
21243      indoc! { r#"
21244        .foo {
21245          --a: rgb(0 0 0 / var(--alpha));
21246          --b: rgb(128 128 128 / var(--alpha));
21247          --c: rgb(var(--x) 0 0);
21248          --d: rgb(0 var(--x) 0);
21249          --e: rgb(0 0 var(--x));
21250          --f: rgb(var(--x) 0 0 / var(--alpha));
21251          --g: rgb(0 var(--x) 0 / var(--alpha));
21252          --h: rgb(0 0 var(--x) / var(--alpha));
21253          --i: rgb(none 0 0 / var(--alpha));
21254          --j: rgb(255 255 0 / var(--alpha));
21255        }
21256      "#},
21257      Browsers {
21258        safari: Some(13 << 16),
21259        ..Browsers::default()
21260      },
21261    );
21262
21263    prefix_test(
21264      r#"
21265      .foo {
21266        --a: hsl(270 100% 50% / var(--alpha));
21267        --b: hsl(var(--x) 0 0);
21268        --c: hsl(0 var(--x) 0);
21269        --d: hsl(0 0 var(--x));
21270        --e: hsl(var(--x) 0 0 / var(--alpha));
21271        --f: hsl(0 var(--x) 0 / var(--alpha));
21272        --g: hsl(0 0 var(--x) / var(--alpha));
21273        --h: hsl(270 100% 50% / calc(var(--alpha) / 2));
21274        --i: hsl(none 100% 50% / var(--alpha));
21275        --j: hsl(from yellow h s l / var(--alpha));
21276      }
21277      "#,
21278      indoc! { r#"
21279        .foo {
21280          --a: hsla(270, 100%, 50%, var(--alpha));
21281          --b: hsl(var(--x) 0 0);
21282          --c: hsl(0 var(--x) 0);
21283          --d: hsl(0 0 var(--x));
21284          --e: hsl(var(--x) 0 0 / var(--alpha));
21285          --f: hsl(0 var(--x) 0 / var(--alpha));
21286          --g: hsl(0 0 var(--x) / var(--alpha));
21287          --h: hsla(270, 100%, 50%, calc(var(--alpha) / 2));
21288          --i: hsl(none 100% 50% / var(--alpha));
21289          --j: hsla(60, 100%, 50%, var(--alpha));
21290        }
21291      "#},
21292      Browsers {
21293        safari: Some(11 << 16),
21294        ..Browsers::default()
21295      },
21296    );
21297
21298    prefix_test(
21299      r#"
21300      .foo {
21301        --a: hsl(270 100% 50% / var(--alpha));
21302        --b: hsl(var(--x) 0 0);
21303        --c: hsl(0 var(--x) 0);
21304        --d: hsl(0 0 var(--x));
21305        --e: hsl(var(--x) 0 0 / var(--alpha));
21306        --f: hsl(0 var(--x) 0 / var(--alpha));
21307        --g: hsl(0 0 var(--x) / var(--alpha));
21308        --h: hsl(270 100% 50% / calc(var(--alpha) / 2));
21309        --i: hsl(none 100% 50% / var(--alpha));
21310      }
21311      "#,
21312      indoc! { r#"
21313        .foo {
21314          --a: hsl(270 100% 50% / var(--alpha));
21315          --b: hsl(var(--x) 0 0);
21316          --c: hsl(0 var(--x) 0);
21317          --d: hsl(0 0 var(--x));
21318          --e: hsl(var(--x) 0 0 / var(--alpha));
21319          --f: hsl(0 var(--x) 0 / var(--alpha));
21320          --g: hsl(0 0 var(--x) / var(--alpha));
21321          --h: hsl(270 100% 50% / calc(var(--alpha) / 2));
21322          --i: hsl(none 100% 50% / var(--alpha));
21323        }
21324      "#},
21325      Browsers {
21326        safari: Some(13 << 16),
21327        ..Browsers::default()
21328      },
21329    );
21330
21331    test(
21332      r#"
21333      .foo {
21334        --a: rgb(50% 50% 50% / calc(100% / 2));
21335        --b: hsl(calc(360deg / 2) 50% 50%);
21336        --c: oklab(40.101% calc(0.1 + 0.2) 0.0453);
21337        --d: color(display-p3 0.43313 0.50108 calc(0.1 + 0.2));
21338        --e: rgb(calc(255 / 2), calc(255 / 2), calc(255 / 2));
21339      }
21340      "#,
21341      indoc! { r#"
21342        .foo {
21343          --a: #80808080;
21344          --b: #40bfbf;
21345          --c: oklab(40.101% .3 .0453);
21346          --d: color(display-p3 .43313 .50108 .3);
21347          --e: gray;
21348        }
21349      "#},
21350    );
21351  }
21352
21353  #[test]
21354  fn test_relative_color() {
21355    #[track_caller]
21356    fn test(input: &str, output: &str) {
21357      let parsed = match CssColor::parse_string(output) {
21358        Ok(c) => c,
21359        Err(e) => panic!(
21360          "test_relative_color: parse expected output failed\nerror: {e:?}\ninput: {input}\noutput: {output}",
21361        ),
21362      };
21363      let output_css = match parsed.to_css_string(PrinterOptions {
21364        minify: true,
21365        ..PrinterOptions::default()
21366      }) {
21367        Ok(s) => s,
21368        Err(e) => panic!(
21369          "test_relative_color: stringify expected output failed\nerror: {e}\nerror(debug): {e:?}\ninput: {input}\noutput: {output}",
21370        ),
21371      };
21372      minify_test(
21373        &format!(".foo {{ color: {} }}", input),
21374        &format!(".foo{{color:{}}}", output_css),
21375      );
21376    }
21377
21378    test("lab(from indianred calc(l * .8) a b)", "lab(43.1402% 45.7516 23.1557)");
21379    test("lch(from indianred calc(l + 10) c h)", "lch(63.9252% 51.2776 26.8448)");
21380    test("lch(from indianred l calc(c - 50) h)", "lch(53.9252% 1.27763 26.8448)");
21381    test(
21382      "lch(from indianred l c calc(h + 180deg))",
21383      "lch(53.9252% 51.2776 206.845)",
21384    );
21385    test("lch(from orchid l 30 h)", "lch(62.7526% 30 326.969)");
21386    test("lch(from orchid l 30 h)", "lch(62.7526% 30 326.969)");
21387    test("lch(from peru calc(l * 0.8) c h)", "lch(49.8022% 54.0117 63.6804)");
21388    test("rgb(from indianred 255 g b)", "rgb(255, 92, 92)");
21389    test("rgb(from indianred r g b / .5)", "rgba(205, 92, 92, .5)");
21390    test(
21391      "rgb(from rgba(205, 92, 92, .5) r g b / calc(alpha + .2))",
21392      "rgba(205, 92, 92, .7)",
21393    );
21394    test(
21395      "rgb(from rgba(205, 92, 92, .5) r g b / calc(alpha + .2))",
21396      "rgba(205, 92, 92, .7)",
21397    );
21398    test("lch(from indianred l sin(c) h)", "lch(53.9252% .84797 26.8448)");
21399    test("lch(from indianred l sqrt(c) h)", "lch(53.9252% 7.16084 26.8448)");
21400    test("lch(from indianred l c sin(h))", "lch(53.9252% 51.2776 .451575)");
21401    test("lch(from indianred calc(10% + 20%) c h)", "lch(30% 51.2776 26.8448)");
21402    test("lch(from indianred calc(10 + 20) c h)", "lch(30% 51.2776 26.8448)");
21403    test("lch(from indianred l c calc(10 + 20))", "lch(53.9252% 51.2776 30)");
21404    test(
21405      "lch(from indianred l c calc(10deg + 20deg))",
21406      "lch(53.9252% 51.2776 30)",
21407    );
21408    test(
21409      "lch(from indianred l c calc(10deg + 0.35rad))",
21410      "lch(53.9252% 51.2776 30.0535)",
21411    );
21412    minify_test(
21413      ".foo{color:lch(from currentColor l c sin(h))}",
21414      ".foo{color:lch(from currentColor l c sin(h))}",
21415    );
21416
21417    // The following tests were converted from WPT:
21418    // https://github.com/web-platform-tests/wpt/blob/master/css/css-color/parsing/alpha-color-parsing-valid.html
21419
21420    // Basic usage with literal alpha.
21421    test("alpha(from red / 0.5)", "rgba(255, 0, 0, 0.5)");
21422    test("alpha(from blue / 1)", "rgb(0, 0, 255)");
21423    test("alpha(from green / 0)", "rgba(0, 128, 0, 0)");
21424
21425    // Percentage alpha.
21426    test("alpha(from red / 50%)", "rgba(255, 0, 0, 0.5)");
21427    test("alpha(from red / 0%)", "rgba(255, 0, 0, 0)");
21428    test("alpha(from red / 100%)", "rgb(255, 0, 0)");
21429
21430    // None alpha.
21431    test("alpha(from red / none)", "rgba(255, 0, 0, 0)");
21432
21433    // Omitted alpha (defaults to origin's alpha).
21434    test("alpha(from red)", "rgb(255, 0, 0)");
21435    // test() does not support keywords such as currentcolor; change it to minify_test()
21436    minify_test(
21437      ".foo{color:alpha(from currentcolor)}",
21438      ".foo{color:alpha(from currentcolor)}",
21439    );
21440
21441    // Alpha keyword referencing origin's alpha.
21442    minify_test(
21443      ".foo{color:alpha(from currentcolor / alpha)}",
21444      ".foo{color:alpha(from currentcolor / alpha)}",
21445    );
21446    test("alpha(from rgba(255, 0, 0, 0.8) / alpha)", "rgba(255, 0, 0, 0.8)");
21447
21448    // Calc with alpha keyword.
21449    test(
21450      "alpha(from rgba(255, 0, 0, 0.8) / calc(alpha * 0.5))",
21451      "rgba(255, 0, 0, 0.4)",
21452    );
21453    test(
21454      "alpha(from rgba(255, 0, 0, 0.8) / calc(alpha + 0.1))",
21455      "rgba(255, 0, 0, 0.9)",
21456    );
21457
21458    // Supplementary testing
21459    // TODO: calc does not support division by zero yet, so `alpha / 0` fails while `alpha / 1` works.
21460    // Depends on: https://github.com/parcel-bundler/lightningcss/pull/1122
21461    // test(
21462    //   "alpha(from green / calc(alpha / 0))",
21463    //   "rgb(0, 128, 0)",
21464    // );
21465    test("alpha(from green / calc(alpha / 1))", "rgb(0, 128, 0)");
21466
21467    // Test sibling-index() and sibling-count()
21468    minify_test(
21469      ".foo{color:alpha(from green / sibling-index())}",
21470      ".foo{color:alpha(from green / sibling-index())}",
21471    );
21472    minify_test(
21473      ".foo{color:alpha(from green / calc(sibling-index() * 0.2))}",
21474      ".foo{color:alpha(from green / calc(sibling-index() * .2))}",
21475    );
21476    minify_test(
21477      ".foo{color:alpha(from green / sibling-count())}",
21478      ".foo{color:alpha(from green / sibling-count())}",
21479    );
21480
21481    // Nested in other color functions.
21482    minify_test(
21483      ".foo{color:color-mix(in srgb, alpha(from red / 0.5), blue)}",
21484      ".foo{color:#5500aabf}",
21485    );
21486    test("rgb(from alpha(from red / 0.5) r g b / alpha)", "rgba(255, 0, 0, 0.5)");
21487
21488    // Other color functions as origin.
21489    test("alpha(from color-mix(in srgb, red, blue) / 0.5)", "#80008080");
21490    test("alpha(from rgb(from red r g b) / 0.8)", "rgba(255, 0, 0, 0.8)");
21491
21492    // Non-sRGB color spaces preserved.
21493    test(
21494      "alpha(from color(display-p3 1 0 0) / 0.5)",
21495      "color(display-p3 1 0 0 / 0.5)",
21496    );
21497    test("alpha(from lab(50 20 -30) / 0.5)", "lab(50% 20 -30 / 0.5)");
21498    test("alpha(from oklch(0.5 0.2 120) / 0.5)", "oklch(50% 0.2 120 / 0.5)");
21499
21500    // System and named colors.
21501    // https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/system-color#syntax
21502    minify_test(
21503      ".foo{color:alpha(from ActiveText / 0.5)}",
21504      ".foo{color:alpha(from ActiveText / .5)}",
21505    );
21506
21507    // Out-of-range alpha values.
21508    test("alpha(from red / 2)", "rgb(255, 0, 0)");
21509    test("alpha(from red / -1)", "rgba(255, 0, 0, 0)");
21510
21511    // Supplementary testing
21512    // nested alpha() precision.
21513    test("alpha(from alpha(from red / 0.5) / calc(alpha + 0.25))", "#ff0000bf");
21514    test("alpha(from alpha(from red / -0.5) / calc(alpha + 0.6))", "#f009");
21515    test("alpha(from alpha(from green / 0%) / 100%)", "green");
21516
21517    // Unresolved relative colors keep their tokens.
21518    minify_test(
21519      ".foo{color:rgb(from alpha(from currentColor / 0.5) r g b)}",
21520      ".foo{color:rgb(from alpha(from currentColor / .5) r g b)}",
21521    );
21522    minify_test(
21523      ".foo{color:alpha(from red / var(--alpha))}",
21524      ".foo{color:alpha(from red / var(--alpha))}",
21525    );
21526
21527    // RGBA origin alpha preserve/replace.
21528    test("alpha(from rgba(255, 0, 0, 0.3))", "rgba(255, 0, 0, 0.3)");
21529    test("alpha(from rgba(255, 0, 0, 0.3) / 0.8)", "rgba(255, 0, 0, 0.8)");
21530
21531    // color(srgb) preserves its color space.
21532    test("alpha(from color(srgb 1 0 0) / 50%)", "color(srgb 1 0 0 / 0.5)");
21533
21534    // alpha() nested in more relative color functions.
21535    test("hsl(from alpha(from red / 0.5) h s l / alpha)", "rgba(255, 0, 0, 0.5)");
21536    test("hwb(from alpha(from red / 0.5) h w b / alpha)", "rgba(255, 0, 0, 0.5)");
21537    test(
21538      "lab(from alpha(from lab(50% 20 -30) / 0.5) l a b / alpha)",
21539      "lab(50% 20 -30 / 0.5)",
21540    );
21541    test(
21542      "lch(from alpha(from lch(50% 20 30) / 0.5) l c h / alpha)",
21543      "lch(50% 20 30 / 0.5)",
21544    );
21545    test(
21546      "oklab(from alpha(from oklab(50% 0.2 -0.3) / 0.5) l a b / alpha)",
21547      "oklab(50% 0.2 -0.3 / 0.5)",
21548    );
21549    test(
21550      "oklch(from alpha(from oklch(50% 0.2 120) / 0.5) l c h / alpha)",
21551      "oklch(50% 0.2 120 / 0.5)",
21552    );
21553    test(
21554      "color(from alpha(from color(display-p3 1 0 0) / 0.5) display-p3 r g b / alpha)",
21555      "color(display-p3 1 0 0 / 0.5)",
21556    );
21557    test(
21558      "color(from alpha(from red / 1.5) srgb r g b / calc(alpha - 0.2))",
21559      "color(srgb 1 0 0 / 0.8)", // alpha = 1 - 0.2
21560    );
21561
21562    // Test in image()
21563    minify_test(".foo { mask: image(alpha(from red / 1))}", ".foo{mask:image(red)}");
21564
21565    // Test in linear-gradient()
21566    minify_test(
21567      ".foo { mask: linear-gradient(90deg, alpha(from red / 0%), red) }",
21568      ".foo{mask:linear-gradient(90deg,#f000,red)}",
21569    );
21570    // Compare relative color
21571    // TODO: Support <color-interpolation-method>
21572    minify_test(
21573      ".foo { mask: linear-gradient(90deg in hsl longer hue, rgb(from red r g b / 0), red) }",
21574      ".foo{mask:linear-gradient(90deg in hsl longer hue, #f000, red)}",
21575    );
21576    minify_test(
21577      ".foo { mask: linear-gradient(90deg in hsl longer hue, alpha(from red / 0%), red) }",
21578      ".foo{mask:linear-gradient(90deg in hsl longer hue, #f000, red)}",
21579    );
21580
21581    minify_test(
21582      ".foo { color: alpha(from color(display-p3 1 0 0) / 0.5) }",
21583      ".foo{color:color(display-p3 1 0 0/.5)}",
21584    );
21585
21586    // The following tests were converted from WPT: https://github.com/web-platform-tests/wpt/blob/master/css/css-color/parsing/relative-color-valid.html
21587    // Find: test_valid_value\(`color`, `(.*?)`,\s*`(.*?)`\)
21588    // Replace: test("$1", "$2")
21589
21590    // Testing no modifications.
21591    test("rgb(from rebeccapurple r g b)", "#639");
21592    test("rgb(from rebeccapurple r g b / alpha)", "#639");
21593    test("rgb(from rgb(20%, 40%, 60%, 80%) r g b / alpha)", "#369c");
21594    test("rgb(from rgb(20%, 40%, 60%, 80%) r g b)", "#369c");
21595    test("rgb(from hsl(120deg 20% 50% / .5) r g b / alpha)", "#66996680");
21596    test("rgb(from rgb(255 0 0 / 50%) r g b)", "rgba(255, 0, 0, 0.5)");
21597    test("rgb(from rgb(255, 0, 0, 0) r g b)", "#f000");
21598    test("rgb(from color(srgb 1 0 0 / 50%) r g b)", "rgba(255, 0, 0, 0.5)");
21599    test(
21600      "rgb(from color(srgb 1 0 0 / 50%) r g b / alpha)",
21601      "rgba(255, 0, 0, 0.5)",
21602    );
21603    test(
21604      "color(from color(srgb 1 0 0 / 50%) srgb r g b)",
21605      "color(srgb 1 0 0 / 0.5)",
21606    );
21607    test(
21608      "color(from color(srgb 1 0 0 / 50%) srgb r g b / alpha)",
21609      "color(srgb 1 0 0 / 0.5)",
21610    );
21611
21612    // Test with alpha()
21613    test(
21614      "color(from alpha(from red / 0.5) srgb r g b)",
21615      "color(srgb 1 0 0 / 0.5)",
21616    );
21617    test(
21618      "color(from alpha(from red / 0.5) srgb r g b / alpha)",
21619      "color(srgb 1 0 0 / 0.5)",
21620    );
21621    test(
21622      "color(from alpha(from red / 0.5) srgb r g b / 0.8)",
21623      "color(srgb 1 0 0 / 0.8)",
21624    );
21625    test(
21626      "color(from alpha(from rgba(255, 0, 0, 1) / 0.5) srgb r g b)",
21627      "color(srgb 1 0 0 / 0.5)",
21628    );
21629    // TODO: Floating-point precision issue; the current result is: .501961
21630    // test("color(from alpha(from rgb(255 0 0 / 50%) / alpha) srgb r g b)", "color(srgb 1 0 0 / 0.5)");
21631
21632    // Explicit alpha overrides the inherited value.
21633    test("rgb(from rgb(255 0 0 / 0.8) r g b / 1)", "red");
21634    test("rgb(from rgb(255 0 0 / 0) r g b / 1)", "red");
21635    test("rgb(from rgb(255 0 0 / 50%) r g b / none)", "rgba(255, 0, 0, 0)");
21636    test("rgb(from color(srgb 1 0 0) r g b / 80%)", "rgba(255, 0, 0, 0.8)");
21637    test(
21638      "rgb(from color(srgb 1 0 0 / 0.5) r g b / calc(alpha - 0.3))",
21639      "rgba(255, 0, 0, 0.2)",
21640    );
21641    test(
21642      "color(from color(display-p3 0.7 0.5 0.3 / 0.4) display-p3 r g b / .6)",
21643      "color(display-p3 0.7 0.5 0.3 / 0.6)",
21644    );
21645    test(
21646      "color(from color(srgb 1 0 0) srgb r g b / 0.5)",
21647      "color(srgb 1 0 0 / 0.5)",
21648    );
21649    test(
21650      "color(from color(srgb 1 0 0 / 100%) srgb r g b / 50%)",
21651      "color(srgb 1 0 0 / 0.5)",
21652    );
21653
21654    // Test nesting relative colors.
21655    test("rgb(from rgb(from rebeccapurple r g b) r g b)", "#639");
21656    test("rgb(from rgb(from rgb(255 0 0 / 0.8) g b r) r g b)", "#00fc");
21657
21658    // Testing non-sRGB origin colors to see gamut mapping.
21659    test("rgb(from color(display-p3 0 1 0) r g b / alpha)", "#00fb29"); // Naive clip based mapping would give rgb(0, 255, 0).
21660    test("rgb(from lab(100% 104.3 -50.9) r g b)", "#fff"); // Naive clip based mapping would give rgb(255, 150, 255).
21661    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.
21662    test("rgb(from lch(100% 116 334) r g b)", "#fff"); // Naive clip based mapping would give rgb(255, 150, 255).
21663    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.
21664    test("rgb(from oklab(100% 0.365 -0.16) r g b)", "#fff"); // Naive clip based mapping would give rgb(255, 92, 255).
21665    test("rgb(from oklab(0% 0.365 -0.16) r g b)", "#000"); // Naive clip based mapping would give rgb(19, 0, 24).
21666    test("rgb(from oklch(100% 0.399 336.3) r g b)", "#fff"); // Naive clip based mapping would give rgb(255, 91, 255).
21667    test("rgb(from oklch(0% 0.399 336.3) r g b)", "#000"); // Naive clip based mapping would give rgb(20, 0, 24).
21668
21669    // Testing replacement with 0.
21670    test("rgb(from rebeccapurple 0 0 0)", "rgb(0, 0, 0)");
21671    test("rgb(from rebeccapurple 0 0 0 / 0)", "rgba(0, 0, 0, 0)");
21672    test("rgb(from rebeccapurple 0 g b / alpha)", "rgb(0, 51, 153)");
21673    test("rgb(from rebeccapurple r 0 b / alpha)", "rgb(102, 0, 153)");
21674    test("rgb(from rebeccapurple r g 0 / alpha)", "rgb(102, 51, 0)");
21675    test("rgb(from rebeccapurple r g b / 0)", "rgba(102, 51, 153, 0)");
21676    test(
21677      "rgb(from rgb(20%, 40%, 60%, 80%) 0 g b / alpha)",
21678      "rgba(0, 102, 153, 0.8)",
21679    );
21680    test(
21681      "rgb(from rgb(20%, 40%, 60%, 80%) r 0 b / alpha)",
21682      "rgba(51, 0, 153, 0.8)",
21683    );
21684    test(
21685      "rgb(from rgb(20%, 40%, 60%, 80%) r g 0 / alpha)",
21686      "rgba(51, 102, 0, 0.8)",
21687    );
21688    test("rgb(from rgb(20%, 40%, 60%, 80%) r g b / 0)", "rgba(51, 102, 153, 0)");
21689
21690    // Testing replacement with a number.
21691    test("rgb(from rebeccapurple 25 g b / alpha)", "rgb(25, 51, 153)");
21692    test("rgb(from rebeccapurple r 25 b / alpha)", "rgb(102, 25, 153)");
21693    test("rgb(from rebeccapurple r g 25 / alpha)", "rgb(102, 51, 25)");
21694    test("rgb(from rebeccapurple r g b / .25)", "rgba(102, 51, 153, 0.25)");
21695    test(
21696      "rgb(from rgb(20%, 40%, 60%, 80%) 25 g b / alpha)",
21697      "rgba(25, 102, 153, 0.8)",
21698    );
21699    test(
21700      "rgb(from rgb(20%, 40%, 60%, 80%) r 25 b / alpha)",
21701      "rgba(51, 25, 153, 0.8)",
21702    );
21703    test(
21704      "rgb(from rgb(20%, 40%, 60%, 80%) r g 25 / alpha)",
21705      "rgba(51, 102, 25, 0.8)",
21706    );
21707    test(
21708      "rgb(from rgb(20%, 40%, 60%, 80%) r g b / .20)",
21709      "rgba(51, 102, 153, 0.2)",
21710    );
21711
21712    // Testing replacement with a percentage.
21713    test("rgb(from rebeccapurple 20% g b / alpha)", "rgb(51, 51, 153)");
21714    test("rgb(from rebeccapurple r 20% b / alpha)", "rgb(102, 51, 153)");
21715    test("rgb(from rebeccapurple r g 20% / alpha)", "rgb(102, 51, 51)");
21716    test("rgb(from rebeccapurple r g b / 20%)", "rgba(102, 51, 153, 0.2)");
21717    test(
21718      "rgb(from rgb(20%, 40%, 60%, 80%) 20% g b / alpha)",
21719      "rgba(51, 102, 153, 0.8)",
21720    );
21721    test(
21722      "rgb(from rgb(20%, 40%, 60%, 80%) r 20% b / alpha)",
21723      "rgba(51, 51, 153, 0.8)",
21724    );
21725    test(
21726      "rgb(from rgb(20%, 40%, 60%, 80%) r g 20% / alpha)",
21727      "rgba(51, 102, 51, 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 number for r, g, b but percent for alpha.
21735    test("rgb(from rebeccapurple 25 g b / 25%)", "rgba(25, 51, 153, 0.25)");
21736    test("rgb(from rebeccapurple r 25 b / 25%)", "rgba(102, 25, 153, 0.25)");
21737    test("rgb(from rebeccapurple r g 25 / 25%)", "rgba(102, 51, 25, 0.25)");
21738    test(
21739      "rgb(from rgb(20%, 40%, 60%, 80%) 25 g b / 25%)",
21740      "rgba(25, 102, 153, 0.25)",
21741    );
21742    test(
21743      "rgb(from rgb(20%, 40%, 60%, 80%) r 25 b / 25%)",
21744      "rgba(51, 25, 153, 0.25)",
21745    );
21746    test(
21747      "rgb(from rgb(20%, 40%, 60%, 80%) r g 25 / 25%)",
21748      "rgba(51, 102, 25, 0.25)",
21749    );
21750
21751    // Testing permutation.
21752    test("rgb(from rebeccapurple g b r)", "rgb(51, 153, 102)");
21753    test("rgb(from rebeccapurple b alpha r / g)", "rgba(153, 1, 102, 1)");
21754    test("rgb(from rebeccapurple r r r / r)", "rgba(102, 102, 102, 1)");
21755    test("rgb(from rebeccapurple alpha alpha alpha / alpha)", "rgb(1, 1, 1)");
21756    test("rgb(from rgb(20%, 40%, 60%, 80%) g b r)", "rgba(102, 153, 51, 0.8)");
21757    test("rgb(from rgb(20%, 40%, 60%, 80%) b alpha r / g)", "rgba(153, 1, 51, 1)");
21758    test("rgb(from rgb(20%, 40%, 60%, 80%) r r r / r)", "rgba(51, 51, 51, 1)");
21759    test(
21760      "rgb(from rgb(20%, 40%, 60%, 80%) alpha alpha alpha / alpha)",
21761      "rgba(1, 1, 1, 0.8)",
21762    );
21763
21764    // Testing mixes of number and percentage. (These would not be allowed in the non-relative syntax).
21765    test("rgb(from rebeccapurple r 20% 10)", "rgb(102, 51, 10)");
21766    test("rgb(from rebeccapurple r 10 20%)", "rgb(102, 10, 51)");
21767    test("rgb(from rebeccapurple 0% 10 10)", "rgb(0, 10, 10)");
21768    test("rgb(from rgb(20%, 40%, 60%, 80%) r 20% 10)", "rgba(51, 51, 10, 0.8)");
21769    test("rgb(from rgb(20%, 40%, 60%, 80%) r 10 20%)", "rgba(51, 10, 51, 0.8)");
21770    test("rgb(from rgb(20%, 40%, 60%, 80%) 0% 10 10)", "rgba(0, 10, 10, 0.8)");
21771
21772    // Testing with calc().
21773    test("rgb(from rebeccapurple calc(r) calc(g) calc(b))", "rgb(102, 51, 153)");
21774    test("rgb(from rebeccapurple r calc(g * 2) 10)", "rgb(102, 102, 10)");
21775    test("rgb(from rebeccapurple b calc(r * .5) 10)", "rgb(153, 51, 10)");
21776    test("rgb(from rebeccapurple r calc(g * .5 + g * .5) 10)", "rgb(102, 51, 10)");
21777    test("rgb(from rebeccapurple r calc(b * .5 - g * .5) 10)", "rgb(102, 51, 10)");
21778    test(
21779      "rgb(from rgb(20%, 40%, 60%, 80%) calc(r) calc(g) calc(b) / calc(alpha))",
21780      "rgba(51, 102, 153, 0.8)",
21781    );
21782
21783    // Testing with 'none'.
21784    test("rgb(from rebeccapurple none none none)", "rgb(0, 0, 0)");
21785    test("rgb(from rebeccapurple none none none / none)", "rgba(0, 0, 0, 0)");
21786    test("rgb(from rebeccapurple r g none)", "rgb(102, 51, 0)");
21787    test("rgb(from rebeccapurple r g none / alpha)", "rgb(102, 51, 0)");
21788    test("rgb(from rebeccapurple r g b / none)", "rgba(102, 51, 153, 0)");
21789    test(
21790      "rgb(from rgb(20% 40% 60% / 80%) r g none / alpha)",
21791      "rgba(51, 102, 0, 0.8)",
21792    );
21793    test("rgb(from rgb(20% 40% 60% / 80%) r g b / none)", "rgba(51, 102, 153, 0)");
21794    // FIXME: Clarify with spec editors if 'none' should pass through to the constants.
21795    test("rgb(from rgb(none none none) r g b)", "rgb(0, 0, 0)");
21796    test("rgb(from rgb(none none none / none) r g b / alpha)", "rgba(0, 0, 0, 0)");
21797    test("rgb(from rgb(20% none 60%) r g b)", "rgb(51, 0, 153)");
21798    test(
21799      "rgb(from rgb(20% 40% 60% / none) r g b / alpha)",
21800      "rgba(51, 102, 153, 0)",
21801    );
21802
21803    // hsl(from ...)
21804
21805    // Testing no modifications.
21806    test("hsl(from rebeccapurple h s l)", "rgb(102, 51, 153)");
21807    test("hsl(from rebeccapurple h s l / alpha)", "rgb(102, 51, 153)");
21808    test(
21809      "hsl(from rgb(20%, 40%, 60%, 80%) h s l / alpha)",
21810      "rgba(51, 102, 153, 0.8)",
21811    );
21812    test(
21813      "hsl(from hsl(120deg 20% 50% / .5) h s l / alpha)",
21814      "rgba(102, 153, 102, 0.5)",
21815    );
21816
21817    // Test nesting relative colors.
21818    test("hsl(from hsl(from rebeccapurple h s l) h s l)", "rgb(102, 51, 153)");
21819
21820    // Testing non-sRGB origin colors to see gamut mapping.
21821    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).
21822    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).
21823    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,
21824    test("hsl(from lch(100% 116 334) h s l)", "rgb(255, 255, 255)"); // Naive clip based mapping would give rgb(255, 150, 255).
21825    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,
21826    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).
21827    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).
21828    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).
21829    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).
21830
21831    // Testing replacement with 0.
21832    test("hsl(from rebeccapurple 0 0% 0%)", "rgb(0, 0, 0)");
21833    test("hsl(from rebeccapurple 0deg 0% 0%)", "rgb(0, 0, 0)");
21834    test("hsl(from rebeccapurple 0 0% 0% / 0)", "rgba(0, 0, 0, 0)");
21835    test("hsl(from rebeccapurple 0deg 0% 0% / 0)", "rgba(0, 0, 0, 0)");
21836    test("hsl(from rebeccapurple 0 s l / alpha)", "rgb(153, 51, 51)");
21837    test("hsl(from rebeccapurple 0deg s l / alpha)", "rgb(153, 51, 51)");
21838    test("hsl(from rebeccapurple h 0% l / alpha)", "rgb(102, 102, 102)");
21839    test("hsl(from rebeccapurple h s 0% / alpha)", "rgb(0, 0, 0)");
21840    test("hsl(from rebeccapurple h s l / 0)", "rgba(102, 51, 153, 0)");
21841    test(
21842      "hsl(from rgb(20%, 40%, 60%, 80%) 0 s l / alpha)",
21843      "rgba(153, 51, 51, 0.8)",
21844    );
21845    test(
21846      "hsl(from rgb(20%, 40%, 60%, 80%) 0deg s l / alpha)",
21847      "rgba(153, 51, 51, 0.8)",
21848    );
21849    test(
21850      "hsl(from rgb(20%, 40%, 60%, 80%) h 0% l / alpha)",
21851      "rgba(102, 102, 102, 0.8)",
21852    );
21853    test("hsl(from rgb(20%, 40%, 60%, 80%) h s 0% / alpha)", "rgba(0, 0, 0, 0.8)");
21854    test("hsl(from rgb(20%, 40%, 60%, 80%) h s l / 0)", "rgba(51, 102, 153, 0)");
21855
21856    // Testing replacement with a constant.
21857    test("hsl(from rebeccapurple 25 s l / alpha)", "rgb(153, 94, 51)");
21858    test("hsl(from rebeccapurple 25deg s l / alpha)", "rgb(153, 94, 51)");
21859    test("hsl(from rebeccapurple h 20% l / alpha)", "rgb(102, 82, 122)");
21860    test("hsl(from rebeccapurple h s 20% / alpha)", "rgb(51, 25, 77)");
21861    test("hsl(from rebeccapurple h s l / .25)", "rgba(102, 51, 153, 0.25)");
21862    test(
21863      "hsl(from rgb(20%, 40%, 60%, 80%) 25 s l / alpha)",
21864      "rgba(153, 94, 51, 0.8)",
21865    );
21866    test(
21867      "hsl(from rgb(20%, 40%, 60%, 80%) 25deg s l / alpha)",
21868      "rgba(153, 94, 51, 0.8)",
21869    );
21870    test(
21871      "hsl(from rgb(20%, 40%, 60%, 80%) h 20% l / alpha)",
21872      "rgba(82, 102, 122, 0.8)",
21873    );
21874    test(
21875      "hsl(from rgb(20%, 40%, 60%, 80%) h s 20% / alpha)",
21876      "rgba(25, 51, 77, 0.8)",
21877    );
21878    test(
21879      "hsl(from rgb(20%, 40%, 60%, 80%) h s l / .2)",
21880      "rgba(51, 102, 153, 0.2)",
21881    );
21882
21883    // Testing valid permutation (types match).
21884    test("hsl(from rebeccapurple h l s)", "rgb(128, 77, 179)");
21885    test(
21886      "hsl(from rebeccapurple h calc(alpha * 100) l / calc(s / 100))",
21887      "rgba(102, 0, 204, 0.5)",
21888    );
21889    test(
21890      "hsl(from rebeccapurple h l l / calc(l / 100))",
21891      "rgba(102, 61, 143, 0.4)",
21892    );
21893    test(
21894      "hsl(from rebeccapurple h calc(alpha * 100) calc(alpha * 100) / calc(alpha * 100))",
21895      "rgb(255, 255, 255)",
21896    );
21897    test("hsl(from rgb(20%, 40%, 60%, 80%) h l s)", "rgba(77, 128, 179, 0.8)");
21898    test(
21899      "hsl(from rgb(20%, 40%, 60%, 80%) h calc(alpha * 100) l / calc(s / 100))",
21900      "rgba(20, 102, 184, 0.5)",
21901    );
21902    test(
21903      "hsl(from rgb(20%, 40%, 60%, 80%) h l l / calc(l / 100))",
21904      "rgba(61, 102, 143, 0.4)",
21905    );
21906    test(
21907      "hsl(from rgb(20%, 40%, 60%, 80%) h calc(alpha * 100) calc(alpha * 100) / alpha)",
21908      "rgba(163, 204, 245, 0.8)",
21909    );
21910
21911    // Testing with calc().
21912    test("hsl(from rebeccapurple calc(h) calc(s) calc(l))", "rgb(102, 51, 153)");
21913    test(
21914      "hsl(from rgb(20%, 40%, 60%, 80%) calc(h) calc(s) calc(l) / calc(alpha))",
21915      "rgba(51, 102, 153, 0.8)",
21916    );
21917
21918    // Testing with 'none'.
21919    test("hsl(from rebeccapurple none none none)", "rgb(0, 0, 0)");
21920    test("hsl(from rebeccapurple none none none / none)", "rgba(0, 0, 0, 0)");
21921    test("hsl(from rebeccapurple h s none)", "rgb(0, 0, 0)");
21922    test("hsl(from rebeccapurple h s none / alpha)", "rgb(0, 0, 0)");
21923    test("hsl(from rebeccapurple h s l / none)", "rgba(102, 51, 153, 0)");
21924    test("hsl(from rebeccapurple none s l / alpha)", "rgb(153, 51, 51)");
21925    test(
21926      "hsl(from hsl(120deg 20% 50% / .5) h s none / alpha)",
21927      "rgba(0, 0, 0, 0.5)",
21928    );
21929    test(
21930      "hsl(from hsl(120deg 20% 50% / .5) h s l / none)",
21931      "rgba(102, 153, 102, 0)",
21932    );
21933    test(
21934      "hsl(from hsl(120deg 20% 50% / .5) none s l / alpha)",
21935      "rgba(153, 102, 102, 0.5)",
21936    );
21937    // FIXME: Clarify with spec editors if 'none' should pass through to the constants.
21938    test("hsl(from hsl(none none none) h s l)", "rgb(0, 0, 0)");
21939    test("hsl(from hsl(none none none / none) h s l / alpha)", "rgba(0, 0, 0, 0)");
21940    test("hsl(from hsl(120deg none 50% / .5) h s l)", "rgba(128, 128, 128, 0.5)");
21941    test(
21942      "hsl(from hsl(120deg 20% 50% / none) h s l / alpha)",
21943      "rgba(102, 153, 102, 0)",
21944    );
21945    test(
21946      "hsl(from hsl(none 20% 50% / .5) h s l / alpha)",
21947      "rgba(153, 102, 102, 0.5)",
21948    );
21949
21950    // hwb(from ...)
21951
21952    // Testing no modifications.
21953    test("hwb(from rebeccapurple h w b)", "rgb(102, 51, 153)");
21954    test("hwb(from rebeccapurple h w b / alpha)", "rgb(102, 51, 153)");
21955    test(
21956      "hwb(from rgb(20%, 40%, 60%, 80%) h w b / alpha)",
21957      "rgba(51, 102, 153, 0.8)",
21958    );
21959    test(
21960      "hwb(from hsl(120deg 20% 50% / .5) h w b / alpha)",
21961      "rgba(102, 153, 102, 0.5)",
21962    );
21963
21964    // Test nesting relative colors.
21965    test("hwb(from hwb(from rebeccapurple h w b) h w b)", "rgb(102, 51, 153)");
21966
21967    // Testing non-sRGB origin colors to see gamut mapping.
21968    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).
21969    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).
21970    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,
21971    test("hwb(from lch(100% 116 334) h w b)", "rgb(255, 255, 255)"); // Naive clip based mapping would give rgb(255, 150, 255).
21972    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,
21973    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).
21974    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).
21975    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).
21976    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).
21977
21978    // Testing replacement with 0.
21979    test("hwb(from rebeccapurple 0 0% 0%)", "rgb(255, 0, 0)");
21980    test("hwb(from rebeccapurple 0deg 0% 0%)", "rgb(255, 0, 0)");
21981    test("hwb(from rebeccapurple 0 0% 0% / 0)", "rgba(255, 0, 0, 0)");
21982    test("hwb(from rebeccapurple 0deg 0% 0% / 0)", "rgba(255, 0, 0, 0)");
21983    test("hwb(from rebeccapurple 0 w b / alpha)", "rgb(153, 51, 51)");
21984    test("hwb(from rebeccapurple 0deg w b / alpha)", "rgb(153, 51, 51)");
21985    test("hwb(from rebeccapurple h 0% b / alpha)", "rgb(77, 0, 153)");
21986    test("hwb(from rebeccapurple h w 0% / alpha)", "rgb(153, 51, 255)");
21987    test("hwb(from rebeccapurple h w b / 0)", "rgba(102, 51, 153, 0)");
21988    test(
21989      "hwb(from rgb(20%, 40%, 60%, 80%) 0 w b / alpha)",
21990      "rgba(153, 51, 51, 0.8)",
21991    );
21992    test(
21993      "hwb(from rgb(20%, 40%, 60%, 80%) 0deg w b / alpha)",
21994      "rgba(153, 51, 51, 0.8)",
21995    );
21996    test(
21997      "hwb(from rgb(20%, 40%, 60%, 80%) h 0% b / alpha)",
21998      "rgba(0, 77, 153, 0.8)",
21999    );
22000    test(
22001      "hwb(from rgb(20%, 40%, 60%, 80%) h w 0% / alpha)",
22002      "rgba(51, 153, 255, 0.8)",
22003    );
22004    test("hwb(from rgb(20%, 40%, 60%, 80%) h w b / 0)", "rgba(51, 102, 153, 0)");
22005
22006    // Testing replacement with a constant.
22007    test("hwb(from rebeccapurple 25 w b / alpha)", "rgb(153, 94, 51)");
22008    test("hwb(from rebeccapurple 25deg w b / alpha)", "rgb(153, 94, 51)");
22009    test("hwb(from rebeccapurple h 20% b / alpha)", "rgb(102, 51, 153)");
22010    test("hwb(from rebeccapurple h w 20% / alpha)", "rgb(128, 51, 204)");
22011    test("hwb(from rebeccapurple h w b / .2)", "rgba(102, 51, 153, 0.2)");
22012    test(
22013      "hwb(from rgb(20%, 40%, 60%, 80%) 25 w b / alpha)",
22014      "rgba(153, 94, 51, 0.8)",
22015    );
22016    test(
22017      "hwb(from rgb(20%, 40%, 60%, 80%) 25deg w b / alpha)",
22018      "rgba(153, 94, 51, 0.8)",
22019    );
22020    test(
22021      "hwb(from rgb(20%, 40%, 60%, 80%) h 20% b / alpha)",
22022      "rgba(51, 102, 153, 0.8)",
22023    );
22024    test(
22025      "hwb(from rgb(20%, 40%, 60%, 80%) h w 20% / alpha)",
22026      "rgba(51, 128, 204, 0.8)",
22027    );
22028    test(
22029      "hwb(from rgb(20%, 40%, 60%, 80%) h w b / .2)",
22030      "rgba(51, 102, 153, 0.2)",
22031    );
22032
22033    // Testing valid permutation (types match).
22034    test("hwb(from rebeccapurple h b w)", "rgb(153, 102, 204)");
22035    test(
22036      "hwb(from rebeccapurple h calc(alpha * 100) w / calc(b / 100))",
22037      "rgba(213, 213, 213, 0.4)",
22038    );
22039    test(
22040      "hwb(from rebeccapurple h w w / calc(w / 100))",
22041      "rgba(128, 51, 204, 0.2)",
22042    );
22043    test(
22044      "hwb(from rebeccapurple h calc(alpha * 100) calc(alpha * 100) / alpha)",
22045      "rgb(128, 128, 128)",
22046    );
22047    test("hwb(from rgb(20%, 40%, 60%, 80%) h b w)", "rgba(102, 153, 204, 0.8)");
22048    test(
22049      "hwb(from rgb(20%, 40%, 60%, 80%) h calc(alpha * 100) w / calc(b / 100))",
22050      "rgba(204, 204, 204, 0.4)",
22051    );
22052    test(
22053      "hwb(from rgb(20%, 40%, 60%, 80%) h w w / calc(w / 100))",
22054      "rgba(51, 128, 204, 0.2)",
22055    );
22056    test(
22057      "hwb(from rgb(20%, 40%, 60%, 80%) h calc(alpha * 100) calc(alpha * 100) / alpha)",
22058      "rgba(128, 128, 128, 0.8)",
22059    );
22060
22061    // Testing with calc().
22062    test("hwb(from rebeccapurple calc(h) calc(w) calc(b))", "rgb(102, 51, 153)");
22063    test(
22064      "hwb(from rgb(20%, 40%, 60%, 80%) calc(h) calc(w) calc(b) / calc(alpha))",
22065      "rgba(51, 102, 153, 0.8)",
22066    );
22067
22068    // Testing with 'none'.
22069    test("hwb(from rebeccapurple none none none)", "rgb(255, 0, 0)");
22070    test("hwb(from rebeccapurple none none none / none)", "rgba(255, 0, 0, 0)");
22071    test("hwb(from rebeccapurple h w none)", "rgb(153, 51, 255)");
22072    test("hwb(from rebeccapurple h w none / alpha)", "rgb(153, 51, 255)");
22073    test("hwb(from rebeccapurple h w b / none)", "rgba(102, 51, 153, 0)");
22074    test("hwb(from rebeccapurple none w b / alpha)", "rgb(153, 51, 51)");
22075    test(
22076      "hwb(from hwb(120deg 20% 50% / .5) h w none / alpha)",
22077      "rgba(51, 255, 51, 0.5)",
22078    );
22079    test(
22080      "hwb(from hwb(120deg 20% 50% / .5) h w b / none)",
22081      "rgba(51, 128, 51, 0)",
22082    );
22083    test(
22084      "hwb(from hwb(120deg 20% 50% / .5) none w b / alpha)",
22085      "rgba(128, 51, 51, 0.5)",
22086    );
22087    // FIXME: Clarify with spec editors if 'none' should pass through to the constants.
22088    test("hwb(from hwb(none none none) h w b)", "rgb(255, 0, 0)");
22089    test(
22090      "hwb(from hwb(none none none / none) h w b / alpha)",
22091      "rgba(255, 0, 0, 0)",
22092    );
22093    test("hwb(from hwb(120deg none 50% / .5) h w b)", "rgba(0, 128, 0, 0.5)");
22094    test(
22095      "hwb(from hwb(120deg 20% 50% / none) h w b / alpha)",
22096      "rgba(51, 128, 51, 0)",
22097    );
22098    test(
22099      "hwb(from hwb(none 20% 50% / .5) h w b / alpha)",
22100      "rgba(128, 51, 51, 0.5)",
22101    );
22102
22103    for color_space in &["lab", "oklab"] {
22104      // Testing no modifications.
22105      test(
22106        &format!("{}(from {}(25% 20 50) l a b)", color_space, color_space),
22107        &format!("{}(25% 20 50)", color_space),
22108      );
22109      test(
22110        &format!("{}(from {}(25% 20 50) l a b / alpha)", color_space, color_space),
22111        &format!("{}(25% 20 50)", color_space),
22112      );
22113      test(
22114        &format!("{}(from {}(25% 20 50 / 40%) l a b / alpha)", color_space, color_space),
22115        &format!("{}(25% 20 50 / 0.4)", color_space),
22116      );
22117      test(
22118        &format!(
22119          "{}(from {}(200% 300 400 / 500%) l a b / alpha)",
22120          color_space, color_space
22121        ),
22122        &format!("{}(200% 300 400)", color_space),
22123      );
22124      test(
22125        &format!(
22126          "{}(from {}(-200% -300 -400 / -500%) l a b / alpha)",
22127          color_space, color_space
22128        ),
22129        &format!("{}(0% -300 -400 / 0)", color_space),
22130      );
22131
22132      // Test nesting relative colors.
22133      test(
22134        &format!(
22135          "{}(from {}(from {}(25% 20 50) l a b) l a b)",
22136          color_space, color_space, color_space
22137        ),
22138        &format!("{}(25% 20 50)", color_space),
22139      );
22140
22141      // Testing non-${colorSpace} origin to see conversion.
22142      test(
22143        &format!("{}(from color(display-p3 0 0 0) l a b / alpha)", color_space),
22144        &format!("{}(0% 0 0)", color_space),
22145      );
22146
22147      // Testing replacement with 0.
22148      test(
22149        &format!("{}(from {}(25% 20 50) 0% 0 0)", color_space, color_space),
22150        &format!("{}(0% 0 0)", color_space),
22151      );
22152      test(
22153        &format!("{}(from {}(25% 20 50) 0% 0 0 / 0)", color_space, color_space),
22154        &format!("{}(0% 0 0 / 0)", color_space),
22155      );
22156      test(
22157        &format!("{}(from {}(25% 20 50) 0% a b / alpha)", color_space, color_space),
22158        &format!("{}(0% 20 50)", color_space),
22159      );
22160      test(
22161        &format!("{}(from {}(25% 20 50) l 0 b / alpha)", color_space, color_space),
22162        &format!("{}(25% 0 50)", color_space),
22163      );
22164      test(
22165        &format!("{}(from {}(25% 20 50) l a 0 / alpha)", color_space, color_space),
22166        &format!("{}(25% 20 0)", color_space),
22167      );
22168      test(
22169        &format!("{}(from {}(25% 20 50) l a b / 0)", color_space, color_space),
22170        &format!("{}(25% 20 50 / 0)", color_space),
22171      );
22172      test(
22173        &format!("{}(from {}(25% 20 50 / 40%) 0% a b / alpha)", color_space, color_space),
22174        &format!("{}(0% 20 50 / 0.4)", color_space),
22175      );
22176      test(
22177        &format!("{}(from {}(25% 20 50 / 40%) l 0 b / alpha)", color_space, color_space),
22178        &format!("{}(25% 0 50 / 0.4)", color_space),
22179      );
22180      test(
22181        &format!("{}(from {}(25% 20 50 / 40%) l a 0 / alpha)", color_space, color_space),
22182        &format!("{}(25% 20 0 / 0.4)", color_space),
22183      );
22184      test(
22185        &format!("{}(from {}(25% 20 50 / 40%) l a b / 0)", color_space, color_space),
22186        &format!("{}(25% 20 50 / 0)", color_space),
22187      );
22188
22189      // Testing replacement with a constant.
22190      test(
22191        &format!("{}(from {}(25% 20 50) 35% a b / alpha)", color_space, color_space),
22192        &format!("{}(35% 20 50)", color_space),
22193      );
22194      test(
22195        &format!("{}(from {}(25% 20 50) l 35 b / alpha)", color_space, color_space),
22196        &format!("{}(25% 35 50)", color_space),
22197      );
22198      test(
22199        &format!("{}(from {}(25% 20 50) l a 35 / alpha)", color_space, color_space),
22200        &format!("{}(25% 20 35)", color_space),
22201      );
22202      test(
22203        &format!("{}(from {}(25% 20 50) l a b / .35)", color_space, color_space),
22204        &format!("{}(25% 20 50 / 0.35)", color_space),
22205      );
22206      test(
22207        &format!("{}(from {}(25% 20 50 / 40%) 35% a b / alpha)", color_space, color_space),
22208        &format!("{}(35% 20 50 / 0.4)", color_space),
22209      );
22210      test(
22211        &format!("{}(from {}(25% 20 50 / 40%) l 35 b / alpha)", color_space, color_space),
22212        &format!("{}(25% 35 50 / 0.4)", color_space),
22213      );
22214      test(
22215        &format!("{}(from {}(25% 20 50 / 40%) l a 35 / alpha)", color_space, color_space),
22216        &format!("{}(25% 20 35 / 0.4)", color_space),
22217      );
22218      test(
22219        &format!("{}(from {}(25% 20 50 / 40%) l a b / .35)", color_space, color_space),
22220        &format!("{}(25% 20 50 / 0.35)", color_space),
22221      );
22222      test(
22223        &format!(
22224          "{}(from {}(70% 45 30 / 40%) 200% 300 400 / 500)",
22225          color_space, color_space
22226        ),
22227        &format!("{}(200% 300 400)", color_space),
22228      );
22229      test(
22230        &format!(
22231          "{}(from {}(70% 45 30 / 40%) -200% -300 -400 / -500)",
22232          color_space, color_space
22233        ),
22234        &format!("{}(0% -300 -400 / 0)", color_space),
22235      );
22236
22237      // Testing valid permutation (types match).
22238      test(
22239        &format!("{}(from {}(25% 20 50) l b a)", color_space, color_space),
22240        &format!("{}(25% 50 20)", color_space),
22241      );
22242      test(
22243        &format!("{}(from {}(25% 20 50) l a a / a)", color_space, color_space),
22244        &format!("{}(25% 20 20)", color_space),
22245      );
22246      test(
22247        &format!("{}(from {}(25% 20 50 / 40%) l b a)", color_space, color_space),
22248        &format!("{}(25% 50 20 / 0.4)", color_space),
22249      );
22250      test(
22251        &format!("{}(from {}(25% 20 50 / 40%) l a a / a)", color_space, color_space),
22252        &format!("{}(25% 20 20)", color_space),
22253      );
22254
22255      // Testing with calc().
22256      test(
22257        &format!(
22258          "{}(from {}(25% 20 50) calc(l) calc(a) calc(b))",
22259          color_space, color_space
22260        ),
22261        &format!("{}(25% 20 50)", color_space),
22262      );
22263      test(
22264        &format!(
22265          "{}(from {}(25% 20 50 / 40%) calc(l) calc(a) calc(b) / calc(alpha))",
22266          color_space, color_space
22267        ),
22268        &format!("{}(25% 20 50 / 0.4)", color_space),
22269      );
22270
22271      // Testing with 'none'.
22272      test(
22273        &format!("{}(from {}(25% 20 50) none none none)", color_space, color_space),
22274        &format!("{}(none none none)", color_space),
22275      );
22276      test(
22277        &format!("{}(from {}(25% 20 50) none none none / none)", color_space, color_space),
22278        &format!("{}(none none none / none)", color_space),
22279      );
22280      test(
22281        &format!("{}(from {}(25% 20 50) l a none)", color_space, color_space),
22282        &format!("{}(25% 20 none)", color_space),
22283      );
22284      test(
22285        &format!("{}(from {}(25% 20 50) l a none / alpha)", color_space, color_space),
22286        &format!("{}(25% 20 none)", color_space),
22287      );
22288      test(
22289        &format!("{}(from {}(25% 20 50) l a b / none)", color_space, color_space),
22290        &format!("{}(25% 20 50 / none)", color_space),
22291      );
22292      test(
22293        &format!(
22294          "{}(from {}(25% 20 50 / 40%) l a none / alpha)",
22295          color_space, color_space
22296        ),
22297        &format!("{}(25% 20 none / 0.4)", color_space),
22298      );
22299      test(
22300        &format!("{}(from {}(25% 20 50 / 40%) l a b / none)", color_space, color_space),
22301        &format!("{}(25% 20 50 / none)", color_space),
22302      );
22303      // FIXME: Clarify with spec editors if 'none' should pass through to the constants.
22304      test(
22305        &format!("{}(from {}(none none none) l a b)", color_space, color_space),
22306        &format!("{}(0% 0 0)", color_space),
22307      );
22308      test(
22309        &format!(
22310          "{}(from {}(none none none / none) l a b / alpha)",
22311          color_space, color_space
22312        ),
22313        &format!("{}(0% 0 0 / 0)", color_space),
22314      );
22315      test(
22316        &format!("{}(from {}(25% none 50) l a b)", color_space, color_space),
22317        &format!("{}(25% 0 50)", color_space),
22318      );
22319      test(
22320        &format!("{}(from {}(25% 20 50 / none) l a b / alpha)", color_space, color_space),
22321        &format!("{}(25% 20 50 / 0)", color_space),
22322      );
22323    }
22324
22325    // test_valid_value\(`color`, `\$\{colorSpace\}\(from \$\{colorSpace\}\((.*?)`,\s*`\$\{colorSpace\}(.*?)`\)
22326    // test(&format!("{}(from {}($1", color_space, color_space), &format!("{}$2", color_space))
22327
22328    for color_space in &["lch", "oklch"] {
22329      // Cover omitted alpha in LCH and OKLCH.
22330      test(
22331        &format!("{}(from {}(50% 0.2 120 / 0.4) l c h)", color_space, color_space),
22332        &format!("{}(50% 0.2 120 / 0.4)", color_space),
22333      );
22334
22335      // Testing no modifications.
22336      test(
22337        &format!("{}(from {}(70% 45 30) l c h)", color_space, color_space),
22338        &format!("{}(70% 45 30)", color_space),
22339      );
22340      test(
22341        &format!("{}(from {}(70% 45 30) l c h / alpha)", color_space, color_space),
22342        &format!("{}(70% 45 30)", color_space),
22343      );
22344      test(
22345        &format!("{}(from {}(70% 45 30 / 40%) l c h / alpha)", color_space, color_space),
22346        &format!("{}(70% 45 30 / 0.4)", color_space),
22347      );
22348      test(
22349        &format!(
22350          "{}(from {}(200% 300 400 / 500%) l c h / alpha)",
22351          color_space, color_space
22352        ),
22353        &format!("{}(200% 300 40)", color_space),
22354      );
22355      test(
22356        &format!(
22357          "{}(from {}(-200% -300 -400 / -500%) l c h / alpha)",
22358          color_space, color_space
22359        ),
22360        &format!("{}(0% 0 320 / 0)", color_space),
22361      );
22362
22363      // Test nesting relative colors.
22364      test(
22365        &format!(
22366          "{}(from {}(from {}(70% 45 30) l c h) l c h)",
22367          color_space, color_space, color_space
22368        ),
22369        &format!("{}(70% 45 30)", color_space),
22370      );
22371
22372      // Testing non-sRGB origin colors (no gamut mapping will happen since the destination is not a bounded RGB color space).
22373      test(
22374        &format!("{}(from color(display-p3 0 0 0) l c h / alpha)", color_space),
22375        &format!("{}(0% 0 0)", color_space),
22376      );
22377
22378      // Testing replacement with 0.
22379      test(
22380        &format!("{}(from {}(70% 45 30) 0% 0 0)", color_space, color_space),
22381        &format!("{}(0% 0 0)", color_space),
22382      );
22383      test(
22384        &format!("{}(from {}(70% 45 30) 0% 0 0deg)", color_space, color_space),
22385        &format!("{}(0% 0 0)", color_space),
22386      );
22387      test(
22388        &format!("{}(from {}(70% 45 30) 0% 0 0 / 0)", color_space, color_space),
22389        &format!("{}(0% 0 0 / 0)", color_space),
22390      );
22391      test(
22392        &format!("{}(from {}(70% 45 30) 0% 0 0deg / 0)", color_space, color_space),
22393        &format!("{}(0% 0 0 / 0)", color_space),
22394      );
22395      test(
22396        &format!("{}(from {}(70% 45 30) 0% c h / alpha)", color_space, color_space),
22397        &format!("{}(0% 45 30)", color_space),
22398      );
22399      test(
22400        &format!("{}(from {}(70% 45 30) l 0 h / alpha)", color_space, color_space),
22401        &format!("{}(70% 0 30)", color_space),
22402      );
22403      test(
22404        &format!("{}(from {}(70% 45 30) l c 0 / alpha)", color_space, color_space),
22405        &format!("{}(70% 45 0)", color_space),
22406      );
22407      test(
22408        &format!("{}(from {}(70% 45 30) l c 0deg / alpha)", color_space, color_space),
22409        &format!("{}(70% 45 0)", color_space),
22410      );
22411      test(
22412        &format!("{}(from {}(70% 45 30) l c h / 0)", color_space, color_space),
22413        &format!("{}(70% 45 30 / 0)", color_space),
22414      );
22415      test(
22416        &format!("{}(from {}(70% 45 30 / 40%) 0% c h / alpha)", color_space, color_space),
22417        &format!("{}(0% 45 30 / 0.4)", color_space),
22418      );
22419      test(
22420        &format!("{}(from {}(70% 45 30 / 40%) l 0 h / alpha)", color_space, color_space),
22421        &format!("{}(70% 0 30 / 0.4)", color_space),
22422      );
22423      test(
22424        &format!("{}(from {}(70% 45 30 / 40%) l c 0 / alpha)", color_space, color_space),
22425        &format!("{}(70% 45 0 / 0.4)", color_space),
22426      );
22427      test(
22428        &format!(
22429          "{}(from {}(70% 45 30 / 40%) l c 0deg / alpha)",
22430          color_space, color_space
22431        ),
22432        &format!("{}(70% 45 0 / 0.4)", color_space),
22433      );
22434      test(
22435        &format!("{}(from {}(70% 45 30 / 40%) l c h / 0)", color_space, color_space),
22436        &format!("{}(70% 45 30 / 0)", color_space),
22437      );
22438
22439      // Testing replacement with a constant.
22440      test(
22441        &format!("{}(from {}(70% 45 30) 25% c h / alpha)", color_space, color_space),
22442        &format!("{}(25% 45 30)", color_space),
22443      );
22444      test(
22445        &format!("{}(from {}(70% 45 30) l 25 h / alpha)", color_space, color_space),
22446        &format!("{}(70% 25 30)", color_space),
22447      );
22448      test(
22449        &format!("{}(from {}(70% 45 30) l c 25 / alpha)", color_space, color_space),
22450        &format!("{}(70% 45 25)", color_space),
22451      );
22452      test(
22453        &format!("{}(from {}(70% 45 30) l c 25deg / alpha)", color_space, color_space),
22454        &format!("{}(70% 45 25)", color_space),
22455      );
22456      test(
22457        &format!("{}(from {}(70% 45 30) l c h / .25)", color_space, color_space),
22458        &format!("{}(70% 45 30 / 0.25)", color_space),
22459      );
22460      test(
22461        &format!("{}(from {}(70% 45 30 / 40%) 25% c h / alpha)", color_space, color_space),
22462        &format!("{}(25% 45 30 / 0.4)", color_space),
22463      );
22464      test(
22465        &format!("{}(from {}(70% 45 30 / 40%) l 25 h / alpha)", color_space, color_space),
22466        &format!("{}(70% 25 30 / 0.4)", color_space),
22467      );
22468      test(
22469        &format!("{}(from {}(70% 45 30 / 40%) l c 25 / alpha)", color_space, color_space),
22470        &format!("{}(70% 45 25 / 0.4)", color_space),
22471      );
22472      test(
22473        &format!(
22474          "{}(from {}(70% 45 30 / 40%) l c 25deg / alpha)",
22475          color_space, color_space
22476        ),
22477        &format!("{}(70% 45 25 / 0.4)", color_space),
22478      );
22479      test(
22480        &format!("{}(from {}(70% 45 30 / 40%) l c h / .25)", color_space, color_space),
22481        &format!("{}(70% 45 30 / 0.25)", color_space),
22482      );
22483      test(
22484        &format!(
22485          "{}(from {}(70% 45 30 / 40%) 200% 300 400 / 500)",
22486          color_space, color_space
22487        ),
22488        &format!("{}(200% 300 400)", color_space),
22489      );
22490      test(
22491        &format!(
22492          "{}(from {}(70% 45 30 / 40%) -200% -300 -400 / -500)",
22493          color_space, color_space
22494        ),
22495        &format!("{}(0% 0 -400 / 0)", color_space),
22496      );
22497      test(
22498        &format!(
22499          "{}(from {}(70% 45 30 / 40%) 50% 120 400deg / 500)",
22500          color_space, color_space
22501        ),
22502        &format!("{}(50% 120 400)", color_space),
22503      );
22504      test(
22505        &format!(
22506          "{}(from {}(70% 45 30 / 40%) 50% 120 -400deg / -500)",
22507          color_space, color_space
22508        ),
22509        &format!("{}(50% 120 -400 / 0)", color_space),
22510      );
22511
22512      // Testing valid permutation (types match).
22513      // NOTE: 'c' is a valid hue, as hue is <angle>|<number>.
22514      test(
22515        &format!("{}(from {}(70% 45 30) alpha c h / l)", color_space, color_space),
22516        &format!(
22517          "{}(1 45 30 / {})",
22518          color_space,
22519          if *color_space == "lch" { "1" } else { ".7" }
22520        ),
22521      );
22522      test(
22523        &format!("{}(from {}(70% 45 30) l c c / alpha)", color_space, color_space),
22524        &format!("{}(70% 45 45)", color_space),
22525      );
22526      test(
22527        &format!("{}(from {}(70% 45 30) alpha c h / alpha)", color_space, color_space),
22528        &format!("{}(1 45 30)", color_space),
22529      );
22530      test(
22531        &format!("{}(from {}(70% 45 30) alpha c c / alpha)", color_space, color_space),
22532        &format!("{}(1 45 45)", color_space),
22533      );
22534      test(
22535        &format!("{}(from {}(70% 45 30 / 40%) alpha c h / l)", color_space, color_space),
22536        &format!(
22537          "{}(.4 45 30 / {})",
22538          color_space,
22539          if *color_space == "lch" { "1" } else { ".7" }
22540        ),
22541      );
22542      test(
22543        &format!("{}(from {}(70% 45 30 / 40%) l c c / alpha)", color_space, color_space),
22544        &format!("{}(70% 45 45 / 0.4)", color_space),
22545      );
22546      test(
22547        &format!(
22548          "{}(from {}(70% 45 30 / 40%) alpha c h / alpha)",
22549          color_space, color_space
22550        ),
22551        &format!("{}(.4 45 30 / 0.4)", color_space),
22552      );
22553      test(
22554        &format!(
22555          "{}(from {}(70% 45 30 / 40%) alpha c c / alpha)",
22556          color_space, color_space
22557        ),
22558        &format!("{}(.4 45 45 / 0.4)", color_space),
22559      );
22560
22561      // Testing with calc().
22562      test(
22563        &format!(
22564          "{}(from {}(70% 45 30) calc(l) calc(c) calc(h))",
22565          color_space, color_space
22566        ),
22567        &format!("{}(70% 45 30)", color_space),
22568      );
22569      test(
22570        &format!(
22571          "{}(from {}(70% 45 30 / 40%) calc(l) calc(c) calc(h) / calc(alpha))",
22572          color_space, color_space
22573        ),
22574        &format!("{}(70% 45 30 / 0.4)", color_space),
22575      );
22576
22577      // Testing with 'none'.
22578      test(
22579        &format!("{}(from {}(70% 45 30) none none none)", color_space, color_space),
22580        &format!("{}(none none none)", color_space),
22581      );
22582      test(
22583        &format!("{}(from {}(70% 45 30) none none none / none)", color_space, color_space),
22584        &format!("{}(none none none / none)", color_space),
22585      );
22586      test(
22587        &format!("{}(from {}(70% 45 30) l c none)", color_space, color_space),
22588        &format!("{}(70% 45 none)", color_space),
22589      );
22590      test(
22591        &format!("{}(from {}(70% 45 30) l c none / alpha)", color_space, color_space),
22592        &format!("{}(70% 45 none)", color_space),
22593      );
22594      test(
22595        &format!("{}(from {}(70% 45 30) l c h / none)", color_space, color_space),
22596        &format!("{}(70% 45 30 / none)", color_space),
22597      );
22598      test(
22599        &format!(
22600          "{}(from {}(70% 45 30 / 40%) l c none / alpha)",
22601          color_space, color_space
22602        ),
22603        &format!("{}(70% 45 none / 0.4)", color_space),
22604      );
22605      test(
22606        &format!("{}(from {}(70% 45 30 / 40%) l c h / none)", color_space, color_space),
22607        &format!("{}(70% 45 30 / none)", color_space),
22608      );
22609      // FIXME: Clarify with spec editors if 'none' should pass through to the constants.
22610      test(
22611        &format!("{}(from {}(none none none) l c h)", color_space, color_space),
22612        &format!("{}(0% 0 0)", color_space),
22613      );
22614      test(
22615        &format!(
22616          "{}(from {}(none none none / none) l c h / alpha)",
22617          color_space, color_space
22618        ),
22619        &format!("{}(0% 0 0 / 0)", color_space),
22620      );
22621      test(
22622        &format!("{}(from {}(70% none 30) l c h)", color_space, color_space),
22623        &format!("{}(70% 0 30)", color_space),
22624      );
22625      test(
22626        &format!("{}(from {}(70% 45 30 / none) l c h / alpha)", color_space, color_space),
22627        &format!("{}(70% 45 30 / 0)", color_space),
22628      );
22629    }
22630
22631    // test_valid_value\(`color`, `color\(from color\(\$\{colorSpace\}(.*?) \$\{colorSpace\}(.*?)`,\s*`color\(\$\{colorSpace\}(.*?)`\)
22632    // test(&format!("color(from color({}$1 {}$2", color_space, color_space), &format!("color({}$3", color_space))
22633
22634    for color_space in &["srgb", "srgb-linear", "a98-rgb", "rec2020", "prophoto-rgb"] {
22635      // Testing no modifications.
22636      test(
22637        &format!("color(from color({} 0.7 0.5 0.3) {} r g b)", color_space, color_space),
22638        &format!("color({} 0.7 0.5 0.3)", color_space),
22639      );
22640      test(
22641        &format!(
22642          "color(from color({} 0.7 0.5 0.3) {} r g b / alpha)",
22643          color_space, color_space
22644        ),
22645        &format!("color({} 0.7 0.5 0.3)", color_space),
22646      );
22647      test(
22648        &format!(
22649          "color(from color({} 0.7 0.5 0.3 / 40%) {} r g b)",
22650          color_space, color_space
22651        ),
22652        &format!("color({} 0.7 0.5 0.3 / 0.4)", color_space),
22653      );
22654      test(
22655        &format!(
22656          "color(from color({} 0.7 0.5 0.3 / 40%) {} r g b / alpha)",
22657          color_space, color_space
22658        ),
22659        &format!("color({} 0.7 0.5 0.3 / 0.4)", color_space),
22660      );
22661
22662      // Test nesting relative colors.
22663      test(
22664        &format!(
22665          "color(from color(from color({} 0.7 0.5 0.3) {} r g b) {} r g b)",
22666          color_space, color_space, color_space
22667        ),
22668        &format!("color({} 0.7 0.5 0.3)", color_space),
22669      );
22670
22671      // Testing replacement with 0.
22672      test(
22673        &format!("color(from color({} 0.7 0.5 0.3) {} 0 0 0)", color_space, color_space),
22674        &format!("color({} 0 0 0)", color_space),
22675      );
22676      test(
22677        &format!(
22678          "color(from color({} 0.7 0.5 0.3) {} 0 0 0 / 0)",
22679          color_space, color_space
22680        ),
22681        &format!("color({} 0 0 0 / 0)", color_space),
22682      );
22683      test(
22684        &format!(
22685          "color(from color({} 0.7 0.5 0.3) {} 0 g b / alpha)",
22686          color_space, color_space
22687        ),
22688        &format!("color({} 0 0.5 0.3)", color_space),
22689      );
22690      test(
22691        &format!(
22692          "color(from color({} 0.7 0.5 0.3) {} r 0 b / alpha)",
22693          color_space, color_space
22694        ),
22695        &format!("color({} 0.7 0 0.3)", color_space),
22696      );
22697      test(
22698        &format!(
22699          "color(from color({} 0.7 0.5 0.3) {} r g 0 / alpha)",
22700          color_space, color_space
22701        ),
22702        &format!("color({} 0.7 0.5 0)", color_space),
22703      );
22704      test(
22705        &format!(
22706          "color(from color({} 0.7 0.5 0.3) {} r g b / 0)",
22707          color_space, color_space
22708        ),
22709        &format!("color({} 0.7 0.5 0.3 / 0)", color_space),
22710      );
22711      test(
22712        &format!(
22713          "color(from color({} 0.7 0.5 0.3 / 40%) {} 0 g b / alpha)",
22714          color_space, color_space
22715        ),
22716        &format!("color({} 0 0.5 0.3 / 0.4)", color_space),
22717      );
22718      test(
22719        &format!(
22720          "color(from color({} 0.7 0.5 0.3 / 40%) {} r 0 b / alpha)",
22721          color_space, color_space
22722        ),
22723        &format!("color({} 0.7 0 0.3 / 0.4)", color_space),
22724      );
22725      test(
22726        &format!(
22727          "color(from color({} 0.7 0.5 0.3 / 40%) {} r g 0 / alpha)",
22728          color_space, color_space
22729        ),
22730        &format!("color({} 0.7 0.5 0 / 0.4)", color_space),
22731      );
22732      test(
22733        &format!(
22734          "color(from color({} 0.7 0.5 0.3 / 40%) {} r g b / 0)",
22735          color_space, color_space
22736        ),
22737        &format!("color({} 0.7 0.5 0.3 / 0)", color_space),
22738      );
22739
22740      // Testing replacement with a constant.
22741      test(
22742        &format!(
22743          "color(from color({} 0.7 0.5 0.3) {} 0.2 g b / alpha)",
22744          color_space, color_space
22745        ),
22746        &format!("color({} 0.2 0.5 0.3)", color_space),
22747      );
22748      test(
22749        &format!(
22750          "color(from color({} 0.7 0.5 0.3) {} 20% g b / alpha)",
22751          color_space, color_space
22752        ),
22753        &format!("color({} 0.2 0.5 0.3)", color_space),
22754      );
22755      test(
22756        &format!(
22757          "color(from color({} 0.7 0.5 0.3) {} r 0.2 b / alpha)",
22758          color_space, color_space
22759        ),
22760        &format!("color({} 0.7 0.2 0.3)", color_space),
22761      );
22762      test(
22763        &format!(
22764          "color(from color({} 0.7 0.5 0.3) {} r 20% b / alpha)",
22765          color_space, color_space
22766        ),
22767        &format!("color({} 0.7 0.2 0.3)", color_space),
22768      );
22769      test(
22770        &format!(
22771          "color(from color({} 0.7 0.5 0.3) {} r g 0.2 / alpha)",
22772          color_space, color_space
22773        ),
22774        &format!("color({} 0.7 0.5 0.2)", color_space),
22775      );
22776      test(
22777        &format!(
22778          "color(from color({} 0.7 0.5 0.3) {} r g 20% / alpha)",
22779          color_space, color_space
22780        ),
22781        &format!("color({} 0.7 0.5 0.2)", color_space),
22782      );
22783      test(
22784        &format!(
22785          "color(from color({} 0.7 0.5 0.3) {} r g b / 0.2)",
22786          color_space, color_space
22787        ),
22788        &format!("color({} 0.7 0.5 0.3 / 0.2)", color_space),
22789      );
22790      test(
22791        &format!(
22792          "color(from color({} 0.7 0.5 0.3) {} r g b / 20%)",
22793          color_space, color_space
22794        ),
22795        &format!("color({} 0.7 0.5 0.3 / 0.2)", color_space),
22796      );
22797      test(
22798        &format!(
22799          "color(from color({} 0.7 0.5 0.3 / 40%) {} 0.2 g b / alpha)",
22800          color_space, color_space
22801        ),
22802        &format!("color({} 0.2 0.5 0.3 / 0.4)", color_space),
22803      );
22804      test(
22805        &format!(
22806          "color(from color({} 0.7 0.5 0.3 / 40%) {} 20% g b / alpha)",
22807          color_space, color_space
22808        ),
22809        &format!("color({} 0.2 0.5 0.3 / 0.4)", color_space),
22810      );
22811      test(
22812        &format!(
22813          "color(from color({} 0.7 0.5 0.3 / 40%) {} r 0.2 b / alpha)",
22814          color_space, color_space
22815        ),
22816        &format!("color({} 0.7 0.2 0.3 / 0.4)", color_space),
22817      );
22818      test(
22819        &format!(
22820          "color(from color({} 0.7 0.5 0.3 / 40%) {} r 20% b / alpha)",
22821          color_space, color_space
22822        ),
22823        &format!("color({} 0.7 0.2 0.3 / 0.4)", color_space),
22824      );
22825      test(
22826        &format!(
22827          "color(from color({} 0.7 0.5 0.3 / 40%) {} r g 0.2 / alpha)",
22828          color_space, color_space
22829        ),
22830        &format!("color({} 0.7 0.5 0.2 / 0.4)", color_space),
22831      );
22832      test(
22833        &format!(
22834          "color(from color({} 0.7 0.5 0.3 / 40%) {} r g 20% / alpha)",
22835          color_space, color_space
22836        ),
22837        &format!("color({} 0.7 0.5 0.2 / 0.4)", color_space),
22838      );
22839      test(
22840        &format!(
22841          "color(from color({} 0.7 0.5 0.3 / 40%) {} r g b / 0.2)",
22842          color_space, color_space
22843        ),
22844        &format!("color({} 0.7 0.5 0.3 / 0.2)", color_space),
22845      );
22846      test(
22847        &format!(
22848          "color(from color({} 0.7 0.5 0.3 / 40%) {} r g b / 20%)",
22849          color_space, color_space
22850        ),
22851        &format!("color({} 0.7 0.5 0.3 / 0.2)", color_space),
22852      );
22853      test(
22854        &format!("color(from color({} 0.7 0.5 0.3) {} 2 3 4)", color_space, color_space),
22855        &format!("color({} 2 3 4)", color_space),
22856      );
22857      test(
22858        &format!(
22859          "color(from color({} 0.7 0.5 0.3) {} 2 3 4 / 5)",
22860          color_space, color_space
22861        ),
22862        &format!("color({} 2 3 4)", color_space),
22863      );
22864      test(
22865        &format!(
22866          "color(from color({} 0.7 0.5 0.3) {} -2 -3 -4)",
22867          color_space, color_space
22868        ),
22869        &format!("color({} -2 -3 -4)", color_space),
22870      );
22871      test(
22872        &format!(
22873          "color(from color({} 0.7 0.5 0.3) {} -2 -3 -4 / -5)",
22874          color_space, color_space
22875        ),
22876        &format!("color({} -2 -3 -4 / 0)", color_space),
22877      );
22878      test(
22879        &format!(
22880          "color(from color({} 0.7 0.5 0.3) {} 200% 300% 400%)",
22881          color_space, color_space
22882        ),
22883        &format!("color({} 2 3 4)", color_space),
22884      );
22885      test(
22886        &format!(
22887          "color(from color({} 0.7 0.5 0.3) {} 200% 300% 400% / 500%)",
22888          color_space, color_space
22889        ),
22890        &format!("color({} 2 3 4)", color_space),
22891      );
22892      test(
22893        &format!(
22894          "color(from color({} 0.7 0.5 0.3) {} -200% -300% -400%)",
22895          color_space, color_space
22896        ),
22897        &format!("color({} -2 -3 -4)", color_space),
22898      );
22899      test(
22900        &format!(
22901          "color(from color({} 0.7 0.5 0.3) {} -200% -300% -400% / -500%)",
22902          color_space, color_space
22903        ),
22904        &format!("color({} -2 -3 -4 / 0)", color_space),
22905      );
22906
22907      // Testing valid permutation (types match).
22908      test(
22909        &format!("color(from color({} 0.7 0.5 0.3) {} g b r)", color_space, color_space),
22910        &format!("color({} 0.5 0.3 0.7)", color_space),
22911      );
22912      test(
22913        &format!(
22914          "color(from color({} 0.7 0.5 0.3) {} b alpha r / g)",
22915          color_space, color_space
22916        ),
22917        &format!("color({} 0.3 1 0.7 / 0.5)", color_space),
22918      );
22919      test(
22920        &format!(
22921          "color(from color({} 0.7 0.5 0.3) {} r r r / r)",
22922          color_space, color_space
22923        ),
22924        &format!("color({} 0.7 0.7 0.7 / 0.7)", color_space),
22925      );
22926      test(
22927        &format!(
22928          "color(from color({} 0.7 0.5 0.3) {} alpha alpha alpha / alpha)",
22929          color_space, color_space
22930        ),
22931        &format!("color({} 1 1 1)", color_space),
22932      );
22933      test(
22934        &format!(
22935          "color(from color({} 0.7 0.5 0.3 / 40%) {} g b r)",
22936          color_space, color_space
22937        ),
22938        &format!("color({} 0.5 0.3 0.7 / 0.4)", color_space),
22939      );
22940      test(
22941        &format!(
22942          "color(from color({} 0.7 0.5 0.3 / 40%) {} b alpha r / g)",
22943          color_space, color_space
22944        ),
22945        &format!("color({} 0.3 0.4 0.7 / 0.5)", color_space),
22946      );
22947      test(
22948        &format!(
22949          "color(from color({} 0.7 0.5 0.3 / 40%) {} r r r / r)",
22950          color_space, color_space
22951        ),
22952        &format!("color({} 0.7 0.7 0.7 / 0.7)", color_space),
22953      );
22954      test(
22955        &format!(
22956          "color(from color({} 0.7 0.5 0.3 / 40%) {} alpha alpha alpha / alpha)",
22957          color_space, color_space
22958        ),
22959        &format!("color({} 0.4 0.4 0.4 / 0.4)", color_space),
22960      );
22961
22962      // Testing out of gamut components.
22963      test(
22964        &format!("color(from color({} 1.7 1.5 1.3) {} r g b)", color_space, color_space),
22965        &format!("color({} 1.7 1.5 1.3)", color_space),
22966      );
22967      test(
22968        &format!(
22969          "color(from color({} 1.7 1.5 1.3) {} r g b / alpha)",
22970          color_space, color_space
22971        ),
22972        &format!("color({} 1.7 1.5 1.3)", color_space),
22973      );
22974      test(
22975        &format!(
22976          "color(from color({} 1.7 1.5 1.3 / 140%) {} r g b)",
22977          color_space, color_space
22978        ),
22979        &format!("color({} 1.7 1.5 1.3)", color_space),
22980      );
22981      test(
22982        &format!(
22983          "color(from color({} 1.7 1.5 1.3 / 140%) {} r g b / alpha)",
22984          color_space, color_space
22985        ),
22986        &format!("color({} 1.7 1.5 1.3)", color_space),
22987      );
22988      test(
22989        &format!(
22990          "color(from color({} -0.7 -0.5 -0.3) {} r g b)",
22991          color_space, color_space
22992        ),
22993        &format!("color({} -0.7 -0.5 -0.3)", color_space),
22994      );
22995      test(
22996        &format!(
22997          "color(from color({} -0.7 -0.5 -0.3) {} r g b / alpha)",
22998          color_space, color_space
22999        ),
23000        &format!("color({} -0.7 -0.5 -0.3)", color_space),
23001      );
23002      test(
23003        &format!(
23004          "color(from color({} -0.7 -0.5 -0.3 / -40%) {} r g b)",
23005          color_space, color_space
23006        ),
23007        &format!("color({} -0.7 -0.5 -0.3 / 0)", color_space),
23008      );
23009      test(
23010        &format!(
23011          "color(from color({} -0.7 -0.5 -0.3 / -40%) {} r g b / alpha)",
23012          color_space, color_space
23013        ),
23014        &format!("color({} -0.7 -0.5 -0.3 / 0)", color_space),
23015      );
23016
23017      // Testing with calc().
23018      test(
23019        &format!(
23020          "color(from color({} 0.7 0.5 0.3) {} calc(r) calc(g) calc(b))",
23021          color_space, color_space
23022        ),
23023        &format!("color({} 0.7 0.5 0.3)", color_space),
23024      );
23025      test(
23026        &format!(
23027          "color(from color({} 0.7 0.5 0.3 / 40%) {} calc(r) calc(g) calc(b) / calc(alpha))",
23028          color_space, color_space
23029        ),
23030        &format!("color({} 0.7 0.5 0.3 / 0.4)", color_space),
23031      );
23032
23033      // Testing with 'none'.
23034      test(
23035        &format!(
23036          "color(from color({} 0.7 0.5 0.3) {} none none none)",
23037          color_space, color_space
23038        ),
23039        &format!("color({} none none none)", color_space),
23040      );
23041      test(
23042        &format!(
23043          "color(from color({} 0.7 0.5 0.3) {} none none none / none)",
23044          color_space, color_space
23045        ),
23046        &format!("color({} none none none / none)", color_space),
23047      );
23048      test(
23049        &format!(
23050          "color(from color({} 0.7 0.5 0.3) {} r g none)",
23051          color_space, color_space
23052        ),
23053        &format!("color({} 0.7 0.5 none)", color_space),
23054      );
23055      test(
23056        &format!(
23057          "color(from color({} 0.7 0.5 0.3) {} r g none / alpha)",
23058          color_space, color_space
23059        ),
23060        &format!("color({} 0.7 0.5 none)", color_space),
23061      );
23062      test(
23063        &format!(
23064          "color(from color({} 0.7 0.5 0.3) {} r g b / none)",
23065          color_space, color_space
23066        ),
23067        &format!("color({} 0.7 0.5 0.3 / none)", color_space),
23068      );
23069      test(
23070        &format!(
23071          "color(from color({} 0.7 0.5 0.3 / 40%) {} r g none / alpha)",
23072          color_space, color_space
23073        ),
23074        &format!("color({} 0.7 0.5 none / 0.4)", color_space),
23075      );
23076      test(
23077        &format!(
23078          "color(from color({} 0.7 0.5 0.3 / 40%) {} r g b / none)",
23079          color_space, color_space
23080        ),
23081        &format!("color({} 0.7 0.5 0.3 / none)", color_space),
23082      );
23083      // FIXME: Clarify with spec editors if 'none' should pass through to the constants.
23084      test(
23085        &format!(
23086          "color(from color({} none none none) {} r g b)",
23087          color_space, color_space
23088        ),
23089        &format!("color({} 0 0 0)", color_space),
23090      );
23091      test(
23092        &format!(
23093          "color(from color({} none none none / none) {} r g b / alpha)",
23094          color_space, color_space
23095        ),
23096        &format!("color({} 0 0 0 / 0)", color_space),
23097      );
23098      test(
23099        &format!("color(from color({} 0.7 none 0.3) {} r g b)", color_space, color_space),
23100        &format!("color({} 0.7 0 0.3)", color_space),
23101      );
23102      test(
23103        &format!(
23104          "color(from color({} 0.7 0.5 0.3 / none) {} r g b / alpha)",
23105          color_space, color_space
23106        ),
23107        &format!("color({} 0.7 0.5 0.3 / 0)", color_space),
23108      );
23109    }
23110
23111    // test_valid_value\(`color`, `color\(from color\(\$\{colorSpace\}(.*?) \$\{colorSpace\}(.*?)`,\s*`color\(\$\{resultColorSpace\}(.*?)`\)
23112    // test(&format!("color(from color({}$1 {}$2", color_space, color_space), &format!("color({}$3", result_color_space))
23113
23114    for color_space in &["xyz", "xyz-d50", "xyz-d65"] {
23115      let result_color_space = if *color_space == "xyz" { "xyz-d65" } else { color_space };
23116
23117      // Testing no modifications.
23118      test(
23119        &format!("color(from color({} 7 -20.5 100) {} x y z)", color_space, color_space),
23120        &format!("color({} 7 -20.5 100)", result_color_space),
23121      );
23122      test(
23123        &format!(
23124          "color(from color({} 7 -20.5 100) {} x y z / alpha)",
23125          color_space, color_space
23126        ),
23127        &format!("color({} 7 -20.5 100)", result_color_space),
23128      );
23129      test(
23130        &format!(
23131          "color(from color({} 7 -20.5 100 / 40%) {} x y z)",
23132          color_space, color_space
23133        ),
23134        &format!("color({} 7 -20.5 100 / 0.4)", result_color_space),
23135      );
23136      test(
23137        &format!(
23138          "color(from color({} 7 -20.5 100 / 40%) {} x y z / alpha)",
23139          color_space, color_space
23140        ),
23141        &format!("color({} 7 -20.5 100 / 0.4)", result_color_space),
23142      );
23143
23144      // Test nesting relative colors.
23145      test(
23146        &format!(
23147          "color(from color(from color({} 7 -20.5 100) {} x y z) {} x y z)",
23148          color_space, color_space, color_space
23149        ),
23150        &format!("color({} 7 -20.5 100)", result_color_space),
23151      );
23152
23153      // Testing replacement with 0.
23154      test(
23155        &format!("color(from color({} 7 -20.5 100) {} 0 0 0)", color_space, color_space),
23156        &format!("color({} 0 0 0)", result_color_space),
23157      );
23158      test(
23159        &format!(
23160          "color(from color({} 7 -20.5 100) {} 0 0 0 / 0)",
23161          color_space, color_space
23162        ),
23163        &format!("color({} 0 0 0 / 0)", result_color_space),
23164      );
23165      test(
23166        &format!(
23167          "color(from color({} 7 -20.5 100) {} 0 y z / alpha)",
23168          color_space, color_space
23169        ),
23170        &format!("color({} 0 -20.5 100)", result_color_space),
23171      );
23172      test(
23173        &format!(
23174          "color(from color({} 7 -20.5 100) {} x 0 z / alpha)",
23175          color_space, color_space
23176        ),
23177        &format!("color({} 7 0 100)", result_color_space),
23178      );
23179      test(
23180        &format!(
23181          "color(from color({} 7 -20.5 100) {} x y 0 / alpha)",
23182          color_space, color_space
23183        ),
23184        &format!("color({} 7 -20.5 0)", result_color_space),
23185      );
23186      test(
23187        &format!(
23188          "color(from color({} 7 -20.5 100) {} x y z / 0)",
23189          color_space, color_space
23190        ),
23191        &format!("color({} 7 -20.5 100 / 0)", result_color_space),
23192      );
23193      test(
23194        &format!(
23195          "color(from color({} 7 -20.5 100 / 40%) {} 0 y z / alpha)",
23196          color_space, color_space
23197        ),
23198        &format!("color({} 0 -20.5 100 / 0.4)", result_color_space),
23199      );
23200      test(
23201        &format!(
23202          "color(from color({} 7 -20.5 100 / 40%) {} x 0 z / alpha)",
23203          color_space, color_space
23204        ),
23205        &format!("color({} 7 0 100 / 0.4)", result_color_space),
23206      );
23207      test(
23208        &format!(
23209          "color(from color({} 7 -20.5 100 / 40%) {} x y 0 / alpha)",
23210          color_space, color_space
23211        ),
23212        &format!("color({} 7 -20.5 0 / 0.4)", result_color_space),
23213      );
23214      test(
23215        &format!(
23216          "color(from color({} 7 -20.5 100 / 40%) {} x y z / 0)",
23217          color_space, color_space
23218        ),
23219        &format!("color({} 7 -20.5 100 / 0)", result_color_space),
23220      );
23221
23222      // Testing replacement with a constant.
23223      test(
23224        &format!(
23225          "color(from color({} 7 -20.5 100) {} 0.2 y z / alpha)",
23226          color_space, color_space
23227        ),
23228        &format!("color({} 0.2 -20.5 100)", result_color_space),
23229      );
23230      test(
23231        &format!(
23232          "color(from color({} 7 -20.5 100) {} x 0.2 z / alpha)",
23233          color_space, color_space
23234        ),
23235        &format!("color({} 7 0.2 100)", result_color_space),
23236      );
23237      test(
23238        &format!(
23239          "color(from color({} 7 -20.5 100) {} x y 0.2 / alpha)",
23240          color_space, color_space
23241        ),
23242        &format!("color({} 7 -20.5 0.2)", result_color_space),
23243      );
23244      test(
23245        &format!(
23246          "color(from color({} 7 -20.5 100) {} x y z / 0.2)",
23247          color_space, color_space
23248        ),
23249        &format!("color({} 7 -20.5 100 / 0.2)", result_color_space),
23250      );
23251      test(
23252        &format!(
23253          "color(from color({} 7 -20.5 100) {} x y z / 20%)",
23254          color_space, color_space
23255        ),
23256        &format!("color({} 7 -20.5 100 / 0.2)", result_color_space),
23257      );
23258      test(
23259        &format!(
23260          "color(from color({} 7 -20.5 100 / 40%) {} 0.2 y z / alpha)",
23261          color_space, color_space
23262        ),
23263        &format!("color({} 0.2 -20.5 100 / 0.4)", result_color_space),
23264      );
23265      test(
23266        &format!(
23267          "color(from color({} 7 -20.5 100 / 40%) {} x 0.2 z / alpha)",
23268          color_space, color_space
23269        ),
23270        &format!("color({} 7 0.2 100 / 0.4)", result_color_space),
23271      );
23272      test(
23273        &format!(
23274          "color(from color({} 7 -20.5 100 / 40%) {} x y 0.2 / alpha)",
23275          color_space, color_space
23276        ),
23277        &format!("color({} 7 -20.5 0.2 / 0.4)", result_color_space),
23278      );
23279      test(
23280        &format!(
23281          "color(from color({} 7 -20.5 100 / 40%) {} x y z / 0.2)",
23282          color_space, color_space
23283        ),
23284        &format!("color({} 7 -20.5 100 / 0.2)", result_color_space),
23285      );
23286
23287      // Testing valid permutation (types match).
23288      test(
23289        &format!("color(from color({} 7 -20.5 100) {} y z x)", color_space, color_space),
23290        &format!("color({} -20.5 100 7)", result_color_space),
23291      );
23292      test(
23293        &format!(
23294          "color(from color({} 7 -20.5 100) {} x x x / x)",
23295          color_space, color_space
23296        ),
23297        &format!("color({} 7 7 7)", result_color_space),
23298      );
23299      test(
23300        &format!(
23301          "color(from color({} 7 -20.5 100 / 40%) {} y z x)",
23302          color_space, color_space
23303        ),
23304        &format!("color({} -20.5 100 7 / 0.4)", result_color_space),
23305      );
23306      test(
23307        &format!(
23308          "color(from color({} 7 -20.5 100 / 40%) {} x x x / x)",
23309          color_space, color_space
23310        ),
23311        &format!("color({} 7 7 7)", result_color_space),
23312      );
23313
23314      // Testing with calc().
23315      test(
23316        &format!(
23317          "color(from color({} 7 -20.5 100) {} calc(x) calc(y) calc(z))",
23318          color_space, color_space
23319        ),
23320        &format!("color({} 7 -20.5 100)", result_color_space),
23321      );
23322      test(
23323        &format!(
23324          "color(from color({} 7 -20.5 100 / 40%) {} calc(x) calc(y) calc(z) / calc(alpha))",
23325          color_space, color_space
23326        ),
23327        &format!("color({} 7 -20.5 100 / 0.4)", result_color_space),
23328      );
23329
23330      // Testing with 'none'.
23331      test(
23332        &format!(
23333          "color(from color({} 7 -20.5 100) {} none none none)",
23334          color_space, color_space
23335        ),
23336        &format!("color({} none none none)", result_color_space),
23337      );
23338      test(
23339        &format!(
23340          "color(from color({} 7 -20.5 100) {} none none none / none)",
23341          color_space, color_space
23342        ),
23343        &format!("color({} none none none / none)", result_color_space),
23344      );
23345      test(
23346        &format!(
23347          "color(from color({} 7 -20.5 100) {} x y none)",
23348          color_space, color_space
23349        ),
23350        &format!("color({} 7 -20.5 none)", result_color_space),
23351      );
23352      test(
23353        &format!(
23354          "color(from color({} 7 -20.5 100) {} x y none / alpha)",
23355          color_space, color_space
23356        ),
23357        &format!("color({} 7 -20.5 none)", result_color_space),
23358      );
23359      test(
23360        &format!(
23361          "color(from color({} 7 -20.5 100) {} x y z / none)",
23362          color_space, color_space
23363        ),
23364        &format!("color({} 7 -20.5 100 / none)", result_color_space),
23365      );
23366      test(
23367        &format!(
23368          "color(from color({} 7 -20.5 100 / 40%) {} x y none / alpha)",
23369          color_space, color_space
23370        ),
23371        &format!("color({} 7 -20.5 none / 0.4)", result_color_space),
23372      );
23373      test(
23374        &format!(
23375          "color(from color({} 7 -20.5 100 / 40%) {} x y z / none)",
23376          color_space, color_space
23377        ),
23378        &format!("color({} 7 -20.5 100 / none)", result_color_space),
23379      );
23380      // FIXME: Clarify with spec editors if 'none' should pass through to the constants.
23381      test(
23382        &format!(
23383          "color(from color({} none none none) {} x y z)",
23384          color_space, color_space
23385        ),
23386        &format!("color({} 0 0 0)", result_color_space),
23387      );
23388      test(
23389        &format!(
23390          "color(from color({} none none none / none) {} x y z / alpha)",
23391          color_space, color_space
23392        ),
23393        &format!("color({} 0 0 0 / 0)", result_color_space),
23394      );
23395      test(
23396        &format!("color(from color({} 7 none 100) {} x y z)", color_space, color_space),
23397        &format!("color({} 7 0 100)", result_color_space),
23398      );
23399      test(
23400        &format!(
23401          "color(from color({} 7 -20.5 100 / none) {} x y z / alpha)",
23402          color_space, color_space
23403        ),
23404        &format!("color({} 7 -20.5 100 / 0)", result_color_space),
23405      );
23406
23407      // https://github.com/web-platform-tests/wpt/blob/master/css/css-color/parsing/relative-color-invalid.html
23408      minify_test(
23409        ".foo{color:rgb(from rebeccapurple r 10deg 10)}",
23410        ".foo{color:rgb(from rebeccapurple r 10deg 10)}",
23411      );
23412      minify_test(
23413        ".foo{color:rgb(from rebeccapurple l g b)}",
23414        ".foo{color:rgb(from rebeccapurple l g b)}",
23415      );
23416      minify_test(
23417        ".foo{color:hsl(from rebeccapurple s h l)}",
23418        ".foo{color:hsl(from rebeccapurple s h l)}",
23419      );
23420      minify_test(".foo{color:hsl(from rebeccapurple s s s / s)}", ".foo{color:#bfaa40}");
23421      minify_test(
23422        ".foo{color:hsl(from rebeccapurple calc(alpha * 100) calc(alpha * 100) calc(alpha * 100) / alpha)}",
23423        ".foo{color:#fff}",
23424      );
23425    }
23426  }
23427
23428  #[test]
23429  fn test_relative_alpha_color_fallbacks() {
23430    prefix_test(
23431      ".foo { color: alpha(from color(srgb 1 0 0) / 0.5) }",
23432      indoc! { r#"
23433        .foo {
23434          color: #ff000080;
23435          color: color(srgb 1 0 0 / .5);
23436        }
23437      "#},
23438      Browsers {
23439        chrome: Some(90 << 16),
23440        ..Browsers::default()
23441      },
23442    );
23443    prefix_test(
23444      ".foo { color: alpha(from color(display-p3 1 0 0) / 0.5) }",
23445      indoc! { r#"
23446        .foo {
23447          color: #ff0b0c80;
23448          color: color(display-p3 1 0 0 / .5);
23449        }
23450      "#},
23451      Browsers {
23452        chrome: Some(90 << 16),
23453        ..Browsers::default()
23454      },
23455    );
23456  }
23457
23458  #[test]
23459  fn test_color_mix() {
23460    minify_test(
23461      ".foo { color: color-mix(in lab, purple 50%, plum 50%); }",
23462      ".foo{color:lab(51.5117% 43.3777 -29.0443)}",
23463    );
23464    minify_test(
23465      ".foo { color: color-mix(in lch, peru 40%, palegoldenrod); }",
23466      ".foo{color:lch(79.7255% 40.4542 84.7634)}",
23467    );
23468    minify_test(
23469      ".foo { color: color-mix(in lch, teal 65%, olive); }",
23470      ".foo{color:lch(49.4431% 40.4806 162.546)}",
23471    );
23472    minify_test(
23473      ".foo { color: color-mix(in lch, white, black); }",
23474      ".foo{color:lch(50% 0 none)}",
23475    );
23476    minify_test(
23477      ".foo { color: color-mix(in xyz, rgb(82.02% 30.21% 35.02%) 75.23%, rgb(5.64% 55.94% 85.31%)); }",
23478      ".foo{color:color(xyz .287458 .208776 .260566)}",
23479    );
23480    minify_test(
23481      ".foo { color: color-mix(in lch, white, blue); }",
23482      ".foo{color:lch(64.7842% 65.6007 301.364)}",
23483    );
23484    minify_test(
23485      ".foo { color: color-mix(in oklch, white, blue); }",
23486      ".foo{color:oklch(72.6007% .156607 264.052)}",
23487    );
23488    minify_test(
23489      ".foo { color: color-mix(in srgb, white, blue); }",
23490      ".foo{color:#8080ff}",
23491    );
23492    minify_test(
23493      ".foo { color: color-mix(in lch, blue, white); }",
23494      ".foo{color:lch(64.7842% 65.6007 301.364)}",
23495    );
23496    minify_test(
23497      ".foo { color: color-mix(in oklch, blue, white); }",
23498      ".foo{color:oklch(72.6007% .156607 264.052)}",
23499    );
23500    minify_test(
23501      ".foo { color: color-mix(in srgb, blue, white); }",
23502      ".foo{color:#8080ff}",
23503    );
23504    // minify_test(".foo { color: color-mix(in hsl, color(display-p3 0 1 0) 80%, yellow); }", ".foo{color:hsl(108 100% 49.9184%) }");
23505    minify_test(
23506      ".foo { color: color-mix(in hsl, hsl(120 100% 49.898%) 80%, yellow); }",
23507      ".foo{color:#33fe00}",
23508    );
23509    minify_test(
23510      ".foo { color: color-mix(in srgb, rgb(100% 0% 0% / 0.7) 25%, rgb(0% 100% 0% / 0.2)); }",
23511      ".foo{color:#89760053}",
23512    );
23513    minify_test(
23514      ".foo { color: color-mix(in srgb, rgb(100% 0% 0% / 0.7) 20%, rgb(0% 100% 0% / 0.2) 60%); }",
23515      ".foo{color:#89760042}",
23516    );
23517    minify_test(
23518      ".foo { color: color-mix(in lch, color(display-p3 0 1 none), color(display-p3 0 0 1)); }",
23519      ".foo{color:lch(58.8143% 141.732 218.684)}",
23520    );
23521    minify_test(
23522      ".foo { color: color-mix(in srgb, rgb(128 128 none), rgb(none none 128)); }",
23523      ".foo{color:gray}",
23524    );
23525    minify_test(
23526      ".foo { color: color-mix(in srgb, rgb(50% 50% none), rgb(none none 50%)); }",
23527      ".foo{color:gray}",
23528    );
23529    minify_test(
23530      ".foo { color: color-mix(in srgb, rgb(none 50% none), rgb(50% none 50%)); }",
23531      ".foo{color:gray}",
23532    );
23533    minify_test(
23534      ".foo { --color: color-mix(in lch, teal 65%, olive); }",
23535      ".foo{--color:lch(49.4431% 40.4806 162.546)}",
23536    );
23537    minify_test(
23538      ".foo { color: color-mix(in xyz, transparent, green 65%); }",
23539      ".foo{color:color(xyz .0771883 .154377 .0257295/.65)}",
23540    );
23541    prefix_test(
23542      ".foo { color: color-mix(in xyz, transparent, green 65%); }",
23543      indoc! { r#"
23544      .foo {
23545        color: #008000a6;
23546        color: color(xyz .0771883 .154377 .0257295 / .65);
23547      }
23548      "# },
23549      Browsers {
23550        chrome: Some(95 << 16),
23551        ..Default::default()
23552      },
23553    );
23554    minify_test(
23555      ".foo { color: color-mix(in srgb, currentColor, blue); }",
23556      ".foo{color:color-mix(in srgb, currentColor, blue)}",
23557    );
23558    minify_test(
23559      ".foo { color: color-mix(in srgb, blue, currentColor); }",
23560      ".foo{color:color-mix(in srgb, blue, currentColor)}",
23561    );
23562    minify_test(
23563      ".foo { color: color-mix(in srgb, accentcolor, blue); }",
23564      ".foo{color:color-mix(in srgb, accentcolor, blue)}",
23565    );
23566    minify_test(
23567      ".foo { color: color-mix(in srgb, blue, accentcolor); }",
23568      ".foo{color:color-mix(in srgb, blue, accentcolor)}",
23569    );
23570
23571    // regex for converting web platform tests:
23572    // test_computed_value\(.*?, `(.*?)`, `(.*?)`\);
23573    // minify_test(".foo { color: $1 }", ".foo{color:$2}");
23574
23575    // https://github.com/web-platform-tests/wpt/blob/f8c76b11cff66a7adc87264a18e39353cb5a60c9/css/css-color/parsing/color-mix-computed.html
23576    minify_test(
23577      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20%), hsl(30deg 30% 40%)) }",
23578      ".foo{color:#545c3d}",
23579    );
23580    minify_test(
23581      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20%) 25%, hsl(30deg 30% 40%)) }",
23582      ".foo{color:#706a43}",
23583    );
23584    minify_test(
23585      ".foo { color: color-mix(in hsl, 25% hsl(120deg 10% 20%), hsl(30deg 30% 40%)) }",
23586      ".foo{color:#706a43}",
23587    );
23588    minify_test(
23589      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20%), 25% hsl(30deg 30% 40%)) }",
23590      ".foo{color:#3d4936}",
23591    );
23592    minify_test(
23593      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20%), hsl(30deg 30% 40%) 25%) }",
23594      ".foo{color:#3d4936}",
23595    );
23596    minify_test(
23597      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20%) 25%, hsl(30deg 30% 40%) 75%) }",
23598      ".foo{color:#706a43}",
23599    );
23600    minify_test(
23601      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20%) 30%, hsl(30deg 30% 40%) 90%) }",
23602      ".foo{color:#706a43}",
23603    ); // Scale down > 100% sum.
23604    minify_test(
23605      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20%) 12.5%, hsl(30deg 30% 40%) 37.5%) }",
23606      ".foo{color:#706a4380}",
23607    ); // Scale up < 100% sum, causes alpha multiplication.
23608    minify_test(
23609      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20%) 0%, hsl(30deg 30% 40%)) }",
23610      ".foo{color:#856647}",
23611    );
23612
23613    minify_test(
23614      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20% / .4), hsl(30deg 30% 40% / .8)) }",
23615      ".foo{color:#5f694199}",
23616    );
23617    minify_test(
23618      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20%) 25%, hsl(30deg 30% 40% / .8)) }",
23619      ".foo{color:#6c6742d9}",
23620    );
23621    minify_test(
23622      ".foo { color: color-mix(in hsl, 25% hsl(120deg 10% 20% / .4), hsl(30deg 30% 40% / .8)) }",
23623      ".foo{color:#797245b3}",
23624    );
23625    minify_test(
23626      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20% / .4), 25% hsl(30deg 30% 40% / .8)) }",
23627      ".foo{color:#44543b80}",
23628    );
23629    minify_test(
23630      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20% / .4), hsl(30deg 30% 40% / .8) 25%) }",
23631      ".foo{color:#44543b80}",
23632    );
23633    minify_test(
23634      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20% / .4) 25%, hsl(30deg 30% 40% / .8) 75%) }",
23635      ".foo{color:#797245b3}",
23636    );
23637    minify_test(
23638      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20% / .4) 30%, hsl(30deg 30% 40% / .8) 90%) }",
23639      ".foo{color:#797245b3}",
23640    ); // Scale down > 100% sum.
23641    minify_test(
23642      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20% / .4) 12.5%, hsl(30deg 30% 40% / .8) 37.5%) }",
23643      ".foo{color:#79724559}",
23644    ); // Scale up < 100% sum, causes alpha multiplication.
23645    minify_test(
23646      ".foo { color: color-mix(in hsl, hsl(120deg 10% 20% / .4) 0%, hsl(30deg 30% 40% / .8)) }",
23647      ".foo{color:#856647cc}",
23648    );
23649
23650    fn canonicalize(s: &str) -> String {
23651      use crate::traits::{Parse, ToCss};
23652      use crate::values::color::CssColor;
23653      use cssparser::{Parser, ParserInput};
23654
23655      let mut input = ParserInput::new(s);
23656      let mut parser = Parser::new(&mut input);
23657      let v = CssColor::parse(&mut parser).unwrap().to_rgb().unwrap();
23658      format!(".foo{{color:{}}}", v.to_css_string(PrinterOptions::default()).unwrap())
23659    }
23660
23661    // regex for converting web platform tests:
23662    // test_computed_value\(.*?, `(.*?)`, canonicalize\(`(.*?)`\)\);
23663    // minify_test(".foo { color: $1 }", &canonicalize("$2"));
23664
23665    minify_test(
23666      ".foo { color: color-mix(in hsl, hsl(40deg 50% 50%), hsl(60deg 50% 50%)) }",
23667      &canonicalize("hsl(50deg 50% 50%)"),
23668    );
23669    minify_test(
23670      ".foo { color: color-mix(in hsl, hsl(60deg 50% 50%), hsl(40deg 50% 50%)) }",
23671      &canonicalize("hsl(50deg 50% 50%)"),
23672    );
23673    minify_test(
23674      ".foo { color: color-mix(in hsl, hsl(50deg 50% 50%), hsl(330deg 50% 50%)) }",
23675      &canonicalize("hsl(10deg 50% 50%)"),
23676    );
23677    minify_test(
23678      ".foo { color: color-mix(in hsl, hsl(330deg 50% 50%), hsl(50deg 50% 50%)) }",
23679      &canonicalize("hsl(10deg 50% 50%)"),
23680    );
23681    minify_test(
23682      ".foo { color: color-mix(in hsl, hsl(20deg 50% 50%), hsl(320deg 50% 50%)) }",
23683      &canonicalize("hsl(350deg 50% 50%)"),
23684    );
23685    minify_test(
23686      ".foo { color: color-mix(in hsl, hsl(320deg 50% 50%), hsl(20deg 50% 50%)) }",
23687      &canonicalize("hsl(350deg 50% 50%)"),
23688    );
23689
23690    minify_test(
23691      ".foo { color: color-mix(in hsl shorter hue, hsl(40deg 50% 50%), hsl(60deg 50% 50%)) }",
23692      &canonicalize("hsl(50deg 50% 50%)"),
23693    );
23694    minify_test(
23695      ".foo { color: color-mix(in hsl shorter hue, hsl(60deg 50% 50%), hsl(40deg 50% 50%)) }",
23696      &canonicalize("hsl(50deg 50% 50%)"),
23697    );
23698    minify_test(
23699      ".foo { color: color-mix(in hsl shorter hue, hsl(50deg 50% 50%), hsl(330deg 50% 50%)) }",
23700      &canonicalize("hsl(10deg 50% 50%)"),
23701    );
23702    minify_test(
23703      ".foo { color: color-mix(in hsl shorter hue, hsl(330deg 50% 50%), hsl(50deg 50% 50%)) }",
23704      &canonicalize("hsl(10deg 50% 50%)"),
23705    );
23706    minify_test(
23707      ".foo { color: color-mix(in hsl shorter hue, hsl(20deg 50% 50%), hsl(320deg 50% 50%)) }",
23708      &canonicalize("hsl(350deg 50% 50%)"),
23709    );
23710    minify_test(
23711      ".foo { color: color-mix(in hsl shorter hue, hsl(320deg 50% 50%), hsl(20deg 50% 50%)) }",
23712      &canonicalize("hsl(350deg 50% 50%)"),
23713    );
23714
23715    minify_test(
23716      ".foo { color: color-mix(in hsl longer hue, hsl(40deg 50% 50%), hsl(60deg 50% 50%)) }",
23717      &canonicalize("hsl(230deg 50% 50%)"),
23718    );
23719    minify_test(
23720      ".foo { color: color-mix(in hsl longer hue, hsl(60deg 50% 50%), hsl(40deg 50% 50%)) }",
23721      &canonicalize("hsl(230deg 50% 50%)"),
23722    );
23723    minify_test(
23724      ".foo { color: color-mix(in hsl longer hue, hsl(50deg 50% 50%), hsl(330deg 50% 50%)) }",
23725      &canonicalize("hsl(190deg 50% 50%)"),
23726    );
23727    minify_test(
23728      ".foo { color: color-mix(in hsl longer hue, hsl(330deg 50% 50%), hsl(50deg 50% 50%)) }",
23729      &canonicalize("hsl(190deg 50% 50%)"),
23730    );
23731    // minify_test(".foo { color: color-mix(in hsl longer hue, hsl(20deg 50% 50%), hsl(320deg 50% 50%)) }", &canonicalize("hsl(170deg 50% 50%)"));
23732    // minify_test(".foo { color: color-mix(in hsl longer hue, hsl(320deg 50% 50%), hsl(20deg 50% 50%)) }", &canonicalize("hsl(170deg 50% 50%)"));
23733
23734    minify_test(
23735      ".foo { color: color-mix(in hsl increasing hue, hsl(40deg 50% 50%), hsl(60deg 50% 50%)) }",
23736      &canonicalize("hsl(50deg 50% 50%)"),
23737    );
23738    minify_test(
23739      ".foo { color: color-mix(in hsl increasing hue, hsl(60deg 50% 50%), hsl(40deg 50% 50%)) }",
23740      &canonicalize("hsl(230deg 50% 50%)"),
23741    );
23742    minify_test(
23743      ".foo { color: color-mix(in hsl increasing hue, hsl(50deg 50% 50%), hsl(330deg 50% 50%)) }",
23744      &canonicalize("hsl(190deg 50% 50%)"),
23745    );
23746    minify_test(
23747      ".foo { color: color-mix(in hsl increasing hue, hsl(330deg 50% 50%), hsl(50deg 50% 50%)) }",
23748      &canonicalize("hsl(10deg 50% 50%)"),
23749    );
23750    // minify_test(".foo { color: color-mix(in hsl increasing hue, hsl(20deg 50% 50%), hsl(320deg 50% 50%)) }", &canonicalize("hsl(170deg 50% 50%)"));
23751    // minify_test(".foo { color: color-mix(in hsl increasing hue, hsl(320deg 50% 50%), hsl(20deg 50% 50%)) }", &canonicalize("hsl(350deg 50% 50%)"));
23752
23753    minify_test(
23754      ".foo { color: color-mix(in hsl decreasing hue, hsl(40deg 50% 50%), hsl(60deg 50% 50%)) }",
23755      &canonicalize("hsl(230deg 50% 50%)"),
23756    );
23757    minify_test(
23758      ".foo { color: color-mix(in hsl decreasing hue, hsl(60deg 50% 50%), hsl(40deg 50% 50%)) }",
23759      &canonicalize("hsl(50deg 50% 50%)"),
23760    );
23761    minify_test(
23762      ".foo { color: color-mix(in hsl decreasing hue, hsl(50deg 50% 50%), hsl(330deg 50% 50%)) }",
23763      &canonicalize("hsl(10deg 50% 50%)"),
23764    );
23765    minify_test(
23766      ".foo { color: color-mix(in hsl decreasing hue, hsl(330deg 50% 50%), hsl(50deg 50% 50%)) }",
23767      &canonicalize("hsl(190deg 50% 50%)"),
23768    );
23769    minify_test(
23770      ".foo { color: color-mix(in hsl decreasing hue, hsl(20deg 50% 50%), hsl(320deg 50% 50%)) }",
23771      &canonicalize("hsl(350deg 50% 50%)"),
23772    );
23773    // minify_test(".foo { color: color-mix(in hsl decreasing hue, hsl(320deg 50% 50%), hsl(20deg 50% 50%)) }", &canonicalize("hsl(170deg 50% 50%)"));
23774
23775    minify_test(
23776      ".foo { color: color-mix(in hsl specified hue, hsl(40deg 50% 50%), hsl(60deg 50% 50%)) }",
23777      &canonicalize("hsl(50deg 50% 50%)"),
23778    );
23779    minify_test(
23780      ".foo { color: color-mix(in hsl specified 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 specified hue, hsl(50deg 50% 50%), hsl(330deg 50% 50%)) }",
23785      &canonicalize("hsl(190deg 50% 50%)"),
23786    );
23787    minify_test(
23788      ".foo { color: color-mix(in hsl specified hue, hsl(330deg 50% 50%), hsl(50deg 50% 50%)) }",
23789      &canonicalize("hsl(190deg 50% 50%)"),
23790    );
23791    // minify_test(".foo { color: color-mix(in hsl specified hue, hsl(20deg 50% 50%), hsl(320deg 50% 50%)) }", &canonicalize("hsl(170deg 50% 50%)"));
23792    // minify_test(".foo { color: color-mix(in hsl specified hue, hsl(320deg 50% 50%), hsl(20deg 50% 50%)) }", &canonicalize("hsl(170deg 50% 50%)"));
23793
23794    minify_test(
23795      ".foo { color: color-mix(in hsl, hsl(none none none), hsl(none none none)) }",
23796      &canonicalize("hsl(none none none)"),
23797    );
23798    minify_test(
23799      ".foo { color: color-mix(in hsl, hsl(none none none), hsl(30deg 40% 80%)) }",
23800      &canonicalize("hsl(30deg 40% 80%)"),
23801    );
23802    minify_test(
23803      ".foo { color: color-mix(in hsl, hsl(120deg 20% 40%), hsl(none none none)) }",
23804      &canonicalize("hsl(120deg 20% 40%)"),
23805    );
23806    minify_test(
23807      ".foo { color: color-mix(in hsl, hsl(120deg 20% none), hsl(30deg 40% 60%)) }",
23808      &canonicalize("hsl(75deg 30% 60%)"),
23809    );
23810    minify_test(
23811      ".foo { color: color-mix(in hsl, hsl(120deg 20% 40%), hsl(30deg 20% none)) }",
23812      &canonicalize("hsl(75deg 20% 40%)"),
23813    );
23814    minify_test(
23815      ".foo { color: color-mix(in hsl, hsl(none 20% 40%), hsl(30deg none 80%)) }",
23816      &canonicalize("hsl(30deg 20% 60%)"),
23817    );
23818
23819    minify_test(
23820      ".foo { color: color-mix(in hsl, color(display-p3 0 1 0) 100%, rgb(0, 0, 0) 0%) }",
23821      &canonicalize("rgb(0, 251, 41)"),
23822    ); // Naive clip based mapping would give rgb(0, 255, 0).
23823    minify_test(
23824      ".foo { color: color-mix(in hsl, lab(100% 104.3 -50.9) 100%, rgb(0, 0, 0) 0%) }",
23825      &canonicalize("rgb(255, 255, 255)"),
23826    ); // Naive clip based mapping would give rgb(255, 150, 255).
23827    minify_test(
23828      ".foo { color: color-mix(in hsl, lab(0% 104.3 -50.9) 100%, rgb(0, 0, 0) 0%) }",
23829      &canonicalize("rgb(42, 0, 34)"),
23830    ); // Naive clip based mapping would give rgb(90, 0, 76). NOTE: 0% lightness in Lab/LCH does not automatically correspond with sRGB black,
23831    minify_test(
23832      ".foo { color: color-mix(in hsl, lch(100% 116 334) 100%, rgb(0, 0, 0) 0%) }",
23833      &canonicalize("rgb(255, 255, 255)"),
23834    ); // Naive clip based mapping would give rgb(255, 150, 255).
23835    minify_test(
23836      ".foo { color: color-mix(in hsl, lch(0% 116 334) 100%, rgb(0, 0, 0) 0%) }",
23837      &canonicalize("rgb(42, 0, 34)"),
23838    ); // Naive clip based mapping would give rgb(90, 0, 76). NOTE: 0% lightness in Lab/LCH does not automatically correspond with sRGB black,
23839    minify_test(
23840      ".foo { color: color-mix(in hsl, oklab(100% 0.365 -0.16) 100%, rgb(0, 0, 0) 0%) }",
23841      &canonicalize("rgb(255, 255, 255)"),
23842    ); // Naive clip based mapping would give rgb(255, 92, 255).
23843    minify_test(
23844      ".foo { color: color-mix(in hsl, oklab(0% 0.365 -0.16) 100%, rgb(0, 0, 0) 0%) }",
23845      &canonicalize("rgb(0, 0, 0)"),
23846    ); // Naive clip based mapping would give rgb(19, 0, 24).
23847    minify_test(
23848      ".foo { color: color-mix(in hsl, oklch(100% 0.399 336.3) 100%, rgb(0, 0, 0) 0%) }",
23849      &canonicalize("rgb(255, 255, 255)"),
23850    ); // Naive clip based mapping would give rgb(255, 91, 255).
23851    minify_test(
23852      ".foo { color: color-mix(in hsl, oklch(0% 0.399 336.3) 100%, rgb(0, 0, 0) 0%) }",
23853      &canonicalize("rgb(0, 0, 0)"),
23854    ); // Naive clip based mapping would give rgb(20, 0, 24).
23855
23856    minify_test(
23857      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20%), hwb(30deg 30% 40%)) }",
23858      &canonicalize("rgb(147, 179, 52)"),
23859    );
23860    minify_test(
23861      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20%) 25%, hwb(30deg 30% 40%)) }",
23862      &canonicalize("rgb(166, 153, 64)"),
23863    );
23864    minify_test(
23865      ".foo { color: color-mix(in hwb, 25% hwb(120deg 10% 20%), hwb(30deg 30% 40%)) }",
23866      &canonicalize("rgb(166, 153, 64)"),
23867    );
23868    minify_test(
23869      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20%), 25% hwb(30deg 30% 40%)) }",
23870      &canonicalize("rgb(96, 191, 39)"),
23871    );
23872    minify_test(
23873      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20%), hwb(30deg 30% 40%) 25%) }",
23874      &canonicalize("rgb(96, 191, 39)"),
23875    );
23876    minify_test(
23877      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20%) 25%, hwb(30deg 30% 40%) 75%) }",
23878      &canonicalize("rgb(166, 153, 64)"),
23879    );
23880    minify_test(
23881      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20%) 30%, hwb(30deg 30% 40%) 90%) }",
23882      &canonicalize("rgb(166, 153, 64)"),
23883    ); // Scale down > 100% sum.
23884    minify_test(
23885      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20%) 12.5%, hwb(30deg 30% 40%) 37.5%) }",
23886      &canonicalize("rgba(166, 153, 64, 0.5)"),
23887    ); // Scale up < 100% sum, causes alpha multiplication.
23888    minify_test(
23889      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20%) 0%, hwb(30deg 30% 40%)) }",
23890      &canonicalize("rgb(153, 115, 77)"),
23891    );
23892
23893    minify_test(
23894      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20% / .4), hwb(30deg 30% 40% / .8)) }",
23895      &canonicalize("rgba(143, 170, 60, 0.6)"),
23896    );
23897    minify_test(
23898      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20% / .4) 25%, hwb(30deg 30% 40% / .8)) }",
23899      &canonicalize("rgba(160, 149, 70, 0.7)"),
23900    );
23901    minify_test(
23902      ".foo { color: color-mix(in hwb, 25% hwb(120deg 10% 20% / .4), hwb(30deg 30% 40% / .8)) }",
23903      &canonicalize("rgba(160, 149, 70, 0.7)"),
23904    );
23905    minify_test(
23906      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20%), 25% hwb(30deg 30% 40% / .8)) }",
23907      &canonicalize("rgba(95, 193, 37, 0.95)"),
23908    );
23909    minify_test(
23910      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20% / .4), hwb(30deg 30% 40% / .8) 25%) }",
23911      &canonicalize("rgba(98, 184, 46, 0.5)"),
23912    );
23913    minify_test(
23914      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20% / .4) 25%, hwb(30deg 30% 40% / .8) 75%) }",
23915      &canonicalize("rgba(160, 149, 70, 0.7)"),
23916    );
23917    minify_test(
23918      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20% / .4) 30%, hwb(30deg 30% 40% / .8) 90%) }",
23919      &canonicalize("rgba(160, 149, 70, 0.7)"),
23920    ); // Scale down > 100% sum.
23921    minify_test(
23922      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20% / .4) 12.5%, hwb(30deg 30% 40% / .8) 37.5%) }",
23923      &canonicalize("rgba(160, 149, 70, 0.35)"),
23924    ); // Scale up < 100% sum, causes alpha multiplication.
23925    minify_test(
23926      ".foo { color: color-mix(in hwb, hwb(120deg 10% 20% / .4) 0%, hwb(30deg 30% 40% / .8)) }",
23927      &canonicalize("rgba(153, 115, 77, 0.8)"),
23928    );
23929
23930    //  minify_test(".foo { color: color-mix(in hwb, hwb(40deg 30% 40%), hwb(60deg 30% 40%)) }", &canonicalize("hwb(50deg 30% 40%)"));
23931    //  minify_test(".foo { color: color-mix(in hwb, hwb(60deg 30% 40%), hwb(40deg 30% 40%)) }", &canonicalize("hwb(50deg 30% 40%)"));
23932    minify_test(
23933      ".foo { color: color-mix(in hwb, hwb(50deg 30% 40%), hwb(330deg 30% 40%)) }",
23934      &canonicalize("hwb(10deg 30% 40%)"),
23935    );
23936    minify_test(
23937      ".foo { color: color-mix(in hwb, hwb(330deg 30% 40%), hwb(50deg 30% 40%)) }",
23938      &canonicalize("hwb(10deg 30% 40%)"),
23939    );
23940    minify_test(
23941      ".foo { color: color-mix(in hwb, hwb(20deg 30% 40%), hwb(320deg 30% 40%)) }",
23942      &canonicalize("hwb(350deg 30% 40%)"),
23943    );
23944    minify_test(
23945      ".foo { color: color-mix(in hwb, hwb(320deg 30% 40%), hwb(20deg 30% 40%)) }",
23946      &canonicalize("hwb(350deg 30% 40%)"),
23947    );
23948
23949    //  minify_test(".foo { color: color-mix(in hwb shorter hue, hwb(40deg 30% 40%), hwb(60deg 30% 40%)) }", &canonicalize("hwb(50deg 30% 40%)"));
23950    //  minify_test(".foo { color: color-mix(in hwb shorter hue, hwb(60deg 30% 40%), hwb(40deg 30% 40%)) }", &canonicalize("hwb(50deg 30% 40%)"));
23951    minify_test(
23952      ".foo { color: color-mix(in hwb shorter hue, hwb(50deg 30% 40%), hwb(330deg 30% 40%)) }",
23953      &canonicalize("hwb(10deg 30% 40%)"),
23954    );
23955    minify_test(
23956      ".foo { color: color-mix(in hwb shorter hue, hwb(330deg 30% 40%), hwb(50deg 30% 40%)) }",
23957      &canonicalize("hwb(10deg 30% 40%)"),
23958    );
23959    minify_test(
23960      ".foo { color: color-mix(in hwb shorter hue, hwb(20deg 30% 40%), hwb(320deg 30% 40%)) }",
23961      &canonicalize("hwb(350deg 30% 40%)"),
23962    );
23963    minify_test(
23964      ".foo { color: color-mix(in hwb shorter hue, hwb(320deg 30% 40%), hwb(20deg 30% 40%)) }",
23965      &canonicalize("hwb(350deg 30% 40%)"),
23966    );
23967
23968    minify_test(
23969      ".foo { color: color-mix(in hwb longer hue, hwb(40deg 30% 40%), hwb(60deg 30% 40%)) }",
23970      &canonicalize("hwb(230deg 30% 40%)"),
23971    );
23972    minify_test(
23973      ".foo { color: color-mix(in hwb longer hue, hwb(60deg 30% 40%), hwb(40deg 30% 40%)) }",
23974      &canonicalize("hwb(230deg 30% 40%)"),
23975    );
23976    //  minify_test(".foo { color: color-mix(in hwb longer hue, hwb(50deg 30% 40%), hwb(330deg 30% 40%)) }", &canonicalize("hwb(190deg 30% 40%)"));
23977    //  minify_test(".foo { color: color-mix(in hwb longer hue, hwb(330deg 30% 40%), hwb(50deg 30% 40%)) }", &canonicalize("hwb(190deg 30% 40%)"));
23978    //  minify_test(".foo { color: color-mix(in hwb longer hue, hwb(20deg 30% 40%), hwb(320deg 30% 40%)) }", &canonicalize("hwb(170deg 30% 40%)"));
23979    //  minify_test(".foo { color: color-mix(in hwb longer hue, hwb(320deg 30% 40%), hwb(20deg 30% 40%)) }", &canonicalize("hwb(170deg 30% 40%)"));
23980
23981    // minify_test(".foo { color: color-mix(in hwb increasing hue, hwb(40deg 30% 40%), hwb(60deg 30% 40%)) }", &canonicalize("hwb(50deg 30% 40%)"));
23982    minify_test(
23983      ".foo { color: color-mix(in hwb increasing hue, hwb(60deg 30% 40%), hwb(40deg 30% 40%)) }",
23984      &canonicalize("hwb(230deg 30% 40%)"),
23985    );
23986    // minify_test(".foo { color: color-mix(in hwb increasing hue, hwb(50deg 30% 40%), hwb(330deg 30% 40%)) }", &canonicalize("hwb(190deg 30% 40%)"));
23987    minify_test(
23988      ".foo { color: color-mix(in hwb increasing hue, hwb(330deg 30% 40%), hwb(50deg 30% 40%)) }",
23989      &canonicalize("hwb(10deg 30% 40%)"),
23990    );
23991    // minify_test(".foo { color: color-mix(in hwb increasing hue, hwb(20deg 30% 40%), hwb(320deg 30% 40%)) }", &canonicalize("hwb(170deg 30% 40%)"));
23992    minify_test(
23993      ".foo { color: color-mix(in hwb increasing hue, hwb(320deg 30% 40%), hwb(20deg 30% 40%)) }",
23994      &canonicalize("hwb(350deg 30% 40%)"),
23995    );
23996
23997    minify_test(
23998      ".foo { color: color-mix(in hwb decreasing hue, hwb(40deg 30% 40%), hwb(60deg 30% 40%)) }",
23999      &canonicalize("hwb(230deg 30% 40%)"),
24000    );
24001    // minify_test(".foo { color: color-mix(in hwb decreasing hue, hwb(60deg 30% 40%), hwb(40deg 30% 40%)) }", &canonicalize("hwb(50deg 30% 40%)"));
24002    minify_test(
24003      ".foo { color: color-mix(in hwb decreasing hue, hwb(50deg 30% 40%), hwb(330deg 30% 40%)) }",
24004      &canonicalize("hwb(10deg 30% 40%)"),
24005    );
24006    // minify_test(".foo { color: color-mix(in hwb decreasing hue, hwb(330deg 30% 40%), hwb(50deg 30% 40%)) }", &canonicalize("hwb(190deg 30% 40%)"));
24007    minify_test(
24008      ".foo { color: color-mix(in hwb decreasing hue, hwb(20deg 30% 40%), hwb(320deg 30% 40%)) }",
24009      &canonicalize("hwb(350deg 30% 40%)"),
24010    );
24011    // minify_test(".foo { color: color-mix(in hwb decreasing hue, hwb(320deg 30% 40%), hwb(20deg 30% 40%)) }", &canonicalize("hwb(170deg 30% 40%)"));
24012
24013    // minify_test(".foo { color: color-mix(in hwb specified hue, hwb(40deg 30% 40%), hwb(60deg 30% 40%)) }", &canonicalize("hwb(50deg 30% 40%)"));
24014    // minify_test(".foo { color: color-mix(in hwb specified hue, hwb(60deg 30% 40%), hwb(40deg 30% 40%)) }", &canonicalize("hwb(50deg 30% 40%)"));
24015    // minify_test(".foo { color: color-mix(in hwb specified hue, hwb(50deg 30% 40%), hwb(330deg 30% 40%)) }", &canonicalize("hwb(190deg 30% 40%)"));
24016    // minify_test(".foo { color: color-mix(in hwb specified hue, hwb(330deg 30% 40%), hwb(50deg 30% 40%)) }", &canonicalize("hwb(190deg 30% 40%)"));
24017    // minify_test(".foo { color: color-mix(in hwb specified hue, hwb(20deg 30% 40%), hwb(320deg 30% 40%)) }", &canonicalize("hwb(170deg 30% 40%)"));
24018    // minify_test(".foo { color: color-mix(in hwb specified hue, hwb(320deg 30% 40%), hwb(20deg 30% 40%)) }", &canonicalize("hwb(170deg 30% 40%)"));
24019
24020    minify_test(
24021      ".foo { color: color-mix(in hwb, color(display-p3 0 1 0) 100%, rgb(0, 0, 0) 0%) }",
24022      &canonicalize("rgb(0, 251, 41)"),
24023    ); // Naive clip based mapping would give rgb(0, 255, 0).
24024    minify_test(
24025      ".foo { color: color-mix(in hwb, lab(100% 104.3 -50.9) 100%, rgb(0, 0, 0) 0%) }",
24026      &canonicalize("rgb(255, 255, 255)"),
24027    ); // Naive clip based mapping would give rgb(255, 150, 255).
24028    minify_test(
24029      ".foo { color: color-mix(in hwb, lab(0% 104.3 -50.9) 100%, rgb(0, 0, 0) 0%) }",
24030      &canonicalize("rgb(42, 0, 34)"),
24031    ); // Naive clip based mapping would give rgb(90, 0, 76). NOTE: 0% lightness in Lab/LCH does not automatically correspond with sRGB black,
24032    minify_test(
24033      ".foo { color: color-mix(in hwb, lch(100% 116 334) 100%, rgb(0, 0, 0) 0%) }",
24034      &canonicalize("rgb(255, 255, 255)"),
24035    ); // Naive clip based mapping would give rgb(255, 150, 255).
24036    minify_test(
24037      ".foo { color: color-mix(in hwb, lch(0% 116 334) 100%, rgb(0, 0, 0) 0%) }",
24038      &canonicalize("rgb(42, 0, 34)"),
24039    ); // Naive clip based mapping would give rgb(90, 0, 76). NOTE: 0% lightness in Lab/LCH does not automatically correspond with sRGB black,
24040    minify_test(
24041      ".foo { color: color-mix(in hwb, oklab(100% 0.365 -0.16) 100%, rgb(0, 0, 0) 0%) }",
24042      &canonicalize("rgb(255, 255, 255)"),
24043    ); // Naive clip based mapping would give rgb(255, 92, 255).
24044    minify_test(
24045      ".foo { color: color-mix(in hwb, oklab(0% 0.365 -0.16) 100%, rgb(0, 0, 0) 0%) }",
24046      &canonicalize("rgb(0, 0, 0)"),
24047    ); // Naive clip based mapping would give rgb(19, 0, 24).
24048    minify_test(
24049      ".foo { color: color-mix(in hwb, oklch(100% 0.399 336.3) 100%, rgb(0, 0, 0) 0%) }",
24050      &canonicalize("rgb(255, 255, 255)"),
24051    ); // Naive clip based mapping would give rgb(255, 91, 255).
24052    minify_test(
24053      ".foo { color: color-mix(in hwb, oklch(0% 0.399 336.3) 100%, rgb(0, 0, 0) 0%) }",
24054      &canonicalize("rgb(0, 0, 0)"),
24055    ); // Naive clip based mapping would give rgb(20, 0, 24).
24056
24057    for color_space in &["lch", "oklch"] {
24058      // regex for converting web platform tests:
24059      // test_computed_value\(.*?, `color-mix\(in \$\{colorSpace\}(.*?), (.*?)\$\{colorSpace\}(.*?) \$\{colorSpace\}(.*?)`, `\$\{colorSpace\}(.*?)`\);
24060      // minify_test(&format!(".foo {{ color: color-mix(in {0}$1, $2{0}$3 {0}$4 }}", color_space), &format!(".foo{{color:{}$5}}", color_space));
24061
24062      minify_test(
24063        &format!(
24064          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg), {0}(50% 60 70deg)) }}",
24065          color_space
24066        ),
24067        &format!(".foo{{color:{}(30% 40 50)}}", color_space),
24068      );
24069      minify_test(
24070        &format!(
24071          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg) 25%, {0}(50% 60 70deg)) }}",
24072          color_space
24073        ),
24074        &format!(".foo{{color:{}(40% 50 60)}}", color_space),
24075      );
24076      minify_test(
24077        &format!(
24078          ".foo {{ color: color-mix(in {0}, 25% {0}(10% 20 30deg), {0}(50% 60 70deg)) }}",
24079          color_space
24080        ),
24081        &format!(".foo{{color:{}(40% 50 60)}}", color_space),
24082      );
24083      minify_test(
24084        &format!(
24085          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg), 25% {0}(50% 60 70deg)) }}",
24086          color_space
24087        ),
24088        &format!(".foo{{color:{}(20% 30 40)}}", color_space),
24089      );
24090      minify_test(
24091        &format!(
24092          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg), {0}(50% 60 70deg) 25%) }}",
24093          color_space
24094        ),
24095        &format!(".foo{{color:{}(20% 30 40)}}", color_space),
24096      );
24097      minify_test(
24098        &format!(
24099          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg) 25%, {0}(50% 60 70deg) 75%) }}",
24100          color_space
24101        ),
24102        &format!(".foo{{color:{}(40% 50 60)}}", color_space),
24103      );
24104      minify_test(
24105        &format!(
24106          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg) 30%, {0}(50% 60 70deg) 90%) }}",
24107          color_space
24108        ),
24109        &format!(".foo{{color:{}(40% 50 60)}}", color_space),
24110      ); // Scale down > 100% sum.
24111      minify_test(
24112        &format!(
24113          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg) 12.5%, {0}(50% 60 70deg) 37.5%) }}",
24114          color_space
24115        ),
24116        &format!(".foo{{color:{}(40% 50 60/.5)}}", color_space),
24117      ); // Scale up < 100% sum, causes alpha multiplication.
24118      minify_test(
24119        &format!(
24120          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg) 0%, {0}(50% 60 70deg)) }}",
24121          color_space
24122        ),
24123        &format!(".foo{{color:{}(50% 60 70)}}", color_space),
24124      );
24125
24126      minify_test(
24127        &format!(
24128          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg / .4), {0}(50% 60 70deg / .8)) }}",
24129          color_space
24130        ),
24131        &format!(".foo{{color:{}(36.6667% 46.6667 50/.6)}}", color_space),
24132      );
24133      minify_test(
24134        &format!(
24135          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg / .4) 25%, {0}(50% 60 70deg / .8)) }}",
24136          color_space
24137        ),
24138        &format!(".foo{{color:{}(44.2857% 54.2857 60/.7)}}", color_space),
24139      );
24140      minify_test(
24141        &format!(
24142          ".foo {{ color: color-mix(in {0}, 25% {0}(10% 20 30deg / .4), {0}(50% 60 70deg / .8)) }}",
24143          color_space
24144        ),
24145        &format!(".foo{{color:{}(44.2857% 54.2857 60/.7)}}", color_space),
24146      );
24147      minify_test(
24148        &format!(
24149          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg / .4), 25% {0}(50% 60 70deg / .8)) }}",
24150          color_space
24151        ),
24152        &format!(".foo{{color:{}(26% 36 40/.5)}}", color_space),
24153      );
24154      minify_test(
24155        &format!(
24156          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg / .4), {0}(50% 60 70deg / .8) 25%) }}",
24157          color_space
24158        ),
24159        &format!(".foo{{color:{}(26% 36 40/.5)}}", color_space),
24160      );
24161      minify_test(
24162        &format!(
24163          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg / .4) 25%, {0}(50% 60 70deg / .8) 75%) }}",
24164          color_space
24165        ),
24166        &format!(".foo{{color:{}(44.2857% 54.2857 60/.7)}}", color_space),
24167      );
24168      minify_test(
24169        &format!(
24170          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg / .4) 30%, {0}(50% 60 70deg / .8) 90%) }}",
24171          color_space
24172        ),
24173        &format!(".foo{{color:{}(44.2857% 54.2857 60/.7)}}", color_space),
24174      ); // Scale down > 100% sum.
24175      minify_test(
24176        &format!(
24177          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg / .4) 12.5%, {0}(50% 60 70deg / .8) 37.5%) }}",
24178          color_space
24179        ),
24180        &format!(".foo{{color:{}(44.2857% 54.2857 60/.35)}}", color_space),
24181      ); // Scale up < 100% sum, causes alpha multiplication.
24182      minify_test(
24183        &format!(
24184          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg / .4) 0%, {0}(50% 60 70deg / .8)) }}",
24185          color_space
24186        ),
24187        &format!(".foo{{color:{}(50% 60 70/.8)}}", color_space),
24188      );
24189
24190      minify_test(
24191        &format!(
24192          ".foo {{ color: color-mix(in {0}, {0}(100% 0 40deg), {0}(100% 0 60deg)) }}",
24193          color_space
24194        ),
24195        &format!(".foo{{color:{}(100% 0 50)}}", color_space),
24196      );
24197      minify_test(
24198        &format!(
24199          ".foo {{ color: color-mix(in {0}, {0}(100% 0 60deg), {0}(100% 0 40deg)) }}",
24200          color_space
24201        ),
24202        &format!(".foo{{color:{}(100% 0 50)}}", color_space),
24203      );
24204      minify_test(
24205        &format!(
24206          ".foo {{ color: color-mix(in {0}, {0}(100% 0 50deg), {0}(100% 0 330deg)) }}",
24207          color_space
24208        ),
24209        &format!(".foo{{color:{}(100% 0 10)}}", color_space),
24210      );
24211      minify_test(
24212        &format!(
24213          ".foo {{ color: color-mix(in {0}, {0}(100% 0 330deg), {0}(100% 0 50deg)) }}",
24214          color_space
24215        ),
24216        &format!(".foo{{color:{}(100% 0 10)}}", color_space),
24217      );
24218      minify_test(
24219        &format!(
24220          ".foo {{ color: color-mix(in {0}, {0}(100% 0 20deg), {0}(100% 0 320deg)) }}",
24221          color_space
24222        ),
24223        &format!(".foo{{color:{}(100% 0 350)}}", color_space),
24224      );
24225      minify_test(
24226        &format!(
24227          ".foo {{ color: color-mix(in {0}, {0}(100% 0 320deg), {0}(100% 0 20deg)) }}",
24228          color_space
24229        ),
24230        &format!(".foo{{color:{}(100% 0 350)}}", color_space),
24231      );
24232
24233      minify_test(
24234        &format!(
24235          ".foo {{ color: color-mix(in {0} shorter hue, {0}(100% 0 40deg), {0}(100% 0 60deg)) }}",
24236          color_space
24237        ),
24238        &format!(".foo{{color:{}(100% 0 50)}}", color_space),
24239      );
24240      minify_test(
24241        &format!(
24242          ".foo {{ color: color-mix(in {0} shorter hue, {0}(100% 0 60deg), {0}(100% 0 40deg)) }}",
24243          color_space
24244        ),
24245        &format!(".foo{{color:{}(100% 0 50)}}", color_space),
24246      );
24247      minify_test(
24248        &format!(
24249          ".foo {{ color: color-mix(in {0} shorter hue, {0}(100% 0 50deg), {0}(100% 0 330deg)) }}",
24250          color_space
24251        ),
24252        &format!(".foo{{color:{}(100% 0 10)}}", color_space),
24253      );
24254      minify_test(
24255        &format!(
24256          ".foo {{ color: color-mix(in {0} shorter hue, {0}(100% 0 330deg), {0}(100% 0 50deg)) }}",
24257          color_space
24258        ),
24259        &format!(".foo{{color:{}(100% 0 10)}}", color_space),
24260      );
24261      minify_test(
24262        &format!(
24263          ".foo {{ color: color-mix(in {0} shorter hue, {0}(100% 0 20deg), {0}(100% 0 320deg)) }}",
24264          color_space
24265        ),
24266        &format!(".foo{{color:{}(100% 0 350)}}", color_space),
24267      );
24268      minify_test(
24269        &format!(
24270          ".foo {{ color: color-mix(in {0} shorter hue, {0}(100% 0 320deg), {0}(100% 0 20deg)) }}",
24271          color_space
24272        ),
24273        &format!(".foo{{color:{}(100% 0 350)}}", color_space),
24274      );
24275
24276      minify_test(
24277        &format!(
24278          ".foo {{ color: color-mix(in {0} longer hue, {0}(100% 0 40deg), {0}(100% 0 60deg)) }}",
24279          color_space
24280        ),
24281        &format!(".foo{{color:{}(100% 0 230)}}", color_space),
24282      );
24283      minify_test(
24284        &format!(
24285          ".foo {{ color: color-mix(in {0} longer hue, {0}(100% 0 60deg), {0}(100% 0 40deg)) }}",
24286          color_space
24287        ),
24288        &format!(".foo{{color:{}(100% 0 230)}}", color_space),
24289      );
24290      minify_test(
24291        &format!(
24292          ".foo {{ color: color-mix(in {0} longer hue, {0}(100% 0 50deg), {0}(100% 0 330deg)) }}",
24293          color_space
24294        ),
24295        &format!(".foo{{color:{}(100% 0 190)}}", color_space),
24296      );
24297      minify_test(
24298        &format!(
24299          ".foo {{ color: color-mix(in {0} longer hue, {0}(100% 0 330deg), {0}(100% 0 50deg)) }}",
24300          color_space
24301        ),
24302        &format!(".foo{{color:{}(100% 0 190)}}", color_space),
24303      );
24304      minify_test(
24305        &format!(
24306          ".foo {{ color: color-mix(in {0} longer hue, {0}(100% 0 20deg), {0}(100% 0 320deg)) }}",
24307          color_space
24308        ),
24309        &format!(".foo{{color:{}(100% 0 170)}}", color_space),
24310      );
24311      minify_test(
24312        &format!(
24313          ".foo {{ color: color-mix(in {0} longer hue, {0}(100% 0 320deg), {0}(100% 0 20deg)) }}",
24314          color_space
24315        ),
24316        &format!(".foo{{color:{}(100% 0 170)}}", color_space),
24317      );
24318
24319      minify_test(
24320        &format!(
24321          ".foo {{ color: color-mix(in {0} increasing hue, {0}(100% 0 40deg), {0}(100% 0 60deg)) }}",
24322          color_space
24323        ),
24324        &format!(".foo{{color:{}(100% 0 50)}}", color_space),
24325      );
24326      minify_test(
24327        &format!(
24328          ".foo {{ color: color-mix(in {0} increasing hue, {0}(100% 0 60deg), {0}(100% 0 40deg)) }}",
24329          color_space
24330        ),
24331        &format!(".foo{{color:{}(100% 0 230)}}", color_space),
24332      );
24333      minify_test(
24334        &format!(
24335          ".foo {{ color: color-mix(in {0} increasing hue, {0}(100% 0 50deg), {0}(100% 0 330deg)) }}",
24336          color_space
24337        ),
24338        &format!(".foo{{color:{}(100% 0 190)}}", color_space),
24339      );
24340      minify_test(
24341        &format!(
24342          ".foo {{ color: color-mix(in {0} increasing hue, {0}(100% 0 330deg), {0}(100% 0 50deg)) }}",
24343          color_space
24344        ),
24345        &format!(".foo{{color:{}(100% 0 10)}}", color_space),
24346      );
24347      minify_test(
24348        &format!(
24349          ".foo {{ color: color-mix(in {0} increasing hue, {0}(100% 0 20deg), {0}(100% 0 320deg)) }}",
24350          color_space
24351        ),
24352        &format!(".foo{{color:{}(100% 0 170)}}", color_space),
24353      );
24354      minify_test(
24355        &format!(
24356          ".foo {{ color: color-mix(in {0} increasing hue, {0}(100% 0 320deg), {0}(100% 0 20deg)) }}",
24357          color_space
24358        ),
24359        &format!(".foo{{color:{}(100% 0 350)}}", color_space),
24360      );
24361
24362      minify_test(
24363        &format!(
24364          ".foo {{ color: color-mix(in {0} decreasing hue, {0}(100% 0 40deg), {0}(100% 0 60deg)) }}",
24365          color_space
24366        ),
24367        &format!(".foo{{color:{}(100% 0 230)}}", color_space),
24368      );
24369      minify_test(
24370        &format!(
24371          ".foo {{ color: color-mix(in {0} decreasing hue, {0}(100% 0 60deg), {0}(100% 0 40deg)) }}",
24372          color_space
24373        ),
24374        &format!(".foo{{color:{}(100% 0 50)}}", color_space),
24375      );
24376      minify_test(
24377        &format!(
24378          ".foo {{ color: color-mix(in {0} decreasing hue, {0}(100% 0 50deg), {0}(100% 0 330deg)) }}",
24379          color_space
24380        ),
24381        &format!(".foo{{color:{}(100% 0 10)}}", color_space),
24382      );
24383      minify_test(
24384        &format!(
24385          ".foo {{ color: color-mix(in {0} decreasing hue, {0}(100% 0 330deg), {0}(100% 0 50deg)) }}",
24386          color_space
24387        ),
24388        &format!(".foo{{color:{}(100% 0 190)}}", color_space),
24389      );
24390      minify_test(
24391        &format!(
24392          ".foo {{ color: color-mix(in {0} decreasing hue, {0}(100% 0 20deg), {0}(100% 0 320deg)) }}",
24393          color_space
24394        ),
24395        &format!(".foo{{color:{}(100% 0 350)}}", color_space),
24396      );
24397      minify_test(
24398        &format!(
24399          ".foo {{ color: color-mix(in {0} decreasing hue, {0}(100% 0 320deg), {0}(100% 0 20deg)) }}",
24400          color_space
24401        ),
24402        &format!(".foo{{color:{}(100% 0 170)}}", color_space),
24403      );
24404
24405      minify_test(
24406        &format!(
24407          ".foo {{ color: color-mix(in {0} specified hue, {0}(100% 0 40deg), {0}(100% 0 60deg)) }}",
24408          color_space
24409        ),
24410        &format!(".foo{{color:{}(100% 0 50)}}", color_space),
24411      );
24412      minify_test(
24413        &format!(
24414          ".foo {{ color: color-mix(in {0} specified hue, {0}(100% 0 60deg), {0}(100% 0 40deg)) }}",
24415          color_space
24416        ),
24417        &format!(".foo{{color:{}(100% 0 50)}}", color_space),
24418      );
24419      minify_test(
24420        &format!(
24421          ".foo {{ color: color-mix(in {0} specified hue, {0}(100% 0 50deg), {0}(100% 0 330deg)) }}",
24422          color_space
24423        ),
24424        &format!(".foo{{color:{}(100% 0 190)}}", color_space),
24425      );
24426      minify_test(
24427        &format!(
24428          ".foo {{ color: color-mix(in {0} specified hue, {0}(100% 0 330deg), {0}(100% 0 50deg)) }}",
24429          color_space
24430        ),
24431        &format!(".foo{{color:{}(100% 0 190)}}", color_space),
24432      );
24433      minify_test(
24434        &format!(
24435          ".foo {{ color: color-mix(in {0} specified hue, {0}(100% 0 20deg), {0}(100% 0 320deg)) }}",
24436          color_space
24437        ),
24438        &format!(".foo{{color:{}(100% 0 170)}}", color_space),
24439      );
24440      minify_test(
24441        &format!(
24442          ".foo {{ color: color-mix(in {0} specified hue, {0}(100% 0 320deg), {0}(100% 0 20deg)) }}",
24443          color_space
24444        ),
24445        &format!(".foo{{color:{}(100% 0 170)}}", color_space),
24446      );
24447
24448      minify_test(
24449        &format!(
24450          ".foo {{ color: color-mix(in {0}, {0}(none none none), {0}(none none none)) }}",
24451          color_space
24452        ),
24453        &format!(".foo{{color:{}(none none none)}}", color_space),
24454      );
24455      minify_test(
24456        &format!(
24457          ".foo {{ color: color-mix(in {0}, {0}(none none none), {0}(50% 60 70deg)) }}",
24458          color_space
24459        ),
24460        &format!(".foo{{color:{}(50% 60 70)}}", color_space),
24461      );
24462      minify_test(
24463        &format!(
24464          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg), {0}(none none none)) }}",
24465          color_space
24466        ),
24467        &format!(".foo{{color:{}(10% 20 30)}}", color_space),
24468      );
24469      minify_test(
24470        &format!(
24471          ".foo {{ color: color-mix(in {0}, {0}(10% 20 none), {0}(50% 60 70deg)) }}",
24472          color_space
24473        ),
24474        &format!(".foo{{color:{}(30% 40 70)}}", color_space),
24475      );
24476      minify_test(
24477        &format!(
24478          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg), {0}(50% 60 none)) }}",
24479          color_space
24480        ),
24481        &format!(".foo{{color:{}(30% 40 30)}}", color_space),
24482      );
24483      minify_test(
24484        &format!(
24485          ".foo {{ color: color-mix(in {0}, {0}(none 20 30deg), {0}(50% none 70deg)) }}",
24486          color_space
24487        ),
24488        &format!(".foo{{color:{}(50% 20 50)}}", color_space),
24489      );
24490      minify_test(
24491        &format!(
24492          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg / none), {0}(50% 60 70deg)) }}",
24493          color_space
24494        ),
24495        &format!(".foo{{color:{}(30% 40 50)}}", color_space),
24496      );
24497      minify_test(
24498        &format!(
24499          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg / none), {0}(50% 60 70deg / 0.5)) }}",
24500          color_space
24501        ),
24502        &format!(".foo{{color:{}(30% 40 50/.5)}}", color_space),
24503      );
24504      minify_test(
24505        &format!(
24506          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30deg / none), {0}(50% 60 70deg / none)) }}",
24507          color_space
24508        ),
24509        &format!(".foo{{color:{}(30% 40 50/none)}}", color_space),
24510      );
24511    }
24512
24513    for color_space in ["lab", "oklab"] {
24514      minify_test(
24515        &format!(
24516          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30), {0}(50% 60 70)) }}",
24517          color_space
24518        ),
24519        &format!(".foo{{color:{}(30% 40 50)}}", color_space),
24520      );
24521      minify_test(
24522        &format!(
24523          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30) 25%, {0}(50% 60 70)) }}",
24524          color_space
24525        ),
24526        &format!(".foo{{color:{}(40% 50 60)}}", color_space),
24527      );
24528      minify_test(
24529        &format!(
24530          ".foo {{ color: color-mix(in {0}, 25% {0}(10% 20 30), {0}(50% 60 70)) }}",
24531          color_space
24532        ),
24533        &format!(".foo{{color:{}(40% 50 60)}}", color_space),
24534      );
24535      minify_test(
24536        &format!(
24537          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30), 25% {0}(50% 60 70)) }}",
24538          color_space
24539        ),
24540        &format!(".foo{{color:{}(20% 30 40)}}", color_space),
24541      );
24542      minify_test(
24543        &format!(
24544          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30), {0}(50% 60 70) 25%) }}",
24545          color_space
24546        ),
24547        &format!(".foo{{color:{}(20% 30 40)}}", color_space),
24548      );
24549      minify_test(
24550        &format!(
24551          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30) 25%, {0}(50% 60 70) 75%) }}",
24552          color_space
24553        ),
24554        &format!(".foo{{color:{}(40% 50 60)}}", color_space),
24555      );
24556      minify_test(
24557        &format!(
24558          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30) 30%, {0}(50% 60 70) 90%) }}",
24559          color_space
24560        ),
24561        &format!(".foo{{color:{}(40% 50 60)}}", color_space),
24562      ); // Scale down > 100% sum.
24563      minify_test(
24564        &format!(
24565          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30) 12.5%, {0}(50% 60 70) 37.5%) }}",
24566          color_space
24567        ),
24568        &format!(".foo{{color:{}(40% 50 60/.5)}}", color_space),
24569      ); // Scale up < 100% sum, causes alpha multiplication.
24570      minify_test(
24571        &format!(
24572          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30) 0%, {0}(50% 60 70)) }}",
24573          color_space
24574        ),
24575        &format!(".foo{{color:{}(50% 60 70)}}", color_space),
24576      );
24577
24578      minify_test(
24579        &format!(
24580          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30 / .4), {0}(50% 60 70 / .8)) }}",
24581          color_space
24582        ),
24583        &format!(".foo{{color:{}(36.6667% 46.6667 56.6667/.6)}}", color_space),
24584      );
24585      minify_test(
24586        &format!(
24587          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30 / .4) 25%, {0}(50% 60 70 / .8)) }}",
24588          color_space
24589        ),
24590        &format!(".foo{{color:{}(44.2857% 54.2857 64.2857/.7)}}", color_space),
24591      );
24592      minify_test(
24593        &format!(
24594          ".foo {{ color: color-mix(in {0}, 25% {0}(10% 20 30 / .4), {0}(50% 60 70 / .8)) }}",
24595          color_space
24596        ),
24597        &format!(".foo{{color:{}(44.2857% 54.2857 64.2857/.7)}}", color_space),
24598      );
24599      minify_test(
24600        &format!(
24601          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30 / .4), 25% {0}(50% 60 70 / .8)) }}",
24602          color_space
24603        ),
24604        &format!(".foo{{color:{}(26% 36 46/.5)}}", color_space),
24605      );
24606      minify_test(
24607        &format!(
24608          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30 / .4), {0}(50% 60 70 / .8) 25%) }}",
24609          color_space
24610        ),
24611        &format!(".foo{{color:{}(26% 36 46/.5)}}", color_space),
24612      );
24613      minify_test(
24614        &format!(
24615          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30 / .4) 25%, {0}(50% 60 70 / .8) 75%) }}",
24616          color_space
24617        ),
24618        &format!(".foo{{color:{}(44.2857% 54.2857 64.2857/.7)}}", color_space),
24619      );
24620      minify_test(
24621        &format!(
24622          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30 / .4) 30%, {0}(50% 60 70 / .8) 90%) }}",
24623          color_space
24624        ),
24625        &format!(".foo{{color:{}(44.2857% 54.2857 64.2857/.7)}}", color_space),
24626      ); // Scale down > 100% sum.
24627      minify_test(
24628        &format!(
24629          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30 / .4) 12.5%, {0}(50% 60 70 / .8) 37.5%) }}",
24630          color_space
24631        ),
24632        &format!(".foo{{color:{}(44.2857% 54.2857 64.2857/.35)}}", color_space),
24633      ); // Scale up < 100% sum, causes alpha multiplication.
24634      minify_test(
24635        &format!(
24636          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30 / .4) 0%, {0}(50% 60 70 / .8)) }}",
24637          color_space
24638        ),
24639        &format!(".foo{{color:{}(50% 60 70/.8)}}", color_space),
24640      );
24641
24642      minify_test(
24643        &format!(
24644          ".foo {{ color: color-mix(in {0}, {0}(none none none), {0}(none none none)) }}",
24645          color_space
24646        ),
24647        &format!(".foo{{color:{}(none none none)}}", color_space),
24648      );
24649      minify_test(
24650        &format!(
24651          ".foo {{ color: color-mix(in {0}, {0}(none none none), {0}(50% 60 70)) }}",
24652          color_space
24653        ),
24654        &format!(".foo{{color:{}(50% 60 70)}}", color_space),
24655      );
24656      minify_test(
24657        &format!(
24658          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30), {0}(none none none)) }}",
24659          color_space
24660        ),
24661        &format!(".foo{{color:{}(10% 20 30)}}", color_space),
24662      );
24663      minify_test(
24664        &format!(
24665          ".foo {{ color: color-mix(in {0}, {0}(10% 20 none), {0}(50% 60 70)) }}",
24666          color_space
24667        ),
24668        &format!(".foo{{color:{}(30% 40 70)}}", color_space),
24669      );
24670      minify_test(
24671        &format!(
24672          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30), {0}(50% 60 none)) }}",
24673          color_space
24674        ),
24675        &format!(".foo{{color:{}(30% 40 30)}}", color_space),
24676      );
24677      minify_test(
24678        &format!(
24679          ".foo {{ color: color-mix(in {0}, {0}(none 20 30), {0}(50% none 70)) }}",
24680          color_space
24681        ),
24682        &format!(".foo{{color:{}(50% 20 50)}}", color_space),
24683      );
24684      minify_test(
24685        &format!(
24686          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30 / none), {0}(50% 60 70)) }}",
24687          color_space
24688        ),
24689        &format!(".foo{{color:{}(30% 40 50)}}", color_space),
24690      );
24691      minify_test(
24692        &format!(
24693          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30 / none), {0}(50% 60 70 / 0.5)) }}",
24694          color_space
24695        ),
24696        &format!(".foo{{color:{}(30% 40 50/.5)}}", color_space),
24697      );
24698      minify_test(
24699        &format!(
24700          ".foo {{ color: color-mix(in {0}, {0}(10% 20 30 / none), {0}(50% 60 70 / none)) }}",
24701          color_space
24702        ),
24703        &format!(".foo{{color:{}(30% 40 50/none)}}", color_space),
24704      );
24705    }
24706
24707    for color_space in [/*"srgb", */ "srgb-linear", "xyz", "xyz-d50", "xyz-d65"] {
24708      // regex for converting web platform tests:
24709      // test_computed_value\(.*?, `color-mix\(in \$\{colorSpace\}(.*?), (.*?)color\(\$\{colorSpace\}(.*?) color\(\$\{colorSpace\}(.*?)`, `color\(\$\{resultColorSpace\}(.*?)`\);
24710      // 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));
24711
24712      let result_color_space = if color_space == "xyz-d65" { "xyz" } else { color_space };
24713
24714      minify_test(
24715        &format!(
24716          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3), color({0} .5 .6 .7)) }}",
24717          color_space
24718        ),
24719        &format!(".foo{{color:color({} .3 .4 .5)}}", result_color_space),
24720      );
24721      minify_test(
24722        &format!(
24723          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3) 25%, color({0} .5 .6 .7)) }}",
24724          color_space
24725        ),
24726        &format!(".foo{{color:color({} .4 .5 .6)}}", result_color_space),
24727      );
24728      minify_test(
24729        &format!(
24730          ".foo {{ color: color-mix(in {0}, 25% color({0} .1 .2 .3), color({0} .5 .6 .7)) }}",
24731          color_space
24732        ),
24733        &format!(".foo{{color:color({} .4 .5 .6)}}", result_color_space),
24734      );
24735      minify_test(
24736        &format!(
24737          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3), color({0} .5 .6 .7) 25%) }}",
24738          color_space
24739        ),
24740        &format!(".foo{{color:color({} .2 .3 .4)}}", result_color_space),
24741      );
24742      minify_test(
24743        &format!(
24744          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3), 25% color({0} .5 .6 .7)) }}",
24745          color_space
24746        ),
24747        &format!(".foo{{color:color({} .2 .3 .4)}}", result_color_space),
24748      );
24749      minify_test(
24750        &format!(
24751          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3) 25%, color({0} .5 .6 .7) 75%) }}",
24752          color_space
24753        ),
24754        &format!(".foo{{color:color({} .4 .5 .6)}}", result_color_space),
24755      );
24756      minify_test(
24757        &format!(
24758          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3) 30%, color({0} .5 .6 .7) 90%) }}",
24759          color_space
24760        ),
24761        &format!(".foo{{color:color({} .4 .5 .6)}}", result_color_space),
24762      ); // Scale down > 100% sum.
24763      minify_test(
24764        &format!(
24765          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3) 12.5%, color({0} .5 .6 .7) 37.5%) }}",
24766          color_space
24767        ),
24768        &format!(".foo{{color:color({} .4 .5 .6/.5)}}", result_color_space),
24769      ); // Scale up < 100% sum, causes alpha multiplication.
24770      minify_test(
24771        &format!(
24772          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3) 0%, color({0} .5 .6 .7)) }}",
24773          color_space
24774        ),
24775        &format!(".foo{{color:color({} .5 .6 .7)}}", result_color_space),
24776      );
24777
24778      minify_test(
24779        &format!(
24780          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3 / .5), color({0} .5 .6 .7 / .8)) }}",
24781          color_space
24782        ),
24783        &format!(
24784          ".foo{{color:color({} .346154 .446154 .546154/.65)}}",
24785          result_color_space
24786        ),
24787      );
24788      minify_test(
24789        &format!(
24790          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3 / .4) 25%, color({0} .5 .6 .7 / .8)) }}",
24791          color_space
24792        ),
24793        &format!(".foo{{color:color({} .442857 .542857 .642857/.7)}}", result_color_space),
24794      );
24795      minify_test(
24796        &format!(
24797          ".foo {{ color: color-mix(in {0}, 25% color({0} .1 .2 .3 / .4), color({0} .5 .6 .7 / .8)) }}",
24798          color_space
24799        ),
24800        &format!(".foo{{color:color({} .442857 .542857 .642857/.7)}}", result_color_space),
24801      );
24802      minify_test(
24803        &format!(
24804          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3 / .4), color({0} .5 .6 .7 / .8) 25%) }}",
24805          color_space
24806        ),
24807        &format!(".foo{{color:color({} .26 .36 .46/.5)}}", result_color_space),
24808      );
24809      minify_test(
24810        &format!(
24811          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3 / .4), 25% color({0} .5 .6 .7 / .8)) }}",
24812          color_space
24813        ),
24814        &format!(".foo{{color:color({} .26 .36 .46/.5)}}", result_color_space),
24815      );
24816      minify_test(
24817        &format!(
24818          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3 / .4) 25%, color({0} .5 .6 .7 / .8) 75%) }}",
24819          color_space
24820        ),
24821        &format!(".foo{{color:color({} .442857 .542857 .642857/.7)}}", result_color_space),
24822      );
24823      minify_test(
24824        &format!(
24825          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3 / .4) 30%, color({0} .5 .6 .7 / .8) 90%) }}",
24826          color_space
24827        ),
24828        &format!(".foo{{color:color({} .442857 .542857 .642857/.7)}}", result_color_space),
24829      ); // Scale down > 100% sum.
24830      minify_test(
24831        &format!(
24832          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3 / .4) 12.5%, color({0} .5 .6 .7 / .8) 37.5%) }}",
24833          color_space
24834        ),
24835        &format!(
24836          ".foo{{color:color({} .442857 .542857 .642857/.35)}}",
24837          result_color_space
24838        ),
24839      ); // Scale up < 100% sum, causes alpha multiplication.
24840      minify_test(
24841        &format!(
24842          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3 / .4) 0%, color({0} .5 .6 .7 / .8)) }}",
24843          color_space
24844        ),
24845        &format!(".foo{{color:color({} .5 .6 .7/.8)}}", result_color_space),
24846      );
24847
24848      minify_test(
24849        &format!(
24850          ".foo {{ color: color-mix(in {0}, color({0} 2 3 4 / 5), color({0} 4 6 8 / 10)) }}",
24851          color_space
24852        ),
24853        &format!(".foo{{color:color({} 3 4.5 6)}}", result_color_space),
24854      );
24855      minify_test(
24856        &format!(
24857          ".foo {{ color: color-mix(in {0}, color({0} -2 -3 -4), color({0} -4 -6 -8)) }}",
24858          color_space
24859        ),
24860        &format!(".foo{{color:color({} -3 -4.5 -6)}}", result_color_space),
24861      );
24862      minify_test(
24863        &format!(
24864          ".foo {{ color: color-mix(in {0}, color({0} -2 -3 -4 / -5), color({0} -4 -6 -8 / -10)) }}",
24865          color_space
24866        ),
24867        &format!(".foo{{color:color({} 0 0 0/0)}}", result_color_space),
24868      );
24869
24870      minify_test(
24871        &format!(
24872          ".foo {{ color: color-mix(in {0}, color({0} none none none), color({0} none none none)) }}",
24873          color_space
24874        ),
24875        &format!(".foo{{color:color({} none none none)}}", result_color_space),
24876      );
24877      minify_test(
24878        &format!(
24879          ".foo {{ color: color-mix(in {0}, color({0} none none none), color({0} .5 .6 .7)) }}",
24880          color_space
24881        ),
24882        &format!(".foo{{color:color({} .5 .6 .7)}}", result_color_space),
24883      );
24884      minify_test(
24885        &format!(
24886          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3), color({0} none none none)) }}",
24887          color_space
24888        ),
24889        &format!(".foo{{color:color({} .1 .2 .3)}}", result_color_space),
24890      );
24891      minify_test(
24892        &format!(
24893          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 none), color({0} .5 .6 .7)) }}",
24894          color_space
24895        ),
24896        &format!(".foo{{color:color({} .3 .4 .7)}}", result_color_space),
24897      );
24898      minify_test(
24899        &format!(
24900          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3), color({0} .5 .6 none)) }}",
24901          color_space
24902        ),
24903        &format!(".foo{{color:color({} .3 .4 .3)}}", result_color_space),
24904      );
24905      minify_test(
24906        &format!(
24907          ".foo {{ color: color-mix(in {0}, color({0} none .2 .3), color({0} .5 none .7)) }}",
24908          color_space
24909        ),
24910        &format!(".foo{{color:color({} .5 .2 .5)}}", result_color_space),
24911      );
24912      minify_test(
24913        &format!(
24914          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3 / none), color({0} .5 .6 .7)) }}",
24915          color_space
24916        ),
24917        &format!(".foo{{color:color({} .3 .4 .5)}}", result_color_space),
24918      );
24919      minify_test(
24920        &format!(
24921          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3 / none), color({0} .5 .6 .7 / 0.5)) }}",
24922          color_space
24923        ),
24924        &format!(".foo{{color:color({} .3 .4 .5/.5)}}", result_color_space),
24925      );
24926      minify_test(
24927        &format!(
24928          ".foo {{ color: color-mix(in {0}, color({0} .1 .2 .3 / none), color({0} .5 .6 .7 / none)) }}",
24929          color_space
24930        ),
24931        &format!(".foo{{color:color({} .3 .4 .5/none)}}", result_color_space),
24932      );
24933    }
24934  }
24935
24936  #[test]
24937  fn test_grid() {
24938    property_range_test(
24939      &["gap", "row-gap", "column-gap"],
24940      &[
24941        ("-1px", None),
24942        ("calc(1px - 2px)", Some("0")),
24943        ("calc(-1px + 2px)", Some("1px")),
24944        ("-1%", None),
24945        ("calc(1em - 2px)", Some("calc(1em - 2px)")),
24946        ("calc(-1%)", Some("calc(-1%)")),
24947      ],
24948    );
24949    property_range_test(
24950      &["grid-template-columns", "grid-auto-rows"],
24951      &[
24952        ("-1px", None),
24953        ("calc(1px - 2px)", Some("0")),
24954        ("calc(-1px + 2px)", Some("1px")),
24955        ("-1%", None),
24956        ("calc(1em - 2px)", Some("calc(1em - 2px)")),
24957        ("calc(-1%)", Some("calc(-1%)")),
24958        ("-1fr", None),
24959        ("-0fr", Some("-0fr")),
24960        ("minmax(-1px, 1fr)", None),
24961        ("fit-content(-1px)", None),
24962      ],
24963    );
24964    minify_test(
24965      ".foo { grid-template-columns: [first nav-start]  150px [main-start] 1fr [last]; }",
24966      ".foo{grid-template-columns:[first nav-start]150px[main-start]1fr[last]}",
24967    );
24968    minify_test(
24969      ".foo { grid-template-columns: 150px 1fr; }",
24970      ".foo{grid-template-columns:150px 1fr}",
24971    );
24972    minify_test(
24973      ".foo { grid-template-columns: repeat(4, 1fr); }",
24974      ".foo{grid-template-columns:repeat(4,1fr)}",
24975    );
24976    minify_test(
24977      ".foo { grid-template-columns: repeat(2, [e] 40px); }",
24978      ".foo{grid-template-columns:repeat(2,[e]40px)}",
24979    );
24980    minify_test(
24981      ".foo { grid-template-columns: repeat(4, [col-start] 250px [col-end]); }",
24982      ".foo{grid-template-columns:repeat(4,[col-start]250px[col-end])}",
24983    );
24984    minify_test(
24985      ".foo { grid-template-columns: repeat(4, [col-start] 60% [col-end]); }",
24986      ".foo{grid-template-columns:repeat(4,[col-start]60%[col-end])}",
24987    );
24988    minify_test(
24989      ".foo { grid-template-columns: repeat(4, [col-start] 1fr [col-end]); }",
24990      ".foo{grid-template-columns:repeat(4,[col-start]1fr[col-end])}",
24991    );
24992    minify_test(
24993      ".foo { grid-template-columns: repeat(4, [col-start] min-content [col-end]); }",
24994      ".foo{grid-template-columns:repeat(4,[col-start]min-content[col-end])}",
24995    );
24996    minify_test(
24997      ".foo { grid-template-columns: repeat(4, [col-start] max-content [col-end]); }",
24998      ".foo{grid-template-columns:repeat(4,[col-start]max-content[col-end])}",
24999    );
25000    minify_test(
25001      ".foo { grid-template-columns: repeat(4, [col-start] auto [col-end]); }",
25002      ".foo{grid-template-columns:repeat(4,[col-start]auto[col-end])}",
25003    );
25004    minify_test(
25005      ".foo { grid-template-columns: repeat(4, [col-start] minmax(100px, 1fr) [col-end]); }",
25006      ".foo{grid-template-columns:repeat(4,[col-start]minmax(100px,1fr)[col-end])}",
25007    );
25008    minify_test(
25009      ".foo { grid-template-columns: repeat(4, [col-start] fit-content(200px) [col-end]); }",
25010      ".foo{grid-template-columns:repeat(4,[col-start]fit-content(200px)[col-end])}",
25011    );
25012    minify_test(
25013      ".foo { grid-template-columns: repeat(4, 10px [col-start] 30% [col-middle] auto [col-end]); }",
25014      ".foo{grid-template-columns:repeat(4,10px[col-start]30%[col-middle]auto[col-end])}",
25015    );
25016    minify_test(
25017      ".foo { grid-template-columns: repeat(5, auto); }",
25018      ".foo{grid-template-columns:repeat(5,auto)}",
25019    );
25020    minify_test(
25021      ".foo { grid-template-columns: repeat(auto-fill, 250px); }",
25022      ".foo{grid-template-columns:repeat(auto-fill,250px)}",
25023    );
25024    minify_test(
25025      ".foo { grid-template-columns: repeat(auto-fit, 250px); }",
25026      ".foo{grid-template-columns:repeat(auto-fit,250px)}",
25027    );
25028    minify_test(
25029      ".foo { grid-template-columns: repeat(auto-fill, [col-start] 250px [col-end]); }",
25030      ".foo{grid-template-columns:repeat(auto-fill,[col-start]250px[col-end])}",
25031    );
25032    minify_test(
25033      ".foo { grid-template-columns: repeat(auto-fill, [col-start] minmax(100px, 1fr) [col-end]); }",
25034      ".foo{grid-template-columns:repeat(auto-fill,[col-start]minmax(100px,1fr)[col-end])}",
25035    );
25036    minify_test(
25037      ".foo { grid-template-columns: minmax(min-content, 1fr); }",
25038      ".foo{grid-template-columns:minmax(min-content,1fr)}",
25039    );
25040    minify_test(
25041      ".foo { grid-template-columns: 200px repeat(auto-fill, 100px) 300px; }",
25042      ".foo{grid-template-columns:200px repeat(auto-fill,100px) 300px}",
25043    );
25044    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]}");
25045    minify_test(
25046      ".foo { grid-template-rows: [linename1 linename2] 100px repeat(auto-fit, [linename1] 300px) [linename3]; }",
25047      ".foo{grid-template-rows:[linename1 linename2]100px repeat(auto-fit,[linename1]300px)[linename3]}",
25048    );
25049
25050    minify_test(".foo { grid-auto-rows: auto; }", ".foo{grid-auto-rows:auto}");
25051    minify_test(".foo { grid-auto-rows: 1fr; }", ".foo{grid-auto-rows:1fr}");
25052    minify_test(".foo { grid-auto-rows: 100px; }", ".foo{grid-auto-rows:100px}");
25053    minify_test(
25054      ".foo { grid-auto-rows: min-content; }",
25055      ".foo{grid-auto-rows:min-content}",
25056    );
25057    minify_test(
25058      ".foo { grid-auto-rows: max-content; }",
25059      ".foo{grid-auto-rows:max-content}",
25060    );
25061    minify_test(
25062      ".foo { grid-auto-rows: minmax(100px,auto); }",
25063      ".foo{grid-auto-rows:minmax(100px,auto)}",
25064    );
25065    minify_test(
25066      ".foo { grid-auto-rows: fit-content(20%); }",
25067      ".foo{grid-auto-rows:fit-content(20%)}",
25068    );
25069    minify_test(
25070      ".foo { grid-auto-rows: 100px minmax(100px, auto) 10% 0.5fr fit-content(400px); }",
25071      ".foo{grid-auto-rows:100px minmax(100px,auto) 10% .5fr fit-content(400px)}",
25072    );
25073    minify_test(
25074      ".foo { grid-auto-columns: 100px minmax(100px, auto) 10% 0.5fr fit-content(400px); }",
25075      ".foo{grid-auto-columns:100px minmax(100px,auto) 10% .5fr fit-content(400px)}",
25076    );
25077
25078    minify_test(
25079      r#"
25080      .foo {
25081        grid-template-areas: "head head"
25082                             "nav  main"
25083                             "foot ....";
25084      }
25085    "#,
25086      ".foo{grid-template-areas:\"head head\"\"nav main\"\"foot.\"}",
25087    );
25088    minify_test(
25089      r#"
25090      .foo {
25091        grid-template-areas: "head head"
25092                             "nav  main"
25093                             ".... foot";
25094      }
25095    "#,
25096      ".foo{grid-template-areas:\"head head\"\"nav main\"\".foot\"}",
25097    );
25098    minify_test(
25099      r#"
25100      .foo {
25101        grid-template-areas: "head head"
25102                             "nav  main"
25103                             ".... ....";
25104      }
25105    "#,
25106      ".foo{grid-template-areas:\"head head\"\"nav main\"\". .\"}",
25107    );
25108
25109    // to grid-* shorthand
25110    minify_test(
25111      r#"
25112      .test-miss-areas {
25113        grid-template-columns: 1fr 90px;
25114        grid-template-rows: auto 80px;
25115        grid-template-areas: "one";
25116      }
25117    "#,
25118      ".test-miss-areas{grid-template:\"one\"\".\"80px/1fr 90px}",
25119    );
25120    test(
25121      r#"
25122      .test-miss-areas-2 {
25123        grid-template-columns: 1fr 1fr 1fr;
25124        grid-template-rows: 30px 60px 100px;
25125        grid-template-areas: "a a a" "b c c";
25126      }
25127    "#,
25128      indoc! { r#"
25129      .test-miss-areas-2 {
25130        grid-template: "a a a" 30px
25131                       "b c c" 60px
25132                       ". . ." 100px
25133                       / 1fr 1fr 1fr;
25134      }
25135    "#},
25136    );
25137
25138    test(
25139      r#"
25140      .test-miss-areas-3 {
25141        grid-template: 30px 60px 100px / 1fr 1fr 1fr;
25142        grid-template-areas: "a a a" "b c c";
25143      }
25144    "#,
25145      indoc! { r#"
25146      .test-miss-areas-3 {
25147        grid-template: "a a a" 30px
25148                       "b c c" 60px
25149                       ". . ." 100px
25150                       / 1fr 1fr 1fr;
25151      }
25152    "#},
25153    );
25154
25155    test(
25156      r#"
25157      .test-miss-areas-4 {
25158        grid: 30px 60px 100px / 1fr 1fr 1fr;
25159        grid-template-areas: "a a a" "b c c";
25160      }
25161    "#,
25162      indoc! { r#"
25163      .test-miss-areas-4 {
25164        grid: "a a a" 30px
25165              "b c c" 60px
25166              ". . ." 100px
25167              / 1fr 1fr 1fr;
25168      }
25169    "#},
25170    );
25171
25172    // test no unreachable error
25173    minify_test(
25174      r#"
25175    .grid-shorthand-areas {
25176      grid: auto / 1fr 3fr;
25177      grid-template-areas: ". content .";
25178    }
25179  "#,
25180      ".grid-shorthand-areas{grid:\".content.\"/1fr 3fr}",
25181    );
25182    minify_test(
25183      r#"
25184    .grid-shorthand-areas-rows {
25185      grid: auto / 1fr 3fr;
25186      grid-template-rows: 20px;
25187      grid-template-areas: ". content .";
25188    }
25189  "#,
25190      ".grid-shorthand-areas-rows{grid:\".content.\"20px/1fr 3fr}",
25191    );
25192
25193    // test grid-auto-flow: row in grid shorthand
25194    test(
25195      r#"
25196      .test-auto-flow-row-1 {
25197        grid: auto-flow   /  1fr 2fr 1fr;
25198        grid-template-areas: "  .   one  .  ";
25199      }
25200    "#,
25201      indoc! { r#"
25202      .test-auto-flow-row-1 {
25203        grid: auto-flow / 1fr 2fr 1fr;
25204        grid-template-areas: ". one .";
25205      }
25206    "#},
25207    );
25208    test(
25209      r#"
25210      .test-auto-flow-row-2 {
25211        grid: auto-flow   auto   /  100px   100px;
25212        grid-template-areas: " one  two ";
25213      }
25214    "#,
25215      indoc! { r#"
25216      .test-auto-flow-row-2 {
25217        grid: auto-flow / 100px 100px;
25218        grid-template-areas: "one two";
25219      }
25220    "#},
25221    );
25222    test(
25223      r#"
25224      .test-auto-flow-dense {
25225        grid: dense auto-flow  /  1fr 2fr;
25226        grid-template-areas: "  .   content  .  ";
25227      }
25228    "#,
25229      indoc! { r#"
25230      .test-auto-flow-dense {
25231        grid: auto-flow dense / 1fr 2fr;
25232        grid-template-areas: ". content .";
25233      }
25234    "#},
25235    );
25236    minify_test(
25237      r#"
25238      .grid-auto-flow-row-auto-rows {
25239        grid: auto-flow 40px / 1fr 90px;
25240        grid-template-areas: "a";
25241      }
25242    "#,
25243      ".grid-auto-flow-row-auto-rows{grid:auto-flow 40px/1fr 90px;grid-template-areas:\"a\"}",
25244    );
25245    minify_test(
25246      r#"
25247      .grid-auto-flow-row-auto-rows-multiple {
25248        grid: auto-flow 40px max-content / 1fr;
25249        grid-template-areas: ". a";
25250      }
25251    "#,
25252      ".grid-auto-flow-row-auto-rows-multiple{grid:auto-flow 40px max-content/1fr;grid-template-areas:\".a\"}",
25253    );
25254
25255    // test grid-auto-flow: column in grid shorthand
25256    test(
25257      r#"
25258      .test-auto-flow-column-1 {
25259        grid: 300px / auto-flow;
25260        grid-template-areas: "  .   one  .  ";
25261      }
25262    "#,
25263      indoc! { r#"
25264      .test-auto-flow-column-1 {
25265        grid: 300px / auto-flow;
25266        grid-template-areas: ". one .";
25267      }
25268    "#},
25269    );
25270    test(
25271      r#"
25272      .test-auto-flow-column-2 {
25273        grid: 200px 1fr / auto-flow auto;
25274        grid-template-areas: "  .   one  .  ";
25275      }
25276    "#,
25277      indoc! { r#"
25278      .test-auto-flow-column-2 {
25279        grid: 200px 1fr / auto-flow;
25280        grid-template-areas: ". one .";
25281      }
25282    "#},
25283    );
25284    test(
25285      r#"
25286      .test-auto-flow-column-dense {
25287        grid: 1fr 2fr / dense auto-flow;
25288        grid-template-areas: "  .   content  .  ";
25289      }
25290    "#,
25291      indoc! { r#"
25292      .test-auto-flow-column-dense {
25293        grid: 1fr 2fr / auto-flow dense;
25294        grid-template-areas: ". content .";
25295      }
25296    "#},
25297    );
25298    minify_test(
25299      r#"
25300      .grid-auto-flow-column-auto-rows {
25301        grid: 1fr 3fr / auto-flow 40px;
25302        grid-template-areas: "a";
25303      }
25304    "#,
25305      ".grid-auto-flow-column-auto-rows{grid:1fr 3fr/auto-flow 40px;grid-template-areas:\"a\"}",
25306    );
25307    minify_test(
25308      r#"
25309      .grid-auto-flow-column-auto-rows-multiple {
25310        grid: 1fr / auto-flow 40px max-content ;
25311        grid-template-areas: ". a";
25312      }
25313    "#,
25314      ".grid-auto-flow-column-auto-rows-multiple{grid:1fr/auto-flow 40px max-content;grid-template-areas:\".a\"}",
25315    );
25316
25317    test(
25318      r#"
25319      .foo {
25320        grid-template-areas: "head head" "nav  main" "foot ....";
25321      }
25322    "#,
25323      indoc! { r#"
25324      .foo {
25325        grid-template-areas: "head head"
25326                             "nav main"
25327                             "foot .";
25328      }
25329    "#},
25330    );
25331
25332    minify_test(
25333      r#"
25334      .foo {
25335        grid-template: [header-top] "a   a   a"     [header-bottom]
25336                       [main-top] "b   b   b" 1fr [main-bottom];
25337      }
25338    "#,
25339      ".foo{grid-template:[header-top]\"a a a\"[header-bottom main-top]\"b b b\"1fr[main-bottom]}",
25340    );
25341    minify_test(
25342      r#"
25343      .foo {
25344        grid-template: "head head"
25345                       "nav  main" 1fr
25346                       "foot ....";
25347      }
25348    "#,
25349      ".foo{grid-template:\"head head\"\"nav main\"1fr\"foot.\"}",
25350    );
25351    minify_test(
25352      r#"
25353      .foo {
25354        grid-template: [header-top] "a   a   a"     [header-bottom]
25355                         [main-top] "b   b   b" 1fr [main-bottom]
25356                                  / auto 1fr auto;
25357      }
25358    "#,
25359      ".foo{grid-template:[header-top]\"a a a\"[header-bottom main-top]\"b b b\"1fr[main-bottom]/auto 1fr auto}",
25360    );
25361
25362    minify_test(
25363      ".foo { grid-template: auto 1fr / auto 1fr auto; }",
25364      ".foo{grid-template:auto 1fr/auto 1fr auto}",
25365    );
25366    minify_test(
25367      ".foo { grid-template: [linename1 linename2] 100px repeat(auto-fit, [linename1] 300px) [linename3] / [linename1 linename2] 100px repeat(auto-fit, [linename1] 300px) [linename3]; }",
25368      ".foo{grid-template:[linename1 linename2]100px repeat(auto-fit,[linename1]300px)[linename3]/[linename1 linename2]100px repeat(auto-fit,[linename1]300px)[linename3]}"
25369    );
25370
25371    test(
25372      ".foo{grid-template:[header-top]\"a a a\"[header-bottom main-top]\"b b b\"1fr[main-bottom]/auto 1fr auto}",
25373      indoc! {r#"
25374        .foo {
25375          grid-template: [header-top] "a a a" [header-bottom]
25376                         [main-top] "b b b" 1fr [main-bottom]
25377                         / auto 1fr auto;
25378        }
25379      "#},
25380    );
25381    test(
25382      ".foo{grid-template:[header-top]\"a a a\"[main-top]\"b b b\"1fr/auto 1fr auto}",
25383      indoc! {r#"
25384        .foo {
25385          grid-template: [header-top] "a a a"
25386                         [main-top] "b b b" 1fr
25387                         / auto 1fr auto;
25388        }
25389      "#},
25390    );
25391
25392    minify_test(".foo { grid-auto-flow: row }", ".foo{grid-auto-flow:row}");
25393    minify_test(".foo { grid-auto-flow: column }", ".foo{grid-auto-flow:column}");
25394    minify_test(".foo { grid-auto-flow: row dense }", ".foo{grid-auto-flow:dense}");
25395    minify_test(".foo { grid-auto-flow: dense row }", ".foo{grid-auto-flow:dense}");
25396    minify_test(
25397      ".foo { grid-auto-flow: column dense }",
25398      ".foo{grid-auto-flow:column dense}",
25399    );
25400    minify_test(
25401      ".foo { grid-auto-flow: dense column }",
25402      ".foo{grid-auto-flow:column dense}",
25403    );
25404
25405    minify_test(".foo { grid: none }", ".foo{grid:none}");
25406    minify_test(".foo { grid: \"a\" 100px \"b\" 1fr }", ".foo{grid:\"a\"100px\"b\"1fr}");
25407    minify_test(
25408      ".foo { grid: [linename1] \"a\" 100px [linename2] }",
25409      ".foo{grid:[linename1]\"a\"100px[linename2]}",
25410    );
25411    minify_test(
25412      ".foo { grid: \"a\" 200px \"b\" min-content }",
25413      ".foo{grid:\"a\"200px\"b\"min-content}",
25414    );
25415    minify_test(
25416      ".foo { grid: \"a\" minmax(100px, max-content) \"b\" 20% }",
25417      ".foo{grid:\"a\"minmax(100px,max-content)\"b\"20%}",
25418    );
25419    minify_test(".foo { grid: 100px / 200px }", ".foo{grid:100px/200px}");
25420    minify_test(
25421      ".foo { grid: minmax(400px, min-content) / repeat(auto-fill, 50px) }",
25422      ".foo{grid:minmax(400px,min-content)/repeat(auto-fill,50px)}",
25423    );
25424
25425    minify_test(".foo { grid: 200px / auto-flow }", ".foo{grid:200px/auto-flow}");
25426    minify_test(".foo { grid: 30% / auto-flow dense }", ".foo{grid:30%/auto-flow dense}");
25427    minify_test(".foo { grid: 30% / dense auto-flow }", ".foo{grid:30%/auto-flow dense}");
25428    minify_test(
25429      ".foo { grid: repeat(3, [line1 line2 line3] 200px) / auto-flow 300px }",
25430      ".foo{grid:repeat(3,[line1 line2 line3]200px)/auto-flow 300px}",
25431    );
25432    minify_test(
25433      ".foo { grid: [line1] minmax(20em, max-content) / auto-flow dense 40% }",
25434      ".foo{grid:[line1]minmax(20em,max-content)/auto-flow dense 40%}",
25435    );
25436    minify_test(".foo { grid: none / auto-flow 1fr }", ".foo{grid:none/auto-flow 1fr}");
25437
25438    minify_test(".foo { grid: auto-flow / 200px }", ".foo{grid:none/200px}");
25439    minify_test(".foo { grid: auto-flow dense / 30% }", ".foo{grid:auto-flow dense/30%}");
25440    minify_test(".foo { grid: dense auto-flow / 30% }", ".foo{grid:auto-flow dense/30%}");
25441    minify_test(
25442      ".foo { grid: auto-flow 300px / repeat(3, [line1 line2 line3] 200px) }",
25443      ".foo{grid:auto-flow 300px/repeat(3,[line1 line2 line3]200px)}",
25444    );
25445    minify_test(
25446      ".foo { grid: auto-flow dense 40% / [line1] minmax(20em, max-content) }",
25447      ".foo{grid:auto-flow dense 40%/[line1]minmax(20em,max-content)}",
25448    );
25449
25450    minify_test(".foo { grid-row-start: auto }", ".foo{grid-row-start:auto}");
25451    minify_test(".foo { grid-row-start: some-area }", ".foo{grid-row-start:some-area}");
25452    minify_test(".foo { grid-row-start: 2 }", ".foo{grid-row-start:2}");
25453    minify_test(
25454      ".foo { grid-row-start: 2 some-line }",
25455      ".foo{grid-row-start:2 some-line}",
25456    );
25457    minify_test(
25458      ".foo { grid-row-start: some-line 2 }",
25459      ".foo{grid-row-start:2 some-line}",
25460    );
25461    minify_test(".foo { grid-row-start: span 3 }", ".foo{grid-row-start:span 3}");
25462    minify_test(
25463      ".foo { grid-row-start: span some-line }",
25464      ".foo{grid-row-start:span some-line}",
25465    );
25466    minify_test(
25467      ".foo { grid-row-start: span some-line 1 }",
25468      ".foo{grid-row-start:span some-line}",
25469    );
25470    minify_test(
25471      ".foo { grid-row-start: span 1 some-line }",
25472      ".foo{grid-row-start:span some-line}",
25473    );
25474    minify_test(
25475      ".foo { grid-row-start: span 5 some-line }",
25476      ".foo{grid-row-start:span 5 some-line}",
25477    );
25478    minify_test(
25479      ".foo { grid-row-start: span some-line 5 }",
25480      ".foo{grid-row-start:span 5 some-line}",
25481    );
25482
25483    minify_test(
25484      ".foo { grid-row-end: span 1 some-line }",
25485      ".foo{grid-row-end:span some-line}",
25486    );
25487    minify_test(
25488      ".foo { grid-column-start: span 1 some-line }",
25489      ".foo{grid-column-start:span some-line}",
25490    );
25491    minify_test(
25492      ".foo { grid-column-end: span 1 some-line }",
25493      ".foo{grid-column-end:span some-line}",
25494    );
25495
25496    minify_test(".foo { grid-row: 1 }", ".foo{grid-row:1}");
25497    minify_test(".foo { grid-row: 1 / auto }", ".foo{grid-row:1}");
25498    minify_test(".foo { grid-row: 1 / 1 }", ".foo{grid-row:1/1}");
25499    minify_test(".foo { grid-row: 1 / 3 }", ".foo{grid-row:1/3}");
25500    minify_test(".foo { grid-row: 1 / span 2 }", ".foo{grid-row:1/span 2}");
25501    minify_test(".foo { grid-row: main-start }", ".foo{grid-row:main-start}");
25502    minify_test(
25503      ".foo { grid-row: main-start / main-end }",
25504      ".foo{grid-row:main-start/main-end}",
25505    );
25506    minify_test(
25507      ".foo { grid-row: main-start / main-start }",
25508      ".foo{grid-row:main-start}",
25509    );
25510    minify_test(".foo { grid-column: 1 / auto }", ".foo{grid-column:1}");
25511
25512    minify_test(".foo { grid-area: a }", ".foo{grid-area:a}");
25513    minify_test(".foo { grid-area: a / a / a / a }", ".foo{grid-area:a}");
25514    minify_test(".foo { grid-area: a / b / a / b }", ".foo{grid-area:a/b}");
25515    minify_test(".foo { grid-area: a / b / c / b }", ".foo{grid-area:a/b/c}");
25516    minify_test(".foo { grid-area: a / b / c / d }", ".foo{grid-area:a/b/c/d}");
25517
25518    minify_test(".foo { grid-area: auto / auto / auto / auto }", ".foo{grid-area:auto}");
25519    minify_test(".foo { grid-area: 1 / auto }", ".foo{grid-area:1}");
25520    minify_test(".foo { grid-area: 1 / 2 / 3 / 4 }", ".foo{grid-area:1/2/3/4}");
25521    minify_test(".foo { grid-area: 1 / 1 / 1 / 1 }", ".foo{grid-area:1/1/1/1}");
25522
25523    test(
25524      r#"
25525        .foo{
25526          grid-template-rows: auto 1fr;
25527          grid-template-columns: auto 1fr auto;
25528          grid-template-areas: none;
25529        }
25530      "#,
25531      indoc! {r#"
25532        .foo {
25533          grid-template: auto 1fr / auto 1fr auto;
25534        }
25535      "#},
25536    );
25537
25538    test(
25539      r#"
25540        .foo{
25541          grid-template-areas: "a a a"
25542                               "b b b";
25543          grid-template-rows: [header-top] auto [header-bottom main-top] 1fr [main-bottom];
25544          grid-template-columns: auto 1fr auto;
25545        }
25546      "#,
25547      indoc! {r#"
25548        .foo {
25549          grid-template: [header-top] "a a a" [header-bottom]
25550                         [main-top] "b b b" 1fr [main-bottom]
25551                         / auto 1fr auto;
25552        }
25553      "#},
25554    );
25555
25556    test(
25557      r#"
25558        .foo{
25559          grid-template-areas: "a a a"
25560                               "b b b";
25561          grid-template-columns: repeat(3, 1fr);
25562          grid-template-rows: auto 1fr;
25563        }
25564      "#,
25565      indoc! {r#"
25566        .foo {
25567          grid-template-rows: auto 1fr;
25568          grid-template-columns: repeat(3, 1fr);
25569          grid-template-areas: "a a a"
25570                               "b b b";
25571        }
25572      "#},
25573    );
25574
25575    test(
25576      r#"
25577        .foo{
25578          grid-template-areas: "a a a"
25579                               "b b b";
25580          grid-template-columns: auto 1fr auto;
25581          grid-template-rows: repeat(2, 1fr);
25582        }
25583      "#,
25584      indoc! {r#"
25585        .foo {
25586          grid-template-rows: repeat(2, 1fr);
25587          grid-template-columns: auto 1fr auto;
25588          grid-template-areas: "a a a"
25589                               "b b b";
25590        }
25591      "#},
25592    );
25593
25594    test(
25595      r#"
25596        .foo{
25597          grid-template-areas: ". a a ."
25598                               ". b b .";
25599          grid-template-rows: auto 1fr;
25600          grid-template-columns: 10px 1fr 1fr 10px;
25601        }
25602      "#,
25603      indoc! {r#"
25604        .foo {
25605          grid-template: ". a a ."
25606                         ". b b ." 1fr
25607                         / 10px 1fr 1fr 10px;
25608        }
25609      "#},
25610    );
25611
25612    test(
25613      r#"
25614        .foo{
25615          grid-template-areas: none;
25616          grid-template-columns: auto 1fr auto;
25617          grid-template-rows: repeat(2, 1fr);
25618        }
25619      "#,
25620      indoc! {r#"
25621        .foo {
25622          grid-template: repeat(2, 1fr) / auto 1fr auto;
25623        }
25624      "#},
25625    );
25626
25627    test(
25628      r#"
25629        .foo{
25630          grid-template-areas: none;
25631          grid-template-columns: none;
25632          grid-template-rows: none;
25633        }
25634      "#,
25635      indoc! {r#"
25636        .foo {
25637          grid-template: none;
25638        }
25639      "#},
25640    );
25641
25642    test(
25643      r#"
25644        .foo{
25645          grid-template-areas: "a a a"
25646                               "b b b";
25647          grid-template-rows: [header-top] auto [header-bottom main-top] 1fr [main-bottom];
25648          grid-template-columns: auto 1fr auto;
25649          grid-auto-flow: row;
25650          grid-auto-rows: auto;
25651          grid-auto-columns: auto;
25652        }
25653      "#,
25654      indoc! {r#"
25655        .foo {
25656          grid: [header-top] "a a a" [header-bottom]
25657                [main-top] "b b b" 1fr [main-bottom]
25658                / auto 1fr auto;
25659        }
25660      "#},
25661    );
25662
25663    test(
25664      r#"
25665        .foo{
25666          grid-template-areas: none;
25667          grid-template-columns: auto 1fr auto;
25668          grid-template-rows: repeat(2, 1fr);
25669          grid-auto-flow: row;
25670          grid-auto-rows: auto;
25671          grid-auto-columns: auto;
25672        }
25673      "#,
25674      indoc! {r#"
25675        .foo {
25676          grid: repeat(2, 1fr) / auto 1fr auto;
25677        }
25678      "#},
25679    );
25680
25681    test(
25682      r#"
25683        .foo{
25684          grid-template-areas: none;
25685          grid-template-columns: none;
25686          grid-template-rows: none;
25687          grid-auto-flow: row;
25688          grid-auto-rows: auto;
25689          grid-auto-columns: auto;
25690        }
25691      "#,
25692      indoc! {r#"
25693        .foo {
25694          grid: none;
25695        }
25696      "#},
25697    );
25698
25699    test(
25700      r#"
25701        .foo{
25702          grid-template-areas: "a a a"
25703                               "b b b";
25704          grid-template-rows: [header-top] auto [header-bottom main-top] 1fr [main-bottom];
25705          grid-template-columns: auto 1fr auto;
25706          grid-auto-flow: column;
25707          grid-auto-rows: 1fr;
25708          grid-auto-columns: 1fr;
25709        }
25710      "#,
25711      indoc! {r#"
25712        .foo {
25713          grid-template: [header-top] "a a a" [header-bottom]
25714                         [main-top] "b b b" 1fr [main-bottom]
25715                         / auto 1fr auto;
25716          grid-auto-rows: 1fr;
25717          grid-auto-columns: 1fr;
25718          grid-auto-flow: column;
25719        }
25720      "#},
25721    );
25722
25723    test(
25724      r#"
25725        .foo{
25726          grid-template-rows: auto 1fr;
25727          grid-template-columns: auto 1fr auto;
25728          grid-template-areas: none;
25729          grid-auto-flow: row;
25730          grid-auto-rows: auto;
25731          grid-auto-columns: auto;
25732        }
25733      "#,
25734      indoc! {r#"
25735        .foo {
25736          grid: auto 1fr / auto 1fr auto;
25737        }
25738      "#},
25739    );
25740
25741    test(
25742      r#"
25743        .foo{
25744          grid-template-rows: auto 1fr;
25745          grid-template-columns: auto 1fr auto;
25746          grid-template-areas: none;
25747          grid-auto-flow: column;
25748          grid-auto-rows: 1fr;
25749          grid-auto-columns: 1fr;
25750        }
25751      "#,
25752      indoc! {r#"
25753        .foo {
25754          grid-template: auto 1fr / auto 1fr auto;
25755          grid-auto-rows: 1fr;
25756          grid-auto-columns: 1fr;
25757          grid-auto-flow: column;
25758        }
25759      "#},
25760    );
25761
25762    test(
25763      r#"
25764        .foo{
25765          grid-template-rows: none;
25766          grid-template-columns: auto 1fr auto;
25767          grid-template-areas: none;
25768          grid-auto-flow: column;
25769          grid-auto-rows: 1fr;
25770          grid-auto-columns: 1fr;
25771        }
25772      "#,
25773      indoc! {r#"
25774        .foo {
25775          grid-template: none / auto 1fr auto;
25776          grid-auto-rows: 1fr;
25777          grid-auto-columns: 1fr;
25778          grid-auto-flow: column;
25779        }
25780      "#},
25781    );
25782
25783    test(
25784      r#"
25785        .foo{
25786          grid-template-rows: none;
25787          grid-template-columns: auto 1fr auto;
25788          grid-template-areas: none;
25789          grid-auto-flow: row;
25790          grid-auto-rows: 1fr;
25791          grid-auto-columns: auto;
25792        }
25793      "#,
25794      indoc! {r#"
25795        .foo {
25796          grid: auto-flow 1fr / auto 1fr auto;
25797        }
25798      "#},
25799    );
25800
25801    test(
25802      r#"
25803        .foo{
25804          grid-template-rows: none;
25805          grid-template-columns: auto 1fr auto;
25806          grid-template-areas: none;
25807          grid-auto-flow: row dense;
25808          grid-auto-rows: 1fr;
25809          grid-auto-columns: auto;
25810        }
25811      "#,
25812      indoc! {r#"
25813        .foo {
25814          grid: auto-flow dense 1fr / auto 1fr auto;
25815        }
25816      "#},
25817    );
25818
25819    test(
25820      r#"
25821        .foo{
25822          grid-template-rows: auto 1fr auto;
25823          grid-template-columns: none;
25824          grid-template-areas: none;
25825          grid-auto-flow: column;
25826          grid-auto-rows: auto;
25827          grid-auto-columns: 1fr;
25828        }
25829      "#,
25830      indoc! {r#"
25831        .foo {
25832          grid: auto 1fr auto / auto-flow 1fr;
25833        }
25834      "#},
25835    );
25836
25837    test(
25838      r#"
25839        .foo{
25840          grid-template-rows: auto 1fr auto;
25841          grid-template-columns: none;
25842          grid-template-areas: none;
25843          grid-auto-flow: column dense;
25844          grid-auto-rows: auto;
25845          grid-auto-columns: 1fr;
25846        }
25847      "#,
25848      indoc! {r#"
25849        .foo {
25850          grid: auto 1fr auto / auto-flow dense 1fr;
25851        }
25852      "#},
25853    );
25854
25855    test(
25856      r#"
25857        .foo{
25858          grid-template-rows: auto 1fr auto;
25859          grid-template-columns: none;
25860          grid-template-areas: none;
25861          grid-auto-flow: var(--auto-flow);
25862          grid-auto-rows: auto;
25863          grid-auto-columns: 1fr;
25864        }
25865      "#,
25866      indoc! {r#"
25867        .foo {
25868          grid-template: auto 1fr auto / none;
25869          grid-auto-flow: var(--auto-flow);
25870          grid-auto-rows: auto;
25871          grid-auto-columns: 1fr;
25872        }
25873      "#},
25874    );
25875
25876    test(
25877      r#"
25878        .foo{
25879          grid: auto 1fr auto / auto-flow dense 1fr;
25880          grid-template-rows: 1fr 1fr 1fr;
25881        }
25882      "#,
25883      indoc! {r#"
25884        .foo {
25885          grid: 1fr 1fr 1fr / auto-flow dense 1fr;
25886        }
25887      "#},
25888    );
25889
25890    test(
25891      r#"
25892        .foo{
25893          grid-row-start: a;
25894          grid-row-end: a;
25895          grid-column-start: a;
25896          grid-column-end: a;
25897        }
25898      "#,
25899      indoc! {r#"
25900        .foo {
25901          grid-area: a;
25902        }
25903      "#},
25904    );
25905
25906    test(
25907      r#"
25908        .foo{
25909          grid-row-start: 1;
25910          grid-row-end: 2;
25911          grid-column-start: 3;
25912          grid-column-end: 4;
25913        }
25914      "#,
25915      indoc! {r#"
25916        .foo {
25917          grid-area: 1 / 3 / 2 / 4;
25918        }
25919      "#},
25920    );
25921
25922    test(
25923      r#"
25924        .foo{
25925          grid-row-start: a;
25926          grid-row-end: a;
25927        }
25928      "#,
25929      indoc! {r#"
25930        .foo {
25931          grid-row: a;
25932        }
25933      "#},
25934    );
25935
25936    test(
25937      r#"
25938        .foo{
25939          grid-column-start: a;
25940          grid-column-end: a;
25941        }
25942      "#,
25943      indoc! {r#"
25944        .foo {
25945          grid-column: a;
25946        }
25947      "#},
25948    );
25949  }
25950
25951  #[test]
25952  fn test_moz_document() {
25953    minify_test(
25954      r#"
25955      @-moz-document url-prefix() {
25956        h1 {
25957          color: yellow;
25958        }
25959      }
25960    "#,
25961      "@-moz-document url-prefix(){h1{color:#ff0}}",
25962    );
25963    minify_test(
25964      r#"
25965      @-moz-document url-prefix("") {
25966        h1 {
25967          color: yellow;
25968        }
25969      }
25970    "#,
25971      "@-moz-document url-prefix(){h1{color:#ff0}}",
25972    );
25973    error_test(
25974      "@-moz-document url-prefix(foo) {}",
25975      ParserError::UnexpectedToken(crate::properties::custom::Token::Ident("foo".into())),
25976    );
25977    error_test(
25978      "@-moz-document url-prefix(\"foo\") {}",
25979      ParserError::UnexpectedToken(crate::properties::custom::Token::String("foo".into())),
25980    );
25981  }
25982
25983  #[test]
25984  fn test_custom_properties() {
25985    minify_test(".foo { --test: ; }", ".foo{--test: }");
25986    minify_test(".foo { --test:  ; }", ".foo{--test: }");
25987    minify_test(".foo { --test: foo; }", ".foo{--test:foo}");
25988    minify_test(".foo { --test:  foo; }", ".foo{--test:foo}");
25989    minify_test(".foo { --test: foo ; }", ".foo{--test:foo}");
25990    minify_test(".foo { --test: foo  ; }", ".foo{--test:foo}");
25991    minify_test(".foo { --test:foo; }", ".foo{--test:foo}");
25992    minify_test(".foo { --test:foo ; }", ".foo{--test:foo}");
25993    minify_test(".foo { --test: var(--foo, 20px); }", ".foo{--test:var(--foo,20px)}");
25994    minify_test(
25995      ".foo { transition: var(--foo, 20px),\nvar(--bar, 40px); }",
25996      ".foo{transition:var(--foo,20px), var(--bar,40px)}",
25997    );
25998    minify_test(
25999      ".foo { background: var(--color) var(--image); }",
26000      ".foo{background:var(--color) var(--image)}",
26001    );
26002    minify_test(
26003      ".foo { height: calc(var(--spectrum-global-dimension-size-300) / 2);",
26004      ".foo{height:calc(var(--spectrum-global-dimension-size-300) / 2)}",
26005    );
26006    minify_test(
26007      ".foo { color: var(--color, rgb(255, 255, 0)); }",
26008      ".foo{color:var(--color,#ff0)}",
26009    );
26010    minify_test(
26011      ".foo { color: var(--color, #ffff00); }",
26012      ".foo{color:var(--color,#ff0)}",
26013    );
26014    minify_test(
26015      ".foo { color: var(--color, rgb(var(--red), var(--green), 0)); }",
26016      ".foo{color:var(--color,rgb(var(--red), var(--green), 0))}",
26017    );
26018    minify_test(".foo { --test: .5s; }", ".foo{--test:.5s}");
26019    minify_test(".foo { --theme-sizes-1\\/12: 2 }", ".foo{--theme-sizes-1\\/12:2}");
26020    minify_test(".foo { --test: 0px; }", ".foo{--test:0px}");
26021    test(
26022      ".foo { transform: var(--bar, ) }",
26023      indoc! {r#"
26024      .foo {
26025        transform: var(--bar, );
26026      }
26027      "#},
26028    );
26029    test(
26030      ".foo { transform: env(--bar, ) }",
26031      indoc! {r#"
26032      .foo {
26033        transform: env(--bar, );
26034      }
26035      "#},
26036    );
26037
26038    // Test attr() function with type() syntax - minified
26039    minify_test(
26040      ".foo { background-color: attr(data-color type(<color>)); }",
26041      ".foo{background-color:attr(data-color type(<color>))}",
26042    );
26043    minify_test(
26044      ".foo { width: attr(data-width type(<length>), 100px); }",
26045      ".foo{width:attr(data-width type(<length>), 100px)}",
26046    );
26047
26048    minify_test(".foo { width: attr( data-foo    % ); }", ".foo{width:attr(data-foo %)}");
26049
26050    // <attr-args> = attr( <declaration-value>, <declaration-value>? )
26051    // 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.
26052    // Spec: https://drafts.csswg.org/css-values-5/#funcdef-attr
26053    minify_test(
26054      ".foo { width: attr( data-foo    %, ); }",
26055      ".foo{width:attr(data-foo %,)}",
26056    );
26057
26058    minify_test(
26059      ".foo { width: attr( data-foo    px ); }",
26060      ".foo{width:attr(data-foo px)}",
26061    );
26062
26063    minify_test(
26064      ".foo { width: attr(data-foo    number ); }",
26065      ".foo{width:attr(data-foo number)}",
26066    );
26067
26068    minify_test(
26069      ".foo { width: attr(data-foo    raw-string); }",
26070      ".foo{width:attr(data-foo raw-string)}",
26071    );
26072
26073    // Test attr() function with type() syntax - non-minified (issue with extra spaces)
26074    test(
26075      ".foo { background-color: attr(data-color type(<color>)); }",
26076      ".foo {\n  background-color: attr(data-color type(<color>));\n}\n",
26077    );
26078    test(
26079      ".foo { width: attr(data-width type(<length>), 100px); }",
26080      ".foo {\n  width: attr(data-width type(<length>), 100px);\n}\n",
26081    );
26082
26083    prefix_test(
26084      r#"
26085      .foo {
26086        --custom: lab(40% 56.6 39);
26087      }
26088    "#,
26089      indoc! {r#"
26090      .foo {
26091        --custom: #b32323;
26092      }
26093
26094      @supports (color: lab(0% 0 0)) {
26095        .foo {
26096          --custom: lab(40% 56.6 39);
26097        }
26098      }
26099    "#},
26100      Browsers {
26101        chrome: Some(90 << 16),
26102        ..Browsers::default()
26103      },
26104    );
26105
26106    prefix_test(
26107      r#"
26108      @supports (color: lab(0% 0 0)) {
26109        .foo {
26110          --custom: lab(40% 56.6 39);
26111        }
26112      }
26113    "#,
26114      indoc! {r#"
26115      @supports (color: lab(0% 0 0)) {
26116        .foo {
26117          --custom: lab(40% 56.6 39);
26118        }
26119      }
26120    "#},
26121      Browsers {
26122        chrome: Some(90 << 16),
26123        ..Browsers::default()
26124      },
26125    );
26126
26127    prefix_test(
26128      r#"
26129      .foo {
26130        --custom: lab(40% 56.6 39) !important;
26131      }
26132    "#,
26133      indoc! {r#"
26134      .foo {
26135        --custom: #b32323 !important;
26136      }
26137
26138      @supports (color: lab(0% 0 0)) {
26139        .foo {
26140          --custom: lab(40% 56.6 39) !important;
26141        }
26142      }
26143    "#},
26144      Browsers {
26145        chrome: Some(90 << 16),
26146        ..Browsers::default()
26147      },
26148    );
26149
26150    prefix_test(
26151      r#"
26152      @supports (color: lab(0% 0 0)) {
26153        .foo {
26154          --custom: lab(40% 56.6 39) !important;
26155        }
26156      }
26157    "#,
26158      indoc! {r#"
26159      @supports (color: lab(0% 0 0)) {
26160        .foo {
26161          --custom: lab(40% 56.6 39) !important;
26162        }
26163      }
26164    "#},
26165      Browsers {
26166        chrome: Some(90 << 16),
26167        ..Browsers::default()
26168      },
26169    );
26170
26171    prefix_test(
26172      r#"
26173      .foo {
26174        --custom: lab(40% 56.6 39);
26175      }
26176    "#,
26177      indoc! {r#"
26178      .foo {
26179        --custom: #b32323;
26180      }
26181
26182      @supports (color: color(display-p3 0 0 0)) {
26183        .foo {
26184          --custom: color(display-p3 .643308 .192455 .167712);
26185        }
26186      }
26187
26188      @supports (color: lab(0% 0 0)) {
26189        .foo {
26190          --custom: lab(40% 56.6 39);
26191        }
26192      }
26193    "#},
26194      Browsers {
26195        chrome: Some(90 << 16),
26196        safari: Some(14 << 16),
26197        ..Browsers::default()
26198      },
26199    );
26200
26201    prefix_test(
26202      r#"
26203      @supports (color: color(display-p3 0 0 0)) {
26204        .foo {
26205          --custom: color(display-p3 .643308 .192455 .167712);
26206        }
26207      }
26208
26209      @supports (color: lab(0% 0 0)) {
26210        .foo {
26211          --custom: lab(40% 56.6 39);
26212        }
26213      }
26214    "#,
26215      indoc! {r#"
26216      @supports (color: color(display-p3 0 0 0)) {
26217        .foo {
26218          --custom: color(display-p3 .643308 .192455 .167712);
26219        }
26220      }
26221
26222      @supports (color: lab(0% 0 0)) {
26223        .foo {
26224          --custom: lab(40% 56.6 39);
26225        }
26226      }
26227    "#},
26228      Browsers {
26229        chrome: Some(90 << 16),
26230        safari: Some(14 << 16),
26231        ..Browsers::default()
26232      },
26233    );
26234
26235    prefix_test(
26236      r#"
26237      .foo {
26238        --custom: lab(40% 56.6 39);
26239      }
26240    "#,
26241      indoc! {r#"
26242      .foo {
26243        --custom: color(display-p3 .643308 .192455 .167712);
26244      }
26245
26246      @supports (color: lab(0% 0 0)) {
26247        .foo {
26248          --custom: lab(40% 56.6 39);
26249        }
26250      }
26251    "#},
26252      Browsers {
26253        safari: Some(14 << 16),
26254        ..Browsers::default()
26255      },
26256    );
26257
26258    prefix_test(
26259      r#"
26260      .foo {
26261        --custom: lab(40% 56.6 39);
26262      }
26263    "#,
26264      indoc! {r#"
26265      .foo {
26266        --custom: lab(40% 56.6 39);
26267      }
26268    "#},
26269      Browsers {
26270        safari: Some(15 << 16),
26271        ..Browsers::default()
26272      },
26273    );
26274
26275    prefix_test(
26276      r#"
26277      .foo {
26278        --custom: oklab(59.686% 0.1009 0.1192);
26279      }
26280    "#,
26281      indoc! {r#"
26282      .foo {
26283        --custom: lab(52.2319% 40.1449 59.9171);
26284      }
26285    "#},
26286      Browsers {
26287        safari: Some(15 << 16),
26288        ..Browsers::default()
26289      },
26290    );
26291
26292    prefix_test(
26293      r#"
26294      .foo {
26295        --custom: oklab(59.686% 0.1009 0.1192);
26296      }
26297    "#,
26298      indoc! {r#"
26299      .foo {
26300        --custom: color(display-p3 .724144 .386777 .148795);
26301      }
26302
26303      @supports (color: lab(0% 0 0)) {
26304        .foo {
26305          --custom: lab(52.2319% 40.1449 59.9171);
26306        }
26307      }
26308    "#},
26309      Browsers {
26310        safari: Some(14 << 16),
26311        ..Browsers::default()
26312      },
26313    );
26314
26315    prefix_test(
26316      r#"
26317      .foo {
26318        --custom: oklab(59.686% 0.1009 0.1192);
26319      }
26320    "#,
26321      indoc! {r#"
26322      .foo {
26323        --custom: #c65d07;
26324      }
26325
26326      @supports (color: color(display-p3 0 0 0)) {
26327        .foo {
26328          --custom: color(display-p3 .724144 .386777 .148795);
26329        }
26330      }
26331
26332      @supports (color: lab(0% 0 0)) {
26333        .foo {
26334          --custom: lab(52.2319% 40.1449 59.9171);
26335        }
26336      }
26337    "#},
26338      Browsers {
26339        safari: Some(14 << 16),
26340        chrome: Some(90 << 16),
26341        ..Browsers::default()
26342      },
26343    );
26344
26345    prefix_test(
26346      r#"
26347      .foo {
26348        --foo: oklab(59.686% 0.1009 0.1192);
26349        --bar: lab(40% 56.6 39);
26350      }
26351    "#,
26352      indoc! {r#"
26353      .foo {
26354        --foo: #c65d07;
26355        --bar: #b32323;
26356      }
26357
26358      @supports (color: color(display-p3 0 0 0)) {
26359        .foo {
26360          --foo: color(display-p3 .724144 .386777 .148795);
26361          --bar: color(display-p3 .643308 .192455 .167712);
26362        }
26363      }
26364
26365      @supports (color: lab(0% 0 0)) {
26366        .foo {
26367          --foo: lab(52.2319% 40.1449 59.9171);
26368          --bar: lab(40% 56.6 39);
26369        }
26370      }
26371    "#},
26372      Browsers {
26373        safari: Some(14 << 16),
26374        chrome: Some(90 << 16),
26375        ..Browsers::default()
26376      },
26377    );
26378
26379    prefix_test(
26380      r#"
26381      .foo {
26382        --foo: color(display-p3 0 1 0);
26383      }
26384    "#,
26385      indoc! {r#"
26386      .foo {
26387        --foo: #00fb29;
26388      }
26389
26390      @supports (color: color(display-p3 0 0 0)) {
26391        .foo {
26392          --foo: color(display-p3 0 1 0);
26393        }
26394      }
26395    "#},
26396      Browsers {
26397        safari: Some(14 << 16),
26398        chrome: Some(90 << 16),
26399        ..Browsers::default()
26400      },
26401    );
26402
26403    prefix_test(
26404      r#"
26405      @supports (color: color(display-p3 0 0 0)) {
26406        .foo {
26407          --foo: color(display-p3 0 1 0);
26408        }
26409      }
26410    "#,
26411      indoc! {r#"
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      .foo {
26428        --foo: color(display-p3 0 1 0);
26429      }
26430    "#,
26431      indoc! {r#"
26432      .foo {
26433        --foo: color(display-p3 0 1 0);
26434      }
26435    "#},
26436      Browsers {
26437        safari: Some(14 << 16),
26438        ..Browsers::default()
26439      },
26440    );
26441
26442    prefix_test(
26443      r#"
26444      .foo {
26445        --foo: color(display-p3 0 1 0);
26446      }
26447    "#,
26448      indoc! {r#"
26449      .foo {
26450        --foo: #00fb29;
26451      }
26452
26453      @supports (color: color(display-p3 0 0 0)) {
26454        .foo {
26455          --foo: color(display-p3 0 1 0);
26456        }
26457      }
26458    "#},
26459      Browsers {
26460        safari: Some(15 << 16),
26461        chrome: Some(90 << 16),
26462        ..Browsers::default()
26463      },
26464    );
26465
26466    prefix_test(
26467      r#"
26468      .foo {
26469        --foo: color(display-p3 0 1 0);
26470      }
26471    "#,
26472      indoc! {r#"
26473      .foo {
26474        --foo: #00fb29;
26475      }
26476
26477      @supports (color: color(display-p3 0 0 0)) {
26478        .foo {
26479          --foo: color(display-p3 0 1 0);
26480        }
26481      }
26482    "#},
26483      Browsers {
26484        chrome: Some(90 << 16),
26485        ..Browsers::default()
26486      },
26487    );
26488
26489    prefix_test(
26490      r#"
26491      .foo {
26492        text-decoration: underline;
26493      }
26494
26495      .foo {
26496        --custom: lab(40% 56.6 39);
26497      }
26498    "#,
26499      indoc! {r#"
26500      .foo {
26501        --custom: #b32323;
26502        text-decoration: underline;
26503      }
26504
26505      @supports (color: lab(0% 0 0)) {
26506        .foo {
26507          --custom: lab(40% 56.6 39);
26508        }
26509      }
26510    "#},
26511      Browsers {
26512        chrome: Some(90 << 16),
26513        ..Browsers::default()
26514      },
26515    );
26516
26517    prefix_test(
26518      r#"
26519      .foo {
26520        --custom: lab(40% 56.6 39);
26521      }
26522
26523      .foo {
26524        text-decoration: underline;
26525      }
26526    "#,
26527      indoc! {r#"
26528      .foo {
26529        --custom: #b32323;
26530      }
26531
26532      @supports (color: lab(0% 0 0)) {
26533        .foo {
26534          --custom: lab(40% 56.6 39);
26535        }
26536      }
26537
26538      .foo {
26539        text-decoration: underline;
26540      }
26541    "#},
26542      Browsers {
26543        chrome: Some(90 << 16),
26544        ..Browsers::default()
26545      },
26546    );
26547
26548    prefix_test(
26549      r#"
26550      @keyframes foo {
26551        from {
26552          --custom: lab(40% 56.6 39);
26553        }
26554
26555        to {
26556          --custom: lch(50.998% 135.363 338);
26557        }
26558      }
26559    "#,
26560      indoc! {r#"
26561      @keyframes foo {
26562        from {
26563          --custom: #b32323;
26564        }
26565
26566        to {
26567          --custom: #f000c0;
26568        }
26569      }
26570
26571      @supports (color: lab(0% 0 0)) {
26572        @keyframes foo {
26573          from {
26574            --custom: lab(40% 56.6 39);
26575          }
26576
26577          to {
26578            --custom: lab(50.998% 125.506 -50.7078);
26579          }
26580        }
26581      }
26582    "#},
26583      Browsers {
26584        chrome: Some(90 << 16),
26585        ..Browsers::default()
26586      },
26587    );
26588
26589    prefix_test(
26590      r#"
26591      @supports (color: lab(0% 0 0)) {
26592        @keyframes foo {
26593          from {
26594            --custom: lab(40% 56.6 39);
26595          }
26596
26597          to {
26598            --custom: lab(50.998% 125.506 -50.7078);
26599          }
26600        }
26601      }
26602    "#,
26603      indoc! {r#"
26604      @supports (color: lab(0% 0 0)) {
26605        @keyframes foo {
26606          from {
26607            --custom: lab(40% 56.6 39);
26608          }
26609
26610          to {
26611            --custom: lab(50.998% 125.506 -50.7078);
26612          }
26613        }
26614      }
26615    "#},
26616      Browsers {
26617        chrome: Some(90 << 16),
26618        ..Browsers::default()
26619      },
26620    );
26621
26622    prefix_test(
26623      r#"
26624      @keyframes foo {
26625        from {
26626          --custom: lab(40% 56.6 39);
26627        }
26628
26629        to {
26630          --custom: lch(50.998% 135.363 338);
26631        }
26632      }
26633    "#,
26634      indoc! {r#"
26635      @keyframes foo {
26636        from {
26637          --custom: #b32323;
26638        }
26639
26640        to {
26641          --custom: #f000c0;
26642        }
26643      }
26644
26645      @supports (color: color(display-p3 0 0 0)) {
26646        @keyframes foo {
26647          from {
26648            --custom: color(display-p3 .643308 .192455 .167712);
26649          }
26650
26651          to {
26652            --custom: color(display-p3 .972962 -.362078 .804206);
26653          }
26654        }
26655      }
26656
26657      @supports (color: lab(0% 0 0)) {
26658        @keyframes foo {
26659          from {
26660            --custom: lab(40% 56.6 39);
26661          }
26662
26663          to {
26664            --custom: lab(50.998% 125.506 -50.7078);
26665          }
26666        }
26667      }
26668    "#},
26669      Browsers {
26670        chrome: Some(90 << 16),
26671        safari: Some(14 << 16),
26672        ..Browsers::default()
26673      },
26674    );
26675
26676    prefix_test(
26677      r#"
26678      @supports (color: color(display-p3 0 0 0)) {
26679        @keyframes foo {
26680          from {
26681            --custom: color(display-p3 .643308 .192455 .167712);
26682          }
26683
26684          to {
26685            --custom: color(display-p3 .972962 -.362078 .804206);
26686          }
26687        }
26688      }
26689
26690      @supports (color: lab(0% 0 0)) {
26691        @keyframes foo {
26692          from {
26693            --custom: lab(40% 56.6 39);
26694          }
26695
26696          to {
26697            --custom: lab(50.998% 125.506 -50.7078);
26698          }
26699        }
26700      }
26701    "#,
26702      indoc! {r#"
26703      @supports (color: color(display-p3 0 0 0)) {
26704        @keyframes foo {
26705          from {
26706            --custom: color(display-p3 .643308 .192455 .167712);
26707          }
26708
26709          to {
26710            --custom: color(display-p3 .972962 -.362078 .804206);
26711          }
26712        }
26713      }
26714
26715      @supports (color: lab(0% 0 0)) {
26716        @keyframes foo {
26717          from {
26718            --custom: lab(40% 56.6 39);
26719          }
26720
26721          to {
26722            --custom: lab(50.998% 125.506 -50.7078);
26723          }
26724        }
26725      }
26726    "#},
26727      Browsers {
26728        chrome: Some(90 << 16),
26729        safari: Some(14 << 16),
26730        ..Browsers::default()
26731      },
26732    );
26733
26734    prefix_test(
26735      r#"
26736      @keyframes foo {
26737        from {
26738          --custom: #ff0;
26739          opacity: 0;
26740        }
26741
26742        to {
26743          --custom: lch(50.998% 135.363 338);
26744          opacity: 1;
26745        }
26746      }
26747    "#,
26748      indoc! {r#"
26749      @keyframes foo {
26750        from {
26751          --custom: #ff0;
26752          opacity: 0;
26753        }
26754
26755        to {
26756          --custom: #f000c0;
26757          opacity: 1;
26758        }
26759      }
26760
26761      @supports (color: lab(0% 0 0)) {
26762        @keyframes foo {
26763          from {
26764            --custom: #ff0;
26765            opacity: 0;
26766          }
26767
26768          to {
26769            --custom: lab(50.998% 125.506 -50.7078);
26770            opacity: 1;
26771          }
26772        }
26773      }
26774    "#},
26775      Browsers {
26776        chrome: Some(90 << 16),
26777        ..Browsers::default()
26778      },
26779    );
26780
26781    prefix_test(
26782      r#"
26783      @keyframes foo {
26784        from {
26785          text-decoration: var(--foo) lab(29.2345% 39.3825 20.0664);
26786        }
26787      }
26788    "#,
26789      indoc! {r#"
26790      @keyframes foo {
26791        from {
26792          text-decoration: var(--foo) #7d2329;
26793        }
26794      }
26795
26796      @supports (color: lab(0% 0 0)) {
26797        @keyframes foo {
26798          from {
26799            text-decoration: var(--foo) lab(29.2345% 39.3825 20.0664);
26800          }
26801        }
26802      }
26803    "#},
26804      Browsers {
26805        chrome: Some(90 << 16),
26806        ..Browsers::default()
26807      },
26808    );
26809  }
26810
26811  #[test]
26812  fn test_charset() {
26813    test(
26814      r#"
26815      @charset "UTF-8";
26816
26817      .foo {
26818        color: red;
26819      }
26820
26821      @charset "UTF-8";
26822
26823      .bar {
26824        color: yellow;
26825      }
26826    "#,
26827      indoc! { r#"
26828      .foo {
26829        color: red;
26830      }
26831
26832      .bar {
26833        color: #ff0;
26834      }
26835    "#},
26836    )
26837  }
26838
26839  #[test]
26840  fn test_style_attr() {
26841    attr_test("color: yellow; flex: 1 1 auto", "color: #ff0; flex: auto", false, None);
26842    attr_test("color: yellow; flex: 1 1 auto", "color:#ff0;flex:auto", true, None);
26843    attr_test(
26844      "border-inline-start: 2px solid red",
26845      "border-inline-start: 2px solid red",
26846      false,
26847      Some(Browsers {
26848        safari: Some(12 << 16),
26849        ..Browsers::default()
26850      }),
26851    );
26852    attr_test(
26853      "color: lab(40% 56.6 39);",
26854      "color:#b32323;color:lab(40% 56.6 39)",
26855      true,
26856      Some(Browsers {
26857        safari: Some(8 << 16),
26858        ..Browsers::default()
26859      }),
26860    );
26861    attr_test(
26862      "--foo: lab(40% 56.6 39);",
26863      "--foo:#b32323",
26864      true,
26865      Some(Browsers {
26866        safari: Some(8 << 16),
26867        ..Browsers::default()
26868      }),
26869    );
26870    attr_test(
26871      "text-decoration: var(--foo) lab(40% 56.6 39);",
26872      "text-decoration:var(--foo) #b32323",
26873      true,
26874      Some(Browsers {
26875        chrome: Some(90 << 16),
26876        ..Browsers::default()
26877      }),
26878    );
26879  }
26880
26881  #[test]
26882  fn test_nesting() {
26883    nesting_test(
26884      r#"
26885        .foo {
26886          @apply --mixin;
26887          @apply --mixin-no-args();
26888          @apply --mixin-args(1, 2);
26889          @apply --mixin-with-empty-body {};
26890          @apply --mixin-with-body {
26891            color: red;
26892          }
26893          .bar {
26894            @apply --nested;
26895          }
26896        }
26897      "#,
26898      indoc! {r#"
26899        .foo {
26900          @apply --mixin;
26901          @apply --mixin-no-args();
26902          @apply --mixin-args(1, 2);
26903          @apply --mixin-with-empty-body {
26904            
26905          }
26906          @apply --mixin-with-body {
26907            color: red;
26908          }
26909        }
26910
26911        .foo .bar {
26912          @apply --nested;
26913        }
26914      "#},
26915    );
26916
26917    minify_test(
26918      r#"
26919        .foo {
26920          @apply --mixin;
26921          @apply --mixin-no-args();
26922          @apply --mixin-args(1,2);
26923          @apply --mixin-with-empty-body {};
26924          @apply --mixin-with-body {
26925            color: red;
26926          };
26927          .bar {
26928            @apply --nested;
26929          }
26930        }
26931      "#,
26932      ".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;}}",
26933    );
26934
26935    nesting_test(
26936      r#"
26937        .foo {
26938          color: blue;
26939          & > .bar { color: red; }
26940        }
26941      "#,
26942      indoc! {r#"
26943        .foo {
26944          color: #00f;
26945        }
26946
26947        .foo > .bar {
26948          color: red;
26949        }
26950      "#},
26951    );
26952
26953    nesting_test(
26954      r#"
26955        .foo {
26956          color: blue;
26957          &.bar { color: red; }
26958        }
26959      "#,
26960      indoc! {r#"
26961        .foo {
26962          color: #00f;
26963        }
26964
26965        .foo.bar {
26966          color: red;
26967        }
26968      "#},
26969    );
26970
26971    nesting_test(
26972      r#"
26973        .foo, .bar {
26974          color: blue;
26975          & + .baz, &.qux { color: red; }
26976        }
26977      "#,
26978      indoc! {r#"
26979        .foo, .bar {
26980          color: #00f;
26981        }
26982
26983        :is(.foo, .bar) + .baz, :is(.foo, .bar).qux {
26984          color: red;
26985        }
26986      "#},
26987    );
26988
26989    nesting_test(
26990      r#"
26991        .foo {
26992          color: blue;
26993          & .bar & .baz & .qux { color: red; }
26994        }
26995      "#,
26996      indoc! {r#"
26997        .foo {
26998          color: #00f;
26999        }
27000
27001        .foo .bar .foo .baz .foo .qux {
27002          color: red;
27003        }
27004      "#},
27005    );
27006
27007    nesting_test(
27008      r#"
27009        .foo {
27010          color: blue;
27011          & { padding: 2ch; }
27012        }
27013      "#,
27014      indoc! {r#"
27015        .foo {
27016          color: #00f;
27017        }
27018
27019        .foo {
27020          padding: 2ch;
27021        }
27022      "#},
27023    );
27024
27025    nesting_test(
27026      r#"
27027        .foo {
27028          color: blue;
27029          && { padding: 2ch; }
27030        }
27031      "#,
27032      indoc! {r#"
27033        .foo {
27034          color: #00f;
27035        }
27036
27037        .foo.foo {
27038          padding: 2ch;
27039        }
27040      "#},
27041    );
27042
27043    nesting_test(
27044      r#"
27045        .error, .invalid {
27046          &:hover > .baz { color: red; }
27047        }
27048      "#,
27049      indoc! {r#"
27050        :is(.error, .invalid):hover > .baz {
27051          color: red;
27052        }
27053      "#},
27054    );
27055
27056    nesting_test(
27057      r#"
27058        .foo {
27059          &:is(.bar, &.baz) { color: red; }
27060        }
27061      "#,
27062      indoc! {r#"
27063        .foo:is(.bar, .foo.baz) {
27064          color: red;
27065        }
27066      "#},
27067    );
27068
27069    nesting_test(
27070      r#"
27071        figure {
27072          margin: 0;
27073
27074          & > figcaption {
27075            background: hsl(0 0% 0% / 50%);
27076
27077            & > p {
27078              font-size: .9rem;
27079            }
27080          }
27081        }
27082      "#,
27083      indoc! {r#"
27084        figure {
27085          margin: 0;
27086        }
27087
27088        figure > figcaption {
27089          background: #00000080;
27090        }
27091
27092        figure > figcaption > p {
27093          font-size: .9rem;
27094        }
27095      "#},
27096    );
27097
27098    nesting_test(
27099      r#"
27100        .foo {
27101          display: grid;
27102
27103          @media (orientation: landscape) {
27104            grid-auto-flow: column;
27105          }
27106        }
27107      "#,
27108      indoc! {r#"
27109        .foo {
27110          display: grid;
27111        }
27112
27113        @media (orientation: landscape) {
27114          .foo {
27115            grid-auto-flow: column;
27116          }
27117        }
27118      "#},
27119    );
27120
27121    nesting_test(
27122      r#"
27123        .foo {
27124          display: grid;
27125
27126          @media (orientation: landscape) {
27127            grid-auto-flow: column;
27128
27129            @media (width > 1024px) {
27130              max-inline-size: 1024px;
27131            }
27132          }
27133        }
27134      "#,
27135      indoc! {r#"
27136        .foo {
27137          display: grid;
27138        }
27139
27140        @media (orientation: landscape) {
27141          .foo {
27142            grid-auto-flow: column;
27143          }
27144
27145          @media not (max-width: 1024px) {
27146            .foo {
27147              max-inline-size: 1024px;
27148            }
27149          }
27150        }
27151      "#},
27152    );
27153
27154    nesting_test(
27155      r#"
27156        .foo {
27157          @media (min-width: 640px) {
27158            color: red !important;
27159          }
27160        }
27161      "#,
27162      indoc! {r#"
27163        @media (min-width: 640px) {
27164          .foo {
27165            color: red !important;
27166          }
27167        }
27168      "#},
27169    );
27170
27171    nesting_test(
27172      r#"
27173        .foo {
27174          display: grid;
27175
27176          @supports (foo: bar) {
27177            grid-auto-flow: column;
27178          }
27179        }
27180      "#,
27181      indoc! {r#"
27182        .foo {
27183          display: grid;
27184        }
27185
27186        @supports (foo: bar) {
27187          .foo {
27188            grid-auto-flow: column;
27189          }
27190        }
27191      "#},
27192    );
27193
27194    nesting_test(
27195      r#"
27196        .foo {
27197          display: grid;
27198
27199          @container (min-width: 100px) {
27200            grid-auto-flow: column;
27201          }
27202        }
27203      "#,
27204      indoc! {r#"
27205        .foo {
27206          display: grid;
27207        }
27208
27209        @container (width >= 100px) {
27210          .foo {
27211            grid-auto-flow: column;
27212          }
27213        }
27214      "#},
27215    );
27216
27217    nesting_test(
27218      r#"
27219        .foo {
27220          display: grid;
27221
27222          @layer test {
27223            grid-auto-flow: column;
27224          }
27225        }
27226      "#,
27227      indoc! {r#"
27228        .foo {
27229          display: grid;
27230        }
27231
27232        @layer test {
27233          .foo {
27234            grid-auto-flow: column;
27235          }
27236        }
27237      "#},
27238    );
27239
27240    nesting_test(
27241      r#"
27242        .foo {
27243          display: grid;
27244
27245          @layer {
27246            grid-auto-flow: column;
27247          }
27248        }
27249      "#,
27250      indoc! {r#"
27251        .foo {
27252          display: grid;
27253        }
27254
27255        @layer {
27256          .foo {
27257            grid-auto-flow: column;
27258          }
27259        }
27260      "#},
27261    );
27262
27263    nesting_test(
27264      r#"
27265        @namespace "http://example.com/foo";
27266        @namespace toto "http://toto.example.org";
27267
27268        .foo {
27269          &div {
27270            color: red;
27271          }
27272
27273          &* {
27274            color: green;
27275          }
27276
27277          &|x {
27278            color: red;
27279          }
27280
27281          &*|x {
27282            color: green;
27283          }
27284
27285          &toto|x {
27286            color: red;
27287          }
27288        }
27289      "#,
27290      indoc! {r#"
27291        @namespace "http://example.com/foo";
27292        @namespace toto "http://toto.example.org";
27293
27294        div.foo {
27295          color: red;
27296        }
27297
27298        *.foo {
27299          color: green;
27300        }
27301
27302        |x.foo {
27303          color: red;
27304        }
27305
27306        *|x.foo {
27307          color: green;
27308        }
27309
27310        toto|x.foo {
27311          color: red;
27312        }
27313      "#},
27314    );
27315
27316    nesting_test(
27317      r#"
27318        .foo {
27319          &article > figure {
27320            color: red;
27321          }
27322        }
27323      "#,
27324      indoc! {r#"
27325        article.foo > figure {
27326          color: red;
27327        }
27328      "#},
27329    );
27330
27331    nesting_test(
27332      r#"
27333        div {
27334          &.bar {
27335            background: green;
27336          }
27337        }
27338      "#,
27339      indoc! {r#"
27340        div.bar {
27341          background: green;
27342        }
27343      "#},
27344    );
27345
27346    nesting_test(
27347      r#"
27348        div > .foo {
27349          &span {
27350            background: green;
27351          }
27352        }
27353      "#,
27354      indoc! {r#"
27355        span:is(div > .foo) {
27356          background: green;
27357        }
27358      "#},
27359    );
27360
27361    nesting_test(
27362      r#"
27363        .foo {
27364          & h1 {
27365            background: green;
27366          }
27367        }
27368      "#,
27369      indoc! {r#"
27370        .foo h1 {
27371          background: green;
27372        }
27373      "#},
27374    );
27375
27376    nesting_test(
27377      r#"
27378        .foo .bar {
27379          &h1 {
27380            background: green;
27381          }
27382        }
27383      "#,
27384      indoc! {r#"
27385        h1:is(.foo .bar) {
27386          background: green;
27387        }
27388      "#},
27389    );
27390
27391    nesting_test(
27392      r#"
27393        .foo.bar {
27394          &h1 {
27395            background: green;
27396          }
27397        }
27398      "#,
27399      indoc! {r#"
27400        h1.foo.bar {
27401          background: green;
27402        }
27403      "#},
27404    );
27405
27406    nesting_test(
27407      r#"
27408        .foo .bar {
27409          &h1 .baz {
27410            background: green;
27411          }
27412        }
27413      "#,
27414      indoc! {r#"
27415        h1:is(.foo .bar) .baz {
27416          background: green;
27417        }
27418      "#},
27419    );
27420
27421    nesting_test(
27422      r#"
27423        .foo .bar {
27424          &.baz {
27425            background: green;
27426          }
27427        }
27428      "#,
27429      indoc! {r#"
27430        .foo .bar.baz {
27431          background: green;
27432        }
27433      "#},
27434    );
27435
27436    nesting_test(
27437      r#"
27438        .foo {
27439          color: red;
27440          @nest .parent & {
27441            color: blue;
27442          }
27443        }
27444      "#,
27445      indoc! {r#"
27446        .foo {
27447          color: red;
27448        }
27449
27450        .parent .foo {
27451          color: #00f;
27452        }
27453      "#},
27454    );
27455
27456    nesting_test(
27457      r#"
27458        .foo {
27459          color: red;
27460          @nest :not(&) {
27461            color: blue;
27462          }
27463        }
27464      "#,
27465      indoc! {r#"
27466        .foo {
27467          color: red;
27468        }
27469
27470        :not(.foo) {
27471          color: #00f;
27472        }
27473      "#},
27474    );
27475
27476    nesting_test(
27477      r#"
27478        .foo {
27479          color: blue;
27480          @nest .bar & {
27481            color: red;
27482            &.baz {
27483              color: green;
27484            }
27485          }
27486        }
27487      "#,
27488      indoc! {r#"
27489        .foo {
27490          color: #00f;
27491        }
27492
27493        .bar .foo {
27494          color: red;
27495        }
27496
27497        .bar .foo.baz {
27498          color: green;
27499        }
27500      "#},
27501    );
27502
27503    nesting_test(
27504      r#"
27505        .foo {
27506          @nest :not(&) {
27507            color: red;
27508          }
27509
27510          & h1 {
27511            background: green;
27512          }
27513        }
27514      "#,
27515      indoc! {r#"
27516        :not(.foo) {
27517          color: red;
27518        }
27519
27520        .foo h1 {
27521          background: green;
27522        }
27523      "#},
27524    );
27525
27526    nesting_test(
27527      r#"
27528        .foo {
27529          & h1 {
27530            background: green;
27531          }
27532
27533          @nest :not(&) {
27534            color: red;
27535          }
27536        }
27537      "#,
27538      indoc! {r#"
27539        .foo h1 {
27540          background: green;
27541        }
27542
27543        :not(.foo) {
27544          color: red;
27545        }
27546      "#},
27547    );
27548
27549    nesting_test(
27550      r#"
27551        .foo .bar {
27552          @nest h1& {
27553            background: green;
27554          }
27555        }
27556      "#,
27557      indoc! {r#"
27558        h1:is(.foo .bar) {
27559          background: green;
27560        }
27561      "#},
27562    );
27563
27564    nesting_test(
27565      r#"
27566        @namespace "http://example.com/foo";
27567        @namespace toto "http://toto.example.org";
27568
27569        div {
27570          @nest .foo& {
27571            color: red;
27572          }
27573        }
27574
27575        * {
27576          @nest .foo& {
27577            color: red;
27578          }
27579        }
27580
27581        |x {
27582          @nest .foo& {
27583            color: red;
27584          }
27585        }
27586
27587        *|x {
27588          @nest .foo& {
27589            color: red;
27590          }
27591        }
27592
27593        toto|x {
27594          @nest .foo& {
27595            color: red;
27596          }
27597        }
27598      "#,
27599      indoc! {r#"
27600        @namespace "http://example.com/foo";
27601        @namespace toto "http://toto.example.org";
27602
27603        .foo:is(div) {
27604          color: red;
27605        }
27606
27607        .foo:is(*) {
27608          color: red;
27609        }
27610
27611        .foo:is(|x) {
27612          color: red;
27613        }
27614
27615        .foo:is(*|x) {
27616          color: red;
27617        }
27618
27619        .foo:is(toto|x) {
27620          color: red;
27621        }
27622      "#},
27623    );
27624
27625    nesting_test(
27626      r#"
27627        .foo .bar {
27628          @nest h1 .baz& {
27629            background: green;
27630          }
27631        }
27632      "#,
27633      indoc! {r#"
27634        h1 .baz:is(.foo .bar) {
27635          background: green;
27636        }
27637      "#},
27638    );
27639
27640    nesting_test(
27641      r#"
27642        .foo .bar {
27643          @nest .baz& {
27644            background: green;
27645          }
27646        }
27647      "#,
27648      indoc! {r#"
27649        .baz:is(.foo .bar) {
27650          background: green;
27651        }
27652      "#},
27653    );
27654
27655    nesting_test(
27656      r#"
27657        .foo .bar {
27658          @nest .baz & {
27659            background: green;
27660          }
27661        }
27662      "#,
27663      indoc! {r#"
27664        .baz :is(.foo .bar) {
27665          background: green;
27666        }
27667      "#},
27668    );
27669
27670    nesting_test(
27671      r#"
27672        .foo {
27673          color: red;
27674          @nest & > .bar {
27675            color: blue;
27676          }
27677        }
27678      "#,
27679      indoc! {r#"
27680        .foo {
27681          color: red;
27682        }
27683
27684        .foo > .bar {
27685          color: #00f;
27686        }
27687      "#},
27688    );
27689
27690    nesting_test(
27691      r#"
27692      .foo {
27693        color: red;
27694        .bar {
27695          color: blue;
27696        }
27697      }
27698      "#,
27699      indoc! {r#"
27700      .foo {
27701        color: red;
27702      }
27703
27704      .foo .bar {
27705        color: #00f;
27706      }
27707      "#},
27708    );
27709
27710    nesting_test(
27711      r#"
27712      .foo {
27713        color: red;
27714        .bar & {
27715          color: blue;
27716        }
27717      }
27718      "#,
27719      indoc! {r#"
27720      .foo {
27721        color: red;
27722      }
27723
27724      .bar .foo {
27725        color: #00f;
27726      }
27727      "#},
27728    );
27729
27730    nesting_test(
27731      r#"
27732      .foo {
27733        color: red;
27734        + .bar + & { color: blue; }
27735      }
27736      "#,
27737      indoc! {r#"
27738      .foo {
27739        color: red;
27740      }
27741
27742      .foo + .bar + .foo {
27743        color: #00f;
27744      }
27745      "#},
27746    );
27747
27748    nesting_test(
27749      r#"
27750      .foo {
27751        color: red;
27752        .bar & {
27753          color: blue;
27754        }
27755      }
27756      "#,
27757      indoc! {r#"
27758      .foo {
27759        color: red;
27760      }
27761
27762      .bar .foo {
27763        color: #00f;
27764      }
27765      "#},
27766    );
27767
27768    nesting_test(
27769      r#"
27770        .foo {
27771          color: red;
27772          .parent & {
27773            color: blue;
27774          }
27775        }
27776      "#,
27777      indoc! {r#"
27778        .foo {
27779          color: red;
27780        }
27781
27782        .parent .foo {
27783          color: #00f;
27784        }
27785      "#},
27786    );
27787
27788    nesting_test(
27789      r#"
27790        .foo {
27791          color: red;
27792          :not(&) {
27793            color: blue;
27794          }
27795        }
27796      "#,
27797      indoc! {r#"
27798        .foo {
27799          color: red;
27800        }
27801
27802        :not(.foo) {
27803          color: #00f;
27804        }
27805      "#},
27806    );
27807
27808    nesting_test(
27809      r#"
27810        .foo {
27811          color: blue;
27812          .bar & {
27813            color: red;
27814            &.baz {
27815              color: green;
27816            }
27817          }
27818        }
27819      "#,
27820      indoc! {r#"
27821        .foo {
27822          color: #00f;
27823        }
27824
27825        .bar .foo {
27826          color: red;
27827        }
27828
27829        .bar .foo.baz {
27830          color: green;
27831        }
27832      "#},
27833    );
27834
27835    nesting_test(
27836      r#"
27837        .foo {
27838          :not(&) {
27839            color: red;
27840          }
27841
27842          & h1 {
27843            background: green;
27844          }
27845        }
27846      "#,
27847      indoc! {r#"
27848        :not(.foo) {
27849          color: red;
27850        }
27851
27852        .foo h1 {
27853          background: green;
27854        }
27855      "#},
27856    );
27857
27858    nesting_test(
27859      r#"
27860        .foo {
27861          & h1 {
27862            background: green;
27863          }
27864
27865          :not(&) {
27866            color: red;
27867          }
27868        }
27869      "#,
27870      indoc! {r#"
27871        .foo h1 {
27872          background: green;
27873        }
27874
27875        :not(.foo) {
27876          color: red;
27877        }
27878      "#},
27879    );
27880
27881    nesting_test(
27882      r#"
27883        .foo .bar {
27884          :is(h1)& {
27885            background: green;
27886          }
27887        }
27888      "#,
27889      indoc! {r#"
27890        :is(h1):is(.foo .bar) {
27891          background: green;
27892        }
27893      "#},
27894    );
27895
27896    nesting_test(
27897      r#"
27898        @namespace "http://example.com/foo";
27899        @namespace toto "http://toto.example.org";
27900
27901        div {
27902          .foo& {
27903            color: red;
27904          }
27905        }
27906
27907        * {
27908          .foo& {
27909            color: red;
27910          }
27911        }
27912
27913        |x {
27914          .foo& {
27915            color: red;
27916          }
27917        }
27918
27919        *|x {
27920          .foo& {
27921            color: red;
27922          }
27923        }
27924
27925        toto|x {
27926          .foo& {
27927            color: red;
27928          }
27929        }
27930      "#,
27931      indoc! {r#"
27932        @namespace "http://example.com/foo";
27933        @namespace toto "http://toto.example.org";
27934
27935        .foo:is(div) {
27936          color: red;
27937        }
27938
27939        .foo:is(*) {
27940          color: red;
27941        }
27942
27943        .foo:is(|x) {
27944          color: red;
27945        }
27946
27947        .foo:is(*|x) {
27948          color: red;
27949        }
27950
27951        .foo:is(toto|x) {
27952          color: red;
27953        }
27954      "#},
27955    );
27956
27957    nesting_test(
27958      r#"
27959        .foo .bar {
27960          :is(h1) .baz& {
27961            background: green;
27962          }
27963        }
27964      "#,
27965      indoc! {r#"
27966        :is(h1) .baz:is(.foo .bar) {
27967          background: green;
27968        }
27969      "#},
27970    );
27971
27972    nesting_test(
27973      r#"
27974        .foo .bar {
27975          .baz& {
27976            background: green;
27977          }
27978        }
27979      "#,
27980      indoc! {r#"
27981        .baz:is(.foo .bar) {
27982          background: green;
27983        }
27984      "#},
27985    );
27986
27987    nesting_test(
27988      r#"
27989        .foo .bar {
27990          .baz & {
27991            background: green;
27992          }
27993        }
27994      "#,
27995      indoc! {r#"
27996        .baz :is(.foo .bar) {
27997          background: green;
27998        }
27999      "#},
28000    );
28001
28002    nesting_test(
28003      r#"
28004        .foo {
28005          .bar {
28006            color: blue;
28007          }
28008          color: red;
28009        }
28010      "#,
28011      indoc! {r#"
28012        .foo .bar {
28013          color: #00f;
28014        }
28015
28016        .foo {
28017          color: red;
28018        }
28019      "#},
28020    );
28021
28022    nesting_test(
28023      r#"
28024        article {
28025          color: green;
28026          & { color: blue; }
28027          color: red;
28028        }
28029      "#,
28030      indoc! {r#"
28031        article {
28032          color: green;
28033        }
28034
28035        article {
28036          color: #00f;
28037        }
28038
28039        article {
28040          color: red;
28041        }
28042      "#},
28043    );
28044
28045    nesting_test(
28046      r#"
28047        & .foo {
28048          color: red;
28049        }
28050      "#,
28051      indoc! {r#"
28052        :scope .foo {
28053          color: red;
28054        }
28055      "#},
28056    );
28057
28058    nesting_test(
28059      r#"
28060        &.foo {
28061          color: red;
28062        }
28063      "#,
28064      indoc! {r#"
28065        :scope.foo {
28066          color: red;
28067        }
28068      "#},
28069    );
28070
28071    nesting_test(
28072      r#"
28073        .foo& {
28074          color: red;
28075        }
28076      "#,
28077      indoc! {r#"
28078        .foo:scope {
28079          color: red;
28080        }
28081      "#},
28082    );
28083
28084    nesting_test(
28085      r#"
28086        &html {
28087          color: red;
28088        }
28089      "#,
28090      indoc! {r#"
28091        html:scope {
28092          color: red;
28093        }
28094      "#},
28095    );
28096
28097    nesting_test(
28098      r#"
28099        .foo {
28100          color: blue;
28101          div {
28102            color: red;
28103          }
28104        }
28105      "#,
28106      indoc! {r#"
28107        .foo {
28108          color: #00f;
28109        }
28110
28111        .foo div {
28112          color: red;
28113        }
28114      "#},
28115    );
28116
28117    nesting_test(
28118      r#"
28119        div {
28120          color: blue;
28121
28122          button:focus {
28123            color: red;
28124          }
28125        }
28126      "#,
28127      indoc! {r#"
28128        div {
28129          color: #00f;
28130        }
28131
28132        div button:focus {
28133          color: red;
28134        }
28135      "#},
28136    );
28137    nesting_test(
28138      r#"
28139        div {
28140          color: blue;
28141
28142          --button:focus {
28143            color: red;
28144          }
28145        }
28146      "#,
28147      indoc! {r#"
28148        div {
28149          color: #00f;
28150          --button: focus {
28151                    color: red;
28152                  };
28153        }
28154      "#},
28155    );
28156    nesting_test(
28157      r#"
28158      .foo {
28159        &::before, &::after {
28160          background: blue;
28161          @media screen {
28162            background: orange;
28163          }
28164        }
28165      }
28166      "#,
28167      indoc! {r#"
28168      .foo:before, .foo:after {
28169        background: #00f;
28170      }
28171
28172      @media screen {
28173        .foo:before, .foo:after {
28174          background: orange;
28175        }
28176      }
28177      "#},
28178    );
28179
28180    nesting_test_no_targets(
28181      r#"
28182        .foo {
28183          color: blue;
28184          @nest .bar & {
28185            color: red;
28186            &.baz {
28187              color: green;
28188            }
28189          }
28190        }
28191      "#,
28192      indoc! {r#"
28193        .foo {
28194          color: #00f;
28195
28196          @nest .bar & {
28197            color: red;
28198
28199            &.baz {
28200              color: green;
28201            }
28202          }
28203        }
28204      "#},
28205    );
28206
28207    nesting_test_no_targets(
28208      r#"
28209        .foo {
28210          color: blue;
28211          &div {
28212            color: red;
28213          }
28214
28215          &span {
28216            color: purple;
28217          }
28218        }
28219      "#,
28220      indoc! {r#"
28221        .foo {
28222          color: #00f;
28223
28224          &div {
28225            color: red;
28226          }
28227
28228          &span {
28229            color: purple;
28230          }
28231        }
28232      "#},
28233    );
28234
28235    nesting_test_no_targets(
28236      r#"
28237        .error, .invalid {
28238          &:hover > .baz { color: red; }
28239        }
28240      "#,
28241      indoc! {r#"
28242        .error, .invalid {
28243          &:hover > .baz {
28244            color: red;
28245          }
28246        }
28247      "#},
28248    );
28249
28250    nesting_test_with_targets(
28251      r#"
28252        .foo {
28253          color: blue;
28254          & > .bar { color: red; }
28255        }
28256      "#,
28257      indoc! {r#"
28258        .foo {
28259          color: #00f;
28260        }
28261
28262        .foo > .bar {
28263          color: red;
28264        }
28265      "#},
28266      Targets {
28267        browsers: Some(Browsers {
28268          chrome: Some(112 << 16),
28269          ..Browsers::default()
28270        }),
28271        include: Features::Nesting,
28272        exclude: Features::empty(),
28273      },
28274    );
28275    nesting_test_with_targets(
28276      r#"
28277        .foo {
28278          color: blue;
28279          & > .bar { color: red; }
28280        }
28281      "#,
28282      indoc! {r#"
28283        .foo {
28284          color: #00f;
28285
28286          & > .bar {
28287            color: red;
28288          }
28289        }
28290      "#},
28291      Targets {
28292        browsers: Some(Browsers {
28293          chrome: Some(50 << 16),
28294          ..Browsers::default()
28295        }),
28296        include: Features::empty(),
28297        exclude: Features::Nesting,
28298      },
28299    );
28300
28301    let mut stylesheet = StyleSheet::parse(
28302      r#"
28303      .foo {
28304        color: blue;
28305        .bar {
28306          color: red;
28307        }
28308      }
28309      "#,
28310      ParserOptions::default(),
28311    )
28312    .unwrap();
28313    stylesheet.minify(MinifyOptions::default()).unwrap();
28314    let res = stylesheet
28315      .to_css(PrinterOptions {
28316        minify: true,
28317        ..PrinterOptions::default()
28318      })
28319      .unwrap();
28320    assert_eq!(res.code, ".foo{color:#00f;& .bar{color:red}}");
28321
28322    nesting_test_with_targets(
28323      r#"
28324        .a {
28325          &.b,
28326          &.c {
28327            &.d {
28328              color: red;
28329            }
28330          }
28331        }
28332      "#,
28333      indoc! {r#"
28334        .a.b.d {
28335          color: red;
28336        }
28337
28338        .a.c.d {
28339          color: red;
28340        }
28341      "#},
28342      Targets {
28343        browsers: Some(Browsers {
28344          safari: Some(13 << 16),
28345          ..Browsers::default()
28346        }),
28347        include: Features::Nesting,
28348        exclude: Features::empty(),
28349      },
28350    );
28351
28352    minify_test(
28353      r#"
28354    .foo {
28355      color: red;
28356      .bar {
28357        color: green;
28358      }
28359      color: blue;
28360      .baz {
28361        color: pink;
28362      }
28363    }"#,
28364      ".foo{color:red;& .bar{color:green}color:#00f;& .baz{color:pink}}",
28365    );
28366  }
28367
28368  #[test]
28369  fn test_nesting_error_recovery() {
28370    error_recovery_test(
28371      "
28372    .container {
28373      padding: 3rem;
28374      @media (max-width: --styled-jsx-placeholder-0__) {
28375        .responsive {
28376          color: purple;
28377        }
28378      }
28379    }
28380    ",
28381    );
28382  }
28383
28384  #[test]
28385  fn test_css_variable_error_recovery() {
28386    error_recovery_test("
28387    .container {
28388      --local-var: --styled-jsx-placeholder-0__;
28389      color: var(--text-color);
28390      background: linear-gradient(to right, --styled-jsx-placeholder-1__, --styled-jsx-placeholder-2__);
28391
28392      .item {
28393        transform: translate(calc(var(--x) + --styled-jsx-placeholder-3__px), calc(var(--y) + --styled-jsx-placeholder-4__px));
28394      }
28395
28396      div {
28397        margin: calc(10px + --styled-jsx-placeholder-5__px);
28398      }
28399    }
28400  ");
28401  }
28402
28403  #[test]
28404  fn test_css_modules() {
28405    css_modules_test(
28406      r#"
28407      .foo {
28408        color: red;
28409      }
28410
28411      #id {
28412        animation: 2s test;
28413      }
28414
28415      @keyframes test {
28416        from { color: red }
28417        to { color: yellow }
28418      }
28419
28420      @counter-style circles {
28421        symbols: Ⓐ Ⓑ Ⓒ;
28422      }
28423
28424      ul {
28425        list-style: circles;
28426      }
28427
28428      ol {
28429        list-style-type: none;
28430      }
28431
28432      li {
28433        list-style-type: disc;
28434      }
28435
28436      @keyframes fade {
28437        from { opacity: 0 }
28438        to { opacity: 1 }
28439      }
28440    "#,
28441      indoc! {r#"
28442      .EgL3uq_foo {
28443        color: red;
28444      }
28445
28446      #EgL3uq_id {
28447        animation: 2s EgL3uq_test;
28448      }
28449
28450      @keyframes EgL3uq_test {
28451        from {
28452          color: red;
28453        }
28454
28455        to {
28456          color: #ff0;
28457        }
28458      }
28459
28460      @counter-style EgL3uq_circles {
28461        symbols: Ⓐ Ⓑ Ⓒ;
28462      }
28463
28464      ul {
28465        list-style: EgL3uq_circles;
28466      }
28467
28468      ol {
28469        list-style-type: none;
28470      }
28471
28472      li {
28473        list-style-type: disc;
28474      }
28475
28476      @keyframes EgL3uq_fade {
28477        from {
28478          opacity: 0;
28479        }
28480
28481        to {
28482          opacity: 1;
28483        }
28484      }
28485    "#},
28486      map! {
28487        "foo" => "EgL3uq_foo",
28488        "id" => "EgL3uq_id",
28489        "test" => "EgL3uq_test" referenced: true,
28490        "circles" => "EgL3uq_circles" referenced: true,
28491        "fade" => "EgL3uq_fade"
28492      },
28493      IndexMap::new(),
28494      Default::default(),
28495      false,
28496    );
28497
28498    css_modules_test(
28499      r#"
28500      .foo {
28501        color: red;
28502      }
28503
28504      #id {
28505        animation: 2s test;
28506      }
28507
28508      @keyframes test {
28509        from { color: red }
28510        to { color: yellow }
28511      }
28512    "#,
28513      indoc! {r#"
28514      .EgL3uq_foo {
28515        color: red;
28516      }
28517
28518      #EgL3uq_id {
28519        animation: 2s test;
28520      }
28521
28522      @keyframes test {
28523        from {
28524          color: red;
28525        }
28526
28527        to {
28528          color: #ff0;
28529        }
28530      }
28531    "#},
28532      map! {
28533        "foo" => "EgL3uq_foo",
28534        "id" => "EgL3uq_id"
28535      },
28536      IndexMap::new(),
28537      crate::css_modules::Config {
28538        animation: false,
28539        // custom_idents: false,
28540        ..Default::default()
28541      },
28542      false,
28543    );
28544
28545    css_modules_test(
28546      r#"
28547      @counter-style circles {
28548        symbols: Ⓐ Ⓑ Ⓒ;
28549      }
28550
28551      ul {
28552        list-style: circles;
28553      }
28554
28555      ol {
28556        list-style-type: none;
28557      }
28558
28559      li {
28560        list-style-type: disc;
28561      }
28562    "#,
28563      indoc! {r#"
28564      @counter-style circles {
28565        symbols: Ⓐ Ⓑ Ⓒ;
28566      }
28567
28568      ul {
28569        list-style: circles;
28570      }
28571
28572      ol {
28573        list-style-type: none;
28574      }
28575
28576      li {
28577        list-style-type: disc;
28578      }
28579    "#},
28580      map! {
28581        "circles" => "EgL3uq_circles" referenced: true
28582      },
28583      IndexMap::new(),
28584      crate::css_modules::Config {
28585        custom_idents: false,
28586        ..Default::default()
28587      },
28588      false,
28589    );
28590
28591    css_modules_test(
28592      r#"
28593      body {
28594        grid: [header-top] "a a a" [header-bottom]
28595              [main-top] "b b b" 1fr [main-bottom]
28596              / auto 1fr auto;
28597      }
28598
28599      header {
28600        grid-area: a;
28601      }
28602
28603      main {
28604        grid-row: main-top / main-bottom;
28605      }
28606    "#,
28607      indoc! {r#"
28608      body {
28609        grid: [EgL3uq_header-top] "EgL3uq_a EgL3uq_a EgL3uq_a" [EgL3uq_header-bottom]
28610              [EgL3uq_main-top] "EgL3uq_b EgL3uq_b EgL3uq_b" 1fr [EgL3uq_main-bottom]
28611              / auto 1fr auto;
28612      }
28613
28614      header {
28615        grid-area: EgL3uq_a;
28616      }
28617
28618      main {
28619        grid-row: EgL3uq_main-top / EgL3uq_main-bottom;
28620      }
28621    "#},
28622      map! {
28623        "header-top" => "EgL3uq_header-top",
28624        "header-bottom" => "EgL3uq_header-bottom",
28625        "main-top" => "EgL3uq_main-top",
28626        "main-bottom" => "EgL3uq_main-bottom",
28627        "a" => "EgL3uq_a",
28628        "b" => "EgL3uq_b"
28629      },
28630      IndexMap::new(),
28631      Default::default(),
28632      false,
28633    );
28634
28635    css_modules_test(
28636      r#"
28637        .grid {
28638          grid-template-areas: "foo";
28639        }
28640
28641        .foo {
28642          grid-area: foo;
28643        }
28644
28645        .bar {
28646          grid-column-start: foo-start;
28647        }
28648      "#,
28649      indoc! {r#"
28650        .EgL3uq_grid {
28651          grid-template-areas: "EgL3uq_foo";
28652        }
28653
28654        .EgL3uq_foo {
28655          grid-area: EgL3uq_foo;
28656        }
28657
28658        .EgL3uq_bar {
28659          grid-column-start: EgL3uq_foo-start;
28660        }
28661      "#},
28662      map! {
28663        "foo" => "EgL3uq_foo",
28664        "foo-start" => "EgL3uq_foo-start",
28665        "grid" => "EgL3uq_grid",
28666        "bar" => "EgL3uq_bar"
28667      },
28668      IndexMap::new(),
28669      Default::default(),
28670      false,
28671    );
28672
28673    css_modules_test(
28674      r#"
28675        .grid {
28676          grid-template-areas: "foo";
28677        }
28678
28679        .foo {
28680          grid-area: foo;
28681        }
28682
28683        .bar {
28684          grid-column-start: foo-start;
28685        }
28686      "#,
28687      indoc! {r#"
28688        .EgL3uq_grid {
28689          grid-template-areas: "foo";
28690        }
28691
28692        .EgL3uq_foo {
28693          grid-area: foo;
28694        }
28695
28696        .EgL3uq_bar {
28697          grid-column-start: foo-start;
28698        }
28699      "#},
28700      map! {
28701        "foo" => "EgL3uq_foo",
28702        "grid" => "EgL3uq_grid",
28703        "bar" => "EgL3uq_bar"
28704      },
28705      IndexMap::new(),
28706      crate::css_modules::Config {
28707        grid: false,
28708        ..Default::default()
28709      },
28710      false,
28711    );
28712
28713    css_modules_test(
28714      r#"
28715      test {
28716        transition-property: opacity;
28717      }
28718    "#,
28719      indoc! {r#"
28720      test {
28721        transition-property: opacity;
28722      }
28723    "#},
28724      map! {},
28725      IndexMap::new(),
28726      Default::default(),
28727      false,
28728    );
28729
28730    css_modules_test(
28731      r#"
28732      :global(.foo) {
28733        color: red;
28734      }
28735
28736      :local(.bar) {
28737        color: yellow;
28738      }
28739
28740      .bar :global(.baz) {
28741        color: purple;
28742      }
28743    "#,
28744      indoc! {r#"
28745      .foo {
28746        color: red;
28747      }
28748
28749      .EgL3uq_bar {
28750        color: #ff0;
28751      }
28752
28753      .EgL3uq_bar .baz {
28754        color: purple;
28755      }
28756    "#},
28757      map! {
28758        "bar" => "EgL3uq_bar"
28759      },
28760      IndexMap::new(),
28761      Default::default(),
28762      false,
28763    );
28764
28765    // :global(:local(.hi)) {
28766    //   color: green;
28767    // }
28768
28769    css_modules_test(
28770      r#"
28771      .test {
28772        composes: foo;
28773        background: white;
28774      }
28775
28776      .foo {
28777        color: red;
28778      }
28779    "#,
28780      indoc! {r#"
28781      .EgL3uq_test {
28782        background: #fff;
28783      }
28784
28785      .EgL3uq_foo {
28786        color: red;
28787      }
28788    "#},
28789      map! {
28790        "test" => "EgL3uq_test" "EgL3uq_foo",
28791        "foo" => "EgL3uq_foo"
28792      },
28793      IndexMap::new(),
28794      Default::default(),
28795      false,
28796    );
28797
28798    css_modules_test(
28799      r#"
28800      .a, .b {
28801        composes: foo;
28802        background: white;
28803      }
28804
28805      .foo {
28806        color: red;
28807      }
28808    "#,
28809      indoc! {r#"
28810      .EgL3uq_a, .EgL3uq_b {
28811        background: #fff;
28812      }
28813
28814      .EgL3uq_foo {
28815        color: red;
28816      }
28817    "#},
28818      map! {
28819        "a" => "EgL3uq_a" "EgL3uq_foo",
28820        "b" => "EgL3uq_b" "EgL3uq_foo",
28821        "foo" => "EgL3uq_foo"
28822      },
28823      IndexMap::new(),
28824      Default::default(),
28825      false,
28826    );
28827
28828    css_modules_test(
28829      r#"
28830      .test {
28831        composes: foo bar;
28832        background: white;
28833      }
28834
28835      .foo {
28836        color: red;
28837      }
28838
28839      .bar {
28840        color: yellow;
28841      }
28842    "#,
28843      indoc! {r#"
28844      .EgL3uq_test {
28845        background: #fff;
28846      }
28847
28848      .EgL3uq_foo {
28849        color: red;
28850      }
28851
28852      .EgL3uq_bar {
28853        color: #ff0;
28854      }
28855    "#},
28856      map! {
28857        "test" => "EgL3uq_test" "EgL3uq_foo" "EgL3uq_bar",
28858        "foo" => "EgL3uq_foo",
28859        "bar" => "EgL3uq_bar"
28860      },
28861      IndexMap::new(),
28862      Default::default(),
28863      false,
28864    );
28865
28866    css_modules_test(
28867      r#"
28868      .test {
28869        composes: foo from global;
28870        background: white;
28871      }
28872    "#,
28873      indoc! {r#"
28874      .EgL3uq_test {
28875        background: #fff;
28876      }
28877    "#},
28878      map! {
28879        "test" => "EgL3uq_test" "foo" global: true
28880      },
28881      IndexMap::new(),
28882      Default::default(),
28883      false,
28884    );
28885
28886    css_modules_test(
28887      r#"
28888      .test {
28889        composes: foo bar from global;
28890        background: white;
28891      }
28892    "#,
28893      indoc! {r#"
28894      .EgL3uq_test {
28895        background: #fff;
28896      }
28897    "#},
28898      map! {
28899        "test" => "EgL3uq_test" "foo" global: true "bar" global: true
28900      },
28901      IndexMap::new(),
28902      Default::default(),
28903      false,
28904    );
28905
28906    css_modules_test(
28907      r#"
28908      .test {
28909        composes: foo from "foo.css";
28910        background: white;
28911      }
28912    "#,
28913      indoc! {r#"
28914      .EgL3uq_test {
28915        background: #fff;
28916      }
28917    "#},
28918      map! {
28919        "test" => "EgL3uq_test" "foo" from "foo.css"
28920      },
28921      IndexMap::new(),
28922      Default::default(),
28923      false,
28924    );
28925
28926    css_modules_test(
28927      r#"
28928      .test {
28929        composes: foo bar from "foo.css";
28930        background: white;
28931      }
28932    "#,
28933      indoc! {r#"
28934      .EgL3uq_test {
28935        background: #fff;
28936      }
28937    "#},
28938      map! {
28939        "test" => "EgL3uq_test" "foo" from "foo.css" "bar" from "foo.css"
28940      },
28941      IndexMap::new(),
28942      Default::default(),
28943      false,
28944    );
28945
28946    css_modules_test(
28947      r#"
28948      .test {
28949        composes: foo;
28950        composes: foo from "foo.css";
28951        composes: bar from "bar.css";
28952        background: white;
28953      }
28954
28955      .foo {
28956        color: red;
28957      }
28958    "#,
28959      indoc! {r#"
28960      .EgL3uq_test {
28961        background: #fff;
28962      }
28963
28964      .EgL3uq_foo {
28965        color: red;
28966      }
28967    "#},
28968      map! {
28969        "test" => "EgL3uq_test" "EgL3uq_foo" "foo" from "foo.css" "bar" from "bar.css",
28970        "foo" => "EgL3uq_foo"
28971      },
28972      IndexMap::new(),
28973      Default::default(),
28974      false,
28975    );
28976
28977    css_modules_test(
28978      r#"
28979      .foo {
28980        color: red;
28981      }
28982    "#,
28983      indoc! {r#"
28984      .test-EgL3uq-foo {
28985        color: red;
28986      }
28987    "#},
28988      map! {
28989        "foo" => "test-EgL3uq-foo"
28990      },
28991      IndexMap::new(),
28992      crate::css_modules::Config {
28993        pattern: crate::css_modules::Pattern::parse("test-[hash]-[local]").unwrap(),
28994        ..Default::default()
28995      },
28996      false,
28997    );
28998
28999    let stylesheet = StyleSheet::parse(
29000      r#"
29001        .grid {
29002          grid-template-areas: "foo";
29003        }
29004
29005        .foo {
29006          grid-area: foo;
29007        }
29008
29009        .bar {
29010          grid-column-start: foo-start;
29011        }
29012      "#,
29013      ParserOptions {
29014        css_modules: Some(crate::css_modules::Config {
29015          pattern: crate::css_modules::Pattern::parse("test-[local]-[hash]").unwrap(),
29016          ..Default::default()
29017        }),
29018        ..ParserOptions::default()
29019      },
29020    )
29021    .unwrap();
29022    if let Err(err) = stylesheet.to_css(PrinterOptions::default()) {
29023      assert_eq!(err.kind, PrinterErrorKind::InvalidCssModulesPatternInGrid);
29024    } else {
29025      unreachable!()
29026    }
29027
29028    css_modules_test(
29029      r#"
29030      @property --foo {
29031        syntax: '<color>';
29032        inherits: false;
29033        initial-value: yellow;
29034      }
29035
29036      .foo {
29037        --foo: red;
29038        color: var(--foo);
29039      }
29040    "#,
29041      indoc! {r#"
29042      @property --foo {
29043        syntax: "<color>";
29044        inherits: false;
29045        initial-value: #ff0;
29046      }
29047
29048      .EgL3uq_foo {
29049        --foo: red;
29050        color: var(--foo);
29051      }
29052    "#},
29053      map! {
29054        "foo" => "EgL3uq_foo"
29055      },
29056      IndexMap::new(),
29057      Default::default(),
29058      false,
29059    );
29060
29061    css_modules_test(
29062      r#"
29063      @property --foo {
29064        syntax: '<color>';
29065        inherits: false;
29066        initial-value: yellow;
29067      }
29068
29069      @font-palette-values --Cooler {
29070        font-family: Bixa;
29071        base-palette: 1;
29072        override-colors: 1 #7EB7E4;
29073      }
29074
29075      .foo {
29076        --foo: red;
29077        --bar: green;
29078        color: var(--foo);
29079        font-palette: --Cooler;
29080      }
29081
29082      .bar {
29083        color: var(--color from "./b.css");
29084      }
29085    "#,
29086      indoc! {r#"
29087      @property --EgL3uq_foo {
29088        syntax: "<color>";
29089        inherits: false;
29090        initial-value: #ff0;
29091      }
29092
29093      @font-palette-values --EgL3uq_Cooler {
29094        font-family: Bixa;
29095        base-palette: 1;
29096        override-colors: 1 #7eb7e4;
29097      }
29098
29099      .EgL3uq_foo {
29100        --EgL3uq_foo: red;
29101        --EgL3uq_bar: green;
29102        color: var(--EgL3uq_foo);
29103        font-palette: --EgL3uq_Cooler;
29104      }
29105
29106      .EgL3uq_bar {
29107        color: var(--ma1CsG);
29108      }
29109    "#},
29110      map! {
29111        "foo" => "EgL3uq_foo",
29112        "--foo" => "--EgL3uq_foo" referenced: true,
29113        "--bar" => "--EgL3uq_bar",
29114        "bar" => "EgL3uq_bar",
29115        "--Cooler" => "--EgL3uq_Cooler" referenced: true
29116      },
29117      IndexMap::from([(
29118        "--ma1CsG".into(),
29119        CssModuleReference::Dependency {
29120          name: "--color".into(),
29121          specifier: "./b.css".into(),
29122        },
29123      )]),
29124      crate::css_modules::Config {
29125        dashed_idents: true,
29126        ..Default::default()
29127      },
29128      false,
29129    );
29130
29131    css_modules_test(
29132      r#"
29133      .test {
29134        animation: rotate var(--duration) linear infinite;
29135      }
29136    "#,
29137      indoc! {r#"
29138      .EgL3uq_test {
29139        animation: EgL3uq_rotate var(--duration) linear infinite;
29140      }
29141    "#},
29142      map! {
29143        "test" => "EgL3uq_test",
29144        "rotate" => "EgL3uq_rotate" referenced: true
29145      },
29146      IndexMap::new(),
29147      Default::default(),
29148      false,
29149    );
29150    css_modules_test(
29151      r#"
29152      .test {
29153        animation: none var(--duration);
29154      }
29155    "#,
29156      indoc! {r#"
29157      .EgL3uq_test {
29158        animation: none var(--duration);
29159      }
29160    "#},
29161      map! {
29162        "test" => "EgL3uq_test"
29163      },
29164      IndexMap::new(),
29165      Default::default(),
29166      false,
29167    );
29168    css_modules_test(
29169      r#"
29170      .test {
29171        animation: var(--animation);
29172      }
29173    "#,
29174      indoc! {r#"
29175      .EgL3uq_test {
29176        animation: var(--animation);
29177      }
29178    "#},
29179      map! {
29180        "test" => "EgL3uq_test"
29181      },
29182      IndexMap::new(),
29183      Default::default(),
29184      false,
29185    );
29186    css_modules_test(
29187      r#"
29188      .test {
29189        animation: rotate var(--duration);
29190      }
29191    "#,
29192      indoc! {r#"
29193      .EgL3uq_test {
29194        animation: rotate var(--duration);
29195      }
29196    "#},
29197      map! {
29198        "test" => "EgL3uq_test"
29199      },
29200      IndexMap::new(),
29201      crate::css_modules::Config {
29202        animation: false,
29203        ..Default::default()
29204      },
29205      false,
29206    );
29207    css_modules_test(
29208      r#"
29209      .test {
29210        animation: "rotate" var(--duration);
29211      }
29212    "#,
29213      indoc! {r#"
29214      .EgL3uq_test {
29215        animation: EgL3uq_rotate var(--duration);
29216      }
29217    "#},
29218      map! {
29219        "test" => "EgL3uq_test",
29220        "rotate" => "EgL3uq_rotate" referenced: true
29221      },
29222      IndexMap::new(),
29223      crate::css_modules::Config { ..Default::default() },
29224      false,
29225    );
29226
29227    css_modules_test(
29228      r#"
29229      .test {
29230        composes: foo bar from "foo.css";
29231        background: white;
29232      }
29233    "#,
29234      indoc! {r#"
29235      ._5h2kwG-test {
29236        background: #fff;
29237      }
29238    "#},
29239      map! {
29240        "test" => "_5h2kwG-test" "foo" from "foo.css" "bar" from "foo.css"
29241      },
29242      IndexMap::new(),
29243      crate::css_modules::Config {
29244        pattern: crate::css_modules::Pattern::parse("[content-hash]-[local]").unwrap(),
29245        ..Default::default()
29246      },
29247      false,
29248    );
29249
29250    css_modules_test(
29251      r#"
29252      .box2 {
29253        @container main (width >= 0) {
29254          background-color: #90ee90;
29255        }
29256      }
29257    "#,
29258      indoc! {r#"
29259      .EgL3uq_box2 {
29260        @container EgL3uq_main (width >= 0) {
29261          background-color: #90ee90;
29262        }
29263      }
29264    "#},
29265      map! {
29266        "main" => "EgL3uq_main",
29267        "box2" => "EgL3uq_box2"
29268      },
29269      IndexMap::new(),
29270      crate::css_modules::Config { ..Default::default() },
29271      false,
29272    );
29273
29274    css_modules_test(
29275      r#"
29276      .box2 {
29277        @container main (width >= 0) {
29278          background-color: #90ee90;
29279        }
29280      }
29281    "#,
29282      indoc! {r#"
29283      .EgL3uq_box2 {
29284        @container main (width >= 0) {
29285          background-color: #90ee90;
29286        }
29287      }
29288    "#},
29289      map! {
29290        "box2" => "EgL3uq_box2"
29291      },
29292      IndexMap::new(),
29293      crate::css_modules::Config {
29294        container: false,
29295        ..Default::default()
29296      },
29297      false,
29298    );
29299
29300    css_modules_test(
29301      ".foo { view-transition-name: bar }",
29302      ".EgL3uq_foo{view-transition-name:EgL3uq_bar}",
29303      map! {
29304        "foo" => "EgL3uq_foo",
29305        "bar" => "EgL3uq_bar"
29306      },
29307      IndexMap::new(),
29308      Default::default(),
29309      true,
29310    );
29311    css_modules_test(
29312      ".foo { view-transition-name: none }",
29313      ".EgL3uq_foo{view-transition-name:none}",
29314      map! {
29315        "foo" => "EgL3uq_foo"
29316      },
29317      IndexMap::new(),
29318      Default::default(),
29319      true,
29320    );
29321    css_modules_test(
29322      ".foo { view-transition-name: auto }",
29323      ".EgL3uq_foo{view-transition-name:auto}",
29324      map! {
29325        "foo" => "EgL3uq_foo"
29326      },
29327      IndexMap::new(),
29328      Default::default(),
29329      true,
29330    );
29331    css_modules_test(
29332      ".foo { view-transition-name: match-element }",
29333      ".EgL3uq_foo{view-transition-name:match-element}",
29334      map! {
29335        "foo" => "EgL3uq_foo"
29336      },
29337      IndexMap::new(),
29338      Default::default(),
29339      true,
29340    );
29341
29342    css_modules_test(
29343      ".foo { view-transition-class: bar baz qux }",
29344      ".EgL3uq_foo{view-transition-class:EgL3uq_bar EgL3uq_baz EgL3uq_qux}",
29345      map! {
29346        "foo" => "EgL3uq_foo",
29347        "bar" => "EgL3uq_bar",
29348        "baz" => "EgL3uq_baz",
29349        "qux" => "EgL3uq_qux"
29350      },
29351      IndexMap::new(),
29352      Default::default(),
29353      true,
29354    );
29355
29356    css_modules_test(
29357      ".foo { view-transition-group: contain }",
29358      ".EgL3uq_foo{view-transition-group:contain}",
29359      map! {
29360        "foo" => "EgL3uq_foo"
29361      },
29362      IndexMap::new(),
29363      Default::default(),
29364      true,
29365    );
29366    css_modules_test(
29367      ".foo { view-transition-group: bar }",
29368      ".EgL3uq_foo{view-transition-group:EgL3uq_bar}",
29369      map! {
29370        "foo" => "EgL3uq_foo",
29371        "bar" => "EgL3uq_bar"
29372      },
29373      IndexMap::new(),
29374      Default::default(),
29375      true,
29376    );
29377
29378    css_modules_test(
29379      "@view-transition { types: foo bar baz }",
29380      "@view-transition{types:EgL3uq_foo EgL3uq_bar EgL3uq_baz}",
29381      map! {
29382        "foo" => "EgL3uq_foo",
29383        "bar" => "EgL3uq_bar",
29384        "baz" => "EgL3uq_baz"
29385      },
29386      IndexMap::new(),
29387      Default::default(),
29388      true,
29389    );
29390
29391    css_modules_test(
29392      ":root:active-view-transition-type(foo, bar) { color: red }",
29393      ":root:active-view-transition-type(EgL3uq_foo,EgL3uq_bar){color:red}",
29394      map! {
29395        "foo" => "EgL3uq_foo",
29396        "bar" => "EgL3uq_bar"
29397      },
29398      IndexMap::new(),
29399      Default::default(),
29400      true,
29401    );
29402
29403    for name in &[
29404      "view-transition-group",
29405      "view-transition-image-pair",
29406      "view-transition-new",
29407      "view-transition-old",
29408    ] {
29409      css_modules_test(
29410        &format!(":root::{}(foo) {{position: fixed}}", name),
29411        &format!(":root::{}(EgL3uq_foo){{position:fixed}}", name),
29412        map! {
29413          "foo" => "EgL3uq_foo"
29414        },
29415        IndexMap::new(),
29416        Default::default(),
29417        true,
29418      );
29419      css_modules_test(
29420        &format!(":root::{}(.bar) {{position: fixed}}", name),
29421        &format!(":root::{}(.EgL3uq_bar){{position:fixed}}", name),
29422        map! {
29423          "bar" => "EgL3uq_bar"
29424        },
29425        IndexMap::new(),
29426        Default::default(),
29427        true,
29428      );
29429      css_modules_test(
29430        &format!(":root::{}(foo.bar.baz) {{position: fixed}}", name),
29431        &format!(":root::{}(EgL3uq_foo.EgL3uq_bar.EgL3uq_baz){{position:fixed}}", name),
29432        map! {
29433          "foo" => "EgL3uq_foo",
29434          "bar" => "EgL3uq_bar",
29435          "baz" => "EgL3uq_baz"
29436        },
29437        IndexMap::new(),
29438        Default::default(),
29439        true,
29440      );
29441
29442      css_modules_test(
29443        ":nth-child(1 of .foo) {width: 20px}",
29444        ":nth-child(1 of .EgL3uq_foo){width:20px}",
29445        map! {
29446          "foo" => "EgL3uq_foo"
29447        },
29448        IndexMap::new(),
29449        Default::default(),
29450        true,
29451      );
29452      css_modules_test(
29453        ":nth-last-child(1 of .foo) {width: 20px}",
29454        ":nth-last-child(1 of .EgL3uq_foo){width:20px}",
29455        map! {
29456          "foo" => "EgL3uq_foo"
29457        },
29458        IndexMap::new(),
29459        Default::default(),
29460        true,
29461      );
29462    }
29463
29464    // Stable hashes between project roots.
29465    fn test_project_root(project_root: &str, filename: &str, hash: &str) {
29466      let stylesheet = StyleSheet::parse(
29467        r#"
29468        .foo {
29469          background: red;
29470        }
29471        "#,
29472        ParserOptions {
29473          filename: filename.into(),
29474          css_modules: Some(Default::default()),
29475          ..ParserOptions::default()
29476        },
29477      )
29478      .unwrap();
29479      let res = stylesheet
29480        .to_css(PrinterOptions {
29481          project_root: Some(project_root),
29482          ..PrinterOptions::default()
29483        })
29484        .unwrap();
29485      assert_eq!(
29486        res.code,
29487        format!(
29488          indoc! {r#"
29489      .{}_foo {{
29490        background: red;
29491      }}
29492      "#},
29493          hash
29494        )
29495      );
29496    }
29497
29498    test_project_root("/foo/bar", "/foo/bar/test.css", "EgL3uq");
29499    test_project_root("/foo", "/foo/test.css", "EgL3uq");
29500    test_project_root("/foo/bar", "/foo/bar/baz/test.css", "xLEkNW");
29501    test_project_root("/foo", "/foo/baz/test.css", "xLEkNW");
29502
29503    let mut stylesheet = StyleSheet::parse(
29504      r#"
29505      .foo {
29506        color: red;
29507        .bar {
29508          color: green;
29509        }
29510        composes: test from "foo.css";
29511      }
29512      "#,
29513      ParserOptions {
29514        filename: "test.css".into(),
29515        css_modules: Some(Default::default()),
29516        ..ParserOptions::default()
29517      },
29518    )
29519    .unwrap();
29520    stylesheet.minify(MinifyOptions::default()).unwrap();
29521    let res = stylesheet
29522      .to_css(PrinterOptions {
29523        targets: Browsers {
29524          chrome: Some(95 << 16),
29525          ..Browsers::default()
29526        }
29527        .into(),
29528        ..Default::default()
29529      })
29530      .unwrap();
29531    assert_eq!(
29532      res.code,
29533      indoc! {r#"
29534    .EgL3uq_foo {
29535      color: red;
29536    }
29537
29538    .EgL3uq_foo .EgL3uq_bar {
29539      color: green;
29540    }
29541
29542
29543    "#}
29544    );
29545    assert_eq!(
29546      res.exports.unwrap(),
29547      map! {
29548        "foo" => "EgL3uq_foo" "test" from "foo.css",
29549        "bar" => "EgL3uq_bar"
29550      }
29551    );
29552  }
29553
29554  #[test]
29555  fn test_pseudo_replacement() {
29556    let source = r#"
29557      .foo:hover {
29558        color: red;
29559      }
29560
29561      .foo:active {
29562        color: yellow;
29563      }
29564
29565      .foo:focus-visible {
29566        color: purple;
29567      }
29568    "#;
29569
29570    let expected = indoc! { r#"
29571      .foo.is-hovered {
29572        color: red;
29573      }
29574
29575      .foo.is-active {
29576        color: #ff0;
29577      }
29578
29579      .foo.focus-visible {
29580        color: purple;
29581      }
29582    "#};
29583
29584    let stylesheet = StyleSheet::parse(&source, ParserOptions::default()).unwrap();
29585    let res = stylesheet
29586      .to_css(PrinterOptions {
29587        pseudo_classes: Some(PseudoClasses {
29588          hover: Some("is-hovered"),
29589          active: Some("is-active"),
29590          focus_visible: Some("focus-visible"),
29591          ..PseudoClasses::default()
29592        }),
29593        ..PrinterOptions::default()
29594      })
29595      .unwrap();
29596    assert_eq!(res.code, expected);
29597
29598    let source = r#"
29599      .foo:hover {
29600        color: red;
29601      }
29602    "#;
29603
29604    let expected = indoc! { r#"
29605      .EgL3uq_foo.EgL3uq_is-hovered {
29606        color: red;
29607      }
29608    "#};
29609
29610    let stylesheet = StyleSheet::parse(
29611      &source,
29612      ParserOptions {
29613        filename: "test.css".into(),
29614        css_modules: Some(Default::default()),
29615        ..ParserOptions::default()
29616      },
29617    )
29618    .unwrap();
29619    let res = stylesheet
29620      .to_css(PrinterOptions {
29621        pseudo_classes: Some(PseudoClasses {
29622          hover: Some("is-hovered"),
29623          ..PseudoClasses::default()
29624        }),
29625        ..PrinterOptions::default()
29626      })
29627      .unwrap();
29628    assert_eq!(res.code, expected);
29629  }
29630
29631  #[test]
29632  fn test_unused_symbols() {
29633    let source = r#"
29634      .foo {
29635        color: red;
29636      }
29637
29638      .bar {
29639        color: green;
29640      }
29641
29642      .bar:hover {
29643        color: purple;
29644      }
29645
29646      .bar .baz {
29647        background: red;
29648      }
29649
29650      .baz:is(.bar) {
29651        background: green;
29652      }
29653
29654      #id {
29655        animation: 2s test;
29656      }
29657
29658      #other_id {
29659        color: red;
29660      }
29661
29662      @keyframes test {
29663        from { color: red }
29664        to { color: yellow }
29665      }
29666
29667      @counter-style circles {
29668        symbols: Ⓐ Ⓑ Ⓒ;
29669      }
29670
29671      @keyframes fade {
29672        from { opacity: 0 }
29673        to { opacity: 1 }
29674      }
29675    "#;
29676
29677    let expected = indoc! {r#"
29678      .foo {
29679        color: red;
29680      }
29681
29682      #id {
29683        animation: 2s test;
29684      }
29685
29686      @keyframes test {
29687        from {
29688          color: red;
29689        }
29690
29691        to {
29692          color: #ff0;
29693        }
29694      }
29695    "#};
29696
29697    let mut stylesheet = StyleSheet::parse(&source, ParserOptions::default()).unwrap();
29698    stylesheet
29699      .minify(MinifyOptions {
29700        unused_symbols: vec!["bar", "other_id", "fade", "circles"]
29701          .iter()
29702          .map(|s| String::from(*s))
29703          .collect(),
29704        ..MinifyOptions::default()
29705      })
29706      .unwrap();
29707    let res = stylesheet.to_css(PrinterOptions::default()).unwrap();
29708    assert_eq!(res.code, expected);
29709
29710    let source = r#"
29711      .foo {
29712        color: red;
29713
29714        &.bar {
29715          color: green;
29716        }
29717      }
29718    "#;
29719
29720    let expected = indoc! {r#"
29721      .foo {
29722        color: red;
29723      }
29724    "#};
29725
29726    let mut stylesheet = StyleSheet::parse(&source, ParserOptions::default()).unwrap();
29727    stylesheet
29728      .minify(MinifyOptions {
29729        unused_symbols: vec!["bar"].iter().map(|s| String::from(*s)).collect(),
29730        ..MinifyOptions::default()
29731      })
29732      .unwrap();
29733    let res = stylesheet.to_css(PrinterOptions::default()).unwrap();
29734    assert_eq!(res.code, expected);
29735
29736    let source = r#"
29737      .foo {
29738        color: red;
29739
29740        &.bar {
29741          color: purple;
29742        }
29743
29744        @nest &.bar {
29745          color: orange;
29746        }
29747
29748        @nest :not(&) {
29749          color: green;
29750        }
29751
29752        @media (orientation: portrait) {
29753          color: brown;
29754        }
29755      }
29756
29757      .x {
29758        color: purple;
29759
29760        &.y {
29761          color: green;
29762        }
29763      }
29764    "#;
29765
29766    let expected = indoc! {r#"
29767      :not(.foo) {
29768        color: green;
29769      }
29770    "#};
29771
29772    let mut stylesheet = StyleSheet::parse(&source, ParserOptions::default()).unwrap();
29773    stylesheet
29774      .minify(MinifyOptions {
29775        unused_symbols: vec!["foo", "x"].iter().map(|s| String::from(*s)).collect(),
29776        ..MinifyOptions::default()
29777      })
29778      .unwrap();
29779    let res = stylesheet
29780      .to_css(PrinterOptions {
29781        targets: Browsers {
29782          chrome: Some(95 << 16),
29783          ..Browsers::default()
29784        }
29785        .into(),
29786        ..PrinterOptions::default()
29787      })
29788      .unwrap();
29789    assert_eq!(res.code, expected);
29790
29791    let source = r#"
29792      @property --EgL3uq_foo {
29793        syntax: "<color>";
29794        inherits: false;
29795        initial-value: #ff0;
29796      }
29797
29798      @font-palette-values --EgL3uq_Cooler {
29799        font-family: Bixa;
29800        base-palette: 1;
29801        override-colors: 1 #7EB7E4;
29802      }
29803
29804      .EgL3uq_foo {
29805        --EgL3uq_foo: red;
29806      }
29807
29808      .EgL3uq_bar {
29809        color: green;
29810      }
29811    "#;
29812
29813    let expected = indoc! {r#"
29814      .EgL3uq_bar {
29815        color: green;
29816      }
29817    "#};
29818
29819    let mut stylesheet = StyleSheet::parse(&source, ParserOptions::default()).unwrap();
29820    stylesheet
29821      .minify(MinifyOptions {
29822        unused_symbols: vec!["--EgL3uq_foo", "--EgL3uq_Cooler"]
29823          .iter()
29824          .map(|s| String::from(*s))
29825          .collect(),
29826        ..MinifyOptions::default()
29827      })
29828      .unwrap();
29829    let res = stylesheet.to_css(PrinterOptions::default()).unwrap();
29830    assert_eq!(res.code, expected);
29831  }
29832
29833  #[test]
29834  fn test_svg() {
29835    property_range_test(
29836      &["stroke-dasharray"],
29837      &[
29838        ("-1px", None),
29839        ("-1%", None),
29840        ("calc(-1px)", Some("0")),
29841        ("calc(-1px + 2px)", Some("1")),
29842        ("calc(-1%)", Some("calc(-1%)")),
29843      ],
29844    );
29845    property_range_test(&["stroke-dashoffset"], &[("-1px", Some("-1px"))]);
29846    property_range_test(&["stroke-dasharray"], &[("1px -2px", None)]);
29847    property_range_test(
29848      &["stroke-width"],
29849      &[
29850        ("-1px", None),
29851        ("calc(1px - 2px)", Some("0")),
29852        ("calc(-1px + 2px)", Some("1px")),
29853        ("-1%", None),
29854        ("calc(1em - 2px)", Some("calc(1em - 2px)")),
29855        ("calc(-1%)", Some("calc(-1%)")),
29856      ],
29857    );
29858    use crate::properties::svg;
29859
29860    minify_test(".foo { fill: yellow; }", ".foo{fill:#ff0}");
29861    minify_test(".foo { fill: url(#foo); }", ".foo{fill:url(#foo)}");
29862    minify_test(".foo { fill: url(#foo) none; }", ".foo{fill:url(#foo) none}");
29863    minify_test(".foo { fill: url(#foo) yellow; }", ".foo{fill:url(#foo) #ff0}");
29864    minify_test(".foo { fill: none; }", ".foo{fill:none}");
29865    minify_test(".foo { fill: context-fill; }", ".foo{fill:context-fill}");
29866    minify_test(".foo { fill: context-stroke; }", ".foo{fill:context-stroke}");
29867
29868    minify_test(".foo { stroke: yellow; }", ".foo{stroke:#ff0}");
29869    minify_test(".foo { stroke: url(#foo); }", ".foo{stroke:url(#foo)}");
29870    minify_test(".foo { stroke: url(#foo) none; }", ".foo{stroke:url(#foo) none}");
29871    minify_test(".foo { stroke: url(#foo) yellow; }", ".foo{stroke:url(#foo) #ff0}");
29872    minify_test(".foo { stroke: none; }", ".foo{stroke:none}");
29873    minify_test(".foo { stroke: context-fill; }", ".foo{stroke:context-fill}");
29874    minify_test(".foo { stroke: context-stroke; }", ".foo{stroke:context-stroke}");
29875
29876    minify_test(".foo { marker-start: url(#foo); }", ".foo{marker-start:url(#foo)}");
29877
29878    minify_test(".foo { stroke-dasharray: 4 1 2; }", ".foo{stroke-dasharray:4 1 2}");
29879    minify_test(".foo { stroke-dasharray: 4,1,2; }", ".foo{stroke-dasharray:4 1 2}");
29880    minify_test(".foo { stroke-dasharray: 4, 1, 2; }", ".foo{stroke-dasharray:4 1 2}");
29881    minify_test(
29882      ".foo { stroke-dasharray: 4px, 1px, 2px; }",
29883      ".foo{stroke-dasharray:4 1 2}",
29884    );
29885
29886    minify_test(".foo { mask: url('foo.svg'); }", ".foo{mask:url(foo.svg)}");
29887    minify_test(
29888      ".foo { mask: url(masks.svg#star) luminance }",
29889      ".foo{mask:url(masks.svg#star) luminance}",
29890    );
29891    minify_test(
29892      ".foo { mask: url(masks.svg#star) 40px 20px }",
29893      ".foo{mask:url(masks.svg#star) 40px 20px}",
29894    );
29895    minify_test(
29896      ".foo { mask: url(masks.svg#star) 0 0 / 50px 50px }",
29897      ".foo{mask:url(masks.svg#star) 0 0/50px 50px}",
29898    );
29899    minify_test(
29900      ".foo { mask: url(masks.svg#star) repeat-x }",
29901      ".foo{mask:url(masks.svg#star) repeat-x}",
29902    );
29903    minify_test(
29904      ".foo { mask: url(masks.svg#star) stroke-box }",
29905      ".foo{mask:url(masks.svg#star) stroke-box}",
29906    );
29907    minify_test(
29908      ".foo { mask: url(masks.svg#star) stroke-box stroke-box }",
29909      ".foo{mask:url(masks.svg#star) stroke-box}",
29910    );
29911    minify_test(
29912      ".foo { mask: url(masks.svg#star) border-box }",
29913      ".foo{mask:url(masks.svg#star)}",
29914    );
29915    minify_test(
29916      ".foo { mask: url(masks.svg#star) left / 16px repeat-y, url(masks.svg#circle) right / 16px repeat-y }",
29917      ".foo{mask:url(masks.svg#star) 0/16px repeat-y,url(masks.svg#circle) 100%/16px repeat-y}",
29918    );
29919
29920    minify_test(
29921      r#"
29922      .foo {
29923        mask-border: none;
29924      }
29925      "#,
29926      ".foo{mask-border:none}",
29927    );
29928    minify_test(
29929      r#"
29930      .foo {
29931        -webkit-mask-box-image: none;
29932      }
29933      "#,
29934      ".foo{-webkit-mask-box-image:none}",
29935    );
29936    minify_test(
29937      ".foo { mask-border: url('border-mask.png') 25; }",
29938      ".foo{mask-border:url(border-mask.png) 25}",
29939    );
29940    minify_test(
29941      ".foo { mask-border: url('border-mask.png') 25 / 35px / 12px space alpha; }",
29942      ".foo{mask-border:url(border-mask.png) 25/35px/12px space}",
29943    );
29944    minify_test(
29945      ".foo { mask-border: url('border-mask.png') 25 / 35px / 12px space luminance; }",
29946      ".foo{mask-border:url(border-mask.png) 25/35px/12px space luminance}",
29947    );
29948    minify_test(
29949      ".foo { mask-border: url('border-mask.png') luminance 25 / 35px / 12px space; }",
29950      ".foo{mask-border:url(border-mask.png) 25/35px/12px space luminance}",
29951    );
29952
29953    minify_test(
29954      ".foo { clip-path: url('clip.svg#star'); }",
29955      ".foo{clip-path:url(clip.svg#star)}",
29956    );
29957    minify_test(".foo { clip-path: margin-box; }", ".foo{clip-path:margin-box}");
29958    minify_test(
29959      ".foo { clip-path: inset(100px 50px); }",
29960      ".foo{clip-path:inset(100px 50px)}",
29961    );
29962    minify_test(
29963      ".foo { clip-path: inset(100px 50px round 5px); }",
29964      ".foo{clip-path:inset(100px 50px round 5px)}",
29965    );
29966    minify_test(
29967      ".foo { clip-path: inset(100px 50px round 5px 5px 5px 5px); }",
29968      ".foo{clip-path:inset(100px 50px round 5px)}",
29969    );
29970    minify_test(".foo { clip-path: circle(50px); }", ".foo{clip-path:circle(50px)}");
29971    minify_test(
29972      ".foo { clip-path: circle(50px at center center); }",
29973      ".foo{clip-path:circle(50px)}",
29974    );
29975    minify_test(
29976      ".foo { clip-path: circle(50px at 50% 50%); }",
29977      ".foo{clip-path:circle(50px)}",
29978    );
29979    minify_test(
29980      ".foo { clip-path: circle(50px at 0 100px); }",
29981      ".foo{clip-path:circle(50px at 0 100px)}",
29982    );
29983    minify_test(
29984      ".foo { clip-path: circle(closest-side at 0 100px); }",
29985      ".foo{clip-path:circle(at 0 100px)}",
29986    );
29987    minify_test(
29988      ".foo { clip-path: circle(farthest-side at 0 100px); }",
29989      ".foo{clip-path:circle(farthest-side at 0 100px)}",
29990    );
29991    minify_test(
29992      ".foo { clip-path: circle(closest-side at 50% 50%); }",
29993      ".foo{clip-path:circle()}",
29994    );
29995    minify_test(
29996      ".foo { clip-path: ellipse(50px 60px at 0 10% 20%); }",
29997      ".foo{clip-path:ellipse(50px 60px at 0 10% 20%)}",
29998    );
29999    minify_test(
30000      ".foo { clip-path: ellipse(50px 60px at center center); }",
30001      ".foo{clip-path:ellipse(50px 60px)}",
30002    );
30003    minify_test(
30004      ".foo { clip-path: ellipse(closest-side closest-side at 50% 50%); }",
30005      ".foo{clip-path:ellipse()}",
30006    );
30007    minify_test(
30008      ".foo { clip-path: ellipse(closest-side closest-side at 10% 20%); }",
30009      ".foo{clip-path:ellipse(at 10% 20%)}",
30010    );
30011    minify_test(
30012      ".foo { clip-path: ellipse(farthest-side closest-side at 10% 20%); }",
30013      ".foo{clip-path:ellipse(farthest-side closest-side at 10% 20%)}",
30014    );
30015    minify_test(
30016      ".foo { clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); }",
30017      ".foo{clip-path:polygon(50% 0%,100% 50%,50% 100%,0% 50%)}",
30018    );
30019    minify_test(
30020      ".foo { clip-path: polygon(nonzero, 50% 0%, 100% 50%, 50% 100%, 0% 50%); }",
30021      ".foo{clip-path:polygon(50% 0%,100% 50%,50% 100%,0% 50%)}",
30022    );
30023    minify_test(
30024      ".foo { clip-path: polygon(evenodd, 50% 0%, 100% 50%, 50% 100%, 0% 50%); }",
30025      ".foo{clip-path:polygon(evenodd,50% 0%,100% 50%,50% 100%,0% 50%)}",
30026    );
30027    minify_test(
30028      ".foo { clip-path: padding-box circle(50px at 0 100px); }",
30029      ".foo{clip-path:circle(50px at 0 100px) padding-box}",
30030    );
30031    minify_test(
30032      ".foo { clip-path: circle(50px at 0 100px) padding-box; }",
30033      ".foo{clip-path:circle(50px at 0 100px) padding-box}",
30034    );
30035    minify_test(
30036      ".foo { clip-path: circle(50px at 0 100px) border-box; }",
30037      ".foo{clip-path:circle(50px at 0 100px)}",
30038    );
30039
30040    prefix_test(
30041      ".foo { clip-path: circle(50px); }",
30042      indoc! { r#"
30043        .foo {
30044          -webkit-clip-path: circle(50px);
30045          clip-path: circle(50px);
30046        }
30047      "#},
30048      Browsers {
30049        chrome: Some(30 << 16),
30050        ..Browsers::default()
30051      },
30052    );
30053
30054    prefix_test(
30055      ".foo { clip-path: circle(50px); }",
30056      indoc! { r#"
30057        .foo {
30058          clip-path: circle(50px);
30059        }
30060      "#},
30061      Browsers {
30062        chrome: Some(80 << 16),
30063        ..Browsers::default()
30064      },
30065    );
30066
30067    prefix_test(
30068      ".foo { clip-path: circle(50px); }",
30069      indoc! { r#"
30070        .foo {
30071          -webkit-clip-path: circle(50px);
30072          clip-path: circle(50px);
30073        }
30074      "#},
30075      Browsers {
30076        safari: Some(8 << 16),
30077        ..Browsers::default()
30078      },
30079    );
30080
30081    prefix_test(
30082      ".foo { clip-path: circle(50px); }",
30083      indoc! { r#"
30084        .foo {
30085          clip-path: circle(50px);
30086        }
30087      "#},
30088      Browsers {
30089        safari: Some(14 << 16),
30090        ..Browsers::default()
30091      },
30092    );
30093
30094    prefix_test(
30095      ".foo { fill: lch(50.998% 135.363 338) }",
30096      indoc! { r#"
30097        .foo {
30098          fill: #f000c0;
30099          fill: color(display-p3 .972962 -.362078 .804206);
30100          fill: lch(50.998% 135.363 338);
30101        }
30102      "#},
30103      Browsers {
30104        chrome: Some(90 << 16),
30105        safari: Some(14 << 16),
30106        ..Browsers::default()
30107      },
30108    );
30109
30110    prefix_test(
30111      ".foo { stroke: lch(50.998% 135.363 338) }",
30112      indoc! { r#"
30113        .foo {
30114          stroke: #f000c0;
30115          stroke: color(display-p3 .972962 -.362078 .804206);
30116          stroke: lch(50.998% 135.363 338);
30117        }
30118      "#},
30119      Browsers {
30120        chrome: Some(90 << 16),
30121        safari: Some(14 << 16),
30122        ..Browsers::default()
30123      },
30124    );
30125
30126    prefix_test(
30127      ".foo { fill: url(#foo) lch(50.998% 135.363 338) }",
30128      indoc! { r##"
30129        .foo {
30130          fill: url("#foo") #f000c0;
30131          fill: url("#foo") color(display-p3 .972962 -.362078 .804206);
30132          fill: url("#foo") lch(50.998% 135.363 338);
30133        }
30134      "##},
30135      Browsers {
30136        chrome: Some(90 << 16),
30137        safari: Some(14 << 16),
30138        ..Browsers::default()
30139      },
30140    );
30141
30142    prefix_test(
30143      ".foo { fill: var(--url) lch(50.998% 135.363 338) }",
30144      indoc! { r#"
30145        .foo {
30146          fill: var(--url) #f000c0;
30147        }
30148
30149        @supports (color: lab(0% 0 0)) {
30150          .foo {
30151            fill: var(--url) lab(50.998% 125.506 -50.7078);
30152          }
30153        }
30154      "#},
30155      Browsers {
30156        chrome: Some(90 << 16),
30157        ..Browsers::default()
30158      },
30159    );
30160
30161    prefix_test(
30162      r#"
30163        @supports (color: lab(0% 0 0)) {
30164          .foo {
30165            fill: var(--url) lab(50.998% 125.506 -50.7078);
30166          }
30167        }
30168      "#,
30169      indoc! { r#"
30170        @supports (color: lab(0% 0 0)) {
30171          .foo {
30172            fill: var(--url) lab(50.998% 125.506 -50.7078);
30173          }
30174        }
30175      "#},
30176      Browsers {
30177        chrome: Some(90 << 16),
30178        ..Browsers::default()
30179      },
30180    );
30181
30182    prefix_test(
30183      ".foo { mask-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
30184      indoc! { r#"
30185        .foo {
30186          -webkit-mask-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ff0b0c), to(#766eff));
30187          -webkit-mask-image: -webkit-linear-gradient(top, #ff0b0c, #766eff);
30188          -webkit-mask-image: linear-gradient(#ff0b0c, #766eff);
30189          mask-image: linear-gradient(#ff0b0c, #766eff);
30190          -webkit-mask-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
30191          mask-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
30192        }
30193      "#},
30194      Browsers {
30195        chrome: Some(8 << 16),
30196        ..Browsers::default()
30197      },
30198    );
30199
30200    prefix_test(
30201      ".foo { mask-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) }",
30202      indoc! { r#"
30203        .foo {
30204          -webkit-mask-image: linear-gradient(#ff0b0c, #766eff);
30205          mask-image: linear-gradient(#ff0b0c, #766eff);
30206          -webkit-mask-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
30207          mask-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
30208        }
30209      "#},
30210      Browsers {
30211        chrome: Some(95 << 16),
30212        ..Browsers::default()
30213      },
30214    );
30215
30216    prefix_test(
30217      ".foo { mask-image: linear-gradient(red, green) }",
30218      indoc! { r#"
30219        .foo {
30220          -webkit-mask-image: linear-gradient(red, green);
30221          mask-image: linear-gradient(red, green);
30222        }
30223      "#},
30224      Browsers {
30225        chrome: Some(95 << 16),
30226        ..Browsers::default()
30227      },
30228    );
30229
30230    prefix_test(
30231      ".foo { -webkit-mask-image: url(x.svg); mask-image: url(x.svg); }",
30232      indoc! { r#"
30233        .foo {
30234          -webkit-mask-image: url("x.svg");
30235          mask-image: url("x.svg");
30236        }
30237      "#},
30238      Browsers {
30239        chrome: Some(95 << 16),
30240        ..Browsers::default()
30241      },
30242    );
30243
30244    prefix_test(
30245      ".foo { mask: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 40px 20px }",
30246      indoc! { r#"
30247        .foo {
30248          -webkit-mask: -webkit-gradient(linear, 0 0, 0 100%, from(#ff0b0c), to(#766eff)) 40px 20px;
30249          -webkit-mask: -webkit-linear-gradient(top, #ff0b0c, #766eff) 40px 20px;
30250          -webkit-mask: linear-gradient(#ff0b0c, #766eff) 40px 20px;
30251          mask: linear-gradient(#ff0b0c, #766eff) 40px 20px;
30252          -webkit-mask: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 40px 20px;
30253          mask: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 40px 20px;
30254        }
30255      "#},
30256      Browsers {
30257        chrome: Some(8 << 16),
30258        ..Browsers::default()
30259      },
30260    );
30261
30262    prefix_test(
30263      ".foo { mask: -webkit-linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 40px 20px }",
30264      indoc! { r#"
30265        .foo {
30266          -webkit-mask: -webkit-gradient(linear, 0 0, 0 100%, from(#ff0b0c), to(#766eff)) 40px 20px;
30267          -webkit-mask: -webkit-linear-gradient(#ff0b0c, #766eff) 40px 20px;
30268        }
30269      "#},
30270      Browsers {
30271        chrome: Some(8 << 16),
30272        ..Browsers::default()
30273      },
30274    );
30275
30276    prefix_test(
30277      ".foo { mask: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 40px var(--foo) }",
30278      indoc! { r#"
30279        .foo {
30280          -webkit-mask: linear-gradient(#ff0b0c, #766eff) 40px var(--foo);
30281          mask: linear-gradient(#ff0b0c, #766eff) 40px var(--foo);
30282        }
30283
30284        @supports (color: lab(0% 0 0)) {
30285          .foo {
30286            -webkit-mask: linear-gradient(lab(56.208% 94.4644 98.8928), lab(51% 70.4544 -115.586)) 40px var(--foo);
30287            mask: linear-gradient(lab(56.208% 94.4644 98.8928), lab(51% 70.4544 -115.586)) 40px var(--foo);
30288          }
30289        }
30290      "#},
30291      Browsers {
30292        chrome: Some(90 << 16),
30293        ..Browsers::default()
30294      },
30295    );
30296
30297    prefix_test(
30298      r#"
30299        @supports (color: lab(0% 0 0)) {
30300          .foo {
30301            mask: linear-gradient(lab(56.208% 94.4644 98.8928), lab(51% 70.4544 -115.586)) 40px var(--foo);
30302          }
30303        }
30304      "#,
30305      indoc! { r#"
30306        @supports (color: lab(0% 0 0)) {
30307          .foo {
30308            -webkit-mask: linear-gradient(lab(56.208% 94.4644 98.8928), lab(51% 70.4544 -115.586)) 40px var(--foo);
30309            mask: linear-gradient(lab(56.208% 94.4644 98.8928), lab(51% 70.4544 -115.586)) 40px var(--foo);
30310          }
30311        }
30312      "#},
30313      Browsers {
30314        chrome: Some(90 << 16),
30315        ..Browsers::default()
30316      },
30317    );
30318
30319    prefix_test(
30320      ".foo { mask: url(masks.svg#star) luminance }",
30321      indoc! { r#"
30322        .foo {
30323          -webkit-mask: url("masks.svg#star");
30324          -webkit-mask-source-type: luminance;
30325          mask: url("masks.svg#star") luminance;
30326        }
30327    "#},
30328      Browsers {
30329        chrome: Some(90 << 16),
30330        ..Browsers::default()
30331      },
30332    );
30333
30334    prefix_test(
30335      ".foo { mask-image: url(masks.svg#star) }",
30336      indoc! { r#"
30337        .foo {
30338          -webkit-mask-image: url("masks.svg#star");
30339          mask-image: url("masks.svg#star");
30340        }
30341    "#},
30342      Browsers {
30343        chrome: Some(90 << 16),
30344        ..Browsers::default()
30345      },
30346    );
30347
30348    prefix_test(
30349      r#"
30350        .foo {
30351          mask-image: url(masks.svg#star);
30352          mask-position: 25% 75%;
30353          mask-size: cover;
30354          mask-repeat: no-repeat;
30355          mask-clip: padding-box;
30356          mask-origin: content-box;
30357          mask-composite: subtract;
30358          mask-mode: luminance;
30359        }
30360      "#,
30361      indoc! { r#"
30362        .foo {
30363          -webkit-mask: url("masks.svg#star") 25% 75% / cover no-repeat content-box padding-box;
30364          -webkit-mask-composite: source-out;
30365          -webkit-mask-source-type: luminance;
30366          mask: url("masks.svg#star") 25% 75% / cover no-repeat content-box padding-box subtract luminance;
30367        }
30368    "#},
30369      Browsers {
30370        chrome: Some(90 << 16),
30371        ..Browsers::default()
30372      },
30373    );
30374
30375    prefix_test(
30376      r#"
30377        .foo {
30378          mask-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
30379          mask-position: 25% 75%;
30380          mask-size: cover;
30381          mask-repeat: no-repeat;
30382          mask-clip: padding-box;
30383          mask-origin: content-box;
30384          mask-composite: subtract;
30385          mask-mode: luminance;
30386        }
30387      "#,
30388      indoc! { r#"
30389        .foo {
30390          -webkit-mask: linear-gradient(#ff0b0c, #766eff) 25% 75% / cover no-repeat content-box padding-box;
30391          -webkit-mask-composite: source-out;
30392          -webkit-mask-source-type: luminance;
30393          mask: linear-gradient(#ff0b0c, #766eff) 25% 75% / cover no-repeat content-box padding-box subtract luminance;
30394          -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;
30395          -webkit-mask-composite: source-out;
30396          -webkit-mask-source-type: luminance;
30397          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;
30398        }
30399    "#},
30400      Browsers {
30401        chrome: Some(90 << 16),
30402        ..Browsers::default()
30403      },
30404    );
30405
30406    test(
30407      r#"
30408        .foo {
30409          mask: none center / 100% no-repeat;
30410          mask-image: var(--svg);
30411        }
30412      "#,
30413      indoc! { r#"
30414        .foo {
30415          mask: none center / 100% no-repeat;
30416          mask-image: var(--svg);
30417        }
30418      "#},
30419    );
30420
30421    prefix_test(
30422      r#"
30423        .foo {
30424          mask-composite: subtract;
30425        }
30426      "#,
30427      indoc! { r#"
30428        .foo {
30429          -webkit-mask-composite: source-out;
30430          mask-composite: subtract;
30431        }
30432    "#},
30433      Browsers {
30434        chrome: Some(90 << 16),
30435        ..Browsers::default()
30436      },
30437    );
30438
30439    prefix_test(
30440      r#"
30441        .foo {
30442          mask-mode: luminance;
30443        }
30444      "#,
30445      indoc! { r#"
30446        .foo {
30447          -webkit-mask-source-type: luminance;
30448          mask-mode: luminance;
30449        }
30450    "#},
30451      Browsers {
30452        chrome: Some(90 << 16),
30453        ..Browsers::default()
30454      },
30455    );
30456
30457    prefix_test(
30458      r#"
30459        .foo {
30460          mask-border: url('border-mask.png') 25 / 35px / 12px space luminance;
30461        }
30462      "#,
30463      indoc! { r#"
30464        .foo {
30465          -webkit-mask-box-image: url("border-mask.png") 25 / 35px / 12px space;
30466          mask-border: url("border-mask.png") 25 / 35px / 12px space luminance;
30467        }
30468    "#},
30469      Browsers {
30470        chrome: Some(90 << 16),
30471        ..Browsers::default()
30472      },
30473    );
30474
30475    prefix_test(
30476      r#"
30477        .foo {
30478          mask-border: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 25 / 35px / 12px space luminance;
30479        }
30480      "#,
30481      indoc! { r#"
30482        .foo {
30483          -webkit-mask-box-image: linear-gradient(#ff0b0c, #766eff) 25 / 35px / 12px space;
30484          mask-border: linear-gradient(#ff0b0c, #766eff) 25 / 35px / 12px space luminance;
30485          -webkit-mask-box-image: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 25 / 35px / 12px space;
30486          mask-border: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) 25 / 35px / 12px space luminance;
30487        }
30488    "#},
30489      Browsers {
30490        chrome: Some(90 << 16),
30491        ..Browsers::default()
30492      },
30493    );
30494
30495    prefix_test(
30496      r#"
30497        .foo {
30498          mask-border-source: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
30499        }
30500      "#,
30501      indoc! { r#"
30502        .foo {
30503          -webkit-mask-box-image-source: linear-gradient(#ff0b0c, #766eff);
30504          mask-border-source: linear-gradient(#ff0b0c, #766eff);
30505          -webkit-mask-box-image-source: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
30506          mask-border-source: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364));
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-source: url(foo.png);
30519          mask-border-slice: 10 40 10 40;
30520          mask-border-width: 10px;
30521          mask-border-outset: 0;
30522          mask-border-repeat: round round;
30523          mask-border-mode: luminance;
30524        }
30525      "#,
30526      indoc! { r#"
30527        .foo {
30528          -webkit-mask-box-image: url("foo.png") 10 40 / 10px round;
30529          mask-border: url("foo.png") 10 40 / 10px round luminance;
30530        }
30531    "#},
30532      Browsers {
30533        chrome: Some(90 << 16),
30534        ..Browsers::default()
30535      },
30536    );
30537
30538    prefix_test(
30539      r#"
30540        .foo {
30541          -webkit-mask-box-image-source: url(foo.png);
30542          -webkit-mask-box-image-slice: 10 40 10 40;
30543          -webkit-mask-box-image-width: 10px;
30544          -webkit-mask-box-image-outset: 0;
30545          -webkit-mask-box-image-repeat: round round;
30546        }
30547      "#,
30548      indoc! { r#"
30549        .foo {
30550          -webkit-mask-box-image: url("foo.png") 10 40 / 10px round;
30551        }
30552    "#},
30553      Browsers {
30554        chrome: Some(90 << 16),
30555        ..Browsers::default()
30556      },
30557    );
30558
30559    prefix_test(
30560      r#"
30561        .foo {
30562          mask-border-slice: 10 40 10 40;
30563        }
30564      "#,
30565      indoc! { r#"
30566        .foo {
30567          -webkit-mask-box-image-slice: 10 40;
30568          mask-border-slice: 10 40;
30569        }
30570    "#},
30571      Browsers {
30572        chrome: Some(90 << 16),
30573        ..Browsers::default()
30574      },
30575    );
30576
30577    prefix_test(
30578      r#"
30579        .foo {
30580          mask-border-slice: var(--foo);
30581        }
30582      "#,
30583      indoc! { r#"
30584        .foo {
30585          -webkit-mask-box-image-slice: var(--foo);
30586          mask-border-slice: var(--foo);
30587        }
30588    "#},
30589      Browsers {
30590        chrome: Some(90 << 16),
30591        ..Browsers::default()
30592      },
30593    );
30594
30595    prefix_test(
30596      r#"
30597        .foo {
30598          mask-border: linear-gradient(lch(56.208% 136.76 46.312), lch(51% 135.366 301.364)) var(--foo);
30599        }
30600      "#,
30601      indoc! { r#"
30602        .foo {
30603          -webkit-mask-box-image: linear-gradient(#ff0b0c, #766eff) var(--foo);
30604          mask-border: linear-gradient(#ff0b0c, #766eff) var(--foo);
30605        }
30606
30607        @supports (color: lab(0% 0 0)) {
30608          .foo {
30609            -webkit-mask-box-image: linear-gradient(lab(56.208% 94.4644 98.8928), lab(51% 70.4544 -115.586)) var(--foo);
30610            mask-border: linear-gradient(lab(56.208% 94.4644 98.8928), lab(51% 70.4544 -115.586)) var(--foo);
30611          }
30612        }
30613    "#},
30614      Browsers {
30615        chrome: Some(90 << 16),
30616        ..Browsers::default()
30617      },
30618    );
30619
30620    prefix_test(
30621      r#"
30622        .foo {
30623          transition: mask 200ms;
30624        }
30625      "#,
30626      indoc! { r#"
30627        .foo {
30628          transition: -webkit-mask .2s, mask .2s;
30629        }
30630    "#},
30631      Browsers {
30632        chrome: Some(90 << 16),
30633        ..Browsers::default()
30634      },
30635    );
30636
30637    prefix_test(
30638      r#"
30639        .foo {
30640          transition: mask-border 200ms;
30641        }
30642      "#,
30643      indoc! { r#"
30644        .foo {
30645          transition: -webkit-mask-box-image .2s, mask-border .2s;
30646        }
30647    "#},
30648      Browsers {
30649        chrome: Some(90 << 16),
30650        ..Browsers::default()
30651      },
30652    );
30653
30654    prefix_test(
30655      r#"
30656        .foo {
30657          transition-property: mask;
30658        }
30659      "#,
30660      indoc! { r#"
30661        .foo {
30662          transition-property: -webkit-mask, mask;
30663        }
30664    "#},
30665      Browsers {
30666        chrome: Some(90 << 16),
30667        ..Browsers::default()
30668      },
30669    );
30670
30671    prefix_test(
30672      r#"
30673        .foo {
30674          transition-property: mask-border;
30675        }
30676      "#,
30677      indoc! { r#"
30678        .foo {
30679          transition-property: -webkit-mask-box-image, mask-border;
30680        }
30681    "#},
30682      Browsers {
30683        chrome: Some(90 << 16),
30684        ..Browsers::default()
30685      },
30686    );
30687
30688    prefix_test(
30689      r#"
30690        .foo {
30691          transition-property: mask-composite, mask-mode;
30692        }
30693      "#,
30694      indoc! { r#"
30695        .foo {
30696          transition-property: -webkit-mask-composite, mask-composite, -webkit-mask-source-type, mask-mode;
30697        }
30698    "#},
30699      Browsers {
30700        chrome: Some(90 << 16),
30701        ..Browsers::default()
30702      },
30703    );
30704
30705    let property =
30706      Property::parse_string("text-rendering".into(), "geometricPrecision", ParserOptions::default()).unwrap();
30707    assert_eq!(
30708      property,
30709      Property::TextRendering(svg::TextRendering::GeometricPrecision)
30710    );
30711    let property =
30712      Property::parse_string("shape-rendering".into(), "geometricPrecision", ParserOptions::default()).unwrap();
30713    assert_eq!(
30714      property,
30715      Property::ShapeRendering(svg::ShapeRendering::GeometricPrecision)
30716    );
30717    let property = Property::parse_string("color-interpolation".into(), "sRGB", ParserOptions::default()).unwrap();
30718    assert_eq!(property, Property::ColorInterpolation(svg::ColorInterpolation::SRGB));
30719  }
30720
30721  #[test]
30722  fn test_mask_image_prefix_duplicates() {
30723    let targets = Browsers {
30724      chrome: Some(90 << 16),
30725      ..Browsers::default()
30726    };
30727
30728    for (source, expected) in [
30729      (
30730        ".foo { -webkit-mask-image: var(--image); mask-image: var(--image) }",
30731        indoc! { r#"
30732          .foo {
30733            -webkit-mask-image: var(--image);
30734            mask-image: var(--image);
30735          }
30736        "#},
30737      ),
30738      (
30739        ".foo { mask-image: var(--first); mask-image: var(--second) }",
30740        indoc! { r#"
30741          .foo {
30742            -webkit-mask-image: var(--first);
30743            mask-image: var(--first);
30744            -webkit-mask-image: var(--second);
30745            mask-image: var(--second);
30746          }
30747        "#},
30748      ),
30749      (
30750        ".foo { mask-image: var(--image); mask-position: center; -webkit-mask-image: var(--image) }",
30751        indoc! { r#"
30752          .foo {
30753            -webkit-mask-image: var(--image);
30754            mask-image: var(--image);
30755            -webkit-mask-position: center;
30756            mask-position: center;
30757            -webkit-mask-image: var(--image);
30758          }
30759        "#},
30760      ),
30761      (
30762        ".foo { mask-image: var(--image) !important; -webkit-mask-image: var(--image) }",
30763        indoc! { r#"
30764          .foo {
30765            -webkit-mask-image: var(--image);
30766            -webkit-mask-image: var(--image) !important;
30767            mask-image: var(--image) !important;
30768          }
30769        "#},
30770      ),
30771    ] {
30772      prefix_test(source, expected, targets);
30773      prefix_test(expected, expected, targets);
30774    }
30775
30776    prefix_test(
30777      ".foo { -webkit-mask-image: var(--image); mask-image: var(--image) }",
30778      indoc! { r#"
30779        .foo {
30780          -webkit-mask-image: var(--image);
30781          mask-image: var(--image);
30782        }
30783      "#},
30784      Browsers {
30785        chrome: Some(130 << 16),
30786        ..Browsers::default()
30787      },
30788    );
30789  }
30790
30791  #[test]
30792  fn test_filter() {
30793    property_range_test(
30794      &["filter", "backdrop-filter"],
30795      &[
30796        ("brightness(-1)", None),
30797        ("contrast(-1)", None),
30798        ("grayscale(-1)", None),
30799        ("invert(-1)", None),
30800        ("opacity(-1)", None),
30801        ("saturate(-1)", None),
30802        ("sepia(-1)", None),
30803        ("blur(-1px)", None),
30804        ("blur(calc(-1px))", Some("blur()")),
30805        ("drop-shadow(1px 2px -3px)", None),
30806        ("hue-rotate(-1deg)", Some("hue-rotate(-1deg)")),
30807      ],
30808    );
30809    minify_test(
30810      ".foo { filter: url('filters.svg#filter-id'); }",
30811      ".foo{filter:url(filters.svg#filter-id)}",
30812    );
30813    minify_test(".foo { filter: blur(5px); }", ".foo{filter:blur(5px)}");
30814    minify_test(".foo { filter: blur(0px); }", ".foo{filter:blur()}");
30815    minify_test(".foo { filter: brightness(10%); }", ".foo{filter:brightness(10%)}");
30816    minify_test(".foo { filter: brightness(100%); }", ".foo{filter:brightness()}");
30817    minify_test(
30818      ".foo { filter: drop-shadow(16px 16px 20px yellow); }",
30819      ".foo{filter:drop-shadow(16px 16px 20px #ff0)}",
30820    );
30821    minify_test(
30822      ".foo { filter: contrast(175%) brightness(3%); }",
30823      ".foo{filter:contrast(175%)brightness(3%)}",
30824    );
30825    minify_test(".foo { filter: hue-rotate(0) }", ".foo{filter:hue-rotate()}");
30826
30827    prefix_test(
30828      ".foo { filter: blur(5px) }",
30829      indoc! { r#"
30830        .foo {
30831          -webkit-filter: blur(5px);
30832          filter: blur(5px);
30833        }
30834      "#},
30835      Browsers {
30836        chrome: Some(20 << 16),
30837        ..Browsers::default()
30838      },
30839    );
30840
30841    prefix_test(
30842      ".foo { filter: blur(5px) }",
30843      indoc! { r#"
30844        .foo {
30845          filter: blur(5px);
30846        }
30847      "#},
30848      Browsers {
30849        chrome: Some(80 << 16),
30850        ..Browsers::default()
30851      },
30852    );
30853
30854    prefix_test(
30855      ".foo { backdrop-filter: blur(5px) }",
30856      indoc! { r#"
30857        .foo {
30858          backdrop-filter: blur(5px);
30859        }
30860      "#},
30861      Browsers {
30862        chrome: Some(80 << 16),
30863        ..Browsers::default()
30864      },
30865    );
30866
30867    prefix_test(
30868      ".foo { backdrop-filter: blur(5px) }",
30869      indoc! { r#"
30870        .foo {
30871          -webkit-backdrop-filter: blur(5px);
30872          backdrop-filter: blur(5px);
30873        }
30874      "#},
30875      Browsers {
30876        safari: Some(15 << 16),
30877        ..Browsers::default()
30878      },
30879    );
30880    prefix_test(
30881      r#"
30882      .foo {
30883        -webkit-backdrop-filter: blur(8px);
30884        backdrop-filter: blur(8px);
30885      }
30886      "#,
30887      indoc! {r#"
30888      .foo {
30889        -webkit-backdrop-filter: blur(8px);
30890        backdrop-filter: blur(8px);
30891      }
30892      "#},
30893      Browsers {
30894        safari: Some(16 << 16),
30895        ..Browsers::default()
30896      },
30897    );
30898
30899    prefix_test(
30900      ".foo { filter: var(--foo) }",
30901      indoc! { r#"
30902        .foo {
30903          -webkit-filter: var(--foo);
30904          filter: var(--foo);
30905        }
30906      "#},
30907      Browsers {
30908        chrome: Some(20 << 16),
30909        ..Browsers::default()
30910      },
30911    );
30912
30913    prefix_test(
30914      ".foo { filter: drop-shadow(16px 16px 20px lab(40% 56.6 39)) }",
30915      indoc! { r#"
30916        .foo {
30917          -webkit-filter: drop-shadow(16px 16px 20px #b32323);
30918          filter: drop-shadow(16px 16px 20px #b32323);
30919          filter: drop-shadow(16px 16px 20px lab(40% 56.6 39));
30920        }
30921      "#},
30922      Browsers {
30923        chrome: Some(20 << 16),
30924        ..Browsers::default()
30925      },
30926    );
30927
30928    prefix_test(
30929      ".foo { filter: contrast(175%) drop-shadow(16px 16px 20px lab(40% 56.6 39)) }",
30930      indoc! { r#"
30931        .foo {
30932          filter: contrast(175%) drop-shadow(16px 16px 20px #b32323);
30933          filter: contrast(175%) drop-shadow(16px 16px 20px lab(40% 56.6 39));
30934        }
30935      "#},
30936      Browsers {
30937        chrome: Some(4 << 16),
30938        ..Browsers::default()
30939      },
30940    );
30941
30942    prefix_test(
30943      ".foo { filter: drop-shadow(16px 16px 20px lab(40% 56.6 39)) drop-shadow(16px 16px 20px yellow) }",
30944      indoc! { r#"
30945        .foo {
30946          filter: drop-shadow(16px 16px 20px #b32323) drop-shadow(16px 16px 20px #ff0);
30947          filter: drop-shadow(16px 16px 20px lab(40% 56.6 39)) drop-shadow(16px 16px 20px #ff0);
30948        }
30949      "#},
30950      Browsers {
30951        chrome: Some(4 << 16),
30952        ..Browsers::default()
30953      },
30954    );
30955
30956    prefix_test(
30957      ".foo { filter: var(--foo) drop-shadow(16px 16px 20px lab(40% 56.6 39)) }",
30958      indoc! { r#"
30959        .foo {
30960          filter: var(--foo) drop-shadow(16px 16px 20px #b32323);
30961        }
30962
30963        @supports (color: lab(0% 0 0)) {
30964          .foo {
30965            filter: var(--foo) drop-shadow(16px 16px 20px lab(40% 56.6 39));
30966          }
30967        }
30968      "#},
30969      Browsers {
30970        chrome: Some(4 << 16),
30971        ..Browsers::default()
30972      },
30973    );
30974  }
30975
30976  #[test]
30977  fn test_mix_blend_mode() {
30978    minify_test(".foo { mix-blend-mode: normal }", ".foo{mix-blend-mode:normal}");
30979    minify_test(".foo { mix-blend-mode: multiply }", ".foo{mix-blend-mode:multiply}");
30980    minify_test(".foo { mix-blend-mode: screen }", ".foo{mix-blend-mode:screen}");
30981    minify_test(".foo { mix-blend-mode: overlay }", ".foo{mix-blend-mode:overlay}");
30982    minify_test(".foo { mix-blend-mode: darken }", ".foo{mix-blend-mode:darken}");
30983    minify_test(".foo { mix-blend-mode: lighten }", ".foo{mix-blend-mode:lighten}");
30984    minify_test(
30985      ".foo { mix-blend-mode: color-dodge }",
30986      ".foo{mix-blend-mode:color-dodge}",
30987    );
30988    minify_test(".foo { mix-blend-mode: color-burn }", ".foo{mix-blend-mode:color-burn}");
30989    minify_test(".foo { mix-blend-mode: hard-light }", ".foo{mix-blend-mode:hard-light}");
30990    minify_test(".foo { mix-blend-mode: soft-light }", ".foo{mix-blend-mode:soft-light}");
30991    minify_test(".foo { mix-blend-mode: difference }", ".foo{mix-blend-mode:difference}");
30992    minify_test(".foo { mix-blend-mode: exclusion }", ".foo{mix-blend-mode:exclusion}");
30993    minify_test(".foo { mix-blend-mode: hue }", ".foo{mix-blend-mode:hue}");
30994    minify_test(".foo { mix-blend-mode: saturation }", ".foo{mix-blend-mode:saturation}");
30995    minify_test(".foo { mix-blend-mode: color }", ".foo{mix-blend-mode:color}");
30996    minify_test(".foo { mix-blend-mode: luminosity }", ".foo{mix-blend-mode:luminosity}");
30997    minify_test(
30998      ".foo { mix-blend-mode: plus-darker }",
30999      ".foo{mix-blend-mode:plus-darker}",
31000    );
31001    minify_test(
31002      ".foo { mix-blend-mode: plus-lighter }",
31003      ".foo{mix-blend-mode:plus-lighter}",
31004    );
31005  }
31006
31007  #[test]
31008  fn test_viewport() {
31009    minify_test(
31010      r#"
31011    @viewport {
31012      width: 100vw;
31013    }"#,
31014      "@viewport{width:100vw}",
31015    );
31016    minify_test(
31017      r#"
31018    @-ms-viewport {
31019      width: device-width;
31020    }"#,
31021      "@-ms-viewport{width:device-width}",
31022    );
31023  }
31024
31025  #[test]
31026  fn test_at_scope() {
31027    minify_test(
31028      r#"
31029      @scope {
31030        .foo {
31031          display: flex;
31032        }
31033      }
31034      "#,
31035      "@scope{.foo{display:flex}}",
31036    );
31037    minify_test(
31038      r#"
31039      @scope {
31040        :scope {
31041          display: flex;
31042          color: lightblue;
31043        }
31044      }"#,
31045      "@scope{:scope{color:#add8e6;display:flex}}",
31046    );
31047    minify_test(
31048      r#"
31049      @scope (.light-scheme) {
31050        a { color: yellow; }
31051      }
31052      "#,
31053      "@scope(.light-scheme){a{color:#ff0}}",
31054    );
31055    minify_test(
31056      r#"
31057      @scope (.media-object) to (.content > *) {
31058        a { color: yellow; }
31059      }
31060      "#,
31061      "@scope(.media-object) to (.content>*){a{color:#ff0}}",
31062    );
31063    minify_test(
31064      r#"
31065      @scope to (.content > *) {
31066        a { color: yellow; }
31067      }
31068      "#,
31069      "@scope to (.content>*){a{color:#ff0}}",
31070    );
31071    minify_test(
31072      r#"
31073      @scope (#my-component) {
31074        & { color: yellow; }
31075      }
31076      "#,
31077      "@scope(#my-component){&{color:#ff0}}",
31078    );
31079    minify_test(
31080      r#"
31081      @scope (.parent-scope) {
31082        @scope (:scope > .child-scope) to (:scope .limit) {
31083          .content { color: yellow; }
31084        }
31085      }
31086      "#,
31087      "@scope(.parent-scope){@scope(:scope>.child-scope) to (:scope .limit){.content{color:#ff0}}}",
31088    );
31089    minify_test(
31090      r#"
31091      .foo {
31092        @scope (.bar) {
31093          color: yellow;
31094        }
31095      }
31096      "#,
31097      ".foo{@scope(.bar){color:#ff0}}",
31098    );
31099    nesting_test(
31100      r#"
31101      .foo {
31102        @scope (.bar) {
31103          color: yellow;
31104        }
31105      }
31106      "#,
31107      indoc! {r#"
31108        @scope (.bar) {
31109          color: #ff0;
31110        }
31111      "#},
31112    );
31113    nesting_test(
31114      r#"
31115      .parent {
31116        color: blue;
31117
31118        @scope (& > .scope) to (& .limit) {
31119          & .content {
31120            color: yellow;
31121          }
31122        }
31123      }
31124      "#,
31125      indoc! {r#"
31126        .parent {
31127          color: #00f;
31128        }
31129
31130        @scope (.parent > .scope) to (.parent > .scope .limit) {
31131          :scope .content {
31132            color: #ff0;
31133          }
31134        }
31135      "#},
31136    );
31137  }
31138
31139  #[test]
31140  fn test_custom_media() {
31141    custom_media_test(
31142      r#"
31143      @custom-media --modern (color), (hover);
31144
31145      @media (--modern) and (width > 1024px) {
31146        .a {
31147          color: green;
31148        }
31149      }
31150      "#,
31151      indoc! {r#"
31152      @media ((color) or (hover)) and (width > 1024px) {
31153        .a {
31154          color: green;
31155        }
31156      }
31157      "#},
31158    );
31159
31160    custom_media_test(
31161      r#"
31162      @custom-media --color (color);
31163
31164      @media (--color) and (width > 1024px) {
31165        .a {
31166          color: green;
31167        }
31168      }
31169      "#,
31170      indoc! {r#"
31171      @media (color) and (width > 1024px) {
31172        .a {
31173          color: green;
31174        }
31175      }
31176      "#},
31177    );
31178
31179    custom_media_test(
31180      r#"
31181      @custom-media --a (color);
31182      @custom-media --b (--a);
31183
31184      @media (--b) and (width > 1024px) {
31185        .a {
31186          color: green;
31187        }
31188      }
31189      "#,
31190      indoc! {r#"
31191      @media (color) and (width > 1024px) {
31192        .a {
31193          color: green;
31194        }
31195      }
31196      "#},
31197    );
31198
31199    custom_media_test(
31200      r#"
31201      @custom-media --not-color not (color);
31202
31203      @media not (--not-color) {
31204        .a {
31205          color: green;
31206        }
31207      }
31208      "#,
31209      indoc! {r#"
31210      @media (color) {
31211        .a {
31212          color: green;
31213        }
31214      }
31215      "#},
31216    );
31217
31218    custom_media_test(
31219      r#"
31220      @custom-media --color-print print and (color);
31221
31222      @media (--color-print) {
31223        .a {
31224          color: green;
31225        }
31226      }
31227      "#,
31228      indoc! {r#"
31229      @media print and (color) {
31230        .a {
31231          color: green;
31232        }
31233      }
31234      "#},
31235    );
31236
31237    custom_media_test(
31238      r#"
31239      @custom-media --color-print print and (color);
31240
31241      @media print and (--color-print) {
31242        .a {
31243          color: green;
31244        }
31245      }
31246      "#,
31247      indoc! {r#"
31248      @media print and (color) {
31249        .a {
31250          color: green;
31251        }
31252      }
31253      "#},
31254    );
31255
31256    custom_media_test(
31257      r#"
31258      @custom-media --not-color-print not print and (color);
31259
31260      @media not print and (--not-color-print) {
31261        .a {
31262          color: green;
31263        }
31264      }
31265      "#,
31266      indoc! {r#"
31267      @media not print and (color) {
31268        .a {
31269          color: green;
31270        }
31271      }
31272      "#},
31273    );
31274
31275    custom_media_test(
31276      r#"
31277      @custom-media --print print;
31278
31279      @media (--print) {
31280        .a {
31281          color: green;
31282        }
31283      }
31284      "#,
31285      indoc! {r#"
31286      @media print {
31287        .a {
31288          color: green;
31289        }
31290      }
31291      "#},
31292    );
31293
31294    custom_media_test(
31295      r#"
31296      @custom-media --print print;
31297
31298      @media not (--print) {
31299        .a {
31300          color: green;
31301        }
31302      }
31303      "#,
31304      indoc! {r#"
31305      @media not print {
31306        .a {
31307          color: green;
31308        }
31309      }
31310      "#},
31311    );
31312
31313    custom_media_test(
31314      r#"
31315      @custom-media --print not print;
31316
31317      @media not (--print) {
31318        .a {
31319          color: green;
31320        }
31321      }
31322      "#,
31323      indoc! {r#"
31324      @media print {
31325        .a {
31326          color: green;
31327        }
31328      }
31329      "#},
31330    );
31331
31332    custom_media_test(
31333      r#"
31334      @custom-media --print print;
31335
31336      @media ((--print)) {
31337        .a {
31338          color: green;
31339        }
31340      }
31341      "#,
31342      indoc! {r#"
31343      @media print {
31344        .a {
31345          color: green;
31346        }
31347      }
31348      "#},
31349    );
31350
31351    custom_media_test(
31352      r#"
31353      @custom-media --color (color);
31354      @custom-media --print print;
31355
31356      @media (--print) and (--color) {
31357        .a {
31358          color: green;
31359        }
31360      }
31361      "#,
31362      indoc! {r#"
31363      @media print and (color) {
31364        .a {
31365          color: green;
31366        }
31367      }
31368      "#},
31369    );
31370
31371    custom_media_test(
31372      r#"
31373      @custom-media --color (color);
31374      @custom-media --not-print not print;
31375
31376      @media (--not-print) and (--color) {
31377        .a {
31378          color: green;
31379        }
31380      }
31381      "#,
31382      indoc! {r#"
31383      @media not print and (color) {
31384        .a {
31385          color: green;
31386        }
31387      }
31388      "#},
31389    );
31390
31391    custom_media_test(
31392      r#"
31393      @custom-media --color (color);
31394      @custom-media --screen screen;
31395      @custom-media --print print;
31396
31397      @media (--print) and (--color), (--screen) and (--color) {
31398        .a {
31399          color: green;
31400        }
31401      }
31402      "#,
31403      indoc! {r#"
31404      @media print and (color), screen and (color) {
31405        .a {
31406          color: green;
31407        }
31408      }
31409      "#},
31410    );
31411
31412    custom_media_test(
31413      r#"
31414      @custom-media --color print and (color), print and (script);
31415
31416      @media (--color) {
31417        .a {
31418          color: green;
31419        }
31420      }
31421      "#,
31422      indoc! {r#"
31423      @media print and ((color) or (script)) {
31424        .a {
31425          color: green;
31426        }
31427      }
31428      "#},
31429    );
31430
31431    custom_media_test(
31432      r#"
31433      @custom-media --color (color);
31434      @custom-media --not-color not all and (--color);
31435
31436      @media (--not-color) {
31437        .a {
31438          color: green;
31439        }
31440      }
31441      "#,
31442      indoc! {r#"
31443        @media not all and (color) {
31444          .a {
31445            color: green;
31446          }
31447        }
31448      "#},
31449    );
31450
31451    custom_media_test(
31452      r#"
31453      @custom-media --color (color);
31454
31455      @media not all and (--color) {
31456        .a {
31457          color: green;
31458        }
31459      }
31460      "#,
31461      indoc! {r#"
31462        @media not all and (color) {
31463          .a {
31464            color: green;
31465          }
31466        }
31467      "#},
31468    );
31469
31470    custom_media_test(
31471      r#"
31472      @media (--print) {
31473        .a {
31474          color: green;
31475        }
31476      }
31477
31478      @custom-media --print print;
31479      "#,
31480      indoc! {r#"
31481      @media print {
31482        .a {
31483          color: green;
31484        }
31485      }
31486      "#},
31487    );
31488
31489    custom_media_test(
31490      r#"
31491      @custom-media --not-width not (min-width: 300px);
31492      @media screen and ((prefers-color-scheme: dark) or (--not-width)) {
31493        .foo {
31494          order: 6;
31495        }
31496      }
31497      "#,
31498      indoc! {r#"
31499      @media screen and ((prefers-color-scheme: dark) or ((width < 300px))) {
31500        .foo {
31501          order: 6;
31502        }
31503      }
31504      "#},
31505    );
31506
31507    fn custom_media_error_test(source: &str, err: Error<MinifyErrorKind>) {
31508      let mut stylesheet = StyleSheet::parse(
31509        &source,
31510        ParserOptions {
31511          filename: "test.css".into(),
31512          flags: ParserFlags::CUSTOM_MEDIA,
31513          ..ParserOptions::default()
31514        },
31515      )
31516      .unwrap();
31517      let res = stylesheet.minify(MinifyOptions {
31518        targets: Browsers {
31519          chrome: Some(95 << 16),
31520          ..Browsers::default()
31521        }
31522        .into(),
31523        ..MinifyOptions::default()
31524      });
31525      assert_eq!(res, Err(err))
31526    }
31527
31528    custom_media_error_test(
31529      r#"
31530      @custom-media --color-print print and (color);
31531
31532      @media screen and (--color-print) {
31533        .a {
31534          color: green;
31535        }
31536      }
31537      "#,
31538      Error {
31539        kind: MinifyErrorKind::UnsupportedCustomMediaBooleanLogic {
31540          custom_media_loc: Location {
31541            source_index: 0,
31542            line: 1,
31543            column: 7,
31544          },
31545        },
31546        loc: Some(ErrorLocation {
31547          filename: "test.css".into(),
31548          line: 3,
31549          column: 7,
31550        }),
31551      },
31552    );
31553
31554    custom_media_error_test(
31555      r#"
31556      @custom-media --color-print print and (color);
31557
31558      @media not print and (--color-print) {
31559        .a {
31560          color: green;
31561        }
31562      }
31563      "#,
31564      Error {
31565        kind: MinifyErrorKind::UnsupportedCustomMediaBooleanLogic {
31566          custom_media_loc: Location {
31567            source_index: 0,
31568            line: 1,
31569            column: 7,
31570          },
31571        },
31572        loc: Some(ErrorLocation {
31573          filename: "test.css".into(),
31574          line: 3,
31575          column: 7,
31576        }),
31577      },
31578    );
31579
31580    custom_media_error_test(
31581      r#"
31582      @custom-media --color-print print and (color);
31583      @custom-media --color-screen screen and (color);
31584
31585      @media (--color-print) or (--color-screen) {}
31586      "#,
31587      Error {
31588        kind: MinifyErrorKind::UnsupportedCustomMediaBooleanLogic {
31589          custom_media_loc: Location {
31590            source_index: 0,
31591            line: 2,
31592            column: 7,
31593          },
31594        },
31595        loc: Some(ErrorLocation {
31596          filename: "test.css".into(),
31597          line: 4,
31598          column: 7,
31599        }),
31600      },
31601    );
31602
31603    custom_media_error_test(
31604      r#"
31605      @custom-media --color-print print and (color);
31606      @custom-media --color-screen screen and (color);
31607
31608      @media (--color-print) and (--color-screen) {}
31609      "#,
31610      Error {
31611        kind: MinifyErrorKind::UnsupportedCustomMediaBooleanLogic {
31612          custom_media_loc: Location {
31613            source_index: 0,
31614            line: 2,
31615            column: 7,
31616          },
31617        },
31618        loc: Some(ErrorLocation {
31619          filename: "test.css".into(),
31620          line: 4,
31621          column: 7,
31622        }),
31623      },
31624    );
31625
31626    custom_media_error_test(
31627      r#"
31628      @custom-media --screen screen;
31629      @custom-media --print print;
31630
31631      @media (--print) and (--screen) {}
31632      "#,
31633      Error {
31634        kind: MinifyErrorKind::UnsupportedCustomMediaBooleanLogic {
31635          custom_media_loc: Location {
31636            source_index: 0,
31637            line: 1,
31638            column: 7,
31639          },
31640        },
31641        loc: Some(ErrorLocation {
31642          filename: "test.css".into(),
31643          line: 4,
31644          column: 7,
31645        }),
31646      },
31647    );
31648
31649    custom_media_error_test(
31650      r#"
31651      @custom-media --not-print not print and (color);
31652      @custom-media --not-screen not screen and (color);
31653
31654      @media ((script) or ((--not-print) and (--not-screen))) {
31655        .a {
31656          color: green;
31657        }
31658      }
31659      "#,
31660      Error {
31661        kind: MinifyErrorKind::UnsupportedCustomMediaBooleanLogic {
31662          custom_media_loc: Location {
31663            source_index: 0,
31664            line: 2,
31665            column: 7,
31666          },
31667        },
31668        loc: Some(ErrorLocation {
31669          filename: "test.css".into(),
31670          line: 4,
31671          column: 7,
31672        }),
31673      },
31674    );
31675
31676    custom_media_error_test(
31677      r#"
31678      @custom-media --color screen and (color), print and (color);
31679
31680      @media (--color) {
31681        .a {
31682          color: green;
31683        }
31684      }
31685      "#,
31686      Error {
31687        kind: MinifyErrorKind::UnsupportedCustomMediaBooleanLogic {
31688          custom_media_loc: Location {
31689            source_index: 0,
31690            line: 1,
31691            column: 7,
31692          },
31693        },
31694        loc: Some(ErrorLocation {
31695          filename: "test.css".into(),
31696          line: 3,
31697          column: 7,
31698        }),
31699      },
31700    );
31701
31702    custom_media_error_test(
31703      r#"
31704      @media (--not-defined) {
31705        .a {
31706          color: green;
31707        }
31708      }
31709      "#,
31710      Error {
31711        kind: MinifyErrorKind::CustomMediaNotDefined {
31712          name: "--not-defined".into(),
31713        },
31714        loc: Some(ErrorLocation {
31715          filename: "test.css".into(),
31716          line: 1,
31717          column: 7,
31718        }),
31719      },
31720    );
31721
31722    custom_media_error_test(
31723      r#"
31724      @custom-media --circular-mq-a (--circular-mq-b);
31725      @custom-media --circular-mq-b (--circular-mq-a);
31726
31727      @media (--circular-mq-a) {
31728        body {
31729          order: 3;
31730        }
31731      }
31732      "#,
31733      Error {
31734        kind: MinifyErrorKind::CircularCustomMedia {
31735          name: "--circular-mq-a".into(),
31736        },
31737        loc: Some(ErrorLocation {
31738          filename: "test.css".into(),
31739          line: 4,
31740          column: 7,
31741        }),
31742      },
31743    );
31744  }
31745
31746  #[test]
31747  fn test_dependencies() {
31748    fn dep_test(source: &str, expected: &str, deps: Vec<(&str, &str)>) {
31749      let mut stylesheet = StyleSheet::parse(
31750        &source,
31751        ParserOptions {
31752          filename: "test.css".into(),
31753          ..ParserOptions::default()
31754        },
31755      )
31756      .unwrap();
31757      stylesheet.minify(MinifyOptions::default()).unwrap();
31758      let res = stylesheet
31759        .to_css(PrinterOptions {
31760          analyze_dependencies: Some(Default::default()),
31761          minify: true,
31762          ..PrinterOptions::default()
31763        })
31764        .unwrap();
31765      assert_eq!(res.code, expected);
31766      let dependencies = res.dependencies.unwrap();
31767      assert_eq!(dependencies.len(), deps.len());
31768      for (i, (url, placeholder)) in deps.into_iter().enumerate() {
31769        match &dependencies[i] {
31770          Dependency::Url(dep) => {
31771            assert_eq!(dep.url, url);
31772            assert_eq!(dep.placeholder, placeholder);
31773          }
31774          Dependency::Import(dep) => {
31775            assert_eq!(dep.url, url);
31776            assert_eq!(dep.placeholder, placeholder);
31777          }
31778        }
31779      }
31780    }
31781
31782    fn dep_error_test(source: &str, error: PrinterErrorKind) {
31783      let stylesheet = StyleSheet::parse(&source, ParserOptions::default()).unwrap();
31784      let res = stylesheet.to_css(PrinterOptions {
31785        analyze_dependencies: Some(Default::default()),
31786        ..PrinterOptions::default()
31787      });
31788      match res {
31789        Err(e) => assert_eq!(e.kind, error),
31790        _ => unreachable!(),
31791      }
31792    }
31793
31794    dep_test(
31795      ".foo { background: image-set('./img12x.png', './img21x.png' 2x)}",
31796      ".foo{background:image-set(\"hXFI8W\" 1x,\"5TkpBa\" 2x)}",
31797      vec![("./img12x.png", "hXFI8W"), ("./img21x.png", "5TkpBa")],
31798    );
31799
31800    dep_test(
31801      ".foo { background: image-set(url(./img12x.png), url('./img21x.png') 2x)}",
31802      ".foo{background:image-set(\"hXFI8W\" 1x,\"5TkpBa\" 2x)}",
31803      vec![("./img12x.png", "hXFI8W"), ("./img21x.png", "5TkpBa")],
31804    );
31805
31806    dep_test(
31807      ".foo { --test: url(/foo.png) }",
31808      ".foo{--test:url(\"lDnnrG\")}",
31809      vec![("/foo.png", "lDnnrG")],
31810    );
31811
31812    dep_test(
31813      ".foo { --test: url(\"/foo.png\") }",
31814      ".foo{--test:url(\"lDnnrG\")}",
31815      vec![("/foo.png", "lDnnrG")],
31816    );
31817
31818    dep_test(
31819      ".foo { --test: url(\"http://example.com/foo.png\") }",
31820      ".foo{--test:url(\"3X1zSW\")}",
31821      vec![("http://example.com/foo.png", "3X1zSW")],
31822    );
31823
31824    dep_test(
31825      ".foo { --test: url(\"data:image/svg+xml;utf8,<svg></svg>\") }",
31826      ".foo{--test:url(\"-vl-rG\")}",
31827      vec![("data:image/svg+xml;utf8,<svg></svg>", "-vl-rG")],
31828    );
31829
31830    dep_test(
31831      ".foo { background: url(\"foo.png\") var(--test) }",
31832      ".foo{background:url(\"Vwkwkq\") var(--test)}",
31833      vec![("foo.png", "Vwkwkq")],
31834    );
31835
31836    dep_error_test(
31837      ".foo { --test: url(\"foo.png\") }",
31838      PrinterErrorKind::AmbiguousUrlInCustomProperty { url: "foo.png".into() },
31839    );
31840
31841    dep_error_test(
31842      ".foo { --test: url(foo.png) }",
31843      PrinterErrorKind::AmbiguousUrlInCustomProperty { url: "foo.png".into() },
31844    );
31845
31846    dep_error_test(
31847      ".foo { --test: url(./foo.png) }",
31848      PrinterErrorKind::AmbiguousUrlInCustomProperty {
31849        url: "./foo.png".into(),
31850      },
31851    );
31852
31853    dep_test(
31854      ".foo { behavior: url(#foo) }",
31855      ".foo{behavior:url(\"Zn9-2q\")}",
31856      vec![("#foo", "Zn9-2q")],
31857    );
31858
31859    dep_test(
31860      ".foo { --foo: url(#foo) }",
31861      ".foo{--foo:url(\"Zn9-2q\")}",
31862      vec![("#foo", "Zn9-2q")],
31863    );
31864
31865    dep_test(
31866      "@import \"test.css\"; .foo { color: red }",
31867      "@import \"hHsogW\";.foo{color:red}",
31868      vec![("test.css", "hHsogW")],
31869    );
31870  }
31871
31872  #[test]
31873  fn test_api() {
31874    let stylesheet = StyleSheet::parse(".foo:hover { color: red }", ParserOptions::default()).unwrap();
31875    match &stylesheet.rules.0[0] {
31876      CssRule::Style(s) => {
31877        assert_eq!(&s.selectors.to_string(), ".foo:hover");
31878      }
31879      _ => unreachable!(),
31880    }
31881
31882    let color = CssColor::parse_string("#f0f").unwrap();
31883    assert_eq!(color.to_css_string(PrinterOptions::default()).unwrap(), "#f0f");
31884
31885    let rule = CssRule::parse_string(".foo { color: red }", ParserOptions::default()).unwrap();
31886    assert_eq!(
31887      rule.to_css_string(PrinterOptions::default()).unwrap(),
31888      indoc! {r#"
31889    .foo {
31890      color: red;
31891    }"#}
31892    );
31893
31894    let property = Property::parse_string("color".into(), "#f0f", ParserOptions::default()).unwrap();
31895    assert_eq!(
31896      property.to_css_string(false, PrinterOptions::default()).unwrap(),
31897      "color: #f0f"
31898    );
31899    assert_eq!(
31900      property.to_css_string(true, PrinterOptions::default()).unwrap(),
31901      "color: #f0f !important"
31902    );
31903
31904    let code = indoc! { r#"
31905      .foo {
31906        color: green;
31907      }
31908
31909      .bar {
31910        color: red;
31911        background: pink;
31912      }
31913
31914      @media print {
31915        .baz {
31916          color: green;
31917        }
31918      }
31919    "#};
31920    let stylesheet = StyleSheet::parse(code, ParserOptions::default()).unwrap();
31921    if let CssRule::Style(style) = &stylesheet.rules.0[1] {
31922      let (key, val) = style.property_location(code, 0).unwrap();
31923      assert_eq!(
31924        key,
31925        SourceLocation { line: 5, column: 3 }..SourceLocation { line: 5, column: 8 }
31926      );
31927      assert_eq!(
31928        val,
31929        SourceLocation { line: 5, column: 10 }..SourceLocation { line: 5, column: 13 }
31930      );
31931    }
31932
31933    if let CssRule::Style(style) = &stylesheet.rules.0[1] {
31934      let (key, val) = style.property_location(code, 1).unwrap();
31935      assert_eq!(
31936        key,
31937        SourceLocation { line: 6, column: 3 }..SourceLocation { line: 6, column: 13 }
31938      );
31939      assert_eq!(
31940        val,
31941        SourceLocation { line: 6, column: 15 }..SourceLocation { line: 6, column: 19 }
31942      );
31943    }
31944    if let CssRule::Media(media) = &stylesheet.rules.0[2] {
31945      if let CssRule::Style(style) = &media.rules.0[0] {
31946        let (key, val) = style.property_location(code, 0).unwrap();
31947        assert_eq!(
31948          key,
31949          SourceLocation { line: 11, column: 5 }..SourceLocation { line: 11, column: 10 }
31950        );
31951        assert_eq!(
31952          val,
31953          SourceLocation { line: 11, column: 12 }..SourceLocation { line: 11, column: 17 }
31954        );
31955      }
31956    }
31957
31958    let mut property = Property::Transform(Default::default(), VendorPrefix::WebKit);
31959    property.set_prefix(VendorPrefix::None);
31960    assert_eq!(property, Property::Transform(Default::default(), VendorPrefix::None));
31961    property.set_prefix(VendorPrefix::Moz);
31962    assert_eq!(property, Property::Transform(Default::default(), VendorPrefix::Moz));
31963    property.set_prefix(VendorPrefix::WebKit | VendorPrefix::Moz);
31964    assert_eq!(
31965      property,
31966      Property::Transform(Default::default(), VendorPrefix::WebKit | VendorPrefix::Moz)
31967    );
31968
31969    let mut property = Property::TextDecorationLine(Default::default(), VendorPrefix::None);
31970    property.set_prefix(VendorPrefix::Ms);
31971    assert_eq!(
31972      property,
31973      Property::TextDecorationLine(Default::default(), VendorPrefix::None)
31974    );
31975    property.set_prefix(VendorPrefix::WebKit | VendorPrefix::Moz | VendorPrefix::Ms);
31976    assert_eq!(
31977      property,
31978      Property::TextDecorationLine(Default::default(), VendorPrefix::WebKit | VendorPrefix::Moz)
31979    );
31980
31981    let mut property = Property::AccentColor(Default::default());
31982    property.set_prefix(VendorPrefix::WebKit);
31983    assert_eq!(property, Property::AccentColor(Default::default()));
31984  }
31985
31986  #[cfg(feature = "substitute_variables")]
31987  #[test]
31988  fn test_substitute_vars() {
31989    use crate::properties::custom::TokenList;
31990    use crate::traits::ParseWithOptions;
31991
31992    fn test(property: Property, vars: HashMap<&str, &str>, expected: &str) {
31993      if let Property::Unparsed(unparsed) = property {
31994        let vars = vars
31995          .into_iter()
31996          .map(|(k, v)| {
31997            (
31998              k,
31999              TokenList::parse_string_with_options(v, ParserOptions::default()).unwrap(),
32000            )
32001          })
32002          .collect();
32003        let substituted = unparsed.substitute_variables(&vars).unwrap();
32004        assert_eq!(
32005          substituted.to_css_string(false, PrinterOptions::default()).unwrap(),
32006          expected
32007        );
32008      } else {
32009        panic!("Not an unparsed property");
32010      }
32011    }
32012
32013    let property = Property::parse_string("color".into(), "var(--test)", ParserOptions::default()).unwrap();
32014    test(property, HashMap::from([("--test", "yellow")]), "color: #ff0");
32015
32016    let property =
32017      Property::parse_string("color".into(), "var(--test, var(--foo))", ParserOptions::default()).unwrap();
32018    test(property, HashMap::from([("--foo", "yellow")]), "color: #ff0");
32019    let property = Property::parse_string(
32020      "color".into(),
32021      "var(--test, var(--foo, yellow))",
32022      ParserOptions::default(),
32023    )
32024    .unwrap();
32025    test(property, HashMap::new(), "color: #ff0");
32026
32027    let property =
32028      Property::parse_string("width".into(), "calc(var(--a) + var(--b))", ParserOptions::default()).unwrap();
32029    test(property, HashMap::from([("--a", "2px"), ("--b", "4px")]), "width: 6px");
32030
32031    let property = Property::parse_string("color".into(), "var(--a)", ParserOptions::default()).unwrap();
32032    test(
32033      property,
32034      HashMap::from([("--a", "var(--b)"), ("--b", "yellow")]),
32035      "color: #ff0",
32036    );
32037
32038    let property = Property::parse_string("color".into(), "var(--a)", ParserOptions::default()).unwrap();
32039    test(
32040      property,
32041      HashMap::from([("--a", "var(--b)"), ("--b", "var(--c)"), ("--c", "var(--a)")]),
32042      "color: var(--a)",
32043    );
32044  }
32045
32046  #[test]
32047  fn test_layer() {
32048    minify_test("@layer foo;", "@layer foo;");
32049    minify_test("@layer foo, bar;", "@layer foo,bar;");
32050    minify_test("@layer foo.bar;", "@layer foo.bar;");
32051    minify_test("@layer foo.bar, baz;", "@layer foo.bar,baz;");
32052
32053    minify_test(
32054      r#"
32055      @layer foo {
32056        .bar {
32057          color: red;
32058        }
32059      }
32060    "#,
32061      "@layer foo{.bar{color:red}}",
32062    );
32063    minify_test(
32064      r#"
32065      @layer foo.bar {
32066        .bar {
32067          color: red;
32068        }
32069      }
32070    "#,
32071      "@layer foo.bar{.bar{color:red}}",
32072    );
32073    minify_test(r#"
32074      @layer base {
32075        p { max-width: 70ch; }
32076      }
32077
32078      @layer framework {
32079        @layer base {
32080          p { margin-block: 0.75em; }
32081        }
32082
32083        @layer theme {
32084          p { color: #222; }
32085        }
32086      }
32087    "#, "@layer base{p{max-width:70ch}}@layer framework{@layer base{p{margin-block:.75em}}@layer theme{p{color:#222}}}");
32088    minify_test(
32089      r#"
32090      @layer {
32091        .bar {
32092          color: red;
32093        }
32094      }
32095    "#,
32096      "@layer{.bar{color:red}}",
32097    );
32098    minify_test(
32099      r#"
32100      @layer foo\20 bar, baz;
32101    "#,
32102      "@layer foo\\ bar,baz;",
32103    );
32104    minify_test(
32105      r#"
32106      @layer one.two\20 three\#four\.five {
32107        .bar {
32108          color: red;
32109        }
32110      }
32111    "#,
32112      "@layer one.two\\ three\\#four\\.five{.bar{color:red}}",
32113    );
32114
32115    error_test("@layer;", ParserError::UnexpectedToken(Token::Semicolon));
32116    error_test("@layer foo, bar {};", ParserError::AtRuleBodyInvalid);
32117    minify_test("@import 'test.css' layer;", "@import \"test.css\" layer;");
32118    minify_test("@import 'test.css' layer(foo);", "@import \"test.css\" layer(foo);");
32119    minify_test(
32120      "@import 'test.css' layer(foo.bar);",
32121      "@import \"test.css\" layer(foo.bar);",
32122    );
32123    minify_test(
32124      "@import 'test.css' layer(foo\\20 bar);",
32125      "@import \"test.css\" layer(foo\\ bar);",
32126    );
32127    error_test(
32128      "@import 'test.css' layer(foo, bar) {};",
32129      ParserError::UnexpectedToken(Token::Comma),
32130    );
32131    minify_test(
32132      r#"
32133      @layer one {
32134        body {
32135          background: red;
32136        }
32137      }
32138
32139      body {
32140        background: red;
32141      }
32142
32143      @layer two {
32144        body {
32145          background: green;
32146        }
32147      }
32148
32149      @layer one {
32150        body {
32151          background: yellow;
32152        }
32153      }
32154      "#,
32155      "@layer one{body{background:#ff0}}body{background:red}@layer two{body{background:green}}",
32156    );
32157  }
32158
32159  #[test]
32160  fn test_property() {
32161    minify_test(
32162      r#"
32163      @property --property-name {
32164        syntax: '<color>';
32165        inherits: false;
32166        initial-value: yellow;
32167      }
32168    "#,
32169      "@property --property-name{syntax:\"<color>\";inherits:false;initial-value:#ff0}",
32170    );
32171
32172    test(
32173      r#"
32174      @property --property-name {
32175        syntax: '*';
32176        inherits: false;
32177        initial-value: ;
32178      }
32179    "#,
32180      indoc! {r#"
32181      @property --property-name {
32182        syntax: "*";
32183        inherits: false;
32184        initial-value: ;
32185      }
32186    "#},
32187    );
32188
32189    minify_test(
32190      r#"
32191      @property --property-name {
32192        syntax: '*';
32193        inherits: false;
32194        initial-value: ;
32195      }
32196    "#,
32197      "@property --property-name{syntax:\"*\";inherits:false;initial-value:}",
32198    );
32199
32200    test(
32201      r#"
32202      @property --property-name {
32203        syntax: '*';
32204        inherits: false;
32205        initial-value:;
32206      }
32207    "#,
32208      indoc! {r#"
32209      @property --property-name {
32210        syntax: "*";
32211        inherits: false;
32212        initial-value: ;
32213      }
32214    "#},
32215    );
32216
32217    minify_test(
32218      r#"
32219      @property --property-name {
32220        syntax: '*';
32221        inherits: false;
32222        initial-value:;
32223      }
32224    "#,
32225      "@property --property-name{syntax:\"*\";inherits:false;initial-value:}",
32226    );
32227    minify_test(
32228      r#"
32229      @property --property-name {
32230        syntax: '*';
32231        inherits: false;
32232        initial-value: foo bar;
32233      }
32234    "#,
32235      "@property --property-name{syntax:\"*\";inherits:false;initial-value:foo bar}",
32236    );
32237
32238    minify_test(
32239      r#"
32240      @property --property-name {
32241        syntax: '<length>';
32242        inherits: true;
32243        initial-value: 25px;
32244      }
32245    "#,
32246      "@property --property-name{syntax:\"<length>\";inherits:true;initial-value:25px}",
32247    );
32248
32249    minify_test(
32250      r#"
32251      @property --property-name {
32252        syntax: '<string>';
32253        inherits: true;
32254        initial-value: "hi";
32255      }
32256    "#,
32257      "@property --property-name{syntax:\"<string>\";inherits:true;initial-value:\"hi\"}",
32258    );
32259
32260    error_test(
32261      r#"
32262      @property --property-name {
32263        syntax: '<color>';
32264        inherits: false;
32265        initial-value: 25px;
32266      }
32267    "#,
32268      ParserError::UnexpectedToken(crate::properties::custom::Token::Dimension {
32269        has_sign: false,
32270        value: 25.0,
32271        int_value: Some(25),
32272        unit: "px".into(),
32273      }),
32274    );
32275
32276    error_test(
32277      r#"
32278      @property --property-name {
32279        syntax: '<length>';
32280        inherits: false;
32281        initial-value: var(--some-value);
32282      }
32283    "#,
32284      ParserError::UnexpectedToken(crate::properties::custom::Token::Function("var".into())),
32285    );
32286
32287    error_test(
32288      r#"
32289      @property --property-name {
32290        syntax: '<color>';
32291        inherits: false;
32292      }
32293    "#,
32294      ParserError::AtRuleBodyInvalid,
32295    );
32296
32297    minify_test(
32298      r#"
32299      @property --property-name {
32300        syntax: '*';
32301        inherits: false;
32302      }
32303    "#,
32304      "@property --property-name{syntax:\"*\";inherits:false}",
32305    );
32306
32307    error_test(
32308      r#"
32309      @property --property-name {
32310        syntax: '*';
32311      }
32312    "#,
32313      ParserError::AtRuleBodyInvalid,
32314    );
32315
32316    error_test(
32317      r#"
32318      @property --property-name {
32319        inherits: false;
32320      }
32321    "#,
32322      ParserError::AtRuleBodyInvalid,
32323    );
32324
32325    error_test(
32326      r#"
32327      @property property-name {
32328        syntax: '*';
32329        inherits: false;
32330      }
32331    "#,
32332      ParserError::UnexpectedToken(crate::properties::custom::Token::Ident("property-name".into())),
32333    );
32334
32335    minify_test(
32336      r#"
32337      @property --property-name {
32338        syntax: 'custom | <color>';
32339        inherits: false;
32340        initial-value: yellow;
32341      }
32342    "#,
32343      "@property --property-name{syntax:\"custom|<color>\";inherits:false;initial-value:#ff0}",
32344    );
32345
32346    // TODO: Re-enable with a better solution
32347    //       See: https://github.com/parcel-bundler/lightningcss/issues/288
32348    // minify_test(r#"
32349    //   @property --property-name {
32350    //     syntax: '<transform-list>';
32351    //     inherits: false;
32352    //     initial-value: translate(200px,300px) translate(100px,200px) scale(2);
32353    //   }
32354    // "#, "@property --property-name{syntax:\"<transform-list>\";inherits:false;initial-value:matrix(2,0,0,2,300,500)}");
32355
32356    minify_test(
32357      r#"
32358      @property --property-name {
32359        syntax: '<time>';
32360        inherits: false;
32361        initial-value: 1000ms;
32362      }
32363    "#,
32364      "@property --property-name{syntax:\"<time>\";inherits:false;initial-value:1s}",
32365    );
32366
32367    minify_test(
32368      r#"
32369      @property --property-name {
32370        syntax: '<url>';
32371        inherits: false;
32372        initial-value: url("foo.png");
32373      }
32374    "#,
32375      "@property --property-name{syntax:\"<url>\";inherits:false;initial-value:url(foo.png)}",
32376    );
32377
32378    minify_test(
32379      r#"
32380      @property --property-name {
32381        syntax: '<image>';
32382        inherits: false;
32383        initial-value: linear-gradient(yellow, blue);
32384      }
32385    "#,
32386      "@property --property-name{syntax:\"<image>\";inherits:false;initial-value:linear-gradient(#ff0,#00f)}",
32387    );
32388
32389    minify_test(
32390      r#"
32391      @property --property-name {
32392        initial-value: linear-gradient(yellow, blue);
32393        inherits: false;
32394        syntax: '<image>';
32395      }
32396    "#,
32397      "@property --property-name{syntax:\"<image>\";inherits:false;initial-value:linear-gradient(#ff0,#00f)}",
32398    );
32399
32400    test(
32401      r#"
32402      @property --property-name {
32403        syntax: '<length>|none';
32404        inherits: false;
32405        initial-value: none;
32406      }
32407    "#,
32408      indoc! {r#"
32409      @property --property-name {
32410        syntax: "<length> | none";
32411        inherits: false;
32412        initial-value: none;
32413      }
32414    "#},
32415    );
32416
32417    minify_test(
32418      r#"
32419      @property --property-name {
32420        syntax: '<color>#';
32421        inherits: false;
32422        initial-value: yellow, blue;
32423      }
32424    "#,
32425      "@property --property-name{syntax:\"<color>#\";inherits:false;initial-value:#ff0,#00f}",
32426    );
32427    minify_test(
32428      r#"
32429      @property --property-name {
32430        syntax: '<color>+';
32431        inherits: false;
32432        initial-value: yellow blue;
32433      }
32434    "#,
32435      "@property --property-name{syntax:\"<color>+\";inherits:false;initial-value:#ff0 #00f}",
32436    );
32437    minify_test(
32438      r#"
32439      @property --property-name {
32440        syntax: '<color>';
32441        inherits: false;
32442        initial-value: yellow;
32443      }
32444      .foo {
32445        color: var(--property-name)
32446      }
32447      @property --property-name {
32448        syntax: '<color>';
32449        inherits: true;
32450        initial-value: blue;
32451      }
32452    "#,
32453      "@property --property-name{syntax:\"<color>\";inherits:true;initial-value:#00f}.foo{color:var(--property-name)}",
32454    );
32455
32456    test(
32457      r#"
32458      @media (width < 800px) {
32459        @property --property-name {
32460          syntax: '*';
32461          inherits: false;
32462        }
32463      }
32464    "#,
32465      indoc! {r#"
32466        @media (width < 800px) {
32467          @property --property-name {
32468            syntax: "*";
32469            inherits: false
32470          }
32471        }
32472    "#},
32473    );
32474
32475    test(
32476      r#"
32477      @layer foo {
32478        @property --property-name {
32479          syntax: '*';
32480          inherits: false;
32481        }
32482      }
32483    "#,
32484      indoc! {r#"
32485        @layer foo {
32486          @property --property-name {
32487            syntax: "*";
32488            inherits: false
32489          }
32490        }
32491    "#},
32492    );
32493  }
32494
32495  #[test]
32496  fn test_quoting_unquoting_urls() {
32497    // Single quotes avoid escaping the double quotes in SVG attributes.
32498    minify_test(
32499      r#"
32500      .foo {
32501        background-image: url('data:image/svg+xml,<svg width="1" height="1"></svg>');
32502      }
32503      "#,
32504      r#".foo{background-image:url('data:image/svg+xml,<svg width="1" height="1"></svg>')}"#,
32505    );
32506
32507    // Keep double quotes when they are shorter or tied with single quotes.
32508    minify_test(
32509      r#"
32510      .foo {
32511        background-image: url("a 'b' c"), url('a "b" \'c\''), url('a "b" \'c');
32512      }
32513      "#,
32514      r#".foo{background-image:url("a 'b' c"),url("a \"b\" 'c'"),url('a "b" \'c')}"#,
32515    );
32516
32517    // Unquoted output still wins ties, including an empty URL.
32518    minify_test(
32519      r#"
32520      .foo {
32521        background-image: url('"'), url('""'), url('"""'), url('');
32522      }
32523      "#,
32524      r#".foo{background-image:url(\"),url(\"\"),url('"""'),url()}"#,
32525    );
32526
32527    // Escaped quotes and backslashes are parsed before choosing the quote style.
32528    minify_test(
32529      r#"
32530      .foo {
32531        background-image: url("a \\\"b\\\" \\c"), url('a "b" \\\'c');
32532      }
32533      "#,
32534      r#".foo{background-image:url('a \\"b\\" \\c'),url('a "b" \\\'c')}"#,
32535    );
32536
32537    // Preserve control characters and hex escape terminators before hex digits and spaces.
32538    minify_test(
32539      r#"
32540      .foo {
32541        background-image: url('"a"\a f\d  \c a\1 b\7f c\9 "é😀"');
32542      }
32543      "#,
32544      r#".foo{background-image:url('"a"\a f\d  \c a\1 b\7f c\9 "é😀"')}"#,
32545    );
32546
32547    minify_test(
32548      r#"
32549      .foo {
32550        background-image: url('"a" \
32551b\0 c');
32552      }
32553      "#,
32554      r#".foo{background-image:url('"a" b�c')}"#,
32555    );
32556
32557    // Keep the existing double-quoted output when not minifying.
32558    test(
32559      r#"
32560      .foo {
32561        background-image: url('a "b" c');
32562      }
32563      "#,
32564      ".foo {\n  background-image: url(\"a \\\"b\\\" c\");\n}\n",
32565    );
32566
32567    // Quotes remain double quotes when not minifying
32568    test(
32569      r#".foo {
32570      background-image: url("0123abcd");
32571    }"#,
32572      r#".foo {
32573  background-image: url("0123abcd");
32574}
32575"#,
32576    );
32577
32578    // Quotes removed when minifying
32579    minify_test(
32580      r#".foo {
32581      background-image: url("0123abcd");
32582    }"#,
32583      r#".foo{background-image:url(0123abcd)}"#,
32584    );
32585
32586    // Doubles quotes added if not present when not minifying
32587    test(
32588      r#".foo {
32589      background-image: url(0123abcd);
32590    }"#,
32591      r#".foo {
32592  background-image: url("0123abcd");
32593}
32594"#,
32595    );
32596
32597    // No quotes changed if not present when not minifying
32598    minify_test(
32599      r#".foo {
32600      background-image: url(0123abcd);
32601    }"#,
32602      r#".foo{background-image:url(0123abcd)}"#,
32603    );
32604  }
32605
32606  #[test]
32607  fn test_url_quote_roundtrip() {
32608    use crate::values::url::Url;
32609
32610    // Exercise escape boundaries on both sides of quotes, including a literal
32611    // backslash followed by a hex digit and non-ASCII text.
32612    let parts = [
32613      "\"", "'", "\\", "\n", "\r", "\x0c", "\x01", "\x7f", "\t", " ", "f", "é😀", "(", ")",
32614    ];
32615    for a in parts {
32616      for b in parts {
32617        for c in parts {
32618          let value = format!("\"\"{a}{b}{c}\"\"");
32619          let url = Url {
32620            url: value.as_str().into(),
32621            loc: crate::dependencies::Location { line: 1, column: 1 },
32622          };
32623          let serialized = url
32624            .to_css_string(PrinterOptions {
32625              minify: true,
32626              ..Default::default()
32627            })
32628            .unwrap();
32629          assert_eq!(Url::parse_string(&serialized).unwrap(), url);
32630        }
32631      }
32632    }
32633  }
32634
32635  #[test]
32636  fn test_url_quoting_dependencies() {
32637    let stylesheet = StyleSheet::parse(
32638      r#"
32639      .foo {
32640        background-image: url('a "b" c');
32641      }
32642      "#,
32643      ParserOptions::default(),
32644    )
32645    .unwrap();
32646    let result = stylesheet
32647      .to_css(PrinterOptions {
32648        minify: true,
32649        analyze_dependencies: Some(Default::default()),
32650        ..Default::default()
32651      })
32652      .unwrap();
32653    let dependencies = result.dependencies.unwrap();
32654    assert_eq!(dependencies.len(), 1);
32655    let Dependency::Url(dep) = &dependencies[0] else {
32656      panic!("expected URL dependency")
32657    };
32658    assert_eq!(dep.url, r#"a "b" c"#);
32659    assert_eq!(
32660      result.code,
32661      format!(".foo{{background-image:url(\"{}\")}}", dep.placeholder)
32662    );
32663  }
32664
32665  #[test]
32666  #[cfg(feature = "sourcemap")]
32667  fn test_url_quoting_source_map() {
32668    let stylesheet = StyleSheet::parse(
32669      r#"
32670      .foo {
32671        background-image: url('"a" \a b');
32672      }
32673      .bar {
32674        color: red;
32675      }
32676      "#,
32677      ParserOptions::default(),
32678    )
32679    .unwrap();
32680    let mut sm = parcel_sourcemap::SourceMap::new("/");
32681    let result = stylesheet
32682      .to_css(PrinterOptions {
32683        minify: true,
32684        ..PrinterOptions::default().with_source_map(&mut sm)
32685      })
32686      .unwrap();
32687    let column = result.code.find(".bar").unwrap() as u32;
32688    let mapping = sm.find_closest_mapping(0, column).unwrap();
32689    assert_eq!(mapping.generated_column, column);
32690    assert_eq!(mapping.original.unwrap().original_line, 4);
32691  }
32692
32693  #[test]
32694  fn test_zindex() {
32695    minify_test(".foo { z-index: 2 }", ".foo{z-index:2}");
32696    minify_test(".foo { z-index: -2 }", ".foo{z-index:-2}");
32697    minify_test(".foo { z-index: 999999 }", ".foo{z-index:999999}");
32698    minify_test(".foo { z-index: 9999999 }", ".foo{z-index:9999999}");
32699    minify_test(".foo { z-index: -9999999 }", ".foo{z-index:-9999999}");
32700  }
32701
32702  #[cfg(feature = "custom_sourcemap")]
32703  #[derive(Default)]
32704  struct TestSourceMap {
32705    sources: Vec<String>,
32706    names: Vec<String>,
32707    sources_content: Vec<(u32, String)>,
32708    mappings: Vec<(u32, u32, Option<OriginalLocation>)>,
32709  }
32710
32711  #[cfg(feature = "custom_sourcemap")]
32712  impl SourceMap for TestSourceMap {
32713    fn add_source(&mut self, source: &str) -> u32 {
32714      if let Some(index) = self.sources.iter().position(|s| s == source) {
32715        index as u32
32716      } else {
32717        self.sources.push(source.to_owned());
32718        (self.sources.len() - 1) as u32
32719      }
32720    }
32721
32722    fn add_name(&mut self, name: &str) -> u32 {
32723      if let Some(index) = self.names.iter().position(|s| s == name) {
32724        index as u32
32725      } else {
32726        self.names.push(name.to_owned());
32727        (self.names.len() - 1) as u32
32728      }
32729    }
32730
32731    fn set_source_content(&mut self, source_index: u32, source_content: &str) {
32732      self.sources_content.push((source_index, source_content.to_owned()));
32733    }
32734
32735    fn add_mapping(&mut self, generated_line: u32, generated_column: u32, original: Option<OriginalLocation>) {
32736      self.mappings.push((generated_line, generated_column, original));
32737    }
32738
32739    fn from_data_url(_source_root: &str, _data_url: &str) -> Option<Self> {
32740      None
32741    }
32742
32743    fn find_closest_mapping(&mut self, line: u32, column: u32) -> Option<OriginalLocation> {
32744      self
32745        .mappings
32746        .iter()
32747        .rev()
32748        .find(|(generated_line, generated_column, _)| (*generated_line, *generated_column) <= (line, column))
32749        .and_then(|(_, _, original)| *original)
32750    }
32751
32752    fn get_source(&self, source_index: u32) -> Option<&str> {
32753      self.sources.get(source_index as usize).map(String::as_str)
32754    }
32755
32756    fn get_name(&self, name_index: u32) -> Option<&str> {
32757      self.names.get(name_index as usize).map(String::as_str)
32758    }
32759
32760    fn get_source_content(&self, source_index: u32) -> Option<&str> {
32761      self
32762        .sources_content
32763        .iter()
32764        .find(|(index, _)| *index == source_index)
32765        .map(|(_, content)| content.as_str())
32766    }
32767  }
32768
32769  #[test]
32770  #[cfg(feature = "custom_sourcemap")]
32771  fn test_custom_source_map_remapped_content() {
32772    use crate::printer::Printer;
32773
32774    for content in [None, Some(""), Some(".original { color: red }")] {
32775      let original = OriginalLocation {
32776        original_line: 10,
32777        original_column: 5,
32778        source: 0,
32779        name: Some(0),
32780      };
32781      let input_map = || TestSourceMap {
32782        sources: vec!["original.scss".into()],
32783        names: vec!["original".into()],
32784        sources_content: content.map(|content| vec![(0, content.into())]).unwrap_or_default(),
32785        mappings: vec![(0, 0, Some(original))],
32786      };
32787      let mut output = TestSourceMap::default();
32788      // Ensure the cache uses output indices, which may differ from input indices.
32789      output.add_source("existing.css");
32790      let mut css = String::new();
32791      let mut printer = Printer::new(&mut css, PrinterOptions::default().with_source_map(&mut output));
32792      printer.source_maps = vec![Some(input_map()), Some(input_map())];
32793      for source_index in [0, 1] {
32794        for line in 0..100 {
32795          printer.add_mapping(Location {
32796            source_index,
32797            line,
32798            column: 1,
32799          });
32800        }
32801      }
32802      drop(printer);
32803
32804      assert_eq!(output.sources, vec!["existing.css", "original.scss"]);
32805      assert_eq!(output.names, vec!["original"]);
32806      assert_eq!(
32807        output.sources_content,
32808        content.map(|content| vec![(1, content.into())]).unwrap_or_default()
32809      );
32810      assert_eq!(output.mappings.len(), 200);
32811      assert!(output
32812        .mappings
32813        .iter()
32814        .all(|(_, _, location)| *location == Some(OriginalLocation { source: 1, ..original })));
32815    }
32816  }
32817
32818  #[test]
32819  #[cfg(feature = "custom_sourcemap")]
32820  fn test_custom_source_map() {
32821    let mut stylesheet = StyleSheet::parse(".foo { color: red }", ParserOptions::default()).unwrap();
32822    stylesheet.minify(MinifyOptions::default()).unwrap();
32823
32824    let mut source_map = TestSourceMap::default();
32825    let result = stylesheet
32826      .to_css(
32827        PrinterOptions {
32828          minify: true,
32829          ..PrinterOptions::default()
32830        }
32831        .with_source_map(&mut source_map),
32832      )
32833      .unwrap();
32834
32835    assert_eq!(result.code, ".foo{color:red}");
32836    assert_eq!(
32837      source_map.mappings.first(),
32838      Some(&(
32839        0,
32840        0,
32841        Some(OriginalLocation {
32842          original_line: 0,
32843          original_column: 0,
32844          source: 0,
32845          name: None,
32846        })
32847      ))
32848    );
32849  }
32850
32851  #[test]
32852  #[cfg(feature = "sourcemap")]
32853  fn test_input_source_map() {
32854    let source = r#".imported {
32855      content: "yay, file support!";
32856    }
32857
32858    .selector {
32859      margin: 1em;
32860      background-color: #f60;
32861    }
32862
32863    .selector .nested {
32864      margin: 0.5em;
32865    }
32866
32867    /*# sourceMappingURL=data:application/json;base64,ewoJInZlcnNpb24iOiAzLAoJInNvdXJjZVJvb3QiOiAicm9vdCIsCgkiZmlsZSI6ICJzdGRvdXQiLAoJInNvdXJjZXMiOiBbCgkJInN0ZGluIiwKCQkic2Fzcy9fdmFyaWFibGVzLnNjc3MiLAoJCSJzYXNzL19kZW1vLnNjc3MiCgldLAoJInNvdXJjZXNDb250ZW50IjogWwoJCSJAaW1wb3J0IFwiX3ZhcmlhYmxlc1wiO1xuQGltcG9ydCBcIl9kZW1vXCI7XG5cbi5zZWxlY3RvciB7XG4gIG1hcmdpbjogJHNpemU7XG4gIGJhY2tncm91bmQtY29sb3I6ICRicmFuZENvbG9yO1xuXG4gIC5uZXN0ZWQge1xuICAgIG1hcmdpbjogJHNpemUgLyAyO1xuICB9XG59IiwKCQkiJGJyYW5kQ29sb3I6ICNmNjA7XG4kc2l6ZTogMWVtOyIsCgkJIi5pbXBvcnRlZCB7XG4gIGNvbnRlbnQ6IFwieWF5LCBmaWxlIHN1cHBvcnQhXCI7XG59IgoJXSwKCSJtYXBwaW5ncyI6ICJBRUFBLFNBQVMsQ0FBQztFQUNSLE9BQU8sRUFBRSxvQkFBcUI7Q0FDL0I7O0FGQ0QsU0FBUyxDQUFDO0VBQ1IsTUFBTSxFQ0hELEdBQUc7RURJUixnQkFBZ0IsRUNMTCxJQUFJO0NEVWhCOztBQVBELFNBQVMsQ0FJUCxPQUFPLENBQUM7RUFDTixNQUFNLEVDUEgsS0FBRztDRFFQIiwKCSJuYW1lcyI6IFtdCn0= */"#;
32868
32869    let mut stylesheet = StyleSheet::parse(&source, ParserOptions::default()).unwrap();
32870    stylesheet.minify(MinifyOptions::default()).unwrap();
32871    let mut sm = parcel_sourcemap::SourceMap::new("/");
32872    stylesheet
32873      .to_css(PrinterOptions {
32874        minify: true,
32875        ..PrinterOptions::default().with_source_map(&mut sm)
32876      })
32877      .unwrap();
32878    let map = sm.to_json(None).unwrap();
32879    assert_eq!(
32880      map,
32881      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":[]}"#
32882    );
32883  }
32884
32885  #[test]
32886  #[cfg(feature = "sourcemap")]
32887  fn test_source_maps_with_license_comments() {
32888    let source = r#"/*! a single line comment */
32889    /*!
32890      a comment
32891      containing
32892      multiple
32893      lines
32894    */
32895    .a {
32896      display: flex;
32897    }
32898
32899    .b {
32900      display: hidden;
32901    }
32902    "#;
32903
32904    let mut sm = parcel_sourcemap::SourceMap::new("/");
32905    let source_index = sm.add_source("input.css");
32906    sm.set_source_content(source_index as usize, source).unwrap();
32907
32908    let mut stylesheet = StyleSheet::parse(
32909      &source,
32910      ParserOptions {
32911        source_index,
32912        ..Default::default()
32913      },
32914    )
32915    .unwrap();
32916    stylesheet.minify(MinifyOptions::default()).unwrap();
32917    stylesheet
32918      .to_css(PrinterOptions {
32919        minify: true,
32920        ..PrinterOptions::default().with_source_map(&mut sm)
32921      })
32922      .unwrap();
32923    let map = sm.to_json(None).unwrap();
32924    assert_eq!(
32925      map,
32926      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":[]}"#
32927    );
32928  }
32929
32930  #[test]
32931  fn test_error_recovery() {
32932    use std::sync::{Arc, RwLock};
32933    let warnings = Some(Arc::new(RwLock::new(Vec::new())));
32934    test_with_options(
32935      r#"
32936      h1(>h1) {
32937        color: red;
32938      }
32939
32940      .foo {
32941        color: red;
32942      }
32943
32944      .clearfix {
32945        *zoom: 1;
32946        background: red;
32947      }
32948
32949      @media (hover) {
32950        h1(>h1) {
32951          color: red;
32952        }
32953
32954        .bar {
32955          color: red;
32956        }
32957      }
32958
32959      input:placeholder {
32960        color: red;
32961      }
32962
32963      input::hover {
32964        color: red;
32965      }
32966    "#,
32967      indoc! { r#"
32968      .foo {
32969        color: red;
32970      }
32971
32972      .clearfix {
32973        background: red;
32974      }
32975
32976      @media (hover) {
32977        .bar {
32978          color: red;
32979        }
32980      }
32981
32982      input:placeholder {
32983        color: red;
32984      }
32985
32986      input::hover {
32987        color: red;
32988      }
32989    "#},
32990      ParserOptions {
32991        filename: "test.css".into(),
32992        error_recovery: true,
32993        warnings: warnings.clone(),
32994        ..ParserOptions::default()
32995      },
32996    );
32997    let w = warnings.unwrap();
32998    let warnings = w.read().unwrap();
32999    assert_eq!(
33000      *warnings,
33001      vec![
33002        Error {
33003          kind: ParserError::SelectorError(SelectorError::EmptySelector),
33004          loc: Some(ErrorLocation {
33005            filename: "test.css".into(),
33006            line: 1,
33007            column: 7
33008          })
33009        },
33010        Error {
33011          kind: ParserError::UnexpectedToken(Token::Semicolon),
33012          loc: Some(ErrorLocation {
33013            filename: "test.css".into(),
33014            line: 10,
33015            column: 17
33016          })
33017        },
33018        Error {
33019          kind: ParserError::SelectorError(SelectorError::EmptySelector),
33020          loc: Some(ErrorLocation {
33021            filename: "test.css".into(),
33022            line: 15,
33023            column: 9
33024          })
33025        },
33026        Error {
33027          kind: ParserError::SelectorError(SelectorError::UnsupportedPseudoClass("placeholder".into())),
33028          loc: Some(ErrorLocation {
33029            filename: "test.css".into(),
33030            line: 24,
33031            column: 13,
33032          }),
33033        },
33034        Error {
33035          kind: ParserError::SelectorError(SelectorError::UnsupportedPseudoElement("hover".into())),
33036          loc: Some(ErrorLocation {
33037            filename: "test.css".into(),
33038            line: 28,
33039            column: 13,
33040          }),
33041        },
33042      ]
33043    )
33044  }
33045
33046  #[test]
33047  fn test_invalid() {
33048    error_test(
33049      ".a{color: hsla(120, 62.32%;}",
33050      ParserError::UnexpectedToken(Token::CloseCurlyBracket),
33051    );
33052    error_test(
33053      ".a{--foo: url(foo\\) b\\)ar)}",
33054      ParserError::UnexpectedToken(Token::BadUrl("foo\\) b\\)ar".into())),
33055    );
33056  }
33057
33058  #[test]
33059  fn test_container_queries() {
33060    // name only (no condition) - new syntax
33061    minify_test(
33062      r#"
33063      @container foo {
33064        .inner {
33065          background: green;
33066        }
33067      }
33068    "#,
33069      "@container foo{.inner{background:green}}",
33070    );
33071
33072    // with name
33073    minify_test(
33074      r#"
33075      @container my-layout (inline-size > 45em) {
33076        .foo {
33077          color: red;
33078        }
33079      }
33080    "#,
33081      "@container my-layout (inline-size>45em){.foo{color:red}}",
33082    );
33083
33084    minify_test(
33085      r#"
33086      @container my-layout ( not (width > 500px) ) {
33087        .foo {
33088          color: red;
33089        }
33090      }
33091    "#,
33092      "@container my-layout not (width>500px){.foo{color:red}}",
33093    );
33094
33095    minify_test(
33096      r#"
33097      @container my-layout not (width > 500px) {
33098        .foo {
33099          color: red;
33100        }
33101      }
33102    "#,
33103      "@container my-layout not (width>500px){.foo{color:red}}",
33104    );
33105
33106    minify_test(
33107      r#"
33108      @container not (width > 500px) {
33109        .foo {
33110          color: red;
33111        }
33112      }
33113    "#,
33114      "@container not (width>500px){.foo{color:red}}",
33115    );
33116
33117    minify_test(
33118      r#"
33119      @container my-layout ((width: 100px) and (not (height: 100px))) {
33120        .foo {
33121          color: red;
33122        }
33123      }
33124    "#,
33125      "@container my-layout (width:100px) and (not (height:100px)){.foo{color:red}}",
33126    );
33127
33128    minify_test(
33129      r#"
33130      @container my-layout (width = max(10px, 10em)) {
33131        .foo {
33132          color: red;
33133        }
33134      }
33135    "#,
33136      "@container my-layout (width=max(10px,10em)){.foo{color:red}}",
33137    );
33138
33139    // without name
33140    minify_test(
33141      r#"
33142      @container (inline-size > 45em) {
33143        .foo {
33144          color: red;
33145        }
33146      }
33147    "#,
33148      "@container (inline-size>45em){.foo{color:red}}",
33149    );
33150
33151    minify_test(
33152      r#"
33153      @container (inline-size > 45em) and (inline-size < 100em) {
33154        .foo {
33155          color: red;
33156        }
33157      }
33158    "#,
33159      "@container (inline-size>45em) and (inline-size<100em){.foo{color:red}}",
33160    );
33161
33162    // calc()
33163    minify_test(
33164      r#"
33165      @container (width > calc(100vw - 50px)) {
33166        .foo {
33167          color: red;
33168        }
33169      }
33170    "#,
33171      "@container (width>calc(100vw - 50px)){.foo{color:red}}",
33172    );
33173
33174    minify_test(
33175      r#"
33176      @container (calc(100vh - 50px) <= height ) {
33177        .foo {
33178          color: red;
33179        }
33180      }
33181    "#,
33182      "@container (height>=calc(100vh - 50px)){.foo{color:red}}",
33183    );
33184
33185    // merge adjacent
33186    minify_test(
33187      r#"
33188      @container my-layout (inline-size > 45em) {
33189        .foo {
33190          color: red;
33191        }
33192      }
33193
33194      @container my-layout (inline-size > 45em) {
33195        .foo {
33196          background: yellow;
33197        }
33198
33199        .bar {
33200          color: white;
33201        }
33202      }
33203    "#,
33204      "@container my-layout (inline-size>45em){.foo{color:red;background:#ff0}.bar{color:#fff}}",
33205    );
33206
33207    minify_test(
33208      r#"
33209    .foo {
33210      container-name: foo bar;
33211      container-type: size;
33212    }
33213    "#,
33214      ".foo{container:foo bar/size}",
33215    );
33216    minify_test(
33217      r#"
33218    .foo {
33219      container-name: foo bar;
33220      container-type: normal;
33221    }
33222    "#,
33223      ".foo{container:foo bar}",
33224    );
33225    minify_test(
33226      ".foo{ container-type: inline-size }",
33227      ".foo{container-type:inline-size}",
33228    );
33229    minify_test(".foo{ container-name: none; }", ".foo{container-name:none}");
33230    minify_test(".foo{ container-name: foo; }", ".foo{container-name:foo}");
33231    minify_test(".foo{ container: foo / normal; }", ".foo{container:foo}");
33232    minify_test(
33233      ".foo{ container: foo / inline-size; }",
33234      ".foo{container:foo/inline-size}",
33235    );
33236    minify_test(".foo { width: calc(1cqw + 2cqw) }", ".foo{width:3cqw}");
33237    minify_test(".foo { width: calc(1cqh + 2cqh) }", ".foo{width:3cqh}");
33238    minify_test(".foo { width: calc(1cqi + 2cqi) }", ".foo{width:3cqi}");
33239    minify_test(".foo { width: calc(1cqb + 2cqb) }", ".foo{width:3cqb}");
33240    minify_test(".foo { width: calc(1cqmin + 2cqmin) }", ".foo{width:3cqmin}");
33241    minify_test(".foo { width: calc(1cqmax + 2cqmax) }", ".foo{width:3cqmax}");
33242
33243    // Unlike in @media, there is no need to convert the range syntax in @container,
33244    // because browsers all support this syntax.
33245    prefix_test(
33246      r#"
33247      @container (width > 100px) {
33248        .foo { padding: 5px; }
33249      }
33250      "#,
33251      indoc! { r#"
33252        @container (width > 100px) {
33253          .foo {
33254            padding: 5px;
33255          }
33256        }
33257      "#},
33258      Browsers {
33259        chrome: Some(105 << 16),
33260        ..Browsers::default()
33261      },
33262    );
33263    prefix_test(
33264      r#"
33265      @container (min-width: 100px) {
33266        .foo { padding: 5px; }
33267      }
33268      "#,
33269      indoc! { r#"
33270        @container (width >= 100px) {
33271          .foo {
33272            padding: 5px;
33273          }
33274        }
33275      "#},
33276      Browsers {
33277        chrome: Some(105 << 16),
33278        ..Browsers::default()
33279      },
33280    );
33281
33282    minify_test(
33283      r#"
33284      @container style(--responsive: true) {
33285        .foo {
33286          color: red;
33287        }
33288      }
33289    "#,
33290      "@container style(--responsive:true){.foo{color:red}}",
33291    );
33292    minify_test(
33293      r#"
33294      @container style(--responsive: true) and style(color: yellow) {
33295        .foo {
33296          color: red;
33297        }
33298      }
33299    "#,
33300      "@container style(--responsive:true) and style(color:#ff0){.foo{color:red}}",
33301    );
33302    minify_test(
33303      r#"
33304      @container not style(--responsive: true) {
33305        .foo {
33306          color: red;
33307        }
33308      }
33309    "#,
33310      "@container not style(--responsive:true){.foo{color:red}}",
33311    );
33312    minify_test(
33313      r#"
33314      @container (inline-size > 45em) and style(--responsive: true) {
33315        .foo {
33316          color: red;
33317        }
33318      }
33319    "#,
33320      "@container (inline-size>45em) and style(--responsive:true){.foo{color:red}}",
33321    );
33322    minify_test(
33323      r#"
33324      @container style((accent-color: yellow) or (--bar: 10px)) {
33325        .foo {
33326          color: red;
33327        }
33328      }
33329    "#,
33330      "@container style((accent-color:#ff0) or (--bar:10px)){.foo{color:red}}",
33331    );
33332    minify_test(
33333      r#"
33334      @container style(not ((width: calc(10px + 20px)) and ((--bar: url(x))))) {
33335        .foo {
33336          color: red;
33337        }
33338      }
33339    "#,
33340      "@container style(not ((width:30px) and (--bar:url(x)))){.foo{color:red}}",
33341    );
33342    minify_test(
33343      r#"
33344      @container style(color: yellow !important) {
33345        .foo {
33346          color: red;
33347        }
33348      }
33349    "#,
33350      "@container style(color:yellow){.foo{color:red}}",
33351    );
33352    minify_test(
33353      r#"
33354      @container style(--foo:) {
33355        .foo {
33356          color: red;
33357        }
33358      }
33359    "#,
33360      "@container style(--foo:){.foo{color:red}}",
33361    );
33362    minify_test(
33363      r#"
33364      @container style(--foo: ) {
33365        .foo {
33366          color: red;
33367        }
33368      }
33369    "#,
33370      "@container style(--foo:){.foo{color:red}}",
33371    );
33372    minify_test(
33373      r#"
33374      @container style(--my-prop: foo - bar ()) {
33375        .foo {
33376          color: red;
33377        }
33378      }
33379    "#,
33380      "@container style(--my-prop:foo - bar ()){.foo{color:red}}",
33381    );
33382    minify_test(
33383      r#"
33384      @container style(--test) {
33385        .foo {
33386          color: red;
33387        }
33388      }
33389    "#,
33390      "@container style(--test){.foo{color:red}}",
33391    );
33392    minify_test(
33393      r#"
33394      @container style(width) {
33395        .foo {
33396          color: red;
33397        }
33398      }
33399    "#,
33400      "@container style(width){.foo{color:red}}",
33401    );
33402    minify_test(
33403      r#"
33404      @container scroll-state(scrollable: top) {
33405        .foo {
33406          color: red;
33407        }
33408      }
33409    "#,
33410      "@container scroll-state(scrollable:top){.foo{color:red}}",
33411    );
33412    minify_test(
33413      r#"
33414      @container scroll-state((stuck: top) and (stuck: left)) {
33415        .foo {
33416          color: red;
33417        }
33418      }
33419    "#,
33420      "@container scroll-state((stuck:top) and (stuck:left)){.foo{color:red}}",
33421    );
33422    minify_test(
33423      r#"
33424      @container scroll-state(not ((scrollable: bottom) and (scrollable: right))) {
33425        .foo {
33426          color: red;
33427        }
33428      }
33429    "#,
33430      "@container scroll-state(not ((scrollable:bottom) and (scrollable:right))){.foo{color:red}}",
33431    );
33432    minify_test(
33433      r#"
33434      @container (scroll-state(scrollable: inline-end)) {
33435        .foo {
33436          color: red;
33437        }
33438      }
33439    "#,
33440      "@container scroll-state(scrollable:inline-end){.foo{color:red}}",
33441    );
33442    minify_test(
33443      r#"
33444      @container not scroll-state(scrollable: top) {
33445        .foo {
33446          color: red;
33447        }
33448      }
33449    "#,
33450      "@container not scroll-state(scrollable:top){.foo{color:red}}",
33451    );
33452
33453    // Disallow 'none', 'not', 'and', 'or' as a `<container-name>`
33454    // https://github.com/w3c/csswg-drafts/issues/7203#issuecomment-1144257312
33455    // https://chromium-review.googlesource.com/c/chromium/src/+/3698402
33456    error_test(
33457      "@container none (width < 100vw) {}",
33458      ParserError::UnexpectedToken(crate::properties::custom::Token::Ident("none".into())),
33459    );
33460
33461    error_test(
33462      "@container and (width < 100vw) {}",
33463      ParserError::UnexpectedToken(crate::properties::custom::Token::Ident("and".into())),
33464    );
33465
33466    error_test(
33467      "@container or (width < 100vw) {}",
33468      ParserError::UnexpectedToken(crate::properties::custom::Token::Ident("or".into())),
33469    );
33470
33471    // Disallow CSS wide keywords as a `<container-name>`
33472    error_test(
33473      "@container revert-layer (width < 100vw) {}",
33474      ParserError::UnexpectedToken(crate::properties::custom::Token::Ident("revert-layer".into())),
33475    );
33476
33477    error_test(
33478      "@container initial (width < 100vw) {}",
33479      ParserError::UnexpectedToken(crate::properties::custom::Token::Ident("initial".into())),
33480    );
33481
33482    // <ident> contains spaces
33483    // https://github.com/web-platform-tests/wpt/blob/39f0da08fbbe33d0582a35749b6dbf8bd067a52d/css/css-contain/container-queries/at-container-parsing.html#L160-L178
33484    error_test(
33485      "@container foo bar (width < 100vw) {}",
33486      ParserError::UnexpectedToken(crate::properties::custom::Token::Ident("bar".into())),
33487    );
33488
33489    error_test("@container (inline-size <= foo) {}", ParserError::InvalidMediaQuery);
33490    error_test("@container (orientation <= 10px) {}", ParserError::InvalidMediaQuery);
33491
33492    error_test(
33493      "@container style(style(--foo: bar)) {}",
33494      ParserError::UnexpectedToken(crate::properties::custom::Token::Function("style".into())),
33495    );
33496    error_test(
33497      "@container scroll-state(scroll-state(scrollable: top)) {}",
33498      ParserError::InvalidMediaQuery,
33499    );
33500    error_test(
33501      "@container unknown(foo) {}",
33502      ParserError::UnexpectedToken(crate::properties::custom::Token::Function("unknown".into())),
33503    );
33504
33505    // empty container (no name and no condition) should error
33506    error_test("@container {}", ParserError::EndOfInput);
33507
33508    // empty brackets should return a clearer error message
33509    error_test("@container () {}", ParserError::EmptyBracketInCondition);
33510
33511    // invalid condition after a name should error
33512    error_test("@container foo () {}", ParserError::EmptyBracketInCondition);
33513    error_test(
33514      "@container foo bar {}",
33515      ParserError::UnexpectedToken(crate::properties::custom::Token::Ident("bar".into())),
33516    );
33517
33518    error_recovery_test("@container unknown(foo) {}");
33519  }
33520
33521  #[test]
33522  fn test_css_modules_value_rule() {
33523    css_modules_error_test(
33524      "@value compact: (max-width: 37.4375em);",
33525      ParserError::DeprecatedCssModulesValueRule,
33526    );
33527  }
33528
33529  #[test]
33530  fn test_unknown_at_rules() {
33531    minify_test("@foo;", "@foo;");
33532    minify_test("@foo bar;", "@foo bar;");
33533    minify_test("@foo (bar: baz);", "@foo (bar: baz);");
33534    test(
33535      r#"@foo test {
33536      div {
33537        color: red;
33538      }
33539    }"#,
33540      indoc! { r#"@foo test {
33541      div {
33542            color: red;
33543          }
33544    }
33545    "#},
33546    );
33547    minify_test(
33548      r#"@foo test {
33549      div {
33550        color: red;
33551      }
33552    }"#,
33553      "@foo test{div { color: red; }}",
33554    );
33555    minify_test(
33556      r#"@foo test {
33557        foo: bar;
33558      }"#,
33559      "@foo test{foo: bar;}",
33560    );
33561    test(
33562      r#"@foo {
33563        foo: bar;
33564      }"#,
33565      indoc! {r#"
33566      @foo {
33567        foo: bar;
33568      }
33569      "#},
33570    );
33571    minify_test(
33572      r#"@foo {
33573        foo: bar;
33574      }"#,
33575      "@foo{foo: bar;}",
33576    );
33577  }
33578
33579  #[test]
33580  fn test_resolution() {
33581    use crate::values::resolution::Resolution;
33582
33583    for source in ["-1dpi", "-1dpcm", "-1dppx", "-1x"] {
33584      non_negative_test::<Resolution>(source, None);
33585      assert!(Resolution::parse_string(source).is_ok());
33586    }
33587    non_negative_test::<Resolution>("0dpi", Some("0dpi"));
33588    non_negative_test::<Resolution>("10dpcm", Some("10dpcm"));
33589
33590    prefix_test(
33591      r#"
33592      @media (resolution: 1dppx) {
33593        body {
33594          background: red;
33595        }
33596      }
33597      "#,
33598      indoc! { r#"
33599      @media (resolution: 1dppx) {
33600        body {
33601          background: red;
33602        }
33603      }
33604      "#},
33605      Browsers {
33606        chrome: Some(50 << 16),
33607        ..Browsers::default()
33608      },
33609    );
33610
33611    prefix_test(
33612      r#"
33613      @media (resolution: 1dppx) {
33614        body {
33615          background: red;
33616        }
33617      }
33618      "#,
33619      indoc! { r#"
33620      @media (resolution: 1x) {
33621        body {
33622          background: red;
33623        }
33624      }
33625      "#},
33626      Browsers {
33627        chrome: Some(95 << 16),
33628        ..Browsers::default()
33629      },
33630    );
33631  }
33632
33633  #[test]
33634  fn test_environment() {
33635    minify_test(
33636      r#"
33637      @media (max-width: env(--branding-small)) {
33638        body {
33639          padding: env(--branding-padding);
33640        }
33641      }
33642    "#,
33643      "@media (width<=env(--branding-small)){body{padding:env(--branding-padding)}}",
33644    );
33645
33646    minify_test(
33647      r#"
33648      @media (max-width: env(--branding-small 1)) {
33649        body {
33650          padding: env(--branding-padding 2);
33651        }
33652      }
33653    "#,
33654      "@media (width<=env(--branding-small 1)){body{padding:env(--branding-padding 2)}}",
33655    );
33656
33657    minify_test(
33658      r#"
33659      @media (max-width: env(--branding-small 1, 20px)) {
33660        body {
33661          padding: env(--branding-padding 2, 20px);
33662        }
33663      }
33664    "#,
33665      "@media (width<=env(--branding-small 1,20px)){body{padding:env(--branding-padding 2,20px)}}",
33666    );
33667
33668    minify_test(
33669      r#"
33670      @media (max-width: env(safe-area-inset-top)) {
33671        body {
33672          padding: env(safe-area-inset-top);
33673        }
33674      }
33675    "#,
33676      "@media (width<=env(safe-area-inset-top)){body{padding:env(safe-area-inset-top)}}",
33677    );
33678
33679    minify_test(
33680      r#"
33681      @media (max-width: env(unknown)) {
33682        body {
33683          padding: env(unknown);
33684        }
33685      }
33686    "#,
33687      "@media (width<=env(unknown)){body{padding:env(unknown)}}",
33688    );
33689
33690    prefix_test(
33691      r#"
33692      .foo {
33693        color: env(--brand-color, color(display-p3 0 1 0));
33694      }
33695    "#,
33696      indoc! {r#"
33697      .foo {
33698        color: env(--brand-color, #00fb29);
33699      }
33700
33701      @supports (color: color(display-p3 0 0 0)) {
33702        .foo {
33703          color: env(--brand-color, color(display-p3 0 1 0));
33704        }
33705      }
33706    "#},
33707      Browsers {
33708        safari: Some(15 << 16),
33709        chrome: Some(90 << 16),
33710        ..Browsers::default()
33711      },
33712    );
33713
33714    prefix_test(
33715      r#"
33716      @supports (color: color(display-p3 0 0 0)) {
33717        .foo {
33718          color: env(--brand-color, color(display-p3 0 1 0));
33719        }
33720      }
33721    "#,
33722      indoc! {r#"
33723      @supports (color: color(display-p3 0 0 0)) {
33724        .foo {
33725          color: env(--brand-color, color(display-p3 0 1 0));
33726        }
33727      }
33728    "#},
33729      Browsers {
33730        safari: Some(15 << 16),
33731        chrome: Some(90 << 16),
33732        ..Browsers::default()
33733      },
33734    );
33735
33736    css_modules_test(
33737      r#"
33738      @media (max-width: env(--branding-small)) {
33739        .foo {
33740          color: env(--brand-color);
33741        }
33742      }
33743    "#,
33744      indoc! {r#"
33745      @media (width <= env(--EgL3uq_branding-small)) {
33746        .EgL3uq_foo {
33747          color: env(--EgL3uq_brand-color);
33748        }
33749      }
33750    "#},
33751      map! {
33752        "foo" => "EgL3uq_foo",
33753        "--brand-color" => "--EgL3uq_brand-color" referenced: true,
33754        "--branding-small" => "--EgL3uq_branding-small" referenced: true
33755      },
33756      IndexMap::new(),
33757      crate::css_modules::Config {
33758        dashed_idents: true,
33759        ..Default::default()
33760      },
33761      false,
33762    );
33763  }
33764
33765  #[test]
33766  fn test_license_comments() {
33767    minify_test(
33768      r#"
33769      /*! Copyright 2023 Someone awesome */
33770      /* Some other comment */
33771      .foo {
33772        color: red;
33773      }
33774    "#,
33775      indoc! {r#"
33776      /*! Copyright 2023 Someone awesome */
33777      .foo{color:red}"#},
33778    );
33779
33780    minify_test(
33781      r#"
33782      /*! Copyright 2023 Someone awesome */
33783      /*! Copyright 2023 Someone else */
33784      .foo {
33785        color: red;
33786      }
33787    "#,
33788      indoc! {r#"
33789      /*! Copyright 2023 Someone awesome */
33790      /*! Copyright 2023 Someone else */
33791      .foo{color:red}"#},
33792    );
33793  }
33794
33795  #[test]
33796  fn test_starting_style() {
33797    minify_test(
33798      r#"
33799      @starting-style {
33800        h1 {
33801          background: yellow;
33802        }
33803      }
33804      "#,
33805      "@starting-style{h1{background:#ff0}}",
33806    );
33807    minify_test("@starting-style {}", "");
33808
33809    nesting_test(
33810      r#"
33811      h1 {
33812        background: red;
33813        @starting-style {
33814          background: yellow;
33815        }
33816      }
33817      "#,
33818      indoc! {r#"
33819      h1 {
33820        background: red;
33821      }
33822
33823      @starting-style {
33824        h1 {
33825          background: #ff0;
33826        }
33827      }
33828      "#},
33829    );
33830  }
33831
33832  #[test]
33833  fn test_color_scheme() {
33834    minify_test(".foo { color-scheme: normal; }", ".foo{color-scheme:normal}");
33835    minify_test(".foo { color-scheme: light; }", ".foo{color-scheme:light}");
33836    minify_test(".foo { color-scheme: dark; }", ".foo{color-scheme:dark}");
33837    minify_test(".foo { color-scheme: light dark; }", ".foo{color-scheme:light dark}");
33838    minify_test(".foo { color-scheme: dark light; }", ".foo{color-scheme:light dark}");
33839    minify_test(".foo { color-scheme: only light; }", ".foo{color-scheme:light only}");
33840    minify_test(".foo { color-scheme: only dark; }", ".foo{color-scheme:dark only}");
33841    minify_test(".foo { color-scheme: inherit; }", ".foo{color-scheme:inherit}");
33842    minify_test(":root { color-scheme: unset; }", ":root{color-scheme:unset}");
33843    minify_test(".foo { color-scheme: unknow; }", ".foo{color-scheme:unknow}");
33844    minify_test(".foo { color-scheme: only; }", ".foo{color-scheme:only}");
33845    minify_test(".foo { color-scheme: dark foo; }", ".foo{color-scheme:dark foo}");
33846    minify_test(".foo { color-scheme: normal dark; }", ".foo{color-scheme:normal dark}");
33847    minify_test(
33848      ".foo { color-scheme: dark light only; }",
33849      ".foo{color-scheme:light dark only}",
33850    );
33851    minify_test(
33852      ".foo { color-scheme: foo bar light; }",
33853      ".foo{color-scheme:foo bar light}",
33854    );
33855    minify_test(
33856      ".foo { color-scheme: only foo dark bar; }",
33857      ".foo{color-scheme:only foo dark bar}",
33858    );
33859    prefix_test(
33860      ".foo { color-scheme: dark; }",
33861      indoc! { r#"
33862      .foo {
33863        --lightningcss-light: ;
33864        --lightningcss-dark: initial;
33865        color-scheme: dark;
33866      }
33867      "#},
33868      Browsers {
33869        chrome: Some(90 << 16),
33870        ..Browsers::default()
33871      },
33872    );
33873    prefix_test(
33874      ".foo { color-scheme: light; }",
33875      indoc! { r#"
33876      .foo {
33877        --lightningcss-light: initial;
33878        --lightningcss-dark: ;
33879        color-scheme: light;
33880      }
33881      "#},
33882      Browsers {
33883        chrome: Some(90 << 16),
33884        ..Browsers::default()
33885      },
33886    );
33887    prefix_test(
33888      ".foo { color-scheme: light dark; }",
33889      indoc! { r#"
33890      .foo {
33891        --lightningcss-light: initial;
33892        --lightningcss-dark: ;
33893        color-scheme: light dark;
33894      }
33895
33896      @media (prefers-color-scheme: dark) {
33897        .foo {
33898          --lightningcss-light: ;
33899          --lightningcss-dark: initial;
33900        }
33901      }
33902      "#},
33903      Browsers {
33904        chrome: Some(90 << 16),
33905        ..Browsers::default()
33906      },
33907    );
33908    prefix_test(
33909      ".foo { color-scheme: light dark; }",
33910      indoc! { r#"
33911      .foo {
33912        color-scheme: light dark;
33913      }
33914      "#},
33915      Browsers {
33916        firefox: Some(120 << 16),
33917        ..Browsers::default()
33918      },
33919    );
33920
33921    minify_test(
33922      ".foo { color: light-dark(yellow, red); }",
33923      ".foo{color:light-dark(#ff0,red)}",
33924    );
33925    minify_test(
33926      ".foo { color: light-dark(light-dark(yellow, red), light-dark(yellow, red)); }",
33927      ".foo{color:light-dark(#ff0,red)}",
33928    );
33929    minify_test(
33930      ".foo { color: light-dark(rgb(0, 0, 255), hsl(120deg, 50%, 50%)); }",
33931      ".foo{color:light-dark(#00f,#40bf40)}",
33932    );
33933    prefix_test(
33934      ".foo { color: light-dark(oklch(40% 0.1268735435 34.568626), oklab(59.686% 0.1009 0.1192)); }",
33935      indoc! { r#"
33936      .foo {
33937        color: var(--lightningcss-light, #7e250f) var(--lightningcss-dark, #c65d07);
33938        color: var(--lightningcss-light, lab(29.2661% 38.2437 35.3889)) var(--lightningcss-dark, lab(52.2319% 40.1449 59.9171));
33939      }
33940      "#},
33941      Browsers {
33942        chrome: Some(90 << 16),
33943        ..Browsers::default()
33944      },
33945    );
33946    prefix_test(
33947      ".foo { color: light-dark(oklch(40% 0.1268735435 34.568626), oklab(59.686% 0.1009 0.1192)); }",
33948      indoc! { r#"
33949      .foo {
33950        color: light-dark(oklch(40% .126874 34.5686), oklab(59.686% .1009 .1192));
33951      }
33952      "#},
33953      Browsers {
33954        firefox: Some(120 << 16),
33955        ..Browsers::default()
33956      },
33957    );
33958    prefix_test(
33959      r#"
33960      .foo {
33961        box-shadow:
33962            oklch(100% 0 0deg / 50%) 0 0.63rem 0.94rem -0.19rem,
33963            currentColor 0 0.44rem 0.8rem -0.58rem;
33964      }
33965    "#,
33966      indoc! { r#"
33967      .foo {
33968        box-shadow: 0 .63rem .94rem -.19rem #ffffff80, 0 .44rem .8rem -.58rem;
33969        box-shadow: 0 .63rem .94rem -.19rem lab(100% 0 0 / .5), 0 .44rem .8rem -.58rem;
33970      }
33971      "#},
33972      Browsers {
33973        chrome: Some(95 << 16),
33974        ..Browsers::default()
33975      },
33976    );
33977    prefix_test(
33978      r#"
33979      .foo {
33980        box-shadow:
33981            oklch(100% 0 0deg / 50%) 0 0.63rem 0.94rem -0.19rem,
33982            currentColor 0 0.44rem 0.8rem -0.58rem;
33983      }
33984    "#,
33985      indoc! { r#"
33986      .foo {
33987        box-shadow: 0 .63rem .94rem -.19rem color(display-p3 1 1 1 / .5), 0 .44rem .8rem -.58rem;
33988        box-shadow: 0 .63rem .94rem -.19rem lab(100% 0 0 / .5), 0 .44rem .8rem -.58rem;
33989      }
33990      "#},
33991      Browsers {
33992        safari: Some(14 << 16),
33993        ..Browsers::default()
33994      },
33995    );
33996
33997    prefix_test(
33998      ".foo { color: light-dark(var(--light), var(--dark)); }",
33999      indoc! { r#"
34000      .foo {
34001        color: var(--lightningcss-light, var(--light)) var(--lightningcss-dark, var(--dark));
34002      }
34003      "#},
34004      Browsers {
34005        chrome: Some(90 << 16),
34006        ..Browsers::default()
34007      },
34008    );
34009    prefix_test(
34010      ".foo { color: rgb(from light-dark(yellow, red) r g b / 10%); }",
34011      indoc! { r#"
34012      .foo {
34013        color: var(--lightningcss-light, #ffff001a) var(--lightningcss-dark, #ff00001a);
34014      }
34015      "#},
34016      Browsers {
34017        chrome: Some(90 << 16),
34018        ..Browsers::default()
34019      },
34020    );
34021    prefix_test(
34022      ".foo { color: alpha(from light-dark(yellow, red) / 10%); }",
34023      indoc! { r#"
34024      .foo {
34025        color: var(--lightningcss-light, #ffff001a) var(--lightningcss-dark, #ff00001a);
34026      }
34027      "#},
34028      Browsers {
34029        chrome: Some(90 << 16),
34030        ..Browsers::default()
34031      },
34032    );
34033    prefix_test(
34034      ".foo { color: rgb(from light-dark(yellow, red) r g b / var(--alpha)); }",
34035      indoc! { r#"
34036      .foo {
34037        color: var(--lightningcss-light, rgb(255 255 0 / var(--alpha))) var(--lightningcss-dark, rgb(255 0 0 / var(--alpha)));
34038      }
34039      "#},
34040      Browsers {
34041        chrome: Some(90 << 16),
34042        ..Browsers::default()
34043      },
34044    );
34045    prefix_test(
34046      ".foo { color: color(from light-dark(yellow, red) srgb r g b / 10%); }",
34047      indoc! { r#"
34048      .foo {
34049        color: var(--lightningcss-light, #ffff001a) var(--lightningcss-dark, #ff00001a);
34050        color: var(--lightningcss-light, color(srgb 1 1 0 / .1)) var(--lightningcss-dark, color(srgb 1 0 0 / .1));
34051      }
34052      "#},
34053      Browsers {
34054        chrome: Some(90 << 16),
34055        ..Browsers::default()
34056      },
34057    );
34058    prefix_test(
34059      ".foo { color: color-mix(in srgb, light-dark(yellow, red), light-dark(red, pink)); }",
34060      indoc! { r#"
34061      .foo {
34062        color: var(--lightningcss-light, #ff8000) var(--lightningcss-dark, #ff6066);
34063      }
34064      "#},
34065      Browsers {
34066        chrome: Some(90 << 16),
34067        ..Browsers::default()
34068      },
34069    );
34070    nesting_test_with_targets(
34071      r#"
34072        .foo { color-scheme: light; }
34073        .bar { color: light-dark(red, green); }
34074      "#,
34075      indoc! {r#"
34076        .foo {
34077          color-scheme: light;
34078        }
34079
34080        .bar {
34081          color: light-dark(red, green);
34082        }
34083      "#},
34084      Targets {
34085        browsers: Some(Browsers {
34086          safari: Some(13 << 16),
34087          ..Browsers::default()
34088        }),
34089        include: Features::empty(),
34090        exclude: Features::LightDark,
34091      },
34092    );
34093  }
34094
34095  #[test]
34096  fn test_print_color_adjust() {
34097    prefix_test(
34098      ".foo { print-color-adjust: exact; }",
34099      indoc! { r#"
34100      .foo {
34101        -webkit-print-color-adjust: exact;
34102        print-color-adjust: exact;
34103      }
34104      "#},
34105      Browsers {
34106        chrome: Some(135 << 16),
34107        ..Browsers::default()
34108      },
34109    );
34110    prefix_test(
34111      ".foo { print-color-adjust: exact; }",
34112      indoc! { r#"
34113      .foo {
34114        print-color-adjust: exact;
34115      }
34116      "#},
34117      Browsers {
34118        chrome: Some(137 << 16),
34119        ..Browsers::default()
34120      },
34121    );
34122  }
34123
34124  #[test]
34125  fn test_all() {
34126    minify_test(".foo { all: initial; all: initial }", ".foo{all:initial}");
34127    minify_test(".foo { all: initial; all: revert }", ".foo{all:revert}");
34128    minify_test(".foo { background: red; all: revert-layer }", ".foo{all:revert-layer}");
34129    minify_test(
34130      ".foo { background: red; all: revert-layer; background: green }",
34131      ".foo{all:revert-layer;background:green}",
34132    );
34133    minify_test(
34134      ".foo { --test: red; all: revert-layer }",
34135      ".foo{--test:red;all:revert-layer}",
34136    );
34137    minify_test(
34138      ".foo { unicode-bidi: embed; all: revert-layer }",
34139      ".foo{all:revert-layer;unicode-bidi:embed}",
34140    );
34141    minify_test(
34142      ".foo { direction: rtl; all: revert-layer }",
34143      ".foo{all:revert-layer;direction:rtl}",
34144    );
34145    minify_test(
34146      ".foo { direction: rtl; all: revert-layer; direction: ltr }",
34147      ".foo{all:revert-layer;direction:ltr}",
34148    );
34149    minify_test(".foo { background: var(--foo); all: unset; }", ".foo{all:unset}");
34150    minify_test(
34151      ".foo { all: unset; background: var(--foo); }",
34152      ".foo{all:unset;background:var(--foo)}",
34153    );
34154    minify_test(
34155      ".foo {--bar:currentcolor; --foo:1.1em; all:unset}",
34156      ".foo{--bar:currentcolor;--foo:1.1em;all:unset}",
34157    );
34158  }
34159
34160  #[test]
34161  fn test_view_transition() {
34162    minify_test(
34163      "@view-transition { navigation: auto }",
34164      "@view-transition{navigation:auto}",
34165    );
34166    minify_test(
34167      "@view-transition { navigation: auto; types: none; }",
34168      "@view-transition{navigation:auto;types:none}",
34169    );
34170    minify_test(
34171      "@view-transition { navigation: auto; types: foo bar; }",
34172      "@view-transition{navigation:auto;types:foo bar}",
34173    );
34174    minify_test(
34175      "@layer { @view-transition { navigation: auto; types: foo bar; } }",
34176      "@layer{@view-transition{navigation:auto;types:foo bar}}",
34177    );
34178  }
34179
34180  #[test]
34181  fn test_skip_generating_unnecessary_fallbacks() {
34182    prefix_test(
34183      r#"
34184      @supports (color: lab(0% 0 0)) and (color: color(display-p3 0 0 0)) {
34185        .foo {
34186          color: lab(40% 56.6 39);
34187        }
34188
34189        .bar {
34190          color: color(display-p3 .643308 .192455 .167712);
34191        }
34192      }
34193      "#,
34194      indoc! {r#"
34195      @supports (color: lab(0% 0 0)) and (color: color(display-p3 0 0 0)) {
34196        .foo {
34197          color: lab(40% 56.6 39);
34198        }
34199
34200        .bar {
34201          color: color(display-p3 .643308 .192455 .167712);
34202        }
34203      }
34204      "#},
34205      Browsers {
34206        chrome: Some(4 << 16),
34207        ..Browsers::default()
34208      },
34209    );
34210
34211    prefix_test(
34212      r#"
34213      @supports (color: lab(40% 56.6 39)) {
34214        .foo {
34215          color: lab(40% 56.6 39);
34216        }
34217      }
34218      "#,
34219      indoc! {r#"
34220      @supports (color: lab(40% 56.6 39)) {
34221        .foo {
34222          color: lab(40% 56.6 39);
34223        }
34224      }
34225      "#},
34226      Browsers {
34227        chrome: Some(4 << 16),
34228        ..Browsers::default()
34229      },
34230    );
34231
34232    prefix_test(
34233      r#"
34234      @supports (background-color: lab(40% 56.6 39)) {
34235        .foo {
34236          background-color: lab(40% 56.6 39);
34237        }
34238      }
34239      "#,
34240      indoc! {r#"
34241      @supports (background-color: lab(40% 56.6 39)) {
34242        .foo {
34243          background-color: lab(40% 56.6 39);
34244        }
34245      }
34246      "#},
34247      Browsers {
34248        chrome: Some(4 << 16),
34249        ..Browsers::default()
34250      },
34251    );
34252
34253    prefix_test(
34254      r#"
34255      @supports (color: light-dark(#f00, #00f)) {
34256        .foo {
34257          color: light-dark(#ff0, #0ff);
34258        }
34259      }
34260      "#,
34261      indoc! {r#"
34262      @supports (color: light-dark(#f00, #00f)) {
34263        .foo {
34264          color: light-dark(#ff0, #0ff);
34265        }
34266      }
34267      "#},
34268      Browsers {
34269        chrome: Some(4 << 16),
34270        ..Browsers::default()
34271      },
34272    );
34273
34274    // NOTE: fallback for lab is not necessary
34275    prefix_test(
34276      r#"
34277      @supports (color: lab(0% 0 0)) and (not (color: color(display-p3 0 0 0))) {
34278        .foo {
34279          color: lab(40% 56.6 39);
34280        }
34281
34282        .bar {
34283          color: color(display-p3 .643308 .192455 .167712);
34284        }
34285      }
34286      "#,
34287      indoc! {r#"
34288      @supports (color: lab(0% 0 0)) and (not (color: color(display-p3 0 0 0))) {
34289        .foo {
34290          color: #b32323;
34291          color: lab(40% 56.6 39);
34292        }
34293
34294        .bar {
34295          color: #b32323;
34296          color: color(display-p3 .643308 .192455 .167712);
34297        }
34298      }
34299      "#},
34300      Browsers {
34301        chrome: Some(4 << 16),
34302        ..Browsers::default()
34303      },
34304    );
34305
34306    prefix_test(
34307      r#"
34308      @supports (color: lab(0% 0 0)) or (color: color(display-p3 0 0 0)) {
34309        .foo {
34310          color: lab(40% 56.6 39);
34311        }
34312
34313        .bar {
34314          color: color(display-p3 .643308 .192455 .167712);
34315        }
34316      }
34317      "#,
34318      indoc! {r#"
34319      @supports (color: lab(0% 0 0)) or (color: color(display-p3 0 0 0)) {
34320        .foo {
34321          color: #b32323;
34322          color: lab(40% 56.6 39);
34323        }
34324
34325        .bar {
34326          color: #b32323;
34327          color: color(display-p3 .643308 .192455 .167712);
34328        }
34329      }
34330      "#},
34331      Browsers {
34332        chrome: Some(4 << 16),
34333        ..Browsers::default()
34334      },
34335    );
34336  }
34337}