From fd5b6786d29d056ff0721a59435b50005f13f05c Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 9 Oct 2022 20:41:09 +0200 Subject: test: add more unit tests --- macros/src/macro_flag.rs | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'macros/src/macro_flag.rs') diff --git a/macros/src/macro_flag.rs b/macros/src/macro_flag.rs index 257a059..97a8ff2 100644 --- a/macros/src/macro_flag.rs +++ b/macros/src/macro_flag.rs @@ -1,7 +1,7 @@ use syn::parse::{Parse, ParseStream}; use syn::{Ident, LitBool, Token}; -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq)] pub struct MacroFlag { pub flag: Ident, @@ -25,3 +25,46 @@ impl Parse for MacroFlag Ok(Self { flag, is_on }) } } + +#[cfg(test)] +mod tests +{ + use std::error::Error; + + use proc_macro2::Span; + use quote::{format_ident, quote}; + use syn::parse2; + + use super::*; + + #[test] + fn can_parse_macro_flag() -> Result<(), Box> + { + assert_eq!( + parse2::(quote! { + more = true + })?, + MacroFlag { + flag: format_ident!("more"), + is_on: LitBool::new(true, Span::call_site()) + } + ); + + assert_eq!( + parse2::(quote! { + do_something = false + })?, + MacroFlag { + flag: format_ident!("do_something"), + is_on: LitBool::new(false, Span::call_site()) + } + ); + + assert!(parse2::(quote! { + 10 = false + }) + .is_err()); + + Ok(()) + } +} -- cgit v1.2.3-18-g5258