Add ServoUrl as a parameter to report_error(...) of ParseErrorReporter

passes test-tidy
removed match and used map

added new test test_report_error_passing_correct_url(...) and modified old unit tests

removed the option for servourl and tidied up

removed the duplicate test.

made a few more changes after @cbrewster suggestions.

changed _url to url in few places

fixed the indenting
This commit is contained in:
avinash 2017-02-27 15:49:48 +05:30 committed by Connor Brewster
parent c62973b77b
commit f48f0567cf
7 changed files with 36 additions and 19 deletions

View file

@ -18,8 +18,10 @@ use style_traits::ToCss;
pub struct CSSErrorReporterTest;
impl ParseErrorReporter for CSSErrorReporterTest {
fn report_error(&self, _input: &mut Parser, _position: SourcePosition, _message: &str) {
}
fn report_error(&self, _input: &mut Parser, _position: SourcePosition, _message: &str,
_url: &ServoUrl) {
}
fn clone(&self) -> Box<ParseErrorReporter + Send + Sync> {
Box::new(CSSErrorReporterTest)
}

View file

@ -17,8 +17,9 @@ use test::{self, Bencher};
struct ErrorringErrorReporter;
impl ParseErrorReporter for ErrorringErrorReporter {
fn report_error(&self, _: &mut Parser, position: SourcePosition, message: &str) {
panic!("CSS error: {:?} {}", position, message);
fn report_error(&self, input: &mut Parser, position: SourcePosition, message: &str,
url: &ServoUrl) {
panic!("CSS error: {}\t\n{:?} {}", url.as_str(), position, message);
}
fn clone(&self) -> Box<ParseErrorReporter + Send + Sync> {

View file

@ -276,6 +276,7 @@ fn test_parse_stylesheet() {
}
struct CSSError {
pub url : ServoUrl,
pub line: usize,
pub column: usize,
pub message: String
@ -294,7 +295,9 @@ impl CSSInvalidErrorReporterTest {
}
impl ParseErrorReporter for CSSInvalidErrorReporterTest {
fn report_error(&self, input: &mut CssParser, position: SourcePosition, message: &str) {
fn report_error(&self, input: &mut CssParser, position: SourcePosition, message: &str,
url: &ServoUrl) {
let location = input.source_location(position);
let errors = self.errors.clone();
@ -302,6 +305,7 @@ impl ParseErrorReporter for CSSInvalidErrorReporterTest {
errors.push(
CSSError{
url: url.clone(),
line: location.line,
column: location.column,
message: message.to_owned()
@ -333,7 +337,7 @@ fn test_report_error_stylesheet() {
let errors = error_reporter.errors.clone();
Stylesheet::from_str(css, url, Origin::UserAgent, Default::default(),
Stylesheet::from_str(css, url.clone(), Origin::UserAgent, Default::default(),
None,
error_reporter,
ParserContextExtraData::default());
@ -349,4 +353,7 @@ fn test_report_error_stylesheet() {
assert_eq!("Unsupported property declaration: 'display: invalid;'", error.message);
assert_eq!(4, error.line);
assert_eq!(9, error.column);
// testing for the url
assert_eq!(url, error.url);
}