Large rework of the project, specifically the String classes.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -2,29 +2,23 @@
|
||||
#include <cstring>
|
||||
#include <unordered_map>
|
||||
#include "../extern/catch.hpp"
|
||||
#include "../src/ConstString.hpp"
|
||||
#include "../src/StringView.hpp"
|
||||
|
||||
TEST_CASE("Use const string in unordered_map", "[Utilities]") {
|
||||
std::unordered_map<ArbUt::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("Initialize compile time", "[Utilities]") {
|
||||
static_assert("foo"_cnc.Length() == 3);
|
||||
static_assert("bar"_cnc.Length() == 3);
|
||||
}
|
||||
|
||||
TEST_CASE("Use const string in switch case", "[Utilities]") {
|
||||
auto val = ArbUt::ConstString("foobar");
|
||||
switch (val) {
|
||||
case "foo"_c: FAIL(); break;
|
||||
case "bar"_c: FAIL(); break;
|
||||
case "foobar"_c: SUCCEED(); break;
|
||||
default: FAIL(); break;
|
||||
}
|
||||
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::CaseInsensitiveConstString, int32_t> map;
|
||||
std::unordered_map<ArbUt::StringView, int32_t> map;
|
||||
map.insert({"foO"_cnc, 1});
|
||||
map.insert({"bAR"_cnc, 5});
|
||||
|
||||
@@ -33,7 +27,7 @@ TEST_CASE("Use insensitive const string in unordered_map", "[Utilities]") {
|
||||
}
|
||||
|
||||
TEST_CASE("Use case insensitive const string in switch case", "[Utilities]") {
|
||||
auto val = ArbUt::CaseInsensitiveConstString("foobar");
|
||||
auto val = ArbUt::StringView("foobar");
|
||||
switch (val) {
|
||||
case "foo"_cnc: FAIL(); break;
|
||||
case "bar"_cnc: FAIL(); break;
|
||||
@@ -42,30 +36,8 @@ TEST_CASE("Use case insensitive const string in switch case", "[Utilities]") {
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef WINDOWS
|
||||
__attribute__((optnone))
|
||||
#endif
|
||||
static ArbUt::CaseInsensitiveConstString
|
||||
TestCreateConstString() {
|
||||
char originalVal[7];
|
||||
originalVal[0] = 'f';
|
||||
originalVal[1] = 'o';
|
||||
originalVal[2] = 'o';
|
||||
originalVal[3] = 'b';
|
||||
originalVal[4] = 'a';
|
||||
originalVal[5] = 'r';
|
||||
originalVal[6] = '\0';
|
||||
return ArbUt::CaseInsensitiveConstString(originalVal);
|
||||
}
|
||||
|
||||
TEST_CASE("Out of scope char* doesn't lose reference", "[Utilities]") {
|
||||
ArbUt::CaseInsensitiveConstString val = TestCreateConstString();
|
||||
INFO(val.c_str());
|
||||
REQUIRE(strcmp(val.c_str(), "foobar") == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Literal conststring to non literal, then use", "[Utilities]") {
|
||||
ArbUt::CaseInsensitiveConstString val;
|
||||
ArbUt::StringView val;
|
||||
{ val = "foobar"_cnc; }
|
||||
INFO(val.c_str());
|
||||
REQUIRE(strcmp(val.c_str(), "foobar") == 0);
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#ifdef TESTS_BUILD
|
||||
#include <cstring>
|
||||
#include "../extern/catch.hpp"
|
||||
#include "../src/StringView.hpp"
|
||||
#include "../src/Enum.hpp"
|
||||
|
||||
ENUM(TestEnum, uint8_t, Val1, Val2, Val3)
|
||||
|
||||
TEST_CASE("Parse Enum case sensitive", "[Utilities]") {
|
||||
CHECK(TestEnumHelper::Parse("Val1") == TestEnum::Val1);
|
||||
CHECK(TestEnumHelper::Parse("Val2") == TestEnum::Val2);
|
||||
CHECK(TestEnumHelper::Parse("Val3") == TestEnum::Val3);
|
||||
STATIC_REQUIRE(TestEnumHelper::Parse("Val1") == TestEnum::Val1);
|
||||
STATIC_REQUIRE(TestEnumHelper::Parse("Val2") == TestEnum::Val2);
|
||||
STATIC_REQUIRE(TestEnumHelper::Parse("Val3") == TestEnum::Val3);
|
||||
CHECK_THROWS(TestEnumHelper::Parse("Val4"));
|
||||
CHECK_THROWS(TestEnumHelper::Parse("val1"));
|
||||
}
|
||||
@@ -53,12 +54,11 @@ TEST_CASE("Try Parse Enum case insensitive", "[Utilities]") {
|
||||
}
|
||||
|
||||
TEST_CASE("Enum To String", "[Utilities]") {
|
||||
CHECK(strcmp(TestEnumHelper::ToString(TestEnum::Val1), "Val1") == 0);
|
||||
CHECK(strcmp(TestEnumHelper::ToString(TestEnum::Val2), "Val2") == 0);
|
||||
CHECK(strcmp(TestEnumHelper::ToString(TestEnum::Val3), "Val3") == 0);
|
||||
auto s = TestEnumHelper::ToString((TestEnum)100);
|
||||
CHECK(strcmp(s, "100") == 0);
|
||||
delete[] s;
|
||||
STATIC_REQUIRE(TestEnumHelper::ToString(TestEnum::Val1) == "Val1");
|
||||
STATIC_REQUIRE(TestEnumHelper::ToString(TestEnum::Val2) == "Val2");
|
||||
STATIC_REQUIRE(TestEnumHelper::ToString(TestEnum::Val3) == "Val3");
|
||||
|
||||
CHECK(TestEnumHelper::ToString((TestEnum)100) == "out of bounds");
|
||||
}
|
||||
|
||||
TEST_CASE("Enum Get Values", "[Utilities]") {
|
||||
@@ -69,4 +69,12 @@ TEST_CASE("Enum Get Values", "[Utilities]") {
|
||||
CHECK(vec[2] == TestEnum::Val3);
|
||||
}
|
||||
|
||||
TEST_CASE("Enum Get Highest", "[Utilities]") { STATIC_REQUIRE(TestEnumHelper::Highest() == TestEnum::Val3); }
|
||||
|
||||
TEST_CASE("Enum Get Lowest", "[Utilities]") { STATIC_REQUIRE(TestEnumHelper::Lowest() == TestEnum::Val1); }
|
||||
|
||||
TEST_CASE("Enum Get First", "[Utilities]") { STATIC_REQUIRE(TestEnumHelper::First() == TestEnum::Val1); }
|
||||
|
||||
TEST_CASE("Enum Get Last", "[Utilities]") { STATIC_REQUIRE(TestEnumHelper::Last() == TestEnum::Val3); }
|
||||
|
||||
#endif
|
||||
@@ -67,4 +67,11 @@ TEST_CASE("Test IndexOf", "[Utilities]") {
|
||||
CHECK(ls.IndexOf(684) == -1);
|
||||
}
|
||||
|
||||
TEST_CASE("Test list out of bounds", "[Utilities]") {
|
||||
auto ls = List<int>({5, 200, 1500, -500, 5, 300, -500});
|
||||
REQUIRE_THROWS(ls.At(-1));
|
||||
REQUIRE_THROWS(ls.At(7));
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -41,4 +41,15 @@ TEST_CASE("Create Unique Ptr list, append, iterate") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Test unique ptr list out of bounds", "[Utilities]") {
|
||||
auto ls = UniquePtrList<uint32_t>();
|
||||
auto v1 = new uint32_t(100);
|
||||
auto v2 = new uint32_t(5000);
|
||||
ls.Append(v1);
|
||||
ls.Append(v2);
|
||||
REQUIRE_THROWS(ls.At(-1));
|
||||
REQUIRE_THROWS(ls.At(2));
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user