From bd11266f8259b4bf777d6c57ca1e29720c74e22d Mon Sep 17 00:00:00 2001 From: DavIvek Date: Mon, 8 Jan 2024 13:17:55 +0100 Subject: [PATCH] Extend ToBoolean function (#1620) --- .../interpret/awesome_memgraph_functions.cpp | 6 ++-- .../memgraph_V1/features/functions.feature | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/query/interpret/awesome_memgraph_functions.cpp b/src/query/interpret/awesome_memgraph_functions.cpp index 6f49ee99f..7e1a7290f 100644 --- a/src/query/interpret/awesome_memgraph_functions.cpp +++ b/src/query/interpret/awesome_memgraph_functions.cpp @@ -1,4 +1,4 @@ -// Copyright 2023 Memgraph Ltd. +// Copyright 2024 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -504,8 +504,8 @@ TypedValue ToBoolean(const TypedValue *args, int64_t nargs, const FunctionContex return TypedValue(value.ValueInt() != 0L, ctx.memory); } else { auto s = utils::ToUpperCase(utils::Trim(value.ValueString())); - if (s == "TRUE") return TypedValue(true, ctx.memory); - if (s == "FALSE") return TypedValue(false, ctx.memory); + if (s == "TRUE" || s == "T") return TypedValue(true, ctx.memory); + if (s == "FALSE" || s == "F") return TypedValue(false, ctx.memory); // I think this is just stupid and that exception should be thrown, but // neo4j does it this way... return TypedValue(ctx.memory); diff --git a/tests/gql_behave/tests/memgraph_V1/features/functions.feature b/tests/gql_behave/tests/memgraph_V1/features/functions.feature index bc9121676..19a7f2332 100644 --- a/tests/gql_behave/tests/memgraph_V1/features/functions.feature +++ b/tests/gql_behave/tests/memgraph_V1/features/functions.feature @@ -60,6 +60,34 @@ Feature: Functions | false | | true | + Scenario: ToBoolean test 03: + Given an empty graph + And having executed + """ + CREATE (:Node {prop: ToBoolean("t")}); + """ + When executing query: + """ + MATCH (n:Node) RETURN n.prop; + """ + Then the result should be: + | n.prop | + | true | + + Scenario: ToBoolean test 03: + Given an empty graph + And having executed + """ + CREATE (:Node {prop: ToBoolean("f")}); + """ + When executing query: + """ + MATCH (n:Node) RETURN n.prop; + """ + Then the result should be: + | n.prop | + | false | + Scenario: ToInteger test 01: Given an empty graph And having executed