Lints and suggestions for the Nix programming language
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: generate_tests supports arbitrary expressions

+8 -15
+8 -15
macros/src/test.rs
··· 2 2 use quote::{ToTokens, quote}; 3 3 use sha2::{Digest, Sha256}; 4 4 use syn::{ 5 - Error, ExprArray, ExprLit, Ident, Lit, LitStr, Token, 5 + Error, Expr, ExprArray, Ident, Token, 6 6 parse::{Parse, ParseStream}, 7 7 parse_macro_input, 8 + punctuated::Punctuated, 8 9 spanned::Spanned, 10 + token::Comma, 9 11 }; 10 12 11 13 struct MacroInvocation { 12 14 rule: Ident, 13 - expressions: Vec<LitStr>, 15 + expressions: Punctuated<Expr, Comma>, 14 16 } 15 17 16 18 impl Parse for MacroInvocation { ··· 39 41 } 40 42 41 43 input.parse::<Token![:]>()?; 42 - let ExprArray { elems, .. } = input.parse::<ExprArray>()?; 43 - 44 - let expressions = elems 45 - .into_iter() 46 - .map(|expr| match expr { 47 - syn::Expr::Lit(ExprLit { 48 - lit: Lit::Str(nix_expression), 49 - .. 50 - }) => Ok(nix_expression), 51 - _ => Err(Error::new(expr.span(), "expected a literal string")), 52 - }) 53 - .collect::<Result<Vec<_>, _>>()?; 44 + let ExprArray { 45 + elems: expressions, .. 46 + } = input.parse::<ExprArray>()?; 54 47 55 48 input.parse::<Token![,]>()?; 56 49 Ok(MacroInvocation { rule, expressions }) ··· 81 74 Fix, 82 75 } 83 76 84 - fn make_test(rule: &Ident, kind: TestKind, nix_expression: &LitStr) -> proc_macro2::TokenStream { 77 + fn make_test(rule: &Ident, kind: TestKind, nix_expression: &Expr) -> proc_macro2::TokenStream { 85 78 let expression_hash = Sha256::digest(nix_expression.to_token_stream().to_string()); 86 79 let expression_hash = hex::encode(expression_hash); 87 80