assert_block! macro
This commit is contained in:
parent
bba433c808
commit
3e422291f4
@ -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!(
|
||||
|
Loading…
Reference in New Issue
Block a user