squall/test/String.cpp

78 lines
2.3 KiB
C++
Raw Normal View History

2020-11-14 17:18:49 -06:00
#include "storm/String.hpp"
2020-11-15 13:09:14 -06:00
#include "storm/Memory.hpp"
2020-11-14 17:18:49 -06:00
#include "test/Test.hpp"
2020-11-14 17:58:34 -06:00
TEST_CASE("SStrCmp", "[string]") {
SECTION("compares two strings that exactly match correctly") {
auto compare = SStrCmp("foo", "foo", STORM_MAX_STR);
REQUIRE(compare == 0);
}
SECTION("compares two strings that partially match correctly") {
auto compare1 = SStrCmp("bar", "foobar", STORM_MAX_STR);
auto compare2 = SStrCmp("foobar", "bar", STORM_MAX_STR);
REQUIRE(compare1 < 0);
REQUIRE(compare2 > 0);
}
SECTION("compares two strings that do not match correctly") {
auto compare = SStrCmp("bar", "xyzzy", STORM_MAX_STR);
REQUIRE(compare < 0);
}
}
2020-11-15 12:47:41 -06:00
TEST_CASE("SStrCmpI", "[string]") {
SECTION("compares two strings that exactly match correctly") {
auto compare = SStrCmpI("foo", "foo", STORM_MAX_STR);
REQUIRE(compare == 0);
}
SECTION("compares two strings that match with differing case correctly") {
auto compare = SStrCmpI("foo", "foO", STORM_MAX_STR);
REQUIRE(compare == 0);
}
SECTION("compares two strings that do not match correctly") {
auto compare = SStrCmpI("bar", "xyzzy", STORM_MAX_STR);
REQUIRE(compare < 0);
}
}
2020-11-15 13:09:14 -06:00
TEST_CASE("SStrDupA", "[string]") {
SECTION("duplicates string correctly") {
auto string1 = "foo bar";
auto string2 = SStrDupA(string1, __FILE__, __LINE__);
auto compare = SStrCmp(string1, string2, STORM_MAX_STR);
auto newPtr = string1 != string2;
SMemFree(string2);
REQUIRE(compare == 0);
REQUIRE(newPtr == true);
}
}
2020-11-14 17:18:49 -06:00
TEST_CASE("SStrHashHT", "[string]") {
SECTION("hashes simple string correctly") {
auto hash = SStrHashHT("foo");
REQUIRE(hash == 1371562358u);
}
SECTION("hashes string with forward slash correctly") {
auto hash = SStrHashHT("foo/bar");
REQUIRE(hash == 2270424393u);
}
SECTION("hashes string with forward slash equivalent to back slash") {
auto hashForwardSlash = SStrHashHT("foo/bar");
auto hashBackSlash = SStrHashHT("foo\\bar");
REQUIRE(hashForwardSlash == hashBackSlash);
}
}
2020-11-15 12:57:32 -06:00
TEST_CASE("SStrLen", "[string]") {
SECTION("calculates string length correctly") {
auto length = SStrLen("foo");
REQUIRE(length == 3);
}
}