| Crates.io | assert-tokenstreams-eq |
| lib.rs | assert-tokenstreams-eq |
| version | 0.1.1 |
| created_at | 2023-02-12 19:14:06.835739+00 |
| updated_at | 2026-01-17 15:12:12.055192+00 |
| description | A utility for comparing token streams: applies rustfmt for consistent formatting and leverages pretty_assertions to clearly visualize differences. |
| homepage | |
| repository | https://github.com/robinohs/assert-tokenstreams-eq |
| max_upload_size | |
| id | 783400 |
| size | 10,872 |
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.
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);
}
rustfmt. This handles differences in
whitespace, indentation, and equivalent syntax.pretty_assertions prints a colorful diff showing exactly
where the mismatch occurred.This crate relies on rustfmt being installed and available in your path.
rustup component add rustfmt