blob: 4d6831b3b4775f8d84403c78f4099fb8e1546727 [file] [log] [blame]
David Tolnaye5806852017-06-01 12:49:20 -07001extern crate proc_macro2;
2
Alex Crichton1a7f7622017-07-05 17:47:15 -07003use proc_macro2::{Term, Literal, TokenStream};
David Tolnaye5806852017-06-01 12:49:20 -07004
5#[test]
6fn symbols() {
Alex Crichton1a7f7622017-07-05 17:47:15 -07007 assert_eq!(Term::intern("foo").as_str(), "foo");
8 assert_eq!(Term::intern("bar").as_str(), "bar");
David Tolnaye5806852017-06-01 12:49:20 -07009}
10
11#[test]
12fn literals() {
Alex Crichton1a7f7622017-07-05 17:47:15 -070013 assert_eq!(Literal::string("foo").to_string(), "\"foo\"");
14 assert_eq!(Literal::string("\"").to_string(), "\"\\\"\"");
David Tolnaye5806852017-06-01 12:49:20 -070015}
16
17#[test]
18fn roundtrip() {
19 fn roundtrip(p: &str) {
20 println!("parse: {}", p);
21 let s = p.parse::<TokenStream>().unwrap().to_string();
22 println!("first: {}", s);
23 let s2 = s.to_string().parse::<TokenStream>().unwrap().to_string();
24 assert_eq!(s, s2);
25 }
26 roundtrip("a");
27 roundtrip("<<");
28 roundtrip("<<=");
29 roundtrip("
30 /// a
31 wut
32 ");
33 roundtrip("
34 1
35 1.0
36 1f32
37 2f64
38 1usize
39 4isize
40 4e10
41 1_000
42 1_0i32
43 8u8
44 9
45 0
46 0xffffffffffffffffffffffffffffffff
47 ");
48 roundtrip("'a");
49 roundtrip("'static");
50}
51
52#[test]
53fn fail() {
54 fn fail(p: &str) {
55 if p.parse::<TokenStream>().is_ok() {
56 panic!("should have failed to parse: {}", p);
57 }
58 }
59 fail("1x");
60 fail("1u80");
61 fail("1f320");
62 fail("' static");
63 fail("'mut");
64}