Raise if Abs function got a boolean

Reviewers: florijan, mislav.bradac

Reviewed By: mislav.bradac

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D289
This commit is contained in:
Teon Banek 2017-04-18 12:07:13 +02:00
parent 231b84e834
commit dbe5ffc4ea
2 changed files with 2 additions and 5 deletions

View File

@ -15,8 +15,6 @@ TypedValue Abs(const std::vector<TypedValue> &args) {
switch (args[0].type()) {
case TypedValue::Type::Null:
return TypedValue::Null;
case TypedValue::Type::Bool:
return args[0].Value<bool>();
case TypedValue::Type::Int:
return static_cast<int64_t>(
std::abs(static_cast<long long>(args[0].Value<int64_t>())));

View File

@ -246,7 +246,7 @@ TEST(ExpressionEvaluator, IsNullOperator) {
ASSERT_EQ(eval.eval.PopBack().Value<bool>(), true);
}
TEST(ExpressionEvaluator, Function) {
TEST(ExpressionEvaluator, AbsFunction) {
AstTreeStorage storage;
NoContextExpressionEvaluator eval;
{
@ -271,8 +271,7 @@ TEST(ExpressionEvaluator, Function) {
{
std::vector<Expression *> arguments = {storage.Create<Literal>(true)};
auto *op = storage.Create<Function>(NameToFunction("ABS"), arguments);
op->Accept(eval.eval);
ASSERT_EQ(eval.eval.PopBack().Value<bool>(), true);
ASSERT_THROW(op->Accept(eval.eval), QueryRuntimeException);
}
{
std::vector<Expression *> arguments = {