mirror of
https://github.com/servo/servo.git
synced 2025-08-14 09:55:35 +01:00
Centralize ParserContext for tests
To simplify adding additional data to `ParserContext`, this moves test usages to a few shared locations, instead of being spread across many tests. MozReview-Commit-ID: 1OahV797eq
This commit is contained in:
parent
f7896fd80b
commit
0936dd24d0
27 changed files with 248 additions and 513 deletions
35
tests/unit/style/parsing/value.rs
Normal file
35
tests/unit/style/parsing/value.rs
Normal file
|
@ -0,0 +1,35 @@
|
|||
/* 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 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() {
|
||||
let l = NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vw(100.));
|
||||
assert!(l.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