Removed IsLittleEndian test, changes in IsLittleEndian, testing Split with non-null-terminated strings
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <bit>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
@@ -138,13 +139,11 @@ namespace OpenVulkano
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[deprecated]]
|
||||||
static bool IsLittleEndian()
|
static bool IsLittleEndian()
|
||||||
{ //TODO update with cpp20
|
{
|
||||||
const int value { 0x01 };
|
constexpr bool isLittleEndian = std::endian::native == std::endian::little;
|
||||||
const void * address { static_cast<const void *>(&value) };
|
return isLittleEndian;
|
||||||
const unsigned char * least_significant_address { static_cast<const unsigned char *>(address) };
|
|
||||||
|
|
||||||
return (*least_significant_address == 0x01);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr bool StartsWith(std::string_view str, std::string_view prefix)
|
static constexpr bool StartsWith(std::string_view str, std::string_view prefix)
|
||||||
|
|||||||
@@ -100,11 +100,6 @@ TEST_CASE("OctToInt", "[Utils]")
|
|||||||
REQUIRE(Utils::OctToInt(" 1234 ") == 668);
|
REQUIRE(Utils::OctToInt(" 1234 ") == 668);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("IsLittleEndian", "[Utils]")
|
|
||||||
{
|
|
||||||
REQUIRE((Utils::IsLittleEndian() || true));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("StartsWith", "[Utils]")
|
TEST_CASE("StartsWith", "[Utils]")
|
||||||
{
|
{
|
||||||
REQUIRE(Utils::StartsWith("abcdef", "abc"));
|
REQUIRE(Utils::StartsWith("abcdef", "abc"));
|
||||||
@@ -206,4 +201,62 @@ TEST_CASE("Split", "[Utils]")
|
|||||||
result = Utils::Split("a,", ',');
|
result = Utils::Split("a,", ',');
|
||||||
REQUIRE(result.size() == 1);
|
REQUIRE(result.size() == 1);
|
||||||
REQUIRE(result[0] == "a");
|
REQUIRE(result[0] == "a");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Split with non-null-terminated strings", "[Utils]")
|
||||||
|
{
|
||||||
|
std::string_view input;
|
||||||
|
std::vector<std::string> result;
|
||||||
|
|
||||||
|
input = { "a,b,c|", 5 };
|
||||||
|
result = Utils::Split(input, ',');
|
||||||
|
|
||||||
|
REQUIRE(result.size() == 3);
|
||||||
|
REQUIRE(result[0] == "a");
|
||||||
|
REQUIRE(result[1] == "b");
|
||||||
|
REQUIRE(result[2] == "c");
|
||||||
|
|
||||||
|
input = { "one|two|three>", 13 };
|
||||||
|
result = Utils::Split(input, '|');
|
||||||
|
REQUIRE(result.size() == 3);
|
||||||
|
REQUIRE(result[0] == "one");
|
||||||
|
REQUIRE(result[1] == "two");
|
||||||
|
REQUIRE(result[2] == "three");
|
||||||
|
|
||||||
|
input = { "no separator here|", 17 };
|
||||||
|
result = Utils::Split(input, ',');
|
||||||
|
REQUIRE(result.size() == 1);
|
||||||
|
REQUIRE(result[0] == "no separator here");
|
||||||
|
|
||||||
|
input = { "a,,b,,c|", 7 };
|
||||||
|
result = Utils::Split(input, ',');
|
||||||
|
REQUIRE(result.size() == 3);
|
||||||
|
REQUIRE(result[0] == "a");
|
||||||
|
REQUIRE(result[1] == "b");
|
||||||
|
REQUIRE(result[2] == "c");
|
||||||
|
|
||||||
|
input = { ",a,b,c,|", 7 };
|
||||||
|
result = Utils::Split(input, ',');
|
||||||
|
REQUIRE(result.size() == 3);
|
||||||
|
REQUIRE(result[0] == "a");
|
||||||
|
REQUIRE(result[1] == "b");
|
||||||
|
REQUIRE(result[2] == "c");
|
||||||
|
|
||||||
|
input = { ",,,,|", 4 };
|
||||||
|
result = Utils::Split(input, ',');
|
||||||
|
REQUIRE(result.empty());
|
||||||
|
|
||||||
|
input = { "a|", 1 };
|
||||||
|
result = Utils::Split(input, ',');
|
||||||
|
REQUIRE(result.size() == 1);
|
||||||
|
REQUIRE(result[0] == "a");
|
||||||
|
|
||||||
|
input = { "a,|", 2 };
|
||||||
|
result = Utils::Split(input, ',');
|
||||||
|
REQUIRE(result.size() == 1);
|
||||||
|
REQUIRE(result[0] == "a");
|
||||||
|
|
||||||
|
input = { ",,,|", 3 };
|
||||||
|
result = Utils::Split(input, ',');
|
||||||
|
REQUIRE(result.empty());
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user