aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/style
diff options
context:
space:
mode:
authorRavi Shankar <wafflespeanut@gmail.com>2016-11-26 20:49:49 +0530
committerRavi Shankar <wafflespeanut@gmail.com>2016-11-27 08:49:28 +0530
commitf290a6f88c53bc7366d16b7735de0dff77fdffdb (patch)
treeaeb7ef2f3950ebdea987eb6aeb91af70aa6344d6 /tests/unit/style
parentdee1a65a6983188a125f820b8bc9505f4909e171 (diff)
downloadservo-f290a6f88c53bc7366d16b7735de0dff77fdffdb.tar.gz
servo-f290a6f88c53bc7366d16b7735de0dff77fdffdb.zip
Fix the unit tests to use context
Diffstat (limited to 'tests/unit/style')
-rw-r--r--tests/unit/style/parsing/basic_shape.rs9
-rw-r--r--tests/unit/style/parsing/mod.rs30
-rw-r--r--tests/unit/style/parsing/position.rs57
-rw-r--r--tests/unit/style/parsing/selectors.rs12
4 files changed, 51 insertions, 57 deletions
diff --git a/tests/unit/style/parsing/basic_shape.rs b/tests/unit/style/parsing/basic_shape.rs
index 6363e7772ca..342d732b5c2 100644
--- a/tests/unit/style/parsing/basic_shape.rs
+++ b/tests/unit/style/parsing/basic_shape.rs
@@ -2,8 +2,11 @@
* 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::basic_shape::*;
use style_traits::ToCss;
@@ -11,8 +14,8 @@ use style_traits::ToCss;
// and their individual components
macro_rules! assert_roundtrip_basicshape {
($fun:expr, $input:expr, $output:expr) => {
- assert_roundtrip!($fun, $input, $output);
- assert_roundtrip!(BasicShape::parse, $input, $output);
+ assert_roundtrip_with_context!($fun, $input, $output);
+ assert_roundtrip_with_context!(BasicShape::parse, $input, $output);
}
}
diff --git a/tests/unit/style/parsing/mod.rs b/tests/unit/style/parsing/mod.rs
index 8e12018a7a3..369e0b66bf0 100644
--- a/tests/unit/style/parsing/mod.rs
+++ b/tests/unit/style/parsing/mod.rs
@@ -5,32 +5,19 @@
//! Tests for parsing and serialization of values/properties
use cssparser::Parser;
+use media_queries::CSSErrorReporterTest;
+use style::parser::ParserContext;
+use style::stylesheets::Origin;
-fn parse<T, F: Fn(&mut Parser) -> Result<T, ()>>(f: F, s: &str) -> Result<T, ()> {
+fn parse<T, F: Fn(&ParserContext, &mut Parser) -> Result<T, ()>>(f: F, s: &str) -> Result<T, ()> {
+ let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
+ let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let mut parser = Parser::new(s);
- f(&mut parser)
+ f(&context, &mut parser)
}
-
// This is a macro so that the file/line information
// is preserved in the panic
-macro_rules! assert_roundtrip {
- ($fun:expr, $string:expr) => {
- assert_roundtrip!($fun, $string, $string);
- };
- ($fun:expr, $input:expr, $output:expr) => {
- let parsed = $crate::parsing::parse($fun, $input)
- .expect(&format!("Failed to parse {}", $input));
- let serialized = ToCss::to_css_string(&parsed);
- assert_eq!(serialized, $output);
-
- let re_parsed = $crate::parsing::parse($fun, &serialized)
- .expect(&format!("Failed to parse serialization {}", $input));
- let re_serialized = ToCss::to_css_string(&re_parsed);
- assert_eq!(serialized, re_serialized);
- }
-}
-
macro_rules! assert_roundtrip_with_context {
($fun:expr, $string:expr) => {
assert_roundtrip_with_context!($fun, $string, $string);
@@ -46,13 +33,12 @@ macro_rules! assert_roundtrip_with_context {
let mut parser = Parser::new(&serialized);
let re_parsed = $fun(&context, &mut parser)
- .expect(&format!("Failed to parse {}", $input));
+ .expect(&format!("Failed to parse serialization {}", $input));
let re_serialized = ToCss::to_css_string(&re_parsed);
assert_eq!(serialized, re_serialized);
}
}
-
macro_rules! parse_longhand {
($name:ident, $s:expr) => {{
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
diff --git a/tests/unit/style/parsing/position.rs b/tests/unit/style/parsing/position.rs
index e610e9cee2e..5bb0d414510 100644
--- a/tests/unit/style/parsing/position.rs
+++ b/tests/unit/style/parsing/position.rs
@@ -2,8 +2,11 @@
* 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::position::*;
use style_traits::ToCss;
@@ -12,38 +15,38 @@ fn test_position() {
// Serialization is not actually specced
// though these are the values expected by basic-shape
// https://github.com/w3c/csswg-drafts/issues/368
- assert_roundtrip!(Position::parse, "center", "center center");
- assert_roundtrip!(Position::parse, "top left", "left top");
- assert_roundtrip!(Position::parse, "left top", "left top");
- assert_roundtrip!(Position::parse, "top right", "right top");
- assert_roundtrip!(Position::parse, "right top", "right top");
- assert_roundtrip!(Position::parse, "bottom left", "left bottom");
- assert_roundtrip!(Position::parse, "left bottom", "left bottom");
- assert_roundtrip!(Position::parse, "left center", "left center");
- assert_roundtrip!(Position::parse, "right center", "right center");
- assert_roundtrip!(Position::parse, "center top", "center top");
- assert_roundtrip!(Position::parse, "center bottom", "center bottom");
- assert_roundtrip!(Position::parse, "center 10px", "center 10px");
- assert_roundtrip!(Position::parse, "center 10%", "center 10%");
- assert_roundtrip!(Position::parse, "right 10%", "right 10%");
+ assert_roundtrip_with_context!(Position::parse, "center", "center center");
+ assert_roundtrip_with_context!(Position::parse, "top left", "left top");
+ assert_roundtrip_with_context!(Position::parse, "left top", "left top");
+ assert_roundtrip_with_context!(Position::parse, "top right", "right top");
+ assert_roundtrip_with_context!(Position::parse, "right top", "right top");
+ assert_roundtrip_with_context!(Position::parse, "bottom left", "left bottom");
+ assert_roundtrip_with_context!(Position::parse, "left bottom", "left bottom");
+ assert_roundtrip_with_context!(Position::parse, "left center", "left center");
+ assert_roundtrip_with_context!(Position::parse, "right center", "right center");
+ assert_roundtrip_with_context!(Position::parse, "center top", "center top");
+ assert_roundtrip_with_context!(Position::parse, "center bottom", "center bottom");
+ assert_roundtrip_with_context!(Position::parse, "center 10px", "center 10px");
+ assert_roundtrip_with_context!(Position::parse, "center 10%", "center 10%");
+ assert_roundtrip_with_context!(Position::parse, "right 10%", "right 10%");
// Only keywords can be reordered
assert!(parse(Position::parse, "top 40%").is_err());
assert!(parse(Position::parse, "40% left").is_err());
// 3 and 4 value serialization
- assert_roundtrip!(Position::parse, "left 10px top 15px", "left 10px top 15px");
- assert_roundtrip!(Position::parse, "top 15px left 10px", "left 10px top 15px");
- assert_roundtrip!(Position::parse, "left 10% top 15px", "left 10% top 15px");
- assert_roundtrip!(Position::parse, "top 15px left 10%", "left 10% top 15px");
- assert_roundtrip!(Position::parse, "left top 15px", "left top 15px");
- assert_roundtrip!(Position::parse, "top 15px left", "left top 15px");
- assert_roundtrip!(Position::parse, "left 10px top", "left 10px top");
- assert_roundtrip!(Position::parse, "top left 10px", "left 10px top");
- assert_roundtrip!(Position::parse, "right 10px bottom", "right 10px bottom");
- assert_roundtrip!(Position::parse, "bottom right 10px", "right 10px bottom");
- assert_roundtrip!(Position::parse, "center right 10px", "right 10px center");
- assert_roundtrip!(Position::parse, "center bottom 10px", "center bottom 10px");
+ assert_roundtrip_with_context!(Position::parse, "left 10px top 15px", "left 10px top 15px");
+ assert_roundtrip_with_context!(Position::parse, "top 15px left 10px", "left 10px top 15px");
+ assert_roundtrip_with_context!(Position::parse, "left 10% top 15px", "left 10% top 15px");
+ assert_roundtrip_with_context!(Position::parse, "top 15px left 10%", "left 10% top 15px");
+ assert_roundtrip_with_context!(Position::parse, "left top 15px", "left top 15px");
+ assert_roundtrip_with_context!(Position::parse, "top 15px left", "left top 15px");
+ assert_roundtrip_with_context!(Position::parse, "left 10px top", "left 10px top");
+ assert_roundtrip_with_context!(Position::parse, "top left 10px", "left 10px top");
+ assert_roundtrip_with_context!(Position::parse, "right 10px bottom", "right 10px bottom");
+ assert_roundtrip_with_context!(Position::parse, "bottom right 10px", "right 10px bottom");
+ assert_roundtrip_with_context!(Position::parse, "center right 10px", "right 10px center");
+ assert_roundtrip_with_context!(Position::parse, "center bottom 10px", "center bottom 10px");
// Only horizontal and vertical keywords can have positions
assert!(parse(Position::parse, "center 10px left 15px").is_err());
diff --git a/tests/unit/style/parsing/selectors.rs b/tests/unit/style/parsing/selectors.rs
index dbbda99381e..3654360b07c 100644
--- a/tests/unit/style/parsing/selectors.rs
+++ b/tests/unit/style/parsing/selectors.rs
@@ -3,11 +3,13 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use cssparser::{Parser, ToCss};
+use media_queries::CSSErrorReporterTest;
use selectors::parser::SelectorList;
+use style::parser::ParserContext;
use style::selector_parser::{SelectorImpl, SelectorParser};
use style::stylesheets::{Origin, Namespaces};
-fn parse(input: &mut Parser) -> Result<SelectorList<SelectorImpl>, ()> {
+fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SelectorList<SelectorImpl>, ()> {
let mut ns = Namespaces::default();
ns.prefixes.insert("svg".into(), ns!(svg));
let parser = SelectorParser {
@@ -19,8 +21,8 @@ fn parse(input: &mut Parser) -> Result<SelectorList<SelectorImpl>, ()> {
#[test]
fn test_selectors() {
- assert_roundtrip!(parse, "div");
- assert_roundtrip!(parse, "svg|circle");
- assert_roundtrip!(parse, "p:before", "p::before");
- assert_roundtrip!(parse, "[border = \"0\"]:-servo-nonzero-border ~ ::-servo-details-summary");
+ assert_roundtrip_with_context!(parse, "div");
+ assert_roundtrip_with_context!(parse, "svg|circle");
+ assert_roundtrip_with_context!(parse, "p:before", "p::before");
+ assert_roundtrip_with_context!(parse, "[border = \"0\"]:-servo-nonzero-border ~ ::-servo-details-summary");
}