Skip to content

Commit

Permalink
Moved testing code to gosub_html5 crate
Browse files Browse the repository at this point in the history
  • Loading branch information
jaytaph committed Dec 19, 2024
1 parent b7068d6 commit e526020
Show file tree
Hide file tree
Showing 20 changed files with 35 additions and 66 deletions.
23 changes: 6 additions & 17 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ gosub_config = { path = "./crates/gosub_config", features = [] }
gosub_html5 = { path = "./crates/gosub_html5", features = [] }
gosub_css3 = { path = "./crates/gosub_css3", features = [] }
gosub_jsapi = { path = "./crates/gosub_jsapi", features = [] }
gosub_testing = { path = "./crates/gosub_testing", features = [] }
gosub_rendering = { path = "crates/gosub_render_utils", features = [] }
gosub_renderer = { path = "./crates/gosub_renderer", features = [] }
gosub_vello = { path = "./crates/gosub_vello", features = [] }
Expand Down
8 changes: 7 additions & 1 deletion crates/gosub_html5/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@ lazy_static = "1.5"
thiserror = "2.0.7"
url = { version = "2.5.4", features = [] }
log = { version = "0.4.22", features = [] }
nom = "7.1.3"
nom_locate = "4.2.0"
regex = "1"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["preserve_order"] }
serde_derive = "1.0"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
ureq = "2.12.1"

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


[features]
debug_parser = []
debug_parser_verbose = []
Expand Down
2 changes: 1 addition & 1 deletion crates/gosub_html5/benches/tokenizer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use criterion::{criterion_group, criterion_main, Criterion};
use gosub_testing::testing::tokenizer::{self, FixtureFile};
use gosub_html5::testing::tokenizer::{self, FixtureFile};

