blob: 6134c5439baa9644e612a8650e2cd282e1bb5ab6 [file] [log] [blame]
David Tolnayd741aa82018-04-04 07:53:04 -07001// Copyright 2018 Syn Developers
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9extern crate proc_macro2;
10extern crate syn;
11
David Tolnayc3f98562018-11-02 08:55:05 -070012mod features;
13
David Tolnay65fb5662018-05-20 20:02:28 -070014use proc_macro2::{Ident, Span, TokenStream};
David Tolnayd741aa82018-04-04 07:53:04 -070015use std::str::FromStr;
David Tolnayb6254182018-08-25 08:44:54 -040016use syn::parse::Error;
David Tolnayd741aa82018-04-04 07:53:04 -070017
David Tolnayad4b2472018-08-25 08:25:24 -040018fn parse(s: &str) -> Result<Ident, Error> {
David Tolnayd741aa82018-04-04 07:53:04 -070019 syn::parse2(TokenStream::from_str(s).unwrap())
20}
21
22fn new(s: &str) -> Ident {
23 Ident::new(s, Span::call_site())
24}
25
26#[test]
27fn ident_parse() {
28 parse("String").unwrap();
29}
30
31#[test]
32fn ident_parse_keyword() {
Alex Crichton3fec3932018-05-17 12:09:13 -070033 parse("abstract").unwrap_err();
David Tolnayd741aa82018-04-04 07:53:04 -070034}
35
36#[test]
37fn ident_parse_empty() {
38 parse("").unwrap_err();
39}
40
41#[test]
42fn ident_parse_lifetime() {
43 parse("'static").unwrap_err();
44}
45
46#[test]
47fn ident_parse_underscore() {
Alex Crichton3fec3932018-05-17 12:09:13 -070048 parse("_").unwrap_err();
David Tolnayd741aa82018-04-04 07:53:04 -070049}
50
51#[test]
52fn ident_parse_number() {
53 parse("255").unwrap_err();
54}
55
56#[test]
57fn ident_parse_invalid() {
58 parse("a#").unwrap_err();
59}
60
61#[test]
62fn ident_new() {
63 new("String");
64}
65
66#[test]
67fn ident_new_keyword() {
68 new("abstract");
69}
70
71#[test]
Alex Crichton499ed642018-05-17 11:02:02 -070072#[should_panic(expected = "use Option<Ident>")]
David Tolnayd741aa82018-04-04 07:53:04 -070073fn ident_new_empty() {
74 new("");
75}
76
77#[test]
Alex Crichton499ed642018-05-17 11:02:02 -070078#[should_panic(expected = "not a valid Ident")]
David Tolnayd741aa82018-04-04 07:53:04 -070079fn ident_new_lifetime() {
80 new("'static");
81}
82
83#[test]
David Tolnayd741aa82018-04-04 07:53:04 -070084fn ident_new_underscore() {
85 new("_");
86}
87
88#[test]
Alex Crichton499ed642018-05-17 11:02:02 -070089#[should_panic(expected = "use Literal instead")]
David Tolnayd741aa82018-04-04 07:53:04 -070090fn ident_new_number() {
91 new("255");
92}
93
94#[test]
Alex Crichton499ed642018-05-17 11:02:02 -070095#[should_panic(expected = "\"a#\" is not a valid Ident")]
David Tolnayd741aa82018-04-04 07:53:04 -070096fn ident_new_invalid() {
97 new("a#");
98}