aboutsummaryrefslogtreecommitdiff
path: root/macros/src/macro_flag.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-10-09 20:41:09 +0200
committerHampusM <hampus@hampusmat.com>2022-10-09 20:42:07 +0200
commitfd5b6786d29d056ff0721a59435b50005f13f05c (patch)
tree3839ff2ffa99a14d1aefb952a55f1cb05aa0f09e /macros/src/macro_flag.rs
parent5b0c6a52022e67a2d9cee251b3d08b9cb2b5f6cb (diff)
test: add more unit tests
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(())
+ }
+}