fn criterion_benchmark(c: &mut Criterion) {
// Criterion can report inconsistent results from run to run in some cases. We attempt to
Expand Down
4 changes: 2 additions & 2 deletions crates/gosub_html5/benches/tree_construction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use gosub_html5::document::document_impl::DocumentImpl;
use gosub_html5::document::fragment::DocumentFragmentImpl;
use gosub_html5::parser::Html5Parser;
use gosub_shared::traits::config::{HasCssSystem, HasDocument, HasHtmlParser};
use gosub_testing::testing::tree_construction;
use gosub_testing::testing::tree_construction::Harness;
use gosub_html5::testing::tree_construction;
use gosub_html5::testing::tree_construction::Harness;

#[derive(Clone, Debug, PartialEq)]
struct Config;
Expand Down
1 change: 1 addition & 0 deletions crates/gosub_html5/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub mod parser;
pub mod tokenizer;
#[allow(dead_code)]
pub mod writer;
pub mod testing;

/// Parses the given HTML string and returns a handle to the resulting DOM tree.
pub fn html_compile<C: HasDocument>(html: &str) -> DocumentHandle<C> {
Expand Down
5 changes: 3 additions & 2 deletions crates/gosub_html5/src/parser/tree_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ mod tests {
use crate::document::document_impl::DocumentImpl;
use crate::document::fragment::DocumentFragmentImpl;
use crate::parser::Html5Parser;
use crate::testing::tree_construction::fixture::{fixture_root_path, read_fixture_from_path};
use crate::testing::tree_construction::Harness;
use gosub_css3::system::Css3System;
use gosub_shared::traits::config::{HasCssSystem, HasDocument, HasHtmlParser};
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;

#[derive(Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -119,6 +119,7 @@ mod tests {
#[test_case("webkit01.dat")]
#[test_case("webkit02.dat")]
fn tree_construction(filename: &str) {
dbg!(fixture_root_path().join(filename));
let fixture_file = read_fixture_from_path(fixture_root_path().join(filename)).expect("fixture");
let mut harness = Harness::new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
pub mod tokenizer;
pub mod tree_construction;

pub const FIXTURE_ROOT: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../gosub_html5/tests/data/html5lib-tests",);
pub const FIXTURE_ROOT: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/./tests/data/html5lib-tests",);
pub const TREE_CONSTRUCTION_PATH: &str = "tree-construction";
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::FIXTURE_ROOT;
use gosub_html5::parser::errors::ErrorLogger;
use gosub_html5::tokenizer::ParserData;
use gosub_html5::tokenizer::{
use crate::parser::errors::ErrorLogger;
use crate::tokenizer::ParserData;
use crate::tokenizer::{
state::State as TokenState,
token::Token,
{Options, Tokenizer},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pub mod fixture;
mod generator;
pub(crate) mod parser;
pub mod parser;
pub mod result;

use generator::TreeOutputGenerator;
use gosub_html5::node::{HTML_NAMESPACE, MATHML_NAMESPACE, SVG_NAMESPACE};
use crate::node::{HTML_NAMESPACE, MATHML_NAMESPACE, SVG_NAMESPACE};
use gosub_shared::byte_stream::{ByteStream, Config, Encoding, Location};
use gosub_shared::document::DocumentHandle;
use gosub_shared::node::NodeId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use gosub_html5::node::HTML_NAMESPACE;
use gosub_html5::node::{MATHML_NAMESPACE, SVG_NAMESPACE, XLINK_NAMESPACE, XMLNS_NAMESPACE};
use crate::node::HTML_NAMESPACE;
use crate::node::{MATHML_NAMESPACE, SVG_NAMESPACE, XLINK_NAMESPACE, XMLNS_NAMESPACE};
use gosub_shared::document::DocumentHandle;
use gosub_shared::traits::config::HasDocument;
use gosub_shared::traits::document::Document;
Expand Down
2 changes: 1 addition & 1 deletion crates/gosub_html5/src/tokenizer/test_cases.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use gosub_testing::testing::tokenizer::{self, FixtureFile};
use crate::testing::tokenizer::{self, FixtureFile};
use lazy_static::lazy_static;
use std::collections::HashSet;
use test_case::test_case;
Expand Down
17 changes: 0 additions & 17 deletions crates/gosub_testing/Cargo.toml

This file was deleted.

6 changes: 0 additions & 6 deletions crates/gosub_testing/src/lib.rs

This file was deleted.

4 changes: 0 additions & 4 deletions docs/crates.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ The engine is split up in a few different crates. This is done to keep the codeb
* gosub_shared
* gosub_svg
* gosub_taffy
* gosub_testing
* gosub_typeface
* gosub_useragent
* gosub_v8
Expand Down Expand Up @@ -53,9 +52,6 @@ Implementation of the SVG Document for `usvg` and optionally the `resvg` crates,
## gosub_taffy
Implementation of layout traits for the `taffy` layouting system.

## gosub_testing
A dedicated crate for testing some of the engine. This will allow to easily test the different parts of the engine, most notably the html5 tokenizer and parser.

## gosub_typeface
Currently doesn't do much, but it is used to store fallback fonts and the `Font` trait

Expand Down
4 changes: 2 additions & 2 deletions src/bin/html5-parser-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use gosub_html5::document::fragment::DocumentFragmentImpl;
use gosub_html5::parser::Html5Parser;
use gosub_shared::traits::config::{HasCssSystem, HasDocument, HasHtmlParser};
use gosub_shared::types::Result;
use gosub_testing::testing::tree_construction::fixture::{fixture_root_path, read_fixture_from_path};
use gosub_testing::testing::tree_construction::Harness;
use gosub_html5::testing::tree_construction::fixture::{fixture_root_path, read_fixture_from_path};
use gosub_html5::testing::tree_construction::Harness;
use std::io::Write;
use std::path::{Path, PathBuf};
use walkdir::WalkDir;
Expand Down
8 changes: 4 additions & 4 deletions src/bin/parser-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use gosub_html5::document::document_impl::DocumentImpl;
use gosub_html5::document::fragment::DocumentFragmentImpl;
use gosub_html5::parser::Html5Parser;
use gosub_shared::traits::config::{HasCssSystem, HasDocument, HasHtmlParser};
use gosub_testing::testing::tree_construction::fixture::read_fixtures;
use gosub_testing::testing::tree_construction::result::ResultStatus;
use gosub_testing::testing::tree_construction::Harness;
use gosub_testing::testing::tree_construction::Test;
use gosub_html5::testing::tree_construction::fixture::read_fixtures;
use gosub_html5::testing::tree_construction::result::ResultStatus;
use gosub_html5::testing::tree_construction::Harness;
use gosub_html5::testing::tree_construction::Test;

/// Holds the results from all tests that are executed
#[derive(Default)]
Expand Down

0 comments on commit e526020

Please sign in to comment.