Skip to content

Commit

Permalink
tests(lib): Make test helper more concise (#34)
Browse files Browse the repository at this point in the history
I was slightly unhappy with the previous helper design, immediately
converting the parsed string back to a token stream which was then used
as the input for `syn::parse_str`, when an `&str` was passed as one of
the function's parameters. This change should make the helper's
implementation more concise.
  • Loading branch information
DunnAnDusted authored Dec 14, 2022
1 parent 0293aa2 commit 29423bf
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,17 +505,14 @@ mod tests {
use super::*;

fn parse_to_tokens<P: Parse + ToTokens>(p: &'static str) {
let tokens = p
.parse::<TokenStream2>()
.expect("string could not be parsed as tokens")
.to_string();
let tokens: TokenStream2 = p.parse().expect("string could not be parsed as tokens");

let parsed = syn::parse_str::<P>(&tokens)
let parsed = syn::parse_str::<P>(&p)
.expect("tokens could not be parsed as type")
.into_token_stream()
.to_string();

assert_eq!(parsed, tokens);
assert_eq!(parsed, tokens.to_string());
}

#[test]
Expand Down

0 comments on commit 29423bf

Please sign in to comment.