Fix incorrect repeat sep eating

This commit is contained in:
Edwin Cheng 2019-04-24 02:59:38 +08:00
parent 5bbd9f43cc
commit e4e2338f97
3 changed files with 304 additions and 24 deletions

View file

@ -384,7 +384,7 @@ impl_froms!(TokenTree: Leaf, Subtree);
"#,
);
assert_expansion(&rules, "foo! { foo, bar }", "fn baz {foo () ; bar () ;}");
assert_expansion(&rules, "foo! { foo, bar }", "fn baz {foo () ; bar ()}");
}
#[test]
@ -1066,4 +1066,260 @@ macro_rules! int_base {
"# [stable (feature = \"rust1\" , since = \"1.0.0\")] impl fmt :: Binary for isize {fn fmt (& self , f : & mut fmt :: Formatter < \'_ >) -> fmt :: Result {Binary . fmt_int (* self as usize , f)}}"
);
}
#[test]
fn test_generate_pattern_iterators() {
// from https://github.com/rust-lang/rust/blob/316a391dcb7d66dc25f1f9a4ec9d368ef7615005/src/libcore/str/mod.rs
let rules = create_rules(
r#"
macro_rules! generate_pattern_iterators {
{ double ended; with $(#[$common_stability_attribute:meta])*,
$forward_iterator:ident,
$reverse_iterator:ident, $iterty:ty
} => {
fn foo(){}
}
}
"#,
);
assert_expansion(&rules, r#"generate_pattern_iterators ! ( double ended ; with # [ stable ( feature = "rust1" , since = "1.0.0" ) ] , Split , RSplit , & 'a str )"#,
"fn foo () {}");
}
#[test]
fn test_impl_fn_for_zst() {
// from https://github.com/rust-lang/rust/blob/5d20ff4d2718c820632b38c1e49d4de648a9810b/src/libcore/internal_macros.rs
let rules = create_rules(
r#"
macro_rules! impl_fn_for_zst {
{ $( $( #[$attr: meta] )*
struct $Name: ident impl$( <$( $lifetime : lifetime ),+> )? Fn =
|$( $arg: ident: $ArgTy: ty ),*| -> $ReturnTy: ty
$body: block; )+
} => {
fn foo(){}
}
}
"#,
);
assert_expansion(&rules, r#"
impl_fn_for_zst ! {
# [ derive ( Clone ) ]
struct CharEscapeDebugContinue impl Fn = | c : char | -> char :: EscapeDebug {
c . escape_debug_ext ( false )
} ;
# [ derive ( Clone ) ]
struct CharEscapeUnicode impl Fn = | c : char | -> char :: EscapeUnicode {
c . escape_unicode ( )
} ;
# [ derive ( Clone ) ]
struct CharEscapeDefault impl Fn = | c : char | -> char :: EscapeDefault {
c . escape_default ( )
} ;
}
"#,
"fn foo () {}");
}
#[test]
fn test_impl_nonzero_fmt() {
// from https://github.com/rust-lang/rust/blob/316a391dcb7d66dc25f1f9a4ec9d368ef7615005/src/libcore/num/mod.rs#L12
let rules = create_rules(
r#"
macro_rules! impl_nonzero_fmt {
( #[$stability: meta] ( $( $Trait: ident ),+ ) for $Ty: ident ) => {
fn foo() {}
}
}
"#,
);
assert_expansion(&rules, r#"impl_nonzero_fmt ! { # [ stable ( feature = "nonzero" , since = "1.28.0" ) ] ( Debug , Display , Binary , Octal , LowerHex , UpperHex ) for NonZeroU8 }"#,
"fn foo () {}");
}
#[test]
fn test_tuple_impls() {
// from https://github.com/rust-lang/rust/blob/316a391dcb7d66dc25f1f9a4ec9d368ef7615005/src/libcore/num/mod.rs#L12
let rules = create_rules(
r#"
macro_rules! tuple_impls {
($(
$Tuple:ident {
$(($idx:tt) -> $T:ident)+
}
)+) => {
$(
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T:PartialEq),+> PartialEq for ($($T,)+) where last_type!($($T,)+): ?Sized {
#[inline]
fn eq(&self, other: &($($T,)+)) -> bool {
$(self.$idx == other.$idx)&&+
}
#[inline]
fn ne(&self, other: &($($T,)+)) -> bool {
$(self.$idx != other.$idx)||+
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T:Eq),+> Eq for ($($T,)+) where last_type!($($T,)+): ?Sized {}
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T:PartialOrd + PartialEq),+> PartialOrd for ($($T,)+)
where last_type!($($T,)+): ?Sized {
#[inline]
fn partial_cmp(&self, other: &($($T,)+)) -> Option<Ordering> {
lexical_partial_cmp!($(self.$idx, other.$idx),+)
}
#[inline]
fn lt(&self, other: &($($T,)+)) -> bool {
lexical_ord!(lt, $(self.$idx, other.$idx),+)
}
#[inline]
fn le(&self, other: &($($T,)+)) -> bool {
lexical_ord!(le, $(self.$idx, other.$idx),+)
}
#[inline]
fn ge(&self, other: &($($T,)+)) -> bool {
lexical_ord!(ge, $(self.$idx, other.$idx),+)
}
#[inline]
fn gt(&self, other: &($($T,)+)) -> bool {
lexical_ord!(gt, $(self.$idx, other.$idx),+)
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T:Ord),+> Ord for ($($T,)+) where last_type!($($T,)+): ?Sized {
#[inline]
fn cmp(&self, other: &($($T,)+)) -> Ordering {
lexical_cmp!($(self.$idx, other.$idx),+)
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T:Default),+> Default for ($($T,)+) {
#[inline]
fn default() -> ($($T,)+) {
($({ let x: $T = Default::default(); x},)+)
}
}
)+
}
}"#,
);
assert_expansion(
&rules,
r#"tuple_impls ! {
Tuple1 {
( 0 ) -> A
}
Tuple2 {
( 0 ) -> A
( 1 ) -> B
}
Tuple3 {
( 0 ) -> A
( 1 ) -> B
( 2 ) -> C
}
Tuple4 {
( 0 ) -> A
( 1 ) -> B
( 2 ) -> C
( 3 ) -> D
}
Tuple5 {
( 0 ) -> A
( 1 ) -> B
( 2 ) -> C
( 3 ) -> D
( 4 ) -> E
}
Tuple6 {
( 0 ) -> A
( 1 ) -> B
( 2 ) -> C
( 3 ) -> D
( 4 ) -> E
( 5 ) -> F
}
Tuple7 {
( 0 ) -> A
( 1 ) -> B
( 2 ) -> C
( 3 ) -> D
( 4 ) -> E
( 5 ) -> F
( 6 ) -> G
}
Tuple8 {
( 0 ) -> A
( 1 ) -> B
( 2 ) -> C
( 3 ) -> D
( 4 ) -> E
( 5 ) -> F
( 6 ) -> G
( 7 ) -> H
}
Tuple9 {
( 0 ) -> A
( 1 ) -> B
( 2 ) -> C
( 3 ) -> D
( 4 ) -> E
( 5 ) -> F
( 6 ) -> G
( 7 ) -> H
( 8 ) -> I
}
Tuple10 {
( 0 ) -> A
( 1 ) -> B
( 2 ) -> C
( 3 ) -> D
( 4 ) -> E
( 5 ) -> F
( 6 ) -> G
( 7 ) -> H
( 8 ) -> I
( 9 ) -> J
}
Tuple11 {
( 0 ) -> A
( 1 ) -> B
( 2 ) -> C
( 3 ) -> D
( 4 ) -> E
( 5 ) -> F
( 6 ) -> G
( 7 ) -> H
( 8 ) -> I
( 9 ) -> J
( 10 ) -> K
}
Tuple12 {
( 0 ) -> A
( 1 ) -> B
( 2 ) -> C
( 3 ) -> D
( 4 ) -> E
( 5 ) -> F
( 6 ) -> G
( 7 ) -> H
( 8 ) -> I
( 9 ) -> J
( 10 ) -> K
( 11 ) -> L
}
}"#,
"fn foo () {}",
);
}
}