#string #assert

assert-str

Macros for asserting multiline strings

2 unstable releases

Uses new Rust 2024

new 0.2.0 Apr 4, 2025
0.1.0 Jul 14, 2020

#338 in Testing

Download history 78/week @ 2024-12-16 10/week @ 2024-12-23 23/week @ 2024-12-30 178/week @ 2025-01-06 66/week @ 2025-01-13 85/week @ 2025-01-20 97/week @ 2025-01-27 250/week @ 2025-02-03 120/week @ 2025-02-10 117/week @ 2025-02-17 117/week @ 2025-02-24 133/week @ 2025-03-03 104/week @ 2025-03-10 54/week @ 2025-03-17 90/week @ 2025-03-24 153/week @ 2025-03-31

403 downloads per month
Used in fewer than 6 crates

Apache-2.0/MIT

21KB
364 lines

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.

No runtime deps