Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/syn/tests/test_meta.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / syn / tests / test_meta.rs` 180 lines ยท 3737 bytes Raw Blame History 1 #![allow( 2 clippy::elidable_lifetime_names, 3 clippy::needless_lifetimes, 4 clippy::shadow_unrelated, 5 clippy::too_many_lines, 6 clippy::uninlined_format_args 7 )] 8 9 #[macro_use] 10 mod snapshot; 11 12 mod debug; 13 14 use quote::quote; 15 use syn::parse::{ParseStream, Parser as _, Result}; 16 use syn::{Meta, MetaList, MetaNameValue, Token}; 17 18 #[test] 19 fn test_parse_meta_item_word() { 20 let input = "hello"; 21 22 snapshot!(input as Meta, @r#" 23 Meta::Path { 24 segments: [ 25 PathSegment { 26 ident: "hello", 27 }, 28 ], 29 } 30 "#); 31 } 32 33 #[test] 34 fn test_parse_meta_name_value() { 35 let input = "foo = 5"; 36 let (inner, meta) = (input, input); 37 38 snapshot!(inner as MetaNameValue, @r#" 39 MetaNameValue { 40 path: Path { 41 segments: [ 42 PathSegment { 43 ident: "foo", 44 }, 45 ], 46 }, 47 value: Expr::Lit { 48 lit: 5, 49 }, 50 } 51 "#); 52 53 snapshot!(meta as Meta, @r#" 54 Meta::NameValue { 55 path: Path { 56 segments: [ 57 PathSegment { 58 ident: "foo", 59 }, 60 ], 61 }, 62 value: Expr::Lit { 63 lit: 5, 64 }, 65 } 66 "#); 67 68 assert_eq!(meta, Meta::NameValue(inner)); 69 } 70 71 #[test] 72 fn test_parse_meta_item_list_lit() { 73 let input = "foo(5)"; 74 let (inner, meta) = (input, input); 75 76 snapshot!(inner as MetaList, @r#" 77 MetaList { 78 path: Path { 79 segments: [ 80 PathSegment { 81 ident: "foo", 82 }, 83 ], 84 }, 85 delimiter: MacroDelimiter::Paren, 86 tokens: TokenStream(`5`), 87 } 88 "#); 89 90 snapshot!(meta as Meta, @r#" 91 Meta::List { 92 path: Path { 93 segments: [ 94 PathSegment { 95 ident: "foo", 96 }, 97 ], 98 }, 99 delimiter: MacroDelimiter::Paren, 100 tokens: TokenStream(`5`), 101 } 102 "#); 103 104 assert_eq!(meta, Meta::List(inner)); 105 } 106 107 #[test] 108 fn test_parse_meta_item_multiple() { 109 let input = "foo(word, name = 5, list(name2 = 6), word2)"; 110 let (inner, meta) = (input, input); 111 112 snapshot!(inner as MetaList, @r#" 113 MetaList { 114 path: Path { 115 segments: [ 116 PathSegment { 117 ident: "foo", 118 }, 119 ], 120 }, 121 delimiter: MacroDelimiter::Paren, 122 tokens: TokenStream(`word , name = 5 , list (name2 = 6) , word2`), 123 } 124 "#); 125 126 snapshot!(meta as Meta, @r#" 127 Meta::List { 128 path: Path { 129 segments: [ 130 PathSegment { 131 ident: "foo", 132 }, 133 ], 134 }, 135 delimiter: MacroDelimiter::Paren, 136 tokens: TokenStream(`word , name = 5 , list (name2 = 6) , word2`), 137 } 138 "#); 139 140 assert_eq!(meta, Meta::List(inner)); 141 } 142 143 #[test] 144 fn test_parse_path() { 145 let input = "::serde::Serialize"; 146 snapshot!(input as Meta, @r#" 147 Meta::Path { 148 leading_colon: Some, 149 segments: [ 150 PathSegment { 151 ident: "serde", 152 }, 153 Token![::], 154 PathSegment { 155 ident: "Serialize", 156 }, 157 ], 158 } 159 "#); 160 } 161 162 #[test] 163 fn test_fat_arrow_after_meta() { 164 fn parse(input: ParseStream) -> Result<()> { 165 while !input.is_empty() { 166 let _: Meta = input.parse()?; 167 let _: Token![=>] = input.parse()?; 168 let brace; 169 syn::braced!(brace in input); 170 } 171 Ok(()) 172 } 173 174 let input = quote! { 175 target_os = "linux" => {} 176 windows => {} 177 }; 178 179 parse.parse2(input).unwrap(); 180 }