Skip to content

Commit

Permalink
Merge pull request #21 from jaytaph/test-fixes
Browse files Browse the repository at this point in the history
Fixed tests so they run correctly now
  • Loading branch information
jaytaph authored Sep 24, 2023
2 parents bff2c38 + ce9ed88 commit 49c3d7c
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 24 deletions.
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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}'
1 change: 1 addition & 0 deletions src/html5_parser/parser/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
25 changes: 16 additions & 9 deletions src/html5_parser/tokenizer/character_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: ("©", "©")
Expand Down Expand Up @@ -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}")
}
}
25 changes: 10 additions & 15 deletions src/html5_parser/tokenizer/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"),
}
}
Expand Down Expand Up @@ -207,15 +202,15 @@ mod tests {
let token = Token::CommentToken {
value: "Hello World".to_string(),
};
assert_eq!(format!("{}", token), "Comment[<!-- Hello World -->]");
assert_eq!(format!("{}", token), "<!-- Hello World -->");
}

#[test]
fn test_token_display_text() {
let token = Token::TextToken {
value: "Hello World".to_string(),
};
assert_eq!(format!("{}", token), "Text[Hello World]");
assert_eq!(format!("{}", token), "Hello World");
}

#[test]
Expand All @@ -225,7 +220,7 @@ mod tests {
is_self_closing: false,
attributes: HashMap::new(),
};
assert_eq!(format!("{}", token), "StartTag[<html>]");
assert_eq!(format!("{}", token), "<html>");

let mut attributes = HashMap::new();
attributes.insert("foo".to_string(), "bar".to_string());
Expand All @@ -235,14 +230,14 @@ mod tests {
is_self_closing: false,
attributes,
};
assert_eq!(format!("{}", token), "StartTag[<html foo=\"bar\">]");
assert_eq!(format!("{}", token), "<html foo=\"bar\">");

let token = Token::StartTagToken {
name: "br".to_string(),
is_self_closing: true,
attributes: HashMap::new(),
};
assert_eq!(format!("{}", token), "StartTag[<br />]");
assert_eq!(format!("{}", token), "<br />");
}

#[test]
Expand All @@ -252,7 +247,7 @@ mod tests {
is_self_closing: false,
attributes: HashMap::new(),
};
assert_eq!(format!("{}", token), "EndTag[</html>]");
assert_eq!(format!("{}", token), "</html>");
}

#[test]
Expand Down
38 changes: 38 additions & 0 deletions test-utils.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 49c3d7c

Please sign in to comment.