philiprehberger-diff-assert 0.1.8

Better test assertion diffs with colored inline comparisons
Documentation

rs-diff-assert

CI Crates.io GitHub release Last updated License Bug Reports Feature Requests Sponsor

Better test assertion diffs with colored inline comparisons

Installation

[dependencies]
philiprehberger-diff-assert = "0.1.8"

Usage

use philiprehberger_diff_assert::assert_eq_diff;

#[test]
fn my_test() {
    let expected = "hello\nworld\nfoo";
    let actual = "hello\neveryone\nfoo";

    // Shows a colored diff on failure instead of raw Debug output
    assert_eq_diff!(expected, actual);
}

Output on failure:

  hello
- world
+ everyone
  foo

Programmatic use

use philiprehberger_diff_assert::diff_strings;

let diff = diff_strings("line1\nline2", "line1\nline3");
println!("{}", diff);

API

Function / Macro Description
assert_eq_diff!(left, right) Assert equality with colored diff on failure
assert_eq_diff!(left, right, msg, ..) With custom failure message
diff_strings(left, right) Get colored diff of two strings
diff_strings_no_color(left, right) Get diff without ANSI codes
diff_debug(left, right) Diff Debug output of two values

Development

cargo test
cargo clippy -- -D warnings

Support

If you find this package useful, consider giving it a star on GitHub — it helps motivate continued maintenance and development.

LinkedIn More packages

License

MIT