aboutsummaryrefslogtreecommitdiff
path: root/macros/src/macro_flag.rs
diff options
context:
space:
mode:
Diffstat (limited to 'macros/src/macro_flag.rs')
-rw-r--r--macros/src/macro_flag.rs45
1 files changed, 44 insertions, 1 deletions
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<dyn Error>>
+ {
+ assert_eq!(
+ parse2::<MacroFlag>(quote! {
+ more = true
+ })?,
+ MacroFlag {
+ flag: format_ident!("more"),
+ is_on: LitBool::new(true, Span::call_site())
+ }
+ );
+
+ assert_eq!(
+ parse2::<MacroFlag>(quote! {
+ do_something = false
+ })?,
+ MacroFlag {
+ flag: format_ident!("do_something"),
+ is_on: LitBool::new(false, Span::call_site())
+ }
+ );
+
+ assert!(parse2::<MacroFlag>(quote! {
+ 10 = false
+ })
+ .is_err());
+
+ Ok(())
+ }
+}