summaryrefslogtreecommitdiffstatshomepage
path: root/tests/lib/util/corestr.cpp
blob: fa2dcabf48bc1306bdfacfcc6aad64130bf552ee (plain) (blame)
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
// license:BSD-3-Clause
// copyright-holders:Miodrag Milanovic

#include "gtest/gtest.h"
#include "corestr.h"

TEST(corestr,strmakeupper) 
{
   std::string value = "test";
   EXPECT_STREQ("TEST", strmakeupper(value).c_str());
}

TEST(corestr,strmakelower) 
{
   std::string value = "ValUE";
   EXPECT_STREQ("value", strmakelower(value).c_str());
}

TEST(corestr,strreplace) 
{
   std::string value = "Main string";
   EXPECT_EQ(1, strreplace(value,"str","aaa"));
   EXPECT_STREQ("Main aaaing", value.c_str());
   EXPECT_EQ(4, strreplace(value,"a","b"));
}

TEST(corestr,strtrimspace) 
{
   std::string value = "    a value  for test  ";
   EXPECT_STREQ("a value  for test", strtrimspace(value).c_str());
   value = "\r\n\ta value  for test\r\n\n\r";
   EXPECT_STREQ("a value  for test", strtrimspace(value).c_str());
}

TEST(corestr,strreplacechr) 
{
   std::string value = "String for doing replaces";
   strreplacechr(value,'a','A');
   strreplacechr(value,'e','E');
   strreplacechr(value,'i','I');
   strreplacechr(value,'o','O');
   EXPECT_STREQ("StrIng fOr dOIng rEplAcEs", value.c_str());
}

TEST(corestr,strdelchr) 
{
   std::string value = "String for doing deletes";
   strdelchr(value,'a');
   strdelchr(value,'e');
   strdelchr(value,'i');
   strdelchr(value,'o');
   EXPECT_STREQ("Strng fr dng dlts", value.c_str());
}