Skip to content

Commit

Permalink
More tests for token stream pretty-printing with adjacent punctuation.
Browse files Browse the repository at this point in the history
We currently do the wrong thing on a lot of these. The next commit will
fix things.
  • Loading branch information
nnethercote committed Nov 8, 2023
1 parent 783d4b8 commit 438b9a6
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/ui/macros/stringify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,3 +801,32 @@ fn test_vis() {
assert_eq!(inherited_vis!(struct), "");
assert_eq!(stringify!(), "");
}

macro_rules! p {
([$($tt:tt)*], $s:literal) => {
assert_eq!(stringify!($($tt)*), $s);
};
}

#[test]
fn test_punct() {
// For all these cases, we must preserve spaces between the tokens.
// Otherwise, any old proc macro that parses pretty-printed code might glue
// together tokens that shouldn't be glued.
p!([ = = < < <= <= == == != != >= >= > > ], "= = < < <= <= == == != != >= >= > >");
p!([ && && & & || || | | ! ! ], "&& && & & || || | |!!"); // FIXME
p!([ ~ ~ @ @ # # ], "~ ~ @ @ # #");
p!([ . . .. .. ... ... ..= ..=], ".... .. ... ... ..= ..="); // FIXME
p!([ , , ; ; : : :: :: ], ",, ; ; : : :: ::"); // FIXME
p!([ -> -> <- <- => =>], "-> -> <- <- => =>");
p!([ $ $ ? ? ' ' ], "$$? ? ' '"); // FIXME
p!([ + + += += - - -= -= * * *= *= / / /= /= ], "+ + += += - - -= -= * * *= *= / / /= /=");
p!([ % % %= %= ^ ^ ^= ^= << << <<= <<= >> >> >>= >>= ],
"% % %= %= ^ ^ ^= ^= << << <<= <<= >> >> >>= >>=");

// For these one we must insert spaces between adjacent tokens, again due
// to proc macros.
p!([ +! ?= |> >>@ --> <-- $$ =====> ], "+! ? = | > >> @ - -> <- - $$== == =>"); // FIXME
p!([ ,; ;, ** @@ $+$ >< <> ?? +== ], ", ; ;, * * @ @ $+ $> < < > ? ? += ="); // FIXME
p!([ :#!@|$=&*,+;*~? ], ": #! @ | $= & *, + ; * ~ ?"); // FIXME
}

0 comments on commit 438b9a6

Please sign in to comment.