aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/yson_string/unittests/convert_ut.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/yt/yson_string/unittests/convert_ut.cpp
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/yt/yson_string/unittests/convert_ut.cpp')
-rw-r--r--library/cpp/yt/yson_string/unittests/convert_ut.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/library/cpp/yt/yson_string/unittests/convert_ut.cpp b/library/cpp/yt/yson_string/unittests/convert_ut.cpp
new file mode 100644
index 0000000000..3a64f63896
--- /dev/null
+++ b/library/cpp/yt/yson_string/unittests/convert_ut.cpp
@@ -0,0 +1,79 @@
+#include <library/cpp/testing/gtest/gtest.h>
+
+#include <library/cpp/testing/gtest_extensions/assertions.h>
+
+#include <library/cpp/yt/yson_string/convert.h>
+
+#include <thread>
+
+namespace NYT::NYson {
+namespace {
+
+////////////////////////////////////////////////////////////////////////////////
+
+template <class T, class R = T, class U>
+void Check(const U& value)
+{
+ auto str = ConvertToYsonString(static_cast<T>(value));
+ auto anotherValue = ConvertFromYsonString<R>(str);
+ EXPECT_EQ(static_cast<T>(value), anotherValue);
+}
+
+TEST(TConvertTest, Basic)
+{
+ Check<i8>(13);
+ Check<i32>(13);
+ Check<i64>(13);
+ Check<i8>(-13);
+ Check<i32>(-13);
+ Check<i64>(-13);
+ Check<ui8>(13);
+ Check<ui32>(13);
+ Check<ui64>(13);
+ Check<TString>("");
+ Check<TString>("hello");
+ Check<TStringBuf, TString>("hello");
+ Check<const char*, TString>("hello");
+ Check<float>(3.14);
+ Check<double>(3.14);
+ Check<bool>(true);
+ Check<bool>(false);
+ Check<TInstant>(TInstant::Now());
+ Check<TDuration>(TDuration::Seconds(123));
+ Check<TGuid>(TGuid::FromString("12345678-12345678-abcdabcd-fefefefe"));
+}
+
+TEST(TConvertTest, InRange)
+{
+ EXPECT_EQ(ConvertFromYsonString<i16>(ConvertToYsonString(static_cast<i64>(-123))), -123);
+ EXPECT_EQ(ConvertFromYsonString<ui16>(ConvertToYsonString(static_cast<ui64>(123))), 123U);
+}
+
+TEST(TConvertTest, OutOfRange)
+{
+ EXPECT_THROW_MESSAGE_HAS_SUBSTR(
+ ConvertFromYsonString<i8>(ConvertToYsonString(static_cast<i64>(128))),
+ TYsonLiteralParseException,
+ "is out of expected range");
+ EXPECT_THROW_MESSAGE_HAS_SUBSTR(
+ ConvertFromYsonString<ui8>(ConvertToYsonString(static_cast<ui64>(256))),
+ TYsonLiteralParseException,
+ "is out of expected range");
+}
+
+TEST(TConvertTest, MalformedValues)
+{
+ EXPECT_THROW_MESSAGE_HAS_SUBSTR(
+ ConvertFromYsonString<TInstant>(ConvertToYsonString(TStringBuf("sometime"))),
+ TYsonLiteralParseException,
+ "Error parsing \"instant\" value");
+ EXPECT_THROW_MESSAGE_HAS_SUBSTR(
+ ConvertFromYsonString<TGuid>(ConvertToYsonString(TStringBuf("1-2-3-g"))),
+ TYsonLiteralParseException,
+ "Error parsing \"guid\" value");
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace
+} // namespace NYT::NYson