test_eq 0.2.0

assert_eq!-like macros that return a Result instead
Documentation
  • Coverage
  • 100%
    10 out of 10 items documented9 out of 10 items with examples
  • Size
  • Source code size: 69.28 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.49 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Kriskras99/test_eq
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Kriskras99

test_eq!

assert_eq!-like macros that return a Result instead.

The primary use case is in writing parsers, where you want to check that magic values are correct and that values are as expected. The macros are implemented using macro_rules and should therefore not have a significant impact on compile times.

Usage

This crate contains two kinds of macros:

  1. Macros that check variables are as expected (test_eq!, test_any!, …).
  2. Macros that compose the test macros (test_and! and test_or!).

Examples

use test_eq::{TestFailure, test_eq, test_and, test_or, test_any, test_ge};

pub fn parser() -> Result<(), TestFailure> {
    let magic: u32 = todo!();
    test_eq!(magic, 0xDEAD_BEEF)?;
    let version: u8 = todo!();
    test_any!(version, 1..4, "unsupported version found")?;
    let field: String = todo!();
    test_or!(test_ge!(field.len(), 8), test_eq!(field, "spam"))?;
    let field2: u32 = todo!();
    test_and!(
        test_any!(field2, 42..=2048),
        test_eq!(field2 % 2, 0),
        "related field: {}", field
    )?;
}

Features

line-info

Provide the location in the source file where the error happened. This feature is enabled by default. This information is set at compile time and cannot be removed with debug=false or strip=true.

Copyright

The implementation of these macros is based on the implementations of the assert*! macros in the standard library. The Rust standard library is dual-licensed under the MIT and Apache-2.0 licenses just like this library.