1// Boost string_algo library iterator_test.cpp file ---------------------------//
2
3// Copyright Pavol Droba 2002-2003. Use, modification and
4// distribution is subject to the Boost Software License, Version
5// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6// http://www.boost.org/LICENSE_1_0.txt)
7
8// See http://www.boost.org for updates, documentation, and revision history.
9
10#include <boost/algorithm/string/join.hpp>
11#include <boost/algorithm/string/classification.hpp>
12// equals predicate is used for result comparison
13#include <boost/algorithm/string/predicate.hpp>
14
15// Include unit test framework
16#define BOOST_TEST_MAIN
17#include <boost/test/unit_test.hpp>
18
19#include <string>
20#include <vector>
21#include <iostream>
22
23#include <boost/test/test_tools.hpp>
24
25
26using namespace std;
27using namespace boost;
28
29bool is_not_empty(const std::string& str)
30{
31 return !str.empty();
32}
33
34void join_test()
35{
36 // Prepare inputs
37 vector<string> tokens1;
38 tokens1.push_back("xx");
39 tokens1.push_back("abc");
40 tokens1.push_back("xx");
41
42 vector<string> tokens2;
43 tokens2.push_back("");
44 tokens2.push_back("xx");
45 tokens2.push_back("abc");
46 tokens2.push_back("");
47 tokens2.push_back("abc");
48 tokens2.push_back("xx");
49 tokens2.push_back("");
50
51 vector<string> tokens3;
52 tokens3.push_back("");
53 tokens3.push_back("");
54 tokens3.push_back("");
55
56 vector<string> empty_tokens;
57
58 vector<vector<int> > vtokens;
59 for(unsigned int n=0; n<tokens2.size(); ++n)
60 {
61 vtokens.push_back(vector<int>(tokens2[n].begin(), tokens2[n].end()));
62 }
63
64 BOOST_CHECK( equals(join(tokens1, "-"), "xx-abc-xx") );
65 BOOST_CHECK( equals(join(tokens2, "-"), "-xx-abc--abc-xx-") );
66 BOOST_CHECK( equals(join(vtokens, "-"), "-xx-abc--abc-xx-") );
67 BOOST_CHECK( equals(join(empty_tokens, "-"), "") );
68
69 BOOST_CHECK( equals(join_if(tokens2, "-", is_not_empty), "xx-abc-abc-xx") );
70 BOOST_CHECK( equals(join_if(empty_tokens, "-", is_not_empty), "") );
71 BOOST_CHECK( equals(join_if(tokens3, "-", is_not_empty), "") );
72}
73
74
75BOOST_AUTO_TEST_CASE( test_main )
76{
77 join_test();
78}
79