servo: Merge #16713 - style: Allow parsing nested calc() expressions (from emilio:calc-in-calc); r=manishearth

Source-Repo: https://github.com/servo/servo
Source-Revision: 53b391daf84b3a611e5b356ed97fc22f6cbe92b7

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 0c9b88e0d1c9000590e438ad60c1327e607149d6
This commit is contained in:
Emilio Cobos Álvarez 2017-05-03 18:33:03 -05:00
Родитель cd2d82d36b
Коммит 01d358ada0
2 изменённых файлов: 5 добавлений и 0 удалений

Просмотреть файл

@ -843,6 +843,10 @@ impl CalcLengthOrPercentage {
input.parse_nested_block(|i| CalcLengthOrPercentage::parse_sum(context, i, expected_unit)) input.parse_nested_block(|i| CalcLengthOrPercentage::parse_sum(context, i, expected_unit))
.map(|result| CalcValueNode::Sum(Box::new(result))) .map(|result| CalcValueNode::Sum(Box::new(result)))
}, },
(Token::Function(ref name), _) if name.eq_ignore_ascii_case("calc") => {
input.parse_nested_block(|i| CalcLengthOrPercentage::parse_sum(context, i, expected_unit))
.map(|result| CalcValueNode::Sum(Box::new(result)))
}
_ => Err(()) _ => Err(())
} }
} }

Просмотреть файл

@ -16,6 +16,7 @@ use style_traits::ToCss;
#[test] #[test]
fn test_calc() { fn test_calc() {
assert!(parse(Length::parse, "calc(1px+ 2px)").is_err()); assert!(parse(Length::parse, "calc(1px+ 2px)").is_err());
assert!(parse(Length::parse, "calc(calc(1px) + calc(1px + 4px))").is_ok());
assert!(parse(Length::parse, "calc( 1px + 2px )").is_ok()); assert!(parse(Length::parse, "calc( 1px + 2px )").is_ok());
assert!(parse(Length::parse, "calc(1px + 2px )").is_ok()); assert!(parse(Length::parse, "calc(1px + 2px )").is_ok());
assert!(parse(Length::parse, "calc( 1px + 2px)").is_ok()); assert!(parse(Length::parse, "calc( 1px + 2px)").is_ok());