File: table-formatter.cc

package info (click to toggle)
snapper 0.10.6-1.3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,136 kB
  • sloc: cpp: 24,846; ansic: 1,466; sh: 1,410; makefile: 511; python: 127; ruby: 90
file content (53 lines) | stat: -rw-r--r-- 1,094 bytes parent folder | download | duplicates (4)
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

#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE snapper

#include <boost/test/unit_test.hpp>

#include "../client/utils/TableFormatter.h"


using namespace std;
using namespace snapper;


string
str(const TableFormatter& formatter)
{
    ostringstream stream;
    stream << formatter;
    return stream.str();
}


BOOST_AUTO_TEST_CASE(test1)
{
    locale::global(locale("en_GB.UTF-8"));

    TableFormatter formatter(Ascii);

    formatter.header() = {
	{ "Number", TableAlign::RIGHT },
	{ "Name EN", TableAlign::LEFT },
	{ "Name DE", TableAlign::LEFT },
	{ "Square", TableAlign::RIGHT }
    };

    formatter.rows() = {
	{ "0", "zero", "Null", "0" },
	{ "1", "one", "Eins", "1"} ,
	{ "5", "five", "Fünf", "25" },
	{ "12", "twelve", "Zwölf", "144" }
    };

    string result = {
	"Number | Name EN | Name DE | Square\n"
	"-------+---------+---------+-------\n"
	"     0 | zero    | Null    |      0\n"
	"     1 | one     | Eins    |      1\n"
	"     5 | five    | Fünf    |     25\n"
	"    12 | twelve  | Zwölf   |    144\n"
    };

    BOOST_CHECK_EQUAL(str(formatter), result);
}