aboutsummaryrefslogtreecommitdiff
path: root/tests/misc.rs
blob: 416e506e2b00b722c79a6edbcae6a342fdacbf82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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.
}