cp
This commit is contained in:
parent
f3e6db018e
commit
551a05ad63
2 changed files with 38 additions and 10 deletions
|
@ -230,13 +230,25 @@ mod test {
|
||||||
use super::Container::*;
|
use super::Container::*;
|
||||||
use super::Event::*;
|
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::<Vec<_>>();
|
||||||
|
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]
|
#[test]
|
||||||
fn container_brace() {
|
fn container_brace() {
|
||||||
let mut p = super::Parser::new();
|
test_parse!("{_abc_}", Enter(Emphasis), Atom(Str), Exit(Emphasis));
|
||||||
p.parse("{_hej_}");
|
|
||||||
assert_eq!(
|
|
||||||
p.collect::<Vec<_>>().as_slice(),
|
|
||||||
&[Enter(Emphasis), Atom(Str), Exit(Emphasis)],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
24
src/lib.rs
24
src/lib.rs
|
@ -97,11 +97,27 @@ mod test {
|
||||||
use crate::inline::Atom::*;
|
use crate::inline::Atom::*;
|
||||||
use crate::inline::Event::*;
|
use crate::inline::Event::*;
|
||||||
|
|
||||||
|
macro_rules! test_parse {
|
||||||
|
($($st:ident,)? $src:expr $(,$($token:expr),* $(,)?)?) => {
|
||||||
|
#[allow(unused)]
|
||||||
|
let actual = super::Parser::new($src).iter().collect::<Vec<_>>();
|
||||||
|
let expected = &[$($($token),*,)?];
|
||||||
|
assert_eq!(actual, expected, "\n\n{}\n\n", $src);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic() {
|
fn para() {
|
||||||
assert_eq!(
|
test_parse!("abc", Start(Leaf(Paragraph)), Inline(Atom(Str)), End);
|
||||||
super::Parser::new("abc").iter().collect::<Vec<_>>(),
|
test_parse!("abc def", Start(Leaf(Paragraph)), Inline(Atom(Str)), End);
|
||||||
&[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,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue