Skip to content

Commit

Permalink
Merge pull request #29 from FrankBro/move-tests-out
Browse files Browse the repository at this point in the history
move tests out
  • Loading branch information
FrankBro authored Jan 7, 2024
2 parents 29f16b7 + 4639864 commit cd185d1
Show file tree
Hide file tree
Showing 7 changed files with 747 additions and 748 deletions.
139 changes: 0 additions & 139 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,142 +350,3 @@ pub enum TypeVar {
Generic,
GenericRow(Constraints),
}

#[cfg(test)]
pub mod util {
use super::{Expr, ExprAt, ExprOnly, IntBinOp, PatternAt, PatternOnly, PositionContext};

pub fn pvar(var: &str) -> PatternOnly {
Expr::Var(var.to_owned()).into()
}

pub fn precord(labels: Vec<(&str, PatternOnly)>) -> PatternOnly {
let labels = labels
.into_iter()
.map(|(label, pattern)| (label.to_owned(), pattern))
.collect();
Expr::RecordExtend(labels, Box::new(Expr::RecordEmpty.into())).into()
}

pub fn bool(b: bool) -> ExprOnly {
Expr::Bool(b).into()
}

pub fn int(i: i64) -> ExprOnly {
Expr::Int(i).into()
}

pub fn int_at(i: i64, context: PositionContext) -> ExprAt {
ExprAt {
context,
expr: Expr::Int(i),
}
}

pub fn var(var: &str) -> ExprOnly {
Expr::Var(var.to_owned()).into()
}

pub fn var_at(var: &str, context: PositionContext) -> ExprAt {
ExprAt {
context,
expr: Expr::Var(var.to_owned()),
}
}

pub fn call(fn_expr: ExprOnly, args: Vec<ExprOnly>) -> ExprOnly {
Expr::Call(fn_expr.into(), args).into()
}

pub fn fun(args: Vec<PatternOnly>, body: ExprOnly) -> ExprOnly {
Expr::Fun(args, body.into()).into()
}

pub fn let_(var: PatternOnly, value: ExprOnly, body: ExprOnly) -> ExprOnly {
Expr::Let(var.into(), value.into(), body.into()).into()
}

pub fn let_at(var: PatternAt, value: ExprAt, body: ExprAt, context: PositionContext) -> ExprAt {
ExprAt {
context,
expr: Expr::Let(var.into(), value.into(), body.into()),
}
}

pub fn empty() -> ExprOnly {
Expr::RecordEmpty.into()
}

pub fn select(r: ExprOnly, label: &str) -> ExprOnly {
Expr::RecordSelect(r.into(), label.to_owned()).into()
}

pub fn restrict(r: ExprOnly, label: &str) -> ExprOnly {
Expr::RecordRestrict(r.into(), label.to_owned()).into()
}

pub fn record(labels: Vec<(&str, ExprOnly)>, r: ExprOnly) -> ExprOnly {
let labels = labels
.into_iter()
.map(|(label, expr)| (label.to_owned(), expr))
.collect();
Expr::RecordExtend(labels, r.into()).into()
}

pub fn plus(lhs: ExprOnly, rhs: ExprOnly) -> ExprOnly {
Expr::IntBinOp(IntBinOp::Plus, lhs.into(), rhs.into()).into()
}

pub fn plus_at(lhs: ExprAt, rhs: ExprAt, context: PositionContext) -> ExprAt {
ExprAt {
context,
expr: Expr::IntBinOp(IntBinOp::Plus, lhs.into(), rhs.into()),
}
}

pub fn minus(lhs: ExprOnly, rhs: ExprOnly) -> ExprOnly {
Expr::IntBinOp(IntBinOp::Minus, lhs.into(), rhs.into()).into()
}

pub fn multiply(lhs: ExprOnly, rhs: ExprOnly) -> ExprOnly {
Expr::IntBinOp(IntBinOp::Multiply, lhs.into(), rhs.into()).into()
}

pub fn divide(lhs: ExprOnly, rhs: ExprOnly) -> ExprOnly {
Expr::IntBinOp(IntBinOp::Divide, lhs.into(), rhs.into()).into()
}

pub fn negate(expr: ExprOnly) -> ExprOnly {
Expr::Negate(expr.into()).into()
}

pub fn equalequal(lhs: ExprOnly, rhs: ExprOnly) -> ExprOnly {
Expr::EqualEqual(lhs.into(), rhs.into()).into()
}

pub fn gt(lhs: ExprOnly, rhs: ExprOnly) -> ExprOnly {
Expr::IntBinOp(IntBinOp::GreaterThan, lhs.into(), rhs.into()).into()
}

pub fn match_(
val: ExprOnly,
cases: Vec<(&str, &str, ExprOnly)>,
def: Option<(&str, ExprOnly)>,
) -> ExprOnly {
let cases = cases
.into_iter()
.map(|(variant, var, body)| (variant.to_owned(), var.to_owned(), body))
.collect();
let def = def.map(|(var, body)| (var.to_owned(), body.into()));
Expr::Case(val.into(), cases, def).into()
}

pub fn if_(
if_expr: ExprOnly,
if_body: ExprOnly,
elifs: Vec<(ExprOnly, ExprOnly)>,
else_body: ExprOnly,
) -> ExprOnly {
Expr::If(if_expr.into(), if_body.into(), elifs, else_body.into()).into()
}
}
Loading

0 comments on commit cd185d1

Please sign in to comment.