summaryrefslogtreecommitdiffhomepage
path: root/tests/test-stringhelper.cpp
blob: 7f326af06c25df74e482a9e191ab9e8f5ca44f93 (plain)
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
#include <gtest/gtest.h>

#include "stringhelper.h"

#include <string>
#include <vector>

class StringhelperTest: public ::testing::Test
{
protected:
 StringhelperTest(){
 }

 ~StringhelperTest() override{
 }

 void SetUp() override
 {
 }

 void TearDown() override
 {
 }

};

TEST_F(StringhelperTest, strfmt)
{
 EXPECT_EQ(Reichwein::Stringhelper::strfmt(""), "");
 EXPECT_EQ(Reichwein::Stringhelper::strfmt("abc"), "abc");
 EXPECT_EQ(Reichwein::Stringhelper::strfmt("abc%ddef", 123), "abc123def");
 EXPECT_EQ(Reichwein::Stringhelper::strfmt("abc%sdef", "XYZ"), "abcXYZdef");
}

TEST_F(StringhelperTest, split)
{
 EXPECT_EQ(Reichwein::Stringhelper::split(""), std::vector<std::string>{});
 EXPECT_EQ(Reichwein::Stringhelper::split("abc"), std::vector<std::string>{"abc"});
 std::vector<std::string> v{"abc", "def", "ghi"};
 EXPECT_EQ(Reichwein::Stringhelper::split("abc def ghi"), v);
 EXPECT_EQ(Reichwein::Stringhelper::split("abcxdefxghi", "x"), v);
}

TEST_F(StringhelperTest, join)
{
 EXPECT_EQ(Reichwein::Stringhelper::join({}), "");
 EXPECT_EQ(Reichwein::Stringhelper::join({"abc"}), "abc");
 EXPECT_EQ(Reichwein::Stringhelper::join({"abc", "def"}), "abc\ndef");
 EXPECT_EQ(Reichwein::Stringhelper::join({"abc", "def"}, " "), "abc def");
 EXPECT_EQ(Reichwein::Stringhelper::join({"abc", "def", "ghi"}, "12"), "abc12def12ghi");
}

TEST_F(StringhelperTest, startsWithAnyOfLower)
{
 EXPECT_TRUE(Reichwein::Stringhelper::istartsWithAnyOf("", {""}));
 EXPECT_TRUE(Reichwein::Stringhelper::istartsWithAnyOf("a", {""}));
 EXPECT_TRUE(Reichwein::Stringhelper::istartsWithAnyOf("abc", {"a"}));
 EXPECT_TRUE(Reichwein::Stringhelper::istartsWithAnyOf("abc", {"A"}));
 EXPECT_TRUE(Reichwein::Stringhelper::istartsWithAnyOf("Abc", {"a"}));
 EXPECT_TRUE(Reichwein::Stringhelper::istartsWithAnyOf("Abc", {"A"}));
 EXPECT_TRUE(Reichwein::Stringhelper::istartsWithAnyOf("Abc", {"AB"}));
 EXPECT_TRUE(Reichwein::Stringhelper::istartsWithAnyOf("Abc", {"B", "aB"}));
 
 EXPECT_FALSE(Reichwein::Stringhelper::istartsWithAnyOf("", {"a"}));
 EXPECT_FALSE(Reichwein::Stringhelper::istartsWithAnyOf("Abc", {"B"}));
}