• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #![allow(clippy::assertions_on_result_states, clippy::non_ascii_literal)]
2 
3 #[macro_use]
4 mod macros;
5 
6 use proc_macro2::{Delimiter, Group, Ident, Span, TokenStream, TokenTree};
7 use quote::quote;
8 use std::iter::FromIterator;
9 use syn::Stmt;
10 
11 #[test]
test_raw_operator()12 fn test_raw_operator() {
13     let stmt = syn::parse_str::<Stmt>("let _ = &raw const x;").unwrap();
14 
15     snapshot!(stmt, @r###"
16     Local(Local {
17         pat: Pat::Wild,
18         init: Some(Verbatim(`& raw const x`)),
19     })
20     "###);
21 }
22 
23 #[test]
test_raw_variable()24 fn test_raw_variable() {
25     let stmt = syn::parse_str::<Stmt>("let _ = &raw;").unwrap();
26 
27     snapshot!(stmt, @r###"
28     Local(Local {
29         pat: Pat::Wild,
30         init: Some(Expr::Reference {
31             expr: Expr::Path {
32                 path: Path {
33                     segments: [
34                         PathSegment {
35                             ident: "raw",
36                             arguments: None,
37                         },
38                     ],
39                 },
40             },
41         }),
42     })
43     "###);
44 }
45 
46 #[test]
test_raw_invalid()47 fn test_raw_invalid() {
48     assert!(syn::parse_str::<Stmt>("let _ = &raw x;").is_err());
49 }
50 
51 #[test]
test_none_group()52 fn test_none_group() {
53     // <Ø async fn f() {} Ø>
54     let tokens = TokenStream::from_iter(vec![TokenTree::Group(Group::new(
55         Delimiter::None,
56         TokenStream::from_iter(vec![
57             TokenTree::Ident(Ident::new("async", Span::call_site())),
58             TokenTree::Ident(Ident::new("fn", Span::call_site())),
59             TokenTree::Ident(Ident::new("f", Span::call_site())),
60             TokenTree::Group(Group::new(Delimiter::Parenthesis, TokenStream::new())),
61             TokenTree::Group(Group::new(Delimiter::Brace, TokenStream::new())),
62         ]),
63     ))]);
64 
65     snapshot!(tokens as Stmt, @r###"
66     Item(Item::Fn {
67         vis: Inherited,
68         sig: Signature {
69             asyncness: Some,
70             ident: "f",
71             generics: Generics,
72             output: Default,
73         },
74         block: Block,
75     })
76     "###);
77 }
78 
79 #[test]
test_let_dot_dot()80 fn test_let_dot_dot() {
81     let tokens = quote! {
82         let .. = 10;
83     };
84 
85     snapshot!(tokens as Stmt, @r###"
86     Local(Local {
87         pat: Pat::Rest,
88         init: Some(Expr::Lit {
89             lit: 10,
90         }),
91     })
92     "###);
93 }
94