1fad3a1d3Sopenharmony_ci#![allow(clippy::uninlined_format_args)] 2fad3a1d3Sopenharmony_ci 3fad3a1d3Sopenharmony_ci#[macro_use] 4fad3a1d3Sopenharmony_cimod macros; 5fad3a1d3Sopenharmony_ci 6fad3a1d3Sopenharmony_ciuse syn::parse::Parser; 7fad3a1d3Sopenharmony_ciuse syn::{Attribute, Meta}; 8fad3a1d3Sopenharmony_ci 9fad3a1d3Sopenharmony_ci#[test] 10fad3a1d3Sopenharmony_cifn test_meta_item_word() { 11fad3a1d3Sopenharmony_ci let meta = test("#[foo]"); 12fad3a1d3Sopenharmony_ci 13fad3a1d3Sopenharmony_ci snapshot!(meta, @r###" 14fad3a1d3Sopenharmony_ci Meta::Path { 15fad3a1d3Sopenharmony_ci segments: [ 16fad3a1d3Sopenharmony_ci PathSegment { 17fad3a1d3Sopenharmony_ci ident: "foo", 18fad3a1d3Sopenharmony_ci }, 19fad3a1d3Sopenharmony_ci ], 20fad3a1d3Sopenharmony_ci } 21fad3a1d3Sopenharmony_ci "###); 22fad3a1d3Sopenharmony_ci} 23fad3a1d3Sopenharmony_ci 24fad3a1d3Sopenharmony_ci#[test] 25fad3a1d3Sopenharmony_cifn test_meta_item_name_value() { 26fad3a1d3Sopenharmony_ci let meta = test("#[foo = 5]"); 27fad3a1d3Sopenharmony_ci 28fad3a1d3Sopenharmony_ci snapshot!(meta, @r###" 29fad3a1d3Sopenharmony_ci Meta::NameValue { 30fad3a1d3Sopenharmony_ci path: Path { 31fad3a1d3Sopenharmony_ci segments: [ 32fad3a1d3Sopenharmony_ci PathSegment { 33fad3a1d3Sopenharmony_ci ident: "foo", 34fad3a1d3Sopenharmony_ci }, 35fad3a1d3Sopenharmony_ci ], 36fad3a1d3Sopenharmony_ci }, 37fad3a1d3Sopenharmony_ci value: Expr::Lit { 38fad3a1d3Sopenharmony_ci lit: 5, 39fad3a1d3Sopenharmony_ci }, 40fad3a1d3Sopenharmony_ci } 41fad3a1d3Sopenharmony_ci "###); 42fad3a1d3Sopenharmony_ci} 43fad3a1d3Sopenharmony_ci 44fad3a1d3Sopenharmony_ci#[test] 45fad3a1d3Sopenharmony_cifn test_meta_item_bool_value() { 46fad3a1d3Sopenharmony_ci let meta = test("#[foo = true]"); 47fad3a1d3Sopenharmony_ci 48fad3a1d3Sopenharmony_ci snapshot!(meta, @r###" 49fad3a1d3Sopenharmony_ci Meta::NameValue { 50fad3a1d3Sopenharmony_ci path: Path { 51fad3a1d3Sopenharmony_ci segments: [ 52fad3a1d3Sopenharmony_ci PathSegment { 53fad3a1d3Sopenharmony_ci ident: "foo", 54fad3a1d3Sopenharmony_ci }, 55fad3a1d3Sopenharmony_ci ], 56fad3a1d3Sopenharmony_ci }, 57fad3a1d3Sopenharmony_ci value: Expr::Lit { 58fad3a1d3Sopenharmony_ci lit: Lit::Bool { 59fad3a1d3Sopenharmony_ci value: true, 60fad3a1d3Sopenharmony_ci }, 61fad3a1d3Sopenharmony_ci }, 62fad3a1d3Sopenharmony_ci } 63fad3a1d3Sopenharmony_ci "###); 64fad3a1d3Sopenharmony_ci 65fad3a1d3Sopenharmony_ci let meta = test("#[foo = false]"); 66fad3a1d3Sopenharmony_ci 67fad3a1d3Sopenharmony_ci snapshot!(meta, @r###" 68fad3a1d3Sopenharmony_ci Meta::NameValue { 69fad3a1d3Sopenharmony_ci path: Path { 70fad3a1d3Sopenharmony_ci segments: [ 71fad3a1d3Sopenharmony_ci PathSegment { 72fad3a1d3Sopenharmony_ci ident: "foo", 73fad3a1d3Sopenharmony_ci }, 74fad3a1d3Sopenharmony_ci ], 75fad3a1d3Sopenharmony_ci }, 76fad3a1d3Sopenharmony_ci value: Expr::Lit { 77fad3a1d3Sopenharmony_ci lit: Lit::Bool { 78fad3a1d3Sopenharmony_ci value: false, 79fad3a1d3Sopenharmony_ci }, 80fad3a1d3Sopenharmony_ci }, 81fad3a1d3Sopenharmony_ci } 82fad3a1d3Sopenharmony_ci "###); 83fad3a1d3Sopenharmony_ci} 84fad3a1d3Sopenharmony_ci 85fad3a1d3Sopenharmony_ci#[test] 86fad3a1d3Sopenharmony_cifn test_meta_item_list_lit() { 87fad3a1d3Sopenharmony_ci let meta = test("#[foo(5)]"); 88fad3a1d3Sopenharmony_ci 89fad3a1d3Sopenharmony_ci snapshot!(meta, @r###" 90fad3a1d3Sopenharmony_ci Meta::List { 91fad3a1d3Sopenharmony_ci path: Path { 92fad3a1d3Sopenharmony_ci segments: [ 93fad3a1d3Sopenharmony_ci PathSegment { 94fad3a1d3Sopenharmony_ci ident: "foo", 95fad3a1d3Sopenharmony_ci }, 96fad3a1d3Sopenharmony_ci ], 97fad3a1d3Sopenharmony_ci }, 98fad3a1d3Sopenharmony_ci delimiter: MacroDelimiter::Paren, 99fad3a1d3Sopenharmony_ci tokens: TokenStream(`5`), 100fad3a1d3Sopenharmony_ci } 101fad3a1d3Sopenharmony_ci "###); 102fad3a1d3Sopenharmony_ci} 103fad3a1d3Sopenharmony_ci 104fad3a1d3Sopenharmony_ci#[test] 105fad3a1d3Sopenharmony_cifn test_meta_item_list_word() { 106fad3a1d3Sopenharmony_ci let meta = test("#[foo(bar)]"); 107fad3a1d3Sopenharmony_ci 108fad3a1d3Sopenharmony_ci snapshot!(meta, @r###" 109fad3a1d3Sopenharmony_ci Meta::List { 110fad3a1d3Sopenharmony_ci path: Path { 111fad3a1d3Sopenharmony_ci segments: [ 112fad3a1d3Sopenharmony_ci PathSegment { 113fad3a1d3Sopenharmony_ci ident: "foo", 114fad3a1d3Sopenharmony_ci }, 115fad3a1d3Sopenharmony_ci ], 116fad3a1d3Sopenharmony_ci }, 117fad3a1d3Sopenharmony_ci delimiter: MacroDelimiter::Paren, 118fad3a1d3Sopenharmony_ci tokens: TokenStream(`bar`), 119fad3a1d3Sopenharmony_ci } 120fad3a1d3Sopenharmony_ci "###); 121fad3a1d3Sopenharmony_ci} 122fad3a1d3Sopenharmony_ci 123fad3a1d3Sopenharmony_ci#[test] 124fad3a1d3Sopenharmony_cifn test_meta_item_list_name_value() { 125fad3a1d3Sopenharmony_ci let meta = test("#[foo(bar = 5)]"); 126fad3a1d3Sopenharmony_ci 127fad3a1d3Sopenharmony_ci snapshot!(meta, @r###" 128fad3a1d3Sopenharmony_ci Meta::List { 129fad3a1d3Sopenharmony_ci path: Path { 130fad3a1d3Sopenharmony_ci segments: [ 131fad3a1d3Sopenharmony_ci PathSegment { 132fad3a1d3Sopenharmony_ci ident: "foo", 133fad3a1d3Sopenharmony_ci }, 134fad3a1d3Sopenharmony_ci ], 135fad3a1d3Sopenharmony_ci }, 136fad3a1d3Sopenharmony_ci delimiter: MacroDelimiter::Paren, 137fad3a1d3Sopenharmony_ci tokens: TokenStream(`bar = 5`), 138fad3a1d3Sopenharmony_ci } 139fad3a1d3Sopenharmony_ci "###); 140fad3a1d3Sopenharmony_ci} 141fad3a1d3Sopenharmony_ci 142fad3a1d3Sopenharmony_ci#[test] 143fad3a1d3Sopenharmony_cifn test_meta_item_list_bool_value() { 144fad3a1d3Sopenharmony_ci let meta = test("#[foo(bar = true)]"); 145fad3a1d3Sopenharmony_ci 146fad3a1d3Sopenharmony_ci snapshot!(meta, @r###" 147fad3a1d3Sopenharmony_ci Meta::List { 148fad3a1d3Sopenharmony_ci path: Path { 149fad3a1d3Sopenharmony_ci segments: [ 150fad3a1d3Sopenharmony_ci PathSegment { 151fad3a1d3Sopenharmony_ci ident: "foo", 152fad3a1d3Sopenharmony_ci }, 153fad3a1d3Sopenharmony_ci ], 154fad3a1d3Sopenharmony_ci }, 155fad3a1d3Sopenharmony_ci delimiter: MacroDelimiter::Paren, 156fad3a1d3Sopenharmony_ci tokens: TokenStream(`bar = true`), 157fad3a1d3Sopenharmony_ci } 158fad3a1d3Sopenharmony_ci "###); 159fad3a1d3Sopenharmony_ci} 160fad3a1d3Sopenharmony_ci 161fad3a1d3Sopenharmony_ci#[test] 162fad3a1d3Sopenharmony_cifn test_meta_item_multiple() { 163fad3a1d3Sopenharmony_ci let meta = test("#[foo(word, name = 5, list(name2 = 6), word2)]"); 164fad3a1d3Sopenharmony_ci 165fad3a1d3Sopenharmony_ci snapshot!(meta, @r###" 166fad3a1d3Sopenharmony_ci Meta::List { 167fad3a1d3Sopenharmony_ci path: Path { 168fad3a1d3Sopenharmony_ci segments: [ 169fad3a1d3Sopenharmony_ci PathSegment { 170fad3a1d3Sopenharmony_ci ident: "foo", 171fad3a1d3Sopenharmony_ci }, 172fad3a1d3Sopenharmony_ci ], 173fad3a1d3Sopenharmony_ci }, 174fad3a1d3Sopenharmony_ci delimiter: MacroDelimiter::Paren, 175fad3a1d3Sopenharmony_ci tokens: TokenStream(`word , name = 5 , list (name2 = 6) , word2`), 176fad3a1d3Sopenharmony_ci } 177fad3a1d3Sopenharmony_ci "###); 178fad3a1d3Sopenharmony_ci} 179fad3a1d3Sopenharmony_ci 180fad3a1d3Sopenharmony_ci#[test] 181fad3a1d3Sopenharmony_cifn test_bool_lit() { 182fad3a1d3Sopenharmony_ci let meta = test("#[foo(true)]"); 183fad3a1d3Sopenharmony_ci 184fad3a1d3Sopenharmony_ci snapshot!(meta, @r###" 185fad3a1d3Sopenharmony_ci Meta::List { 186fad3a1d3Sopenharmony_ci path: Path { 187fad3a1d3Sopenharmony_ci segments: [ 188fad3a1d3Sopenharmony_ci PathSegment { 189fad3a1d3Sopenharmony_ci ident: "foo", 190fad3a1d3Sopenharmony_ci }, 191fad3a1d3Sopenharmony_ci ], 192fad3a1d3Sopenharmony_ci }, 193fad3a1d3Sopenharmony_ci delimiter: MacroDelimiter::Paren, 194fad3a1d3Sopenharmony_ci tokens: TokenStream(`true`), 195fad3a1d3Sopenharmony_ci } 196fad3a1d3Sopenharmony_ci "###); 197fad3a1d3Sopenharmony_ci} 198fad3a1d3Sopenharmony_ci 199fad3a1d3Sopenharmony_ci#[test] 200fad3a1d3Sopenharmony_cifn test_negative_lit() { 201fad3a1d3Sopenharmony_ci let meta = test("#[form(min = -1, max = 200)]"); 202fad3a1d3Sopenharmony_ci 203fad3a1d3Sopenharmony_ci snapshot!(meta, @r###" 204fad3a1d3Sopenharmony_ci Meta::List { 205fad3a1d3Sopenharmony_ci path: Path { 206fad3a1d3Sopenharmony_ci segments: [ 207fad3a1d3Sopenharmony_ci PathSegment { 208fad3a1d3Sopenharmony_ci ident: "form", 209fad3a1d3Sopenharmony_ci }, 210fad3a1d3Sopenharmony_ci ], 211fad3a1d3Sopenharmony_ci }, 212fad3a1d3Sopenharmony_ci delimiter: MacroDelimiter::Paren, 213fad3a1d3Sopenharmony_ci tokens: TokenStream(`min = - 1 , max = 200`), 214fad3a1d3Sopenharmony_ci } 215fad3a1d3Sopenharmony_ci "###); 216fad3a1d3Sopenharmony_ci} 217fad3a1d3Sopenharmony_ci 218fad3a1d3Sopenharmony_cifn test(input: &str) -> Meta { 219fad3a1d3Sopenharmony_ci let attrs = Attribute::parse_outer.parse_str(input).unwrap(); 220fad3a1d3Sopenharmony_ci 221fad3a1d3Sopenharmony_ci assert_eq!(attrs.len(), 1); 222fad3a1d3Sopenharmony_ci let attr = attrs.into_iter().next().unwrap(); 223fad3a1d3Sopenharmony_ci 224fad3a1d3Sopenharmony_ci attr.meta 225fad3a1d3Sopenharmony_ci} 226