46 lines
1.2 KiB
C++
46 lines
1.2 KiB
C++
#ifdef TESTS_BUILD
|
|
#include <cstring>
|
|
#include <unordered_map>
|
|
#include "../extern/catch.hpp"
|
|
#include "../src/ConstString.hpp"
|
|
|
|
TEST_CASE("Use const string in unordered_map", "[Utilities]") {
|
|
std::unordered_map<Arbutils::ConstString, int32_t> map;
|
|
map.insert({"foo"_c, 1});
|
|
map.insert({"bar"_c, 5});
|
|
|
|
CHECK(map["bar"_c] == 5);
|
|
CHECK(map["foo"_c] == 1);
|
|
}
|
|
|
|
TEST_CASE("Use const string in switch case", "[Utilities]") {
|
|
auto val = Arbutils::ConstString("foobar");
|
|
switch (val){
|
|
case "foo"_c: FAIL(); break;
|
|
case "bar"_c: FAIL(); break;
|
|
case "foobar"_c: SUCCEED(); break;
|
|
default: FAIL(); break;
|
|
}
|
|
}
|
|
|
|
TEST_CASE("Use insensitive const string in unordered_map", "[Utilities]") {
|
|
std::unordered_map<Arbutils::CaseInsensitiveConstString, 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 = Arbutils::CaseInsensitiveConstString("foobar");
|
|
switch (val){
|
|
case "foo"_cnc: FAIL(); break;
|
|
case "bar"_cnc: FAIL(); break;
|
|
case "FOObAr"_cnc: SUCCEED(); break;
|
|
default: FAIL(); break;
|
|
}
|
|
}
|
|
|
|
|
|
#endif |