html5ever_test_util/
lib.rs

1// Copyright 2014 The html5ever Project Developers. See the
2// COPYRIGHT file at the top-level directory of this distribution.
3//
4// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7// option. This file may not be copied, modified, or distributed
8// except according to those terms.
9
10use std::fs;
11use std::ffi::OsStr;
12use std::path::Path;
13use std::ops::FnMut;
14
15pub fn foreach_html5lib_test<Mk>(
16        src_dir: &Path,
17        subdir: &'static str,
18        ext: &'static OsStr,
19        mut mk: Mk)
20    where Mk: FnMut(&Path, fs::File)
21{
22    let mut test_dir_path = src_dir.to_path_buf();
23    test_dir_path.push("html5lib-tests");
24    test_dir_path.push(subdir);
25
26    let test_files = fs::read_dir(&test_dir_path).unwrap();
27    for entry in test_files {
28        let path = entry.unwrap().path();
29        if path.extension() == Some(ext) {
30            let file = fs::File::open(&path).unwrap();
31            mk(&path, file);
32        }
33    }
34}