ulib/tests/3party/optional/optional_unittest.cpp
tqcq f85932cbfa
All checks were successful
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Successful in 48s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Successful in 57s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Successful in 1m3s
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Successful in 1m8s
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Successful in 1m5s
linux-x64-gcc / linux-gcc (push) Successful in 1m47s
linux-mips64-gcc / linux-gcc-mips64el (push) Successful in 3m9s
feat add optional to namespace ulib
2024-01-05 14:07:54 +08:00

20 lines
440 B
C++

#include <gtest/gtest.h>
#include <optional.h>
TEST(optional, has_value)
{
ulib::optional<int> int_opt = 1;
EXPECT_TRUE(int_opt.has_value());
EXPECT_EQ(*int_opt, 1);
EXPECT_EQ(int_opt.value(), 1);
EXPECT_EQ(int_opt.value_or(2), 1);
}
TEST(optional, not_has_value)
{
ulib::optional<int> int_opt;
EXPECT_FALSE(int_opt.has_value());
EXPECT_EQ(int_opt.value_or(1), 1);
EXPECT_EQ(int_opt.value_or(2), 2);
}