Move all use of snapshot to inline
diff --git a/tests/test_generics.rs b/tests/test_generics.rs
index 112215a..27b204e 100644
--- a/tests/test_generics.rs
+++ b/tests/test_generics.rs
@@ -11,13 +11,98 @@
#[test]
fn test_split_for_impl() {
- let code = quote! {
+ let input = quote! {
struct S<'a, 'b: 'a, #[may_dangle] T: 'a = ()> where T: Debug;
};
- let actual = snapshot!(code as DeriveInput);
+ snapshot!(input as DeriveInput, @r###"
+ ⋮DeriveInput {
+ ⋮ vis: Inherited,
+ ⋮ ident: "S",
+ ⋮ generics: Generics {
+ ⋮ lt_token: Some,
+ ⋮ params: [
+ ⋮ Lifetime(LifetimeDef {
+ ⋮ lifetime: Lifetime {
+ ⋮ ident: "a",
+ ⋮ },
+ ⋮ }),
+ ⋮ Lifetime(LifetimeDef {
+ ⋮ lifetime: Lifetime {
+ ⋮ ident: "b",
+ ⋮ },
+ ⋮ colon_token: Some,
+ ⋮ bounds: [
+ ⋮ Lifetime {
+ ⋮ ident: "a",
+ ⋮ },
+ ⋮ ],
+ ⋮ }),
+ ⋮ Type(TypeParam {
+ ⋮ attrs: [
+ ⋮ Attribute {
+ ⋮ style: Outer,
+ ⋮ path: Path {
+ ⋮ segments: [
+ ⋮ PathSegment {
+ ⋮ ident: "may_dangle",
+ ⋮ arguments: None,
+ ⋮ },
+ ⋮ ],
+ ⋮ },
+ ⋮ tts: ``,
+ ⋮ },
+ ⋮ ],
+ ⋮ ident: "T",
+ ⋮ colon_token: Some,
+ ⋮ bounds: [
+ ⋮ Lifetime(Lifetime {
+ ⋮ ident: "a",
+ ⋮ }),
+ ⋮ ],
+ ⋮ eq_token: Some,
+ ⋮ default: Some(Type::Tuple),
+ ⋮ }),
+ ⋮ ],
+ ⋮ gt_token: Some,
+ ⋮ where_clause: Some(WhereClause {
+ ⋮ predicates: [
+ ⋮ Type(PredicateType {
+ ⋮ bounded_ty: Type::Path {
+ ⋮ path: Path {
+ ⋮ segments: [
+ ⋮ PathSegment {
+ ⋮ ident: "T",
+ ⋮ arguments: None,
+ ⋮ },
+ ⋮ ],
+ ⋮ },
+ ⋮ },
+ ⋮ bounds: [
+ ⋮ Trait(TraitBound {
+ ⋮ modifier: None,
+ ⋮ path: Path {
+ ⋮ segments: [
+ ⋮ PathSegment {
+ ⋮ ident: "Debug",
+ ⋮ arguments: None,
+ ⋮ },
+ ⋮ ],
+ ⋮ },
+ ⋮ }),
+ ⋮ ],
+ ⋮ }),
+ ⋮ ],
+ ⋮ }),
+ ⋮ },
+ ⋮ data: Data::Struct {
+ ⋮ fields: Unit,
+ ⋮ semi_token: Some,
+ ⋮ },
+ ⋮}
+ "###);
- let generics = actual.generics;
+ let generics = input.generics;
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
let generated = quote! {
@@ -45,23 +130,55 @@
#[test]
fn test_ty_param_bound() {
let tokens = quote!('a);
- snapshot!(tokens as TypeParamBound);
+ snapshot!(tokens as TypeParamBound, @r###"
+ ⋮Lifetime(Lifetime {
+ ⋮ ident: "a",
+ ⋮})
+ "###);
let tokens = quote!('_);
- snapshot!(tokens as TypeParamBound);
+ snapshot!(tokens as TypeParamBound, @r###"
+ ⋮Lifetime(Lifetime {
+ ⋮ ident: "_",
+ ⋮})
+ "###);
let tokens = quote!(Debug);
- snapshot!(tokens as TypeParamBound);
+ snapshot!(tokens as TypeParamBound, @r###"
+ ⋮Trait(TraitBound {
+ ⋮ modifier: None,
+ ⋮ path: Path {
+ ⋮ segments: [
+ ⋮ PathSegment {
+ ⋮ ident: "Debug",
+ ⋮ arguments: None,
+ ⋮ },
+ ⋮ ],
+ ⋮ },
+ ⋮})
+ "###);
let tokens = quote!(?Sized);
- snapshot!(tokens as TypeParamBound);
+ snapshot!(tokens as TypeParamBound, @r###"
+ ⋮Trait(TraitBound {
+ ⋮ modifier: Maybe,
+ ⋮ path: Path {
+ ⋮ segments: [
+ ⋮ PathSegment {
+ ⋮ ident: "Sized",
+ ⋮ arguments: None,
+ ⋮ },
+ ⋮ ],
+ ⋮ },
+ ⋮})
+ "###);
}
#[test]
fn test_fn_precedence_in_where_clause() {
// This should parse as two separate bounds, `FnOnce() -> i32` and `Send` - not
// `FnOnce() -> (i32 + Send)`.
- let code = quote! {
+ let input = quote! {
fn f<G>()
where
G: FnOnce() -> i32 + Send,
@@ -69,9 +186,80 @@
}
};
- let actual = snapshot!(code as ItemFn);
+ snapshot!(input as ItemFn, @r###"
+ ⋮ItemFn {
+ ⋮ vis: Inherited,
+ ⋮ ident: "f",
+ ⋮ decl: FnDecl {
+ ⋮ generics: Generics {
+ ⋮ lt_token: Some,
+ ⋮ params: [
+ ⋮ Type(TypeParam {
+ ⋮ ident: "G",
+ ⋮ }),
+ ⋮ ],
+ ⋮ gt_token: Some,
+ ⋮ where_clause: Some(WhereClause {
+ ⋮ predicates: [
+ ⋮ Type(PredicateType {
+ ⋮ bounded_ty: Type::Path {
+ ⋮ path: Path {
+ ⋮ segments: [
+ ⋮ PathSegment {
+ ⋮ ident: "G",
+ ⋮ arguments: None,
+ ⋮ },
+ ⋮ ],
+ ⋮ },
+ ⋮ },
+ ⋮ bounds: [
+ ⋮ Trait(TraitBound {
+ ⋮ modifier: None,
+ ⋮ path: Path {
+ ⋮ segments: [
+ ⋮ PathSegment {
+ ⋮ ident: "FnOnce",
+ ⋮ arguments: PathArguments::Parenthesized {
+ ⋮ output: Type(
+ ⋮ Type::Path {
+ ⋮ path: Path {
+ ⋮ segments: [
+ ⋮ PathSegment {
+ ⋮ ident: "i32",
+ ⋮ arguments: None,
+ ⋮ },
+ ⋮ ],
+ ⋮ },
+ ⋮ },
+ ⋮ ),
+ ⋮ },
+ ⋮ },
+ ⋮ ],
+ ⋮ },
+ ⋮ }),
+ ⋮ Trait(TraitBound {
+ ⋮ modifier: None,
+ ⋮ path: Path {
+ ⋮ segments: [
+ ⋮ PathSegment {
+ ⋮ ident: "Send",
+ ⋮ arguments: None,
+ ⋮ },
+ ⋮ ],
+ ⋮ },
+ ⋮ }),
+ ⋮ ],
+ ⋮ }),
+ ⋮ ],
+ ⋮ }),
+ ⋮ },
+ ⋮ output: Default,
+ ⋮ },
+ ⋮ block: Block,
+ ⋮}
+ "###);
- let where_clause = actual.decl.generics.where_clause.as_ref().unwrap();
+ let where_clause = input.decl.generics.where_clause.as_ref().unwrap();
assert_eq!(where_clause.predicates.len(), 1);
let predicate = match &where_clause.predicates[0] {
@@ -90,10 +278,11 @@
#[test]
fn test_where_clause_at_end_of_input() {
- let tokens = quote! {
+ let input = quote! {
where
};
- let where_clause = snapshot!(tokens as WhereClause);
- assert_eq!(where_clause.predicates.len(), 0);
+ snapshot!(input as WhereClause, @"WhereClause");
+
+ assert_eq!(input.predicates.len(), 0);
}