foresterre / foresterre/parameterized
Add iterator input functions as arguments
- Dominant language
- Rust
- Stars
- 27
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
**Overview:**
Add an input method based on any function which returns `impl IntoIterator` where the type of `V` is of the same type as a function argument.
For example for the following test case, the type of `V` would be either `&str` or `u32`:
```
#[parameterized(input = { "0", "1", "2" }, expected = { 0, 1, 2 })]
fn my_test(input: &str, expected: u32) {
let parsed: Result = input.parse().map_err(|_| ());
assert_eq!(parsed.unwrap(), expected);
}
```
**(Proposed) Syntax:**
```
#[parameterized(fn my_inputs as input, expected = { 0, 1, 2 })]
```
or
```
#[parameterized(using my_inputs as input, expected = { 0, 1, 2 })]
fn my_test(input: &str, expected: u32) {
let parsed: Result = input.parse().map_err(|_| ());
assert_eq!(parsed.unwrap(), expected);
}
fn my_inputs() -> impl IntoIterator {
vec!["0", "1", "2"]
}
```
or
```
#[parameterized(using v = my_provider)]
fn my_test(v: Option) {}
fn my_provider() -> impl IntoIterator> {
vec![Some(1)]
}
```
**Considerations:**
- Always at least one finite iterator expected; or a finite expression based input from which we can take the max length as the amount of test cases
* https://doc.rust-lang.org/std/iter/trait.ExactSizeIterator.html
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.