assert-tokenstreams-eq

Crates.ioassert-tokenstreams-eq
lib.rsassert-tokenstreams-eq
version0.1.1
created_at2023-02-12 19:14:06.835739+00
updated_at2026-01-17 15:12:12.055192+00
descriptionA utility for comparing token streams: applies rustfmt for consistent formatting and leverages pretty_assertions to clearly visualize differences.
homepage
repositoryhttps://github.com/robinohs/assert-tokenstreams-eq
max_upload_size
id783400
size10,872
Robin Ohs (robinohs)

documentation

README

assert-tokenstreams-eq

A utility for comparing token streams in tests. It applies rustfmt to the token streams to ensure consistent formatting and leverages pretty_assertions to clearly visualize differences when the assertion fails.

MSRV License CircleCI

Usage

Add this to your Cargo.toml:

[dev-dependencies]
assert-tokenstreams-eq = "0.1"
quote = "1.0"

Then use the macro in your tests:

use assert_tokenstreams_eq::assert_tokenstreams_eq;
use quote::quote;

#[test]
fn test_code_generation() {
    let expected = quote! {
        fn test(a: String, b: String) {
            return a;
        }
    };

    let actual = quote! {
        fn   test  ( a :String,b:String){return a ;}
    };

    assert_tokenstreams_eq!(&expected, &actual);
}

How It Works

  1. Both token streams are formatted using rustfmt. This handles differences in whitespace, indentation, and equivalent syntax.
  2. The formatted strings are compared.
  3. If they differ, pretty_assertions prints a colorful diff showing exactly where the mismatch occurred.

Prerequisites

This crate relies on rustfmt being installed and available in your path.

rustup component add rustfmt
Commit count: 41

cargo fmt