Crates.io | test_eq |
lib.rs | test_eq |
version | |
source | src |
created_at | 2024-10-23 20:25:36.599233 |
updated_at | 2024-10-24 10:02:38.210341 |
description | assert_eq!-like macros that return a Result instead |
homepage | |
repository | https://github.com/kriskras99/test_eq |
max_upload_size | |
id | 1420582 |
Cargo.toml error: | TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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.
This crate contains two kinds of macros:
test_eq!
, test_any!
, …).test_and!
and test_or!
).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
)?;
}
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
.
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.