diff --git a/src/parse/value/css_function.rs b/src/parse/value/css_function.rs index 676e22c..0115b91 100644 --- a/src/parse/value/css_function.rs +++ b/src/parse/value/css_function.rs @@ -202,7 +202,7 @@ impl<'a> Parser<'a> { } 'm' | 'M' => { self.toks.advance_cursor(); - match self.toks.peek() { + let inner_fn_name = match self.toks.peek() { Some(Token { kind: 'i', .. }) | Some(Token { kind: 'I', .. }) => { self.toks.advance_cursor(); if !matches!( @@ -211,7 +211,8 @@ impl<'a> Parser<'a> { ) { return Ok(None); } - buf.push_str("min("); + + "min" } Some(Token { kind: 'a', .. }) | Some(Token { kind: 'A', .. }) => { self.toks.advance_cursor(); @@ -221,10 +222,11 @@ impl<'a> Parser<'a> { ) { return Ok(None); } - buf.push_str("max("); + + "max" } _ => return Ok(None), - } + }; self.toks.advance_cursor(); @@ -232,7 +234,9 @@ impl<'a> Parser<'a> { return Ok(None); } - if let Some(val) = self.try_parse_min_max(fn_name, false)? { + self.toks.advance_cursor(); + + if let Some(val) = self.try_parse_min_max(inner_fn_name, true)? { buf.push_str(&val); } else { return Ok(None); diff --git a/tests/min-max.rs b/tests/min-max.rs index b9ec498..66d8a24 100644 --- a/tests/min-max.rs +++ b/tests/min-max.rs @@ -105,3 +105,28 @@ error!( "$a: 1px;\n$b: 2%;\na {\n color: max($a, $b);\n}\n", "Error: Incompatible units px and %." ); // todo: special functions, min(calc(1), $b); +test!( + min_containing_max, + "a {\n color: min(1, max(2));\n}\n", + "a {\n color: min(1, max(2));\n}\n" +); +test!( + max_containing_min, + "a {\n color: max(1, min(2));\n}\n", + "a {\n color: max(1, min(2));\n}\n" +); +test!( + min_containing_max_as_only_arg, + "a {\n color: min(max(1px, 2px));\n}\n", + "a {\n color: min(max(1px, 2px));\n}\n" +); +test!( + max_containing_min_as_only_arg, + "a {\n color: max(min(1px, 2px));\n}\n", + "a {\n color: max(min(1px, 2px));\n}\n" +); +test!( + extremely_nested_min_and_max, + "a {\n color: min(max(min(max(min(min(1), max(2))))), min(max(min(3))));\n}\n", + "a {\n color: min(max(min(max(min(min(1), max(2))))), min(max(min(3))));\n}\n" +);