blob: 0f81816965658cadee4ba5910c29631f111997b6 [file] [log] [blame]
David Tolnaye5806852017-06-01 12:49:20 -07001extern crate proc_macro2;
2
3use proc_macro2::{Symbol, Literal, TokenStream};
4
5#[test]
6fn symbols() {
7 assert_eq!(Symbol::from("foo").as_str(), "foo");
8 assert_eq!(Symbol::from("bar").as_str(), "bar");
9}
10
11#[test]
12fn literals() {
13 assert_eq!(Literal::from("foo").to_string(), "\"foo\"");
14 assert_eq!(Literal::from("\"").to_string(), "\"\\\"\"");
15}
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}