Skip to content

Commit

Permalink
Merge pull request #12 from jaytaph/ci-fixes
Browse files Browse the repository at this point in the history
Fixed a few CI issues
  • Loading branch information
jaytaph authored Sep 23, 2023
2 parents 17d2e41 + ccb37c5 commit 9729c9c
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 30 deletions.
10 changes: 5 additions & 5 deletions src/bin/parser_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ fn read_tests(file_path: PathBuf) -> io::Result<Vec<Test>> {
};
let mut section: Option<&str> = None;

let mut line_num: usize = 0;
for line in reader.lines() {
line_num += 1;

let line = line?;
for (line_num, line) in reader.lines().enumerate() {
if line.is_err() {
continue;
}
let line = line.unwrap();

if line.starts_with("#data") {
if !current_test.data.is_empty()
Expand Down
4 changes: 3 additions & 1 deletion src/bin/tokenizer_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ fn match_error(tokenizer: &Tokenizer, expected_err: &Error) -> ErrorResult {
// it's not always correct, it might be a off-by-one position.
let mut result = ErrorResult::Failure;
for got_err in tokenizer.get_error_logger().get_errors() {
if got_err.message == expected_err.code && (got_err.line as i64 != expected_err.line || got_err.col as i64 != expected_err.col) {
if got_err.message == expected_err.code
&& (got_err.line as i64 != expected_err.line || got_err.col as i64 != expected_err.col)
{
// println!("❌ Expected error '{}' at {}:{}", expected_err.code, expected_err.line, expected_err.col);
result = ErrorResult::PositionFailure;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/html5_parser/input_stream.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::html5_parser::tokenizer::{CHAR_CR, CHAR_LF};
use std::fs::File;
use std::{fmt, io};
use std::io::Read;
use std::{fmt, io};

// Encoding defines the way the buffer stream is read, as what defines a "character".
#[derive(PartialEq)]
Expand Down
12 changes: 9 additions & 3 deletions src/html5_parser/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,19 @@ impl Node {

// Returns true if the given node is "special" node based on the namespace and name
pub fn is_special(&self) -> bool {
if self.namespace == Some(HTML_NAMESPACE.into()) && SPECIAL_HTML_ELEMENTS.contains(&self.name.as_str()) {
if self.namespace == Some(HTML_NAMESPACE.into())
&& SPECIAL_HTML_ELEMENTS.contains(&self.name.as_str())
{
return true;
}
if self.namespace == Some(MATHML_NAMESPACE.into()) && SPECIAL_MATHML_ELEMENTS.contains(&self.name.as_str()) {
if self.namespace == Some(MATHML_NAMESPACE.into())
&& SPECIAL_MATHML_ELEMENTS.contains(&self.name.as_str())
{
return true;
}
if self.namespace == Some(SVG_NAMESPACE.into()) && SPECIAL_SVG_ELEMENTS.contains(&self.name.as_str()) {
if self.namespace == Some(SVG_NAMESPACE.into())
&& SPECIAL_SVG_ELEMENTS.contains(&self.name.as_str())
{
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion src/html5_parser/parser/adoption_agency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ impl<'a> Html5Parser<'a> {
ref name,
ref attributes,
..
} = temp_node.data {
} = temp_node.data
{
if name == subject && !attributes.is_empty() {
formatting_element_idx = idx;
formatting_element_id = node_id;
Expand Down
16 changes: 4 additions & 12 deletions src/html5_parser/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1625,18 +1625,10 @@ impl<'a> Html5Parser<'a> {
}
Token::StartTagToken {
name, attributes, ..
} => {
Node::new_element(name, attributes.clone(), namespace)
}
Token::EndTagToken { name, .. } => {
Node::new_element(name, HashMap::new(), namespace)
}
Token::CommentToken { value } => {
Node::new_comment(value)
}
Token::TextToken { value } => {
Node::new_text(value.to_string().as_str())
}
} => Node::new_element(name, attributes.clone(), namespace),
Token::EndTagToken { name, .. } => Node::new_element(name, HashMap::new(), namespace),
Token::CommentToken { value } => Node::new_comment(value),
Token::TextToken { value } => Node::new_text(value.to_string().as_str()),
Token::EofToken => {
panic!("EOF token not allowed");
}
Expand Down
12 changes: 8 additions & 4 deletions src/html5_parser/parser/quirks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ impl<'a> Html5Parser<'a> {
return QuirksMode::Quirks;
}

if sys_identifier.is_none() && QUIRKS_PUB_IDENTIFIER_PREFIX_MISSING_SYS
if sys_identifier.is_none()
&& QUIRKS_PUB_IDENTIFIER_PREFIX_MISSING_SYS
.iter()
.any(|&prefix| pub_id.as_str().starts_with(prefix)) {
.any(|&prefix| pub_id.as_str().starts_with(prefix))
{
return QuirksMode::Quirks;
}

Expand All @@ -45,9 +47,11 @@ impl<'a> Html5Parser<'a> {
return QuirksMode::LimitedQuirks;
}

if sys_identifier.is_some() && LIMITED_QUIRKS_PUB_IDENTIFIER_PREFIX
if sys_identifier.is_some()
&& LIMITED_QUIRKS_PUB_IDENTIFIER_PREFIX
.iter()
.any(|&prefix| pub_id.as_str().starts_with(prefix)) {
.any(|&prefix| pub_id.as_str().starts_with(prefix))
{
return QuirksMode::LimitedQuirks;
}
}
Expand Down
13 changes: 10 additions & 3 deletions src/html5_parser/tokenizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ macro_rules! set_public_identifier {
macro_rules! add_public_identifier {
($self:expr, $c:expr) => {
match &mut $self.current_token {
Some(Token::DocTypeToken { pub_identifier: Some(pid), .. }) => {
Some(Token::DocTypeToken {
pub_identifier: Some(pid),
..
}) => {
pid.push($c);
}
_ => {}
Expand All @@ -113,7 +116,10 @@ macro_rules! set_system_identifier {
macro_rules! add_system_identifier {
($self:expr, $c:expr) => {
match &mut $self.current_token {
Some(Token::DocTypeToken { sys_identifier: Some(sid), .. }) => {
Some(Token::DocTypeToken {
sys_identifier: Some(sid),
..
}) => {
sid.push($c);
}
_ => {}
Expand Down Expand Up @@ -2291,7 +2297,8 @@ impl<'a> Tokenizer<'a> {

// Set force_quirk mode in current token
fn set_quirks_mode(&mut self, quirky: bool) {
if let Token::DocTypeToken { force_quirks, .. } = &mut self.current_token.as_mut().unwrap() {
if let Token::DocTypeToken { force_quirks, .. } = &mut self.current_token.as_mut().unwrap()
{
*force_quirks = quirky;
}
}
Expand Down

0 comments on commit 9729c9c

Please sign in to comment.