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