Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add iterator input functions as arguments #10

Open
foresterre opened this issue Nov 11, 2019 · 0 comments
Open

Add iterator input functions as arguments #10

foresterre opened this issue Nov 11, 2019 · 0 comments
Labels
A-parameterized-macro Area: changes related to the parameterized proc macro C-enhancement Category: enhancements

Comments

@foresterre
Copy link
Owner

foresterre commented Nov 11, 2019

Overview:

Add an input method based on any function which returns impl IntoIterator<Item=V> 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<u32, ()> = 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<u32, ()> = input.parse().map_err(|_| ());
    assert_eq!(parsed.unwrap(), expected);
}

fn my_inputs() -> impl IntoIterator<Item = &'static str> {
    vec!["0", "1", "2"]
}

or


#[parameterized(using v = my_provider)]
fn my_test(v: Option<i32>) {}

fn my_provider() -> impl IntoIterator<Option<i32>> {
    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
@foresterre foresterre added A-parameterized-macro Area: changes related to the parameterized proc macro C-enhancement Category: enhancements labels Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parameterized-macro Area: changes related to the parameterized proc macro C-enhancement Category: enhancements
Projects
None yet
Development

No branches or pull requests

1 participant