Giter Club home page Giter Club logo

assert_matches's People

Contributors

jpastuszek avatar murarth avatar tbu- avatar yvt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

assert_matches's Issues

Error enum field parsing bug?

Consider this example(I would do a playground one if assert_matches were accesible there):

#[derive(Debug)]
pub enum Error {
    Lowercase { name: String },
}

fn do_something(n: String) -> Result<(), Error> {
    match n {
        name if name.chars().any(|c| !c.is_lowercase()) => Err(Error::Lowercase { name }),
        _ => panic!("All good"),
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use assert_matches::assert_matches;

    #[test]
    fn example() {
        let name = "BazinGa";
        let e: Result<(), Error> = Err(Error::Lowercase {
            name: "".to_owned(),
        });
        assert_matches!(do_something(name.to_owned()), e);
    }
}

Here are a few issues:

  • if you place error in assert_matches directly it will not compile.
  • if you make it a separate e variable the compiler will complain that it is not used both in place of declaration and usage
  • finally while the in the passing test the error type parsed correctly(if you will add another one and change the variant it should fail) but the name field name is not mathed correctly.

Propose this to libstd in an RFC

Hi!

I found myself implementing a very similar macro a few times. I called it assert_pat, but it did virtually the same thing. Today I thought I should create an RFC proposing that my macro is added to the standard library. I find it very useful and ergonomic whenever you need to assert equality on something that does not implement Eq, but that can be matched by a destructure. For example, when using error-chain this is very needed, since the errors generated by that library does not implement Eq.

However. In my research I found this crate, which is awesome! But have you thought about suggesting it be included in the standard library?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.