Crate sleuth

source ·
Expand description

Extremely opinionated testing framework generating an exact specification and reducing code to its minimal implementation.

use ::sleuth::sleuth;

fn roundtrip<T, U, F, G>(f: F, g: G, x: T) -> bool
  where
  T: PartialEq + Clone,
  F: Fn(U) -> T,
  G: Fn(T) -> U,
{
  x.clone() == f(g(x))
}

#[sleuth(roundtrip(sub_one, 42), !roundtrip(add_one, 42))]
fn add_one(x: u8) -> u8 { x + 1 }

#[sleuth(roundtrip(add_one, 42), !roundtrip(sub_one, 42))]
fn sub_one(x: u8) -> u8 { x - 1 }

Re-exports

Modules

  • The actual functions with which we can reconstruct a function in AST-aligned form.

Macros

  • Like an ordinary assertion, except success yields None and error yields the error message.
  • Like an ordinary assertion, except success yields None and error yields the error message.

Functions

  • Turns the output of a timid_assert! into a test.

Attribute Macros

  • Test that this is the shortest possible implementation to fulfill a set of properties.