Skip to content

lydiaaam/assertion-diff-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 

Repository files navigation

assertion-diff-helper

A Rust library that highlights differences between expected and actual values in test assertions.

Features

  • Colorized diff output (ANSI terminal support)
  • Custom type support through traits
  • Integration with common test frameworks

Quick Start

Add to your Cargo.toml:

assertion-diff-helper = "*"

Example Usage

use assertion_diff_helper::prelude::*;

let expected = "hello world";
let actual = "hello word";

println!("{}", diff_strings(expected, actual));

Terminal Diff Example

Expected: hello world Actual: hello word

Output (simplified):

hello wor[l]d
          ^ expected 'l' not found in 'actual'

Custom Type Diffing

To highlight diffs in your own types, implement the Diffable trait:

use assertion_diff_helper::traits::Diffable;
use assertion_diff_helper::diff_helpers::DiffOutput;

struct MyType {
    a: i32,
    b: String,
}

impl Diffable for MyType {
    fn diff(&self, other: &Self) -> DiffOutput {
        let a_diff = self.a.diff(&other.a);
        let b_diff = self.b.diff(&other.b);
        DiffOutput::combine_fields(vec![
            ("a", a_diff),
            ("b", b_diff)
        ])
    }
}

You can then diff MyType instances just like built-in types.


Test Integration

Works with:

Color Output

ANSI color output can be toggled globally:

assertion_diff_helper::color::set_color_enabled(false);

Development

See the tests/ folder for usage patterns and behavior.

License

MIT OR Apache-2.0

About

A Rust library that highlights differences between expected and actual values in test assertions.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages