aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2023-08-15 09:11:18 +0200
committerMartin Fischer <martin@push-f.com>2023-08-19 06:41:55 +0200
commitd5a3bc85197e74ccd4fd2bc01ee1fe16a78ec604 (patch)
treec207d6749a78f933bea8deff2780757ac624bd30
parent8bc84de0213d60e810620a97449f83dc1bc9f13e (diff)
refactor: separate test logic from html5lib-test parsing
-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,