Skip to content

Commit

Permalink
Moved tokenizer.rs and tree_construction.rs tests into crates for issue
Browse files Browse the repository at this point in the history
#445 (#457)

* Moved tokenizer.rs from tests to crates

Moved tokenizer.rs from tests to its crate. Also added the #[cfg(test)] and mod declaration as requested.

* Deleted tokenizer.rs from tests folder.

It was copied into its crate.

* Copied tree_construction.rs from tests into a crate.

Copied tree_construction.rs from tests into its specific crate. I also put it in the module as requested.

* Deleted tree_construction.rs from the test folder

Deleted tree_construction.rs from the test folder as it was copied over to a crate

* Update and rename test.rs to tests.rs

Removes the #[cfg(test)] from the file and removed extra indentation. Also renamed it to tests.rs as asked.

* Update tokenizer.rs

* Delete tests/lib.rs

* Update Cargo.toml

Deleted the [[test]] lines.

* cargo add test_case --dev -p gosub_html5

* make format

* import gosub testing in html5 crate

* move testing data

* apply diff from PR to fix final changes

* remove benchmarks that the other patch didnt get

---------

Co-authored-by: Adrian Edwards <[email protected]>
  • Loading branch information
kaigidwani and MoralCode authored May 27, 2024
1 parent 5cb2bf7 commit f218de8
Show file tree
Hide file tree
Showing 118 changed files with 117 additions and 115 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 0 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,6 @@ members = [
[[example]]
name = "html5-parser"

[[test]]
name = "tokenizer"
path = "tests/tokenizer.rs"

[[test]]
name = "tree_construction"
path = "tests/tree_construction.rs"

[[bench]]
name = "tokenizer"
harness = false

[[bench]]
name = "tree_construction"
harness = false

[[bench]]
name = "tree_iterator"
harness = false
Expand Down
13 changes: 13 additions & 0 deletions crates/gosub_html5/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,16 @@ log = { version = "0.4.21", features = [] }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
ureq = "2.9.7"

[dev-dependencies]
gosub_testing = { path = "../gosub_testing" }
test-case = "3.3.1"
criterion = { version = "0.5.1", features = ["html_reports"] }


[[bench]]
name = "tokenizer"
harness = false

[[bench]]
name = "tree_construction"
harness = false
File renamed without changes.
File renamed without changes.
99 changes: 99 additions & 0 deletions crates/gosub_html5/src/parser/tree_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,102 @@ pub trait TreeBuilder {
/// Insert/update an attribute for an element node.
fn insert_attribute(&mut self, key: &str, value: &str, element_id: NodeId) -> Result<()>;
}

#[cfg(test)]
mod tests {
use gosub_testing::testing::tree_construction::fixture::{
fixture_root_path, read_fixture_from_path,
};
use gosub_testing::testing::tree_construction::Harness;
use test_case::test_case;

const DISABLED_CASES: &[&str] = &[
// tests18.dat
"<!doctype html><template><plaintext>a</template>b",
];

// See tests/data/html5lib-tests/tree-construction/ for other test files.
#[test_case("tests1.dat")]
#[test_case("tests2.dat")]
#[test_case("tests3.dat")]
#[test_case("tests4.dat")]
#[test_case("tests5.dat")]
#[test_case("tests6.dat")]
#[test_case("tests7.dat")]
#[test_case("tests8.dat")]
#[test_case("tests9.dat")]
#[test_case("tests10.dat")]
#[test_case("tests11.dat")]
#[test_case("tests12.dat")]
#[test_case("tests14.dat")]
#[test_case("tests15.dat")]
#[test_case("tests16.dat")]
#[test_case("tests17.dat")]
#[test_case("tests18.dat")]
#[test_case("tests19.dat")]
#[test_case("tests20.dat")]
#[test_case("tests21.dat")]
#[test_case("tests22.dat")]
#[test_case("tests23.dat")]
#[test_case("tests24.dat")]
#[test_case("tests25.dat")]
#[test_case("tests26.dat")]
#[test_case("adoption01.dat")]
#[test_case("adoption02.dat")]
#[test_case("blocks.dat")]
#[test_case("comments01.dat")]
#[test_case("doctype01.dat")]
#[test_case("domjs-unsafe.dat")]
#[test_case("entities01.dat")]
#[test_case("entities02.dat")]
#[test_case("foreign-fragment.dat")]
#[test_case("html5test-com.dat")]
#[test_case("inbody01.dat")]
#[test_case("isindex.dat")]
#[test_case("main-element.dat")]
#[test_case("math.dat")]
#[test_case("menuitem-element.dat")]
#[test_case("namespace-sensitivity.dat")]
#[test_case("noscript01.dat")]
#[test_case("pending-spec-changes.dat")]
#[test_case("pending-spec-changes-plain-text-unsafe.dat")]
#[test_case("plain-text-unsafe.dat")]
#[test_case("quirks01.dat")]
#[test_case("ruby.dat")]
#[test_case("scriptdata01.dat")]
#[test_case("search-element.dat")]
#[test_case("svg.dat")]
#[test_case("tables01.dat")]
#[test_case("template.dat")]
#[test_case("tests_innerHTML_1.dat")]
#[test_case("tricky01.dat")]
#[test_case("webkit01.dat")]
#[test_case("webkit02.dat")]
fn tree_construction(filename: &str) {
let fixture_file =
read_fixture_from_path(fixture_root_path().join(filename)).expect("fixture");
let mut harness = Harness::new();

for test in fixture_file.tests {
// skip disabled tests
if DISABLED_CASES.contains(&test.document_as_str()) {
continue;
}

// for each test, run it with and without scripting enabled based on the test file
for &scripting_enabled in test.script_modes() {
let result = harness
.run_test(test.clone(), scripting_enabled)
.expect("problem parsing");

println!(
"tree construction: {}:{} {}",
test.file_path,
test.line,
test.document_as_str()
);
assert!(result.is_success());
}
}
}
}
3 changes: 3 additions & 0 deletions crates/gosub_html5/src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ pub mod token;
mod character_reference;
mod replacement_tables;

#[cfg(test)]
mod tests;

use crate::error_logger::{ErrorLogger, ParserError};
use crate::errors::Error;
use crate::node::HTML_NAMESPACE;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 0 additions & 5 deletions tests/lib.rs

This file was deleted.

94 changes: 0 additions & 94 deletions tests/tree_construction.rs

This file was deleted.

0 comments on commit f218de8

Please sign in to comment.