aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/style/parsing/position.rs75
-rw-r--r--tests/unit/style/properties/serialization.rs64
2 files changed, 117 insertions, 22 deletions
diff --git a/tests/unit/style/parsing/position.rs b/tests/unit/style/parsing/position.rs
index 5bb0d414510..34b7528a329 100644
--- a/tests/unit/style/parsing/position.rs
+++ b/tests/unit/style/parsing/position.rs
@@ -61,4 +61,79 @@ fn test_position() {
assert!(parse(Position::parse, "top 10px bottom").is_err());
assert!(parse(Position::parse, "top 10px bottom 15%").is_err());
+ // Logical keywords are not supported in Position yet
+ assert!(parse(Position::parse, "x-start").is_err());
+ assert!(parse(Position::parse, "y-end").is_err());
+ assert!(parse(Position::parse, "x-start y-end").is_err());
+ assert!(parse(Position::parse, "x-end 10px").is_err());
+ assert!(parse(Position::parse, "y-start 20px").is_err());
+ assert!(parse(Position::parse, "x-start bottom 10%").is_err());
+ assert!(parse(Position::parse, "left y-start 10%").is_err());
+ assert!(parse(Position::parse, "x-start 20px y-end 10%").is_err());
+}
+
+#[test]
+fn test_horizontal_position() {
+ // One value serializations.
+ assert_roundtrip_with_context!(HorizontalPosition::parse, "20px", "20px");
+ assert_roundtrip_with_context!(HorizontalPosition::parse, "25%", "25%");
+ assert_roundtrip_with_context!(HorizontalPosition::parse, "center", "center");
+ assert_roundtrip_with_context!(HorizontalPosition::parse, "left", "left");
+ assert_roundtrip_with_context!(HorizontalPosition::parse, "right", "right");
+ assert_roundtrip_with_context!(HorizontalPosition::parse, "x-start", "x-start");
+ assert_roundtrip_with_context!(HorizontalPosition::parse, "x-end", "x-end");
+
+ // Two value serializations.
+ assert_roundtrip_with_context!(HorizontalPosition::parse, "right 10px", "right 10px");
+ assert_roundtrip_with_context!(HorizontalPosition::parse, "10px left", "left 10px");
+ assert_roundtrip_with_context!(HorizontalPosition::parse, "x-end 20%", "x-end 20%");
+ assert_roundtrip_with_context!(HorizontalPosition::parse, "20px x-start", "x-start 20px");
+
+ // Invalid horizontal positions.
+ assert!(parse(HorizontalPosition::parse, "top").is_err());
+ assert!(parse(HorizontalPosition::parse, "bottom").is_err());
+ assert!(parse(HorizontalPosition::parse, "y-start").is_err());
+ assert!(parse(HorizontalPosition::parse, "y-end").is_err());
+ assert!(parse(HorizontalPosition::parse, "20px y-end").is_err());
+ assert!(parse(HorizontalPosition::parse, "y-end 20px ").is_err());
+ assert!(parse(HorizontalPosition::parse, "bottom 20px").is_err());
+ assert!(parse(HorizontalPosition::parse, "20px top").is_err());
+ assert!(parse(HorizontalPosition::parse, "left center").is_err());
+ assert!(parse(HorizontalPosition::parse, "bottom top").is_err());
+ assert!(parse(HorizontalPosition::parse, "left top").is_err());
+ assert!(parse(HorizontalPosition::parse, "left right").is_err());
+ assert!(parse(HorizontalPosition::parse, "20px 30px").is_err());
+}
+
+#[test]
+fn test_vertical_position() {
+ // One value serializations.
+ assert_roundtrip_with_context!(VerticalPosition::parse, "20px", "20px");
+ assert_roundtrip_with_context!(VerticalPosition::parse, "25%", "25%");
+ assert_roundtrip_with_context!(VerticalPosition::parse, "center", "center");
+ assert_roundtrip_with_context!(VerticalPosition::parse, "top", "top");
+ assert_roundtrip_with_context!(VerticalPosition::parse, "bottom", "bottom");
+ assert_roundtrip_with_context!(VerticalPosition::parse, "y-start", "y-start");
+ assert_roundtrip_with_context!(VerticalPosition::parse, "y-end", "y-end");
+
+ // Two value serializations.
+ assert_roundtrip_with_context!(VerticalPosition::parse, "bottom 10px", "bottom 10px");
+ assert_roundtrip_with_context!(VerticalPosition::parse, "10px top", "top 10px");
+ assert_roundtrip_with_context!(VerticalPosition::parse, "y-end 20%", "y-end 20%");
+ assert_roundtrip_with_context!(VerticalPosition::parse, "20px y-start", "y-start 20px");
+
+ // Invalid vertical positions.
+ assert!(parse(VerticalPosition::parse, "left").is_err());
+ assert!(parse(VerticalPosition::parse, "right").is_err());
+ assert!(parse(VerticalPosition::parse, "x-start").is_err());
+ assert!(parse(VerticalPosition::parse, "x-end").is_err());
+ assert!(parse(VerticalPosition::parse, "20px x-end").is_err());
+ assert!(parse(VerticalPosition::parse, "x-end 20px ").is_err());
+ assert!(parse(VerticalPosition::parse, "left 20px").is_err());
+ assert!(parse(VerticalPosition::parse, "20px right").is_err());
+ assert!(parse(VerticalPosition::parse, "left center").is_err());
+ assert!(parse(VerticalPosition::parse, "bottom top").is_err());
+ assert!(parse(VerticalPosition::parse, "left top").is_err());
+ assert!(parse(VerticalPosition::parse, "left right").is_err());
+ assert!(parse(VerticalPosition::parse, "20px 30px").is_err());
}
diff --git a/tests/unit/style/properties/serialization.rs b/tests/unit/style/properties/serialization.rs
index c27fe00dc61..182f128faa0 100644
--- a/tests/unit/style/properties/serialization.rs
+++ b/tests/unit/style/properties/serialization.rs
@@ -692,7 +692,7 @@ mod shorthand_serialization {
use style::properties::longhands::background_repeat as repeat;
use style::properties::longhands::background_size as size;
use style::values::specified::Image;
- use style::values::specified::position::Position;
+ use style::values::specified::position::{HorizontalPosition, Position, VerticalPosition};
use super::*;
macro_rules! single_vec_value_typedef {
($name:ident, $path:expr) => {
@@ -733,10 +733,14 @@ mod shorthand_serialization {
let position = single_vec_value_typedef!(position,
Position {
- horiz_keyword: None,
- horiz_position: Some(LengthOrPercentage::Length(Length::from_px(7f32))),
- vert_keyword: None,
- vert_position: Some(LengthOrPercentage::Length(Length::from_px(4f32)))
+ horizontal: HorizontalPosition {
+ keyword: None,
+ position: Some(LengthOrPercentage::Length(Length::from_px(7f32))),
+ },
+ vertical: VerticalPosition {
+ keyword: None,
+ position: Some(LengthOrPercentage::Length(Length::from_px(4f32))),
+ },
}
);
@@ -787,10 +791,14 @@ mod shorthand_serialization {
let position = single_vec_value_typedef!(position,
Position {
- horiz_keyword: None,
- horiz_position: Some(LengthOrPercentage::Length(Length::from_px(7f32))),
- vert_keyword: None,
- vert_position: Some(LengthOrPercentage::Length(Length::from_px(4f32)))
+ horizontal: HorizontalPosition {
+ keyword: None,
+ position: Some(LengthOrPercentage::Length(Length::from_px(7f32))),
+ },
+ vertical: VerticalPosition {
+ keyword: None,
+ position: Some(LengthOrPercentage::Length(Length::from_px(4f32))),
+ },
}
);
@@ -840,10 +848,14 @@ mod shorthand_serialization {
let position = single_vec_value_typedef!(position,
Position {
- horiz_keyword: None,
- horiz_position: Some(LengthOrPercentage::Length(Length::from_px(0f32))),
- vert_keyword: None,
- vert_position: Some(LengthOrPercentage::Length(Length::from_px(0f32)))
+ horizontal: HorizontalPosition {
+ keyword: None,
+ position: Some(LengthOrPercentage::Length(Length::from_px(0f32))),
+ },
+ vertical: VerticalPosition {
+ keyword: None,
+ position: Some(LengthOrPercentage::Length(Length::from_px(0f32))),
+ },
}
);
@@ -881,7 +893,7 @@ mod shorthand_serialization {
use style::properties::longhands::mask_repeat as repeat;
use style::properties::longhands::mask_size as size;
use style::values::specified::Image;
- use style::values::specified::position::Position;
+ use style::values::specified::position::{HorizontalPosition, Position, VerticalPosition};
use super::*;
macro_rules! single_vec_value_typedef {
@@ -918,10 +930,14 @@ mod shorthand_serialization {
let position = single_vec_value_typedef!(position,
Position {
- horiz_keyword: None,
- horiz_position: Some(LengthOrPercentage::Length(Length::from_px(7f32))),
- vert_keyword: None,
- vert_position: Some(LengthOrPercentage::Length(Length::from_px(4f32)))
+ horizontal: HorizontalPosition {
+ keyword: None,
+ position: Some(LengthOrPercentage::Length(Length::from_px(7f32))),
+ },
+ vertical: VerticalPosition {
+ keyword: None,
+ position: Some(LengthOrPercentage::Length(Length::from_px(4f32))),
+ },
}
);
@@ -968,10 +984,14 @@ mod shorthand_serialization {
let position = single_vec_value_typedef!(position,
Position {
- horiz_keyword: None,
- horiz_position: Some(LengthOrPercentage::Length(Length::from_px(7f32))),
- vert_keyword: None,
- vert_position: Some(LengthOrPercentage::Length(Length::from_px(4f32)))
+ horizontal: HorizontalPosition {
+ keyword: None,
+ position: Some(LengthOrPercentage::Length(Length::from_px(7f32))),
+ },
+ vertical: VerticalPosition {
+ keyword: None,
+ position: Some(LengthOrPercentage::Length(Length::from_px(4f32))),
+ },
}
);