Assertables Rust crate of macros for "assert" and "assertable"

This assertables Rust crate provides macros for assert…! and assertable…!, which are useful for testing and also for runtime reliability checking. By SixArm.com.

Crate: https://crates.io/crates/assertables

Docs: https://docs.rs/assertables/

Repo: https://github.com/sixarm/assertables-rust-crate/

assert & assertable

These macros have two styles:

Examples of "assert less than" and "assertable less than":

```rust assert_lt!(1, 2); // assert 1 is less than 2 //-> ()

assert_lt!(2, 1); //-> panic! // assertion failed: assert_lt!(left, right) // left: 2, // right: 1

let x = assertable_lt!(1, 2); //-> Ok(())

let x = assertable_lt!(2, 1); //-> Err("…") // assertable failed: assertable_lt!(left, right) // left: 2, // right: 1 ```

These two styles are useful because:

The macros use abbreviations: eq (equals), ne (not equals), lt (less than), le (less than or equal to), gt (greater than), ge (greater than or equals).

The macros have a second form where a custom error message can be provided.

assert_xx for values

Compare values.

Examples:

```rust assert_lt!(1, 2); //-> ()

assert_lt!(2, 1); //-> panic! // assertion failed: assert_lt!(left, right) // left: 2 // right: 1 ```

assertfxx for function returns

Examples:

```rust assertflt!(i32::abs, 1, -2); //-> ()

assertflt!(i32::abs, -2, 1); //-> panic! // assertion failed: assert_f_eq!(function, left, right) // function: \"i32::abs\", // left input: -2, // right input: 1, // left output: 2, // right output: 1 ```

assertfok_xx for function Result Ok values

```rust fn exampledigitto_string(i: isize) -> Result { match i { 0..=9 => Ok(format!("{}", i)), _ => Err(format!("{:?} is out of range", i)), } }

assertfoklt!(exampledigittostring, 1, 2); //-> ()

assertfoklt!(exampledigittostring, 2, 1); //-> panic! // assertion failed: assert_f_eq!(function, left, right) // function: \"example_digit_to_string\", // left input: 2, // right input: 1, // left output: \"2\", // right output: \"1\" ```

assertferrstringxx for function Result Err strings

Examples:

```rust fn exampledigitto_string(i: isize) -> Result { match i { 0..=9 => Ok(format!("{}", i)), _ => Err(format!("{:?} is out of range", i)), } }

assertferrstringlt!(exampledigitto_string, 10, 20); //-> ()

assertferrstringlt!(exampledigitto_string, 20, 10); //-> panic! // assertion failed: assert_f_err_string_eq!(example_digit_to_string, left, right) // function: \"example_digit_to_string\", // left input: 20, // right input: 10``, // left is err:true, // right is err:true, // left output:\"20 is out of range\", // right output:\"10 is out of range\"` ```

Two functions that we use often:

assertsetxx for set comparisons

These macros help with comparison of set parameters, such as two arrays or two vectors. where the item order does not matter, and the item count does not matter. The macros convert inputs into HashSet iterators.

Examples:

```rust assertseteq!([1, 2], [2, 1]); //-> ()

assertseteq!([1, 2], [3, 4]); //-> panic // assertion failed: assert_set_eq!(left, right) // left: [1, 2], // right: [3, 4] //-> panic!("assertion failed: assert_set_eq!(left, right)\n left: [1, 2],\n right: [3, 4]"); ```

assertbagxx for bag comparisons

These macros help with comparison of bag parameters, such as comparison of two arrays or two vectors, where the item order does not matter, and the item count does matter. The macros convert inputs into HashMap iterators.

Examples:

```rust assertbageq!([1, 1], [1, 1]); //-> ()

assertbageq!([1, 1], [1, 1, 1]); //-> panic! // assertion failed: assert_bag_eq!(left, right) // left: [1, 1], // right: [1, 1, 1] ```

assertioxx for input/output comparisons

These macros help with input/output checking, such as with comparison of disk files, IO streams, etc.

Examples:

```rust assertiolt!(1, 2); //-> ()

assertiolt!(2, 1); //-> panic! // assertion failed: assert_io_lt!(left, right) // left: 2, // right: 1 ```

assertreadtostringxx for std::io::Read comparisons

These macros help with readers, such as file handles, byte arrays, input streams, and the trait std::io::Read.

Examples:

```rust use std::io::Read;

let mut a = "a".asbytes(); let mut b = "b".asbytes(); assertreadtostringlt!(a, b); //-> ()

let mut a = "a".asbytes(); let mut b = "b".asbytes(); assertreadtostringlt!(b, a); //-> panic! // assertion failed: assert_read_to_string_lt!(left, right) // left: \"b\", // right: \"a\" ```