aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.core/tabulate.test.cc
blob: e1ea32f403536d31b41be8a0a0db6ddb4f2f4106 (plain) (blame)
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
// This source code is released into the public domain.

#include <catch2/catch_test_macros.hpp>

import nihil.std;
import nihil.core;

using namespace std::literals;
using namespace nihil;

namespace {
TEST_CASE("tabulate: basic", "[tabulate]")
{
	auto input = std::vector{
		std::vector{"a",   "foo", "b"},
		std::vector{"bar", "c",   "baz"},
	};

	auto result = std::string();
	tabulate("{:1} {:2} {:3}", input, std::back_inserter(result));
	REQUIRE(result ==
"1   2   3\n"
"a   foo b\n"
"bar c   baz\n");
}

TEST_CASE("tabulate: basic wide", "[tabulate]")
{
	auto input = std::vector{
		std::vector{L"a",   L"foo", L"b"},
		std::vector{L"bar", L"c",   L"baz"},
	};

	auto result = std::wstring();
	wtabulate(L"{:1} {:2} {:3}", input, std::back_inserter(result));

	REQUIRE(result ==
L"1   2   3\n"
"a   foo b\n"
"bar c   baz\n");
}

TEST_CASE("tabulate: jagged", "[tabulate]")
{
	auto input = std::vector{
		std::vector{"a",   "foo", "b"},
		std::vector{"bar", "baz"},
	};

	auto result = std::string();
	tabulate("{:1} {:2} {:3}", input, std::back_inserter(result));
	REQUIRE(result ==
"1   2   3\n"
"a   foo b\n"
"bar baz\n");
}

TEST_CASE("tabulate: align", "[tabulate]")
{
	auto input = std::vector{
		std::vector{"a", "longvalue", "s"},
		std::vector{"a", "s",         "longvalue"},
	};

	auto result = std::string();
	tabulate("{:1} {<:2} {>:3}", input, std::back_inserter(result));
	REQUIRE(result ==
"1 2                 3\n"
"a longvalue         s\n"
"a s         longvalue\n");
}
} // anonymous namespace