diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-01-13 11:54:50 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-01-13 11:54:50 +0100 |
| commit | 539735e668f601058c2c71a847335e17fac107e8 (patch) | |
| tree | 32ce04a99fd92a089625e4abdc09d2373687f0ab /src/parse/tests.rs | |
| parent | d2ba1b705ed7a532266294aa100f19423bb07f4d (diff) | |
Basic let bindings 🎞
Diffstat (limited to 'src/parse/tests.rs')
| -rw-r--r-- | src/parse/tests.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/parse/tests.rs b/src/parse/tests.rs index b9a3d301..9460db6b 100644 --- a/src/parse/tests.rs +++ b/src/parse/tests.rs @@ -202,6 +202,21 @@ macro_rules! Block { }; } +macro_rules! Let { + (@$pat:expr $(=> $expr:expr)?) => {{ + #[allow(unused)] + let mut expr = None; + $(expr = Some(Box::new(into!($expr)));)? + Expr::Let(ExprLet { + pat: into!($pat).map(|s: &str| Ident(s.into())), + expr + }) + }}; + ($($tts:tt)*) => { + Node::Expr(Let!(@$($tts)*)) + }; +} + #[test] fn test_parse_comments() { // In markup. @@ -651,3 +666,26 @@ fn test_parse_values() { nodes: [], errors: [S(1..3, "expected expression, found invalid token")]); } + +#[test] +fn test_parse_let_bindings() { + // Basic let. + t!("#let x;" Let!("x")); + t!("#let _y=1;" Let!("_y" => Int(1))); + + // Followed by text. + t!("#let x = 1\n+\n2;\nHi there" + Let!("x" => Binary(Int(1), Add, Int(2))), + Space, Text("Hi"), Space, Text("there")); + + // Missing semicolon. + t!("#let x = a\nHi" + nodes: [Let!("x" => Id("a"))], + errors: [S(11..13, "unexpected identifier"), + S(13..13, "expected semicolon")]); + + // Missing identifier. + t!("#let 1;" + nodes: [], + errors: [S(5..6, "expected identifier, found integer")]) +} |
