Skip to content

Snapbox parameter order (expected, actual) breaks common convention #226

Closed
@not-my-profile

Description

@not-my-profile

The following code:

snapbox::assert_eq("foo", "bar");

results in:

--- Expected
+++ Actual
   1      - foo∅
        1 + bar∅

which funnily enough is rather unexpected. When writing comparisons in code it is common practice to put constants on the right side of the operator e.g:

if self.length == 0 {

rather than:

if 0 == self.length {

And even though std::assert_eq does not document any convention and also just speaks of left and right in its panic messages, the vast majority of Rust code uses the same convention of putting the expected value last (e.g. assert_eq!(self.length, 0) instead of assert_eq!(0, self.length).

The non-file-based methods of snapbox however use the opposite order ... which matters because snapbox (contrary to std, pretty_assertions and similar-asserts does label its diff with expected/actual instead of just left/right).

Note that I think attempting to label actual/expected for non-file based methods is a good idea ... it's just that I think not breaking the user expectation is more important than anything else. We could still achieve both labeling and adhering to user expectations but it would require a breaking change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-snapboxArea: snapbox packagequestionUncertainty is involved

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions