blob: 5a8cba70966022f7701ec5b2e053bf8a4458a287 [file] [log] [blame]
David Tolnay7d8b3312019-03-10 01:26:11 -08001extern crate syn;
2
3mod features;
4
5#[macro_use]
6mod macros;
7
David Tolnay2beee042019-04-03 08:36:59 -07008use std::fmt::Debug;
David Tolnay7d8b3312019-03-10 01:26:11 -08009use syn::parse::Parse;
10use syn::{Meta, MetaList, MetaNameValue, NestedMeta};
David Tolnay7d8b3312019-03-10 01:26:11 -080011
12#[test]
13fn test_parse_meta_item_word() {
14 let code = "hello";
15
16 snapshot!(code as Meta);
17}
18
19#[test]
20fn test_parse_meta_name_value() {
21 test::<MetaNameValue>("foo = 5");
22}
23
24#[test]
25fn test_parse_meta_name_value_with_keyword() {
26 test::<MetaNameValue>("static = 5");
27}
28
29#[test]
30fn test_parse_meta_name_value_with_bool() {
31 test::<MetaNameValue>("true = 5");
32}
33
34#[test]
35fn test_parse_meta_item_list_lit() {
36 test::<MetaList>("foo(5)");
37}
38
39#[test]
40fn test_parse_meta_item_multiple() {
41 test::<MetaList>("foo(word, name = 5, list(name2 = 6), word2)");
42}
43
44#[test]
45fn test_parse_nested_meta() {
46 let code = "5";
47 snapshot!(code as NestedMeta);
48
49 let code = "list(name2 = 6)";
50 snapshot!(code as NestedMeta);
51}
52
53fn test<T>(input: &str)
54where
55 T: Parse + Into<Meta> + Debug,
56{
57 let inner = snapshot!(input as T);
58 let meta = snapshot!(input as Meta);
59
60 assert_eq!(meta, inner.into());
61}