mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
style: Rewrite calc to be cleaner and support arbitrary expressions.
This improves Servo's calc support compliant with[1], and makes it cleaner and more straight-forward. [1]: https://github.com/w3c/csswg-drafts/issues/1241
This commit is contained in:
parent
36f26148e6
commit
3608dc8088
7 changed files with 638 additions and 596 deletions
|
@ -6,7 +6,6 @@ use app_units::Au;
|
|||
use parsing::parse;
|
||||
use style::values::HasViewportPercentage;
|
||||
use style::values::specified::{AbsoluteLength, NoCalcLength, ViewportPercentageLength};
|
||||
use style::values::specified::length::{CalcLengthOrPercentage, CalcUnit};
|
||||
|
||||
#[test]
|
||||
fn length_has_viewport_percentage() {
|
||||
|
@ -15,21 +14,3 @@ fn length_has_viewport_percentage() {
|
|||
let l = NoCalcLength::Absolute(AbsoluteLength::Px(Au(100).to_f32_px()));
|
||||
assert!(!l.has_viewport_percentage());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn calc_top_level_number_with_unit() {
|
||||
fn parse_value(text: &str, unit: CalcUnit) -> Result<CalcLengthOrPercentage, ()> {
|
||||
parse(|context, input| CalcLengthOrPercentage::parse(context, input, unit), text)
|
||||
}
|
||||
assert_eq!(parse_value("1", CalcUnit::Length), Err(()));
|
||||
assert_eq!(parse_value("1", CalcUnit::LengthOrPercentage), Err(()));
|
||||
assert_eq!(parse_value("1", CalcUnit::Angle), Err(()));
|
||||
assert_eq!(parse_value("1", CalcUnit::Time), Err(()));
|
||||
assert_eq!(parse_value("1px + 1", CalcUnit::Length), Err(()));
|
||||
assert_eq!(parse_value("1em + 1", CalcUnit::Length), Err(()));
|
||||
assert_eq!(parse_value("1px + 1", CalcUnit::LengthOrPercentage), Err(()));
|
||||
assert_eq!(parse_value("1% + 1", CalcUnit::LengthOrPercentage), Err(()));
|
||||
assert_eq!(parse_value("1rad + 1", CalcUnit::Angle), Err(()));
|
||||
assert_eq!(parse_value("1deg + 1", CalcUnit::Angle), Err(()));
|
||||
assert_eq!(parse_value("1s + 1", CalcUnit::Time), Err(()));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue