-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathcmp-lt.cc
76 lines (52 loc) · 1.42 KB
/
cmp-lt.cc
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
64
65
66
67
68
69
70
71
72
73
74
75
76
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE snapper
#include <locale>
#include <boost/test/unit_test.hpp>
#include <snapper/File.h>
using namespace snapper;
namespace std
{
std::ostream&
operator<<(std::ostream& s, const vector<string>& v)
{
for (std::vector<string>::const_iterator it = v.begin(); it != v.end(); ++it)
{
if (it != v.begin())
s << " ";
s << *it;
}
return s;
}
}
namespace snapper
{
bool cmp_lt(const string& lhs, const string& rhs);
}
BOOST_AUTO_TEST_CASE(test1)
{
std::locale::global(std::locale("C"));
vector<string> v = { "A", "B", "b", "a" };
sort(v.begin(), v.end(), cmp_lt);
BOOST_CHECK_EQUAL(v, vector<string>({ "A", "B", "a", "b" }));
}
BOOST_AUTO_TEST_CASE(test2)
{
std::locale::global(std::locale("en_US.UTF-8"));
vector<string> v = { "A", "B", "b", "a" };
sort(v.begin(), v.end(), cmp_lt);
BOOST_CHECK_EQUAL(v, vector<string>({ "a", "A", "b", "B" }));
}
BOOST_AUTO_TEST_CASE(test3)
{
std::locale::global(std::locale("de_DE.UTF-8"));
vector<string> v = { "a", "b", "ä" };
sort(v.begin(), v.end(), cmp_lt);
BOOST_CHECK_EQUAL(v, vector<string>({ "a", "ä", "b" }));
}
BOOST_AUTO_TEST_CASE(test4)
{
std::locale::global(std::locale("en_US.UTF-8"));
vector<string> v = { "a", "\344" }; // invalid UTF-8
sort(v.begin(), v.end(), cmp_lt);
BOOST_CHECK_EQUAL(v, vector<string>({ "\344", "a" }));
}