From 551a05ad637eccc340ef61394c52b46a9faf40a9 Mon Sep 17 00:00:00 2001 From: Noah Hellman Date: Tue, 22 Nov 2022 19:48:17 +0100 Subject: [PATCH] cp --- src/inline.rs | 24 ++++++++++++++++++------ src/lib.rs | 24 ++++++++++++++++++++---- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/inline.rs b/src/inline.rs index ec7bb8a..c51b9fa 100644 --- a/src/inline.rs +++ b/src/inline.rs @@ -230,13 +230,25 @@ mod test { use super::Container::*; use super::Event::*; + macro_rules! test_parse { + ($($st:ident,)? $src:expr $(,$($token:expr),* $(,)?)?) => { + #[allow(unused)] + let mut p = super::Parser::new(); + p.parse($src); + let actual = p.collect::>(); + let expected = &[$($($token),*,)?]; + assert_eq!(actual, expected, "\n\n{}\n\n", $src); + }; + } + + #[test] + fn str() { + test_parse!("abc", Atom(Str)); + test_parse!("abc def", Atom(Str)); + } + #[test] fn container_brace() { - let mut p = super::Parser::new(); - p.parse("{_hej_}"); - assert_eq!( - p.collect::>().as_slice(), - &[Enter(Emphasis), Atom(Str), Exit(Emphasis)], - ); + test_parse!("{_abc_}", Enter(Emphasis), Atom(Str), Exit(Emphasis)); } } diff --git a/src/lib.rs b/src/lib.rs index 83e0d4d..a7c6393 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -97,11 +97,27 @@ mod test { use crate::inline::Atom::*; use crate::inline::Event::*; + macro_rules! test_parse { + ($($st:ident,)? $src:expr $(,$($token:expr),* $(,)?)?) => { + #[allow(unused)] + let actual = super::Parser::new($src).iter().collect::>(); + let expected = &[$($($token),*,)?]; + assert_eq!(actual, expected, "\n\n{}\n\n", $src); + }; + } + #[test] - fn basic() { - assert_eq!( - super::Parser::new("abc").iter().collect::>(), - &[Start(Leaf(Paragraph)), Inline(Atom(Str)), End] + fn para() { + test_parse!("abc", Start(Leaf(Paragraph)), Inline(Atom(Str)), End); + test_parse!("abc def", Start(Leaf(Paragraph)), Inline(Atom(Str)), End); + test_parse!( + "this is a paragraph\n\nfollowed by another one", + Start(Leaf(Paragraph)), + Inline(Atom(Str)), + End, + Start(Leaf(Paragraph)), + Inline(Atom(Str)), + End, ); } }