forked from openSUSE/snapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable.cc
73 lines (53 loc) · 1.51 KB
/
table.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
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE snapper
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <numeric>
#include <iomanip>
#include "../client/utils/Table.h"
using namespace std;
void
check(const Table& table, const vector<string>& output)
{
ostringstream tmp;
tmp << setw(42) << table;
string lhs = tmp.str();
string rhs = accumulate(output.begin(), output.end(), (string)(""),
[](const string& a, const string& b) { return a + b + '\n'; });
BOOST_CHECK_EQUAL(lhs, rhs);
}
BOOST_AUTO_TEST_CASE(test1)
{
locale::global(locale("en_GB.UTF-8"));
Table table;
TableHeader header;
header.add("Number", TableAlign::RIGHT);
header.add("Name EN");
header.add("Name DE");
header.add("Square", TableAlign::RIGHT);
table.setHeader(header);
TableRow row1;
row1.add("0");
row1.add("zero");
row1.add("Null");
row1.add("0");
table.add(row1);
TableRow row2;
row2 << "1" << "one" << "Eins" << "1";
table.add(row2);
TableRow row3;
row3 << "5" << "five" << "Fünf" << "25";
table.add(row3);
TableRow row4;
row4 << "12" << "twelve" << "Zwölf" << "144";
table.add(row4);
vector<string> output = {
"Number | Name EN | Name DE | Square",
"-------+---------+---------+-------",
" 0 | zero | Null | 0",
" 1 | one | Eins | 1",
" 5 | five | Fünf | 25",
" 12 | twelve | Zwölf | 144"
};
check(table, output);
}