1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
/*
* SPDX-License-Identifier: GPL-2.0-or-later
* SPDX-FileName: StringUtils.h
* SPDX-FileContributor: Dmitry Vedenko
*/
#include "StringUtils.h"
#include <catch2/catch.hpp>
TEST_CASE("Join", "[StringUtils]")
{
SECTION("Join empty container")
{
std::vector<std::string> container;
REQUIRE(Join(container, ",") == "");
}
SECTION("Join single item")
{
std::vector<std::string> container { "item" };
REQUIRE(Join(container, ",") == "item");
}
SECTION("Join multiple items")
{
std::vector<std::string> container { "item1", "item2", "item3" };
REQUIRE(Join(container, ",") == "item1,item2,item3");
}
}
TEST_CASE("IsPrefixed", "[StringUtils]")
{
SECTION("Empty prefix")
{
REQUIRE(IsPrefixed("test", ""));
}
SECTION("Empty string")
{
REQUIRE_FALSE(IsPrefixed("", "test"));
}
SECTION("Prefix longer than string")
{
REQUIRE_FALSE(IsPrefixed("test", "test1"));
}
SECTION("Prefix is not a prefix")
{
REQUIRE_FALSE(IsPrefixed("test", "abc"));
}
SECTION("Prefix is a prefix")
{
REQUIRE(IsPrefixed("test", "tes"));
}
SECTION("Prefix matches string")
{
REQUIRE(IsPrefixed("test", "test"));
}
SECTION("Case insensitive")
{
REQUIRE(IsPrefixedInsensitive("test", "TEST"));
}
}
|