1#![allow( 2 clippy::shadow_unrelated, 3 clippy::too_many_lines, 4 clippy::uninlined_format_args 5)] 6 7#[macro_use] 8mod macros; 9 10use syn::{Meta, MetaList, MetaNameValue}; 11 12#[test] 13fn test_parse_meta_item_word() { 14 let input = "hello"; 15 16 snapshot!(input as Meta, @r###" 17 Meta::Path { 18 segments: [ 19 PathSegment { 20 ident: "hello", 21 }, 22 ], 23 } 24 "###); 25} 26 27#[test] 28fn test_parse_meta_name_value() { 29 let input = "foo = 5"; 30 let (inner, meta) = (input, input); 31 32 snapshot!(inner as MetaNameValue, @r###" 33 MetaNameValue { 34 path: Path { 35 segments: [ 36 PathSegment { 37 ident: "foo", 38 }, 39 ], 40 }, 41 value: Expr::Lit { 42 lit: 5, 43 }, 44 } 45 "###); 46 47 snapshot!(meta as Meta, @r###" 48 Meta::NameValue { 49 path: Path { 50 segments: [ 51 PathSegment { 52 ident: "foo", 53 }, 54 ], 55 }, 56 value: Expr::Lit { 57 lit: 5, 58 }, 59 } 60 "###); 61 62 assert_eq!(meta, inner.into()); 63} 64 65#[test] 66fn test_parse_meta_item_list_lit() { 67 let input = "foo(5)"; 68 let (inner, meta) = (input, input); 69 70 snapshot!(inner as MetaList, @r###" 71 MetaList { 72 path: Path { 73 segments: [ 74 PathSegment { 75 ident: "foo", 76 }, 77 ], 78 }, 79 delimiter: MacroDelimiter::Paren, 80 tokens: TokenStream(`5`), 81 } 82 "###); 83 84 snapshot!(meta as Meta, @r###" 85 Meta::List { 86 path: Path { 87 segments: [ 88 PathSegment { 89 ident: "foo", 90 }, 91 ], 92 }, 93 delimiter: MacroDelimiter::Paren, 94 tokens: TokenStream(`5`), 95 } 96 "###); 97 98 assert_eq!(meta, inner.into()); 99} 100 101#[test] 102fn test_parse_meta_item_multiple() { 103 let input = "foo(word, name = 5, list(name2 = 6), word2)"; 104 let (inner, meta) = (input, input); 105 106 snapshot!(inner as MetaList, @r###" 107 MetaList { 108 path: Path { 109 segments: [ 110 PathSegment { 111 ident: "foo", 112 }, 113 ], 114 }, 115 delimiter: MacroDelimiter::Paren, 116 tokens: TokenStream(`word , name = 5 , list (name2 = 6) , word2`), 117 } 118 "###); 119 120 snapshot!(meta as Meta, @r###" 121 Meta::List { 122 path: Path { 123 segments: [ 124 PathSegment { 125 ident: "foo", 126 }, 127 ], 128 }, 129 delimiter: MacroDelimiter::Paren, 130 tokens: TokenStream(`word , name = 5 , list (name2 = 6) , word2`), 131 } 132 "###); 133 134 assert_eq!(meta, inner.into()); 135} 136 137#[test] 138fn test_parse_path() { 139 let input = "::serde::Serialize"; 140 snapshot!(input as Meta, @r###" 141 Meta::Path { 142 leading_colon: Some, 143 segments: [ 144 PathSegment { 145 ident: "serde", 146 }, 147 Token![::], 148 PathSegment { 149 ident: "Serialize", 150 }, 151 ], 152 } 153 "###); 154} 155