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_receiver.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_receiver.rs` 275 lines ยท 7189 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::{parse_quote, TraitItemFn}; 13 14 #[test] 15 fn test_by_value() { 16 let TraitItemFn { sig, .. } = parse_quote! { 17 fn by_value(self: Self); 18 }; 19 snapshot!(&sig.inputs[0], @r#" 20 FnArg::Receiver(Receiver { 21 kind: ReceiverKind::Typed( 22 Type::Path { 23 path: Path { 24 segments: [ 25 PathSegment { 26 ident: "Self", 27 }, 28 ], 29 }, 30 }, 31 ), 32 }) 33 "#); 34 } 35 36 #[test] 37 fn test_by_mut_value() { 38 let TraitItemFn { sig, .. } = parse_quote! { 39 fn by_mut(mut self: Self); 40 }; 41 snapshot!(&sig.inputs[0], @r#" 42 FnArg::Receiver(Receiver { 43 mutability: Some, 44 kind: ReceiverKind::Typed( 45 Type::Path { 46 path: Path { 47 segments: [ 48 PathSegment { 49 ident: "Self", 50 }, 51 ], 52 }, 53 }, 54 ), 55 }) 56 "#); 57 } 58 59 #[test] 60 fn test_by_ref() { 61 let TraitItemFn { sig, .. } = parse_quote! { 62 fn by_ref(self: &Self); 63 }; 64 snapshot!(&sig.inputs[0], @r#" 65 FnArg::Receiver(Receiver { 66 kind: ReceiverKind::Typed( 67 Type::Reference { 68 elem: Type::Path { 69 path: Path { 70 segments: [ 71 PathSegment { 72 ident: "Self", 73 }, 74 ], 75 }, 76 }, 77 }, 78 ), 79 }) 80 "#); 81 } 82 83 #[test] 84 fn test_by_box() { 85 let TraitItemFn { sig, .. } = parse_quote! { 86 fn by_box(self: Box); 87 }; 88 snapshot!(&sig.inputs[0], @r#" 89 FnArg::Receiver(Receiver { 90 kind: ReceiverKind::Typed( 91 Type::Path { 92 path: Path { 93 segments: [ 94 PathSegment { 95 ident: "Box", 96 arguments: PathArguments::AngleBracketed { 97 args: [ 98 GenericArgument::Type(Type::Path { 99 path: Path { 100 segments: [ 101 PathSegment { 102 ident: "Self", 103 }, 104 ], 105 }, 106 }), 107 ], 108 }, 109 }, 110 ], 111 }, 112 }, 113 ), 114 }) 115 "#); 116 } 117 118 #[test] 119 fn test_by_pin() { 120 let TraitItemFn { sig, .. } = parse_quote! { 121 fn by_pin(self: Pin); 122 }; 123 snapshot!(&sig.inputs[0], @r#" 124 FnArg::Receiver(Receiver { 125 kind: ReceiverKind::Typed( 126 Type::Path { 127 path: Path { 128 segments: [ 129 PathSegment { 130 ident: "Pin", 131 arguments: PathArguments::AngleBracketed { 132 args: [ 133 GenericArgument::Type(Type::Path { 134 path: Path { 135 segments: [ 136 PathSegment { 137 ident: "Self", 138 }, 139 ], 140 }, 141 }), 142 ], 143 }, 144 }, 145 ], 146 }, 147 }, 148 ), 149 }) 150 "#); 151 } 152 153 #[test] 154 fn test_explicit_type() { 155 let TraitItemFn { sig, .. } = parse_quote! { 156 fn explicit_type(self: Pin); 157 }; 158 snapshot!(&sig.inputs[0], @r#" 159 FnArg::Receiver(Receiver { 160 kind: ReceiverKind::Typed( 161 Type::Path { 162 path: Path { 163 segments: [ 164 PathSegment { 165 ident: "Pin", 166 arguments: PathArguments::AngleBracketed { 167 args: [ 168 GenericArgument::Type(Type::Path { 169 path: Path { 170 segments: [ 171 PathSegment { 172 ident: "MyType", 173 }, 174 ], 175 }, 176 }), 177 ], 178 }, 179 }, 180 ], 181 }, 182 }, 183 ), 184 }) 185 "#); 186 } 187 188 #[test] 189 fn test_value_shorthand() { 190 let TraitItemFn { sig, .. } = parse_quote! { 191 fn value_shorthand(self); 192 }; 193 snapshot!(&sig.inputs[0], @" 194 FnArg::Receiver(Receiver { 195 kind: ReceiverKind::Value, 196 }) 197 "); 198 } 199 200 #[test] 201 fn test_mut_value_shorthand() { 202 let TraitItemFn { sig, .. } = parse_quote! { 203 fn mut_value_shorthand(mut self); 204 }; 205 snapshot!(&sig.inputs[0], @" 206 FnArg::Receiver(Receiver { 207 mutability: Some, 208 kind: ReceiverKind::Value, 209 }) 210 "); 211 } 212 213 #[test] 214 fn test_ref_shorthand() { 215 let TraitItemFn { sig, .. } = parse_quote! { 216 fn ref_shorthand(&self); 217 }; 218 snapshot!(&sig.inputs[0], @" 219 FnArg::Receiver(Receiver { 220 kind: ReceiverKind::Reference( 221 None, 222 None, 223 ), 224 }) 225 "); 226 } 227 228 #[test] 229 fn test_ref_shorthand_with_lifetime() { 230 let TraitItemFn { sig, .. } = parse_quote! { 231 fn ref_shorthand(&'a self); 232 }; 233 snapshot!(&sig.inputs[0], @r#" 234 FnArg::Receiver(Receiver { 235 kind: ReceiverKind::Reference( 236 Some(Lifetime { 237 ident: "a", 238 }), 239 None, 240 ), 241 }) 242 "#); 243 } 244 245 #[test] 246 fn test_ref_mut_shorthand() { 247 let TraitItemFn { sig, .. } = parse_quote! { 248 fn ref_mut_shorthand(&mut self); 249 }; 250 snapshot!(&sig.inputs[0], @" 251 FnArg::Receiver(Receiver { 252 kind: ReceiverKind::Reference( 253 None, 254 Some, 255 ), 256 }) 257 "); 258 } 259 260 #[test] 261 fn test_ref_mut_shorthand_with_lifetime() { 262 let TraitItemFn { sig, .. } = parse_quote! { 263 fn ref_mut_shorthand(&'a mut self); 264 }; 265 snapshot!(&sig.inputs[0], @r#" 266 FnArg::Receiver(Receiver { 267 kind: ReceiverKind::Reference( 268 Some(Lifetime { 269 ident: "a", 270 }), 271 Some, 272 ), 273 }) 274 "#); 275 }