2020-02-27 12:42:26 +00:00
|
|
|
#ifdef TESTS_BUILD
|
|
|
|
#include <cstring>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include "../extern/catch.hpp"
|
2020-06-26 13:56:00 +00:00
|
|
|
#include "../src/StringView.hpp"
|
2020-02-27 12:42:26 +00:00
|
|
|
|
2020-06-26 13:56:00 +00:00
|
|
|
TEST_CASE("Initialize compile time", "[Utilities]") {
|
|
|
|
static_assert("foo"_cnc.Length() == 3);
|
|
|
|
static_assert("bar"_cnc.Length() == 3);
|
|
|
|
}
|
2020-02-27 12:42:26 +00:00
|
|
|
|
2020-06-26 13:58:42 +00:00
|
|
|
TEST_CASE("Compare compile time", "[Utilities]") { static_assert("foo"_cnc != "bar"_cnc); }
|
2020-02-27 12:42:26 +00:00
|
|
|
|
2020-06-26 13:56:00 +00:00
|
|
|
TEST_CASE("Compare compile time with CaseInsensitiveConstString", "[Utilities]") {
|
|
|
|
static_assert("foo"_cnc == ArbUt::StringViewLiteral("foo"));
|
2020-02-27 12:42:26 +00:00
|
|
|
}
|
|
|
|
|
2020-02-27 14:18:54 +00:00
|
|
|
TEST_CASE("Use insensitive const string in unordered_map", "[Utilities]") {
|
2020-06-26 13:56:00 +00:00
|
|
|
std::unordered_map<ArbUt::StringView, int32_t> map;
|
2020-02-27 14:18:54 +00:00
|
|
|
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]") {
|
2020-06-26 13:56:00 +00:00
|
|
|
auto val = ArbUt::StringView("foobar");
|
2020-04-28 14:55:00 +00:00
|
|
|
switch (val) {
|
2020-02-27 14:18:54 +00:00
|
|
|
case "foo"_cnc: FAIL(); break;
|
|
|
|
case "bar"_cnc: FAIL(); break;
|
|
|
|
case "FOObAr"_cnc: SUCCEED(); break;
|
|
|
|
default: FAIL(); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-10 12:38:01 +00:00
|
|
|
TEST_CASE("Literal conststring to non literal, then use", "[Utilities]") {
|
2020-06-26 13:56:00 +00:00
|
|
|
ArbUt::StringView val;
|
2020-04-28 14:55:00 +00:00
|
|
|
{ val = "foobar"_cnc; }
|
2020-04-10 12:38:01 +00:00
|
|
|
INFO(val.c_str());
|
|
|
|
REQUIRE(strcmp(val.c_str(), "foobar") == 0);
|
|
|
|
}
|
|
|
|
|
2020-02-27 12:42:26 +00:00
|
|
|
#endif
|