-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6b3acf9
Showing
6 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/target | ||
**/*.rs.bk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "crates/data/assets/toml-test"] | ||
path = crates/data/assets/toml-test | ||
url = https://github.com/BurntSushi/toml-test.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "toml-test-data" | ||
version = "1.0.0" | ||
edition = "2018" | ||
|
||
[dependencies] | ||
include_dir = "0.6" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Item = Valid<'static>> { | ||
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<Item = Valid<'static>> { | ||
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<Item = Invalid<'static>> { | ||
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 } | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |