blob: bec00a70c99c4a6acf2b1741546db21a1522c647 [file] [log] [blame]
David Tolnayd741aa82018-04-04 07:53:04 -07001extern crate proc_macro2;
2extern crate syn;
3
David Tolnayc3f98562018-11-02 08:55:05 -07004mod features;
5
David Tolnay65fb5662018-05-20 20:02:28 -07006use proc_macro2::{Ident, Span, TokenStream};
David Tolnayd741aa82018-04-04 07:53:04 -07007use std::str::FromStr;
David Tolnay67fea042018-11-24 14:50:20 -08008use syn::Result;
David Tolnayd741aa82018-04-04 07:53:04 -07009
David Tolnay67fea042018-11-24 14:50:20 -080010fn parse(s: &str) -> Result<Ident> {
David Tolnayd741aa82018-04-04 07:53:04 -070011 syn::parse2(TokenStream::from_str(s).unwrap())
12}
13
14fn new(s: &str) -> Ident {
15 Ident::new(s, Span::call_site())
16}
17
18#[test]
19fn ident_parse() {
20 parse("String").unwrap();
21}
22
23#[test]
24fn ident_parse_keyword() {
Alex Crichton3fec3932018-05-17 12:09:13 -070025 parse("abstract").unwrap_err();
David Tolnayd741aa82018-04-04 07:53:04 -070026}
27
28#[test]
29fn ident_parse_empty() {
30 parse("").unwrap_err();
31}
32
33#[test]
34fn ident_parse_lifetime() {
35 parse("'static").unwrap_err();
36}
37
38#[test]
39fn ident_parse_underscore() {
Alex Crichton3fec3932018-05-17 12:09:13 -070040 parse("_").unwrap_err();
David Tolnayd741aa82018-04-04 07:53:04 -070041}
42
43#[test]
44fn ident_parse_number() {
45 parse("255").unwrap_err();
46}
47
48#[test]
49fn ident_parse_invalid() {
50 parse("a#").unwrap_err();
51}
52
53#[test]
54fn ident_new() {
55 new("String");
56}
57
58#[test]
59fn ident_new_keyword() {
60 new("abstract");
61}
62
63#[test]
Alex Crichton499ed642018-05-17 11:02:02 -070064#[should_panic(expected = "use Option<Ident>")]
David Tolnayd741aa82018-04-04 07:53:04 -070065fn ident_new_empty() {
66 new("");
67}
68
69#[test]
Alex Crichton499ed642018-05-17 11:02:02 -070070#[should_panic(expected = "not a valid Ident")]
David Tolnayd741aa82018-04-04 07:53:04 -070071fn ident_new_lifetime() {
72 new("'static");
73}
74
75#[test]
David Tolnayd741aa82018-04-04 07:53:04 -070076fn ident_new_underscore() {
77 new("_");
78}
79
80#[test]
Alex Crichton499ed642018-05-17 11:02:02 -070081#[should_panic(expected = "use Literal instead")]
David Tolnayd741aa82018-04-04 07:53:04 -070082fn ident_new_number() {
83 new("255");
84}
85
86#[test]
Alex Crichton499ed642018-05-17 11:02:02 -070087#[should_panic(expected = "\"a#\" is not a valid Ident")]
David Tolnayd741aa82018-04-04 07:53:04 -070088fn ident_new_invalid() {
89 new("a#");
90}