Skip to content

Commit

Permalink
Merge pull request #1556 from dtolnay/punctuatedsnapshot
Browse files Browse the repository at this point in the history
Include punctuation tokens in snapshot tests containing Punctuated
  • Loading branch information
dtolnay committed Dec 25, 2023
2 parents af53f20 + 131b40b commit f9ad833
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 16 deletions.
16 changes: 2 additions & 14 deletions tests/debug/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use proc_macro2::{Ident, Literal, TokenStream};
use ref_cast::RefCast;
use std::fmt::{self, Debug};
use std::ops::Deref;
use syn::punctuated::{self, Punctuated};
use syn::punctuated::Punctuated;

#[derive(RefCast)]
#[repr(transparent)]
Expand Down Expand Up @@ -113,25 +113,13 @@ where
}

impl<T, P> Debug for Lite<Punctuated<T, P>>
where
Lite<T>: Debug,
{
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
.debug_list()
.entries(self.value.iter().map(Lite))
.finish()
}
}

impl<'a, T, P> Debug for Lite<punctuated::Pairs<'a, T, P>>
where
Lite<T>: Debug,
Lite<P>: Debug,
{
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
let mut list = formatter.debug_list();
for pair in self.value.clone() {
for pair in self.pairs() {
let (node, punct) = pair.into_tuple();
list.entry(Lite(node));
list.entries(punct.map(Lite));
Expand Down
14 changes: 14 additions & 0 deletions tests/test_derive_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ fn test_struct() {
},
},
},
Token![,],
Field {
vis: Visibility::Public,
ident: Some("attrs"),
Expand Down Expand Up @@ -157,6 +158,7 @@ fn test_union() {
colon_token: Some,
ty: Type::Tuple,
},
Token![,],
Field {
vis: Visibility::Inherited,
ident: Some("value"),
Expand Down Expand Up @@ -232,6 +234,7 @@ fn test_enum() {
GenericParam::Type(TypeParam {
ident: "T",
}),
Token![,],
GenericParam::Type(TypeParam {
ident: "E",
}),
Expand Down Expand Up @@ -259,6 +262,7 @@ fn test_enum() {
],
},
},
Token![,],
Variant {
ident: "Err",
fields: Fields::Unnamed {
Expand All @@ -278,13 +282,15 @@ fn test_enum() {
],
},
},
Token![,],
Variant {
ident: "Surprise",
fields: Fields::Unit,
discriminant: Some(Expr::Lit {
lit: 0isize,
}),
},
Token![,],
Variant {
ident: "ProcMacroHack",
fields: Fields::Unit,
Expand All @@ -294,6 +300,7 @@ fn test_enum() {
Expr::Lit {
lit: 0,
},
Token![,],
Expr::Lit {
lit: "data",
},
Expand Down Expand Up @@ -363,6 +370,7 @@ fn test_attr_with_mod_style_path_with_self() {
PathSegment {
ident: "foo",
},
Token![::],
PathSegment {
ident: "self",
},
Expand All @@ -386,6 +394,7 @@ fn test_attr_with_mod_style_path_with_self() {
PathSegment {
ident: "foo",
},
Token![::],
PathSegment {
ident: "self",
},
Expand Down Expand Up @@ -426,6 +435,7 @@ fn test_pub_restricted() {
PathSegment {
ident: "m",
},
Token![::],
PathSegment {
ident: "n",
},
Expand Down Expand Up @@ -589,6 +599,7 @@ fn test_fields_on_named_struct() {
},
},
},
Token![,],
Field {
vis: Visibility::Public,
ident: Some("bar"),
Expand All @@ -603,6 +614,7 @@ fn test_fields_on_named_struct() {
},
},
},
Token![,],
],
},
},
Expand Down Expand Up @@ -674,6 +686,7 @@ fn test_fields_on_tuple_struct() {
},
},
},
Token![,],
Field {
vis: Visibility::Public,
ty: Type::Path {
Expand Down Expand Up @@ -751,6 +764,7 @@ fn test_ambiguous_crate() {
PathSegment {
ident: "crate",
},
Token![::],
PathSegment {
ident: "X",
},
Expand Down
5 changes: 5 additions & 0 deletions tests/test_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ fn test_extended_interpolated_path() {
PathSegment {
ident: "a",
},
Token![::],
PathSegment {
ident: "b",
},
Expand All @@ -411,6 +412,7 @@ fn test_extended_interpolated_path() {
PathSegment {
ident: "a",
},
Token![::],
PathSegment {
ident: "b",
},
Expand All @@ -427,9 +429,11 @@ fn test_extended_interpolated_path() {
PathSegment {
ident: "a",
},
Token![::],
PathSegment {
ident: "b",
},
Token![::],
PathSegment {
ident: "c",
},
Expand All @@ -451,6 +455,7 @@ fn test_extended_interpolated_path() {
PathSegment {
ident: "a",
},
Token![::],
PathSegment {
ident: "b",
},
Expand Down
4 changes: 4 additions & 0 deletions tests/test_generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ fn test_split_for_impl() {
ident: "a",
},
}),
Token![,],
GenericParam::Lifetime(LifetimeParam {
lifetime: Lifetime {
ident: "b",
Expand All @@ -39,6 +40,7 @@ fn test_split_for_impl() {
},
],
}),
Token![,],
GenericParam::Type(TypeParam {
attrs: [
Attribute {
Expand Down Expand Up @@ -227,6 +229,7 @@ fn test_fn_precedence_in_where_clause() {
],
},
}),
Token![+],
TypeParamBound::Trait(TraitBound {
path: Path {
segments: [
Expand All @@ -238,6 +241,7 @@ fn test_fn_precedence_in_where_clause() {
}),
],
}),
Token![,],
],
}),
},
Expand Down
2 changes: 2 additions & 0 deletions tests/test_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ fn test_supertraits() {
],
},
}),
Token![+],
],
}
"###);
Expand Down Expand Up @@ -318,6 +319,7 @@ fn test_impl_trait_trailing_plus() {
],
},
}),
Token![+],
],
},
),
Expand Down
1 change: 1 addition & 0 deletions tests/test_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ fn test_parse_path() {
PathSegment {
ident: "serde",
},
Token![::],
PathSegment {
ident: "Serialize",
},
Expand Down
6 changes: 4 additions & 2 deletions tests/test_parse_quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ fn test_field() {
PathSegment {
ident: "primitive",
},
Token![::],
PathSegment {
ident: "bool",
},
Expand Down Expand Up @@ -97,6 +98,7 @@ fn test_pat() {
}),
],
},
Token![|],
Pat::Ident {
ident: "None",
},
Expand All @@ -111,7 +113,7 @@ fn test_pat() {
#[test]
fn test_punctuated() {
let punctuated: Punctuated<Lit, Token![|]> = parse_quote!(true | true);
snapshot!(punctuated.pairs(), @r###"
snapshot!(punctuated, @r###"
[
Lit::Bool {
value: true,
Expand All @@ -124,7 +126,7 @@ fn test_punctuated() {
"###);

let punctuated: Punctuated<Lit, Token![|]> = parse_quote!(true | true |);
snapshot!(punctuated.pairs(), @r###"
snapshot!(punctuated, @r###"
[
Lit::Bool {
value: true,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fn parse_interpolated_leading_component() {
PathSegment {
ident: "first",
},
Token![::],
PathSegment {
ident: "rest",
},
Expand All @@ -39,6 +40,7 @@ fn parse_interpolated_leading_component() {
PathSegment {
ident: "first",
},
Token![::],
PathSegment {
ident: "rest",
},
Expand Down
6 changes: 6 additions & 0 deletions tests/test_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ fn test_group_colons() {
],
},
},
Token![::],
PathSegment {
ident: "Item",
},
Expand Down Expand Up @@ -245,6 +246,7 @@ fn test_trait_object() {
],
},
}),
Token![+],
TypeParamBound::Lifetime {
ident: "static",
},
Expand All @@ -260,6 +262,7 @@ fn test_trait_object() {
TypeParamBound::Lifetime {
ident: "a",
},
Token![+],
TypeParamBound::Trait(TraitBound {
path: Path {
segments: [
Expand Down Expand Up @@ -294,6 +297,7 @@ fn test_trailing_plus() {
],
},
}),
Token![+],
],
}
"###);
Expand All @@ -313,6 +317,7 @@ fn test_trailing_plus() {
],
},
}),
Token![+],
],
}
"###);
Expand All @@ -331,6 +336,7 @@ fn test_trailing_plus() {
],
},
}),
Token![+],
],
}
"###);
Expand Down

0 comments on commit f9ad833

Please sign in to comment.