diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53eaa21 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +**/*.rs.bk diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..ac40300 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "crates/data/assets/toml-test"] + path = crates/data/assets/toml-test + url = https://github.com/BurntSushi/toml-test.git diff --git a/crates/data/Cargo.toml b/crates/data/Cargo.toml new file mode 100644 index 0000000..850d823 --- /dev/null +++ b/crates/data/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "toml-test-data" +version = "1.0.0" +edition = "2018" + +[dependencies] +include_dir = "0.6" diff --git a/crates/data/assets/toml-test b/crates/data/assets/toml-test new file mode 160000 index 0000000..0a2c92b --- /dev/null +++ b/crates/data/assets/toml-test @@ -0,0 +1 @@ +Subproject commit 0a2c92b1664c87cc6895405d5ba2f8892d589c05 diff --git a/crates/data/src/lib.rs b/crates/data/src/lib.rs new file mode 100644 index 0000000..45bb3c3 --- /dev/null +++ b/crates/data/src/lib.rs @@ -0,0 +1,62 @@ +const VALID_DIR: include_dir::Dir = include_dir::include_dir!("assets/toml-test/tests/valid"); +const INVALID_DIR: include_dir::Dir = include_dir::include_dir!("assets/toml-test/tests/invalid"); + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub struct Valid<'a> { + pub name: &'a str, + pub fixture: &'a [u8], + pub expected: &'a [u8], +} + +pub fn valid() -> impl Iterator> { + valid_files(VALID_DIR.files()).chain(VALID_DIR.dirs().iter().flat_map(|d| { + assert!(d.dirs().is_empty()); + valid_files(d.files()) + })) +} + +fn valid_files( + files: &'static [include_dir::File<'static>], +) -> impl Iterator> { + files + .iter() + .filter(|f| f.path().extension().unwrap_or_default() == "toml") + .map(move |f| { + let t = f; + let j = files + .iter() + .find(|f| { + f.path().parent() == t.path().parent() + && f.path().file_stem() == t.path().file_stem() + && f.path().extension().unwrap() == "json" + }) + .unwrap(); + let name = t.path().to_str().unwrap(); + let fixture = t.contents(); + let expected = j.contents(); + Valid { + name, + fixture, + expected, + } + }) +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub struct Invalid<'a> { + pub name: &'a str, + pub fixture: &'a [u8], +} + +pub fn invalid() -> impl Iterator> { + assert!(INVALID_DIR.files().is_empty()); + INVALID_DIR.dirs().iter().flat_map(|d| { + assert!(d.dirs().is_empty()); + d.files().iter().map(|f| { + let t = f; + let name = f.path().to_str().unwrap(); + let fixture = t.contents(); + Invalid { name, fixture } + }) + }) +} diff --git a/crates/data/tests/test.rs b/crates/data/tests/test.rs new file mode 100644 index 0000000..352ef37 --- /dev/null +++ b/crates/data/tests/test.rs @@ -0,0 +1,9 @@ +#[test] +fn valid_doesnt_panic() { + toml_test_data::valid().last().unwrap(); +} + +#[test] +fn invalid_doesnt_panic() { + toml_test_data::invalid().last().unwrap(); +}