foresterre / foresterre/parameterized

Add iterator input functions as arguments

Open
#10 4 comments 0 reactions 0 assignees View on GitHub
A-parameterized-macro C-enhancement
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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.