Refactor how calc() clamping is done on computed values (fixes #15296)

This commit is contained in:
Anthony Ramine 2017-05-16 15:44:59 +02:00
parent f935f2da01
commit d0b9bd9c64
13 changed files with 173 additions and 154 deletions

View file

@ -5,17 +5,18 @@
use app_units::Au;
use style::attr::{AttrValue, LengthOrPercentageOrAuto, parse_length};
use style::values::computed::CalcLengthOrPercentage;
use style_traits::values::specified::AllowedLengthType;
#[test]
fn test_length_calc() {
let calc = CalcLengthOrPercentage { length: Au(10), percentage: Some(0.2) };
assert_eq!(calc.to_computed(Some(Au(10))), Some(Au(12)));
assert_eq!(calc.to_computed(Some(Au(0))), Some(Au(10)));
assert_eq!(calc.to_computed(None), None);
let calc = CalcLengthOrPercentage::new(Au(10), Some(0.2));
assert_eq!(calc.to_used_value(Some(Au(10))), Some(Au(12)));
assert_eq!(calc.to_used_value(Some(Au(0))), Some(Au(10)));
assert_eq!(calc.to_used_value(None), None);
let calc = CalcLengthOrPercentage { length: Au(10), percentage: None };
assert_eq!(calc.to_computed(Some(Au(0))), Some(Au(10)));
assert_eq!(calc.to_computed(None), Some(Au(10)));
let calc = CalcLengthOrPercentage::new(Au(10), None);
assert_eq!(calc.to_used_value(Some(Au(0))), Some(Au(10)));
assert_eq!(calc.to_used_value(None), Some(Au(10)));
}
#[test]