From c6cb7c1d6825198d2453a69dbc3be538303122f7 Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Fri, 30 Jul 2021 05:57:13 -0400 Subject: [PATCH] support special fn `clamp` --- src/parse/value/parse.rs | 3 +++ src/value/css_function.rs | 1 + tests/special-functions.rs | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/src/parse/value/parse.rs b/src/parse/value/parse.rs index a420e69..b27f5cb 100644 --- a/src/parse/value/parse.rs +++ b/src/parse/value/parse.rs @@ -278,6 +278,9 @@ impl<'a, 'b> Parser<'a, 'b> { .to_css_string(self.options.is_compressed())?, ), }, + "clamp" if lower == "clamp" => { + self.parse_calc_args(&mut s)?; + } _ => s.push_str( &self .parse_call_args()? diff --git a/src/value/css_function.rs b/src/value/css_function.rs index 0712f79..671c0df 100644 --- a/src/value/css_function.rs +++ b/src/value/css_function.rs @@ -4,4 +4,5 @@ pub(crate) fn is_special_function(s: &str) -> bool { || s.starts_with("env(") || s.starts_with("min(") || s.starts_with("max(") + || s.starts_with("clamp(") } diff --git a/tests/special-functions.rs b/tests/special-functions.rs index a153406..b50b077 100644 --- a/tests/special-functions.rs +++ b/tests/special-functions.rs @@ -234,3 +234,23 @@ error!( progid_nothing_after, "a { color: progid:", "Error: expected \"(\"." ); +test!( + clamp_empty_args, + "a {\n color: clamp();\n}\n", + "a {\n color: clamp();\n}\n" +); +test!( + clamp_parens_in_args, + "a {\n color: clamp((()));\n}\n", + "a {\n color: clamp((()));\n}\n" +); +test!( + clamp_single_arg, + "a {\n color: clamp(1);\n}\n", + "a {\n color: clamp(1);\n}\n" +); +test!( + clamp_many_args, + "a {\n color: clamp(1, 2, 3);\n}\n", + "a {\n color: clamp(1, 2, 3);\n}\n" +);