k9 icon indicating copy to clipboard operation
k9 copied to clipboard

Trailing comma in multiline macros

Open aaronabramov opened this issue 4 years ago • 3 comments

    assert_err_matches_regex!(
        conn.query_raw("SELECT 1").await,
        "time out"
    );

works, but

    assert_err_matches_regex!(
        conn.query_raw("SELECT 1").await,
        "time out",
    );

doesn't

aaronabramov avatar Jun 17 '20 05:06 aaronabramov

Found a Similar issue: https://github.com/gluon-lang/gluon/issues/770

And it's commit to solve the issue: https://github.com/Marwes/gluon/commit/bb41fa15765f7825f7f7c1e64388010cd4610950

Using this worked for me but it required me to define multiple patterns (One with a trailing comma and one without) inside assertion macros which kinda go against the DRY principle. Let me know if you have a better approach for this. :D

TheWebDevel avatar Jun 17 '20 12:06 TheWebDevel

@TheWebDevel would something like $( , )? work? i remember i solved before with a separate macro definition, but yeah... this whole crate is already not DRY, so it'd be nice to not 2x every macro definition 🙂

aaronabramov avatar Jun 17 '20 15:06 aaronabramov

$( , ) This is what worked for me but I had to define respective pattern matching to handle with and without trailing comma scenarios.

TheWebDevel avatar Jun 17 '20 15:06 TheWebDevel