Repository navigation
Expand file tree
/
Copy pathrix_tests.cpp
More file actions
169 lines (134 loc) · 4.08 KB
/
Copy pathrix_tests.cpp
File metadata and controls
169 lines (134 loc) · 4.08 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/**
* @file rix_tests.cpp
* @brief Basic tests for the unified Rix facade.
*
* @author Gaspard Kirira
*/
#include <rix.hpp>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
namespace
{
void expect_true(bool condition, const std::string &message)
{
if (!condition)
{
std::cerr << "FAILED: " << message << '\n';
std::exit(1);
}
}
void test_global_rix_csv_parse()
{
const std::string input =
"name,language\n"
"Ada,C++\n";
const auto table = rix.csv.parse(input);
expect_true(table.size() == 2, "rix.csv.parse should return 2 rows");
expect_true(table[0][0] == "name", "header first field should be name");
expect_true(table[0][1] == "language", "header second field should be language");
expect_true(table[1][0] == "Ada", "data first field should be Ada");
expect_true(table[1][1] == "C++", "data second field should be C++");
}
void test_global_rix_csv_write()
{
const rixlib::csv::Table table = {
{"name", "language"},
{"Ada", "C++"},
};
const std::string output = rix.csv.write(table);
const std::string expected =
"name,language\n"
"Ada,C++\n";
expect_true(output == expected, "rix.csv.write should serialize CSV data");
}
void test_global_rix_debug_format()
{
const std::string output = rix.debug.format("Hello {}", "Rix");
expect_true(
output == "Hello Rix",
"rix.debug.format should format automatic placeholders");
}
void test_global_rix_debug_format_explicit_indexes()
{
const std::string output = rix.debug.format("{0} + {0} = {1}", 2, 4);
expect_true(
output == "2 + 2 = 4",
"rix.debug.format should format explicit placeholders");
}
void test_global_rix_debug_format_escaped_braces()
{
const std::string output = rix.debug.format("{{ value }} = {}", 42);
expect_true(
output == "{ value } = 42",
"rix.debug.format should support escaped braces");
}
void test_global_rix_debug_format_append()
{
std::string output = "prefix: ";
rix.debug.format.append(output, "{}", "ready");
expect_true(
output == "prefix: ready",
"rix.debug.format.append should append formatted text");
}
void test_global_rix_debug_format_to()
{
std::string output = "old";
rix.debug.format.to(output, "status: {}", "ok");
expect_true(
output == "status: ok",
"rix.debug.format.to should replace destination content");
}
void test_global_rix_debug_print_to_stream()
{
std::ostringstream out;
rixlib::print_to(out, "Hello", "Rix");
expect_true(
out.str() == "Hello Rix\n",
"rixlib::print_to should write arguments separated by spaces with newline");
}
void test_global_rix_debug_inspect_to_string()
{
expect_true(
rix.debug.inspect.to_string(42) == "42",
"rix.debug.inspect.to_string should inspect integers");
expect_true(
rix.debug.inspect.to_string(true) == "true",
"rix.debug.inspect.to_string should inspect booleans");
}
void test_global_rix_debug_inspect_check_pass()
{
const bool ok = rix.debug.inspect.check(42, 42);
expect_true(
ok,
"rix.debug.inspect.check should return true when values are equal");
}
void test_global_rix_debug_inspect_check_fail()
{
const bool ok = rix.debug.inspect.check(42, 24);
expect_true(
!ok,
"rix.debug.inspect.check should return false when values are different");
}
void run_tests()
{
test_global_rix_csv_parse();
test_global_rix_csv_write();
test_global_rix_debug_format();
test_global_rix_debug_format_explicit_indexes();
test_global_rix_debug_format_escaped_braces();
test_global_rix_debug_format_append();
test_global_rix_debug_format_to();
test_global_rix_debug_print_to_stream();
test_global_rix_debug_inspect_to_string();
test_global_rix_debug_inspect_check_pass();
test_global_rix_debug_inspect_check_fail();
}
}
int main()
{
run_tests();
std::cout << "rix facade tests passed\n";
return 0;
}