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