summaryrefslogtreecommitdiff
path: root/src/syntax/parsing.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-02-06 11:15:48 +0100
committerLaurenz <laurmaedje@gmail.com>2020-02-06 11:15:48 +0100
commit02dc29d18a7b67edf0eaa5d125be22eec6cfebb7 (patch)
tree2079ec1be481265655c798adc94d5e9e0166cfc2 /src/syntax/parsing.rs
parent751812f45141a7b2022d0dba138457f3c21950b0 (diff)
Highlight bold / italic / monospace 🎨
Diffstat (limited to 'src/syntax/parsing.rs')
-rw-r--r--src/syntax/parsing.rs30
1 files changed, 30 insertions, 0 deletions
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::<DebugFn>();
scope.add::<DebugFn>("f");
+ scope.add::<DebugFn>("n");
scope.add::<DebugFn>("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)]);
+ }
}