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-2.0.119/tests/snapshot/mod.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-2.0.119 / tests / snapshot / mod.rs` 68 lines ยท 2085 bytes Raw Blame History 1 #![allow(unused_macros, unused_macro_rules)] 2 3 use std::str::FromStr; 4 use syn::parse::Result; 5 6 macro_rules! snapshot { 7 ($($args:tt)*) => { 8 snapshot_impl!(() $($args)*) 9 }; 10 } 11 12 macro_rules! snapshot_impl { 13 (($expr:ident) as $t:ty, @$snapshot:literal) => { 14 let tokens = crate::snapshot::TryIntoTokens::try_into_tokens($expr).unwrap(); 15 let $expr: $t = syn::parse_quote!(#tokens); 16 let debug = crate::debug::Lite(&$expr); 17 if !cfg!(miri) { 18 #[allow(clippy::needless_raw_string_hashes)] // https://github.com/mitsuhiko/insta/issues/389 19 { 20 insta::assert_debug_snapshot!(debug, @$snapshot); 21 } 22 } 23 }; 24 (($($expr:tt)*) as $t:ty, @$snapshot:literal) => {{ 25 let tokens = crate::snapshot::TryIntoTokens::try_into_tokens($($expr)*).unwrap(); 26 let syntax_tree: $t = syn::parse_quote!(#tokens); 27 let debug = crate::debug::Lite(&syntax_tree); 28 if !cfg!(miri) { 29 #[allow(clippy::needless_raw_string_hashes)] 30 { 31 insta::assert_debug_snapshot!(debug, @$snapshot); 32 } 33 } 34 syntax_tree 35 }}; 36 (($($expr:tt)*) , @$snapshot:literal) => {{ 37 let syntax_tree = $($expr)*; 38 let debug = crate::debug::Lite(&syntax_tree); 39 if !cfg!(miri) { 40 #[allow(clippy::needless_raw_string_hashes)] 41 { 42 insta::assert_debug_snapshot!(debug, @$snapshot); 43 } 44 } 45 syntax_tree 46 }}; 47 (($($expr:tt)*) $next:tt $($rest:tt)*) => { 48 snapshot_impl!(($($expr)* $next) $($rest)*) 49 }; 50 } 51 52 pub trait TryIntoTokens { 53 #[allow(dead_code)] 54 fn try_into_tokens(self) -> Result; 55 } 56 57 impl TryIntoTokens for &str { 58 fn try_into_tokens(self) -> Result { 59 let tokens = proc_macro2::TokenStream::from_str(self)?; 60 Ok(tokens) 61 } 62 } 63 64 impl TryIntoTokens for proc_macro2::TokenStream { 65 fn try_into_tokens(self) -> Result { 66 Ok(self) 67 } 68 }