Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved tokenizer.rs and tree_construction.rs tests into crates for issue #445 #457

Merged
merged 14 commits into from
May 27, 2024
Merged
98 changes: 98 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,101 @@ 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;
Comment on lines +34 to +35
Copy link
Contributor

@MoralCode MoralCode May 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to not like these imports for some reason when i run make test locally. Where is the test_case macro being defined?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an external crate. Basically just run

cargo add test_case --dev -p gosub_html5

It also seems like fmt and clippy aren't happy, it can be fixed via make format

I haven't looked really into what is wrong, again I'll do that tomorrow.


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.
94 changes: 0 additions & 94 deletions tests/tree_construction.rs

This file was deleted.

Loading