use toasty_core::stmt::{
BinaryOp, Expr, ExprAnd, ExprBinaryOp, ExprError, ExprIsNull, ExprList, ExprNot, ExprRecord,
Value,
};
#[test]
fn from_expr_error_for_expr() {
let error = ExprError {
message: "bad value".into(),
};
assert_eq!(
Expr::from(error),
Expr::Error(ExprError {
message: "bad value".into(),
})
);
}
#[test]
fn from_expr_list_for_expr() {
let list = ExprList {
items: vec![Expr::Value(Value::Bool(true)), Expr::Value(Value::I64(1))],
};
assert_eq!(
Expr::from(list),
Expr::List(ExprList {
items: vec![Expr::Value(Value::Bool(true)), Expr::Value(Value::I64(1))],
})
);
}
#[test]
fn from_expr_list_empty_for_expr() {
assert_eq!(
Expr::from(ExprList { items: vec![] }),
Expr::List(ExprList { items: vec![] })
);
}
#[test]
fn from_vec_expr_for_expr() {
let items = vec![Expr::Value(Value::I64(1)), Expr::Value(Value::I64(2))];
assert_eq!(
Expr::from(items),
Expr::List(ExprList {
items: vec![Expr::Value(Value::I64(1)), Expr::Value(Value::I64(2))],
})
);
}
#[test]
fn from_vec_expr_empty_for_expr() {
assert_eq!(
Expr::from(Vec::<Expr>::new()),
Expr::List(ExprList { items: vec![] })
);
}
#[test]
fn from_expr_record_for_expr() {
let record = ExprRecord {
fields: vec![
Expr::Value(Value::Bool(true)),
Expr::Value(Value::from("hi")),
],
};
assert_eq!(
Expr::from(record),
Expr::Record(ExprRecord {
fields: vec![
Expr::Value(Value::Bool(true)),
Expr::Value(Value::from("hi"))
],
})
);
}
#[test]
fn from_tuple2_for_expr() {
let expr = Expr::from((true, 42i64));
assert_eq!(
expr,
Expr::Record(ExprRecord {
fields: vec![Expr::Value(Value::Bool(true)), Expr::Value(Value::I64(42)),],
})
);
}
#[test]
fn from_tuple3_for_expr_record() {
let record = ExprRecord::from((true, 1i64, "hi"));
assert_eq!(
record,
ExprRecord {
fields: vec![
Expr::Value(Value::Bool(true)),
Expr::Value(Value::I64(1)),
Expr::Value(Value::from("hi")),
],
}
);
}
#[test]
fn from_expr_and_for_expr() {
let and = ExprAnd {
operands: vec![
Expr::Value(Value::Bool(true)),
Expr::Value(Value::Bool(false)),
],
};
assert_eq!(
Expr::from(and),
Expr::And(ExprAnd {
operands: vec![
Expr::Value(Value::Bool(true)),
Expr::Value(Value::Bool(false))
],
})
);
}
#[test]
fn from_expr_not_for_expr() {
let not = ExprNot {
expr: Box::new(Expr::Value(Value::Bool(true))),
};
assert_eq!(
Expr::from(not),
Expr::Not(ExprNot {
expr: Box::new(Expr::Value(Value::Bool(true))),
})
);
}
#[test]
fn from_expr_is_null_for_expr() {
let is_null = ExprIsNull {
expr: Box::new(Expr::Value(Value::Null)),
};
assert_eq!(
Expr::from(is_null),
Expr::IsNull(ExprIsNull {
expr: Box::new(Expr::Value(Value::Null)),
})
);
}
#[test]
fn from_expr_binary_op_for_expr() {
let op = ExprBinaryOp {
lhs: Box::new(Expr::Value(Value::I64(1))),
op: BinaryOp::Eq,
rhs: Box::new(Expr::Value(Value::I64(1))),
};
assert_eq!(
Expr::from(op),
Expr::BinaryOp(ExprBinaryOp {
lhs: Box::new(Expr::Value(Value::I64(1))),
op: BinaryOp::Eq,
rhs: Box::new(Expr::Value(Value::I64(1))),
})
);
}