Fix unit tests

This commit is contained in:
Nazım Can Altınova 2016-12-12 03:22:22 +03:00
parent ed806efade
commit ca85221525
5 changed files with 69 additions and 46 deletions

View file

@ -7,7 +7,8 @@ use media_queries::CSSErrorReporterTest;
use servo_url::ServoUrl;
use style::parser::ParserContext;
use style::properties::longhands::{background_attachment, background_clip, background_color, background_image};
use style::properties::longhands::{background_origin, background_position, background_repeat, background_size};
use style::properties::longhands::{background_origin, background_position_x, background_position_y, background_repeat};
use style::properties::longhands::background_size;
use style::properties::shorthands::background;
use style::stylesheets::Origin;
@ -20,7 +21,8 @@ fn background_shorthand_should_parse_all_available_properties_when_specified() {
let result = background::parse_value(&context, &mut parser).unwrap();
assert_eq!(result.background_image.unwrap(), parse_longhand!(background_image, "url(\"http://servo/test.png\")"));
assert_eq!(result.background_position.unwrap(), parse_longhand!(background_position, "top center"));
assert_eq!(result.background_position_x.unwrap(), parse_longhand!(background_position_x, "center"));
assert_eq!(result.background_position_y.unwrap(), parse_longhand!(background_position_y, "top"));
assert_eq!(result.background_size.unwrap(), parse_longhand!(background_size, "200px 200px"));
assert_eq!(result.background_repeat.unwrap(), parse_longhand!(background_repeat, "repeat-x"));
assert_eq!(result.background_attachment.unwrap(), parse_longhand!(background_attachment, "fixed"));
@ -36,7 +38,8 @@ fn background_shorthand_should_parse_when_some_fields_set() {
let mut parser = Parser::new("14px 40px repeat-y");
let result = background::parse_value(&context, &mut parser).unwrap();
assert_eq!(result.background_position.unwrap(), parse_longhand!(background_position, "14px 40px"));
assert_eq!(result.background_position_x.unwrap(), parse_longhand!(background_position_x, "14px"));
assert_eq!(result.background_position_y.unwrap(), parse_longhand!(background_position_y, "40px"));
assert_eq!(result.background_repeat.unwrap(), parse_longhand!(background_repeat, "repeat-y"));
let mut parser = Parser::new("url(\"http://servo/test.png\") repeat blue");
@ -68,8 +71,8 @@ fn background_shorthand_should_parse_comma_separated_declarations() {
assert_eq!(result.background_image.unwrap(), parse_longhand!(background_image, "url(\"http://servo/test.png\"), \
url(\"http://servo/test.png\"), none"));
assert_eq!(result.background_position.unwrap(), parse_longhand!(background_position, "left top, center center, \
0% 0%"));
assert_eq!(result.background_position_x.unwrap(), parse_longhand!(background_position_x, "left, center, 0%"));
assert_eq!(result.background_position_y.unwrap(), parse_longhand!(background_position_y, "top, center, 0%"));
assert_eq!(result.background_repeat.unwrap(), parse_longhand!(background_repeat, "no-repeat, no-repeat, repeat"));
assert_eq!(result.background_clip.unwrap(), parse_longhand!(background_clip, "border-box, border-box, border-box"));
assert_eq!(result.background_origin.unwrap(), parse_longhand!(background_origin, "padding-box, padding-box, \
@ -86,12 +89,14 @@ fn background_shorthand_should_parse_position_and_size_correctly() {
let mut parser = Parser::new("7px 4px");
let result = background::parse_value(&context, &mut parser).unwrap();
assert_eq!(result.background_position.unwrap(), parse_longhand!(background_position, "7px 4px"));
assert_eq!(result.background_position_x.unwrap(), parse_longhand!(background_position_x, "7px"));
assert_eq!(result.background_position_y.unwrap(), parse_longhand!(background_position_y, "4px"));
let mut parser = Parser::new("7px 4px / 30px 20px");
let result = background::parse_value(&context, &mut parser).unwrap();
assert_eq!(result.background_position.unwrap(), parse_longhand!(background_position, "7px 4px"));
assert_eq!(result.background_position_x.unwrap(), parse_longhand!(background_position_x, "7px"));
assert_eq!(result.background_position_y.unwrap(), parse_longhand!(background_position_y, "4px"));
assert_eq!(result.background_size.unwrap(), parse_longhand!(background_size, "30px 20px"));
let mut parser = Parser::new("/ 30px 20px");

View file

@ -688,11 +688,12 @@ mod shorthand_serialization {
use style::properties::longhands::background_clip as clip;
use style::properties::longhands::background_image as image;
use style::properties::longhands::background_origin as origin;
use style::properties::longhands::background_position as position;
use style::properties::longhands::background_position_x as position_x;
use style::properties::longhands::background_position_y as position_y;
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::{HorizontalPosition, Position, VerticalPosition};
use style::values::specified::position::{HorizontalPosition, VerticalPosition};
use super::*;
macro_rules! single_vec_value_typedef {
($name:ident, $path:expr) => {
@ -731,16 +732,17 @@ mod shorthand_serialization {
authored: None
});
let position = single_vec_value_typedef!(position,
Position {
horizontal: HorizontalPosition {
let position_x = single_vec_value_typedef!(position_x,
HorizontalPosition {
keyword: None,
position: Some(LengthOrPercentage::Length(Length::from_px(7f32))),
},
vertical: VerticalPosition {
}
);
let position_y = single_vec_value_typedef!(position_y,
VerticalPosition {
keyword: None,
position: Some(LengthOrPercentage::Length(Length::from_px(4f32))),
},
}
);
@ -763,7 +765,8 @@ mod shorthand_serialization {
let clip = single_vec_keyword_value!(clip, padding_box);
properties.push(PropertyDeclaration::BackgroundColor(color));
properties.push(PropertyDeclaration::BackgroundPosition(position));
properties.push(PropertyDeclaration::BackgroundPositionX(position_x));
properties.push(PropertyDeclaration::BackgroundPositionY(position_y));
properties.push(PropertyDeclaration::BackgroundRepeat(repeat));
properties.push(PropertyDeclaration::BackgroundAttachment(attachment));
properties.push(PropertyDeclaration::BackgroundImage(image));
@ -789,16 +792,17 @@ mod shorthand_serialization {
authored: None
});
let position = single_vec_value_typedef!(position,
Position {
horizontal: HorizontalPosition {
let position_x = single_vec_value_typedef!(position_x,
HorizontalPosition {
keyword: None,
position: Some(LengthOrPercentage::Length(Length::from_px(7f32))),
},
vertical: VerticalPosition {
}
);
let position_y = single_vec_value_typedef!(position_y,
VerticalPosition {
keyword: None,
position: Some(LengthOrPercentage::Length(Length::from_px(4f32))),
},
}
);
@ -821,7 +825,8 @@ mod shorthand_serialization {
let clip = single_vec_keyword_value!(clip, padding_box);
properties.push(PropertyDeclaration::BackgroundColor(color));
properties.push(PropertyDeclaration::BackgroundPosition(position));
properties.push(PropertyDeclaration::BackgroundPositionX(position_x));
properties.push(PropertyDeclaration::BackgroundPositionY(position_y));
properties.push(PropertyDeclaration::BackgroundRepeat(repeat));
properties.push(PropertyDeclaration::BackgroundAttachment(attachment));
properties.push(PropertyDeclaration::BackgroundImage(image));
@ -846,16 +851,17 @@ mod shorthand_serialization {
authored: None
});
let position = single_vec_value_typedef!(position,
Position {
horizontal: HorizontalPosition {
let position_x = single_vec_value_typedef!(position_x,
HorizontalPosition {
keyword: None,
position: Some(LengthOrPercentage::Length(Length::from_px(0f32))),
},
vertical: VerticalPosition {
}
);
let position_y = single_vec_value_typedef!(position_y,
VerticalPosition {
keyword: None,
position: Some(LengthOrPercentage::Length(Length::from_px(0f32))),
},
}
);
@ -870,7 +876,8 @@ mod shorthand_serialization {
let clip = DeclaredValue::Initial;
properties.push(PropertyDeclaration::BackgroundColor(color));
properties.push(PropertyDeclaration::BackgroundPosition(position));
properties.push(PropertyDeclaration::BackgroundPositionX(position_x));
properties.push(PropertyDeclaration::BackgroundPositionY(position_y));
properties.push(PropertyDeclaration::BackgroundRepeat(repeat));
properties.push(PropertyDeclaration::BackgroundAttachment(attachment));
properties.push(PropertyDeclaration::BackgroundImage(image));

View file

@ -190,10 +190,15 @@ fn test_parse_stylesheet() {
}
)),
Importance::Normal),
(PropertyDeclaration::BackgroundPosition(DeclaredValue::Value(
longhands::background_position::SpecifiedValue(
vec![longhands::background_position::single_value
::get_initial_specified_value()]))),
(PropertyDeclaration::BackgroundPositionX(DeclaredValue::Value(
longhands::background_position_x::SpecifiedValue(
vec![longhands::background_position_x::single_value
::get_initial_position_value()]))),
Importance::Normal),
(PropertyDeclaration::BackgroundPositionY(DeclaredValue::Value(
longhands::background_position_y::SpecifiedValue(
vec![longhands::background_position_y::single_value
::get_initial_position_value()]))),
Importance::Normal),
(PropertyDeclaration::BackgroundRepeat(DeclaredValue::Value(
longhands::background_repeat::SpecifiedValue(

View file

@ -6,3 +6,6 @@
[background_initial_color]
expected: FAIL
[background_initial_position]
expected: FAIL

View file

@ -6,3 +6,6 @@
[background_specified_color_color]
expected: FAIL
[background_specified_color_position]
expected: FAIL