diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-04-12 01:16:32 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-12 01:16:32 -0500 |
commit | c8cd70f333d41864ff7bf7dce84301509c71d1d6 (patch) | |
tree | ea19e42a502f3674c0d80f6c7f535531f1ce0199 /tests/unit/style | |
parent | 3c5a21ebf39b31cb77cb1a2e162e4abdac325e74 (diff) | |
parent | 7ecee05e4a098788fcb5f2764914411ed8d0ad54 (diff) | |
download | servo-c8cd70f333d41864ff7bf7dce84301509c71d1d6.tar.gz servo-c8cd70f333d41864ff7bf7dce84301509c71d1d6.zip |
Auto merge of #16229 - tomhoule:fix-lengths, r=emilio
style: Do not immediately convert absolute specified lengths
<!-- Please describe your changes on the following line: -->
This PR aims to solve issue #15729. I tried to follow the recommendations there as much as possible.
This is my first attempt at contributing to Servo, so this will probably need a lot of input, although I'm eager to make it as polished as possible.
- The base inaccuracy issue seems solved, as can be easily verified with the `console.log` based example in the issue.
- Very basic unit tests were added.
I have doubts mainly about the right way to represent these new enum variants for the various length units:
1. With new enum variants in `NoCalcLength` *and* newtypes (current solution)
2. With a `NoCalcLength::Absolute` variant that contains a new `AbsoluteLength` enum, but without newtypes
3. Same as solution 2 but with newtypes
- I mostly cared about unit tests until now but will investigate other types of tests
- Tests to check the clamping
- Write a proper commit message
Thanks for your time and feedback :)
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #15729.
<!-- Either: -->
- [X] There are tests for these changes
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16229)
<!-- Reviewable:end -->
Diffstat (limited to 'tests/unit/style')
-rw-r--r-- | tests/unit/style/parsing/length.rs | 17 | ||||
-rw-r--r-- | tests/unit/style/properties/viewport.rs | 4 | ||||
-rw-r--r-- | tests/unit/style/value.rs | 4 |
3 files changed, 20 insertions, 5 deletions
diff --git a/tests/unit/style/parsing/length.rs b/tests/unit/style/parsing/length.rs index eda3b3425e3..39407441aaf 100644 --- a/tests/unit/style/parsing/length.rs +++ b/tests/unit/style/parsing/length.rs @@ -2,9 +2,13 @@ * 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 cssparser::Parser; +use media_queries::CSSErrorReporterTest; use parsing::parse; -use style::parser::Parse; +use style::parser::{Parse, ParserContext}; +use style::stylesheets::Origin; use style::values::specified::length::Length; +use style_traits::ToCss; #[test] fn test_calc() { @@ -13,3 +17,14 @@ fn test_calc() { assert!(parse(Length::parse, "calc(1px + 2px )").is_ok()); assert!(parse(Length::parse, "calc( 1px + 2px)").is_ok()); } + +#[test] +fn test_length_literals() { + assert_roundtrip_with_context!(Length::parse, "0.33px", "0.33px"); + assert_roundtrip_with_context!(Length::parse, "0.33in", "0.33in"); + assert_roundtrip_with_context!(Length::parse, "0.33cm", "0.33cm"); + assert_roundtrip_with_context!(Length::parse, "0.33mm", "0.33mm"); + assert_roundtrip_with_context!(Length::parse, "0.33q", "0.33q"); + assert_roundtrip_with_context!(Length::parse, "0.33pt", "0.33pt"); + assert_roundtrip_with_context!(Length::parse, "0.33pc", "0.33pc"); +} diff --git a/tests/unit/style/properties/viewport.rs b/tests/unit/style/properties/viewport.rs index 8b88d61f293..0f602ac4475 100644 --- a/tests/unit/style/properties/viewport.rs +++ b/tests/unit/style/properties/viewport.rs @@ -6,7 +6,7 @@ use app_units::Au; use style::properties::PropertyDeclaration; use style::properties::longhands::border_top_width; use style::values::HasViewportPercentage; -use style::values::specified::{Length, NoCalcLength, ViewportPercentageLength}; +use style::values::specified::{AbsoluteLength, Length, NoCalcLength, ViewportPercentageLength}; #[test] fn has_viewport_percentage_for_specified_value() { @@ -20,7 +20,7 @@ fn has_viewport_percentage_for_specified_value() { let pabs = PropertyDeclaration::BorderTopWidth(Box::new( border_top_width::SpecifiedValue::from_length( - Length::NoCalc(NoCalcLength::Absolute(Au(100))) + Length::NoCalc(NoCalcLength::Absolute(AbsoluteLength::Px(Au(100).to_f32_px()))) ) )); assert!(!pabs.has_viewport_percentage()); diff --git a/tests/unit/style/value.rs b/tests/unit/style/value.rs index 472a5177d30..4214b5ef1b5 100644 --- a/tests/unit/style/value.rs +++ b/tests/unit/style/value.rs @@ -5,14 +5,14 @@ use app_units::Au; use cssparser::Parser; use style::values::HasViewportPercentage; -use style::values::specified::{ViewportPercentageLength, NoCalcLength}; +use style::values::specified::{AbsoluteLength, ViewportPercentageLength, NoCalcLength}; 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(Au(100)); + let l = NoCalcLength::Absolute(AbsoluteLength::Px(Au(100).to_f32_px())); assert!(!l.has_viewport_percentage()); } |