mirror of
https://github.com/servo/servo.git
synced 2025-10-15 16:00:28 +01:00
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.
36 lines
1.6 KiB
Rust
36 lines
1.6 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* 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() {
|
|
let l = Length::ViewportPercentage(ViewportPercentageLength::Vw(100.));
|
|
assert!(l.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(()));
|
|
}
|