interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / syn / tests / snapshot / mod.rs

68 lines · 2085 bytes Raw Blame History
1#![allow(unused_macros, unused_macro_rules)]
2
3use std::str::FromStr;
4use syn::parse::Result;
5
6macro_rules! snapshot {
7 ($($args:tt)*) => {
8 snapshot_impl!(() $($args)*)
9 };
10}
11
12macro_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
52pub trait TryIntoTokens {
53 #[allow(dead_code)]
54 fn try_into_tokens(self) -> Result<proc_macro2::TokenStream>;
55}
56
57impl TryIntoTokens for &str {
58 fn try_into_tokens(self) -> Result<proc_macro2::TokenStream> {
59 let tokens = proc_macro2::TokenStream::from_str(self)?;
60 Ok(tokens)
61 }
62}
63
64impl TryIntoTokens for proc_macro2::TokenStream {
65 fn try_into_tokens(self) -> Result<proc_macro2::TokenStream> {
66 Ok(self)
67 }
68}