Skip to content

Commit 438b9a6

Browse files
committed
More tests for token stream pretty-printing with adjacent punctuation.
We currently do the wrong thing on a lot of these. The next commit will fix things.
1 parent 783d4b8 commit 438b9a6

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/ui/macros/stringify.rs

+29
Original file line numberDiff line numberDiff line change
@@ -801,3 +801,32 @@ fn test_vis() {
801801
assert_eq!(inherited_vis!(struct), "");
802802
assert_eq!(stringify!(), "");
803803
}
804+
805+
macro_rules! p {
806+
([$($tt:tt)*], $s:literal) => {
807+
assert_eq!(stringify!($($tt)*), $s);
808+
};
809+
}
810+
811+
#[test]
812+
fn test_punct() {
813+
// For all these cases, we must preserve spaces between the tokens.
814+
// Otherwise, any old proc macro that parses pretty-printed code might glue
815+
// together tokens that shouldn't be glued.
816+
p!([ = = < < <= <= == == != != >= >= > > ], "= = < < <= <= == == != != >= >= > >");
817+
p!([ && && & & || || | | ! ! ], "&& && & & || || | |!!"); // FIXME
818+
p!([ ~ ~ @ @ # # ], "~ ~ @ @ # #");
819+
p!([ . . .. .. ... ... ..= ..=], ".... .. ... ... ..= ..="); // FIXME
820+
p!([ , , ; ; : : :: :: ], ",, ; ; : : :: ::"); // FIXME
821+
p!([ -> -> <- <- => =>], "-> -> <- <- => =>");
822+
p!([ $ $ ? ? ' ' ], "$$? ? ' '"); // FIXME
823+
p!([ + + += += - - -= -= * * *= *= / / /= /= ], "+ + += += - - -= -= * * *= *= / / /= /=");
824+
p!([ % % %= %= ^ ^ ^= ^= << << <<= <<= >> >> >>= >>= ],
825+
"% % %= %= ^ ^ ^= ^= << << <<= <<= >> >> >>= >>=");
826+
827+
// For these one we must insert spaces between adjacent tokens, again due
828+
// to proc macros.
829+
p!([ +! ?= |> >>@ --> <-- $$ =====> ], "+! ? = | > >> @ - -> <- - $$== == =>"); // FIXME
830+
p!([ ,; ;, ** @@ $+$ >< <> ?? +== ], ", ; ;, * * @ @ $+ $> < < > ? ? += ="); // FIXME
831+
p!([ :#!@|$=&*,+;*~? ], ": #! @ | $= & *, + ; * ~ ?"); // FIXME
832+
}

0 commit comments

Comments
 (0)