Giter VIP home page Giter VIP logo

test_gen's Introduction

test_gen

A comprehensive function-like macro, for concisely defining parameterized tests.

This crate provides the function-like macro of its namesake, test_gen, which enables the concise definition of batches of named tests, implementing a parameterized argument format to minimise the boilerplate otherwise required for specifying batches of similar tests.

Documentation can be found at Docs.rs.

Usage

Minimum Supported Rust Version: 1.63.0

test_gen can be added to a project, using the following command:

cargo add test_gen --dev

Or alternatively, by adding the following lines to its Cargo.toml file:

[dev-dependancies]
test_gen = "0.2.3"

Examples

Fruits:

use test_gen::*;

enum Fruit<T> {
    Apple,
    Pear,
    Other(T),
}

enum BrambleFruit {
    BlackBerry,
}

trait NameOf {
    fn name_of(&self) -> &str;
}

impl<T: NameOf> NameOf for Fruit<T> {
    fn name_of(&self) -> &str {
        use Fruit::*;

        match self {
            Apple => "apple",
            Pear => "pear",
            Other(fruit) => fruit.name_of(),
        }
    }
}

impl NameOf for BrambleFruit {
    fn name_of(&self) -> &str {
        use BrambleFruit::*;

        match self {
            BlackBerry => "blackberry",
        }
    }
}

// Helper function
fn assert_fruit<T: NameOf>(fruit: Fruit<T>, name: &str) {
    assert_eq!(fruit.name_of(), name);
}

// Test specification
test_gen! {
    // Normal turbofish syntax can be used,
    // when concrete type specification is required
    fn assert_fruit::<BrambleFruit> => {
        apple: {
            (Fruit::Apple, "apple")
        },
        // Applying case specific attributes
        pear: {
            #[ignore]
            (Fruit::Pear, "pear")
        },
        isnt_pear: {
            #[should_panic]
            (Fruit::Pear, "apple")
        },
        blackberry: {
            (Fruit::Other(BrambleFruit::BlackBerry), "blackberry")
        },
    }
}

License

test_gen is licensed under the BSD 3-Clause license.

See LICENSE for details.

test_gen's People

Contributors

dunnandusted avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.