Skip to content

Commit

Permalink
Merge pull request #51 from toml-rs/update
Browse files Browse the repository at this point in the history
fix(data): Update toml-test
  • Loading branch information
epage authored Oct 2, 2023
2 parents 0963d81 + 37bf0eb commit aa38160
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/data/assets/toml-test
10 changes: 10 additions & 0 deletions crates/data/examples/dump.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn main() {
let versions = toml_test_data::versions();
println!("{versions:#?}");

let valid = toml_test_data::valid().collect::<Vec<_>>();
println!("{valid:#?}");

let invalid = toml_test_data::invalid().collect::<Vec<_>>();
println!("{invalid:#?}");
}
25 changes: 25 additions & 0 deletions crates/data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,31 @@
const TESTS_DIR: include_dir::Dir =
include_dir::include_dir!("$CARGO_MANIFEST_DIR/assets/toml-test/tests");

pub fn version(ver: &str) -> impl Iterator<Item = &'static std::path::Path> {
TESTS_DIR
.get_file(&format!("files-toml-{ver}"))
.and_then(|f| std::str::from_utf8(f.contents()).ok())
.into_iter()
.flat_map(|f| f.lines())
.map(std::path::Path::new)
}

pub fn versions() -> std::collections::HashMap<&'static str, Vec<&'static std::path::Path>> {
TESTS_DIR
.files()
.filter_map(|f| {
let name = f.path().file_name()?;
let version = name.to_str()?.strip_prefix("files-toml-")?;
let paths = std::str::from_utf8(f.contents())
.ok()?
.lines()
.map(std::path::Path::new)
.collect::<Vec<_>>();
Some((version, paths))
})
.collect()
}

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct Valid<'a> {
pub name: &'a std::path::Path,
Expand Down

0 comments on commit aa38160

Please sign in to comment.