2021-09-30 05:52:30 +00:00
|
|
|
#![allow(clippy::non_ascii_literal)]
|
|
|
|
|
2020-02-24 21:55:39 +00:00
|
|
|
#[macro_use]
|
|
|
|
mod macros;
|
|
|
|
|
2020-11-01 18:23:25 +00:00
|
|
|
use proc_macro2::{Delimiter, Group, Ident, Span, TokenStream, TokenTree};
|
|
|
|
use std::iter::FromIterator;
|
2020-02-24 21:55:39 +00:00
|
|
|
use syn::Stmt;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_raw_operator() {
|
|
|
|
let stmt = syn::parse_str::<Stmt>("let _ = &raw const x;").unwrap();
|
|
|
|
|
|
|
|
snapshot!(stmt, @r###"
|
|
|
|
Local(Local {
|
|
|
|
pat: Pat::Wild,
|
2020-05-26 22:34:14 +00:00
|
|
|
init: Some(Verbatim(`& raw const x`)),
|
2020-02-24 21:55:39 +00:00
|
|
|
})
|
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_raw_variable() {
|
|
|
|
let stmt = syn::parse_str::<Stmt>("let _ = &raw;").unwrap();
|
|
|
|
|
|
|
|
snapshot!(stmt, @r###"
|
|
|
|
Local(Local {
|
|
|
|
pat: Pat::Wild,
|
|
|
|
init: Some(Expr::Reference {
|
|
|
|
expr: Expr::Path {
|
|
|
|
path: Path {
|
|
|
|
segments: [
|
|
|
|
PathSegment {
|
|
|
|
ident: "raw",
|
|
|
|
arguments: None,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_raw_invalid() {
|
|
|
|
assert!(syn::parse_str::<Stmt>("let _ = &raw x;").is_err());
|
|
|
|
}
|
2020-11-01 18:23:25 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_none_group() {
|
|
|
|
// <Ø async fn f() {} Ø>
|
|
|
|
let tokens = TokenStream::from_iter(vec![TokenTree::Group(Group::new(
|
|
|
|
Delimiter::None,
|
|
|
|
TokenStream::from_iter(vec![
|
|
|
|
TokenTree::Ident(Ident::new("async", Span::call_site())),
|
|
|
|
TokenTree::Ident(Ident::new("fn", Span::call_site())),
|
|
|
|
TokenTree::Ident(Ident::new("f", Span::call_site())),
|
|
|
|
TokenTree::Group(Group::new(Delimiter::Parenthesis, TokenStream::new())),
|
|
|
|
TokenTree::Group(Group::new(Delimiter::Brace, TokenStream::new())),
|
|
|
|
]),
|
|
|
|
))]);
|
|
|
|
|
|
|
|
snapshot!(tokens as Stmt, @r###"
|
|
|
|
Item(Item::Fn {
|
|
|
|
vis: Inherited,
|
|
|
|
sig: Signature {
|
|
|
|
asyncness: Some,
|
|
|
|
ident: "f",
|
|
|
|
generics: Generics,
|
|
|
|
output: Default,
|
|
|
|
},
|
|
|
|
block: Block,
|
|
|
|
})
|
|
|
|
"###);
|
|
|
|
}
|