mirror of
https://github.com/servo/servo.git
synced 2025-08-18 03:45:33 +01:00
Support line number offsets for inline stylesheets
This commit is contained in:
parent
ea20bd6f63
commit
5d8cbd8e6a
11 changed files with 87 additions and 37 deletions
|
@ -19,8 +19,12 @@ use style_traits::ToCss;
|
|||
pub struct CSSErrorReporterTest;
|
||||
|
||||
impl ParseErrorReporter for CSSErrorReporterTest {
|
||||
fn report_error(&self, _input: &mut Parser, _position: SourcePosition, _message: &str,
|
||||
_url: &ServoUrl) {
|
||||
fn report_error(&self,
|
||||
_input: &mut Parser,
|
||||
_position: SourcePosition,
|
||||
_message: &str,
|
||||
_url: &ServoUrl,
|
||||
_line_number_offset: u64) {
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,7 +37,7 @@ fn test_media_rule<F>(css: &str, callback: F)
|
|||
let media_list = Arc::new(lock.wrap(MediaList::empty()));
|
||||
let stylesheet = Stylesheet::from_str(
|
||||
css, url, Origin::Author, media_list, lock,
|
||||
None, &CSSErrorReporterTest);
|
||||
None, &CSSErrorReporterTest, 0u64);
|
||||
let mut rule_count = 0;
|
||||
let guard = stylesheet.shared_lock.read();
|
||||
media_queries(&guard, &stylesheet.rules.read_with(&guard).0, &mut |mq| {
|
||||
|
@ -62,7 +66,7 @@ fn media_query_test(device: &Device, css: &str, expected_rule_count: usize) {
|
|||
let media_list = Arc::new(lock.wrap(MediaList::empty()));
|
||||
let ss = Stylesheet::from_str(
|
||||
css, url, Origin::Author, media_list, lock,
|
||||
None, &CSSErrorReporterTest);
|
||||
None, &CSSErrorReporterTest, 0u64);
|
||||
let mut rule_count = 0;
|
||||
ss.effective_style_rules(device, &ss.shared_lock.read(), |_| rule_count += 1);
|
||||
assert!(rule_count == expected_rule_count, css.to_owned());
|
||||
|
|
|
@ -16,9 +16,15 @@ use test::{self, Bencher};
|
|||
|
||||
struct ErrorringErrorReporter;
|
||||
impl ParseErrorReporter for ErrorringErrorReporter {
|
||||
fn report_error(&self, _input: &mut Parser, position: SourcePosition, message: &str,
|
||||
url: &ServoUrl) {
|
||||
panic!("CSS error: {}\t\n{:?} {}", url.as_str(), position, message);
|
||||
fn report_error(&self,
|
||||
input: &mut Parser,
|
||||
position: SourcePosition,
|
||||
message: &str,
|
||||
url: &ServoUrl,
|
||||
line_number_offset: u64) {
|
||||
let location = input.source_location(position);
|
||||
let line_offset = location.line + line_number_offset as usize;
|
||||
panic!("CSS error: {}\t\n{}:{} {}", url.as_str(), line_offset, location.column, message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,7 +57,8 @@ fn parse_rules(css: &str) -> Vec<(StyleSource, CascadeLevel)> {
|
|||
media,
|
||||
lock,
|
||||
None,
|
||||
&ErrorringErrorReporter);
|
||||
&ErrorringErrorReporter,
|
||||
0u64);
|
||||
let guard = s.shared_lock.read();
|
||||
let rules = s.rules.read_with(&guard);
|
||||
rules.0.iter().filter_map(|rule| {
|
||||
|
|
|
@ -65,7 +65,7 @@ fn test_parse_stylesheet() {
|
|||
let lock = SharedRwLock::new();
|
||||
let media = Arc::new(lock.wrap(MediaList::empty()));
|
||||
let stylesheet = Stylesheet::from_str(css, url.clone(), Origin::UserAgent, media, lock,
|
||||
None, &CSSErrorReporterTest);
|
||||
None, &CSSErrorReporterTest, 0u64);
|
||||
let mut namespaces = Namespaces::default();
|
||||
namespaces.default = Some(ns!(html));
|
||||
let expected = Stylesheet {
|
||||
|
@ -293,16 +293,17 @@ impl ParseErrorReporter for CSSInvalidErrorReporterTest {
|
|||
input: &mut CssParser,
|
||||
position: SourcePosition,
|
||||
message: &str,
|
||||
url: &ServoUrl) {
|
||||
url: &ServoUrl,
|
||||
line_number_offset: u64) {
|
||||
|
||||
let location = input.source_location(position);
|
||||
let line_offset = location.line + line_number_offset as usize;
|
||||
|
||||
let mut errors = self.errors.lock().unwrap();
|
||||
|
||||
errors.push(
|
||||
CSSError{
|
||||
url: url.clone(),
|
||||
line: location.line,
|
||||
line: line_offset,
|
||||
column: location.column,
|
||||
message: message.to_owned()
|
||||
}
|
||||
|
@ -328,18 +329,18 @@ fn test_report_error_stylesheet() {
|
|||
let lock = SharedRwLock::new();
|
||||
let media = Arc::new(lock.wrap(MediaList::empty()));
|
||||
Stylesheet::from_str(css, url.clone(), Origin::UserAgent, media, lock,
|
||||
None, &error_reporter);
|
||||
None, &error_reporter, 5u64);
|
||||
|
||||
let mut errors = errors.lock().unwrap();
|
||||
|
||||
let error = errors.pop().unwrap();
|
||||
assert_eq!("Unsupported property declaration: 'invalid: true;'", error.message);
|
||||
assert_eq!(5, error.line);
|
||||
assert_eq!(10, error.line);
|
||||
assert_eq!(9, error.column);
|
||||
|
||||
let error = errors.pop().unwrap();
|
||||
assert_eq!("Unsupported property declaration: 'display: invalid;'", error.message);
|
||||
assert_eq!(4, error.line);
|
||||
assert_eq!(9, error.line);
|
||||
assert_eq!(9, error.column);
|
||||
|
||||
// testing for the url
|
||||
|
|
|
@ -31,7 +31,8 @@ macro_rules! stylesheet {
|
|||
Arc::new($shared_lock.wrap(MediaList::empty())),
|
||||
$shared_lock,
|
||||
None,
|
||||
&$error_reporter
|
||||
&$error_reporter,
|
||||
0u64
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue