From 3e422291f49e829646401ad8c03c82174cd0b160 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sat, 20 Nov 2021 23:00:19 -0800 Subject: [PATCH] assert_block! macro --- schala-lang/src/parsing/test.rs | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/schala-lang/src/parsing/test.rs b/schala-lang/src/parsing/test.rs index daaa19a..f72f701 100644 --- a/schala-lang/src/parsing/test.rs +++ b/schala-lang/src/parsing/test.rs @@ -142,6 +142,24 @@ macro_rules! assert_fail_expr { }; } +macro_rules! assert_block { + ($input:expr, $correct:expr) => { + let mut parser = Parser::new(); + let block = parser.block_comb($input); + let block2 = parser.block($input); + let block = match block { + Err(err) => { + println!("Expression parse error: {}", err.msg); + panic!(); + } + Ok(item) => item, + }; + + assert_eq!(block, block2.unwrap()); + assert_eq!(block, $correct); + }; +} + #[test] fn basic_literals() { use ExpressionKind::*; @@ -1322,10 +1340,8 @@ fn blocks() { let cases = ["{ a }", "{ a; }", "{a}", "{ a\n }", "{ a\n\n }", "{ a;\n\n; }"]; - let mut parser = Parser::new(); for case in cases.iter() { - let block = parser.block_comb(case); - assert_eq!(block.unwrap(), vec![exst(Value(qn!(a)))].into()); + assert_block!(case, vec![exst(Value(qn!(a)))].into()); } let source = r#"{ @@ -1333,9 +1349,8 @@ fn blocks() { fn foo() { } } }"#; - let block = parser.block_comb(source); - assert_eq!( - block.unwrap(), + assert_block!( + source, vec![decl(Declaration::FuncDecl( Signature { name: rc("quah"), operator: false, params: vec![], type_anno: None }, vec![decl(Declaration::FuncDecl( @@ -1347,9 +1362,9 @@ fn blocks() { .into() ); - let block = parser.block_comb("{}"); - assert_eq!(block.unwrap(), vec![].into()); + assert_block!("{}", vec![].into()); + //TODO this case is broken in the peg version let source = r#"{ //hella @@ -1357,6 +1372,7 @@ fn blocks() { 11; /*chutney*/0xf }"#; + let mut parser = Parser::new(); let block = parser.block_comb(source); assert_eq!(