From 514fed51c42c913378c2f1ba3119e1d375b9ed68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20Pintari=C4=87?= <99442742+mpintaric55334@users.noreply.github.com> Date: Tue, 1 Aug 2023 20:11:38 +0200 Subject: [PATCH] Add implementation of C++ API Node::RemoveProperty (#1128) --- include/mgp.hpp | 5 +++++ tests/unit/cpp_api.cpp | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/mgp.hpp b/include/mgp.hpp index bd7c35983..2dcc6870e 100644 --- a/include/mgp.hpp +++ b/include/mgp.hpp @@ -637,6 +637,9 @@ class Node { /// @brief Sets the chosen property to the given value. void SetProperty(std::string property, Value value); + /// @brief Removes the chosen property. + void RemoveProperty(std::string property); + /// @brief Retrieves the value of the chosen property. Value GetProperty(const std::string &property) const; @@ -2574,6 +2577,8 @@ inline void Node::SetProperty(std::string property, Value value) { mgp::vertex_set_property(ptr_, property.data(), value.ptr()); } +inline void Node::RemoveProperty(std::string property) { SetProperty(property, Value()); } + inline Value Node::GetProperty(const std::string &property) const { mgp_value *vertex_prop = mgp::vertex_get_property(ptr_, property.data(), memory); return Value(steal, vertex_prop); diff --git a/tests/unit/cpp_api.cpp b/tests/unit/cpp_api.cpp index 4c7ba2d25..5f0dfa15f 100644 --- a/tests/unit/cpp_api.cpp +++ b/tests/unit/cpp_api.cpp @@ -561,6 +561,19 @@ TYPED_TEST(CppApiTestFixture, TestMapErase) { ASSERT_EQ(map.Size(), 0); } +TYPED_TEST(CppApiTestFixture, TestNodeRemoveProperty) { + mgp_graph raw_graph = this->CreateGraph(memgraph::storage::View::NEW); + auto graph = mgp::Graph(&raw_graph); + auto node = graph.CreateNode(); + + int64_t int1 = 100; + mgp::Value value{int1}; + node.SetProperty("key", value); + ASSERT_EQ(node.Properties().size(), 1); + node.RemoveProperty("key"); + ASSERT_EQ(node.Properties().size(), 0); +} + TYPED_TEST(CppApiTestFixture, TestValuePrint) { std::string string_1{"abc"}; int64_t int_1{4};