116 lines
2.9 KiB
C++
116 lines
2.9 KiB
C++
#include <iterator>
|
|
#define CODE_ERROR_LOCATIONS
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <string>
|
|
#include "Utils.hpp"
|
|
|
|
namespace nb {
|
|
|
|
TEST(UtilsTest, TestFindAndReplace) {
|
|
ASSERT_STREQ(
|
|
find_and_replace("Jeff", "e", "efe").c_str(),
|
|
"Jefeff"
|
|
);
|
|
|
|
std::string tmp = find_and_replace("Naif", "a", "afa");
|
|
ASSERT_STREQ(
|
|
find_and_replace(tmp, "i", "ifi").c_str(),
|
|
"Nafaifif"
|
|
);
|
|
|
|
tmp = find_and_replace("aeiou", "a", "afa");
|
|
tmp = find_and_replace(tmp, "e", "efe");
|
|
tmp = find_and_replace(tmp, "i", "ifi");
|
|
tmp = find_and_replace(tmp, "o", "ofo");
|
|
tmp = find_and_replace(tmp, "u", "ufu");
|
|
ASSERT_STREQ(
|
|
tmp.c_str(),
|
|
"afaefeifiofoufu"
|
|
);
|
|
|
|
tmp = find_and_replace(tmp, "afa", "a");
|
|
tmp = find_and_replace(tmp, "efe", "e");
|
|
tmp = find_and_replace(tmp, "ifi", "i");
|
|
tmp = find_and_replace(tmp, "ofo", "o");
|
|
tmp = find_and_replace(tmp, "ufu", "u");
|
|
ASSERT_STREQ(
|
|
tmp.c_str(),
|
|
"aeiou"
|
|
);
|
|
}
|
|
|
|
TEST(UtilsTest, TestFindAndReplaceWstr) {
|
|
ASSERT_STREQ(
|
|
find_and_replace<std::wstring>(L"Jeff", L"e", L"efe").c_str(),
|
|
L"Jefeff"
|
|
);
|
|
|
|
std::wstring tmp = find_and_replace<std::wstring>(L"Naif", L"a", L"afa");
|
|
ASSERT_STREQ(
|
|
find_and_replace<std::wstring>(tmp, L"i", L"ifi").c_str(),
|
|
L"Nafaifif"
|
|
);
|
|
|
|
tmp = find_and_replace<std::wstring>(L"aeiou", L"a", L"afa");
|
|
tmp = find_and_replace<std::wstring>(tmp, L"e", L"efe");
|
|
tmp = find_and_replace<std::wstring>(tmp, L"i", L"ifi");
|
|
tmp = find_and_replace<std::wstring>(tmp, L"o", L"ofo");
|
|
tmp = find_and_replace<std::wstring>(tmp, L"u", L"ufu");
|
|
ASSERT_STREQ(
|
|
tmp.c_str(),
|
|
L"afaefeifiofoufu"
|
|
);
|
|
|
|
tmp = find_and_replace<std::wstring>(tmp, L"afa", L"a");
|
|
tmp = find_and_replace<std::wstring>(tmp, L"efe", L"e");
|
|
tmp = find_and_replace<std::wstring>(tmp, L"ifi", L"i");
|
|
tmp = find_and_replace<std::wstring>(tmp, L"ofo", L"o");
|
|
tmp = find_and_replace<std::wstring>(tmp, L"ufu", L"u");
|
|
ASSERT_STREQ(
|
|
tmp.c_str(),
|
|
L"aeiou"
|
|
);
|
|
}
|
|
|
|
TEST(UtilsTest, TestWstrToStr) {
|
|
ASSERT_STREQ(
|
|
nb::wstr_to_str(L"Hi!").c_str(),
|
|
"Hi!"
|
|
);
|
|
ASSERT_STREQ(
|
|
nb::wstr_to_str(L"Naif").c_str(),
|
|
"Naif"
|
|
);
|
|
ASSERT_STREQ(
|
|
nb::wstr_to_str(L"\r\r\r\n").c_str(),
|
|
"\r\r\r\n"
|
|
);
|
|
ASSERT_STREQ(
|
|
nb::wstr_to_str(L"Naif\ttalks\r\ra\t\nlot").c_str(),
|
|
"Naif\ttalks\r\ra\t\nlot"
|
|
);
|
|
}
|
|
|
|
TEST(UtilsTest, TestStrToWstr) {
|
|
ASSERT_STREQ(
|
|
nb::str_to_wstr("Hi!").c_str(),
|
|
L"Hi!"
|
|
);
|
|
ASSERT_STREQ(
|
|
nb::str_to_wstr("Naif").c_str(),
|
|
L"Naif"
|
|
);
|
|
ASSERT_STREQ(
|
|
nb::str_to_wstr("\r\r\r\n").c_str(),
|
|
L"\r\r\r\n"
|
|
);
|
|
ASSERT_STREQ(
|
|
nb::str_to_wstr("Naif\ttalks\r\ra\t\nlot").c_str(),
|
|
L"Naif\ttalks\r\ra\t\nlot"
|
|
);
|
|
}
|
|
|
|
|
|
} // namespace nb
|