44 lines
1.3 KiB
C++
44 lines
1.3 KiB
C++
#ifdef TESTS_BUILD
|
|
#include <cstring>
|
|
#include <unordered_map>
|
|
#include "../extern/catch.hpp"
|
|
#include "../src/StringView.hpp"
|
|
|
|
TEST_CASE("Initialize compile time", "[Utilities]") {
|
|
static_assert("foo"_cnc.Length() == 3);
|
|
static_assert("bar"_cnc.Length() == 3);
|
|
}
|
|
|
|
TEST_CASE("Compare compile time", "[Utilities]") { static_assert("foo"_cnc != "bar"_cnc); }
|
|
|
|
TEST_CASE("Compare compile time with CaseInsensitiveConstString", "[Utilities]") {
|
|
static_assert("foo"_cnc == ArbUt::StringViewLiteral("foo"));
|
|
}
|
|
|
|
TEST_CASE("Use insensitive const string in unordered_map", "[Utilities]") {
|
|
std::unordered_map<ArbUt::StringView, int32_t> map;
|
|
map.insert({"foO"_cnc, 1});
|
|
map.insert({"bAR"_cnc, 5});
|
|
|
|
CHECK(map["bar"_cnc] == 5);
|
|
CHECK(map["foo"_cnc] == 1);
|
|
}
|
|
|
|
TEST_CASE("Use case insensitive const string in switch case", "[Utilities]") {
|
|
auto val = ArbUt::StringView("foobar");
|
|
switch (val) {
|
|
case "foo"_cnc: FAIL(); break;
|
|
case "bar"_cnc: FAIL(); break;
|
|
case "FOObAr"_cnc: SUCCEED(); break;
|
|
default: FAIL(); break;
|
|
}
|
|
}
|
|
|
|
TEST_CASE("Literal conststring to non literal, then use", "[Utilities]") {
|
|
ArbUt::StringView val;
|
|
{ val = "foobar"_cnc; }
|
|
INFO(val.c_str());
|
|
REQUIRE(strcmp(val.c_str(), "foobar") == 0);
|
|
}
|
|
|
|
#endif |