2 unstable releases

0.1.0 Jan 26, 2020
0.0.0 Jan 25, 2020

#2628 in Rust patterns

MIT license

6KB

asserter

Build Status

A new testing utility for rust

Features

  • Works on stable

  • unwrap!

You can easily unwrap nested value easily.

use asserter::*;

enum Complex {
    Normal(String),
    Boxed(Box<Complex>),
}

#[asserter]
fn main() {
    let foo = Complex::Boxed(Box::new(Complex::Normal(String::from("foo"))));

    unwrap!(foo as Complex::Boxed(unbox!(Complex::Normal(s))));
    assert_eq!(s, "foo");   
}

Also, you can use box patterns in unwrap!.

use asserter::*;

enum Complex {
    Normal(String),
    Boxed(Box<Complex>),
}

#[asserter]
fn main() {
    let foo = Complex::Boxed(Box::new(Complex::Normal(String::from("foo"))));

    unwrap!(foo as Complex::Boxed(box Complex::Normal(s)));
    assert_eq!(s, "foo");   
}
  • rustfmt-friendly

There are some syntax sugars to allow using rustfmt with it.

Usage

Cargo.tml:

[dependencies]
asserter = "0.1"
#[asserter]
fn main() {
    let foo = Complex::Boxed(Box::new(Complex::Normal(String::from("foo"))));

    unwrap!(foo as Complex::Boxed(box Complex::Normal(s)));
    assert_eq!(s, "foo");   
}

Dependencies

~1.5MB
~38K SLoC