12#include "../3rdparty/catch2/catch.hpp"
14#include "../string_func.h"
18TEST_CASE(
"StrCompareIgnoreCase - std::string")
42TEST_CASE(
"StrCompareIgnoreCase - char pointer")
66TEST_CASE(
"StrCompareIgnoreCase - std::string_view")
76 std::string_view base{
"aaAbB"};
100TEST_CASE(
"StrEqualsIgnoreCase - std::string")
118TEST_CASE(
"StrEqualsIgnoreCase - char pointer")
136TEST_CASE(
"StrEqualsIgnoreCase - std::string_view")
146 std::string_view base{
"aaAb"};
166TEST_CASE(
"StrStartsWithIgnoreCase - std::string")
191TEST_CASE(
"StrStartsWithIgnoreCase - char pointer")
216TEST_CASE(
"StrStartsWithIgnoreCase - std::string_view")
226 std::string_view base{
"aabAb"};
253TEST_CASE(
"StrEndsWithIgnoreCase - std::string")
278TEST_CASE(
"StrEndsWithIgnoreCase - char pointer")
303TEST_CASE(
"StrEndsWithIgnoreCase - std::string_view")
313 std::string_view base{
"aabAba"};
339TEST_CASE(
"FormatArrayAsHex")
343 CHECK(
FormatArrayAsHex(std::array<uint8_t, 4>{0x13, 0x38, 0x42, 0xAF}) ==
"133842AF");
346TEST_CASE(
"ConvertHexToBytes")
352 std::array<uint8_t, 1> bytes1;
355 CHECK(bytes1[0] == 0x12);
360 std::array<uint8_t, 2> bytes2;
363 CHECK(bytes2[0] == 0x12);
364 CHECK(bytes2[1] == 0x34);
366 std::array<uint8_t, 8> bytes3;
368 CHECK(bytes3[0] == 0x12);
369 CHECK(bytes3[1] == 0x34);
370 CHECK(bytes3[2] == 0x56);
371 CHECK(bytes3[3] == 0x78);
372 CHECK(bytes3[4] == 0x9a);
373 CHECK(bytes3[5] == 0xbc);
374 CHECK(bytes3[6] == 0xde);
375 CHECK(bytes3[7] == 0xf0);
378 CHECK(bytes3[0] == 0x12);
379 CHECK(bytes3[1] == 0x34);
380 CHECK(bytes3[2] == 0x56);
381 CHECK(bytes3[3] == 0x78);
382 CHECK(bytes3[4] == 0x9a);
383 CHECK(bytes3[5] == 0xbc);
384 CHECK(bytes3[6] == 0xde);
385 CHECK(bytes3[7] == 0xf0);
388static const std::vector<std::pair<std::string, std::string>> _str_trim_testcases = {
393 {
" a b c ",
"a b c"},
397TEST_CASE(
"StrTrimInPlace")
399 for (
auto [input, expected] : _str_trim_testcases) {
401 CHECK(input == expected);
405TEST_CASE(
"StrTrimView") {
406 for (
const auto& [input, expected] : _str_trim_testcases) {
407 CHECK(StrTrimView(input) == expected);
bool ConvertHexToBytes(std::string_view hex, std::span< uint8_t > bytes)
Convert a hex-string to a byte-array, while validating it was actually hex.
bool StrEqualsIgnoreCase(const std::string_view str1, const std::string_view str2)
Compares two string( view)s for equality, while ignoring the case of the characters.
std::string FormatArrayAsHex(std::span< const uint8_t > data)
Format a byte array into a continuous hex string.
bool StrStartsWithIgnoreCase(std::string_view str, const std::string_view prefix)
Check whether the given string starts with the given prefix, ignoring case.
int StrCompareIgnoreCase(const std::string_view str1, const std::string_view str2)
Compares two string( view)s, while ignoring the case of the characters.
bool StrEndsWithIgnoreCase(std::string_view str, const std::string_view suffix)
Check whether the given string ends with the given suffix, ignoring case.
void StrTrimInPlace(std::string &str)
Trim the spaces from given string in place, i.e.