split_test.cc
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // split test
4 //
5 // ======================================================================
6 
7 #define BOOST_TEST_MODULE (split test)
8 #include "boost/test/unit_test.hpp"
9 
10 #include "cetlib/split.h"
11 #include <iterator>
12 #include <string>
13 #include <vector>
14 
15 using cet::split;
16 using string_vector = std::vector<std::string>;
17 
18 BOOST_AUTO_TEST_SUITE(split_test)
19 
20 BOOST_AUTO_TEST_CASE(empty_string_test)
21 {
22  std::string s;
23  std::vector<std::string> v;
24  split(s, ':', std::back_inserter(v));
25  BOOST_TEST(v.size() == 0ul);
26 }
27 
28 BOOST_AUTO_TEST_CASE(a_string_test)
29 {
30  std::string s("a");
31  std::vector<std::string> v;
32  split(s, ':', std::back_inserter(v));
33  auto ref = {"a"};
34  BOOST_TEST(v == ref, boost::test_tools::per_element{});
35 }
36 
37 BOOST_AUTO_TEST_CASE(a1_string_test)
38 {
39  std::string s("a:");
40  std::vector<std::string> v;
41  split(s, ':', std::back_inserter(v));
42  auto ref = {"a"};
43  BOOST_TEST(v == ref, boost::test_tools::per_element{});
44 }
45 
46 BOOST_AUTO_TEST_CASE(boo_string_test)
47 {
48  std::string s(":boo");
49  std::vector<std::string> v;
50  split(s, ':', std::back_inserter(v));
51  auto ref = {"boo"};
52  BOOST_TEST(v == ref, boost::test_tools::per_element{});
53 }
54 
55 BOOST_AUTO_TEST_CASE(ab_string_test)
56 {
57  std::string s("a:b");
58  std::vector<std::string> v;
59  split(s, ':', std::back_inserter(v));
60  string_vector const expected{"a", "b"};
61  BOOST_TEST(v == expected);
62 }
63 
64 BOOST_AUTO_TEST_CASE(ab1_string_test)
65 {
66  std::string s("a::b");
67  std::vector<std::string> v;
68  split(s, ':', std::back_inserter(v));
69  string_vector const expected{"a", "b"};
70  BOOST_TEST(v == expected);
71 }
72 
73 BOOST_AUTO_TEST_CASE(split_test_1)
74 {
75  std::string const s("abc:d::ef");
76  std::vector<std::string> v;
77  split(s, ':', std::back_inserter(v));
78  string_vector const expected{"abc", "d", "ef"};
79  BOOST_TEST(v == expected);
80 }
81 
82 BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(empty_string_test)
Definition: split_test.cc:20
const char expected[]
Definition: Exception_t.cc:22
std::string string
Definition: nybbler.cc:12
std::vector< std::string > string_vector
void split(std::string const &s, char c, OutIter dest)
Definition: split.h:35
static QCString * s
Definition: config.cpp:1042