test: add testbench for patch (starts ends with, and contains)
This commit is contained in:
@ -12,6 +12,8 @@ PRIVATE
|
|||||||
yycc/num/stringify.cpp
|
yycc/num/stringify.cpp
|
||||||
yycc/rust/num/parse.cpp
|
yycc/rust/num/parse.cpp
|
||||||
yycc/rust/num/stringify.cpp
|
yycc/rust/num/stringify.cpp
|
||||||
|
yycc/patch/contains.cpp
|
||||||
|
yycc/patch/starts_ends_with.cpp
|
||||||
)
|
)
|
||||||
# Setup headers
|
# Setup headers
|
||||||
target_include_directories(YYCCTestbench
|
target_include_directories(YYCCTestbench
|
||||||
|
58
testbench/yycc/patch/contains.cpp
Normal file
58
testbench/yycc/patch/contains.cpp
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <yycc.hpp>
|
||||||
|
#include <yycc/patch/contains.hpp>
|
||||||
|
|
||||||
|
#include <yycc/prelude/rust.hpp>
|
||||||
|
|
||||||
|
#define FN_CONTAINS ::yycc::patch::contains::contains
|
||||||
|
|
||||||
|
namespace yycctest::patch::contains {
|
||||||
|
|
||||||
|
TEST(PatchContains, Contains) {
|
||||||
|
// Set
|
||||||
|
{
|
||||||
|
std::set<u32> collection{
|
||||||
|
UINT32_C(1),
|
||||||
|
UINT32_C(3),
|
||||||
|
UINT32_C(5),
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(FN_CONTAINS(collection, 1));
|
||||||
|
EXPECT_FALSE(FN_CONTAINS(collection, 2));
|
||||||
|
}
|
||||||
|
// Unordered set
|
||||||
|
{
|
||||||
|
std::unordered_set<u32> collection{
|
||||||
|
UINT32_C(1),
|
||||||
|
UINT32_C(3),
|
||||||
|
UINT32_C(5),
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(FN_CONTAINS(collection, 1));
|
||||||
|
EXPECT_FALSE(FN_CONTAINS(collection, 2));
|
||||||
|
}
|
||||||
|
// Map
|
||||||
|
{
|
||||||
|
std::map<u32, u32> collection{
|
||||||
|
{UINT32_C(1), UINT32_C(2)},
|
||||||
|
{UINT32_C(3), UINT32_C(4)},
|
||||||
|
{UINT32_C(5), UINT32_C(6)},
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(FN_CONTAINS(collection, 1));
|
||||||
|
EXPECT_FALSE(FN_CONTAINS(collection, 2));
|
||||||
|
}
|
||||||
|
// Unordered Map
|
||||||
|
{
|
||||||
|
std::unordered_map<u32, u32> collection{
|
||||||
|
{UINT32_C(1), UINT32_C(2)},
|
||||||
|
{UINT32_C(3), UINT32_C(4)},
|
||||||
|
{UINT32_C(5), UINT32_C(6)},
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(FN_CONTAINS(collection, 1));
|
||||||
|
EXPECT_FALSE(FN_CONTAINS(collection, 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace yycctest::patch::contains
|
59
testbench/yycc/patch/starts_ends_with.cpp
Normal file
59
testbench/yycc/patch/starts_ends_with.cpp
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <yycc.hpp>
|
||||||
|
#include <yycc/patch/starts_ends_with.hpp>
|
||||||
|
|
||||||
|
#define FN_STARTS_WITH ::yycc::patch::starts_ends_with::starts_with
|
||||||
|
#define FN_ENDS_WITH ::yycc::patch::starts_ends_with::ends_with
|
||||||
|
using namespace std::literals;
|
||||||
|
|
||||||
|
namespace yycctest::patch::starts_ends_with {
|
||||||
|
|
||||||
|
#define TEST_STARTS_WITH(prefix) \
|
||||||
|
{ \
|
||||||
|
const auto that = prefix##"Hello, C++20!"s; \
|
||||||
|
EXPECT_TRUE(FN_STARTS_WITH(that, prefix##"He"sv)); \
|
||||||
|
EXPECT_FALSE(FN_STARTS_WITH(that, prefix##"he"sv)); \
|
||||||
|
EXPECT_TRUE(FN_STARTS_WITH(that, prefix##'H')); \
|
||||||
|
EXPECT_FALSE(FN_STARTS_WITH(that, prefix##'h')); \
|
||||||
|
EXPECT_TRUE(FN_STARTS_WITH(that, prefix##"He")); \
|
||||||
|
EXPECT_FALSE(FN_STARTS_WITH(that, prefix##"he")); \
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(PatchStartsEndsWith, StartsWith) {
|
||||||
|
// Ordinary string
|
||||||
|
TEST_STARTS_WITH();
|
||||||
|
// Wide string
|
||||||
|
TEST_STARTS_WITH(L);
|
||||||
|
// UTF8 string
|
||||||
|
TEST_STARTS_WITH(u8);
|
||||||
|
// UTF-16 string
|
||||||
|
TEST_STARTS_WITH(u);
|
||||||
|
// UTF-32 string
|
||||||
|
TEST_STARTS_WITH(U);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TEST_ENDS_WITH(prefix) \
|
||||||
|
{ \
|
||||||
|
const auto that = prefix##"Hello, C++20!"s; \
|
||||||
|
EXPECT_TRUE(FN_ENDS_WITH(that, prefix##"C++20!"sv)); \
|
||||||
|
EXPECT_FALSE(FN_ENDS_WITH(that, prefix##"c++20!"sv)); \
|
||||||
|
EXPECT_TRUE(FN_ENDS_WITH(that, prefix##'!')); \
|
||||||
|
EXPECT_FALSE(FN_ENDS_WITH(that, prefix##'?')); \
|
||||||
|
EXPECT_TRUE(FN_ENDS_WITH(that, prefix##"C++20!")); \
|
||||||
|
EXPECT_FALSE(FN_ENDS_WITH(that, prefix##"c++20!")); \
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(PatchStartsEndsWith, EndsWith) {
|
||||||
|
// Ordinary string
|
||||||
|
TEST_ENDS_WITH();
|
||||||
|
// Wide string
|
||||||
|
TEST_ENDS_WITH(L);
|
||||||
|
// UTF8 string
|
||||||
|
TEST_ENDS_WITH(u8);
|
||||||
|
// UTF-16 string
|
||||||
|
TEST_ENDS_WITH(u);
|
||||||
|
// UTF-32 string
|
||||||
|
TEST_ENDS_WITH(U);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace yycctest::patch::starts_ends_with
|
Reference in New Issue
Block a user