test_case_core/
comment.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use crate::TokenStream2;
use quote::ToTokens;
use syn::parse::{Parse, ParseStream};
use syn::{LitStr, Token};

#[derive(Clone, Debug)]
pub struct TestCaseComment {
    _semicolon: Token![;],
    pub comment: LitStr,
}

impl Parse for TestCaseComment {
    fn parse(input: ParseStream) -> syn::Result<Self> {
        Ok(Self {
            _semicolon: input.parse()?,
            comment: input.parse()?,
        })
    }
}

impl ToTokens for TestCaseComment {
    fn to_tokens(&self, tokens: &mut TokenStream2) {
        self._semicolon.to_tokens(tokens);
        self.comment.to_tokens(tokens);
    }
}

#[cfg(test)]
mod tests {
    use crate::comment::TestCaseComment;
    use proc_macro2::TokenStream;
    use syn::parse_quote;

    #[test]
    fn parses_token_stream() {
        let input: TokenStream = parse_quote! { ; "abcdef" };
        let actual: TestCaseComment = syn::parse2(input).unwrap();
        assert_eq!(actual.comment.value(), "abcdef")
    }
}