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

Parser data #232

Merged
merged 14 commits into from
Nov 8, 2023
8 changes: 6 additions & 2 deletions benches/tree_construction.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
use criterion::{criterion_group, criterion_main, Criterion};
use gosub_engine::testing::tree_construction;
use gosub_engine::testing::tree_construction::Harness;

fn criterion_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("Tree construction");
group.significance_level(0.1).sample_size(500);

// Careful about reading files inside the closure
let filenames = Some(&["tests1.dat"][..]);
let fixtures = tree_construction::fixtures(filenames).expect("problem loading fixtures");
let fixtures =
tree_construction::fixture::read_fixtures(filenames).expect("problem loading fixtures");

let mut harness = Harness::new();

group.bench_function("fixtures", |b| {
b.iter(|| {
for root in &fixtures {
for test in &root.tests {
for &scripting_enabled in test.script_modes() {
let _ = test.parse(scripting_enabled).unwrap();
let _ = harness.run_test(test.clone(), scripting_enabled);
jaytaph marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
36 changes: 24 additions & 12 deletions src/bin/html5-parser-test.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
use gosub_engine::testing::tree_construction::fixture_from_filename;
use gosub_engine::testing::FIXTURE_ROOT;
use gosub_engine::testing::tree_construction::fixture::{
fixture_root_path, read_fixture_from_path,
};
use gosub_engine::testing::tree_construction::Harness;
use gosub_engine::types::Result;
use std::io::Write;
use std::path::Path;
use std::path::{Path, PathBuf};
use walkdir::WalkDir;

fn main() -> Result<()> {
let mut files = get_files_from_path(format!("{}/tree-construction", FIXTURE_ROOT).as_str());
let mut files = get_files_from_path(fixture_root_path());
files.sort();

let mut total = 0;
let mut failed = 0;

for file in files.iter() {
let fixture = fixture_from_filename(file)?;
// if file != "math.dat" {
// continue;
// }
let fixture = read_fixture_from_path(&fixture_root_path().join(file))?;

print!("Test: ({:3}) {} [", fixture.tests.len(), file);
let _ = std::io::stdout().flush();

let mut harness = Harness::new();

// Run tests
for test in fixture.tests {
let results = test.run().expect("problem running tree construction test");
for result in results {
for test in fixture.tests.iter() {
for &scripting_enabled in test.script_modes() {
let result = harness
.run_test(test.clone(), scripting_enabled)
.expect("problem parsing");

total += 1;
if result.success() {

if result.is_success() {
print!(".");
} else {
print!("X");
Expand All @@ -45,10 +57,10 @@ fn main() -> Result<()> {
Ok(())
}

fn get_files_from_path(root_dir: &str) -> Vec<String> {
fn get_files_from_path(dir: PathBuf) -> Vec<String> {
let mut files = Vec::new();

for entry in WalkDir::new(root_dir)
for entry in WalkDir::new(dir.clone())
.follow_links(true)
.into_iter()
.flatten()
Expand All @@ -58,7 +70,7 @@ fn get_files_from_path(root_dir: &str) -> Vec<String> {
if extension == "dat" {
if let Ok(relative_path) = entry
.path()
.strip_prefix(root_dir)
.strip_prefix(dir.clone())
.map(Path::to_str)
.map(|s| s.unwrap().to_string())
{
Expand Down
Loading
Loading