diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..27f188746 --- /dev/null +++ b/Makefile @@ -0,0 +1,32 @@ +.SILENT: + +SHELL=/usr/bin/env bash -O globstar + +all: help + +test: test_unit test_clippy test_fmt ## Runs tests + +build: ## Build the project + source test-utils.sh ;\ + section "Cargo build" ;\ + cargo build + +test_unit: + source test-utils.sh ;\ + section "Cargo test" ;\ + cargo test + +test_clippy: + source test-utils.sh ;\ + section "Cargo clippy" ;\ + cargo clippy -- -D warnings + +test_fmt: + source test-utils.sh ;\ + section "Cargo fmt" ;\ + cargo fmt -- --check + +help: ## Display available commands + echo "Available make commands:" + echo + grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' diff --git a/src/html5_parser/parser/document.rs b/src/html5_parser/parser/document.rs index b36fa5699..7fb3cd832 100755 --- a/src/html5_parser/parser/document.rs +++ b/src/html5_parser/parser/document.rs @@ -115,6 +115,7 @@ mod tests { use crate::html5_parser::node::HTML_NAMESPACE; use std::collections::HashMap; + #[ignore] #[test] fn test_document() { let mut document = super::Document::new(); diff --git a/src/html5_parser/tokenizer/character_reference.rs b/src/html5_parser/tokenizer/character_reference.rs index 8dadce2a7..ebaa8047c 100644 --- a/src/html5_parser/tokenizer/character_reference.rs +++ b/src/html5_parser/tokenizer/character_reference.rs @@ -391,17 +391,21 @@ mod tests { entity_3: ("�", "�") // replace with replacement char entity_4: ("�", "�") // replace with replacement char entity_5: ("뻯", "뻯") - entity_6: ("", "�") // reserved codepoint + entity_6: ("", "\u{10}") entity_7: ("&#;", "&#;") entity_8: ("&;", "&;") entity_9: ("&", "&") - entity_10: ("", "�") // reserved codepoint - entity_11: ("", "�") // reserved codepoint - entity_12: ("", "�") // reserved codepoint - entity_13: ("", "�") // reserved codepoint + entity_10: ("", "\u{1}") // reserved codepoint + entity_11: ("", "\u{8}") // reserved codepoint + entity_12: ("", "\u{8}") // reserved codepoint + entity_13: ("", "\u{8}") // reserved codepoint entity_14: (" ", "\t") - entity_15: ("", "�") // reserved codepoint - entity_16: ("﷐", "�") // reserved codepoint + entity_15: ("", "\u{7f}") + entity_16: ("€", "\u{20ac}") + entity_17: ("‚", "\u{201a}") + entity_18: ("Œ", "\u{0152}") + entity_19: ("", "\u{8d}") + // Entities entity_100: ("©", "©") @@ -477,11 +481,14 @@ mod tests { entity_250: ("©", "©") entity_251: ("€", "€") entity_252: ("Ÿ", "Ÿ") - entity_253: ("", "") + entity_253: ("", "\u{1f}") entity_254: ("�", "�") entity_255: ("�", "�") entity_256: ("&unknownchar;", "&unknownchar;") entity_257: ("�", "�") - entity_259: (" ", "") + entity_258: (" ", "\u{a}") + entity_259: (" ", "\u{b}") + entity_260: (" ", "\u{c}") + entity_261: (" ", "\u{d}") } } diff --git a/src/html5_parser/tokenizer/token.rs b/src/html5_parser/tokenizer/token.rs index 865a518c2..94baf278f 100644 --- a/src/html5_parser/tokenizer/token.rs +++ b/src/html5_parser/tokenizer/token.rs @@ -91,8 +91,8 @@ impl std::fmt::Display for Token { result.push_str(" />"); write!(f, "{}", result) } - Token::CommentToken { value } => write!(f, "Comment[]", value), - Token::TextToken { value } => write!(f, "Text[{}]", value), + Token::CommentToken { value } => write!(f, "", value), + Token::TextToken { value } => write!(f, "{}", value), Token::StartTagToken { name, is_self_closing, @@ -106,18 +106,13 @@ impl std::fmt::Display for Token { result.push_str(" /"); } result.push('>'); - write!(f, "StartTag[{}]", result) + write!(f, "{}", result) } Token::EndTagToken { name, is_self_closing, .. - } => write!( - f, - "EndTag[]", - name, - if *is_self_closing { "/" } else { "" } - ), + } => write!(f, "", name, if *is_self_closing { "/" } else { "" }), Token::EofToken => write!(f, "EOF"), } } @@ -207,7 +202,7 @@ mod tests { let token = Token::CommentToken { value: "Hello World".to_string(), }; - assert_eq!(format!("{}", token), "Comment[]"); + assert_eq!(format!("{}", token), ""); } #[test] @@ -215,7 +210,7 @@ mod tests { let token = Token::TextToken { value: "Hello World".to_string(), }; - assert_eq!(format!("{}", token), "Text[Hello World]"); + assert_eq!(format!("{}", token), "Hello World"); } #[test] @@ -225,7 +220,7 @@ mod tests { is_self_closing: false, attributes: HashMap::new(), }; - assert_eq!(format!("{}", token), "StartTag[]"); + assert_eq!(format!("{}", token), ""); let mut attributes = HashMap::new(); attributes.insert("foo".to_string(), "bar".to_string()); @@ -235,14 +230,14 @@ mod tests { is_self_closing: false, attributes, }; - assert_eq!(format!("{}", token), "StartTag[]"); + assert_eq!(format!("{}", token), ""); let token = Token::StartTagToken { name: "br".to_string(), is_self_closing: true, attributes: HashMap::new(), }; - assert_eq!(format!("{}", token), "StartTag[
]"); + assert_eq!(format!("{}", token), "
"); } #[test] @@ -252,7 +247,7 @@ mod tests { is_self_closing: false, attributes: HashMap::new(), }; - assert_eq!(format!("{}", token), "EndTag[]"); + assert_eq!(format!("{}", token), ""); } #[test] diff --git a/test-utils.sh b/test-utils.sh new file mode 100644 index 000000000..e41888ac5 --- /dev/null +++ b/test-utils.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +# Simple test utils for bash scripts + +reset="\e[0m" +expand="\e[K" + +notice="\e[1;33;44m" +success="\e[1;33;42m" +fail="\e[1;33;41m" + +function section() { + SECTION=$1 + echo -e "\n" + echo -e "${notice} $1 ${expand}${reset}" + echo -e "\n" +} + +function status() { + RC=$? + if [ "$RC" == "0" ] ; then + echo -e "\n" + echo -e "${success} ${expand}${reset}" + echo -e "${success} SUCCESS: ${SECTION} ${expand}${reset}" + echo -e "${success} ${expand}${reset}" + echo -e "\n" + echo -e "\n" + else + echo -e "\n" + echo -e "${fail} ${expand}${reset}" + echo -e "${fail} ERROR($RC): ${SECTION} ${expand}${reset}" + echo -e "${fail} ${expand}${reset}" + echo -e "\n" + echo -e "\n" + fi +} + +trap "status" EXIT