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]
|
#[test]
|
||||||
fn basic_literals() {
|
fn basic_literals() {
|
||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
@ -1322,10 +1340,8 @@ fn blocks() {
|
|||||||
|
|
||||||
let cases = ["{ a }", "{ a; }", "{a}", "{ a\n }", "{ a\n\n }", "{ a;\n\n; }"];
|
let cases = ["{ a }", "{ a; }", "{a}", "{ a\n }", "{ a\n\n }", "{ a;\n\n; }"];
|
||||||
|
|
||||||
let mut parser = Parser::new();
|
|
||||||
for case in cases.iter() {
|
for case in cases.iter() {
|
||||||
let block = parser.block_comb(case);
|
assert_block!(case, vec![exst(Value(qn!(a)))].into());
|
||||||
assert_eq!(block.unwrap(), vec![exst(Value(qn!(a)))].into());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let source = r#"{
|
let source = r#"{
|
||||||
@ -1333,9 +1349,8 @@ fn blocks() {
|
|||||||
fn foo() { }
|
fn foo() { }
|
||||||
}
|
}
|
||||||
}"#;
|
}"#;
|
||||||
let block = parser.block_comb(source);
|
assert_block!(
|
||||||
assert_eq!(
|
source,
|
||||||
block.unwrap(),
|
|
||||||
vec![decl(Declaration::FuncDecl(
|
vec![decl(Declaration::FuncDecl(
|
||||||
Signature { name: rc("quah"), operator: false, params: vec![], type_anno: None },
|
Signature { name: rc("quah"), operator: false, params: vec![], type_anno: None },
|
||||||
vec![decl(Declaration::FuncDecl(
|
vec![decl(Declaration::FuncDecl(
|
||||||
@ -1347,9 +1362,9 @@ fn blocks() {
|
|||||||
.into()
|
.into()
|
||||||
);
|
);
|
||||||
|
|
||||||
let block = parser.block_comb("{}");
|
assert_block!("{}", vec![].into());
|
||||||
assert_eq!(block.unwrap(), vec![].into());
|
|
||||||
|
|
||||||
|
//TODO this case is broken in the peg version
|
||||||
let source = r#"{
|
let source = r#"{
|
||||||
|
|
||||||
//hella
|
//hella
|
||||||
@ -1357,6 +1372,7 @@ fn blocks() {
|
|||||||
11; /*chutney*/0xf
|
11; /*chutney*/0xf
|
||||||
}"#;
|
}"#;
|
||||||
|
|
||||||
|
let mut parser = Parser::new();
|
||||||
let block = parser.block_comb(source);
|
let block = parser.block_comb(source);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
Loading…
Reference in New Issue
Block a user