1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef TEST_STD_UTILITIES_FORMAT_FORMAT_FUNCTIONS_FORMAT_TESTS_H 10 #define TEST_STD_UTILITIES_FORMAT_FORMAT_FUNCTIONS_FORMAT_TESTS_H 11 12 #include <format> 13 14 #include <algorithm> 15 #include <cassert> 16 #include <charconv> 17 #include <cmath> 18 #include <cstdint> 19 #include <iterator> 20 21 #include "string_literal.h" 22 #include "test_macros.h" 23 #include "format.functions.common.h" 24 25 // In this file the following template types are used: 26 // TestFunction must be callable as check(expected-result, string-to-format, args-to-format...) 27 // ExceptionTest must be callable as check_exception(expected-exception, string-to-format, args-to-format...) 28 29 enum class execution_modus { partial, full }; 30 31 template <class CharT> 32 std::vector<std::basic_string_view<CharT>> invalid_types(std::string_view valid) { 33 std::vector<std::basic_string_view<CharT>> result; 34 35 #define CASE(T) \ 36 case #T[0]: \ 37 result.push_back(SV("Invalid formatter type {:" #T "}")); \ 38 break; 39 40 #if TEST_STD_VER > 20 41 constexpr std::string_view types = "aAbBcdeEfFgGopPsxX?"; 42 #else 43 constexpr std::string_view types = "aAbBcdeEfFgGopPsxX"; 44 #endif 45 46 for (auto type : types) { 47 if (valid.find(type) != std::string::npos) 48 continue; 49 50 switch (type) { 51 CASE(a) 52 CASE(A) 53 CASE(b) 54 CASE(B) 55 CASE(c) 56 CASE(d) 57 CASE(e) 58 CASE(E) 59 CASE(f) 60 CASE(F) 61 CASE(g) 62 CASE(G) 63 CASE(o) 64 CASE(p) 65 CASE(P) 66 CASE(s) 67 CASE(x) 68 CASE(X) 69 CASE(?) 70 case 0: 71 break; 72 default: 73 assert(false && "Add the type to the list of cases."); 74 } 75 } 76 #undef CASE 77 78 return result; 79 } 80 81 template <class CharT, class TestFunction> 82 void format_test_buffer_copy(TestFunction check) { 83 // *** copy *** 84 check(SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), 85 SV("{}"), 86 SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); 87 88 check(SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 89 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), 90 SV("{}"), 91 SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 92 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); 93 94 check(SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 95 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 96 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 97 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), 98 SV("{}"), 99 SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 100 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 101 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 102 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); 103 104 check(SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 105 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 106 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 107 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 108 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 109 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 110 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 111 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), 112 SV("{}"), 113 SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 114 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 115 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 116 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 117 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 118 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 119 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 120 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); 121 122 check( 123 SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 124 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 125 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 126 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 127 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 128 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 129 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 130 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 131 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 132 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 133 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 134 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 135 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 136 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 137 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 138 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), 139 SV("{}"), 140 SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 141 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 142 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 143 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 144 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 145 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 146 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 147 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 148 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 149 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 150 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 151 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 152 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 153 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 154 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 155 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); 156 157 // *** copy + push_back *** 158 159 check(SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 160 "X"), 161 SV("{}X"), 162 SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); 163 164 check(SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 165 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 166 "X"), 167 SV("{}X"), 168 SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 169 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); 170 171 check(SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 172 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 173 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 174 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 175 "X"), 176 SV("{}X"), 177 SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 178 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 179 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 180 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); 181 182 check(SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 183 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 184 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 185 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 186 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 187 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 188 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 189 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 190 "X"), 191 SV("{}X"), 192 SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 193 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 194 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 195 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 196 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 197 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 198 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 199 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); 200 201 check( 202 SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 203 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 204 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 205 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 206 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 207 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 208 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 209 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 210 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 211 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 212 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 213 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 214 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 215 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 216 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 217 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 218 "X"), 219 SV("{}X"), 220 SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 221 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 222 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 223 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 224 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 225 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 226 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 227 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 228 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 229 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 230 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 231 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 232 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 233 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 234 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 235 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); 236 237 // *** push_back + copy *** 238 239 check(SV("X" 240 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), 241 SV("X{}"), 242 SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); 243 244 check(SV("X" 245 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 246 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), 247 SV("X{}"), 248 SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 249 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); 250 251 check(SV("X" 252 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 253 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 254 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 255 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), 256 SV("X{}"), 257 SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 258 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 259 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 260 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); 261 262 check(SV("X" 263 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 264 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 265 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 266 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 267 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 268 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 269 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 270 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), 271 SV("X{}"), 272 SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 273 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 274 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 275 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 276 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 277 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 278 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 279 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); 280 281 check( 282 SV("X" 283 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 284 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 285 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 286 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 287 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 288 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 289 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 290 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 291 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 292 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 293 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 294 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 295 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 296 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 297 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 298 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), 299 SV("X{}"), 300 SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 301 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 302 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 303 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 304 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 305 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 306 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 307 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 308 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 309 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 310 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 311 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 312 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 313 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 314 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 315 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); 316 } 317 318 template <class CharT, class TestFunction> 319 void format_test_buffer_full(TestFunction check) { 320 // *** fill *** 321 check(SV("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"), SV("{:|<64}"), SV("")); 322 323 check(SV("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 324 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"), 325 SV("{:|<128}"), 326 SV("")); 327 328 check(SV("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 329 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 330 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 331 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"), 332 SV("{:|<256}"), 333 SV("")); 334 335 check(SV("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 336 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 337 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 338 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 339 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 340 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 341 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 342 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"), 343 SV("{:|<512}"), 344 SV("")); 345 346 check(SV("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 347 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 348 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 349 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 350 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 351 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 352 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 353 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 354 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 355 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 356 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 357 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 358 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 359 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 360 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 361 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"), 362 SV("{:|<1024}"), 363 SV("")); 364 365 // *** fill + push_back *** 366 367 check(SV("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 368 "X"), 369 SV("{:|<64}X"), 370 SV("")); 371 372 check(SV("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 373 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 374 "X"), 375 SV("{:|<128}X"), 376 SV("")); 377 378 check(SV("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 379 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 380 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 381 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 382 "X"), 383 SV("{:|<256}X"), 384 SV("")); 385 386 check(SV("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 387 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 388 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 389 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 390 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 391 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 392 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 393 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 394 "X"), 395 SV("{:|<512}X"), 396 SV("")); 397 398 check(SV("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 399 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 400 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 401 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 402 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 403 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 404 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 405 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 406 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 407 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 408 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 409 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 410 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 411 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 412 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 413 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 414 "X"), 415 SV("{:|<1024}X"), 416 SV("")); 417 418 // *** push_back + fill *** 419 420 check(SV("X" 421 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"), 422 SV("X{:|<64}"), 423 SV("")); 424 425 check(SV("X" 426 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 427 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"), 428 SV("X{:|<128}"), 429 SV("")); 430 431 check(SV("X" 432 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 433 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 434 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 435 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"), 436 SV("X{:|<256}"), 437 SV("")); 438 439 check(SV("X" 440 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 441 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 442 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 443 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 444 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 445 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 446 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 447 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"), 448 SV("X{:|<512}"), 449 SV("")); 450 451 check(SV("X" 452 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 453 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 454 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 455 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 456 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 457 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 458 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 459 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 460 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 461 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 462 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 463 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 464 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 465 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 466 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 467 "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"), 468 SV("X{:|<1024}"), 469 SV("")); 470 } 471 472 // Using a const ref for world and universe so a string literal will be a character array. 473 // When passed as character array W and U have different types. 474 template <class CharT, class W, class U, class TestFunction, class ExceptionTest> 475 void format_test_string(const W& world, const U& universe, TestFunction check, ExceptionTest check_exception) { 476 477 // *** Valid input tests *** 478 // Unused argument is ignored. TODO FMT what does the Standard mandate? 479 check(SV("hello world"), SV("hello {}"), world, universe); 480 check(SV("hello world and universe"), SV("hello {} and {}"), world, universe); 481 check(SV("hello world"), SV("hello {0}"), world, universe); 482 check(SV("hello universe"), SV("hello {1}"), world, universe); 483 check(SV("hello universe and world"), SV("hello {1} and {0}"), world, universe); 484 485 check(SV("hello world"), SV("hello {:_>}"), world); 486 check(SV("hello world "), SV("hello {:8}"), world); 487 check(SV("hello world"), SV("hello {:>8}"), world); 488 check(SV("hello ___world"), SV("hello {:_>8}"), world); 489 check(SV("hello _world__"), SV("hello {:_^8}"), world); 490 check(SV("hello world___"), SV("hello {:_<8}"), world); 491 492 // The fill character ':' is allowed here (P0645) but not in ranges (P2286). 493 check(SV("hello :::world"), SV("hello {::>8}"), world); 494 check(SV("hello <<<world"), SV("hello {:<>8}"), world); 495 check(SV("hello ^^^world"), SV("hello {:^>8}"), world); 496 497 check(SV("hello $world"), SV("hello {:$>{}}"), world, 6); 498 check(SV("hello $world"), SV("hello {0:$>{1}}"), world, 6); 499 check(SV("hello $world"), SV("hello {1:$>{0}}"), 6, world); 500 501 check(SV("hello world"), SV("hello {:.5}"), world); 502 check(SV("hello unive"), SV("hello {:.5}"), universe); 503 504 check(SV("hello univer"), SV("hello {:.{}}"), universe, 6); 505 check(SV("hello univer"), SV("hello {0:.{1}}"), universe, 6); 506 check(SV("hello univer"), SV("hello {1:.{0}}"), 6, universe); 507 508 check(SV("hello %world%"), SV("hello {:%^7.7}"), world); 509 check(SV("hello univers"), SV("hello {:%^7.7}"), universe); 510 check(SV("hello %world%"), SV("hello {:%^{}.{}}"), world, 7, 7); 511 check(SV("hello %world%"), SV("hello {0:%^{1}.{2}}"), world, 7, 7); 512 check(SV("hello %world%"), SV("hello {0:%^{2}.{1}}"), world, 7, 7); 513 check(SV("hello %world%"), SV("hello {1:%^{0}.{2}}"), 7, world, 7); 514 515 check(SV("hello world"), SV("hello {:_>s}"), world); 516 check(SV("hello $world"), SV("hello {:$>{}s}"), world, 6); 517 check(SV("hello world"), SV("hello {:.5s}"), world); 518 check(SV("hello univer"), SV("hello {:.{}s}"), universe, 6); 519 check(SV("hello %world%"), SV("hello {:%^7.7s}"), world); 520 521 check(SV("hello #####uni"), SV("hello {:#>8.3s}"), universe); 522 check(SV("hello ##uni###"), SV("hello {:#^8.3s}"), universe); 523 check(SV("hello uni#####"), SV("hello {:#<8.3s}"), universe); 524 525 // *** sign *** 526 check_exception("The format specifier should consume the input or end with a '}'", SV("hello {:-}"), world); 527 528 // *** alternate form *** 529 check_exception("The format specifier should consume the input or end with a '}'", SV("hello {:#}"), world); 530 531 // *** zero-padding *** 532 check_exception("The width option should not have a leading zero", SV("hello {:0}"), world); 533 534 // *** width *** 535 // Width 0 allowed, but not useful for string arguments. 536 check(SV("hello world"), SV("hello {:{}}"), world, 0); 537 538 #ifdef _LIBCPP_VERSION 539 // This limit isn't specified in the Standard. 540 static_assert(std::__format::__number_max == 2'147'483'647, "Update the assert and the test."); 541 check_exception("The numeric value of the format specifier is too large", SV("{:2147483648}"), world); 542 check_exception("The numeric value of the format specifier is too large", SV("{:5000000000}"), world); 543 check_exception("The numeric value of the format specifier is too large", SV("{:10000000000}"), world); 544 #endif 545 546 check_exception("An argument index may not have a negative value", SV("hello {:{}}"), world, -1); 547 check_exception("The value of the argument index exceeds its maximum value", SV("hello {:{}}"), world, unsigned(-1)); 548 check_exception( 549 "The argument index value is too large for the number of arguments supplied", SV("hello {:{}}"), world); 550 check_exception( 551 "Replacement argument isn't a standard signed or unsigned integer type", SV("hello {:{}}"), world, universe); 552 check_exception("Using manual argument numbering in automatic argument numbering mode", SV("hello {:{0}}"), world, 1); 553 check_exception("Using automatic argument numbering in manual argument numbering mode", SV("hello {0:{}}"), world, 1); 554 // Arg-id may not have leading zeros. 555 check_exception("The argument index is invalid", SV("hello {0:{01}}"), world, 1); 556 557 // *** precision *** 558 #ifdef _LIBCPP_VERSION 559 // This limit isn't specified in the Standard. 560 static_assert(std::__format::__number_max == 2'147'483'647, "Update the assert and the test."); 561 check_exception("The numeric value of the format specifier is too large", SV("{:.2147483648}"), world); 562 check_exception("The numeric value of the format specifier is too large", SV("{:.5000000000}"), world); 563 check_exception("The numeric value of the format specifier is too large", SV("{:.10000000000}"), world); 564 #endif 565 566 // Precision 0 allowed, but not useful for string arguments. 567 check(SV("hello "), SV("hello {:.{}}"), world, 0); 568 // Precision may have leading zeros. Secondly tests the value is still base 10. 569 check(SV("hello 0123456789"), SV("hello {:.000010}"), STR("0123456789abcdef")); 570 check_exception("An argument index may not have a negative value", SV("hello {:.{}}"), world, -1); 571 check_exception("The value of the argument index exceeds its maximum value", SV("hello {:.{}}"), world, ~0u); 572 check_exception( 573 "The argument index value is too large for the number of arguments supplied", SV("hello {:.{}}"), world); 574 check_exception( 575 "Replacement argument isn't a standard signed or unsigned integer type", SV("hello {:.{}}"), world, universe); 576 check_exception("Using manual argument numbering in automatic argument numbering mode", SV("hello {:.{0}}"), world, 577 1); 578 check_exception("Using automatic argument numbering in manual argument numbering mode", SV("hello {0:.{}}"), world, 579 1); 580 // Arg-id may not have leading zeros. 581 check_exception("The argument index is invalid", SV("hello {0:.{01}}"), world, 1); 582 583 // *** locale-specific form *** 584 check_exception("The format specifier should consume the input or end with a '}'", SV("hello {:L}"), world); 585 586 // *** type *** 587 #if TEST_STD_VER > 20 588 const char* valid_types = "s?"; 589 #else 590 const char* valid_types = "s"; 591 #endif 592 for (const auto& fmt : invalid_types<CharT>(valid_types)) 593 check_exception("The type option contains an invalid value for a string formatting argument", fmt, world); 594 } 595 596 template <class CharT, class TestFunction> 597 void format_test_string_unicode([[maybe_unused]] TestFunction check) { 598 // unicode.pass.cpp and ascii.pass.cpp have additional tests. 599 #ifndef TEST_HAS_NO_UNICODE 600 // Make sure all possible types are tested. For clarity don't use macros. 601 if constexpr (std::same_as<CharT, char>) { 602 const char* c_string = "aßc"; 603 check(SV("*aßc*"), SV("{:*^5}"), c_string); 604 check(SV("*aß*"), SV("{:*^4.2}"), c_string); 605 606 check(SV("*aßc*"), SV("{:*^5}"), const_cast<char*>(c_string)); 607 check(SV("*aß*"), SV("{:*^4.2}"), const_cast<char*>(c_string)); 608 609 check(SV("*aßc*"), SV("{:*^5}"), "aßc"); 610 check(SV("*aß*"), SV("{:*^4.2}"), "aßc"); 611 612 check(SV("*aßc*"), SV("{:*^5}"), std::string("aßc")); 613 check(SV("*aß*"), SV("{:*^4.2}"), std::string("aßc")); 614 615 check(SV("*aßc*"), SV("{:*^5}"), std::string_view("aßc")); 616 check(SV("*aß*"), SV("{:*^4.2}"), std::string_view("aßc")); 617 } 618 # ifndef TEST_HAS_NO_WIDE_CHARACTERS 619 else { 620 const wchar_t* c_string = L"aßc"; 621 check(SV("*aßc*"), SV("{:*^5}"), c_string); 622 check(SV("*aß*"), SV("{:*^4.2}"), c_string); 623 624 check(SV("*aßc*"), SV("{:*^5}"), const_cast<wchar_t*>(c_string)); 625 check(SV("*aß*"), SV("{:*^4.2}"), const_cast<wchar_t*>(c_string)); 626 627 check(SV("*aßc*"), SV("{:*^5}"), L"aßc"); 628 check(SV("*aß*"), SV("{:*^4.2}"), L"aßc"); 629 630 check(SV("*aßc*"), SV("{:*^5}"), std::wstring(L"aßc")); 631 check(SV("*aß*"), SV("{:*^4.2}"), std::wstring(L"aßc")); 632 633 check(SV("*aßc*"), SV("{:*^5}"), std::wstring_view(L"aßc")); 634 check(SV("*aß*"), SV("{:*^4.2}"), std::wstring_view(L"aßc")); 635 } 636 # endif // TEST_HAS_NO_WIDE_CHARACTERS 637 638 // ß requires one column 639 check(SV("aßc"), SV("{}"), STR("aßc")); 640 641 check(SV("aßc"), SV("{:.3}"), STR("aßc")); 642 check(SV("aß"), SV("{:.2}"), STR("aßc")); 643 check(SV("a"), SV("{:.1}"), STR("aßc")); 644 645 check(SV("aßc"), SV("{:3.3}"), STR("aßc")); 646 check(SV("aß"), SV("{:2.2}"), STR("aßc")); 647 check(SV("a"), SV("{:1.1}"), STR("aßc")); 648 649 check(SV("aßc---"), SV("{:-<6}"), STR("aßc")); 650 check(SV("-aßc--"), SV("{:-^6}"), STR("aßc")); 651 check(SV("---aßc"), SV("{:->6}"), STR("aßc")); 652 653 // \u1000 requires two columns 654 check(SV("a\u1110c"), SV("{}"), STR("a\u1110c")); 655 656 check(SV("a\u1100c"), SV("{:.4}"), STR("a\u1100c")); 657 check(SV("a\u1100"), SV("{:.3}"), STR("a\u1100c")); 658 check(SV("a"), SV("{:.2}"), STR("a\u1100c")); 659 check(SV("a"), SV("{:.1}"), STR("a\u1100c")); 660 661 check(SV("a\u1100c"), SV("{:-<4.4}"), STR("a\u1100c")); 662 check(SV("a\u1100"), SV("{:-<3.3}"), STR("a\u1100c")); 663 check(SV("a-"), SV("{:-<2.2}"), STR("a\u1100c")); 664 check(SV("a"), SV("{:-<1.1}"), STR("a\u1100c")); 665 666 check(SV("a\u1110c---"), SV("{:-<7}"), STR("a\u1110c")); 667 check(SV("-a\u1110c--"), SV("{:-^7}"), STR("a\u1110c")); 668 check(SV("---a\u1110c"), SV("{:->7}"), STR("a\u1110c")); 669 670 // Examples used in P1868R2 671 check(SV("*\u0041*"), SV("{:*^3}"), STR("\u0041")); // { LATIN CAPITAL LETTER A } 672 check(SV("*\u00c1*"), SV("{:*^3}"), STR("\u00c1")); // { LATIN CAPITAL LETTER A WITH ACUTE } 673 check(SV("*\u0041\u0301*"), 674 SV("{:*^3}"), 675 STR("\u0041\u0301")); // { LATIN CAPITAL LETTER A } { COMBINING ACUTE ACCENT } 676 check(SV("*\u0132*"), SV("{:*^3}"), STR("\u0132")); // { LATIN CAPITAL LIGATURE IJ } 677 check(SV("*\u0394*"), SV("{:*^3}"), STR("\u0394")); // { GREEK CAPITAL LETTER DELTA } 678 679 check(SV("*\u0429*"), SV("{:*^3}"), STR("\u0429")); // { CYRILLIC CAPITAL LETTER SHCHA } 680 check(SV("*\u05d0*"), SV("{:*^3}"), STR("\u05d0")); // { HEBREW LETTER ALEF } 681 check(SV("*\u0634*"), SV("{:*^3}"), STR("\u0634")); // { ARABIC LETTER SHEEN } 682 check(SV("*\u3009*"), SV("{:*^4}"), STR("\u3009")); // { RIGHT-POINTING ANGLE BRACKET } 683 check(SV("*\u754c*"), SV("{:*^4}"), STR("\u754c")); // { CJK Unified Ideograph-754C } 684 check(SV("*\U0001f921*"), SV("{:*^4}"), STR("\U0001f921")); // { UNICORN FACE } 685 check(SV("*\U0001f468\u200d\U0001F469\u200d\U0001F467\u200d\U0001F466*"), 686 SV("{:*^4}"), 687 STR("\U0001f468\u200d\U0001F469\u200d\U0001F467\u200d\U0001F466")); // { Family: Man, Woman, Girl, Boy } 688 #endif // TEST_HAS_NO_UNICODE 689 } 690 691 template <class CharT, class TestFunction, class ExceptionTest> 692 void format_string_tests(TestFunction check, ExceptionTest check_exception) { 693 std::basic_string<CharT> world = STR("world"); 694 std::basic_string<CharT> universe = STR("universe"); 695 696 // Test a string literal in a way it won't decay to a pointer. 697 if constexpr (std::same_as<CharT, char>) 698 format_test_string<CharT>("world", "universe", check, check_exception); 699 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 700 else 701 format_test_string<CharT>(L"world", L"universe", check, check_exception); 702 #endif 703 704 format_test_string<CharT>(world.c_str(), universe.c_str(), check, check_exception); 705 format_test_string<CharT>(const_cast<CharT*>(world.c_str()), const_cast<CharT*>(universe.c_str()), check, 706 check_exception); 707 format_test_string<CharT>(std::basic_string_view<CharT>(world), std::basic_string_view<CharT>(universe), check, 708 check_exception); 709 format_test_string<CharT>(world, universe, check, check_exception); 710 format_test_string_unicode<CharT>(check); 711 } 712 713 template <class CharT, class TestFunction, class ExceptionTest> 714 void format_test_bool(TestFunction check, ExceptionTest check_exception) { 715 716 // *** align-fill & width *** 717 check(SV("answer is 'true '"), SV("answer is '{:7}'"), true); 718 check(SV("answer is ' true'"), SV("answer is '{:>7}'"), true); 719 check(SV("answer is 'true '"), SV("answer is '{:<7}'"), true); 720 check(SV("answer is ' true '"), SV("answer is '{:^7}'"), true); 721 722 check(SV("answer is 'false '"), SV("answer is '{:8s}'"), false); 723 check(SV("answer is ' false'"), SV("answer is '{:>8s}'"), false); 724 check(SV("answer is 'false '"), SV("answer is '{:<8s}'"), false); 725 check(SV("answer is ' false '"), SV("answer is '{:^8s}'"), false); 726 727 // The fill character ':' is allowed here (P0645) but not in ranges (P2286). 728 check(SV("answer is ':::true'"), SV("answer is '{::>7}'"), true); 729 check(SV("answer is 'true:::'"), SV("answer is '{::<7}'"), true); 730 check(SV("answer is ':true::'"), SV("answer is '{::^7}'"), true); 731 732 check(SV("answer is '---false'"), SV("answer is '{:->8s}'"), false); 733 check(SV("answer is 'false---'"), SV("answer is '{:-<8s}'"), false); 734 check(SV("answer is '-false--'"), SV("answer is '{:-^8s}'"), false); 735 736 // *** Sign *** 737 check_exception("The format specifier for a bool does not allow the sign option", SV("{:-}"), true); 738 check_exception("The format specifier for a bool does not allow the sign option", SV("{:+}"), true); 739 check_exception("The format specifier for a bool does not allow the sign option", SV("{: }"), true); 740 741 check_exception("The format specifier for a bool does not allow the sign option", SV("{:-s}"), true); 742 check_exception("The format specifier for a bool does not allow the sign option", SV("{:+s}"), true); 743 check_exception("The format specifier for a bool does not allow the sign option", SV("{: s}"), true); 744 745 // *** alternate form *** 746 check_exception("The format specifier for a bool does not allow the alternate form option", SV("{:#}"), true); 747 check_exception("The format specifier for a bool does not allow the alternate form option", SV("{:#s}"), true); 748 749 // *** zero-padding *** 750 check_exception("The format specifier for a bool does not allow the zero-padding option", SV("{:0}"), true); 751 check_exception("The format specifier for a bool does not allow the zero-padding option", SV("{:0s}"), true); 752 753 // *** precision *** 754 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.}"), true); 755 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.0}"), true); 756 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.42}"), true); 757 758 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.s}"), true); 759 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.0s}"), true); 760 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.42s}"), true); 761 762 // *** locale-specific form *** 763 // See locale-specific_form.pass.cpp 764 765 // *** type *** 766 for (const auto& fmt : invalid_types<CharT>("bBdosxX")) 767 check_exception("The type option contains an invalid value for a bool formatting argument", fmt, true); 768 } 769 770 template <class CharT, class TestFunction, class ExceptionTest> 771 void format_test_bool_as_integer(TestFunction check, ExceptionTest check_exception) { 772 // *** align-fill & width *** 773 check(SV("answer is '1'"), SV("answer is '{:<1d}'"), true); 774 check(SV("answer is '1 '"), SV("answer is '{:<2d}'"), true); 775 check(SV("answer is '0 '"), SV("answer is '{:<2d}'"), false); 776 777 check(SV("answer is ' 1'"), SV("answer is '{:6d}'"), true); 778 check(SV("answer is ' 1'"), SV("answer is '{:>6d}'"), true); 779 check(SV("answer is '1 '"), SV("answer is '{:<6d}'"), true); 780 check(SV("answer is ' 1 '"), SV("answer is '{:^6d}'"), true); 781 782 // The fill character ':' is allowed here (P0645) but not in ranges (P2286). 783 check(SV("answer is ':::::0'"), SV("answer is '{::>6d}'"), false); 784 check(SV("answer is '0:::::'"), SV("answer is '{::<6d}'"), false); 785 check(SV("answer is '::0:::'"), SV("answer is '{::^6d}'"), false); 786 787 // Test whether zero padding is ignored 788 check(SV("answer is ' 1'"), SV("answer is '{:>06d}'"), true); 789 check(SV("answer is '1 '"), SV("answer is '{:<06d}'"), true); 790 check(SV("answer is ' 1 '"), SV("answer is '{:^06d}'"), true); 791 792 // *** Sign *** 793 check(SV("answer is 1"), SV("answer is {:d}"), true); 794 check(SV("answer is 0"), SV("answer is {:-d}"), false); 795 check(SV("answer is +1"), SV("answer is {:+d}"), true); 796 check(SV("answer is 0"), SV("answer is {: d}"), false); 797 798 // *** alternate form *** 799 check(SV("answer is +1"), SV("answer is {:+#d}"), true); 800 check(SV("answer is +1"), SV("answer is {:+b}"), true); 801 check(SV("answer is +0b1"), SV("answer is {:+#b}"), true); 802 check(SV("answer is +0B1"), SV("answer is {:+#B}"), true); 803 check(SV("answer is +1"), SV("answer is {:+o}"), true); 804 check(SV("answer is +01"), SV("answer is {:+#o}"), true); 805 check(SV("answer is +1"), SV("answer is {:+x}"), true); 806 check(SV("answer is +0x1"), SV("answer is {:+#x}"), true); 807 check(SV("answer is +1"), SV("answer is {:+X}"), true); 808 check(SV("answer is +0X1"), SV("answer is {:+#X}"), true); 809 810 check(SV("answer is 0"), SV("answer is {:#d}"), false); 811 check(SV("answer is 0"), SV("answer is {:b}"), false); 812 check(SV("answer is 0b0"), SV("answer is {:#b}"), false); 813 check(SV("answer is 0B0"), SV("answer is {:#B}"), false); 814 check(SV("answer is 0"), SV("answer is {:o}"), false); 815 check(SV("answer is 0"), SV("answer is {:#o}"), false); 816 check(SV("answer is 0"), SV("answer is {:x}"), false); 817 check(SV("answer is 0x0"), SV("answer is {:#x}"), false); 818 check(SV("answer is 0"), SV("answer is {:X}"), false); 819 check(SV("answer is 0X0"), SV("answer is {:#X}"), false); 820 821 // *** zero-padding & width *** 822 check(SV("answer is +00000000001"), SV("answer is {:+#012d}"), true); 823 check(SV("answer is +00000000001"), SV("answer is {:+012b}"), true); 824 check(SV("answer is +0b000000001"), SV("answer is {:+#012b}"), true); 825 check(SV("answer is +0B000000001"), SV("answer is {:+#012B}"), true); 826 check(SV("answer is +00000000001"), SV("answer is {:+012o}"), true); 827 check(SV("answer is +00000000001"), SV("answer is {:+#012o}"), true); 828 check(SV("answer is +00000000001"), SV("answer is {:+012x}"), true); 829 check(SV("answer is +0x000000001"), SV("answer is {:+#012x}"), true); 830 check(SV("answer is +00000000001"), SV("answer is {:+012X}"), true); 831 check(SV("answer is +0X000000001"), SV("answer is {:+#012X}"), true); 832 833 check(SV("answer is 000000000000"), SV("answer is {:#012d}"), false); 834 check(SV("answer is 000000000000"), SV("answer is {:012b}"), false); 835 check(SV("answer is 0b0000000000"), SV("answer is {:#012b}"), false); 836 check(SV("answer is 0B0000000000"), SV("answer is {:#012B}"), false); 837 check(SV("answer is 000000000000"), SV("answer is {:012o}"), false); 838 check(SV("answer is 000000000000"), SV("answer is {:#012o}"), false); 839 check(SV("answer is 000000000000"), SV("answer is {:012x}"), false); 840 check(SV("answer is 0x0000000000"), SV("answer is {:#012x}"), false); 841 check(SV("answer is 000000000000"), SV("answer is {:012X}"), false); 842 check(SV("answer is 0X0000000000"), SV("answer is {:#012X}"), false); 843 844 // *** precision *** 845 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.}"), true); 846 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.0}"), true); 847 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.42}"), true); 848 849 // *** locale-specific form *** 850 // See locale-specific_form.pass.cpp 851 852 // *** type *** 853 for (const auto& fmt : invalid_types<CharT>("bBcdosxX")) 854 check_exception("The type option contains an invalid value for a bool formatting argument", fmt, true); 855 } 856 857 template <class I, class CharT, class TestFunction, class ExceptionTest> 858 void format_test_integer_as_integer(TestFunction check, ExceptionTest check_exception) { 859 // *** align-fill & width *** 860 check(SV("answer is '42'"), SV("answer is '{:<1}'"), I(42)); 861 check(SV("answer is '42'"), SV("answer is '{:<2}'"), I(42)); 862 check(SV("answer is '42 '"), SV("answer is '{:<3}'"), I(42)); 863 864 check(SV("answer is ' 42'"), SV("answer is '{:7}'"), I(42)); 865 check(SV("answer is ' 42'"), SV("answer is '{:>7}'"), I(42)); 866 check(SV("answer is '42 '"), SV("answer is '{:<7}'"), I(42)); 867 check(SV("answer is ' 42 '"), SV("answer is '{:^7}'"), I(42)); 868 869 // The fill character ':' is allowed here (P0645) but not in ranges (P2286). 870 check(SV("answer is ':::::42'"), SV("answer is '{::>7}'"), I(42)); 871 check(SV("answer is '42:::::'"), SV("answer is '{::<7}'"), I(42)); 872 check(SV("answer is '::42:::'"), SV("answer is '{::^7}'"), I(42)); 873 874 // Test whether zero padding is ignored 875 check(SV("answer is ' 42'"), SV("answer is '{:>07}'"), I(42)); 876 check(SV("answer is '42 '"), SV("answer is '{:<07}'"), I(42)); 877 check(SV("answer is ' 42 '"), SV("answer is '{:^07}'"), I(42)); 878 879 // *** Sign *** 880 if constexpr (std::signed_integral<I>) 881 check(SV("answer is -42"), SV("answer is {}"), I(-42)); 882 check(SV("answer is 0"), SV("answer is {}"), I(0)); 883 check(SV("answer is 42"), SV("answer is {}"), I(42)); 884 885 if constexpr (std::signed_integral<I>) 886 check(SV("answer is -42"), SV("answer is {:-}"), I(-42)); 887 check(SV("answer is 0"), SV("answer is {:-}"), I(0)); 888 check(SV("answer is 42"), SV("answer is {:-}"), I(42)); 889 890 if constexpr (std::signed_integral<I>) 891 check(SV("answer is -42"), SV("answer is {:+}"), I(-42)); 892 check(SV("answer is +0"), SV("answer is {:+}"), I(0)); 893 check(SV("answer is +42"), SV("answer is {:+}"), I(42)); 894 895 if constexpr (std::signed_integral<I>) 896 check(SV("answer is -42"), SV("answer is {: }"), I(-42)); 897 check(SV("answer is 0"), SV("answer is {: }"), I(0)); 898 check(SV("answer is 42"), SV("answer is {: }"), I(42)); 899 900 // *** alternate form *** 901 if constexpr (std::signed_integral<I>) { 902 check(SV("answer is -42"), SV("answer is {:#}"), I(-42)); 903 check(SV("answer is -42"), SV("answer is {:#d}"), I(-42)); 904 check(SV("answer is -101010"), SV("answer is {:b}"), I(-42)); 905 check(SV("answer is -0b101010"), SV("answer is {:#b}"), I(-42)); 906 check(SV("answer is -0B101010"), SV("answer is {:#B}"), I(-42)); 907 check(SV("answer is -52"), SV("answer is {:o}"), I(-42)); 908 check(SV("answer is -052"), SV("answer is {:#o}"), I(-42)); 909 check(SV("answer is -2a"), SV("answer is {:x}"), I(-42)); 910 check(SV("answer is -0x2a"), SV("answer is {:#x}"), I(-42)); 911 check(SV("answer is -2A"), SV("answer is {:X}"), I(-42)); 912 check(SV("answer is -0X2A"), SV("answer is {:#X}"), I(-42)); 913 } 914 check(SV("answer is 0"), SV("answer is {:#}"), I(0)); 915 check(SV("answer is 0"), SV("answer is {:#d}"), I(0)); 916 check(SV("answer is 0"), SV("answer is {:b}"), I(0)); 917 check(SV("answer is 0b0"), SV("answer is {:#b}"), I(0)); 918 check(SV("answer is 0B0"), SV("answer is {:#B}"), I(0)); 919 check(SV("answer is 0"), SV("answer is {:o}"), I(0)); 920 check(SV("answer is 0"), SV("answer is {:#o}"), I(0)); 921 check(SV("answer is 0"), SV("answer is {:x}"), I(0)); 922 check(SV("answer is 0x0"), SV("answer is {:#x}"), I(0)); 923 check(SV("answer is 0"), SV("answer is {:X}"), I(0)); 924 check(SV("answer is 0X0"), SV("answer is {:#X}"), I(0)); 925 926 check(SV("answer is +42"), SV("answer is {:+#}"), I(42)); 927 check(SV("answer is +42"), SV("answer is {:+#d}"), I(42)); 928 check(SV("answer is +101010"), SV("answer is {:+b}"), I(42)); 929 check(SV("answer is +0b101010"), SV("answer is {:+#b}"), I(42)); 930 check(SV("answer is +0B101010"), SV("answer is {:+#B}"), I(42)); 931 check(SV("answer is +52"), SV("answer is {:+o}"), I(42)); 932 check(SV("answer is +052"), SV("answer is {:+#o}"), I(42)); 933 check(SV("answer is +2a"), SV("answer is {:+x}"), I(42)); 934 check(SV("answer is +0x2a"), SV("answer is {:+#x}"), I(42)); 935 check(SV("answer is +2A"), SV("answer is {:+X}"), I(42)); 936 check(SV("answer is +0X2A"), SV("answer is {:+#X}"), I(42)); 937 938 // *** zero-padding & width *** 939 if constexpr (std::signed_integral<I>) { 940 check(SV("answer is -00000000042"), SV("answer is {:#012}"), I(-42)); 941 check(SV("answer is -00000000042"), SV("answer is {:#012d}"), I(-42)); 942 check(SV("answer is -00000101010"), SV("answer is {:012b}"), I(-42)); 943 check(SV("answer is -0b000101010"), SV("answer is {:#012b}"), I(-42)); 944 check(SV("answer is -0B000101010"), SV("answer is {:#012B}"), I(-42)); 945 check(SV("answer is -00000000052"), SV("answer is {:012o}"), I(-42)); 946 check(SV("answer is -00000000052"), SV("answer is {:#012o}"), I(-42)); 947 check(SV("answer is -0000000002a"), SV("answer is {:012x}"), I(-42)); 948 check(SV("answer is -0x00000002a"), SV("answer is {:#012x}"), I(-42)); 949 check(SV("answer is -0000000002A"), SV("answer is {:012X}"), I(-42)); 950 check(SV("answer is -0X00000002A"), SV("answer is {:#012X}"), I(-42)); 951 } 952 953 check(SV("answer is 000000000000"), SV("answer is {:#012}"), I(0)); 954 check(SV("answer is 000000000000"), SV("answer is {:#012d}"), I(0)); 955 check(SV("answer is 000000000000"), SV("answer is {:012b}"), I(0)); 956 check(SV("answer is 0b0000000000"), SV("answer is {:#012b}"), I(0)); 957 check(SV("answer is 0B0000000000"), SV("answer is {:#012B}"), I(0)); 958 check(SV("answer is 000000000000"), SV("answer is {:012o}"), I(0)); 959 check(SV("answer is 000000000000"), SV("answer is {:#012o}"), I(0)); 960 check(SV("answer is 000000000000"), SV("answer is {:012x}"), I(0)); 961 check(SV("answer is 0x0000000000"), SV("answer is {:#012x}"), I(0)); 962 check(SV("answer is 000000000000"), SV("answer is {:012X}"), I(0)); 963 check(SV("answer is 0X0000000000"), SV("answer is {:#012X}"), I(0)); 964 965 check(SV("answer is +00000000042"), SV("answer is {:+#012}"), I(42)); 966 check(SV("answer is +00000000042"), SV("answer is {:+#012d}"), I(42)); 967 check(SV("answer is +00000101010"), SV("answer is {:+012b}"), I(42)); 968 check(SV("answer is +0b000101010"), SV("answer is {:+#012b}"), I(42)); 969 check(SV("answer is +0B000101010"), SV("answer is {:+#012B}"), I(42)); 970 check(SV("answer is +00000000052"), SV("answer is {:+012o}"), I(42)); 971 check(SV("answer is +00000000052"), SV("answer is {:+#012o}"), I(42)); 972 check(SV("answer is +0000000002a"), SV("answer is {:+012x}"), I(42)); 973 check(SV("answer is +0x00000002a"), SV("answer is {:+#012x}"), I(42)); 974 check(SV("answer is +0000000002A"), SV("answer is {:+012X}"), I(42)); 975 check(SV("answer is +0X00000002A"), SV("answer is {:+#012X}"), I(42)); 976 977 // *** precision *** 978 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.}"), I(0)); 979 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.0}"), I(0)); 980 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.42}"), I(0)); 981 982 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.{}}"), I(0)); 983 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.{}}"), I(0), true); 984 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.{}}"), I(0), 1.0); 985 986 // *** locale-specific form *** 987 // See locale-specific_form.pass.cpp 988 989 // *** type *** 990 for (const auto& fmt : invalid_types<CharT>("bBcdoxX")) 991 check_exception("The type option contains an invalid value for an integer formatting argument", fmt, I(0)); 992 } 993 994 template <class I, class CharT, class TestFunction, class ExceptionTest> 995 void format_test_integer_as_char(TestFunction check, ExceptionTest check_exception) { 996 // *** align-fill & width *** 997 check(SV("answer is '* '"), SV("answer is '{:6c}'"), I(42)); 998 check(SV("answer is ' *'"), SV("answer is '{:>6c}'"), I(42)); 999 check(SV("answer is '* '"), SV("answer is '{:<6c}'"), I(42)); 1000 check(SV("answer is ' * '"), SV("answer is '{:^6c}'"), I(42)); 1001 1002 // The fill character ':' is allowed here (P0645) but not in ranges (P2286). 1003 check(SV("answer is ':::::*'"), SV("answer is '{::>6c}'"), I(42)); 1004 check(SV("answer is '*:::::'"), SV("answer is '{::<6c}'"), I(42)); 1005 check(SV("answer is '::*:::'"), SV("answer is '{::^6c}'"), I(42)); 1006 1007 // *** Sign *** 1008 check(SV("answer is *"), SV("answer is {:c}"), I(42)); 1009 check_exception("The format specifier for an integer does not allow the sign option", SV("answer is {:-c}"), I(42)); 1010 check_exception("The format specifier for an integer does not allow the sign option", SV("answer is {:+c}"), I(42)); 1011 check_exception("The format specifier for an integer does not allow the sign option", SV("answer is {: c}"), I(42)); 1012 1013 // *** alternate form *** 1014 check_exception( 1015 "The format specifier for an integer does not allow the alternate form option", SV("answer is {:#c}"), I(42)); 1016 1017 // *** zero-padding & width *** 1018 check_exception( 1019 "The format specifier for an integer does not allow the zero-padding option", SV("answer is {:01c}"), I(42)); 1020 1021 // *** precision *** 1022 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.c}"), I(0)); 1023 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.0c}"), I(0)); 1024 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.42c}"), I(0)); 1025 1026 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.{}c}"), I(0)); 1027 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.{}c}"), I(0), true); 1028 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.{}c}"), I(0), 1.0); 1029 1030 // *** locale-specific form *** 1031 // Note it has no effect but it's allowed. 1032 check(SV("answer is '*'"), SV("answer is '{:Lc}'"), I(42)); 1033 1034 // *** type *** 1035 for (const auto& fmt : invalid_types<CharT>("bBcdoxX")) 1036 check_exception("The type option contains an invalid value for an integer formatting argument", fmt, I(42)); 1037 1038 // *** Validate range *** 1039 // The code has some duplications to keep the if statement readable. 1040 if constexpr (std::signed_integral<CharT>) { 1041 if constexpr (std::signed_integral<I> && sizeof(I) > sizeof(CharT)) { 1042 check_exception("Integral value outside the range of the char type", SV("{:c}"), std::numeric_limits<I>::min()); 1043 check_exception("Integral value outside the range of the char type", SV("{:c}"), std::numeric_limits<I>::max()); 1044 } else if constexpr (std::unsigned_integral<I> && sizeof(I) >= sizeof(CharT)) { 1045 check_exception("Integral value outside the range of the char type", SV("{:c}"), std::numeric_limits<I>::max()); 1046 } 1047 } else if constexpr (sizeof(I) > sizeof(CharT)) { 1048 check_exception("Integral value outside the range of the char type", SV("{:c}"), std::numeric_limits<I>::max()); 1049 } 1050 } 1051 1052 template <class I, class CharT, class TestFunction, class ExceptionTest> 1053 void format_test_integer(TestFunction check, ExceptionTest check_exception) { 1054 format_test_integer_as_integer<I, CharT>(check, check_exception); 1055 format_test_integer_as_char<I, CharT>(check, check_exception); 1056 } 1057 1058 template <class CharT, class TestFunction, class ExceptionTest> 1059 void format_test_signed_integer(TestFunction check, ExceptionTest check_exception) { 1060 format_test_integer<signed char, CharT>(check, check_exception); 1061 format_test_integer<short, CharT>(check, check_exception); 1062 format_test_integer<int, CharT>(check, check_exception); 1063 format_test_integer<long, CharT>(check, check_exception); 1064 format_test_integer<long long, CharT>(check, check_exception); 1065 #ifndef TEST_HAS_NO_INT128 1066 format_test_integer<__int128_t, CharT>(check, check_exception); 1067 #endif 1068 // *** check the minima and maxima *** 1069 check(SV("-0b10000000"), SV("{:#b}"), std::numeric_limits<std::int8_t>::min()); 1070 check(SV("-0200"), SV("{:#o}"), std::numeric_limits<std::int8_t>::min()); 1071 check(SV("-128"), SV("{:#}"), std::numeric_limits<std::int8_t>::min()); 1072 check(SV("-0x80"), SV("{:#x}"), std::numeric_limits<std::int8_t>::min()); 1073 1074 check(SV("-0b1000000000000000"), SV("{:#b}"), std::numeric_limits<std::int16_t>::min()); 1075 check(SV("-0100000"), SV("{:#o}"), std::numeric_limits<std::int16_t>::min()); 1076 check(SV("-32768"), SV("{:#}"), std::numeric_limits<std::int16_t>::min()); 1077 check(SV("-0x8000"), SV("{:#x}"), std::numeric_limits<std::int16_t>::min()); 1078 1079 check(SV("-0b10000000000000000000000000000000"), SV("{:#b}"), std::numeric_limits<std::int32_t>::min()); 1080 check(SV("-020000000000"), SV("{:#o}"), std::numeric_limits<std::int32_t>::min()); 1081 check(SV("-2147483648"), SV("{:#}"), std::numeric_limits<std::int32_t>::min()); 1082 check(SV("-0x80000000"), SV("{:#x}"), std::numeric_limits<std::int32_t>::min()); 1083 1084 check(SV("-0b1000000000000000000000000000000000000000000000000000000000000000"), 1085 SV("{:#b}"), 1086 std::numeric_limits<std::int64_t>::min()); 1087 check(SV("-01000000000000000000000"), SV("{:#o}"), std::numeric_limits<std::int64_t>::min()); 1088 check(SV("-9223372036854775808"), SV("{:#}"), std::numeric_limits<std::int64_t>::min()); 1089 check(SV("-0x8000000000000000"), SV("{:#x}"), std::numeric_limits<std::int64_t>::min()); 1090 1091 #ifndef TEST_HAS_NO_INT128 1092 check(SV("-0b1000000000000000000000000000000000000000000000000000000000000000" 1093 "0000000000000000000000000000000000000000000000000000000000000000"), 1094 SV("{:#b}"), 1095 std::numeric_limits<__int128_t>::min()); 1096 check(SV("-02000000000000000000000000000000000000000000"), SV("{:#o}"), std::numeric_limits<__int128_t>::min()); 1097 check(SV("-170141183460469231731687303715884105728"), SV("{:#}"), std::numeric_limits<__int128_t>::min()); 1098 check(SV("-0x80000000000000000000000000000000"), SV("{:#x}"), std::numeric_limits<__int128_t>::min()); 1099 #endif 1100 1101 check(SV("0b1111111"), SV("{:#b}"), std::numeric_limits<std::int8_t>::max()); 1102 check(SV("0177"), SV("{:#o}"), std::numeric_limits<std::int8_t>::max()); 1103 check(SV("127"), SV("{:#}"), std::numeric_limits<std::int8_t>::max()); 1104 check(SV("0x7f"), SV("{:#x}"), std::numeric_limits<std::int8_t>::max()); 1105 1106 check(SV("0b111111111111111"), SV("{:#b}"), std::numeric_limits<std::int16_t>::max()); 1107 check(SV("077777"), SV("{:#o}"), std::numeric_limits<std::int16_t>::max()); 1108 check(SV("32767"), SV("{:#}"), std::numeric_limits<std::int16_t>::max()); 1109 check(SV("0x7fff"), SV("{:#x}"), std::numeric_limits<std::int16_t>::max()); 1110 1111 check(SV("0b1111111111111111111111111111111"), SV("{:#b}"), std::numeric_limits<std::int32_t>::max()); 1112 check(SV("017777777777"), SV("{:#o}"), std::numeric_limits<std::int32_t>::max()); 1113 check(SV("2147483647"), SV("{:#}"), std::numeric_limits<std::int32_t>::max()); 1114 check(SV("0x7fffffff"), SV("{:#x}"), std::numeric_limits<std::int32_t>::max()); 1115 1116 check(SV("0b111111111111111111111111111111111111111111111111111111111111111"), 1117 SV("{:#b}"), 1118 std::numeric_limits<std::int64_t>::max()); 1119 check(SV("0777777777777777777777"), SV("{:#o}"), std::numeric_limits<std::int64_t>::max()); 1120 check(SV("9223372036854775807"), SV("{:#}"), std::numeric_limits<std::int64_t>::max()); 1121 check(SV("0x7fffffffffffffff"), SV("{:#x}"), std::numeric_limits<std::int64_t>::max()); 1122 1123 #ifndef TEST_HAS_NO_INT128 1124 check(SV("0b111111111111111111111111111111111111111111111111111111111111111" 1125 "1111111111111111111111111111111111111111111111111111111111111111"), 1126 SV("{:#b}"), 1127 std::numeric_limits<__int128_t>::max()); 1128 check(SV("01777777777777777777777777777777777777777777"), SV("{:#o}"), std::numeric_limits<__int128_t>::max()); 1129 check(SV("170141183460469231731687303715884105727"), SV("{:#}"), std::numeric_limits<__int128_t>::max()); 1130 check(SV("0x7fffffffffffffffffffffffffffffff"), SV("{:#x}"), std::numeric_limits<__int128_t>::max()); 1131 #endif 1132 } 1133 1134 template <class CharT, class TestFunction, class ExceptionTest> 1135 void format_test_unsigned_integer(TestFunction check, ExceptionTest check_exception) { 1136 format_test_integer<unsigned char, CharT>(check, check_exception); 1137 format_test_integer<unsigned short, CharT>(check, check_exception); 1138 format_test_integer<unsigned, CharT>(check, check_exception); 1139 format_test_integer<unsigned long, CharT>(check, check_exception); 1140 format_test_integer<unsigned long long, CharT>(check, check_exception); 1141 #ifndef TEST_HAS_NO_INT128 1142 format_test_integer<__uint128_t, CharT>(check, check_exception); 1143 #endif 1144 // *** test the maxima *** 1145 check(SV("0b11111111"), SV("{:#b}"), std::numeric_limits<std::uint8_t>::max()); 1146 check(SV("0377"), SV("{:#o}"), std::numeric_limits<std::uint8_t>::max()); 1147 check(SV("255"), SV("{:#}"), std::numeric_limits<std::uint8_t>::max()); 1148 check(SV("0xff"), SV("{:#x}"), std::numeric_limits<std::uint8_t>::max()); 1149 1150 check(SV("0b1111111111111111"), SV("{:#b}"), std::numeric_limits<std::uint16_t>::max()); 1151 check(SV("0177777"), SV("{:#o}"), std::numeric_limits<std::uint16_t>::max()); 1152 check(SV("65535"), SV("{:#}"), std::numeric_limits<std::uint16_t>::max()); 1153 check(SV("0xffff"), SV("{:#x}"), std::numeric_limits<std::uint16_t>::max()); 1154 1155 check(SV("0b11111111111111111111111111111111"), SV("{:#b}"), std::numeric_limits<std::uint32_t>::max()); 1156 check(SV("037777777777"), SV("{:#o}"), std::numeric_limits<std::uint32_t>::max()); 1157 check(SV("4294967295"), SV("{:#}"), std::numeric_limits<std::uint32_t>::max()); 1158 check(SV("0xffffffff"), SV("{:#x}"), std::numeric_limits<std::uint32_t>::max()); 1159 1160 check(SV("0b1111111111111111111111111111111111111111111111111111111111111111"), 1161 SV("{:#b}"), 1162 std::numeric_limits<std::uint64_t>::max()); 1163 check(SV("01777777777777777777777"), SV("{:#o}"), std::numeric_limits<std::uint64_t>::max()); 1164 check(SV("18446744073709551615"), SV("{:#}"), std::numeric_limits<std::uint64_t>::max()); 1165 check(SV("0xffffffffffffffff"), SV("{:#x}"), std::numeric_limits<std::uint64_t>::max()); 1166 1167 #ifndef TEST_HAS_NO_INT128 1168 check(SV("0b1111111111111111111111111111111111111111111111111111111111111111" 1169 "1111111111111111111111111111111111111111111111111111111111111111"), 1170 SV("{:#b}"), 1171 std::numeric_limits<__uint128_t>::max()); 1172 check(SV("03777777777777777777777777777777777777777777"), SV("{:#o}"), std::numeric_limits<__uint128_t>::max()); 1173 check(SV("340282366920938463463374607431768211455"), SV("{:#}"), std::numeric_limits<__uint128_t>::max()); 1174 check(SV("0xffffffffffffffffffffffffffffffff"), SV("{:#x}"), std::numeric_limits<__uint128_t>::max()); 1175 #endif 1176 } 1177 1178 template <class CharT, class TestFunction, class ExceptionTest> 1179 void format_test_char(TestFunction check, ExceptionTest check_exception) { 1180 1181 // ***** Char type ***** 1182 // *** align-fill & width *** 1183 check(SV("answer is '* '"), SV("answer is '{:6}'"), CharT('*')); 1184 check(SV("answer is ' *'"), SV("answer is '{:>6}'"), CharT('*')); 1185 check(SV("answer is '* '"), SV("answer is '{:<6}'"), CharT('*')); 1186 check(SV("answer is ' * '"), SV("answer is '{:^6}'"), CharT('*')); 1187 1188 check(SV("answer is '* '"), SV("answer is '{:6c}'"), CharT('*')); 1189 check(SV("answer is ' *'"), SV("answer is '{:>6c}'"), CharT('*')); 1190 check(SV("answer is '* '"), SV("answer is '{:<6c}'"), CharT('*')); 1191 check(SV("answer is ' * '"), SV("answer is '{:^6c}'"), CharT('*')); 1192 1193 // The fill character ':' is allowed here (P0645) but not in ranges (P2286). 1194 check(SV("answer is ':::::*'"), SV("answer is '{::>6}'"), CharT('*')); 1195 check(SV("answer is '*:::::'"), SV("answer is '{::<6}'"), CharT('*')); 1196 check(SV("answer is '::*:::'"), SV("answer is '{::^6}'"), CharT('*')); 1197 1198 check(SV("answer is '-----*'"), SV("answer is '{:->6c}'"), CharT('*')); 1199 check(SV("answer is '*-----'"), SV("answer is '{:-<6c}'"), CharT('*')); 1200 check(SV("answer is '--*---'"), SV("answer is '{:-^6c}'"), CharT('*')); 1201 1202 // *** Sign *** 1203 check_exception("The format specifier for a character does not allow the sign option", SV("{:-}"), CharT('*')); 1204 check_exception("The format specifier for a character does not allow the sign option", SV("{:+}"), CharT('*')); 1205 check_exception("The format specifier for a character does not allow the sign option", SV("{: }"), CharT('*')); 1206 1207 check_exception("The format specifier for a character does not allow the sign option", SV("{:-c}"), CharT('*')); 1208 check_exception("The format specifier for a character does not allow the sign option", SV("{:+c}"), CharT('*')); 1209 check_exception("The format specifier for a character does not allow the sign option", SV("{: c}"), CharT('*')); 1210 1211 // *** alternate form *** 1212 check_exception( 1213 "The format specifier for a character does not allow the alternate form option", SV("{:#}"), CharT('*')); 1214 check_exception( 1215 "The format specifier for a character does not allow the alternate form option", SV("{:#c}"), CharT('*')); 1216 1217 // *** zero-padding *** 1218 check_exception( 1219 "The format specifier for a character does not allow the zero-padding option", SV("{:0}"), CharT('*')); 1220 check_exception( 1221 "The format specifier for a character does not allow the zero-padding option", SV("{:0c}"), CharT('*')); 1222 1223 // *** precision *** 1224 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.}"), CharT('*')); 1225 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.0}"), CharT('*')); 1226 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.42}"), CharT('*')); 1227 1228 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.c}"), CharT('*')); 1229 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.0c}"), CharT('*')); 1230 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.42c}"), CharT('*')); 1231 1232 // *** locale-specific form *** 1233 // Note it has no effect but it's allowed. 1234 check(SV("answer is '*'"), SV("answer is '{:L}'"), '*'); 1235 check(SV("answer is '*'"), SV("answer is '{:Lc}'"), '*'); 1236 1237 // *** type *** 1238 #if TEST_STD_VER > 20 1239 const char* valid_types = "bBcdoxX?"; 1240 #else 1241 const char* valid_types = "bBcdoxX"; 1242 #endif 1243 for (const auto& fmt : invalid_types<CharT>(valid_types)) 1244 check_exception("The type option contains an invalid value for a character formatting argument", fmt, CharT('*')); 1245 } 1246 1247 template <class CharT, class TestFunction, class ExceptionTest> 1248 void format_test_char_as_integer(TestFunction check, ExceptionTest check_exception) { 1249 // *** align-fill & width *** 1250 check(SV("answer is '42'"), SV("answer is '{:<1d}'"), CharT('*')); 1251 1252 check(SV("answer is '42'"), SV("answer is '{:<2d}'"), CharT('*')); 1253 check(SV("answer is '42 '"), SV("answer is '{:<3d}'"), CharT('*')); 1254 1255 check(SV("answer is ' 42'"), SV("answer is '{:7d}'"), CharT('*')); 1256 check(SV("answer is ' 42'"), SV("answer is '{:>7d}'"), CharT('*')); 1257 check(SV("answer is '42 '"), SV("answer is '{:<7d}'"), CharT('*')); 1258 check(SV("answer is ' 42 '"), SV("answer is '{:^7d}'"), CharT('*')); 1259 1260 // The fill character ':' is allowed here (P0645) but not in ranges (P2286). 1261 check(SV("answer is ':::::42'"), SV("answer is '{::>7d}'"), CharT('*')); 1262 check(SV("answer is '42:::::'"), SV("answer is '{::<7d}'"), CharT('*')); 1263 check(SV("answer is '::42:::'"), SV("answer is '{::^7d}'"), CharT('*')); 1264 1265 // Test whether zero padding is ignored 1266 check(SV("answer is ' 42'"), SV("answer is '{:>07d}'"), CharT('*')); 1267 check(SV("answer is '42 '"), SV("answer is '{:<07d}'"), CharT('*')); 1268 check(SV("answer is ' 42 '"), SV("answer is '{:^07d}'"), CharT('*')); 1269 1270 // *** Sign *** 1271 check(SV("answer is 42"), SV("answer is {:d}"), CharT('*')); 1272 check(SV("answer is 42"), SV("answer is {:-d}"), CharT('*')); 1273 check(SV("answer is +42"), SV("answer is {:+d}"), CharT('*')); 1274 check(SV("answer is 42"), SV("answer is {: d}"), CharT('*')); 1275 1276 // *** alternate form *** 1277 check(SV("answer is +42"), SV("answer is {:+#d}"), CharT('*')); 1278 check(SV("answer is +101010"), SV("answer is {:+b}"), CharT('*')); 1279 check(SV("answer is +0b101010"), SV("answer is {:+#b}"), CharT('*')); 1280 check(SV("answer is +0B101010"), SV("answer is {:+#B}"), CharT('*')); 1281 check(SV("answer is +52"), SV("answer is {:+o}"), CharT('*')); 1282 check(SV("answer is +052"), SV("answer is {:+#o}"), CharT('*')); 1283 check(SV("answer is +2a"), SV("answer is {:+x}"), CharT('*')); 1284 check(SV("answer is +0x2a"), SV("answer is {:+#x}"), CharT('*')); 1285 check(SV("answer is +2A"), SV("answer is {:+X}"), CharT('*')); 1286 check(SV("answer is +0X2A"), SV("answer is {:+#X}"), CharT('*')); 1287 1288 // *** zero-padding & width *** 1289 check(SV("answer is +00000000042"), SV("answer is {:+#012d}"), CharT('*')); 1290 check(SV("answer is +00000101010"), SV("answer is {:+012b}"), CharT('*')); 1291 check(SV("answer is +0b000101010"), SV("answer is {:+#012b}"), CharT('*')); 1292 check(SV("answer is +0B000101010"), SV("answer is {:+#012B}"), CharT('*')); 1293 check(SV("answer is +00000000052"), SV("answer is {:+012o}"), CharT('*')); 1294 check(SV("answer is +00000000052"), SV("answer is {:+#012o}"), CharT('*')); 1295 check(SV("answer is +0000000002a"), SV("answer is {:+012x}"), CharT('*')); 1296 check(SV("answer is +0x00000002a"), SV("answer is {:+#012x}"), CharT('*')); 1297 check(SV("answer is +0000000002A"), SV("answer is {:+012X}"), CharT('*')); 1298 1299 check(SV("answer is +0X00000002A"), SV("answer is {:+#012X}"), CharT('*')); 1300 1301 // *** precision *** 1302 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.d}"), CharT('*')); 1303 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.0d}"), CharT('*')); 1304 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.42d}"), CharT('*')); 1305 1306 // *** locale-specific form *** 1307 // See locale-specific_form.pass.cpp 1308 1309 // *** type *** 1310 #if TEST_STD_VER > 20 1311 const char* valid_types = "bBcdoxX?"; 1312 #else 1313 const char* valid_types = "bBcdoxX"; 1314 #endif 1315 for (const auto& fmt : invalid_types<CharT>(valid_types)) 1316 check_exception("The type option contains an invalid value for a character formatting argument", fmt, CharT('*')); 1317 } 1318 1319 template <class F, class CharT, class TestFunction> 1320 void format_test_floating_point_hex_lower_case(TestFunction check) { 1321 auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" 1322 auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" 1323 1324 // Test whether the hexadecimal letters are the proper case. 1325 // The precision is too large for float, so two tests are used. 1326 check(SV("answer is '1.abcp+0'"), SV("answer is '{:a}'"), F(0x1.abcp+0)); 1327 check(SV("answer is '1.defp+0'"), SV("answer is '{:a}'"), F(0x1.defp+0)); 1328 1329 // *** align-fill & width *** 1330 check(SV("answer is ' 1p-2'"), SV("answer is '{:7a}'"), F(0.25)); 1331 check(SV("answer is ' 1p-2'"), SV("answer is '{:>7a}'"), F(0.25)); 1332 check(SV("answer is '1p-2 '"), SV("answer is '{:<7a}'"), F(0.25)); 1333 check(SV("answer is ' 1p-2 '"), SV("answer is '{:^7a}'"), F(0.25)); 1334 1335 // The fill character ':' is allowed here (P0645) but not in ranges (P2286). 1336 check(SV("answer is ':::1p-3'"), SV("answer is '{::>7a}'"), F(125e-3)); 1337 check(SV("answer is '1p-3:::'"), SV("answer is '{::<7a}'"), F(125e-3)); 1338 check(SV("answer is ':1p-3::'"), SV("answer is '{::^7a}'"), F(125e-3)); 1339 1340 check(SV("answer is '***inf'"), SV("answer is '{:*>6a}'"), std::numeric_limits<F>::infinity()); 1341 check(SV("answer is 'inf***'"), SV("answer is '{:*<6a}'"), std::numeric_limits<F>::infinity()); 1342 check(SV("answer is '*inf**'"), SV("answer is '{:*^6a}'"), std::numeric_limits<F>::infinity()); 1343 1344 check(SV("answer is '###-inf'"), SV("answer is '{:#>7a}'"), -std::numeric_limits<F>::infinity()); 1345 check(SV("answer is '-inf###'"), SV("answer is '{:#<7a}'"), -std::numeric_limits<F>::infinity()); 1346 check(SV("answer is '#-inf##'"), SV("answer is '{:#^7a}'"), -std::numeric_limits<F>::infinity()); 1347 1348 check(SV("answer is '^^^nan'"), SV("answer is '{:^>6a}'"), nan_pos); 1349 check(SV("answer is 'nan^^^'"), SV("answer is '{:^<6a}'"), nan_pos); 1350 check(SV("answer is '^nan^^'"), SV("answer is '{:^^6a}'"), nan_pos); 1351 1352 check(SV("answer is '000-nan'"), SV("answer is '{:0>7a}'"), nan_neg); 1353 check(SV("answer is '-nan000'"), SV("answer is '{:0<7a}'"), nan_neg); 1354 check(SV("answer is '0-nan00'"), SV("answer is '{:0^7a}'"), nan_neg); 1355 1356 // Test whether zero padding is ignored 1357 check(SV("answer is ' 1p-2'"), SV("answer is '{:>07a}'"), F(0.25)); 1358 check(SV("answer is '1p-2 '"), SV("answer is '{:<07a}'"), F(0.25)); 1359 check(SV("answer is ' 1p-2 '"), SV("answer is '{:^07a}'"), F(0.25)); 1360 1361 // *** Sign *** 1362 check(SV("answer is '0p+0'"), SV("answer is '{:a}'"), F(0)); 1363 check(SV("answer is '0p+0'"), SV("answer is '{:-a}'"), F(0)); 1364 check(SV("answer is '+0p+0'"), SV("answer is '{:+a}'"), F(0)); 1365 check(SV("answer is ' 0p+0'"), SV("answer is '{: a}'"), F(0)); 1366 1367 check(SV("answer is '-0p+0'"), SV("answer is '{:a}'"), F(-0.)); 1368 check(SV("answer is '-0p+0'"), SV("answer is '{:-a}'"), F(-0.)); 1369 check(SV("answer is '-0p+0'"), SV("answer is '{:+a}'"), F(-0.)); 1370 check(SV("answer is '-0p+0'"), SV("answer is '{: a}'"), F(-0.)); 1371 1372 // [format.string.std]/5 The sign option applies to floating-point infinity and NaN. 1373 check(SV("answer is 'inf'"), SV("answer is '{:a}'"), std::numeric_limits<F>::infinity()); 1374 check(SV("answer is 'inf'"), SV("answer is '{:-a}'"), std::numeric_limits<F>::infinity()); 1375 check(SV("answer is '+inf'"), SV("answer is '{:+a}'"), std::numeric_limits<F>::infinity()); 1376 check(SV("answer is ' inf'"), SV("answer is '{: a}'"), std::numeric_limits<F>::infinity()); 1377 1378 check(SV("answer is '-inf'"), SV("answer is '{:a}'"), -std::numeric_limits<F>::infinity()); 1379 check(SV("answer is '-inf'"), SV("answer is '{:-a}'"), -std::numeric_limits<F>::infinity()); 1380 check(SV("answer is '-inf'"), SV("answer is '{:+a}'"), -std::numeric_limits<F>::infinity()); 1381 check(SV("answer is '-inf'"), SV("answer is '{: a}'"), -std::numeric_limits<F>::infinity()); 1382 1383 check(SV("answer is 'nan'"), SV("answer is '{:a}'"), nan_pos); 1384 check(SV("answer is 'nan'"), SV("answer is '{:-a}'"), nan_pos); 1385 check(SV("answer is '+nan'"), SV("answer is '{:+a}'"), nan_pos); 1386 check(SV("answer is ' nan'"), SV("answer is '{: a}'"), nan_pos); 1387 1388 check(SV("answer is '-nan'"), SV("answer is '{:a}'"), nan_neg); 1389 check(SV("answer is '-nan'"), SV("answer is '{:-a}'"), nan_neg); 1390 check(SV("answer is '-nan'"), SV("answer is '{:+a}'"), nan_neg); 1391 check(SV("answer is '-nan'"), SV("answer is '{: a}'"), nan_neg); 1392 1393 // *** alternate form *** 1394 // When precision is zero there's no decimal point except when the alternate form is specified. 1395 check(SV("answer is '0p+0'"), SV("answer is '{:a}'"), F(0)); 1396 check(SV("answer is '0.p+0'"), SV("answer is '{:#a}'"), F(0)); 1397 1398 check(SV("answer is '1p+1'"), SV("answer is '{:.0a}'"), F(2.5)); 1399 check(SV("answer is '1.p+1'"), SV("answer is '{:#.0a}'"), F(2.5)); 1400 check(SV("answer is '1.4p+1'"), SV("answer is '{:#a}'"), F(2.5)); 1401 1402 check(SV("answer is 'inf'"), SV("answer is '{:#a}'"), std::numeric_limits<F>::infinity()); 1403 check(SV("answer is '-inf'"), SV("answer is '{:#a}'"), -std::numeric_limits<F>::infinity()); 1404 1405 check(SV("answer is 'nan'"), SV("answer is '{:#a}'"), nan_pos); 1406 check(SV("answer is '-nan'"), SV("answer is '{:#a}'"), nan_neg); 1407 1408 // *** zero-padding & width *** 1409 check(SV("answer is '1p-5'"), SV("answer is '{:04a}'"), 0.03125); 1410 check(SV("answer is '+1p-5'"), SV("answer is '{:+05a}'"), 0.03125); 1411 check(SV("answer is '+01p-5'"), SV("answer is '{:+06a}'"), 0.03125); 1412 1413 check(SV("answer is '0001p-5'"), SV("answer is '{:07a}'"), 0.03125); 1414 check(SV("answer is '0001p-5'"), SV("answer is '{:-07a}'"), 0.03125); 1415 check(SV("answer is '+001p-5'"), SV("answer is '{:+07a}'"), 0.03125); 1416 check(SV("answer is ' 001p-5'"), SV("answer is '{: 07a}'"), 0.03125); 1417 1418 check(SV("answer is ' inf'"), SV("answer is '{:010a}'"), std::numeric_limits<F>::infinity()); 1419 check(SV("answer is ' inf'"), SV("answer is '{:-010a}'"), std::numeric_limits<F>::infinity()); 1420 check(SV("answer is ' +inf'"), SV("answer is '{:+010a}'"), std::numeric_limits<F>::infinity()); 1421 check(SV("answer is ' inf'"), SV("answer is '{: 010a}'"), std::numeric_limits<F>::infinity()); 1422 1423 check(SV("answer is ' -inf'"), SV("answer is '{:010a}'"), -std::numeric_limits<F>::infinity()); 1424 check(SV("answer is ' -inf'"), SV("answer is '{:-010a}'"), -std::numeric_limits<F>::infinity()); 1425 check(SV("answer is ' -inf'"), SV("answer is '{:+010a}'"), -std::numeric_limits<F>::infinity()); 1426 check(SV("answer is ' -inf'"), SV("answer is '{: 010a}'"), -std::numeric_limits<F>::infinity()); 1427 1428 check(SV("answer is ' nan'"), SV("answer is '{:010a}'"), nan_pos); 1429 check(SV("answer is ' nan'"), SV("answer is '{:-010a}'"), nan_pos); 1430 check(SV("answer is ' +nan'"), SV("answer is '{:+010a}'"), nan_pos); 1431 check(SV("answer is ' nan'"), SV("answer is '{: 010a}'"), nan_pos); 1432 1433 check(SV("answer is ' -nan'"), SV("answer is '{:010a}'"), nan_neg); 1434 check(SV("answer is ' -nan'"), SV("answer is '{:-010a}'"), nan_neg); 1435 check(SV("answer is ' -nan'"), SV("answer is '{:+010a}'"), nan_neg); 1436 check(SV("answer is ' -nan'"), SV("answer is '{: 010a}'"), nan_neg); 1437 1438 // *** precision *** 1439 // See format_test_floating_point_hex_lower_case_precision 1440 1441 // *** locale-specific form *** 1442 // See locale-specific_form.pass.cpp 1443 } 1444 1445 template <class F, class CharT, class TestFunction> 1446 void format_test_floating_point_hex_upper_case(TestFunction check) { 1447 auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" 1448 auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" 1449 1450 // Test whether the hexadecimal letters are the proper case. 1451 // The precision is too large for float, so two tests are used. 1452 check(SV("answer is '1.ABCP+0'"), SV("answer is '{:A}'"), F(0x1.abcp+0)); 1453 check(SV("answer is '1.DEFP+0'"), SV("answer is '{:A}'"), F(0x1.defp+0)); 1454 1455 // *** align-fill & width *** 1456 check(SV("answer is ' 1P-2'"), SV("answer is '{:7A}'"), F(0.25)); 1457 check(SV("answer is ' 1P-2'"), SV("answer is '{:>7A}'"), F(0.25)); 1458 check(SV("answer is '1P-2 '"), SV("answer is '{:<7A}'"), F(0.25)); 1459 check(SV("answer is ' 1P-2 '"), SV("answer is '{:^7A}'"), F(0.25)); 1460 1461 check(SV("answer is '---1P-3'"), SV("answer is '{:->7A}'"), F(125e-3)); 1462 check(SV("answer is '1P-3---'"), SV("answer is '{:-<7A}'"), F(125e-3)); 1463 check(SV("answer is '-1P-3--'"), SV("answer is '{:-^7A}'"), F(125e-3)); 1464 1465 check(SV("answer is '***INF'"), SV("answer is '{:*>6A}'"), std::numeric_limits<F>::infinity()); 1466 check(SV("answer is 'INF***'"), SV("answer is '{:*<6A}'"), std::numeric_limits<F>::infinity()); 1467 check(SV("answer is '*INF**'"), SV("answer is '{:*^6A}'"), std::numeric_limits<F>::infinity()); 1468 1469 check(SV("answer is '###-INF'"), SV("answer is '{:#>7A}'"), -std::numeric_limits<F>::infinity()); 1470 check(SV("answer is '-INF###'"), SV("answer is '{:#<7A}'"), -std::numeric_limits<F>::infinity()); 1471 check(SV("answer is '#-INF##'"), SV("answer is '{:#^7A}'"), -std::numeric_limits<F>::infinity()); 1472 1473 check(SV("answer is '^^^NAN'"), SV("answer is '{:^>6A}'"), nan_pos); 1474 check(SV("answer is 'NAN^^^'"), SV("answer is '{:^<6A}'"), nan_pos); 1475 check(SV("answer is '^NAN^^'"), SV("answer is '{:^^6A}'"), nan_pos); 1476 1477 check(SV("answer is '000-NAN'"), SV("answer is '{:0>7A}'"), nan_neg); 1478 check(SV("answer is '-NAN000'"), SV("answer is '{:0<7A}'"), nan_neg); 1479 check(SV("answer is '0-NAN00'"), SV("answer is '{:0^7A}'"), nan_neg); 1480 1481 // Test whether zero padding is ignored 1482 check(SV("answer is ' 1P-2'"), SV("answer is '{:>07A}'"), F(0.25)); 1483 check(SV("answer is '1P-2 '"), SV("answer is '{:<07A}'"), F(0.25)); 1484 check(SV("answer is ' 1P-2 '"), SV("answer is '{:^07A}'"), F(0.25)); 1485 1486 // *** Sign *** 1487 check(SV("answer is '0P+0'"), SV("answer is '{:A}'"), F(0)); 1488 check(SV("answer is '0P+0'"), SV("answer is '{:-A}'"), F(0)); 1489 check(SV("answer is '+0P+0'"), SV("answer is '{:+A}'"), F(0)); 1490 check(SV("answer is ' 0P+0'"), SV("answer is '{: A}'"), F(0)); 1491 1492 check(SV("answer is '-0P+0'"), SV("answer is '{:A}'"), F(-0.)); 1493 check(SV("answer is '-0P+0'"), SV("answer is '{:-A}'"), F(-0.)); 1494 check(SV("answer is '-0P+0'"), SV("answer is '{:+A}'"), F(-0.)); 1495 check(SV("answer is '-0P+0'"), SV("answer is '{: A}'"), F(-0.)); 1496 1497 // [format.string.std]/5 The sign option applies to floating-point infinity and NaN. 1498 check(SV("answer is 'INF'"), SV("answer is '{:A}'"), std::numeric_limits<F>::infinity()); 1499 check(SV("answer is 'INF'"), SV("answer is '{:-A}'"), std::numeric_limits<F>::infinity()); 1500 check(SV("answer is '+INF'"), SV("answer is '{:+A}'"), std::numeric_limits<F>::infinity()); 1501 check(SV("answer is ' INF'"), SV("answer is '{: A}'"), std::numeric_limits<F>::infinity()); 1502 1503 check(SV("answer is '-INF'"), SV("answer is '{:A}'"), -std::numeric_limits<F>::infinity()); 1504 check(SV("answer is '-INF'"), SV("answer is '{:-A}'"), -std::numeric_limits<F>::infinity()); 1505 check(SV("answer is '-INF'"), SV("answer is '{:+A}'"), -std::numeric_limits<F>::infinity()); 1506 check(SV("answer is '-INF'"), SV("answer is '{: A}'"), -std::numeric_limits<F>::infinity()); 1507 1508 check(SV("answer is 'NAN'"), SV("answer is '{:A}'"), nan_pos); 1509 check(SV("answer is 'NAN'"), SV("answer is '{:-A}'"), nan_pos); 1510 check(SV("answer is '+NAN'"), SV("answer is '{:+A}'"), nan_pos); 1511 check(SV("answer is ' NAN'"), SV("answer is '{: A}'"), nan_pos); 1512 1513 check(SV("answer is '-NAN'"), SV("answer is '{:A}'"), nan_neg); 1514 check(SV("answer is '-NAN'"), SV("answer is '{:-A}'"), nan_neg); 1515 check(SV("answer is '-NAN'"), SV("answer is '{:+A}'"), nan_neg); 1516 check(SV("answer is '-NAN'"), SV("answer is '{: A}'"), nan_neg); 1517 1518 // *** alternate form *** 1519 // When precision is zero there's no decimal point except when the alternate form is specified. 1520 check(SV("answer is '0P+0'"), SV("answer is '{:A}'"), F(0)); 1521 check(SV("answer is '0.P+0'"), SV("answer is '{:#A}'"), F(0)); 1522 1523 check(SV("answer is '1P+1'"), SV("answer is '{:.0A}'"), F(2.5)); 1524 check(SV("answer is '1.P+1'"), SV("answer is '{:#.0A}'"), F(2.5)); 1525 check(SV("answer is '1.4P+1'"), SV("answer is '{:#A}'"), F(2.5)); 1526 1527 check(SV("answer is 'INF'"), SV("answer is '{:#A}'"), std::numeric_limits<F>::infinity()); 1528 check(SV("answer is '-INF'"), SV("answer is '{:#A}'"), -std::numeric_limits<F>::infinity()); 1529 1530 check(SV("answer is 'NAN'"), SV("answer is '{:#A}'"), nan_pos); 1531 check(SV("answer is '-NAN'"), SV("answer is '{:#A}'"), nan_neg); 1532 1533 // *** zero-padding & width *** 1534 check(SV("answer is '1P-5'"), SV("answer is '{:04A}'"), 0.03125); 1535 check(SV("answer is '+1P-5'"), SV("answer is '{:+05A}'"), 0.03125); 1536 check(SV("answer is '+01P-5'"), SV("answer is '{:+06A}'"), 0.03125); 1537 1538 check(SV("answer is '0001P-5'"), SV("answer is '{:07A}'"), 0.03125); 1539 check(SV("answer is '0001P-5'"), SV("answer is '{:-07A}'"), 0.03125); 1540 check(SV("answer is '+001P-5'"), SV("answer is '{:+07A}'"), 0.03125); 1541 check(SV("answer is ' 001P-5'"), SV("answer is '{: 07A}'"), 0.03125); 1542 1543 check(SV("answer is ' INF'"), SV("answer is '{:010A}'"), std::numeric_limits<F>::infinity()); 1544 check(SV("answer is ' INF'"), SV("answer is '{:-010A}'"), std::numeric_limits<F>::infinity()); 1545 check(SV("answer is ' +INF'"), SV("answer is '{:+010A}'"), std::numeric_limits<F>::infinity()); 1546 check(SV("answer is ' INF'"), SV("answer is '{: 010A}'"), std::numeric_limits<F>::infinity()); 1547 1548 check(SV("answer is ' -INF'"), SV("answer is '{:010A}'"), -std::numeric_limits<F>::infinity()); 1549 check(SV("answer is ' -INF'"), SV("answer is '{:-010A}'"), -std::numeric_limits<F>::infinity()); 1550 check(SV("answer is ' -INF'"), SV("answer is '{:+010A}'"), -std::numeric_limits<F>::infinity()); 1551 check(SV("answer is ' -INF'"), SV("answer is '{: 010A}'"), -std::numeric_limits<F>::infinity()); 1552 1553 check(SV("answer is ' NAN'"), SV("answer is '{:010A}'"), nan_pos); 1554 check(SV("answer is ' NAN'"), SV("answer is '{:-010A}'"), nan_pos); 1555 check(SV("answer is ' +NAN'"), SV("answer is '{:+010A}'"), nan_pos); 1556 check(SV("answer is ' NAN'"), SV("answer is '{: 010A}'"), nan_pos); 1557 1558 check(SV("answer is ' -NAN'"), SV("answer is '{:010A}'"), nan_neg); 1559 check(SV("answer is ' -NAN'"), SV("answer is '{:-010A}'"), nan_neg); 1560 check(SV("answer is ' -NAN'"), SV("answer is '{:+010A}'"), nan_neg); 1561 check(SV("answer is ' -NAN'"), SV("answer is '{: 010A}'"), nan_neg); 1562 1563 // *** precision *** 1564 // See format_test_floating_point_hex_upper_case_precision 1565 1566 // *** locale-specific form *** 1567 // See locale-specific_form.pass.cpp 1568 } 1569 1570 template <class F, class CharT, class TestFunction> 1571 void format_test_floating_point_hex_lower_case_precision(TestFunction check) { 1572 auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" 1573 auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" 1574 1575 // *** align-fill & width *** 1576 check(SV("answer is ' 1.000000p-2'"), SV("answer is '{:14.6a}'"), F(0.25)); 1577 check(SV("answer is ' 1.000000p-2'"), SV("answer is '{:>14.6a}'"), F(0.25)); 1578 check(SV("answer is '1.000000p-2 '"), SV("answer is '{:<14.6a}'"), F(0.25)); 1579 check(SV("answer is ' 1.000000p-2 '"), SV("answer is '{:^14.6a}'"), F(0.25)); 1580 1581 check(SV("answer is '---1.000000p-3'"), SV("answer is '{:->14.6a}'"), F(125e-3)); 1582 check(SV("answer is '1.000000p-3---'"), SV("answer is '{:-<14.6a}'"), F(125e-3)); 1583 check(SV("answer is '-1.000000p-3--'"), SV("answer is '{:-^14.6a}'"), F(125e-3)); 1584 1585 check(SV("answer is '***inf'"), SV("answer is '{:*>6.6a}'"), std::numeric_limits<F>::infinity()); 1586 check(SV("answer is 'inf***'"), SV("answer is '{:*<6.6a}'"), std::numeric_limits<F>::infinity()); 1587 check(SV("answer is '*inf**'"), SV("answer is '{:*^6.6a}'"), std::numeric_limits<F>::infinity()); 1588 1589 check(SV("answer is '###-inf'"), SV("answer is '{:#>7.6a}'"), -std::numeric_limits<F>::infinity()); 1590 check(SV("answer is '-inf###'"), SV("answer is '{:#<7.6a}'"), -std::numeric_limits<F>::infinity()); 1591 check(SV("answer is '#-inf##'"), SV("answer is '{:#^7.6a}'"), -std::numeric_limits<F>::infinity()); 1592 1593 check(SV("answer is '^^^nan'"), SV("answer is '{:^>6.6a}'"), nan_pos); 1594 check(SV("answer is 'nan^^^'"), SV("answer is '{:^<6.6a}'"), nan_pos); 1595 check(SV("answer is '^nan^^'"), SV("answer is '{:^^6.6a}'"), nan_pos); 1596 1597 check(SV("answer is '000-nan'"), SV("answer is '{:0>7.6a}'"), nan_neg); 1598 check(SV("answer is '-nan000'"), SV("answer is '{:0<7.6a}'"), nan_neg); 1599 check(SV("answer is '0-nan00'"), SV("answer is '{:0^7.6a}'"), nan_neg); 1600 1601 // Test whether zero padding is ignored 1602 check(SV("answer is ' 1.000000p-2'"), SV("answer is '{:>014.6a}'"), F(0.25)); 1603 check(SV("answer is '1.000000p-2 '"), SV("answer is '{:<014.6a}'"), F(0.25)); 1604 check(SV("answer is ' 1.000000p-2 '"), SV("answer is '{:^014.6a}'"), F(0.25)); 1605 1606 // *** Sign *** 1607 check(SV("answer is '0.000000p+0'"), SV("answer is '{:.6a}'"), F(0)); 1608 check(SV("answer is '0.000000p+0'"), SV("answer is '{:-.6a}'"), F(0)); 1609 check(SV("answer is '+0.000000p+0'"), SV("answer is '{:+.6a}'"), F(0)); 1610 check(SV("answer is ' 0.000000p+0'"), SV("answer is '{: .6a}'"), F(0)); 1611 1612 check(SV("answer is '-0.000000p+0'"), SV("answer is '{:.6a}'"), F(-0.)); 1613 check(SV("answer is '-0.000000p+0'"), SV("answer is '{:-.6a}'"), F(-0.)); 1614 check(SV("answer is '-0.000000p+0'"), SV("answer is '{:+.6a}'"), F(-0.)); 1615 check(SV("answer is '-0.000000p+0'"), SV("answer is '{: .6a}'"), F(-0.)); 1616 1617 // [format.string.std]/5 The sign option applies to floating-point infinity and NaN. 1618 check(SV("answer is 'inf'"), SV("answer is '{:.6a}'"), std::numeric_limits<F>::infinity()); 1619 check(SV("answer is 'inf'"), SV("answer is '{:-.6a}'"), std::numeric_limits<F>::infinity()); 1620 check(SV("answer is '+inf'"), SV("answer is '{:+.6a}'"), std::numeric_limits<F>::infinity()); 1621 check(SV("answer is ' inf'"), SV("answer is '{: .6a}'"), std::numeric_limits<F>::infinity()); 1622 1623 check(SV("answer is '-inf'"), SV("answer is '{:.6a}'"), -std::numeric_limits<F>::infinity()); 1624 check(SV("answer is '-inf'"), SV("answer is '{:-.6a}'"), -std::numeric_limits<F>::infinity()); 1625 check(SV("answer is '-inf'"), SV("answer is '{:+.6a}'"), -std::numeric_limits<F>::infinity()); 1626 check(SV("answer is '-inf'"), SV("answer is '{: .6a}'"), -std::numeric_limits<F>::infinity()); 1627 1628 check(SV("answer is 'nan'"), SV("answer is '{:.6a}'"), nan_pos); 1629 check(SV("answer is 'nan'"), SV("answer is '{:-.6a}'"), nan_pos); 1630 check(SV("answer is '+nan'"), SV("answer is '{:+.6a}'"), nan_pos); 1631 check(SV("answer is ' nan'"), SV("answer is '{: .6a}'"), nan_pos); 1632 1633 check(SV("answer is '-nan'"), SV("answer is '{:.6a}'"), nan_neg); 1634 check(SV("answer is '-nan'"), SV("answer is '{:-.6a}'"), nan_neg); 1635 check(SV("answer is '-nan'"), SV("answer is '{:+.6a}'"), nan_neg); 1636 check(SV("answer is '-nan'"), SV("answer is '{: .6a}'"), nan_neg); 1637 1638 // *** alternate form *** 1639 check(SV("answer is '1.400000p+1'"), SV("answer is '{:#.6a}'"), F(2.5)); 1640 1641 check(SV("answer is 'inf'"), SV("answer is '{:#.6a}'"), std::numeric_limits<F>::infinity()); 1642 check(SV("answer is '-inf'"), SV("answer is '{:#.6a}'"), -std::numeric_limits<F>::infinity()); 1643 1644 check(SV("answer is 'nan'"), SV("answer is '{:#.6a}'"), nan_pos); 1645 check(SV("answer is '-nan'"), SV("answer is '{:#.6a}'"), nan_neg); 1646 1647 // *** zero-padding & width *** 1648 check(SV("answer is '1.000000p-5'"), SV("answer is '{:011.6a}'"), 0.03125); 1649 check(SV("answer is '+1.000000p-5'"), SV("answer is '{:+012.6a}'"), 0.03125); 1650 check(SV("answer is '+01.000000p-5'"), SV("answer is '{:+013.6a}'"), 0.03125); 1651 1652 check(SV("answer is '0001.000000p-5'"), SV("answer is '{:014.6a}'"), 0.03125); 1653 check(SV("answer is '0001.000000p-5'"), SV("answer is '{:-014.6a}'"), 0.03125); 1654 check(SV("answer is '+001.000000p-5'"), SV("answer is '{:+014.6a}'"), 0.03125); 1655 check(SV("answer is ' 001.000000p-5'"), SV("answer is '{: 014.6a}'"), 0.03125); 1656 1657 check(SV("answer is ' inf'"), SV("answer is '{:010.6a}'"), std::numeric_limits<F>::infinity()); 1658 check(SV("answer is ' inf'"), SV("answer is '{:-010.6a}'"), std::numeric_limits<F>::infinity()); 1659 check(SV("answer is ' +inf'"), SV("answer is '{:+010.6a}'"), std::numeric_limits<F>::infinity()); 1660 check(SV("answer is ' inf'"), SV("answer is '{: 010.6a}'"), std::numeric_limits<F>::infinity()); 1661 1662 check(SV("answer is ' -inf'"), SV("answer is '{:010.6a}'"), -std::numeric_limits<F>::infinity()); 1663 check(SV("answer is ' -inf'"), SV("answer is '{:-010.6a}'"), -std::numeric_limits<F>::infinity()); 1664 check(SV("answer is ' -inf'"), SV("answer is '{:+010.6a}'"), -std::numeric_limits<F>::infinity()); 1665 check(SV("answer is ' -inf'"), SV("answer is '{: 010.6a}'"), -std::numeric_limits<F>::infinity()); 1666 1667 check(SV("answer is ' nan'"), SV("answer is '{:010.6a}'"), nan_pos); 1668 check(SV("answer is ' nan'"), SV("answer is '{:-010.6a}'"), nan_pos); 1669 check(SV("answer is ' +nan'"), SV("answer is '{:+010.6a}'"), nan_pos); 1670 check(SV("answer is ' nan'"), SV("answer is '{: 010.6a}'"), nan_pos); 1671 1672 check(SV("answer is ' -nan'"), SV("answer is '{:010.6a}'"), nan_neg); 1673 check(SV("answer is ' -nan'"), SV("answer is '{:-010.6a}'"), nan_neg); 1674 check(SV("answer is ' -nan'"), SV("answer is '{:+010.6a}'"), nan_neg); 1675 check(SV("answer is ' -nan'"), SV("answer is '{: 010.6a}'"), nan_neg); 1676 1677 // *** locale-specific form *** 1678 // See locale-specific_form.pass.cpp 1679 } 1680 1681 template <class F, class CharT, class TestFunction> 1682 void format_test_floating_point_hex_upper_case_precision(TestFunction check) { 1683 auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" 1684 auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" 1685 1686 // *** align-fill & width *** 1687 check(SV("answer is ' 1.000000P-2'"), SV("answer is '{:14.6A}'"), F(0.25)); 1688 check(SV("answer is ' 1.000000P-2'"), SV("answer is '{:>14.6A}'"), F(0.25)); 1689 check(SV("answer is '1.000000P-2 '"), SV("answer is '{:<14.6A}'"), F(0.25)); 1690 check(SV("answer is ' 1.000000P-2 '"), SV("answer is '{:^14.6A}'"), F(0.25)); 1691 1692 check(SV("answer is '---1.000000P-3'"), SV("answer is '{:->14.6A}'"), F(125e-3)); 1693 check(SV("answer is '1.000000P-3---'"), SV("answer is '{:-<14.6A}'"), F(125e-3)); 1694 check(SV("answer is '-1.000000P-3--'"), SV("answer is '{:-^14.6A}'"), F(125e-3)); 1695 1696 check(SV("answer is '***INF'"), SV("answer is '{:*>6.6A}'"), std::numeric_limits<F>::infinity()); 1697 check(SV("answer is 'INF***'"), SV("answer is '{:*<6.6A}'"), std::numeric_limits<F>::infinity()); 1698 check(SV("answer is '*INF**'"), SV("answer is '{:*^6.6A}'"), std::numeric_limits<F>::infinity()); 1699 1700 check(SV("answer is '###-INF'"), SV("answer is '{:#>7.6A}'"), -std::numeric_limits<F>::infinity()); 1701 check(SV("answer is '-INF###'"), SV("answer is '{:#<7.6A}'"), -std::numeric_limits<F>::infinity()); 1702 check(SV("answer is '#-INF##'"), SV("answer is '{:#^7.6A}'"), -std::numeric_limits<F>::infinity()); 1703 1704 check(SV("answer is '^^^NAN'"), SV("answer is '{:^>6.6A}'"), nan_pos); 1705 check(SV("answer is 'NAN^^^'"), SV("answer is '{:^<6.6A}'"), nan_pos); 1706 check(SV("answer is '^NAN^^'"), SV("answer is '{:^^6.6A}'"), nan_pos); 1707 1708 check(SV("answer is '000-NAN'"), SV("answer is '{:0>7.6A}'"), nan_neg); 1709 check(SV("answer is '-NAN000'"), SV("answer is '{:0<7.6A}'"), nan_neg); 1710 check(SV("answer is '0-NAN00'"), SV("answer is '{:0^7.6A}'"), nan_neg); 1711 1712 // Test whether zero padding is ignored 1713 check(SV("answer is ' 1.000000P-2'"), SV("answer is '{:>014.6A}'"), F(0.25)); 1714 check(SV("answer is '1.000000P-2 '"), SV("answer is '{:<014.6A}'"), F(0.25)); 1715 check(SV("answer is ' 1.000000P-2 '"), SV("answer is '{:^014.6A}'"), F(0.25)); 1716 1717 // *** Sign *** 1718 check(SV("answer is '0.000000P+0'"), SV("answer is '{:.6A}'"), F(0)); 1719 check(SV("answer is '0.000000P+0'"), SV("answer is '{:-.6A}'"), F(0)); 1720 check(SV("answer is '+0.000000P+0'"), SV("answer is '{:+.6A}'"), F(0)); 1721 check(SV("answer is ' 0.000000P+0'"), SV("answer is '{: .6A}'"), F(0)); 1722 1723 check(SV("answer is '-0.000000P+0'"), SV("answer is '{:.6A}'"), F(-0.)); 1724 check(SV("answer is '-0.000000P+0'"), SV("answer is '{:-.6A}'"), F(-0.)); 1725 check(SV("answer is '-0.000000P+0'"), SV("answer is '{:+.6A}'"), F(-0.)); 1726 check(SV("answer is '-0.000000P+0'"), SV("answer is '{: .6A}'"), F(-0.)); 1727 1728 // [format.string.std]/5 The sign option applies to floating-point infinity and NaN. 1729 check(SV("answer is 'INF'"), SV("answer is '{:.6A}'"), std::numeric_limits<F>::infinity()); 1730 check(SV("answer is 'INF'"), SV("answer is '{:-.6A}'"), std::numeric_limits<F>::infinity()); 1731 check(SV("answer is '+INF'"), SV("answer is '{:+.6A}'"), std::numeric_limits<F>::infinity()); 1732 check(SV("answer is ' INF'"), SV("answer is '{: .6A}'"), std::numeric_limits<F>::infinity()); 1733 1734 check(SV("answer is '-INF'"), SV("answer is '{:.6A}'"), -std::numeric_limits<F>::infinity()); 1735 check(SV("answer is '-INF'"), SV("answer is '{:-.6A}'"), -std::numeric_limits<F>::infinity()); 1736 check(SV("answer is '-INF'"), SV("answer is '{:+.6A}'"), -std::numeric_limits<F>::infinity()); 1737 check(SV("answer is '-INF'"), SV("answer is '{: .6A}'"), -std::numeric_limits<F>::infinity()); 1738 1739 check(SV("answer is 'NAN'"), SV("answer is '{:.6A}'"), nan_pos); 1740 check(SV("answer is 'NAN'"), SV("answer is '{:-.6A}'"), nan_pos); 1741 check(SV("answer is '+NAN'"), SV("answer is '{:+.6A}'"), nan_pos); 1742 check(SV("answer is ' NAN'"), SV("answer is '{: .6A}'"), nan_pos); 1743 1744 check(SV("answer is '-NAN'"), SV("answer is '{:.6A}'"), nan_neg); 1745 check(SV("answer is '-NAN'"), SV("answer is '{:-.6A}'"), nan_neg); 1746 check(SV("answer is '-NAN'"), SV("answer is '{:+.6A}'"), nan_neg); 1747 check(SV("answer is '-NAN'"), SV("answer is '{: .6A}'"), nan_neg); 1748 1749 // *** alternate form *** 1750 check(SV("answer is '1.400000P+1'"), SV("answer is '{:#.6A}'"), F(2.5)); 1751 1752 check(SV("answer is 'INF'"), SV("answer is '{:#.6A}'"), std::numeric_limits<F>::infinity()); 1753 check(SV("answer is '-INF'"), SV("answer is '{:#.6A}'"), -std::numeric_limits<F>::infinity()); 1754 1755 check(SV("answer is 'NAN'"), SV("answer is '{:#.6A}'"), nan_pos); 1756 check(SV("answer is '-NAN'"), SV("answer is '{:#.6A}'"), nan_neg); 1757 1758 // *** zero-padding & width *** 1759 check(SV("answer is '1.000000P-5'"), SV("answer is '{:011.6A}'"), 0.03125); 1760 check(SV("answer is '+1.000000P-5'"), SV("answer is '{:+012.6A}'"), 0.03125); 1761 check(SV("answer is '+01.000000P-5'"), SV("answer is '{:+013.6A}'"), 0.03125); 1762 1763 check(SV("answer is '0001.000000P-5'"), SV("answer is '{:014.6A}'"), 0.03125); 1764 check(SV("answer is '0001.000000P-5'"), SV("answer is '{:-014.6A}'"), 0.03125); 1765 check(SV("answer is '+001.000000P-5'"), SV("answer is '{:+014.6A}'"), 0.03125); 1766 check(SV("answer is ' 001.000000P-5'"), SV("answer is '{: 014.6A}'"), 0.03125); 1767 1768 check(SV("answer is ' INF'"), SV("answer is '{:010.6A}'"), std::numeric_limits<F>::infinity()); 1769 check(SV("answer is ' INF'"), SV("answer is '{:-010.6A}'"), std::numeric_limits<F>::infinity()); 1770 check(SV("answer is ' +INF'"), SV("answer is '{:+010.6A}'"), std::numeric_limits<F>::infinity()); 1771 check(SV("answer is ' INF'"), SV("answer is '{: 010.6A}'"), std::numeric_limits<F>::infinity()); 1772 1773 check(SV("answer is ' -INF'"), SV("answer is '{:010.6A}'"), -std::numeric_limits<F>::infinity()); 1774 check(SV("answer is ' -INF'"), SV("answer is '{:-010.6A}'"), -std::numeric_limits<F>::infinity()); 1775 check(SV("answer is ' -INF'"), SV("answer is '{:+010.6A}'"), -std::numeric_limits<F>::infinity()); 1776 check(SV("answer is ' -INF'"), SV("answer is '{: 010.6A}'"), -std::numeric_limits<F>::infinity()); 1777 1778 check(SV("answer is ' NAN'"), SV("answer is '{:010.6A}'"), nan_pos); 1779 check(SV("answer is ' NAN'"), SV("answer is '{:-010.6A}'"), nan_pos); 1780 check(SV("answer is ' +NAN'"), SV("answer is '{:+010.6A}'"), nan_pos); 1781 check(SV("answer is ' NAN'"), SV("answer is '{: 010.6A}'"), nan_pos); 1782 1783 check(SV("answer is ' -NAN'"), SV("answer is '{:010.6A}'"), nan_neg); 1784 check(SV("answer is ' -NAN'"), SV("answer is '{:-010.6A}'"), nan_neg); 1785 check(SV("answer is ' -NAN'"), SV("answer is '{:+010.6A}'"), nan_neg); 1786 check(SV("answer is ' -NAN'"), SV("answer is '{: 010.6A}'"), nan_neg); 1787 1788 // *** locale-specific form *** 1789 // See locale-specific_form.pass.cpp 1790 } 1791 1792 template <class F, class CharT, class TestFunction> 1793 void format_test_floating_point_scientific_lower_case(TestFunction check) { 1794 auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" 1795 auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" 1796 1797 // *** align-fill & width *** 1798 check(SV("answer is ' 2.500000e-01'"), SV("answer is '{:15e}'"), F(0.25)); 1799 check(SV("answer is ' 2.500000e-01'"), SV("answer is '{:>15e}'"), F(0.25)); 1800 check(SV("answer is '2.500000e-01 '"), SV("answer is '{:<15e}'"), F(0.25)); 1801 check(SV("answer is ' 2.500000e-01 '"), SV("answer is '{:^15e}'"), F(0.25)); 1802 1803 check(SV("answer is '---1.250000e-01'"), SV("answer is '{:->15e}'"), F(125e-3)); 1804 check(SV("answer is '1.250000e-01---'"), SV("answer is '{:-<15e}'"), F(125e-3)); 1805 check(SV("answer is '-1.250000e-01--'"), SV("answer is '{:-^15e}'"), F(125e-3)); 1806 1807 check(SV("answer is '***inf'"), SV("answer is '{:*>6e}'"), std::numeric_limits<F>::infinity()); 1808 check(SV("answer is 'inf***'"), SV("answer is '{:*<6e}'"), std::numeric_limits<F>::infinity()); 1809 check(SV("answer is '*inf**'"), SV("answer is '{:*^6e}'"), std::numeric_limits<F>::infinity()); 1810 1811 check(SV("answer is '###-inf'"), SV("answer is '{:#>7e}'"), -std::numeric_limits<F>::infinity()); 1812 check(SV("answer is '-inf###'"), SV("answer is '{:#<7e}'"), -std::numeric_limits<F>::infinity()); 1813 check(SV("answer is '#-inf##'"), SV("answer is '{:#^7e}'"), -std::numeric_limits<F>::infinity()); 1814 1815 check(SV("answer is '^^^nan'"), SV("answer is '{:^>6e}'"), nan_pos); 1816 check(SV("answer is 'nan^^^'"), SV("answer is '{:^<6e}'"), nan_pos); 1817 check(SV("answer is '^nan^^'"), SV("answer is '{:^^6e}'"), nan_pos); 1818 1819 check(SV("answer is '000-nan'"), SV("answer is '{:0>7e}'"), nan_neg); 1820 check(SV("answer is '-nan000'"), SV("answer is '{:0<7e}'"), nan_neg); 1821 check(SV("answer is '0-nan00'"), SV("answer is '{:0^7e}'"), nan_neg); 1822 1823 // Test whether zero padding is ignored 1824 check(SV("answer is ' 2.500000e-01'"), SV("answer is '{:>015e}'"), F(0.25)); 1825 check(SV("answer is '2.500000e-01 '"), SV("answer is '{:<015e}'"), F(0.25)); 1826 check(SV("answer is ' 2.500000e-01 '"), SV("answer is '{:^015e}'"), F(0.25)); 1827 1828 // *** Sign *** 1829 check(SV("answer is '0.000000e+00'"), SV("answer is '{:e}'"), F(0)); 1830 check(SV("answer is '0.000000e+00'"), SV("answer is '{:-e}'"), F(0)); 1831 check(SV("answer is '+0.000000e+00'"), SV("answer is '{:+e}'"), F(0)); 1832 check(SV("answer is ' 0.000000e+00'"), SV("answer is '{: e}'"), F(0)); 1833 1834 check(SV("answer is '-0.000000e+00'"), SV("answer is '{:e}'"), F(-0.)); 1835 check(SV("answer is '-0.000000e+00'"), SV("answer is '{:-e}'"), F(-0.)); 1836 check(SV("answer is '-0.000000e+00'"), SV("answer is '{:+e}'"), F(-0.)); 1837 check(SV("answer is '-0.000000e+00'"), SV("answer is '{: e}'"), F(-0.)); 1838 1839 // [format.string.std]/5 The sign option applies to floating-point infinity and NaN. 1840 check(SV("answer is 'inf'"), SV("answer is '{:e}'"), std::numeric_limits<F>::infinity()); 1841 check(SV("answer is 'inf'"), SV("answer is '{:-e}'"), std::numeric_limits<F>::infinity()); 1842 check(SV("answer is '+inf'"), SV("answer is '{:+e}'"), std::numeric_limits<F>::infinity()); 1843 check(SV("answer is ' inf'"), SV("answer is '{: e}'"), std::numeric_limits<F>::infinity()); 1844 1845 check(SV("answer is '-inf'"), SV("answer is '{:e}'"), -std::numeric_limits<F>::infinity()); 1846 check(SV("answer is '-inf'"), SV("answer is '{:-e}'"), -std::numeric_limits<F>::infinity()); 1847 check(SV("answer is '-inf'"), SV("answer is '{:+e}'"), -std::numeric_limits<F>::infinity()); 1848 check(SV("answer is '-inf'"), SV("answer is '{: e}'"), -std::numeric_limits<F>::infinity()); 1849 1850 check(SV("answer is 'nan'"), SV("answer is '{:e}'"), nan_pos); 1851 check(SV("answer is 'nan'"), SV("answer is '{:-e}'"), nan_pos); 1852 check(SV("answer is '+nan'"), SV("answer is '{:+e}'"), nan_pos); 1853 check(SV("answer is ' nan'"), SV("answer is '{: e}'"), nan_pos); 1854 1855 check(SV("answer is '-nan'"), SV("answer is '{:e}'"), nan_neg); 1856 check(SV("answer is '-nan'"), SV("answer is '{:-e}'"), nan_neg); 1857 check(SV("answer is '-nan'"), SV("answer is '{:+e}'"), nan_neg); 1858 check(SV("answer is '-nan'"), SV("answer is '{: e}'"), nan_neg); 1859 1860 // *** alternate form ** 1861 // When precision is zero there's no decimal point except when the alternate form is specified. 1862 check(SV("answer is '0e+00'"), SV("answer is '{:.0e}'"), F(0)); 1863 check(SV("answer is '0.e+00'"), SV("answer is '{:#.0e}'"), F(0)); 1864 1865 check(SV("answer is '0.000000e+00'"), SV("answer is '{:#e}'"), F(0)); 1866 check(SV("answer is '2.500000e+00'"), SV("answer is '{:#e}'"), F(2.5)); 1867 1868 check(SV("answer is 'inf'"), SV("answer is '{:#e}'"), std::numeric_limits<F>::infinity()); 1869 check(SV("answer is '-inf'"), SV("answer is '{:#e}'"), -std::numeric_limits<F>::infinity()); 1870 1871 check(SV("answer is 'nan'"), SV("answer is '{:#e}'"), nan_pos); 1872 check(SV("answer is '-nan'"), SV("answer is '{:#e}'"), nan_neg); 1873 1874 // *** zero-padding & width *** 1875 check(SV("answer is '3.125000e-02'"), SV("answer is '{:07e}'"), 0.03125); 1876 check(SV("answer is '+3.125000e-02'"), SV("answer is '{:+07e}'"), 0.03125); 1877 check(SV("answer is '+3.125000e-02'"), SV("answer is '{:+08e}'"), 0.03125); 1878 check(SV("answer is '+3.125000e-02'"), SV("answer is '{:+09e}'"), 0.03125); 1879 1880 check(SV("answer is '003.125000e-02'"), SV("answer is '{:014e}'"), 0.03125); 1881 check(SV("answer is '003.125000e-02'"), SV("answer is '{:-014e}'"), 0.03125); 1882 check(SV("answer is '+03.125000e-02'"), SV("answer is '{:+014e}'"), 0.03125); 1883 check(SV("answer is ' 03.125000e-02'"), SV("answer is '{: 014e}'"), 0.03125); 1884 1885 check(SV("answer is ' inf'"), SV("answer is '{:010e}'"), std::numeric_limits<F>::infinity()); 1886 check(SV("answer is ' inf'"), SV("answer is '{:-010e}'"), std::numeric_limits<F>::infinity()); 1887 check(SV("answer is ' +inf'"), SV("answer is '{:+010e}'"), std::numeric_limits<F>::infinity()); 1888 check(SV("answer is ' inf'"), SV("answer is '{: 010e}'"), std::numeric_limits<F>::infinity()); 1889 1890 check(SV("answer is ' -inf'"), SV("answer is '{:010e}'"), -std::numeric_limits<F>::infinity()); 1891 check(SV("answer is ' -inf'"), SV("answer is '{:-010e}'"), -std::numeric_limits<F>::infinity()); 1892 check(SV("answer is ' -inf'"), SV("answer is '{:+010e}'"), -std::numeric_limits<F>::infinity()); 1893 check(SV("answer is ' -inf'"), SV("answer is '{: 010e}'"), -std::numeric_limits<F>::infinity()); 1894 1895 check(SV("answer is ' nan'"), SV("answer is '{:010e}'"), nan_pos); 1896 check(SV("answer is ' nan'"), SV("answer is '{:-010e}'"), nan_pos); 1897 check(SV("answer is ' +nan'"), SV("answer is '{:+010e}'"), nan_pos); 1898 check(SV("answer is ' nan'"), SV("answer is '{: 010e}'"), nan_pos); 1899 1900 check(SV("answer is ' -nan'"), SV("answer is '{:010e}'"), nan_neg); 1901 check(SV("answer is ' -nan'"), SV("answer is '{:-010e}'"), nan_neg); 1902 check(SV("answer is ' -nan'"), SV("answer is '{:+010e}'"), nan_neg); 1903 check(SV("answer is ' -nan'"), SV("answer is '{: 010e}'"), nan_neg); 1904 1905 // *** precision *** 1906 check(SV("answer is '3e-02'"), SV("answer is '{:.0e}'"), 0.03125); 1907 check(SV("answer is '3.1e-02'"), SV("answer is '{:.1e}'"), 0.03125); 1908 check(SV("answer is '3.125e-02'"), SV("answer is '{:.3e}'"), 0.03125); 1909 check(SV("answer is '3.1250000000e-02'"), SV("answer is '{:.10e}'"), 0.03125); 1910 1911 // *** locale-specific form *** 1912 // See locale-specific_form.pass.cpp 1913 } 1914 1915 template <class F, class CharT, class TestFunction> 1916 void format_test_floating_point_scientific_upper_case(TestFunction check) { 1917 auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" 1918 auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" 1919 1920 // *** align-fill & width *** 1921 check(SV("answer is ' 2.500000E-01'"), SV("answer is '{:15E}'"), F(0.25)); 1922 check(SV("answer is ' 2.500000E-01'"), SV("answer is '{:>15E}'"), F(0.25)); 1923 check(SV("answer is '2.500000E-01 '"), SV("answer is '{:<15E}'"), F(0.25)); 1924 check(SV("answer is ' 2.500000E-01 '"), SV("answer is '{:^15E}'"), F(0.25)); 1925 1926 check(SV("answer is '---1.250000E-01'"), SV("answer is '{:->15E}'"), F(125e-3)); 1927 check(SV("answer is '1.250000E-01---'"), SV("answer is '{:-<15E}'"), F(125e-3)); 1928 check(SV("answer is '-1.250000E-01--'"), SV("answer is '{:-^15E}'"), F(125e-3)); 1929 1930 check(SV("answer is '***INF'"), SV("answer is '{:*>6E}'"), std::numeric_limits<F>::infinity()); 1931 check(SV("answer is 'INF***'"), SV("answer is '{:*<6E}'"), std::numeric_limits<F>::infinity()); 1932 check(SV("answer is '*INF**'"), SV("answer is '{:*^6E}'"), std::numeric_limits<F>::infinity()); 1933 1934 check(SV("answer is '###-INF'"), SV("answer is '{:#>7E}'"), -std::numeric_limits<F>::infinity()); 1935 check(SV("answer is '-INF###'"), SV("answer is '{:#<7E}'"), -std::numeric_limits<F>::infinity()); 1936 check(SV("answer is '#-INF##'"), SV("answer is '{:#^7E}'"), -std::numeric_limits<F>::infinity()); 1937 1938 check(SV("answer is '^^^NAN'"), SV("answer is '{:^>6E}'"), nan_pos); 1939 check(SV("answer is 'NAN^^^'"), SV("answer is '{:^<6E}'"), nan_pos); 1940 check(SV("answer is '^NAN^^'"), SV("answer is '{:^^6E}'"), nan_pos); 1941 1942 check(SV("answer is '000-NAN'"), SV("answer is '{:0>7E}'"), nan_neg); 1943 check(SV("answer is '-NAN000'"), SV("answer is '{:0<7E}'"), nan_neg); 1944 check(SV("answer is '0-NAN00'"), SV("answer is '{:0^7E}'"), nan_neg); 1945 1946 // Test whether zero padding is ignored 1947 check(SV("answer is ' 2.500000E-01'"), SV("answer is '{:>015E}'"), F(0.25)); 1948 check(SV("answer is '2.500000E-01 '"), SV("answer is '{:<015E}'"), F(0.25)); 1949 check(SV("answer is ' 2.500000E-01 '"), SV("answer is '{:^015E}'"), F(0.25)); 1950 1951 // *** Sign *** 1952 check(SV("answer is '0.000000E+00'"), SV("answer is '{:E}'"), F(0)); 1953 check(SV("answer is '0.000000E+00'"), SV("answer is '{:-E}'"), F(0)); 1954 check(SV("answer is '+0.000000E+00'"), SV("answer is '{:+E}'"), F(0)); 1955 check(SV("answer is ' 0.000000E+00'"), SV("answer is '{: E}'"), F(0)); 1956 1957 check(SV("answer is '-0.000000E+00'"), SV("answer is '{:E}'"), F(-0.)); 1958 check(SV("answer is '-0.000000E+00'"), SV("answer is '{:-E}'"), F(-0.)); 1959 check(SV("answer is '-0.000000E+00'"), SV("answer is '{:+E}'"), F(-0.)); 1960 check(SV("answer is '-0.000000E+00'"), SV("answer is '{: E}'"), F(-0.)); 1961 1962 // [format.string.std]/5 The sign option applies to floating-point infinity and NaN. 1963 check(SV("answer is 'INF'"), SV("answer is '{:E}'"), std::numeric_limits<F>::infinity()); 1964 check(SV("answer is 'INF'"), SV("answer is '{:-E}'"), std::numeric_limits<F>::infinity()); 1965 check(SV("answer is '+INF'"), SV("answer is '{:+E}'"), std::numeric_limits<F>::infinity()); 1966 check(SV("answer is ' INF'"), SV("answer is '{: E}'"), std::numeric_limits<F>::infinity()); 1967 1968 check(SV("answer is '-INF'"), SV("answer is '{:E}'"), -std::numeric_limits<F>::infinity()); 1969 check(SV("answer is '-INF'"), SV("answer is '{:-E}'"), -std::numeric_limits<F>::infinity()); 1970 check(SV("answer is '-INF'"), SV("answer is '{:+E}'"), -std::numeric_limits<F>::infinity()); 1971 check(SV("answer is '-INF'"), SV("answer is '{: E}'"), -std::numeric_limits<F>::infinity()); 1972 1973 check(SV("answer is 'NAN'"), SV("answer is '{:E}'"), nan_pos); 1974 check(SV("answer is 'NAN'"), SV("answer is '{:-E}'"), nan_pos); 1975 check(SV("answer is '+NAN'"), SV("answer is '{:+E}'"), nan_pos); 1976 check(SV("answer is ' NAN'"), SV("answer is '{: E}'"), nan_pos); 1977 1978 check(SV("answer is '-NAN'"), SV("answer is '{:E}'"), nan_neg); 1979 check(SV("answer is '-NAN'"), SV("answer is '{:-E}'"), nan_neg); 1980 check(SV("answer is '-NAN'"), SV("answer is '{:+E}'"), nan_neg); 1981 check(SV("answer is '-NAN'"), SV("answer is '{: E}'"), nan_neg); 1982 1983 // *** alternate form ** 1984 // When precision is zero there's no decimal point except when the alternate form is specified. 1985 check(SV("answer is '0E+00'"), SV("answer is '{:.0E}'"), F(0)); 1986 check(SV("answer is '0.E+00'"), SV("answer is '{:#.0E}'"), F(0)); 1987 1988 check(SV("answer is '0.000000E+00'"), SV("answer is '{:#E}'"), F(0)); 1989 check(SV("answer is '2.500000E+00'"), SV("answer is '{:#E}'"), F(2.5)); 1990 1991 check(SV("answer is 'INF'"), SV("answer is '{:#E}'"), std::numeric_limits<F>::infinity()); 1992 check(SV("answer is '-INF'"), SV("answer is '{:#E}'"), -std::numeric_limits<F>::infinity()); 1993 1994 check(SV("answer is 'NAN'"), SV("answer is '{:#E}'"), nan_pos); 1995 check(SV("answer is '-NAN'"), SV("answer is '{:#E}'"), nan_neg); 1996 1997 // *** zero-padding & width *** 1998 check(SV("answer is '3.125000E-02'"), SV("answer is '{:07E}'"), 0.03125); 1999 check(SV("answer is '+3.125000E-02'"), SV("answer is '{:+07E}'"), 0.03125); 2000 check(SV("answer is '+3.125000E-02'"), SV("answer is '{:+08E}'"), 0.03125); 2001 check(SV("answer is '+3.125000E-02'"), SV("answer is '{:+09E}'"), 0.03125); 2002 2003 check(SV("answer is '003.125000E-02'"), SV("answer is '{:014E}'"), 0.03125); 2004 check(SV("answer is '003.125000E-02'"), SV("answer is '{:-014E}'"), 0.03125); 2005 check(SV("answer is '+03.125000E-02'"), SV("answer is '{:+014E}'"), 0.03125); 2006 check(SV("answer is ' 03.125000E-02'"), SV("answer is '{: 014E}'"), 0.03125); 2007 2008 check(SV("answer is ' INF'"), SV("answer is '{:010E}'"), std::numeric_limits<F>::infinity()); 2009 check(SV("answer is ' INF'"), SV("answer is '{:-010E}'"), std::numeric_limits<F>::infinity()); 2010 check(SV("answer is ' +INF'"), SV("answer is '{:+010E}'"), std::numeric_limits<F>::infinity()); 2011 check(SV("answer is ' INF'"), SV("answer is '{: 010E}'"), std::numeric_limits<F>::infinity()); 2012 2013 check(SV("answer is ' -INF'"), SV("answer is '{:010E}'"), -std::numeric_limits<F>::infinity()); 2014 check(SV("answer is ' -INF'"), SV("answer is '{:-010E}'"), -std::numeric_limits<F>::infinity()); 2015 check(SV("answer is ' -INF'"), SV("answer is '{:+010E}'"), -std::numeric_limits<F>::infinity()); 2016 check(SV("answer is ' -INF'"), SV("answer is '{: 010E}'"), -std::numeric_limits<F>::infinity()); 2017 2018 check(SV("answer is ' NAN'"), SV("answer is '{:010E}'"), nan_pos); 2019 check(SV("answer is ' NAN'"), SV("answer is '{:-010E}'"), nan_pos); 2020 check(SV("answer is ' +NAN'"), SV("answer is '{:+010E}'"), nan_pos); 2021 check(SV("answer is ' NAN'"), SV("answer is '{: 010E}'"), nan_pos); 2022 2023 check(SV("answer is ' -NAN'"), SV("answer is '{:010E}'"), nan_neg); 2024 check(SV("answer is ' -NAN'"), SV("answer is '{:-010E}'"), nan_neg); 2025 check(SV("answer is ' -NAN'"), SV("answer is '{:+010E}'"), nan_neg); 2026 check(SV("answer is ' -NAN'"), SV("answer is '{: 010E}'"), nan_neg); 2027 2028 // *** precision *** 2029 check(SV("answer is '3E-02'"), SV("answer is '{:.0E}'"), 0.03125); 2030 check(SV("answer is '3.1E-02'"), SV("answer is '{:.1E}'"), 0.03125); 2031 check(SV("answer is '3.125E-02'"), SV("answer is '{:.3E}'"), 0.03125); 2032 check(SV("answer is '3.1250000000E-02'"), SV("answer is '{:.10E}'"), 0.03125); 2033 2034 // *** locale-specific form *** 2035 // See locale-specific_form.pass.cpp 2036 } 2037 2038 template <class F, class CharT, class TestFunction> 2039 void format_test_floating_point_fixed_lower_case(TestFunction check) { 2040 auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" 2041 auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" 2042 2043 // *** align-fill & width *** 2044 check(SV("answer is ' 0.250000'"), SV("answer is '{:11f}'"), F(0.25)); 2045 check(SV("answer is ' 0.250000'"), SV("answer is '{:>11f}'"), F(0.25)); 2046 check(SV("answer is '0.250000 '"), SV("answer is '{:<11f}'"), F(0.25)); 2047 check(SV("answer is ' 0.250000 '"), SV("answer is '{:^11f}'"), F(0.25)); 2048 2049 check(SV("answer is '---0.125000'"), SV("answer is '{:->11f}'"), F(125e-3)); 2050 check(SV("answer is '0.125000---'"), SV("answer is '{:-<11f}'"), F(125e-3)); 2051 check(SV("answer is '-0.125000--'"), SV("answer is '{:-^11f}'"), F(125e-3)); 2052 2053 check(SV("answer is '***inf'"), SV("answer is '{:*>6f}'"), std::numeric_limits<F>::infinity()); 2054 check(SV("answer is 'inf***'"), SV("answer is '{:*<6f}'"), std::numeric_limits<F>::infinity()); 2055 check(SV("answer is '*inf**'"), SV("answer is '{:*^6f}'"), std::numeric_limits<F>::infinity()); 2056 2057 check(SV("answer is '###-inf'"), SV("answer is '{:#>7f}'"), -std::numeric_limits<F>::infinity()); 2058 check(SV("answer is '-inf###'"), SV("answer is '{:#<7f}'"), -std::numeric_limits<F>::infinity()); 2059 check(SV("answer is '#-inf##'"), SV("answer is '{:#^7f}'"), -std::numeric_limits<F>::infinity()); 2060 2061 check(SV("answer is '^^^nan'"), SV("answer is '{:^>6f}'"), nan_pos); 2062 check(SV("answer is 'nan^^^'"), SV("answer is '{:^<6f}'"), nan_pos); 2063 check(SV("answer is '^nan^^'"), SV("answer is '{:^^6f}'"), nan_pos); 2064 2065 check(SV("answer is '000-nan'"), SV("answer is '{:0>7f}'"), nan_neg); 2066 check(SV("answer is '-nan000'"), SV("answer is '{:0<7f}'"), nan_neg); 2067 check(SV("answer is '0-nan00'"), SV("answer is '{:0^7f}'"), nan_neg); 2068 2069 // Test whether zero padding is ignored 2070 check(SV("answer is ' 0.250000'"), SV("answer is '{:>011f}'"), F(0.25)); 2071 check(SV("answer is '0.250000 '"), SV("answer is '{:<011f}'"), F(0.25)); 2072 check(SV("answer is ' 0.250000 '"), SV("answer is '{:^011f}'"), F(0.25)); 2073 2074 // *** Sign *** 2075 check(SV("answer is '0.000000'"), SV("answer is '{:f}'"), F(0)); 2076 check(SV("answer is '0.000000'"), SV("answer is '{:-f}'"), F(0)); 2077 check(SV("answer is '+0.000000'"), SV("answer is '{:+f}'"), F(0)); 2078 check(SV("answer is ' 0.000000'"), SV("answer is '{: f}'"), F(0)); 2079 2080 check(SV("answer is '-0.000000'"), SV("answer is '{:f}'"), F(-0.)); 2081 check(SV("answer is '-0.000000'"), SV("answer is '{:-f}'"), F(-0.)); 2082 check(SV("answer is '-0.000000'"), SV("answer is '{:+f}'"), F(-0.)); 2083 check(SV("answer is '-0.000000'"), SV("answer is '{: f}'"), F(-0.)); 2084 2085 // [format.string.std]/5 The sign option applies to floating-point infinity and NaN. 2086 check(SV("answer is 'inf'"), SV("answer is '{:f}'"), std::numeric_limits<F>::infinity()); 2087 check(SV("answer is 'inf'"), SV("answer is '{:-f}'"), std::numeric_limits<F>::infinity()); 2088 check(SV("answer is '+inf'"), SV("answer is '{:+f}'"), std::numeric_limits<F>::infinity()); 2089 check(SV("answer is ' inf'"), SV("answer is '{: f}'"), std::numeric_limits<F>::infinity()); 2090 2091 check(SV("answer is '-inf'"), SV("answer is '{:f}'"), -std::numeric_limits<F>::infinity()); 2092 check(SV("answer is '-inf'"), SV("answer is '{:-f}'"), -std::numeric_limits<F>::infinity()); 2093 check(SV("answer is '-inf'"), SV("answer is '{:+f}'"), -std::numeric_limits<F>::infinity()); 2094 check(SV("answer is '-inf'"), SV("answer is '{: f}'"), -std::numeric_limits<F>::infinity()); 2095 2096 check(SV("answer is 'nan'"), SV("answer is '{:f}'"), nan_pos); 2097 check(SV("answer is 'nan'"), SV("answer is '{:-f}'"), nan_pos); 2098 check(SV("answer is '+nan'"), SV("answer is '{:+f}'"), nan_pos); 2099 check(SV("answer is ' nan'"), SV("answer is '{: f}'"), nan_pos); 2100 2101 check(SV("answer is '-nan'"), SV("answer is '{:f}'"), nan_neg); 2102 check(SV("answer is '-nan'"), SV("answer is '{:-f}'"), nan_neg); 2103 check(SV("answer is '-nan'"), SV("answer is '{:+f}'"), nan_neg); 2104 check(SV("answer is '-nan'"), SV("answer is '{: f}'"), nan_neg); 2105 2106 // *** alternate form ** 2107 // When precision is zero there's no decimal point except when the alternate form is specified. 2108 check(SV("answer is '0'"), SV("answer is '{:.0f}'"), F(0)); 2109 check(SV("answer is '0.'"), SV("answer is '{:#.0f}'"), F(0)); 2110 2111 check(SV("answer is '0.000000'"), SV("answer is '{:#f}'"), F(0)); 2112 check(SV("answer is '2.500000'"), SV("answer is '{:#f}'"), F(2.5)); 2113 2114 check(SV("answer is 'inf'"), SV("answer is '{:#f}'"), std::numeric_limits<F>::infinity()); 2115 check(SV("answer is '-inf'"), SV("answer is '{:#f}'"), -std::numeric_limits<F>::infinity()); 2116 2117 check(SV("answer is 'nan'"), SV("answer is '{:#f}'"), nan_pos); 2118 check(SV("answer is '-nan'"), SV("answer is '{:#f}'"), nan_neg); 2119 2120 // *** zero-padding & width *** 2121 check(SV("answer is '0.031250'"), SV("answer is '{:07f}'"), 0.03125); 2122 check(SV("answer is '+0.031250'"), SV("answer is '{:+07f}'"), 0.03125); 2123 check(SV("answer is '+0.031250'"), SV("answer is '{:+08f}'"), 0.03125); 2124 check(SV("answer is '+0.031250'"), SV("answer is '{:+09f}'"), 0.03125); 2125 2126 check(SV("answer is '000.031250'"), SV("answer is '{:010f}'"), 0.03125); 2127 check(SV("answer is '000.031250'"), SV("answer is '{:-010f}'"), 0.03125); 2128 check(SV("answer is '+00.031250'"), SV("answer is '{:+010f}'"), 0.03125); 2129 check(SV("answer is ' 00.031250'"), SV("answer is '{: 010f}'"), 0.03125); 2130 2131 check(SV("answer is ' inf'"), SV("answer is '{:010f}'"), std::numeric_limits<F>::infinity()); 2132 check(SV("answer is ' inf'"), SV("answer is '{:-010f}'"), std::numeric_limits<F>::infinity()); 2133 check(SV("answer is ' +inf'"), SV("answer is '{:+010f}'"), std::numeric_limits<F>::infinity()); 2134 check(SV("answer is ' inf'"), SV("answer is '{: 010f}'"), std::numeric_limits<F>::infinity()); 2135 2136 check(SV("answer is ' -inf'"), SV("answer is '{:010f}'"), -std::numeric_limits<F>::infinity()); 2137 check(SV("answer is ' -inf'"), SV("answer is '{:-010f}'"), -std::numeric_limits<F>::infinity()); 2138 check(SV("answer is ' -inf'"), SV("answer is '{:+010f}'"), -std::numeric_limits<F>::infinity()); 2139 check(SV("answer is ' -inf'"), SV("answer is '{: 010f}'"), -std::numeric_limits<F>::infinity()); 2140 2141 check(SV("answer is ' nan'"), SV("answer is '{:010f}'"), nan_pos); 2142 check(SV("answer is ' nan'"), SV("answer is '{:-010f}'"), nan_pos); 2143 check(SV("answer is ' +nan'"), SV("answer is '{:+010f}'"), nan_pos); 2144 check(SV("answer is ' nan'"), SV("answer is '{: 010f}'"), nan_pos); 2145 2146 check(SV("answer is ' -nan'"), SV("answer is '{:010f}'"), nan_neg); 2147 check(SV("answer is ' -nan'"), SV("answer is '{:-010f}'"), nan_neg); 2148 check(SV("answer is ' -nan'"), SV("answer is '{:+010f}'"), nan_neg); 2149 check(SV("answer is ' -nan'"), SV("answer is '{: 010f}'"), nan_neg); 2150 2151 // *** precision *** 2152 check(SV("answer is '0'"), SV("answer is '{:.0f}'"), 0.03125); 2153 check(SV("answer is '0.0'"), SV("answer is '{:.1f}'"), 0.03125); 2154 check(SV("answer is '0.03125'"), SV("answer is '{:.5f}'"), 0.03125); 2155 check(SV("answer is '0.0312500000'"), SV("answer is '{:.10f}'"), 0.03125); 2156 2157 // *** locale-specific form *** 2158 // See locale-specific_form.pass.cpp 2159 } 2160 2161 template <class F, class CharT, class TestFunction> 2162 void format_test_floating_point_fixed_upper_case(TestFunction check) { 2163 auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" 2164 auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" 2165 2166 // *** align-fill & width *** 2167 check(SV("answer is ' 0.250000'"), SV("answer is '{:11F}'"), F(0.25)); 2168 check(SV("answer is ' 0.250000'"), SV("answer is '{:>11F}'"), F(0.25)); 2169 check(SV("answer is '0.250000 '"), SV("answer is '{:<11F}'"), F(0.25)); 2170 check(SV("answer is ' 0.250000 '"), SV("answer is '{:^11F}'"), F(0.25)); 2171 2172 check(SV("answer is '---0.125000'"), SV("answer is '{:->11F}'"), F(125e-3)); 2173 check(SV("answer is '0.125000---'"), SV("answer is '{:-<11F}'"), F(125e-3)); 2174 check(SV("answer is '-0.125000--'"), SV("answer is '{:-^11F}'"), F(125e-3)); 2175 2176 check(SV("answer is '***INF'"), SV("answer is '{:*>6F}'"), std::numeric_limits<F>::infinity()); 2177 check(SV("answer is 'INF***'"), SV("answer is '{:*<6F}'"), std::numeric_limits<F>::infinity()); 2178 check(SV("answer is '*INF**'"), SV("answer is '{:*^6F}'"), std::numeric_limits<F>::infinity()); 2179 2180 check(SV("answer is '###-INF'"), SV("answer is '{:#>7F}'"), -std::numeric_limits<F>::infinity()); 2181 check(SV("answer is '-INF###'"), SV("answer is '{:#<7F}'"), -std::numeric_limits<F>::infinity()); 2182 check(SV("answer is '#-INF##'"), SV("answer is '{:#^7F}'"), -std::numeric_limits<F>::infinity()); 2183 2184 check(SV("answer is '^^^NAN'"), SV("answer is '{:^>6F}'"), nan_pos); 2185 check(SV("answer is 'NAN^^^'"), SV("answer is '{:^<6F}'"), nan_pos); 2186 check(SV("answer is '^NAN^^'"), SV("answer is '{:^^6F}'"), nan_pos); 2187 2188 check(SV("answer is '000-NAN'"), SV("answer is '{:0>7F}'"), nan_neg); 2189 check(SV("answer is '-NAN000'"), SV("answer is '{:0<7F}'"), nan_neg); 2190 check(SV("answer is '0-NAN00'"), SV("answer is '{:0^7F}'"), nan_neg); 2191 2192 // Test whether zero padding is ignored 2193 check(SV("answer is ' 0.250000'"), SV("answer is '{:>011F}'"), F(0.25)); 2194 check(SV("answer is '0.250000 '"), SV("answer is '{:<011F}'"), F(0.25)); 2195 check(SV("answer is ' 0.250000 '"), SV("answer is '{:^011F}'"), F(0.25)); 2196 2197 // *** Sign *** 2198 check(SV("answer is '0.000000'"), SV("answer is '{:F}'"), F(0)); 2199 check(SV("answer is '0.000000'"), SV("answer is '{:-F}'"), F(0)); 2200 check(SV("answer is '+0.000000'"), SV("answer is '{:+F}'"), F(0)); 2201 check(SV("answer is ' 0.000000'"), SV("answer is '{: F}'"), F(0)); 2202 2203 check(SV("answer is '-0.000000'"), SV("answer is '{:F}'"), F(-0.)); 2204 check(SV("answer is '-0.000000'"), SV("answer is '{:-F}'"), F(-0.)); 2205 check(SV("answer is '-0.000000'"), SV("answer is '{:+F}'"), F(-0.)); 2206 check(SV("answer is '-0.000000'"), SV("answer is '{: F}'"), F(-0.)); 2207 2208 // [format.string.std]/5 The sign option applies to floating-point infinity and NaN. 2209 check(SV("answer is 'INF'"), SV("answer is '{:F}'"), std::numeric_limits<F>::infinity()); 2210 check(SV("answer is 'INF'"), SV("answer is '{:-F}'"), std::numeric_limits<F>::infinity()); 2211 check(SV("answer is '+INF'"), SV("answer is '{:+F}'"), std::numeric_limits<F>::infinity()); 2212 check(SV("answer is ' INF'"), SV("answer is '{: F}'"), std::numeric_limits<F>::infinity()); 2213 2214 check(SV("answer is '-INF'"), SV("answer is '{:F}'"), -std::numeric_limits<F>::infinity()); 2215 check(SV("answer is '-INF'"), SV("answer is '{:-F}'"), -std::numeric_limits<F>::infinity()); 2216 check(SV("answer is '-INF'"), SV("answer is '{:+F}'"), -std::numeric_limits<F>::infinity()); 2217 check(SV("answer is '-INF'"), SV("answer is '{: F}'"), -std::numeric_limits<F>::infinity()); 2218 2219 check(SV("answer is 'NAN'"), SV("answer is '{:F}'"), nan_pos); 2220 check(SV("answer is 'NAN'"), SV("answer is '{:-F}'"), nan_pos); 2221 check(SV("answer is '+NAN'"), SV("answer is '{:+F}'"), nan_pos); 2222 check(SV("answer is ' NAN'"), SV("answer is '{: F}'"), nan_pos); 2223 2224 check(SV("answer is '-NAN'"), SV("answer is '{:F}'"), nan_neg); 2225 check(SV("answer is '-NAN'"), SV("answer is '{:-F}'"), nan_neg); 2226 check(SV("answer is '-NAN'"), SV("answer is '{:+F}'"), nan_neg); 2227 check(SV("answer is '-NAN'"), SV("answer is '{: F}'"), nan_neg); 2228 2229 // *** alternate form ** 2230 // When precision is zero there's no decimal point except when the alternate form is specified. 2231 check(SV("answer is '0'"), SV("answer is '{:.0F}'"), F(0)); 2232 check(SV("answer is '0.'"), SV("answer is '{:#.0F}'"), F(0)); 2233 2234 check(SV("answer is '0.000000'"), SV("answer is '{:#F}'"), F(0)); 2235 check(SV("answer is '2.500000'"), SV("answer is '{:#F}'"), F(2.5)); 2236 2237 check(SV("answer is 'INF'"), SV("answer is '{:#F}'"), std::numeric_limits<F>::infinity()); 2238 check(SV("answer is '-INF'"), SV("answer is '{:#F}'"), -std::numeric_limits<F>::infinity()); 2239 2240 check(SV("answer is 'NAN'"), SV("answer is '{:#F}'"), nan_pos); 2241 check(SV("answer is '-NAN'"), SV("answer is '{:#F}'"), nan_neg); 2242 2243 // *** zero-padding & width *** 2244 check(SV("answer is '0.031250'"), SV("answer is '{:07F}'"), 0.03125); 2245 check(SV("answer is '+0.031250'"), SV("answer is '{:+07F}'"), 0.03125); 2246 check(SV("answer is '+0.031250'"), SV("answer is '{:+08F}'"), 0.03125); 2247 check(SV("answer is '+0.031250'"), SV("answer is '{:+09F}'"), 0.03125); 2248 2249 check(SV("answer is '000.031250'"), SV("answer is '{:010F}'"), 0.03125); 2250 check(SV("answer is '000.031250'"), SV("answer is '{:-010F}'"), 0.03125); 2251 check(SV("answer is '+00.031250'"), SV("answer is '{:+010F}'"), 0.03125); 2252 check(SV("answer is ' 00.031250'"), SV("answer is '{: 010F}'"), 0.03125); 2253 2254 check(SV("answer is ' INF'"), SV("answer is '{:010F}'"), std::numeric_limits<F>::infinity()); 2255 check(SV("answer is ' INF'"), SV("answer is '{:-010F}'"), std::numeric_limits<F>::infinity()); 2256 check(SV("answer is ' +INF'"), SV("answer is '{:+010F}'"), std::numeric_limits<F>::infinity()); 2257 check(SV("answer is ' INF'"), SV("answer is '{: 010F}'"), std::numeric_limits<F>::infinity()); 2258 2259 check(SV("answer is ' -INF'"), SV("answer is '{:010F}'"), -std::numeric_limits<F>::infinity()); 2260 check(SV("answer is ' -INF'"), SV("answer is '{:-010F}'"), -std::numeric_limits<F>::infinity()); 2261 check(SV("answer is ' -INF'"), SV("answer is '{:+010F}'"), -std::numeric_limits<F>::infinity()); 2262 check(SV("answer is ' -INF'"), SV("answer is '{: 010F}'"), -std::numeric_limits<F>::infinity()); 2263 2264 check(SV("answer is ' NAN'"), SV("answer is '{:010F}'"), nan_pos); 2265 check(SV("answer is ' NAN'"), SV("answer is '{:-010F}'"), nan_pos); 2266 check(SV("answer is ' +NAN'"), SV("answer is '{:+010F}'"), nan_pos); 2267 check(SV("answer is ' NAN'"), SV("answer is '{: 010F}'"), nan_pos); 2268 2269 check(SV("answer is ' -NAN'"), SV("answer is '{:010F}'"), nan_neg); 2270 check(SV("answer is ' -NAN'"), SV("answer is '{:-010F}'"), nan_neg); 2271 check(SV("answer is ' -NAN'"), SV("answer is '{:+010F}'"), nan_neg); 2272 check(SV("answer is ' -NAN'"), SV("answer is '{: 010F}'"), nan_neg); 2273 2274 // *** precision *** 2275 check(SV("answer is '0'"), SV("answer is '{:.0F}'"), 0.03125); 2276 check(SV("answer is '0.0'"), SV("answer is '{:.1F}'"), 0.03125); 2277 check(SV("answer is '0.03125'"), SV("answer is '{:.5F}'"), 0.03125); 2278 check(SV("answer is '0.0312500000'"), SV("answer is '{:.10F}'"), 0.03125); 2279 2280 // *** locale-specific form *** 2281 // See locale-specific_form.pass.cpp 2282 } 2283 2284 template <class F, class CharT, class TestFunction> 2285 void format_test_floating_point_general_lower_case(TestFunction check) { 2286 auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" 2287 auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" 2288 2289 // *** align-fill & width *** 2290 check(SV("answer is ' 0.25'"), SV("answer is '{:7g}'"), F(0.25)); 2291 check(SV("answer is ' 0.25'"), SV("answer is '{:>7g}'"), F(0.25)); 2292 check(SV("answer is '0.25 '"), SV("answer is '{:<7g}'"), F(0.25)); 2293 check(SV("answer is ' 0.25 '"), SV("answer is '{:^7g}'"), F(0.25)); 2294 2295 check(SV("answer is '---0.125'"), SV("answer is '{:->8g}'"), F(125e-3)); 2296 check(SV("answer is '0.125---'"), SV("answer is '{:-<8g}'"), F(125e-3)); 2297 check(SV("answer is '-0.125--'"), SV("answer is '{:-^8g}'"), F(125e-3)); 2298 2299 check(SV("answer is '***inf'"), SV("answer is '{:*>6g}'"), std::numeric_limits<F>::infinity()); 2300 check(SV("answer is 'inf***'"), SV("answer is '{:*<6g}'"), std::numeric_limits<F>::infinity()); 2301 check(SV("answer is '*inf**'"), SV("answer is '{:*^6g}'"), std::numeric_limits<F>::infinity()); 2302 2303 check(SV("answer is '###-inf'"), SV("answer is '{:#>7g}'"), -std::numeric_limits<F>::infinity()); 2304 check(SV("answer is '-inf###'"), SV("answer is '{:#<7g}'"), -std::numeric_limits<F>::infinity()); 2305 check(SV("answer is '#-inf##'"), SV("answer is '{:#^7g}'"), -std::numeric_limits<F>::infinity()); 2306 2307 check(SV("answer is '^^^nan'"), SV("answer is '{:^>6g}'"), nan_pos); 2308 check(SV("answer is 'nan^^^'"), SV("answer is '{:^<6g}'"), nan_pos); 2309 check(SV("answer is '^nan^^'"), SV("answer is '{:^^6g}'"), nan_pos); 2310 2311 check(SV("answer is '000-nan'"), SV("answer is '{:0>7g}'"), nan_neg); 2312 check(SV("answer is '-nan000'"), SV("answer is '{:0<7g}'"), nan_neg); 2313 check(SV("answer is '0-nan00'"), SV("answer is '{:0^7g}'"), nan_neg); 2314 2315 // Test whether zero padding is ignored 2316 check(SV("answer is ' 0.25'"), SV("answer is '{:>07g}'"), F(0.25)); 2317 check(SV("answer is '0.25 '"), SV("answer is '{:<07g}'"), F(0.25)); 2318 check(SV("answer is ' 0.25 '"), SV("answer is '{:^07g}'"), F(0.25)); 2319 2320 // *** Sign *** 2321 check(SV("answer is '0'"), SV("answer is '{:g}'"), F(0)); 2322 check(SV("answer is '0'"), SV("answer is '{:-g}'"), F(0)); 2323 check(SV("answer is '+0'"), SV("answer is '{:+g}'"), F(0)); 2324 check(SV("answer is ' 0'"), SV("answer is '{: g}'"), F(0)); 2325 2326 check(SV("answer is '-0'"), SV("answer is '{:g}'"), F(-0.)); 2327 check(SV("answer is '-0'"), SV("answer is '{:-g}'"), F(-0.)); 2328 check(SV("answer is '-0'"), SV("answer is '{:+g}'"), F(-0.)); 2329 check(SV("answer is '-0'"), SV("answer is '{: g}'"), F(-0.)); 2330 2331 // [format.string.std]/5 The sign option applies to floating-point infinity and NaN. 2332 check(SV("answer is 'inf'"), SV("answer is '{:g}'"), std::numeric_limits<F>::infinity()); 2333 check(SV("answer is 'inf'"), SV("answer is '{:-g}'"), std::numeric_limits<F>::infinity()); 2334 check(SV("answer is '+inf'"), SV("answer is '{:+g}'"), std::numeric_limits<F>::infinity()); 2335 check(SV("answer is ' inf'"), SV("answer is '{: g}'"), std::numeric_limits<F>::infinity()); 2336 2337 check(SV("answer is '-inf'"), SV("answer is '{:g}'"), -std::numeric_limits<F>::infinity()); 2338 check(SV("answer is '-inf'"), SV("answer is '{:-g}'"), -std::numeric_limits<F>::infinity()); 2339 check(SV("answer is '-inf'"), SV("answer is '{:+g}'"), -std::numeric_limits<F>::infinity()); 2340 check(SV("answer is '-inf'"), SV("answer is '{: g}'"), -std::numeric_limits<F>::infinity()); 2341 2342 check(SV("answer is 'nan'"), SV("answer is '{:g}'"), nan_pos); 2343 check(SV("answer is 'nan'"), SV("answer is '{:-g}'"), nan_pos); 2344 check(SV("answer is '+nan'"), SV("answer is '{:+g}'"), nan_pos); 2345 check(SV("answer is ' nan'"), SV("answer is '{: g}'"), nan_pos); 2346 2347 check(SV("answer is '-nan'"), SV("answer is '{:g}'"), nan_neg); 2348 check(SV("answer is '-nan'"), SV("answer is '{:-g}'"), nan_neg); 2349 check(SV("answer is '-nan'"), SV("answer is '{:+g}'"), nan_neg); 2350 check(SV("answer is '-nan'"), SV("answer is '{: g}'"), nan_neg); 2351 2352 // *** alternate form ** 2353 // When precision is zero there's no decimal point except when the alternate form is specified. 2354 check(SV("answer is '0'"), SV("answer is '{:.0g}'"), F(0)); 2355 check(SV("answer is '0.'"), SV("answer is '{:#.0g}'"), F(0)); 2356 2357 check(SV("answer is '0.00000'"), SV("answer is '{:#g}'"), F(0)); 2358 check(SV("answer is '2.50000'"), SV("answer is '{:#g}'"), F(2.5)); 2359 2360 check(SV("answer is 'inf'"), SV("answer is '{:#g}'"), std::numeric_limits<F>::infinity()); 2361 check(SV("answer is '-inf'"), SV("answer is '{:#g}'"), -std::numeric_limits<F>::infinity()); 2362 2363 check(SV("answer is 'nan'"), SV("answer is '{:#g}'"), nan_pos); 2364 check(SV("answer is '-nan'"), SV("answer is '{:#g}'"), nan_neg); 2365 2366 // *** zero-padding & width *** 2367 check(SV("answer is '0.03125'"), SV("answer is '{:06g}'"), 0.03125); 2368 check(SV("answer is '+0.03125'"), SV("answer is '{:+06g}'"), 0.03125); 2369 check(SV("answer is '+0.03125'"), SV("answer is '{:+07g}'"), 0.03125); 2370 check(SV("answer is '+0.03125'"), SV("answer is '{:+08g}'"), 0.03125); 2371 2372 check(SV("answer is '000.03125'"), SV("answer is '{:09g}'"), 0.03125); 2373 check(SV("answer is '000.03125'"), SV("answer is '{:-09g}'"), 0.03125); 2374 check(SV("answer is '+00.03125'"), SV("answer is '{:+09g}'"), 0.03125); 2375 check(SV("answer is ' 00.03125'"), SV("answer is '{: 09g}'"), 0.03125); 2376 2377 check(SV("answer is ' inf'"), SV("answer is '{:010g}'"), std::numeric_limits<F>::infinity()); 2378 check(SV("answer is ' inf'"), SV("answer is '{:-010g}'"), std::numeric_limits<F>::infinity()); 2379 check(SV("answer is ' +inf'"), SV("answer is '{:+010g}'"), std::numeric_limits<F>::infinity()); 2380 check(SV("answer is ' inf'"), SV("answer is '{: 010g}'"), std::numeric_limits<F>::infinity()); 2381 2382 check(SV("answer is ' -inf'"), SV("answer is '{:010g}'"), -std::numeric_limits<F>::infinity()); 2383 check(SV("answer is ' -inf'"), SV("answer is '{:-010g}'"), -std::numeric_limits<F>::infinity()); 2384 check(SV("answer is ' -inf'"), SV("answer is '{:+010g}'"), -std::numeric_limits<F>::infinity()); 2385 check(SV("answer is ' -inf'"), SV("answer is '{: 010g}'"), -std::numeric_limits<F>::infinity()); 2386 2387 check(SV("answer is ' nan'"), SV("answer is '{:010g}'"), nan_pos); 2388 check(SV("answer is ' nan'"), SV("answer is '{:-010g}'"), nan_pos); 2389 check(SV("answer is ' +nan'"), SV("answer is '{:+010g}'"), nan_pos); 2390 check(SV("answer is ' nan'"), SV("answer is '{: 010g}'"), nan_pos); 2391 2392 check(SV("answer is ' -nan'"), SV("answer is '{:010g}'"), nan_neg); 2393 check(SV("answer is ' -nan'"), SV("answer is '{:-010g}'"), nan_neg); 2394 check(SV("answer is ' -nan'"), SV("answer is '{:+010g}'"), nan_neg); 2395 check(SV("answer is ' -nan'"), SV("answer is '{: 010g}'"), nan_neg); 2396 2397 // *** precision *** 2398 check(SV("answer is '0.03'"), SV("answer is '{:.0g}'"), 0.03125); 2399 check(SV("answer is '0.03'"), SV("answer is '{:.1g}'"), 0.03125); 2400 check(SV("answer is '0.031'"), SV("answer is '{:.2g}'"), 0.03125); 2401 check(SV("answer is '0.0312'"), SV("answer is '{:.3g}'"), 0.03125); 2402 check(SV("answer is '0.03125'"), SV("answer is '{:.4g}'"), 0.03125); 2403 check(SV("answer is '0.03125'"), SV("answer is '{:.5g}'"), 0.03125); 2404 check(SV("answer is '0.03125'"), SV("answer is '{:.10g}'"), 0.03125); 2405 2406 // *** precision & alternate form *** 2407 2408 // Output validated with printf("%#xg") 2409 check(SV("answer is '1.'"), SV("answer is '{:#.{}g}'"), 1.2, 0); 2410 check(SV("answer is '1.'"), SV("answer is '{:#.{}g}'"), 1.2, 1); 2411 check(SV("answer is '1.2'"), SV("answer is '{:#.{}g}'"), 1.2, 2); 2412 check(SV("answer is '1.20'"), SV("answer is '{:#.{}g}'"), 1.2, 3); 2413 check(SV("answer is '1.200'"), SV("answer is '{:#.{}g}'"), 1.2, 4); 2414 check(SV("answer is '1.2000'"), SV("answer is '{:#.{}g}'"), 1.2, 5); 2415 check(SV("answer is '1.20000'"), SV("answer is '{:#.{}g}'"), 1.2, 6); 2416 2417 check(SV("answer is '1.e+03'"), SV("answer is '{:#.{}g}'"), 1200.0, 0); 2418 check(SV("answer is '1.e+03'"), SV("answer is '{:#.{}g}'"), 1200.0, 1); 2419 check(SV("answer is '1.2e+03'"), SV("answer is '{:#.{}g}'"), 1200.0, 2); 2420 check(SV("answer is '1.20e+03'"), SV("answer is '{:#.{}g}'"), 1200.0, 3); 2421 check(SV("answer is '1200.'"), SV("answer is '{:#.{}g}'"), 1200.0, 4); 2422 check(SV("answer is '1200.0'"), SV("answer is '{:#.{}g}'"), 1200.0, 5); 2423 check(SV("answer is '1200.00'"), SV("answer is '{:#.{}g}'"), 1200.0, 6); 2424 2425 check(SV("answer is '1.e+06'"), SV("answer is '{:#.{}g}'"), 1200000.0, 0); 2426 check(SV("answer is '1.e+06'"), SV("answer is '{:#.{}g}'"), 1200000.0, 1); 2427 check(SV("answer is '1.2e+06'"), SV("answer is '{:#.{}g}'"), 1200000.0, 2); 2428 check(SV("answer is '1.20e+06'"), SV("answer is '{:#.{}g}'"), 1200000.0, 3); 2429 check(SV("answer is '1.200e+06'"), SV("answer is '{:#.{}g}'"), 1200000.0, 4); 2430 check(SV("answer is '1.2000e+06'"), SV("answer is '{:#.{}g}'"), 1200000.0, 5); 2431 check(SV("answer is '1.20000e+06'"), SV("answer is '{:#.{}g}'"), 1200000.0, 6); 2432 2433 // *** locale-specific form *** 2434 // See locale-specific_form.pass.cpp 2435 } 2436 2437 template <class F, class CharT, class TestFunction> 2438 void format_test_floating_point_general_upper_case(TestFunction check) { 2439 auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" 2440 auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" 2441 2442 // *** align-fill & width *** 2443 check(SV("answer is ' 0.25'"), SV("answer is '{:7G}'"), F(0.25)); 2444 check(SV("answer is ' 0.25'"), SV("answer is '{:>7G}'"), F(0.25)); 2445 check(SV("answer is '0.25 '"), SV("answer is '{:<7G}'"), F(0.25)); 2446 check(SV("answer is ' 0.25 '"), SV("answer is '{:^7G}'"), F(0.25)); 2447 2448 check(SV("answer is '---0.125'"), SV("answer is '{:->8G}'"), F(125e-3)); 2449 check(SV("answer is '0.125---'"), SV("answer is '{:-<8G}'"), F(125e-3)); 2450 check(SV("answer is '-0.125--'"), SV("answer is '{:-^8G}'"), F(125e-3)); 2451 2452 check(SV("answer is '***INF'"), SV("answer is '{:*>6G}'"), std::numeric_limits<F>::infinity()); 2453 check(SV("answer is 'INF***'"), SV("answer is '{:*<6G}'"), std::numeric_limits<F>::infinity()); 2454 check(SV("answer is '*INF**'"), SV("answer is '{:*^6G}'"), std::numeric_limits<F>::infinity()); 2455 2456 check(SV("answer is '###-INF'"), SV("answer is '{:#>7G}'"), -std::numeric_limits<F>::infinity()); 2457 check(SV("answer is '-INF###'"), SV("answer is '{:#<7G}'"), -std::numeric_limits<F>::infinity()); 2458 check(SV("answer is '#-INF##'"), SV("answer is '{:#^7G}'"), -std::numeric_limits<F>::infinity()); 2459 2460 check(SV("answer is '^^^NAN'"), SV("answer is '{:^>6G}'"), nan_pos); 2461 check(SV("answer is 'NAN^^^'"), SV("answer is '{:^<6G}'"), nan_pos); 2462 check(SV("answer is '^NAN^^'"), SV("answer is '{:^^6G}'"), nan_pos); 2463 2464 check(SV("answer is '000-NAN'"), SV("answer is '{:0>7G}'"), nan_neg); 2465 check(SV("answer is '-NAN000'"), SV("answer is '{:0<7G}'"), nan_neg); 2466 check(SV("answer is '0-NAN00'"), SV("answer is '{:0^7G}'"), nan_neg); 2467 2468 // Test whether zero padding is ignored 2469 check(SV("answer is ' 0.25'"), SV("answer is '{:>07G}'"), F(0.25)); 2470 check(SV("answer is '0.25 '"), SV("answer is '{:<07G}'"), F(0.25)); 2471 check(SV("answer is ' 0.25 '"), SV("answer is '{:^07G}'"), F(0.25)); 2472 2473 // *** Sign *** 2474 check(SV("answer is '0'"), SV("answer is '{:G}'"), F(0)); 2475 check(SV("answer is '0'"), SV("answer is '{:-G}'"), F(0)); 2476 check(SV("answer is '+0'"), SV("answer is '{:+G}'"), F(0)); 2477 check(SV("answer is ' 0'"), SV("answer is '{: G}'"), F(0)); 2478 2479 check(SV("answer is '-0'"), SV("answer is '{:G}'"), F(-0.)); 2480 check(SV("answer is '-0'"), SV("answer is '{:-G}'"), F(-0.)); 2481 check(SV("answer is '-0'"), SV("answer is '{:+G}'"), F(-0.)); 2482 check(SV("answer is '-0'"), SV("answer is '{: G}'"), F(-0.)); 2483 2484 // [format.string.std]/5 The sign option applies to floating-point infinity and NaN. 2485 check(SV("answer is 'INF'"), SV("answer is '{:G}'"), std::numeric_limits<F>::infinity()); 2486 check(SV("answer is 'INF'"), SV("answer is '{:-G}'"), std::numeric_limits<F>::infinity()); 2487 check(SV("answer is '+INF'"), SV("answer is '{:+G}'"), std::numeric_limits<F>::infinity()); 2488 check(SV("answer is ' INF'"), SV("answer is '{: G}'"), std::numeric_limits<F>::infinity()); 2489 2490 check(SV("answer is '-INF'"), SV("answer is '{:G}'"), -std::numeric_limits<F>::infinity()); 2491 check(SV("answer is '-INF'"), SV("answer is '{:-G}'"), -std::numeric_limits<F>::infinity()); 2492 check(SV("answer is '-INF'"), SV("answer is '{:+G}'"), -std::numeric_limits<F>::infinity()); 2493 check(SV("answer is '-INF'"), SV("answer is '{: G}'"), -std::numeric_limits<F>::infinity()); 2494 2495 check(SV("answer is 'NAN'"), SV("answer is '{:G}'"), nan_pos); 2496 check(SV("answer is 'NAN'"), SV("answer is '{:-G}'"), nan_pos); 2497 check(SV("answer is '+NAN'"), SV("answer is '{:+G}'"), nan_pos); 2498 check(SV("answer is ' NAN'"), SV("answer is '{: G}'"), nan_pos); 2499 2500 check(SV("answer is '-NAN'"), SV("answer is '{:G}'"), nan_neg); 2501 check(SV("answer is '-NAN'"), SV("answer is '{:-G}'"), nan_neg); 2502 check(SV("answer is '-NAN'"), SV("answer is '{:+G}'"), nan_neg); 2503 check(SV("answer is '-NAN'"), SV("answer is '{: G}'"), nan_neg); 2504 2505 // *** alternate form ** 2506 // When precision is zero there's no decimal point except when the alternate form is specified. 2507 check(SV("answer is '0'"), SV("answer is '{:.0G}'"), F(0)); 2508 check(SV("answer is '0.'"), SV("answer is '{:#.0G}'"), F(0)); 2509 2510 check(SV("answer is '0.00000'"), SV("answer is '{:#G}'"), F(0)); 2511 check(SV("answer is '2.50000'"), SV("answer is '{:#G}'"), F(2.5)); 2512 2513 check(SV("answer is 'INF'"), SV("answer is '{:#G}'"), std::numeric_limits<F>::infinity()); 2514 check(SV("answer is '-INF'"), SV("answer is '{:#G}'"), -std::numeric_limits<F>::infinity()); 2515 2516 check(SV("answer is 'NAN'"), SV("answer is '{:#G}'"), nan_pos); 2517 check(SV("answer is '-NAN'"), SV("answer is '{:#G}'"), nan_neg); 2518 2519 // *** zero-padding & width *** 2520 check(SV("answer is '0.03125'"), SV("answer is '{:06G}'"), 0.03125); 2521 check(SV("answer is '+0.03125'"), SV("answer is '{:+06G}'"), 0.03125); 2522 check(SV("answer is '+0.03125'"), SV("answer is '{:+07G}'"), 0.03125); 2523 check(SV("answer is '+0.03125'"), SV("answer is '{:+08G}'"), 0.03125); 2524 2525 check(SV("answer is '000.03125'"), SV("answer is '{:09G}'"), 0.03125); 2526 check(SV("answer is '000.03125'"), SV("answer is '{:-09G}'"), 0.03125); 2527 check(SV("answer is '+00.03125'"), SV("answer is '{:+09G}'"), 0.03125); 2528 check(SV("answer is ' 00.03125'"), SV("answer is '{: 09G}'"), 0.03125); 2529 2530 check(SV("answer is ' INF'"), SV("answer is '{:010G}'"), std::numeric_limits<F>::infinity()); 2531 check(SV("answer is ' INF'"), SV("answer is '{:-010G}'"), std::numeric_limits<F>::infinity()); 2532 check(SV("answer is ' +INF'"), SV("answer is '{:+010G}'"), std::numeric_limits<F>::infinity()); 2533 check(SV("answer is ' INF'"), SV("answer is '{: 010G}'"), std::numeric_limits<F>::infinity()); 2534 2535 check(SV("answer is ' -INF'"), SV("answer is '{:010G}'"), -std::numeric_limits<F>::infinity()); 2536 check(SV("answer is ' -INF'"), SV("answer is '{:-010G}'"), -std::numeric_limits<F>::infinity()); 2537 check(SV("answer is ' -INF'"), SV("answer is '{:+010G}'"), -std::numeric_limits<F>::infinity()); 2538 check(SV("answer is ' -INF'"), SV("answer is '{: 010G}'"), -std::numeric_limits<F>::infinity()); 2539 2540 check(SV("answer is ' NAN'"), SV("answer is '{:010G}'"), nan_pos); 2541 check(SV("answer is ' NAN'"), SV("answer is '{:-010G}'"), nan_pos); 2542 check(SV("answer is ' +NAN'"), SV("answer is '{:+010G}'"), nan_pos); 2543 check(SV("answer is ' NAN'"), SV("answer is '{: 010G}'"), nan_pos); 2544 2545 check(SV("answer is ' -NAN'"), SV("answer is '{:010G}'"), nan_neg); 2546 check(SV("answer is ' -NAN'"), SV("answer is '{:-010G}'"), nan_neg); 2547 check(SV("answer is ' -NAN'"), SV("answer is '{:+010G}'"), nan_neg); 2548 check(SV("answer is ' -NAN'"), SV("answer is '{: 010G}'"), nan_neg); 2549 2550 // *** precision *** 2551 check(SV("answer is '0.03'"), SV("answer is '{:.0G}'"), 0.03125); 2552 check(SV("answer is '0.03'"), SV("answer is '{:.1G}'"), 0.03125); 2553 check(SV("answer is '0.031'"), SV("answer is '{:.2G}'"), 0.03125); 2554 check(SV("answer is '0.0312'"), SV("answer is '{:.3G}'"), 0.03125); 2555 check(SV("answer is '0.03125'"), SV("answer is '{:.4G}'"), 0.03125); 2556 check(SV("answer is '0.03125'"), SV("answer is '{:.5G}'"), 0.03125); 2557 check(SV("answer is '0.03125'"), SV("answer is '{:.10G}'"), 0.03125); 2558 2559 // *** precision & alternate form *** 2560 2561 // Output validated with printf("%#xg") 2562 check(SV("answer is '1.'"), SV("answer is '{:#.{}G}'"), 1.2, 0); 2563 check(SV("answer is '1.'"), SV("answer is '{:#.{}G}'"), 1.2, 1); 2564 check(SV("answer is '1.2'"), SV("answer is '{:#.{}G}'"), 1.2, 2); 2565 check(SV("answer is '1.20'"), SV("answer is '{:#.{}G}'"), 1.2, 3); 2566 check(SV("answer is '1.200'"), SV("answer is '{:#.{}G}'"), 1.2, 4); 2567 check(SV("answer is '1.2000'"), SV("answer is '{:#.{}G}'"), 1.2, 5); 2568 check(SV("answer is '1.20000'"), SV("answer is '{:#.{}G}'"), 1.2, 6); 2569 2570 check(SV("answer is '1.E+03'"), SV("answer is '{:#.{}G}'"), 1200.0, 0); 2571 check(SV("answer is '1.E+03'"), SV("answer is '{:#.{}G}'"), 1200.0, 1); 2572 check(SV("answer is '1.2E+03'"), SV("answer is '{:#.{}G}'"), 1200.0, 2); 2573 check(SV("answer is '1.20E+03'"), SV("answer is '{:#.{}G}'"), 1200.0, 3); 2574 check(SV("answer is '1200.'"), SV("answer is '{:#.{}G}'"), 1200.0, 4); 2575 check(SV("answer is '1200.0'"), SV("answer is '{:#.{}G}'"), 1200.0, 5); 2576 check(SV("answer is '1200.00'"), SV("answer is '{:#.{}G}'"), 1200.0, 6); 2577 2578 check(SV("answer is '1.E+06'"), SV("answer is '{:#.{}G}'"), 1200000.0, 0); 2579 check(SV("answer is '1.E+06'"), SV("answer is '{:#.{}G}'"), 1200000.0, 1); 2580 check(SV("answer is '1.2E+06'"), SV("answer is '{:#.{}G}'"), 1200000.0, 2); 2581 check(SV("answer is '1.20E+06'"), SV("answer is '{:#.{}G}'"), 1200000.0, 3); 2582 check(SV("answer is '1.200E+06'"), SV("answer is '{:#.{}G}'"), 1200000.0, 4); 2583 check(SV("answer is '1.2000E+06'"), SV("answer is '{:#.{}G}'"), 1200000.0, 5); 2584 check(SV("answer is '1.20000E+06'"), SV("answer is '{:#.{}G}'"), 1200000.0, 6); 2585 2586 // *** locale-specific form *** 2587 // See locale-specific_form.pass.cpp 2588 } 2589 2590 template <class F, class CharT, class TestFunction> 2591 void format_test_floating_point_default(TestFunction check) { 2592 auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" 2593 auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" 2594 2595 // *** align-fill & width *** 2596 check(SV("answer is ' 0.25'"), SV("answer is '{:7}'"), F(0.25)); 2597 check(SV("answer is ' 0.25'"), SV("answer is '{:>7}'"), F(0.25)); 2598 check(SV("answer is '0.25 '"), SV("answer is '{:<7}'"), F(0.25)); 2599 check(SV("answer is ' 0.25 '"), SV("answer is '{:^7}'"), F(0.25)); 2600 2601 check(SV("answer is '---0.125'"), SV("answer is '{:->8}'"), F(125e-3)); 2602 check(SV("answer is '0.125---'"), SV("answer is '{:-<8}'"), F(125e-3)); 2603 check(SV("answer is '-0.125--'"), SV("answer is '{:-^8}'"), F(125e-3)); 2604 2605 check(SV("answer is '***inf'"), SV("answer is '{:*>6}'"), std::numeric_limits<F>::infinity()); 2606 check(SV("answer is 'inf***'"), SV("answer is '{:*<6}'"), std::numeric_limits<F>::infinity()); 2607 check(SV("answer is '*inf**'"), SV("answer is '{:*^6}'"), std::numeric_limits<F>::infinity()); 2608 2609 check(SV("answer is '###-inf'"), SV("answer is '{:#>7}'"), -std::numeric_limits<F>::infinity()); 2610 check(SV("answer is '-inf###'"), SV("answer is '{:#<7}'"), -std::numeric_limits<F>::infinity()); 2611 check(SV("answer is '#-inf##'"), SV("answer is '{:#^7}'"), -std::numeric_limits<F>::infinity()); 2612 2613 check(SV("answer is '^^^nan'"), SV("answer is '{:^>6}'"), nan_pos); 2614 check(SV("answer is 'nan^^^'"), SV("answer is '{:^<6}'"), nan_pos); 2615 check(SV("answer is '^nan^^'"), SV("answer is '{:^^6}'"), nan_pos); 2616 2617 check(SV("answer is '000-nan'"), SV("answer is '{:0>7}'"), nan_neg); 2618 check(SV("answer is '-nan000'"), SV("answer is '{:0<7}'"), nan_neg); 2619 check(SV("answer is '0-nan00'"), SV("answer is '{:0^7}'"), nan_neg); 2620 2621 // Test whether zero padding is ignored 2622 check(SV("answer is ' 0.25'"), SV("answer is '{:>07}'"), F(0.25)); 2623 check(SV("answer is '0.25 '"), SV("answer is '{:<07}'"), F(0.25)); 2624 check(SV("answer is ' 0.25 '"), SV("answer is '{:^07}'"), F(0.25)); 2625 2626 // *** Sign *** 2627 check(SV("answer is '0'"), SV("answer is '{:}'"), F(0)); 2628 check(SV("answer is '0'"), SV("answer is '{:-}'"), F(0)); 2629 check(SV("answer is '+0'"), SV("answer is '{:+}'"), F(0)); 2630 check(SV("answer is ' 0'"), SV("answer is '{: }'"), F(0)); 2631 2632 check(SV("answer is '-0'"), SV("answer is '{:}'"), F(-0.)); 2633 check(SV("answer is '-0'"), SV("answer is '{:-}'"), F(-0.)); 2634 check(SV("answer is '-0'"), SV("answer is '{:+}'"), F(-0.)); 2635 check(SV("answer is '-0'"), SV("answer is '{: }'"), F(-0.)); 2636 2637 // [format.string.std]/5 The sign option applies to floating-point infinity and NaN. 2638 check(SV("answer is 'inf'"), SV("answer is '{:}'"), std::numeric_limits<F>::infinity()); 2639 check(SV("answer is 'inf'"), SV("answer is '{:-}'"), std::numeric_limits<F>::infinity()); 2640 check(SV("answer is '+inf'"), SV("answer is '{:+}'"), std::numeric_limits<F>::infinity()); 2641 check(SV("answer is ' inf'"), SV("answer is '{: }'"), std::numeric_limits<F>::infinity()); 2642 2643 check(SV("answer is '-inf'"), SV("answer is '{:}'"), -std::numeric_limits<F>::infinity()); 2644 check(SV("answer is '-inf'"), SV("answer is '{:-}'"), -std::numeric_limits<F>::infinity()); 2645 check(SV("answer is '-inf'"), SV("answer is '{:+}'"), -std::numeric_limits<F>::infinity()); 2646 check(SV("answer is '-inf'"), SV("answer is '{: }'"), -std::numeric_limits<F>::infinity()); 2647 2648 check(SV("answer is 'nan'"), SV("answer is '{:}'"), nan_pos); 2649 check(SV("answer is 'nan'"), SV("answer is '{:-}'"), nan_pos); 2650 check(SV("answer is '+nan'"), SV("answer is '{:+}'"), nan_pos); 2651 check(SV("answer is ' nan'"), SV("answer is '{: }'"), nan_pos); 2652 2653 check(SV("answer is '-nan'"), SV("answer is '{:}'"), nan_neg); 2654 check(SV("answer is '-nan'"), SV("answer is '{:-}'"), nan_neg); 2655 check(SV("answer is '-nan'"), SV("answer is '{:+}'"), nan_neg); 2656 check(SV("answer is '-nan'"), SV("answer is '{: }'"), nan_neg); 2657 2658 // *** alternate form *** 2659 check(SV("answer is '0.'"), SV("answer is '{:#}'"), F(0)); 2660 check(SV("answer is '2.5'"), SV("answer is '{:#}'"), F(2.5)); 2661 2662 check(SV("answer is 'inf'"), SV("answer is '{:#}'"), std::numeric_limits<F>::infinity()); 2663 check(SV("answer is '-inf'"), SV("answer is '{:#}'"), -std::numeric_limits<F>::infinity()); 2664 2665 check(SV("answer is 'nan'"), SV("answer is '{:#}'"), nan_pos); 2666 check(SV("answer is '-nan'"), SV("answer is '{:#}'"), nan_neg); 2667 2668 // *** zero-padding & width *** 2669 check(SV("answer is '0.03125'"), SV("answer is '{:07}'"), 0.03125); 2670 check(SV("answer is '+0.03125'"), SV("answer is '{:+07}'"), 0.03125); 2671 check(SV("answer is '+0.03125'"), SV("answer is '{:+08}'"), 0.03125); 2672 check(SV("answer is '+00.03125'"), SV("answer is '{:+09}'"), 0.03125); 2673 2674 check(SV("answer is '0000.03125'"), SV("answer is '{:010}'"), 0.03125); 2675 check(SV("answer is '0000.03125'"), SV("answer is '{:-010}'"), 0.03125); 2676 check(SV("answer is '+000.03125'"), SV("answer is '{:+010}'"), 0.03125); 2677 check(SV("answer is ' 000.03125'"), SV("answer is '{: 010}'"), 0.03125); 2678 2679 check(SV("answer is ' inf'"), SV("answer is '{:010}'"), std::numeric_limits<F>::infinity()); 2680 check(SV("answer is ' inf'"), SV("answer is '{:-010}'"), std::numeric_limits<F>::infinity()); 2681 check(SV("answer is ' +inf'"), SV("answer is '{:+010}'"), std::numeric_limits<F>::infinity()); 2682 check(SV("answer is ' inf'"), SV("answer is '{: 010}'"), std::numeric_limits<F>::infinity()); 2683 2684 check(SV("answer is ' -inf'"), SV("answer is '{:010}'"), -std::numeric_limits<F>::infinity()); 2685 check(SV("answer is ' -inf'"), SV("answer is '{:-010}'"), -std::numeric_limits<F>::infinity()); 2686 check(SV("answer is ' -inf'"), SV("answer is '{:+010}'"), -std::numeric_limits<F>::infinity()); 2687 check(SV("answer is ' -inf'"), SV("answer is '{: 010}'"), -std::numeric_limits<F>::infinity()); 2688 2689 check(SV("answer is ' nan'"), SV("answer is '{:010}'"), nan_pos); 2690 check(SV("answer is ' nan'"), SV("answer is '{:-010}'"), nan_pos); 2691 check(SV("answer is ' +nan'"), SV("answer is '{:+010}'"), nan_pos); 2692 check(SV("answer is ' nan'"), SV("answer is '{: 010}'"), nan_pos); 2693 2694 check(SV("answer is ' -nan'"), SV("answer is '{:010}'"), nan_neg); 2695 check(SV("answer is ' -nan'"), SV("answer is '{:-010}'"), nan_neg); 2696 check(SV("answer is ' -nan'"), SV("answer is '{:+010}'"), nan_neg); 2697 check(SV("answer is ' -nan'"), SV("answer is '{: 010}'"), nan_neg); 2698 2699 // *** precision *** 2700 // See format_test_floating_point_default_precision 2701 2702 // *** locale-specific form *** 2703 // See locale-specific_form.pass.cpp 2704 } 2705 2706 template <class F, class CharT, class TestFunction> 2707 void format_test_floating_point_default_precision(TestFunction check) { 2708 2709 auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" 2710 auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" 2711 2712 // *** align-fill & width *** 2713 check(SV("answer is ' 0.25'"), SV("answer is '{:7.6}'"), F(0.25)); 2714 check(SV("answer is ' 0.25'"), SV("answer is '{:>7.6}'"), F(0.25)); 2715 check(SV("answer is '0.25 '"), SV("answer is '{:<7.6}'"), F(0.25)); 2716 check(SV("answer is ' 0.25 '"), SV("answer is '{:^7.6}'"), F(0.25)); 2717 2718 check(SV("answer is '---0.125'"), SV("answer is '{:->8.6}'"), F(125e-3)); 2719 check(SV("answer is '0.125---'"), SV("answer is '{:-<8.6}'"), F(125e-3)); 2720 check(SV("answer is '-0.125--'"), SV("answer is '{:-^8.6}'"), F(125e-3)); 2721 2722 check(SV("answer is '***inf'"), SV("answer is '{:*>6.6}'"), std::numeric_limits<F>::infinity()); 2723 check(SV("answer is 'inf***'"), SV("answer is '{:*<6.6}'"), std::numeric_limits<F>::infinity()); 2724 check(SV("answer is '*inf**'"), SV("answer is '{:*^6.6}'"), std::numeric_limits<F>::infinity()); 2725 2726 check(SV("answer is '###-inf'"), SV("answer is '{:#>7.6}'"), -std::numeric_limits<F>::infinity()); 2727 check(SV("answer is '-inf###'"), SV("answer is '{:#<7.6}'"), -std::numeric_limits<F>::infinity()); 2728 check(SV("answer is '#-inf##'"), SV("answer is '{:#^7.6}'"), -std::numeric_limits<F>::infinity()); 2729 2730 check(SV("answer is '^^^nan'"), SV("answer is '{:^>6.6}'"), nan_pos); 2731 check(SV("answer is 'nan^^^'"), SV("answer is '{:^<6.6}'"), nan_pos); 2732 check(SV("answer is '^nan^^'"), SV("answer is '{:^^6.6}'"), nan_pos); 2733 2734 check(SV("answer is '000-nan'"), SV("answer is '{:0>7.6}'"), nan_neg); 2735 check(SV("answer is '-nan000'"), SV("answer is '{:0<7.6}'"), nan_neg); 2736 check(SV("answer is '0-nan00'"), SV("answer is '{:0^7.6}'"), nan_neg); 2737 2738 // Test whether zero padding is ignored 2739 check(SV("answer is ' 0.25'"), SV("answer is '{:>07.6}'"), F(0.25)); 2740 check(SV("answer is '0.25 '"), SV("answer is '{:<07.6}'"), F(0.25)); 2741 check(SV("answer is ' 0.25 '"), SV("answer is '{:^07.6}'"), F(0.25)); 2742 2743 // *** Sign *** 2744 check(SV("answer is '0'"), SV("answer is '{:.6}'"), F(0)); 2745 check(SV("answer is '0'"), SV("answer is '{:-.6}'"), F(0)); 2746 check(SV("answer is '+0'"), SV("answer is '{:+.6}'"), F(0)); 2747 check(SV("answer is ' 0'"), SV("answer is '{: .6}'"), F(0)); 2748 2749 check(SV("answer is '-0'"), SV("answer is '{:.6}'"), F(-0.)); 2750 check(SV("answer is '-0'"), SV("answer is '{:-.6}'"), F(-0.)); 2751 check(SV("answer is '-0'"), SV("answer is '{:+.6}'"), F(-0.)); 2752 check(SV("answer is '-0'"), SV("answer is '{: .6}'"), F(-0.)); 2753 2754 // [format.string.std]/5 The sign option applies to floating-point infinity and NaN. 2755 check(SV("answer is 'inf'"), SV("answer is '{:.6}'"), std::numeric_limits<F>::infinity()); 2756 check(SV("answer is 'inf'"), SV("answer is '{:-.6}'"), std::numeric_limits<F>::infinity()); 2757 check(SV("answer is '+inf'"), SV("answer is '{:+.6}'"), std::numeric_limits<F>::infinity()); 2758 check(SV("answer is ' inf'"), SV("answer is '{: .6}'"), std::numeric_limits<F>::infinity()); 2759 2760 check(SV("answer is '-inf'"), SV("answer is '{:.6}'"), -std::numeric_limits<F>::infinity()); 2761 check(SV("answer is '-inf'"), SV("answer is '{:-.6}'"), -std::numeric_limits<F>::infinity()); 2762 check(SV("answer is '-inf'"), SV("answer is '{:+.6}'"), -std::numeric_limits<F>::infinity()); 2763 check(SV("answer is '-inf'"), SV("answer is '{: .6}'"), -std::numeric_limits<F>::infinity()); 2764 2765 check(SV("answer is 'nan'"), SV("answer is '{:.6}'"), nan_pos); 2766 check(SV("answer is 'nan'"), SV("answer is '{:-.6}'"), nan_pos); 2767 check(SV("answer is '+nan'"), SV("answer is '{:+.6}'"), nan_pos); 2768 check(SV("answer is ' nan'"), SV("answer is '{: .6}'"), nan_pos); 2769 2770 check(SV("answer is '-nan'"), SV("answer is '{:.6}'"), nan_neg); 2771 check(SV("answer is '-nan'"), SV("answer is '{:-.6}'"), nan_neg); 2772 check(SV("answer is '-nan'"), SV("answer is '{:+.6}'"), nan_neg); 2773 check(SV("answer is '-nan'"), SV("answer is '{: .6}'"), nan_neg); 2774 2775 // *** alternate form ** 2776 // When precision is zero there's no decimal point except when the alternate form is specified. 2777 // Note unlike the g and G option the trailing zeros are still removed. 2778 check(SV("answer is '0'"), SV("answer is '{:.0}'"), F(0)); 2779 check(SV("answer is '0.'"), SV("answer is '{:#.0}'"), F(0)); 2780 2781 check(SV("answer is '0.'"), SV("answer is '{:#.6}'"), F(0)); 2782 check(SV("answer is '2.5'"), SV("answer is '{:#.6}'"), F(2.5)); 2783 2784 check(SV("answer is 'inf'"), SV("answer is '{:#.6}'"), std::numeric_limits<F>::infinity()); 2785 check(SV("answer is '-inf'"), SV("answer is '{:#.6}'"), -std::numeric_limits<F>::infinity()); 2786 2787 check(SV("answer is 'nan'"), SV("answer is '{:#.6}'"), nan_pos); 2788 check(SV("answer is '-nan'"), SV("answer is '{:#.6}'"), nan_neg); 2789 2790 // *** zero-padding & width *** 2791 check(SV("answer is '0.03125'"), SV("answer is '{:06.6}'"), 0.03125); 2792 check(SV("answer is '+0.03125'"), SV("answer is '{:+06.6}'"), 0.03125); 2793 check(SV("answer is '+0.03125'"), SV("answer is '{:+07.6}'"), 0.03125); 2794 check(SV("answer is '+0.03125'"), SV("answer is '{:+08.6}'"), 0.03125); 2795 2796 check(SV("answer is '000.03125'"), SV("answer is '{:09.6}'"), 0.03125); 2797 check(SV("answer is '000.03125'"), SV("answer is '{:-09.6}'"), 0.03125); 2798 check(SV("answer is '+00.03125'"), SV("answer is '{:+09.6}'"), 0.03125); 2799 check(SV("answer is ' 00.03125'"), SV("answer is '{: 09.6}'"), 0.03125); 2800 2801 check(SV("answer is ' inf'"), SV("answer is '{:010.6}'"), std::numeric_limits<F>::infinity()); 2802 check(SV("answer is ' inf'"), SV("answer is '{:-010.6}'"), std::numeric_limits<F>::infinity()); 2803 check(SV("answer is ' +inf'"), SV("answer is '{:+010.6}'"), std::numeric_limits<F>::infinity()); 2804 check(SV("answer is ' inf'"), SV("answer is '{: 010.6}'"), std::numeric_limits<F>::infinity()); 2805 2806 check(SV("answer is ' -inf'"), SV("answer is '{:010.6}'"), -std::numeric_limits<F>::infinity()); 2807 check(SV("answer is ' -inf'"), SV("answer is '{:-010.6}'"), -std::numeric_limits<F>::infinity()); 2808 check(SV("answer is ' -inf'"), SV("answer is '{:+010.6}'"), -std::numeric_limits<F>::infinity()); 2809 check(SV("answer is ' -inf'"), SV("answer is '{: 010.6}'"), -std::numeric_limits<F>::infinity()); 2810 2811 check(SV("answer is ' nan'"), SV("answer is '{:010.6}'"), nan_pos); 2812 check(SV("answer is ' nan'"), SV("answer is '{:-010.6}'"), nan_pos); 2813 check(SV("answer is ' +nan'"), SV("answer is '{:+010.6}'"), nan_pos); 2814 check(SV("answer is ' nan'"), SV("answer is '{: 010.6}'"), nan_pos); 2815 2816 check(SV("answer is ' -nan'"), SV("answer is '{:010.6}'"), nan_neg); 2817 check(SV("answer is ' -nan'"), SV("answer is '{:-010.6}'"), nan_neg); 2818 check(SV("answer is ' -nan'"), SV("answer is '{:+010.6}'"), nan_neg); 2819 check(SV("answer is ' -nan'"), SV("answer is '{: 010.6}'"), nan_neg); 2820 2821 // *** precision *** 2822 check(SV("answer is '0.03'"), SV("answer is '{:.0}'"), 0.03125); 2823 check(SV("answer is '0.03'"), SV("answer is '{:.1}'"), 0.03125); 2824 check(SV("answer is '0.031'"), SV("answer is '{:.2}'"), 0.03125); 2825 check(SV("answer is '0.0312'"), SV("answer is '{:.3}'"), 0.03125); 2826 check(SV("answer is '0.03125'"), SV("answer is '{:.4}'"), 0.03125); 2827 check(SV("answer is '0.03125'"), SV("answer is '{:.5}'"), 0.03125); 2828 check(SV("answer is '0.03125'"), SV("answer is '{:.10}'"), 0.03125); 2829 2830 // *** precision & alternate form *** 2831 2832 check(SV("answer is '1.'"), SV("answer is '{:#.{}}'"), 1.2, 0); 2833 check(SV("answer is '1.'"), SV("answer is '{:#.{}}'"), 1.2, 1); 2834 check(SV("answer is '1.2'"), SV("answer is '{:#.{}}'"), 1.2, 2); 2835 check(SV("answer is '1.2'"), SV("answer is '{:#.{}}'"), 1.2, 3); 2836 check(SV("answer is '1.2'"), SV("answer is '{:#.{}}'"), 1.2, 4); 2837 check(SV("answer is '1.2'"), SV("answer is '{:#.{}}'"), 1.2, 5); 2838 check(SV("answer is '1.2'"), SV("answer is '{:#.{}}'"), 1.2, 6); 2839 2840 check(SV("answer is '1.e+03'"), SV("answer is '{:#.{}}'"), 1200.0, 0); 2841 check(SV("answer is '1.e+03'"), SV("answer is '{:#.{}}'"), 1200.0, 1); 2842 check(SV("answer is '1.2e+03'"), SV("answer is '{:#.{}}'"), 1200.0, 2); 2843 check(SV("answer is '1.2e+03'"), SV("answer is '{:#.{}}'"), 1200.0, 3); 2844 check(SV("answer is '1200.'"), SV("answer is '{:#.{}}'"), 1200.0, 4); 2845 check(SV("answer is '1200.'"), SV("answer is '{:#.{}}'"), 1200.0, 5); 2846 check(SV("answer is '1200.'"), SV("answer is '{:#.{}}'"), 1200.0, 6); 2847 2848 check(SV("answer is '1.e+06'"), SV("answer is '{:#.{}}'"), 1200000.0, 0); 2849 check(SV("answer is '1.e+06'"), SV("answer is '{:#.{}}'"), 1200000.0, 1); 2850 check(SV("answer is '1.2e+06'"), SV("answer is '{:#.{}}'"), 1200000.0, 2); 2851 check(SV("answer is '1.2e+06'"), SV("answer is '{:#.{}}'"), 1200000.0, 3); 2852 check(SV("answer is '1.2e+06'"), SV("answer is '{:#.{}}'"), 1200000.0, 4); 2853 check(SV("answer is '1.2e+06'"), SV("answer is '{:#.{}}'"), 1200000.0, 5); 2854 check(SV("answer is '1.2e+06'"), SV("answer is '{:#.{}}'"), 1200000.0, 6); 2855 2856 // *** locale-specific form *** 2857 // See locale-specific_form.pass.cpp 2858 } 2859 2860 template <class F, class CharT, class TestFunction> 2861 void format_test_floating_point_PR58714(TestFunction check) { 2862 check(SV("+1234"), SV("{:+}"), F(1234.0)); 2863 check(SV("+1.348p+10"), SV("{:+a}"), F(1234.0)); 2864 check(SV("+1.234000e+03"), SV("{:+e}"), F(1234.0)); 2865 check(SV("+1234.000000"), SV("{:+f}"), F(1234.0)); 2866 check(SV("+1234"), SV("{:+g}"), F(1234.0)); 2867 2868 check(SV("1234."), SV("{:#}"), F(1234.0)); 2869 check(SV("1.348p+10"), SV("{:#a}"), F(1234.0)); 2870 check(SV("1.234000e+03"), SV("{:#e}"), F(1234.0)); 2871 check(SV("1234.000000"), SV("{:#f}"), F(1234.0)); 2872 check(SV("1234.00"), SV("{:#g}"), F(1234.0)); 2873 2874 check(SV("4.e+30"), SV("{:#}"), F(4.0e+30)); 2875 check(SV("1.p+102"), SV("{:#a}"), F(0x4.0p+100)); 2876 check(SV("4.000000e+30"), SV("{:#e}"), F(4.0e+30)); 2877 check(SV("5070602400912917605986812821504.000000"), SV("{:#f}"), F(0x4.0p+100)); 2878 check(SV("4.00000e+30"), SV("{:#g}"), F(4.0e+30)); 2879 2880 check(SV("1234."), SV("{:#.6}"), F(1234.0)); // # does not restore zeros 2881 check(SV("1.348000p+10"), SV("{:#.6a}"), F(1234.0)); 2882 check(SV("1.234000e+03"), SV("{:#.6e}"), F(1234.0)); 2883 check(SV("1234.000000"), SV("{:#.6f}"), F(1234.0)); 2884 check(SV("1234.00"), SV("{:#.6g}"), F(1234.0)); 2885 2886 check(SV("-1234."), SV("{:#}"), F(-1234.0)); 2887 check(SV("-1.348p+10"), SV("{:#a}"), F(-1234.0)); 2888 check(SV("-1.234000e+03"), SV("{:#e}"), F(-1234.0)); 2889 check(SV("-1234.000000"), SV("{:#f}"), F(-1234.0)); 2890 check(SV("-1234.00"), SV("{:#g}"), F(-1234.0)); 2891 2892 check(SV("-1234."), SV("{:#.6}"), F(-1234.0)); // # does not restore zeros 2893 check(SV("-1.348000p+10"), SV("{:#.6a}"), F(-1234.0)); 2894 check(SV("-1.234000e+03"), SV("{:#.6e}"), F(-1234.0)); 2895 check(SV("-1234.000000"), SV("{:#.6f}"), F(-1234.0)); 2896 check(SV("-1234.00"), SV("{:#.6g}"), F(-1234.0)); 2897 2898 check(SV("+1234."), SV("{:+#}"), F(1234.0)); 2899 check(SV("+1.348p+10"), SV("{:+#a}"), F(1234.0)); 2900 check(SV("+1.234000e+03"), SV("{:+#e}"), F(1234.0)); 2901 check(SV("+1234.000000"), SV("{:+#f}"), F(1234.0)); 2902 check(SV("+1234.00"), SV("{:+#g}"), F(1234.0)); 2903 2904 check(SV("+1234."), SV("{:+#.6}"), F(1234.0)); // # does not restore zeros 2905 check(SV("+1.348000p+10"), SV("{:+#.6a}"), F(1234.0)); 2906 check(SV("+1.234000e+03"), SV("{:+#.6e}"), F(1234.0)); 2907 check(SV("+1234.000000"), SV("{:+#.6f}"), F(1234.0)); 2908 check(SV("+1234.00"), SV("{:+#.6g}"), F(1234.0)); 2909 } 2910 2911 template <class F, class CharT, class TestFunction, class ExceptionTest> 2912 void format_test_floating_point(TestFunction check, ExceptionTest check_exception) { 2913 format_test_floating_point_hex_lower_case<F, CharT>(check); 2914 format_test_floating_point_hex_upper_case<F, CharT>(check); 2915 format_test_floating_point_hex_lower_case_precision<F, CharT>(check); 2916 format_test_floating_point_hex_upper_case_precision<F, CharT>(check); 2917 2918 format_test_floating_point_scientific_lower_case<F, CharT>(check); 2919 format_test_floating_point_scientific_upper_case<F, CharT>(check); 2920 2921 format_test_floating_point_fixed_lower_case<F, CharT>(check); 2922 format_test_floating_point_fixed_upper_case<F, CharT>(check); 2923 2924 format_test_floating_point_general_lower_case<F, CharT>(check); 2925 format_test_floating_point_general_upper_case<F, CharT>(check); 2926 2927 format_test_floating_point_default<F, CharT>(check); 2928 format_test_floating_point_default_precision<F, CharT>(check); 2929 2930 format_test_floating_point_PR58714<F, CharT>(check); 2931 2932 // *** type *** 2933 for (const auto& fmt : invalid_types<CharT>("aAeEfFgG")) 2934 check_exception("The type option contains an invalid value for a floating-point formatting argument", fmt, F(1)); 2935 } 2936 2937 template <class CharT, class TestFunction, class ExceptionTest> 2938 void format_test_floating_point(TestFunction check, ExceptionTest check_exception) { 2939 format_test_floating_point<float, CharT>(check, check_exception); 2940 format_test_floating_point<double, CharT>(check, check_exception); 2941 format_test_floating_point<long double, CharT>(check, check_exception); 2942 } 2943 2944 template <class P, class CharT, class TestFunction, class ExceptionTest> 2945 void format_test_pointer(TestFunction check, ExceptionTest check_exception) { 2946 // *** align-fill & width *** 2947 check(SV("answer is ' 0x0'"), SV("answer is '{:6}'"), P(nullptr)); 2948 check(SV("answer is ' 0x0'"), SV("answer is '{:>6}'"), P(nullptr)); 2949 check(SV("answer is '0x0 '"), SV("answer is '{:<6}'"), P(nullptr)); 2950 check(SV("answer is ' 0x0 '"), SV("answer is '{:^6}'"), P(nullptr)); 2951 2952 // The fill character ':' is allowed here (P0645) but not in ranges (P2286). 2953 check(SV("answer is ':::0x0'"), SV("answer is '{::>6}'"), P(nullptr)); 2954 check(SV("answer is '0x0:::'"), SV("answer is '{::<6}'"), P(nullptr)); 2955 check(SV("answer is ':0x0::'"), SV("answer is '{::^6}'"), P(nullptr)); 2956 2957 // Test whether zero padding is ignored 2958 check(SV("answer is ':::0x0'"), SV("answer is '{::>06}'"), P(nullptr)); 2959 check(SV("answer is '0x0:::'"), SV("answer is '{::<06}'"), P(nullptr)); 2960 check(SV("answer is ':0x0::'"), SV("answer is '{::^06}'"), P(nullptr)); 2961 2962 // *** Sign *** 2963 check_exception("The format specifier should consume the input or end with a '}'", SV("{:-}"), P(nullptr)); 2964 check_exception("The format specifier should consume the input or end with a '}'", SV("{:+}"), P(nullptr)); 2965 check_exception("The format specifier should consume the input or end with a '}'", SV("{: }"), P(nullptr)); 2966 2967 // *** alternate form *** 2968 check_exception("The format specifier should consume the input or end with a '}'", SV("{:#}"), P(nullptr)); 2969 2970 // *** zero-padding *** 2971 check(SV("answer is '0x0000'"), SV("answer is '{:06}'"), P(nullptr)); 2972 check(SV("answer is '0x0000'"), SV("answer is '{:06p}'"), P(nullptr)); 2973 check(SV("answer is '0X0000'"), SV("answer is '{:06P}'"), P(nullptr)); 2974 2975 // *** precision *** 2976 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.}"), nullptr); 2977 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.0}"), nullptr); 2978 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.42}"), nullptr); 2979 2980 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.{}}"), nullptr); 2981 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.{}}"), nullptr, true); 2982 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.{}}"), nullptr, 1.0); 2983 2984 // *** locale-specific form *** 2985 check_exception("The format specifier should consume the input or end with a '}'", SV("{:L}"), P(nullptr)); 2986 2987 // *** type *** 2988 for (const auto& fmt : invalid_types<CharT>("pP")) 2989 check_exception("The type option contains an invalid value for a pointer formatting argument", fmt, P(nullptr)); 2990 } 2991 2992 template <class CharT, class TestFunction, class ExceptionTest> 2993 void format_test_handle(TestFunction check, ExceptionTest check_exception) { 2994 // *** Valid permutations *** 2995 check(SV("answer is '0xaaaa'"), SV("answer is '{}'"), status::foo); 2996 check(SV("answer is '0xaaaa'"), SV("answer is '{:x}'"), status::foo); 2997 check(SV("answer is '0XAAAA'"), SV("answer is '{:X}'"), status::foo); 2998 check(SV("answer is 'foo'"), SV("answer is '{:s}'"), status::foo); 2999 3000 check(SV("answer is '0x5555'"), SV("answer is '{}'"), status::bar); 3001 check(SV("answer is '0x5555'"), SV("answer is '{:x}'"), status::bar); 3002 check(SV("answer is '0X5555'"), SV("answer is '{:X}'"), status::bar); 3003 check(SV("answer is 'bar'"), SV("answer is '{:s}'"), status::bar); 3004 3005 check(SV("answer is '0xaa55'"), SV("answer is '{}'"), status::foobar); 3006 check(SV("answer is '0xaa55'"), SV("answer is '{:x}'"), status::foobar); 3007 check(SV("answer is '0XAA55'"), SV("answer is '{:X}'"), status::foobar); 3008 check(SV("answer is 'foobar'"), SV("answer is '{:s}'"), status::foobar); 3009 3010 // P2418 Changed the argument from a const reference to a forwarding reference. 3011 // This mainly affects handle classes, however since we use an abstraction 3012 // layer here it's "tricky" to verify whether this test would do the "right" 3013 // thing. So these tests are done separately. 3014 3015 // *** type *** 3016 for (const auto& fmt : invalid_types<CharT>("xXs")) 3017 check_exception("The type option contains an invalid value for a status formatting argument", fmt, status::foo); 3018 } 3019 3020 template <class CharT, class TestFunction, class ExceptionTest> 3021 void format_test_pointer(TestFunction check, ExceptionTest check_exception) { 3022 format_test_pointer<std::nullptr_t, CharT>(check, check_exception); 3023 format_test_pointer<void*, CharT>(check, check_exception); 3024 format_test_pointer<const void*, CharT>(check, check_exception); 3025 } 3026 3027 /// Tests special buffer functions with a "large" input. 3028 /// 3029 /// This is a test specific for libc++, however the code should behave the same 3030 /// on all implementations. 3031 /// In \c __format::__output_buffer there are some special functions to optimize 3032 /// outputting multiple characters, \c __copy, \c __transform, \c __fill. This 3033 /// test validates whether the functions behave properly when the output size 3034 /// doesn't fit in its internal buffer. 3035 template <class CharT, class TestFunction> 3036 void format_test_buffer_optimizations(TestFunction check) { 3037 #ifdef _LIBCPP_VERSION 3038 // Used to validate our test sets are the proper size. 3039 // To test the chunked operations it needs to be larger than the internal 3040 // buffer. Picked a nice looking number. 3041 constexpr int minimum = 3 * 256; 3042 #else 3043 constexpr int minimum = 1; 3044 #endif 3045 3046 // Copy 3047 std::basic_string<CharT> str = STR( 3048 "The quick brown fox jumps over the lazy dog." 3049 "The quick brown fox jumps over the lazy dog." 3050 "The quick brown fox jumps over the lazy dog." 3051 "The quick brown fox jumps over the lazy dog." 3052 "The quick brown fox jumps over the lazy dog." 3053 "The quick brown fox jumps over the lazy dog." 3054 "The quick brown fox jumps over the lazy dog." 3055 "The quick brown fox jumps over the lazy dog." 3056 "The quick brown fox jumps over the lazy dog." 3057 "The quick brown fox jumps over the lazy dog." 3058 "The quick brown fox jumps over the lazy dog." 3059 "The quick brown fox jumps over the lazy dog." 3060 "The quick brown fox jumps over the lazy dog." 3061 "The quick brown fox jumps over the lazy dog." 3062 "The quick brown fox jumps over the lazy dog." 3063 "The quick brown fox jumps over the lazy dog." 3064 "The quick brown fox jumps over the lazy dog." 3065 "The quick brown fox jumps over the lazy dog." 3066 "The quick brown fox jumps over the lazy dog." 3067 "The quick brown fox jumps over the lazy dog." 3068 "The quick brown fox jumps over the lazy dog." 3069 "The quick brown fox jumps over the lazy dog." 3070 "The quick brown fox jumps over the lazy dog." 3071 "The quick brown fox jumps over the lazy dog." 3072 "The quick brown fox jumps over the lazy dog." 3073 "The quick brown fox jumps over the lazy dog." 3074 "The quick brown fox jumps over the lazy dog." 3075 "The quick brown fox jumps over the lazy dog." 3076 "The quick brown fox jumps over the lazy dog." 3077 "The quick brown fox jumps over the lazy dog."); 3078 assert(str.size() > minimum); 3079 check(std::basic_string_view<CharT>{str}, SV("{}"), str); 3080 3081 // Fill 3082 std::basic_string<CharT> fill(minimum, CharT('*')); 3083 check(std::basic_string_view<CharT>{str + fill}, SV("{:*<{}}"), str, str.size() + minimum); 3084 check(std::basic_string_view<CharT>{fill + str + fill}, SV("{:*^{}}"), str, minimum + str.size() + minimum); 3085 check(std::basic_string_view<CharT>{fill + str}, SV("{:*>{}}"), str, minimum + str.size()); 3086 } 3087 3088 template <class CharT, execution_modus modus, class TestFunction, class ExceptionTest> 3089 void format_tests(TestFunction check, ExceptionTest check_exception) { 3090 // *** Test escaping *** 3091 check(SV("{"), SV("{{")); 3092 check(SV("}"), SV("}}")); 3093 check(SV("{:^}"), SV("{{:^}}")); 3094 check(SV("{: ^}"), SV("{{:{}^}}"), CharT(' ')); 3095 check(SV("{:{}^}"), SV("{{:{{}}^}}")); 3096 check(SV("{:{ }^}"), SV("{{:{{{}}}^}}"), CharT(' ')); 3097 3098 // *** Test argument ID *** 3099 check(SV("hello false true"), SV("hello {0:} {1:}"), false, true); 3100 check(SV("hello true false"), SV("hello {1:} {0:}"), false, true); 3101 3102 // *** Test many arguments *** 3103 3104 // [format.args]/1 3105 // An instance of basic_format_args provides access to formatting arguments. 3106 // Implementations should optimize the representation of basic_format_args 3107 // for a small number of formatting arguments. 3108 // 3109 // These's no guidances what "a small number of formatting arguments" is. 3110 // - fmtlib uses a 15 elements 3111 // - libc++ uses 12 elements 3112 // - MSVC STL uses a different approach regardless of the number of arguments 3113 // - libstdc++ has no implementation yet 3114 // fmtlib and libc++ use a similar approach, this approach can support 16 3115 // elements (based on design choices both support less elements). This test 3116 // makes sure "the large number of formatting arguments" code path is tested. 3117 check( 3118 SV("1234567890\t1234567890"), 3119 SV("{}{}{}{}{}{}{}{}{}{}\t{}{}{}{}{}{}{}{}{}{}"), 3120 1, 3121 2, 3122 3, 3123 4, 3124 5, 3125 6, 3126 7, 3127 8, 3128 9, 3129 0, 3130 1, 3131 2, 3132 3, 3133 4, 3134 5, 3135 6, 3136 7, 3137 8, 3138 9, 3139 0); 3140 3141 // *** Test buffer boundaries format strings *** 3142 if constexpr (modus == execution_modus::full) { 3143 format_test_buffer_copy<CharT>(check); 3144 format_test_buffer_full<CharT>(check); 3145 } 3146 3147 // *** Test invalid format strings *** 3148 check_exception("The format string terminates at a '{'", SV("{")); 3149 check_exception("The argument index value is too large for the number of arguments supplied", SV("{:")); 3150 check_exception("The replacement field misses a terminating '}'", SV("{:"), 42); 3151 3152 check_exception("The argument index should end with a ':' or a '}'", SV("{0")); 3153 check_exception("The argument index value is too large for the number of arguments supplied", SV("{0:")); 3154 check_exception("The replacement field misses a terminating '}'", SV("{0:"), 42); 3155 3156 check_exception("The format string contains an invalid escape sequence", SV("}")); 3157 check_exception("The format string contains an invalid escape sequence", SV("{:}-}"), 42); 3158 3159 check_exception("The format string contains an invalid escape sequence", SV("} ")); 3160 check_exception("The argument index starts with an invalid character", SV("{-"), 42); 3161 check_exception("The argument index value is too large for the number of arguments supplied", SV("hello {}")); 3162 check_exception("The argument index value is too large for the number of arguments supplied", SV("hello {0}")); 3163 check_exception("The argument index value is too large for the number of arguments supplied", SV("hello {1}"), 42); 3164 3165 // *** Test char format argument *** 3166 // The `char` to `wchar_t` formatting is tested separately. 3167 check(SV("hello 09azAZ!"), 3168 SV("hello {}{}{}{}{}{}{}"), 3169 CharT('0'), 3170 CharT('9'), 3171 CharT('a'), 3172 CharT('z'), 3173 CharT('A'), 3174 CharT('Z'), 3175 CharT('!')); 3176 if constexpr (modus == execution_modus::full) { 3177 format_test_char<CharT>(check, check_exception); 3178 format_test_char_as_integer<CharT>(check, check_exception); 3179 } 3180 3181 // *** Test string format argument *** 3182 { 3183 CharT buffer[] = {CharT('0'), CharT('9'), CharT('a'), CharT('z'), CharT('A'), CharT('Z'), CharT('!'), 0}; 3184 CharT* data = buffer; 3185 check(SV("hello 09azAZ!"), SV("hello {}"), data); 3186 } 3187 { 3188 CharT buffer[] = {CharT('0'), CharT('9'), CharT('a'), CharT('z'), CharT('A'), CharT('Z'), CharT('!'), 0}; 3189 const CharT* data = buffer; 3190 check(SV("hello 09azAZ!"), SV("hello {}"), data); 3191 } 3192 { 3193 std::basic_string<CharT> data = STR("world"); 3194 check(SV("hello world"), SV("hello {}"), data); 3195 } 3196 { 3197 std::basic_string<CharT> buffer = STR("world"); 3198 std::basic_string_view<CharT> data = buffer; 3199 check(SV("hello world"), SV("hello {}"), data); 3200 } 3201 if constexpr (modus == execution_modus::full) 3202 format_string_tests<CharT>(check, check_exception); 3203 3204 // *** Test Boolean format argument *** 3205 check(SV("hello false true"), SV("hello {} {}"), false, true); 3206 3207 if constexpr (modus == execution_modus::full) { 3208 format_test_bool<CharT>(check, check_exception); 3209 format_test_bool_as_integer<CharT>(check, check_exception); 3210 } 3211 // *** Test signed integral format argument *** 3212 check(SV("hello 42"), SV("hello {}"), static_cast<signed char>(42)); 3213 check(SV("hello 42"), SV("hello {}"), static_cast<short>(42)); 3214 check(SV("hello 42"), SV("hello {}"), static_cast<int>(42)); 3215 check(SV("hello 42"), SV("hello {}"), static_cast<long>(42)); 3216 check(SV("hello 42"), SV("hello {}"), static_cast<long long>(42)); 3217 #ifndef TEST_HAS_NO_INT128 3218 check(SV("hello 42"), SV("hello {}"), static_cast<__int128_t>(42)); 3219 #endif 3220 3221 if constexpr (modus == execution_modus::full) 3222 format_test_signed_integer<CharT>(check, check_exception); 3223 3224 // ** Test unsigned integral format argument *** 3225 check(SV("hello 42"), SV("hello {}"), static_cast<unsigned char>(42)); 3226 check(SV("hello 42"), SV("hello {}"), static_cast<unsigned short>(42)); 3227 check(SV("hello 42"), SV("hello {}"), static_cast<unsigned>(42)); 3228 check(SV("hello 42"), SV("hello {}"), static_cast<unsigned long>(42)); 3229 check(SV("hello 42"), SV("hello {}"), static_cast<unsigned long long>(42)); 3230 #ifndef TEST_HAS_NO_INT128 3231 check(SV("hello 42"), SV("hello {}"), static_cast<__uint128_t>(42)); 3232 #endif 3233 if constexpr (modus == execution_modus::full) 3234 format_test_unsigned_integer<CharT>(check, check_exception); 3235 3236 // *** Test floating point format argument *** 3237 check(SV("hello 42"), SV("hello {}"), static_cast<float>(42)); 3238 check(SV("hello 42"), SV("hello {}"), static_cast<double>(42)); 3239 check(SV("hello 42"), SV("hello {}"), static_cast<long double>(42)); 3240 if constexpr (modus == execution_modus::full) 3241 format_test_floating_point<CharT>(check, check_exception); 3242 3243 // *** Test pointer formatter argument *** 3244 check(SV("hello 0x0"), SV("hello {}"), nullptr); 3245 check(SV("hello 0x42"), SV("hello {}"), reinterpret_cast<void*>(0x42)); 3246 check(SV("hello 0x42"), SV("hello {}"), reinterpret_cast<const void*>(0x42)); 3247 if constexpr (modus == execution_modus::full) 3248 format_test_pointer<CharT>(check, check_exception); 3249 3250 // *** Test handle formatter argument *** 3251 format_test_handle<CharT>(check, check_exception); 3252 3253 // *** Test the internal buffer optimizations *** 3254 if constexpr (modus == execution_modus::full) 3255 format_test_buffer_optimizations<CharT>(check); 3256 } 3257 3258 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 3259 template <class TestFunction> 3260 void format_tests_char_to_wchar_t(TestFunction check) { 3261 using CharT = wchar_t; 3262 check(SV("hello 09azA"), SV("hello {}{}{}{}{}"), '0', '9', 'a', 'z', 'A'); 3263 } 3264 #endif 3265 3266 #endif // TEST_STD_UTILITIES_FORMAT_FORMAT_FUNCTIONS_FORMAT_TESTS_H 3267