mirror of
https://github.com/servo/servo.git
synced 2025-08-11 16:35:33 +01:00
Treat top-level number in calc() invalid
Currently, CalcLengthOrPercentage doesn't actually keep the number value, so if we don't treat it invalid, we can end up generating empty `calc()` value when one contains top-level numbers (e.g. `calc(1)`), which would violate assertion elsewhere that `calc` must not be empty.
This commit is contained in:
parent
f159b5cb10
commit
6fec4d7645
2 changed files with 24 additions and 4 deletions
|
@ -3,8 +3,10 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use app_units::Au;
|
||||
use cssparser::Parser;
|
||||
use style::values::HasViewportPercentage;
|
||||
use style::values::specified::{ViewportPercentageLength, Length};
|
||||
use style::values::specified::length::{CalcLengthOrPercentage, CalcUnit};
|
||||
|
||||
#[test]
|
||||
fn length_has_viewport_percentage() {
|
||||
|
@ -13,3 +15,22 @@ fn length_has_viewport_percentage() {
|
|||
let l = Length::Absolute(Au(100));
|
||||
assert!(!l.has_viewport_percentage());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn calc_top_level_number_with_unit() {
|
||||
fn parse(text: &str, unit: CalcUnit) -> Result<CalcLengthOrPercentage, ()> {
|
||||
let mut parser = Parser::new(text);
|
||||
CalcLengthOrPercentage::parse(&mut parser, unit)
|
||||
}
|
||||
assert_eq!(parse("1", CalcUnit::Length), Err(()));
|
||||
assert_eq!(parse("1", CalcUnit::LengthOrPercentage), Err(()));
|
||||
assert_eq!(parse("1", CalcUnit::Angle), Err(()));
|
||||
assert_eq!(parse("1", CalcUnit::Time), Err(()));
|
||||
assert_eq!(parse("1px + 1", CalcUnit::Length), Err(()));
|
||||
assert_eq!(parse("1em + 1", CalcUnit::Length), Err(()));
|
||||
assert_eq!(parse("1px + 1", CalcUnit::LengthOrPercentage), Err(()));
|
||||
assert_eq!(parse("1% + 1", CalcUnit::LengthOrPercentage), Err(()));
|
||||
assert_eq!(parse("1rad + 1", CalcUnit::Angle), Err(()));
|
||||
assert_eq!(parse("1deg + 1", CalcUnit::Angle), Err(()));
|
||||
assert_eq!(parse("1s + 1", CalcUnit::Time), Err(()));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue