mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 08:35:28 +00:00
allow empty quote lines, update tests logic
This commit is contained in:
parent
2891d73b37
commit
e92eb318b3
1 changed files with 12 additions and 14 deletions
|
|
@ -6,7 +6,7 @@ use gtk::{
|
||||||
};
|
};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
const REGEX_QUOTE: &str = r"(?m)>\s*(?P<text>.*)$";
|
const REGEX_QUOTE: &str = r"(?m)^>(?:[ \t]*(?P<text>.*))?$";
|
||||||
|
|
||||||
pub struct Quote(TextTag);
|
pub struct Quote(TextTag);
|
||||||
|
|
||||||
|
|
@ -51,18 +51,16 @@ impl Quote {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_regex() {
|
fn test_regex() {
|
||||||
let cap: Vec<_> = Regex::new(REGEX_QUOTE).unwrap().captures_iter(
|
let cap: Vec<_> = Regex::new(REGEX_QUOTE).unwrap().captures_iter(
|
||||||
"> Some quote 1 with \n> 2\\)Some quote 2 with text\nplain text\n> Some quote 3"
|
"> Some quote 1 with \n>\n> 2\\)Some quote 2 with text\nplain text\n> Some quote 3"
|
||||||
).collect();
|
).collect();
|
||||||
{
|
|
||||||
let m = cap.first().unwrap();
|
let mut i = cap.into_iter();
|
||||||
assert_eq!(&m["text"], "Some quote 1 with ");
|
|
||||||
}
|
assert_eq!(
|
||||||
{
|
&i.next().unwrap()["text"],
|
||||||
let m = cap.get(1).unwrap();
|
"Some quote 1 with "
|
||||||
assert_eq!(&m["text"], "2\\)Some quote 2 with text");
|
);
|
||||||
}
|
assert!(&i.next().unwrap()["text"].is_empty());
|
||||||
{
|
assert_eq!(&i.next().unwrap()["text"], "2\\)Some quote 2 with text");
|
||||||
let m = cap.get(2).unwrap();
|
assert_eq!(&i.next().unwrap()["text"], "Some quote 3");
|
||||||
assert_eq!(&m["text"], "Some quote 3");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue