diff options
author | Martin Fischer <martin@push-f.com> | 2023-08-18 16:54:43 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2023-08-19 13:41:55 +0200 |
commit | 4682f104ea24fc257c22dc12db1a3dad1323662a (patch) | |
tree | 8815652555207038cc0837f25b9ef35068bbc16a /tests/misc.rs | |
parent | 0c495ba984436cccc6caeed66639a2b61095dbad (diff) |
docs: link multipage version of HTML spec
Diffstat (limited to 'tests/misc.rs')
-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. +} |