1#![allow(clippy::assertions_on_result_states, clippy::non_ascii_literal)]
2
3#[macro_use]
4mod macros;
5
6use proc_macro2::{Delimiter, Group, Ident, Span, TokenStream, TokenTree};
7use quote::quote;
8use std::iter::FromIterator;
9use syn::Stmt;
10
11#[test]
12fn 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]
24fn 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]
47fn test_raw_invalid() {
48 assert!(syn::parse_str::<Stmt>("let _ = &raw x;").is_err());
49}
50
51#[test]
52fn 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]
80fn 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