summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--integration_tests/tests/test_html5lib.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/integration_tests/tests/test_html5lib.rs b/integration_tests/tests/test_html5lib.rs
index 32dccd4..61e2133 100644
--- a/integration_tests/tests/test_html5lib.rs
+++ b/integration_tests/tests/test_html5lib.rs
@@ -5,6 +5,13 @@ use pretty_assertions::assert_eq;
use serde::{de::Error as _, Deserialize};
use std::{collections::BTreeMap, fs::File, io::BufReader, path::Path};
+fn parse_tests(
+ reader: impl std::io::Read,
+) -> Result<impl Iterator<Item = Test>, serde_json::Error> {
+ let Tests { tests } = serde_json::from_reader(reader)?;
+ Ok(tests.into_iter().map(undo_double_escaping))
+}
+
struct ExpectedOutputTokens(Vec<Token<()>>);
impl<'de> Deserialize<'de> for ExpectedOutputTokens {
@@ -250,14 +257,14 @@ fn test_tokenizer_file(path: &Path) {
let f = File::open(path).unwrap();
let bf = BufReader::new(f);
- let tests: Tests = serde_json::from_reader(bf).unwrap();
+ let tests = parse_tests(bf).expect(&format!("failed to parse {path:?}"));
- for (i, test) in tests.tests.into_iter().enumerate() {
+ for (i, test) in tests.into_iter().enumerate() {
run_test(fname, i, test);
}
}
-fn run_test(fname: &str, test_i: usize, mut test: Test) {
+fn undo_double_escaping(mut test: Test) -> Test {
test.input = if test.double_escaped {
unescape(&test.input)
} else {
@@ -279,7 +286,10 @@ fn run_test(fname: &str, test_i: usize, mut test: Test) {
} else {
ExpectedOutputTokens(test.output.0)
};
+ test
+}
+fn run_test(fname: &str, test_i: usize, test: Test) {
for state in &test.initial_states {
run_test_inner(
fname,