expect_tests/
expect_tokens.rs

1use proc_macro2::TokenStream;
2
3pub trait ExpectTokens {
4    fn convert(self) -> String;
5}
6
7impl ExpectTokens for TokenStream {
8    fn convert(self) -> String {
9        let Ok(file) = syn::parse2::<syn::File>(self) else {
10            return "[ERROR: Unable to parse input to expect_tokens!]".to_string();
11        };
12        prettyplease::unparse(&file)
13    }
14}
15impl<E: std::fmt::Debug> ExpectTokens for Result<TokenStream, E> {
16    fn convert(self) -> String {
17        match self {
18            Ok(tokens) => tokens.convert(),
19            Err(e) => format!("Error: {:?}", e),
20        }
21    }
22}
23
24impl ExpectTokens for &TokenStream {
25    fn convert(self) -> String {
26        self.clone().convert()
27    }
28}
29
30impl<E: std::fmt::Debug> ExpectTokens for &Result<TokenStream, E> {
31    fn convert(self) -> String {
32        match self {
33            Ok(tokens) => tokens.convert(),
34            Err(e) => format!("Error: {:?}", e),
35        }
36    }
37}