-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.cpp
More file actions
61 lines (47 loc) · 1.75 KB
/
test.cpp
File metadata and controls
61 lines (47 loc) · 1.75 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
#include "format.hpp"
#include <string>
#include <cstdio>
template <int E = '%', typename... Ts>
void test(const char * result, const char * format, Ts ... a)
{
std::string s = formatting::format<E>(format, a ...);
if (s != result)
printf("fail: |%s| <--> |%s|\n", s.c_str(), result);
}
int main()
{
// normal tests
test("test 100 muh 1c6 blabn",
"test %0% %1% %2% blabn", 100, "muh", formatting::hex(454) );
test("test 100",
"test %0%", 100);
// out of order
test("test muh 100 1c6 blabn",
"test %1% %0% %2% blabn", 100, "muh", formatting::hex(454) );
// skip one
test("test muh 12 blabn",
"test %1% %12% blabn", 100, "muh", formatting::hex(454), 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 );
// too many formats
test("test 100 muh 1c6 blabn",
"test %0% %1% %2% blabn", 100, "muh", formatting::hex(454), 304, "ttt" );
// too little formats and escape
test("test 100 %0% %1% blabn % ",
"test %0% %1% %2% blabn %% ", 100 );
// strange formats
test("100 200 300",
"%0% %1% %2%", 100, 200, 300 );
// fault formats ... these are just a "must not crash"
formatting::print<'%'>("%0% %1% %2\n", 100, 200, 300 );
formatting::print<'%'>("0% %1% %2\n", 100, 200, 300 );
// double use
test("test muh 100 100 1c6 blabn",
"test %1% %0% %0% %2% blabn", 100, "muh", formatting::hex(454) );
test("test 100 100 100 1c6 blabn",
"test %s0% %0% %0% %2% blabn", 100, "muh", formatting::hex(454) );
// other escape
test<'|'>("test pipe 100 100 100 blabn",
"test pipe |s0| |0| |0| blabn", 100, "muh", formatting::hex(454) );
// escaped escape
test("test pipe % 100 100 100 blabn",
"test pipe %% %s0% %0% %0% blabn", 100, "muh", formatting::hex(454) );
}