Skip to content

Add iterator input functions as arguments #10

@foresterre

Description

@foresterre

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-parameterized-macroArea: changes related to the parameterized proc macroC-enhancementCategory: enhancements

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions