-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_utils_test.cpp
More file actions
63 lines (50 loc) · 1.71 KB
/
string_utils_test.cpp
File metadata and controls
63 lines (50 loc) · 1.71 KB
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
#include "string_utils.hpp"
#if defined(TEST_MAIN)
// std
#include <cstring>
#include <iostream>
#include <string>
#include <string_view>
#include <vector>
// local
#include "simple_unit_test.hpp"
namespace util::test {
using stringvector_t = std::vector<std::string>;
using stringviewvector_t = std::vector<std::string_view>;
template <typename T, typename A>
std::ostream& operator<<(std::ostream& os, const std::vector<T, A>& v)
{
static const char separator[] = ", ";
const char* separator_p = "";
for (auto I=std::begin(v); I!=std::end(v); ++I)
{
os << separator_p << *I;
separator_p = separator;
}
return os;
}
} // end of namespace
//
int main(int argc, char* argv[])
{
using namespace std::string_literals;
using namespace util::test;
using namespace util;
ASSERT_EQUAL( trim("trim"), "trim"s );
ASSERT_EQUAL( trim(" trim"), "trim"s );
ASSERT_EQUAL( ltrim(" trim"), "trim"s );
ASSERT_EQUAL( rtrim(" trim"), " trim"s );
ASSERT_EQUAL( trim("trim "), "trim"s );
ASSERT_EQUAL( ltrim("trim "), "trim "s );
ASSERT_EQUAL( rtrim("trim "), "trim"s );
ASSERT_EQUAL( trim(" trim "), "trim"s );
ASSERT_EQUAL( trim(" \t\n"), ""s );
ASSERT_EQUAL( trim(" foo bar zot "), "foo bar zot"s );
ASSERT_EQUAL( split("foo", ','), stringviewvector_t({"foo"}) );
ASSERT_EQUAL( split("", ','), stringviewvector_t{} );
ASSERT_EQUAL( split("foo,bar,zot", ','), stringviewvector_t({"foo", "bar", "zot"}) );
ASSERT_EQUAL( split(",,", ','), stringviewvector_t({"", "", ""}) );
ASSERT_EQUAL( split(",foo,", ','), stringviewvector_t({"", "foo", ""}) );
return failed_tests;
}
#endif