assert-str 0.2.0

Macros for asserting multiline strings
Documentation
  • Coverage
  • 100%
    7 out of 7 items documented6 out of 6 items with examples
  • Size
  • Source code size: 32.98 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.48 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • AnderEnder/assert-str
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • AnderEnder

assert-str

build status codecov crates.io

Macros for Asserting Multiline Strings

This is a set of macros designed to assert strings that may be generated on different operating systems, potentially containing different newline characters or varying levels of indentation. These macros allow you to compare prettified JSON or XML with their compressed versions.

Usage

Add the dependency to your Cargo.toml:

[dependencies]
assert-str = "0.1"

Or

[dev-dependencies]
assert-str = "0.1"

Import the macros in your test module or main file:

use assert_str::{assert_str_eq, assert_str_ne};
use assert_str::{assert_str_trim_eq, assert_str_trim_ne};
use assert_str::{assert_str_trim_all_eq, assert_str_trim_all_ne};

Or if you want to import all macros:

use assert_str::*;

Use the macros:

#[test]
fn test_trimmed_string_assertions() {
    assert_str_trim_eq!(
        "<html>\t \n\t<head> \n\t</head></html>",
        "<html>\r\n<head>\r\n</head></html>",
        "Responses should be equal"
    );

    assert_str_trim_all_eq!(
        "<html>\t \n\t<head> \n\t</head></html>",
        "<html><head></head></html>",
        "Responses should be equal"
    );
}
  • assert_str_trim_eq! ignores leading/trailing whitespace and normalizes line endings.
  • assert_str_trim_all_eq! removes all whitespace (including between tags), useful for comparing minified and pretty-printed formats.