split_by_regex_test.cc
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // split_by_regex test
4 //
5 // ======================================================================
6 
7 #define BOOST_TEST_MODULE (split_by_regex test)
8 #include "boost/test/unit_test.hpp"
9 
10 #include "cetlib/split_by_regex.h"
11 #include <string>
12 #include <vector>
13 
15 using string_vector = std::vector<std::string>;
16 
17 BOOST_AUTO_TEST_SUITE(split_by_regex_test)
18 
19 BOOST_AUTO_TEST_CASE(empty_string_test)
20 {
21  string_vector const v = split_by_regex("", ":");
22  BOOST_TEST(v.size() == 1ul);
23 }
24 
25 BOOST_AUTO_TEST_CASE(a_string_test)
26 {
27  string_vector const v = split_by_regex("a", ":");
28  BOOST_TEST(v.size() == 1ul);
29  BOOST_TEST(v[0] == "a");
30 }
31 
32 BOOST_AUTO_TEST_CASE(a1_string_test)
33 {
34  string_vector const v = split_by_regex("a:", ":");
35  BOOST_TEST(v.size() == 1ul);
36  BOOST_TEST(v[0] == "a");
37 }
38 
39 BOOST_AUTO_TEST_CASE(boo_string_test)
40 {
41  string_vector const v = split_by_regex(":boo", ":");
42  string_vector const expected{"", "boo"};
43  BOOST_TEST(v == expected);
44 }
45 
46 BOOST_AUTO_TEST_CASE(ab_string_test)
47 {
48  string_vector const v = split_by_regex("a:b", ":");
49  string_vector const expected{"a", "b"};
50  BOOST_TEST(v == expected);
51 }
52 
53 BOOST_AUTO_TEST_CASE(ab1_string_test)
54 {
55  string_vector const v = split_by_regex("a::b", ":");
56  string_vector const expected{"a", "", "b"};
57  BOOST_TEST(v == expected);
58 }
59 
60 BOOST_AUTO_TEST_CASE(split_test_1)
61 {
62  string_vector const v = split_by_regex("abc:d:ef:", ":");
63  string_vector const expected{"abc", "d", "ef"};
64  BOOST_TEST(v == expected);
65 }
66 
67 BOOST_AUTO_TEST_CASE(split_test_2)
68 {
69  string_vector const v = split_by_regex(
70  "namespace::class::static_function().value", R"((::|\(\)\.))");
71  string_vector const expected{
72  "namespace", "class", "static_function", "value"};
73  BOOST_TEST(v == expected);
74 }
75 
76 BOOST_AUTO_TEST_CASE(variable_subscript)
77 {
78  string_vector const v = split_by_regex("v[0][1][2]", R"((\]\[|\[|\]))");
79  string_vector const expected{"v", "0", "1", "2"};
80  BOOST_TEST(v == expected);
81 }
82 
83 BOOST_AUTO_TEST_SUITE_END()
const char expected[]
Definition: Exception_t.cc:22
std::vector< std::string > split_by_regex(std::string const &str, std::regex const &reDelimSet)
std::vector< std::string > string_vector
BOOST_AUTO_TEST_CASE(empty_string_test)