diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/misc.rs | 47 | 
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/misc.rs b/tests/misc.rs new file mode 100644 index 0000000..416e506 --- /dev/null +++ b/tests/misc.rs @@ -0,0 +1,47 @@ +use similar_asserts::assert_eq; +use walkdir::{DirEntry, WalkDir}; + +#[test] +fn links_to_html_spec_use_multipage_version() { +    for entry in WalkDir::new(".") +        .min_depth(1) +        .into_iter() +        .filter_entry(is_source_file) +        .flatten() +    { +        if !entry.file_type().is_file() { +            continue; +        } + +        let actual = match std::fs::read_to_string(entry.path()) { +            Ok(content) => content, +            Err(err) => panic!("invalid UTF-8 in file content: {:?}: {}", entry.path(), err), +        }; + +        let expected = actual.replace( +            concat!("://html.spec.whatwg.org/", "#"), +            concat!("://html.spec.whatwg.org/multipage/???.html#"), +        ); + +        assert_eq!( +            actual, +            expected, +            "Found a link to the one-page version of the HTML spec, which is huge and takes long to load. We want to link the multipage version instead." +        ); +    } +} + +fn is_source_file(entry: &DirEntry) -> bool { +    let Some(filename) = entry.file_name().to_str() else { +        panic!("invalid UTF-8 in filename: {:?}", entry.path()) +    }; + +    if entry.depth() == 1 && filename == "target" || filename == "Cargo.lock" { +        return false; // cargo files +    } +    if filename == "html5lib-tests" { +        return false; // git submodule +    } + +    !filename.starts_with('.') // .git, etc. +}  | 
