diff options
Diffstat (limited to 'util/ysaveload_ut.cpp')
-rw-r--r-- | util/ysaveload_ut.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/util/ysaveload_ut.cpp b/util/ysaveload_ut.cpp index 7656f8e941..23152ed929 100644 --- a/util/ysaveload_ut.cpp +++ b/util/ysaveload_ut.cpp @@ -27,6 +27,7 @@ class TSaveLoadTest: public TTestBase { UNIT_TEST(TestList) UNIT_TEST(TestTuple) UNIT_TEST(TestVariant) + UNIT_TEST(TestOptional) UNIT_TEST(TestInheritNonVirtualClass) UNIT_TEST(TestInheritVirtualClass) UNIT_TEST_SUITE_END(); @@ -429,6 +430,26 @@ private: UNIT_ASSERT_EXCEPTION(::Load(&s, v2), TLoadEOF); } + template <class T> + void TestOptionalImpl(const std::optional<T>& v) { + std::optional<T> loaded; + TBufferStream s; + ::Save(&s, v); + ::Load(&s, loaded); + + UNIT_ASSERT_VALUES_EQUAL(v.has_value(), loaded.has_value()); + if (v.has_value()) { + UNIT_ASSERT_VALUES_EQUAL(*v, *loaded); + } + } + + void TestOptional() { + TestOptionalImpl(std::optional<ui64>(42ull)); + TestOptionalImpl(std::optional<bool>(true)); + TestOptionalImpl(std::optional<TString>("abacaba")); + TestOptionalImpl(std::optional<ui64>(std::nullopt)); + } + // tests serialization of class with three public string members template <class TDerived, class TInterface = TDerived> void TestInheritClassImpl() { |