Skip to content

Commit

Permalink
support for string inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Dubrov committed May 7, 2019
1 parent 84ad163 commit a751b89
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "datatest"
version = "0.3.0"
version = "0.3.1"
authors = ["Ivan Dubrov <[email protected]>"]
edition = "2018"
repository = "https://github.com/commure/datatest"
Expand All @@ -11,7 +11,7 @@ Data-driven tests in Rust
"""

[dependencies]
datatest-derive = { path = "datatest-derive", version = "0.3.0" }
datatest-derive = { path = "datatest-derive", version = "0.3.1" }
regex = "1.0.0"
walkdir = "2.1.4"
serde = "1.0.84"
Expand Down
2 changes: 1 addition & 1 deletion datatest-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "datatest-derive"
version = "0.3.0"
version = "0.3.1"
authors = ["Ivan Dubrov <[email protected]>"]
edition = "2018"
repository = "https://github.com/commure/datatest"
Expand Down
3 changes: 3 additions & 0 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ fn index_cases(source: &str) -> Vec<Marker> {
Event::StreamEnd => {
break;
}
Event::Scalar(_, _, _, _) if depth == 1 => {
index.push(marker);
}
Event::MappingStart(_idx) if depth == 1 => {
index.push(marker);
depth += 1;
Expand Down
9 changes: 9 additions & 0 deletions tests/datatest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,12 @@ impl fmt::Display for GreeterTestCaseNamed {
fn data_test_name_and_line(data: &GreeterTestCaseNamed) {
assert_eq!(data.expected, format!("Hi, {}!", data.name));
}


/// Can also take string inputs
#[datatest::data("tests/strings.yaml")]
#[test]
fn data_test_string(data: String) {
let half = data.len() / 2;
assert_eq!(data[0..half], data[half..]);
}
3 changes: 3 additions & 0 deletions tests/strings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- "firstfirst"
- "secondsecond"
- "thirdthird"

0 comments on commit a751b89

Please sign in to comment.