More concise test macros

This commit is contained in:
greg 2018-11-05 19:57:11 -08:00
parent 9813609ad7
commit 1e9aa91c5d
2 changed files with 20 additions and 5 deletions

View File

@ -1,6 +1,7 @@
# TODO Items
-fuzz test schala
*A neat idea for pattern matching optimization would be if you could match on one of several things in a list
ex:

View File

@ -1090,6 +1090,7 @@ fn parse_hex(digits: String) -> ParseResult<u64> {
#[cfg(test)]
mod parse_tests {
use ::std::rc::Rc;
use super::tokenize;
use super::ParseResult;
use builtin::{PrefixOp, BinOp};
use ast::{AST, Expression, Statement, IfExpressionBody, Discriminator, Pattern, PatternLiteral, TypeBody, Enumerator, ForBody};
@ -1103,7 +1104,6 @@ mod parse_tests {
use super::ForBody::*;
fn parse(input: &str) -> ParseResult<AST> {
use super::tokenize;
let tokens: Vec<::tokenizing::Token> = tokenize(input);
let mut parser = super::Parser::new(tokens);
parser.parse()
@ -1124,6 +1124,13 @@ mod parse_tests {
macro_rules! exprstatement {
($expr_type:expr) => { Statement::ExpressionStatement(Expression($expr_type, None)) };
($expr_type:expr, $type_anno:expr) => { Statement::ExpressionStatement(Expression($expr_type, Some($type_anno))) };
(s $statement_text:expr) => {
{
let tokens: Vec<::tokenizing::Token> = tokenize($statement_text);
let mut parser = super::Parser::new(tokens);
parser.statement().unwrap()
}
}
}
macro_rules! ty {
($name:expr) => { Singleton(tys!($name)) }
@ -1132,7 +1139,6 @@ mod parse_tests {
($name:expr) => { TypeSingletonName { name: Rc::new($name.to_string()), params: vec![] } };
}
/* new style of test macros */
macro_rules! single_expr {
@ -1140,8 +1146,16 @@ mod parse_tests {
($exprtype:expr, $type:expr) => { AST(vec![Statement::ExpressionStatement(Expression($exprtype, $type))]) }
}
macro_rules! ex {
($expr_type:expr) => { Expression($expr_type, None) }
($expr_type:expr) => { Expression($expr_type, None) };
(s $expr_text:expr) => {
{
let tokens: Vec<::tokenizing::Token> = tokenize($expr_text);
let mut parser = super::Parser::new(tokens);
parser.expression().unwrap()
}
};
}
macro_rules! binexp {
($op:expr, $lhs:expr, $rhs:expr) => { BinExp(BinOp::from_sigil($op), bx!(Expression($lhs, None)), bx!(Expression($rhs, None))) }
}
@ -1201,7 +1215,7 @@ mod parse_tests {
parse_test!("()", AST(vec![exprstatement!(TupleLiteral(vec![]))]));
parse_test!("(\"hella\", 34)", AST(vec![exprstatement!(
TupleLiteral(
vec![ex!(StringLiteral(rc!(hella))), ex!(NatLiteral(34))]
vec![ex!(s r#""hella""#), ex!(s "34")]
)
)]));
parse_test!("((1+2), \"slough\")", AST(vec![exprstatement!(TupleLiteral(vec![
@ -1500,7 +1514,7 @@ fn a(x) {
exprstatement!(Lambda {
params: vec![(rc!(x), Some(ty!("Int")))],
type_anno: Some(ty!("String")),
body: vec![exprstatement!(StringLiteral(rc!(q)))]
body: vec![exprstatement!(s r#""q""#)]
})
])
}