@@ -31,94 +31,97 @@ TEST_CASE("split format string by specifiers", "[ct_format]") {
31
31
}
32
32
33
33
TEST_CASE (" format a static string" , " [ct_format]" ) {
34
- static_assert (stdx::ct_format<" Hello" >() == " Hello" _cts );
34
+ static_assert (stdx::ct_format<" Hello" >() == " Hello" _fmt_res );
35
35
}
36
36
37
37
TEST_CASE (" format a compile-time stringish argument" , " [ct_format]" ) {
38
38
using namespace std ::string_view_literals;
39
39
static_assert (stdx::ct_format<" Hello {}" >(CX_VALUE (" world" sv)) ==
40
- " Hello world" _cts );
40
+ " Hello world" _fmt_res );
41
41
static_assert (stdx::ct_format<" Hello {}" >(CX_VALUE (" world" _cts)) ==
42
- " Hello world" _cts );
42
+ " Hello world" _fmt_res );
43
43
static_assert (stdx::ct_format<" Hello {}" >(CX_VALUE (" world" )) ==
44
- " Hello world" _cts );
44
+ " Hello world" _fmt_res );
45
45
}
46
46
47
47
TEST_CASE (" format a compile-time integral argument" , " [ct_format]" ) {
48
- static_assert (stdx::ct_format<" Hello {}" >(CX_VALUE (42 )) == " Hello 42" _cts);
48
+ static_assert (stdx::ct_format<" Hello {}" >(CX_VALUE (42 )) ==
49
+ " Hello 42" _fmt_res);
49
50
}
50
51
51
52
TEST_CASE (" format a type argument" , " [ct_format]" ) {
52
53
static_assert (stdx::ct_format<" Hello {}" >(CX_VALUE (int )) ==
53
- " Hello int" _cts );
54
+ " Hello int" _fmt_res );
54
55
}
55
56
56
57
TEST_CASE (" format a compile-time argument with fmt spec" , " [ct_format]" ) {
57
58
static_assert (stdx::ct_format<" Hello {:*>#6x}" >(CX_VALUE (42 )) ==
58
- " Hello **0x2a" _cts );
59
+ " Hello **0x2a" _fmt_res );
59
60
}
60
61
61
62
namespace {
62
63
enum struct E { A };
63
64
}
64
65
65
66
TEST_CASE (" format a compile-time enum argument" , " [ct_format]" ) {
66
- static_assert (stdx::ct_format<" Hello {}" >(CX_VALUE (E::A)) == " Hello A" _cts);
67
+ static_assert (stdx::ct_format<" Hello {}" >(CX_VALUE (E::A)) ==
68
+ " Hello A" _fmt_res);
67
69
}
68
70
69
71
TEST_CASE (" format a runtime argument" , " [ct_format]" ) {
70
- auto x = 17 ;
71
- CHECK (stdx::ct_format<" Hello {}" >(x) ==
72
- stdx::format_result{" Hello {}" _cts, stdx::make_tuple (17 )});
73
- static_assert (stdx::ct_format<" Hello {}" >(17 ) ==
74
- stdx::format_result{" Hello {}" _cts, stdx::make_tuple (17 )});
72
+ constexpr auto x = 17 ;
73
+ constexpr auto expected =
74
+ stdx::format_result{" Hello {}" _ctst, stdx::make_tuple (x)};
75
+
76
+ CHECK (stdx::ct_format<" Hello {}" >(x) == expected);
77
+ static_assert (stdx::ct_format<" Hello {}" >(x) == expected);
75
78
}
76
79
77
80
TEST_CASE (" format a compile-time and a runtime argument (1)" , " [ct_format]" ) {
78
- auto x = 17 ;
79
- CHECK (stdx::ct_format< " Hello {} {} " >( CX_VALUE ( int ), x) = =
80
- stdx::format_result{" Hello int {}" _cts , stdx::make_tuple (17 )}) ;
81
- static_assert (
82
- stdx::ct_format<" Hello {} {}" >(CX_VALUE (int ), 17 ) ==
83
- stdx::format_result{ " Hello int {}" _cts, stdx::make_tuple ( 17 )} );
81
+ constexpr auto x = 17 ;
82
+ constexpr auto expected =
83
+ stdx::format_result{" Hello int {}" _ctst , stdx::make_tuple (x)} ;
84
+
85
+ CHECK ( stdx::ct_format<" Hello {} {}" >(CX_VALUE (int ), x ) == expected);
86
+ static_assert ( stdx::ct_format< " Hello {} {}" >( CX_VALUE ( int ), x) == expected );
84
87
}
85
88
86
89
TEST_CASE (" format a compile-time and a runtime argument (2)" , " [ct_format]" ) {
87
90
static_assert (
88
91
stdx::ct_format<" Hello {} {}" >(42 , CX_VALUE (int )) ==
89
- stdx::format_result{" Hello {} int" _cts , stdx::make_tuple (42 )});
92
+ stdx::format_result{" Hello {} int" _ctst , stdx::make_tuple (42 )});
90
93
}
91
94
92
95
TEST_CASE (" format multiple runtime arguments" , " [ct_format]" ) {
93
96
static_assert (
94
97
stdx::ct_format<" Hello {} {}" >(42 , 17 ) ==
95
- stdx::format_result{" Hello {} {}" _cts , stdx::make_tuple (42 , 17 )});
98
+ stdx::format_result{" Hello {} {}" _ctst , stdx::make_tuple (42 , 17 )});
96
99
}
97
100
98
101
TEST_CASE (" format multiple mixed arguments" , " [ct_format]" ) {
99
102
using namespace std ::string_view_literals;
100
103
auto b = " B" sv;
101
104
CHECK (stdx::ct_format<" Hello {} {} {} {} world" >(42 , CX_VALUE (" A" sv), b,
102
105
CX_VALUE (int )) ==
103
- stdx::format_result{" Hello {} A {} int world" _cts ,
106
+ stdx::format_result{" Hello {} A {} int world" _ctst ,
104
107
stdx::make_tuple (42 , " B" sv)});
105
108
static_assert (stdx::ct_format<" Hello {} {} {} {} world" >(
106
109
42 , CX_VALUE (" A" sv), " B" sv, CX_VALUE (int )) ==
107
- stdx::format_result{" Hello {} A {} int world" _cts ,
110
+ stdx::format_result{" Hello {} A {} int world" _ctst ,
108
111
stdx::make_tuple (42 , " B" sv)});
109
112
}
110
113
111
114
TEST_CASE (" format a formatted string" , " [ct_format]" ) {
112
115
static_assert (stdx::ct_format<" The value is {}." >(
113
116
CX_VALUE (stdx::ct_format<" (year={})" >(2022 ))) ==
114
- stdx::format_result{" The value is (year={})." _cts ,
117
+ stdx::format_result{" The value is (year={})." _ctst ,
115
118
stdx::make_tuple (2022 )});
116
119
}
117
120
118
121
TEST_CASE (" format a ct-formatted string" , " [ct_format]" ) {
119
122
constexpr static auto cts = stdx::ct_format<" (year={})" >(CX_VALUE (2024 ));
120
123
static_assert (stdx::ct_format<" The value is {}." >(CX_VALUE (cts)) ==
121
- " The value is (year=2024)." _cts );
124
+ " The value is (year=2024)." _fmt_res );
122
125
}
123
126
124
127
namespace {
@@ -139,7 +142,7 @@ template <class T, T... Ls, T... Rs>
139
142
TEST_CASE (" format_to a different type" , " [ct_format]" ) {
140
143
using namespace std ::string_view_literals;
141
144
static_assert (stdx::ct_format<" {}" , string_constant>(CX_VALUE (" A" sv)) ==
142
- string_constant<char , ' A' >{});
145
+ stdx::format_result{ string_constant<char , ' A' >{} });
143
146
144
147
auto x = 17 ;
145
148
CHECK (stdx::ct_format<" {}" , string_constant>(x) ==
@@ -152,7 +155,7 @@ TEST_CASE("format_to a different type", "[ct_format]") {
152
155
153
156
TEST_CASE (" format a string-type argument" , " [ct_format]" ) {
154
157
static_assert (stdx::ct_format<" Hello {}!" >(string_constant<char , ' A' >{}) ==
155
- " Hello A!" _cts );
158
+ " Hello A!" _fmt_res );
156
159
}
157
160
158
161
TEST_CASE (" format a formatted string with different type" , " [ct_format]" ) {
@@ -168,7 +171,8 @@ TEST_CASE("format a ct-formatted string with different type", "[ct_format]") {
168
171
stdx::ct_format<" B{}C" , string_constant>(CX_VALUE (2024 ));
169
172
static_assert (
170
173
stdx::ct_format<" A{}D" , string_constant>(CX_VALUE (cts)) ==
171
- string_constant<char , ' A' , ' B' , ' 2' , ' 0' , ' 2' , ' 4' , ' C' , ' D' >{});
174
+ stdx::format_result{
175
+ string_constant<char , ' A' , ' B' , ' 2' , ' 0' , ' 2' , ' 4' , ' C' , ' D' >{}});
172
176
}
173
177
174
178
TEST_CASE (" format multiple mixed arguments with different type" ,
0 commit comments