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