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_parse_quote.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_parse_quote.rs` 175 lines ยท 3735 bytes Raw Blame History 1 #![allow( 2 clippy::elidable_lifetime_names, 3 clippy::needless_lifetimes, 4 clippy::uninlined_format_args 5 )] 6 7 #[macro_use] 8 mod snapshot; 9 10 mod debug; 11 12 use syn::punctuated::Punctuated; 13 use syn::{parse_quote, Attribute, Field, Lit, Pat, Stmt, Token}; 14 15 #[test] 16 fn test_attribute() { 17 let attr: Attribute = parse_quote!(#[test]); 18 snapshot!(attr, @r#" 19 Attribute { 20 style: AttrStyle::Outer, 21 meta: Meta::Path { 22 segments: [ 23 PathSegment { 24 ident: "test", 25 }, 26 ], 27 }, 28 } 29 "#); 30 31 let attr: Attribute = parse_quote!(#![no_std]); 32 snapshot!(attr, @r#" 33 Attribute { 34 style: AttrStyle::Inner, 35 meta: Meta::Path { 36 segments: [ 37 PathSegment { 38 ident: "no_std", 39 }, 40 ], 41 }, 42 } 43 "#); 44 } 45 46 #[test] 47 fn test_field() { 48 let field: Field = parse_quote!(pub enabled: bool); 49 snapshot!(field, @r#" 50 Field { 51 vis: Visibility::Public, 52 modifiers: FieldModifiers, 53 ident: Some("enabled"), 54 colon_token: Some, 55 ty: Type::Path { 56 path: Path { 57 segments: [ 58 PathSegment { 59 ident: "bool", 60 }, 61 ], 62 }, 63 }, 64 } 65 "#); 66 67 let field: Field = parse_quote!(primitive::bool); 68 snapshot!(field, @r#" 69 Field { 70 vis: Visibility::Inherited, 71 modifiers: FieldModifiers, 72 ty: Type::Path { 73 path: Path { 74 segments: [ 75 PathSegment { 76 ident: "primitive", 77 }, 78 Token![::], 79 PathSegment { 80 ident: "bool", 81 }, 82 ], 83 }, 84 }, 85 } 86 "#); 87 } 88 89 #[test] 90 fn test_pat() { 91 let pat: Pat = parse_quote!(Some(false) | None); 92 snapshot!(&pat, @r#" 93 Pat::Or { 94 cases: [ 95 Pat::TupleStruct { 96 path: Path { 97 segments: [ 98 PathSegment { 99 ident: "Some", 100 }, 101 ], 102 }, 103 elems: [ 104 Pat::Lit(ExprLit { 105 lit: Lit::Bool { 106 value: false, 107 }, 108 }), 109 ], 110 }, 111 Token![|], 112 Pat::Ident { 113 ident: "None", 114 }, 115 ], 116 } 117 "#); 118 119 let boxed_pat: Box = parse_quote!(Some(false) | None); 120 assert_eq!(*boxed_pat, pat); 121 } 122 123 #[test] 124 fn test_punctuated() { 125 let punctuated: Punctuated = parse_quote!(true | true); 126 snapshot!(punctuated, @r#" 127 [ 128 Lit::Bool { 129 value: true, 130 }, 131 Token![|], 132 Lit::Bool { 133 value: true, 134 }, 135 ] 136 "#); 137 138 let punctuated: Punctuated = parse_quote!(true | true |); 139 snapshot!(punctuated, @r#" 140 [ 141 Lit::Bool { 142 value: true, 143 }, 144 Token![|], 145 Lit::Bool { 146 value: true, 147 }, 148 Token![|], 149 ] 150 "#); 151 } 152 153 #[test] 154 fn test_vec_stmt() { 155 let stmts: Vec = parse_quote! { 156 let _; 157 true 158 }; 159 snapshot!(stmts, @" 160 [ 161 Stmt::Local { 162 modifiers: LocalModifiers, 163 pat: Pat::Wild, 164 }, 165 Stmt::Expr( 166 Expr::Lit { 167 lit: Lit::Bool { 168 value: true, 169 }, 170 }, 171 None, 172 ), 173 ] 174 "); 175 }