Repository: jaytaph/gosub-browser
File: src/bin/parser_test.rs (Rust)

Code before:
use std::process::exit;
use std::{env, fs, io};

pub struct TestResults {
    tests: usize,           // Number of tests (as defined in the suite)
    assertions: usize, // Number of assertions (different combinations of input/output per test)
    succeeded: usize,  // How many succeeded assertions
    failed: usize,     // How many failed assertions
    failed_position: usize, // How many failed assertions where position is not correct
}

struct Test {
    file_path: String,              // Filename of the test
    line: usize,                    // Line number of the test
    data: String,                   // input stream
    errors: Vec<Error>,             // errors
    document: Vec<String>,          // document tree
    document_fragment: Vec<String>, // fragment
}

fn main() -> io::Result<()> {
    let default_dir = "./html5lib-tests";
    let dir = env::args().nth(1).unwrap_or(default_dir.to_string());

    if !Path::new(&dir).exists() {
        println!("Missing 'html5lib-tests'. It is no located at '{dir}' \nIt should be cloned first from here https://github.com/html5lib/html5lib-tests");
        exit(1)
    }

    let mut results = TestResults {
        tests: 0,
        assertions: 0,
        succeeded: 0,
        failed: 0,
        failed_position: 0,
    };

    for entry in fs::read_dir(dir + "/tree-construction")? {
        let entry = entry?;
        let path = entry.path();

        if !path.ends_with("tests1.dat") {
            continue;
        }

        if !path.is_file() || path.extension().unwrap() != "dat" {
            continue;
        }

        let tests = read_tests(path.clone())?;
        println!("🏃‍♂️ Running {} tests from 🗄️ {:?}\n", tests.len(), path);

Review comment (suggestion):
Hey there, I noticed a small typo

```suggestion
        println!("Missing 'html5lib-tests'. It is not located at '{dir}' \nIt should be cloned first from here https://github.com/html5lib/html5lib-tests");
```

Code after:
use std::process::exit;
use std::{fs, io};

pub struct TestResults {
    tests: usize,           // Number of tests (as defined in the suite)
    assertions: usize, // Number of assertions (different combinations of input/output per test)
    succeeded: usize,  // How many succeeded assertions
    failed: usize,     // How many failed assertions
    failed_position: usize, // How many failed assertions where position is not correct
}

struct Test {
    file_path: String,              // Filename of the test
    line: usize,                    // Line number of the test
    data: String,                   // input stream
    errors: Vec<Error>,             // errors
    document: Vec<String>,          // document tree
    document_fragment: Vec<String>, // fragment
}

fn main() -> io::Result<()> {
    let default_dir = "tests/data/html5lib-tests".to_string();

    if !Path::new(&default_dir).exists() {
        println!("Missing 'html5lib-tests'. It is not located at '{default_dir}' \nIt should be cloned first from here https://github.com/html5lib/html5lib-tests");
        exit(1)
    }

    let mut results = TestResults {
        tests: 0,
        assertions: 0,
        succeeded: 0,
        failed: 0,
        failed_position: 0,
    };

    for entry in fs::read_dir(default_dir + "/tree-construction")? {
        let entry = entry?;
        let path = entry.path();

        if !path.ends_with("tests1.dat") {
            continue;
        }

        if !path.is_file() || path.extension().unwrap() != "dat" {
            continue;
        }

        let tests = read_tests(path.clone())?;
        println!("🏃‍♂️ Running {} tests from 🗄️ {:?}\n", tests.len(), path);