1use proc_macro2::{Ident, Span, TokenStream};
2use std::str::FromStr;
3use syn::Result;
4
5fn parse(s: &str) -> Result<Ident> {
6 syn::parse2(TokenStream::from_str(s).unwrap())
7}
8
9fn new(s: &str) -> Ident {
10 Ident::new(s, Span::call_site())
11}
12
13#[test]
14fn ident_parse() {
15 parse("String").unwrap();
16}
17
18#[test]
19fn ident_parse_keyword() {
20 parse("abstract").unwrap_err();
21}
22
23#[test]
24fn ident_parse_empty() {
25 parse("").unwrap_err();
26}
27
28#[test]
29fn ident_parse_lifetime() {
30 parse("'static").unwrap_err();
31}
32
33#[test]
34fn ident_parse_underscore() {
35 parse("_").unwrap_err();
36}
37
38#[test]
39fn ident_parse_number() {
40 parse("255").unwrap_err();
41}
42
43#[test]
44fn ident_parse_invalid() {
45 parse("a#").unwrap_err();
46}
47
48#[test]
49fn ident_new() {
50 new("String");
51}
52
53#[test]
54fn ident_new_keyword() {
55 new("abstract");
56}
57
58#[test]
59#[should_panic(expected = "use Option<Ident>")]
60fn ident_new_empty() {
61 new("");
62}
63
64#[test]
65#[should_panic(expected = "not a valid Ident")]
66fn ident_new_lifetime() {
67 new("'static");
68}
69
70#[test]
71fn ident_new_underscore() {
72 new("_");
73}
74
75#[test]
76#[should_panic(expected = "use Literal instead")]
77fn ident_new_number() {
78 new("255");
79}
80
81#[test]
82#[should_panic(expected = "\"a#\" is not a valid Ident")]
83fn ident_new_invalid() {
84 new("a#");
85}
86