From 90063e5433a3861395ac588026e8222abe79709a Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 14 May 2018 17:32:15 +0200 Subject: [PATCH] mood: Add support for the element. --- src/macros.rs | 5 +++-- src/mood.rs | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 26a4b63..af7b7fc 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -314,7 +314,8 @@ macro_rules! generate_id { } macro_rules! generate_elem_id { - ($elem:ident, $name:tt, $ns:ident) => ( + ($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident) => ( + $(#[$meta])* #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct $elem(pub String); impl ::std::str::FromStr for $elem { @@ -391,7 +392,7 @@ macro_rules! generate_element_with_text { } macro_rules! generate_element_with_children { - ($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, attributes: [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+], children: [$($(#[$child_meta:meta])* $child_ident:ident: Vec<$child_type:ty> = ($child_name:tt, $child_ns:ident) => $child_constructor:ident),+]) => ( + ($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, attributes: [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),*], children: [$($(#[$child_meta:meta])* $child_ident:ident: Vec<$child_type:ty> = ($child_name:tt, $child_ns:ident) => $child_constructor:ident),+]) => ( $(#[$meta])* #[derive(Debug, Clone)] pub struct $elem { diff --git a/src/mood.rs b/src/mood.rs index 400a91c..b8a3ef9 100644 --- a/src/mood.rs +++ b/src/mood.rs @@ -263,6 +263,11 @@ generate_element_enum!( } ); +generate_elem_id!( + /// Free-form text description of the mood. + Text, "text", MOOD +); + #[cfg(test)] mod tests { use super::*; @@ -275,4 +280,11 @@ mod tests { let mood = MoodEnum::try_from(elem).unwrap(); assert_eq!(mood, MoodEnum::Happy); } + + #[test] + fn test_text() { + let elem: Element = "Yay!".parse().unwrap(); + let text = Text::try_from(elem).unwrap(); + assert_eq!(text.0, String::from("Yay!")); + } }