From 02dc29d18a7b67edf0eaa5d125be22eec6cfebb7 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 6 Feb 2020 11:15:48 +0100 Subject: =?UTF-8?q?Highlight=20bold=20/=20italic=20/=20monospace=20?= =?UTF-8?q?=F0=9F=8E=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/syntax/parsing.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/syntax/parsing.rs') diff --git a/src/syntax/parsing.rs b/src/syntax/parsing.rs index 1526a5cb..d24985a6 100644 --- a/src/syntax/parsing.rs +++ b/src/syntax/parsing.rs @@ -375,6 +375,7 @@ mod tests { Space as S, Newline as N, ToggleItalic as Italic, ToggleBolder as Bold, ToggleMonospace as Mono, }; + use Decoration::*; pub use Expr::{Number as Num, Bool}; pub fn Id(text: &str) -> Expr { Expr::Ident(Ident(text.to_string())) } @@ -421,9 +422,32 @@ mod tests { }; } + /// Test whether the given string yields the given decorations. + macro_rules! d { + ($s:expr => [$(($sl:tt:$sc:tt, $el:tt:$ec:tt, $d:expr)),* $(,)?]) => { + let ctx = ParseContext { scope: &scope() }; + let decos = parse(Position::ZERO, $s, ctx).feedback.decos; + + let expected = vec![ + $(Spanned { + v: $d, + span: Span { + start: Position { line: $sl, column: $sc }, + end: Position { line: $el, column: $ec }, + }, + }),* + ]; + + if decos != expected { + fail($s, decos, expected); + } + }; + } + fn scope() -> Scope { let mut scope = Scope::new::(); scope.add::("f"); + scope.add::("n"); scope.add::("box"); scope } @@ -552,4 +576,10 @@ mod tests { (0:21, 0:21, "expected closing bracket"), ]); } + + #[test] + fn parse_decos() { + d!("*Technische Universität Berlin* [n]\n [n]" + => [(0:33, 0:34, ValidFuncName), (1:33, 1:34, ValidFuncName)]); + } } -- cgit v1.2.3