Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert_equal does not handle comparing vectors to arrays #57

Closed
gregtatum opened this issue Jul 13, 2020 · 5 comments · Fixed by #69
Closed

assert_equal does not handle comparing vectors to arrays #57

gregtatum opened this issue Jul 13, 2020 · 5 comments · Fixed by #69

Comments

@gregtatum
Copy link

This is a parity issue with assert_eq!

// This works:
assert_eq!(vec![1, 2, 3], [1, 2, 3]);

// This does not:
assert_equal!(vec![1, 2, 3], [1, 2, 3]);
error[E0308]: mismatched types
   --> src/sampler.rs:429:38
    |
429 |         assert_equal!(vec![1, 2, 3], [1, 2, 3]);
    |                                      ^^^^^^^^^
    |                                      |
    |                                      expected struct `std::vec::Vec`, found array `[{integer}; 3]`
    |                                      help: try using a conversion method: `[1, 2, 3].to_vec()`
    |
    = note: expected struct `std::vec::Vec<{integer}>`
                found array `[{integer}; 3]`
@aaronabramov
Copy link
Owner

interesting! i didn't even know you could do this with assert_eq!. i'll need to dig into the code to see how it's done there

@gregtatum
Copy link
Author

Hah, yeah I was a bit surprised myself. I just did a mass search and replace in my project, and I hit this one and the trailing comment issue. Otherwise things are muuuuuch more readable compared to the built-ins.

@aaronabramov
Copy link
Owner

yeah! trailing comma is a known issue, but the current fix would mean adding a macro branch for each assertion.

also i added assert_matches_inline_snapshot! that i haven't documented yet if you want to try, since i remember you preferred inline snaps to a separate file 😛

@wez
Copy link

wez commented Nov 8, 2020

I also ran into this while migrating from the pretty_assertions crate; maybe worth taking a peek to see what that crate is doing?

@aaronabramov
Copy link
Owner

i guess comparing references will just work for this case
fixed in #69

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants