Overload << operator for mgp::Value::Type (#1080)

This commit is contained in:
Matija Pintarić 2023-07-25 13:30:02 +02:00 committed by GitHub
parent 036da58d30
commit ab4d1efe0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 64 additions and 0 deletions

View File

@ -2536,6 +2536,7 @@ inline void Path::Expand(const Relationship &relationship) { mgp::path_expand(pt
inline bool Path::operator==(const Path &other) const { return util::PathsEqual(ptr_, other.ptr_); }
inline bool Path::operator!=(const Path &other) const { return !(*this == other); }
/* #endregion */
/* #region Temporal types (Date, LocalTime, LocalDateTime, Duration) */
@ -3185,6 +3186,42 @@ inline bool Value::IsDuration() const { return mgp::value_is_duration(ptr_); }
inline bool Value::operator==(const Value &other) const { return util::ValuesEqual(ptr_, other.ptr_); }
inline bool Value::operator!=(const Value &other) const { return !(*this == other); }
inline std::ostream &operator<<(std::ostream &os, const mgp::Type &type) {
switch (type) {
case mgp::Type::Null:
return os << "null";
case mgp::Type::Bool:
return os << "bool";
case mgp::Type::Int:
return os << "int";
case mgp::Type::Double:
return os << "double";
case mgp::Type::String:
return os << "string";
case mgp::Type::List:
return os << "list";
case mgp::Type::Map:
return os << "map";
case mgp::Type::Node:
return os << "vertex";
case mgp::Type::Relationship:
return os << "edge";
case mgp::Type::Path:
return os << "path";
case mgp::Type::Date:
return os << "date";
case mgp::Type::LocalTime:
return os << "local_time";
case mgp::Type::LocalDateTime:
return os << "local_date_time";
case mgp::Type::Duration:
return os << "duration";
default:
throw ValueException("Unknown type");
}
}
/* #endregion */
/* #region Record */

View File

@ -10,6 +10,7 @@
// licenses/APL.txt.
#include <queue>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
@ -471,3 +472,29 @@ TYPED_TEST(CppApiTestFixture, TestNodeProperties) {
ASSERT_EQ(node_1.Properties()["b"].ValueString(), "b");
ASSERT_EQ(node_1.GetProperty("b").ValueString(), "b");
}
TYPED_TEST(CppApiTestFixture, TestTypeOperatorStream) {
std::string string1 = "string";
int64_t int1 = 4;
mgp::List list = mgp::List();
mgp::Value string_value = mgp::Value(string1);
mgp::Value int_value = mgp::Value(int1);
mgp::Value list_value = mgp::Value(list);
std::ostringstream oss_str;
oss_str << string_value.Type();
std::string str_test = oss_str.str();
std::ostringstream oss_int;
oss_int << int_value.Type();
std::string int_test = oss_int.str();
std::ostringstream oss_list;
oss_list << list_value.Type();
std::string list_test = oss_list.str();
ASSERT_EQ(str_test, "string");
ASSERT_EQ(int_test, "int");
ASSERT_EQ(list_test, "list");
}