| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 3 |
// See https://llvm.org/LICENSE.txt for license information. |
| 4 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 5 |
// |
| 6 |
//===----------------------------------------------------------------------===// |
| 7 |
|
| 8 |
#ifndef TEST_STD_UTILITIES_FORMAT_FORMAT_FUNCTIONS_FORMAT_TESTS_H |
| 9 |
#define TEST_STD_UTILITIES_FORMAT_FORMAT_FUNCTIONS_FORMAT_TESTS_H |
| 10 |
|
| 11 |
#include <format> |
| 12 |
|
| 13 |
#include <algorithm> |
| 14 |
#include <cassert> |
| 15 |
#include <charconv> |
| 16 |
#include <cmath> |
| 17 |
#include <cstdint> |
| 18 |
#include <iterator> |
| 19 |
|
| 20 |
#include "string_literal.h" |
| 21 |
#include "test_macros.h" |
| 22 |
#include "format.functions.common.h" |
| 23 |
|
| 24 |
// In this file the following template types are used: |
| 25 |
// TestFunction must be callable as check(expected-result, string-to-format, args-to-format...) |
| 26 |
// ExceptionTest must be callable as check_exception(expected-exception, string-to-format, args-to-format...) |
| 27 |
|
| 28 |
enum class execution_modus { partial, full }; |
| 29 |
|
| 30 |
template <class CharT> |
| 31 |
std::vector<std::basic_string_view<CharT>> invalid_types(std::string_view valid) { |
| 32 |
std::vector<std::basic_string_view<CharT>> result; |
| 33 |
|
| 34 |
#define CASE(T) \ |
| 35 |
case #T[0]: \ |
| 36 |
result.push_back(SV("Invalid formatter type {:" #T "}")); \ |
| 37 |
break; |
| 38 |
|
| 39 |
#if TEST_STD_VER > 20 |
| 40 |
constexpr std::string_view types = "aAbBcdeEfFgGopPsxX?"; |
| 41 |
#else |
| 42 |
constexpr std::string_view types = "aAbBcdeEfFgGopPsxX"; |
| 43 |
#endif |
| 44 |
|
| 45 |
for (auto type : types) { |
| 46 |
if (valid.find(type) != std::string::npos) |
| 47 |
continue; |
| 48 |
|
| 49 |
switch (type) { |
| 50 |
CASE(a) |
| 51 |
CASE(A) |
| 52 |
CASE(b) |
| 53 |
CASE(B) |
| 54 |
CASE(c) |
| 55 |
CASE(d) |
| 56 |
CASE(e) |
| 57 |
CASE(E) |
| 58 |
CASE(f) |
| 59 |
CASE(F) |
| 60 |
CASE(g) |
| 61 |
CASE(G) |
| 62 |
CASE(o) |
| 63 |
CASE(p) |
| 64 |
CASE(P) |
| 65 |
CASE(s) |
| 66 |
CASE(x) |
| 67 |
CASE(X) |
| 68 |
CASE(?) |
| 69 |
case 0: |
| 70 |
break; |
| 71 |
default: |
| 72 |
assert(false && "Add the type to the list of cases."); |
| 73 |
} |
| 74 |
} |
| 75 |
#undef CASE |
| 76 |
|
| 77 |
return result; |
| 78 |
} |
| 79 |
|
| 80 |
template <class CharT, class TestFunction> |
| 81 |
void format_test_buffer_copy(TestFunction check) { |
| 82 |
// *** copy *** |
| 83 |
check(SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), |
| 84 |
SV("{}"), |
| 85 |
SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); |
| 86 |
|
| 87 |
check(SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 88 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), |
| 89 |
SV("{}"), |
| 90 |
SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 91 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); |
| 92 |
|
| 93 |
check(SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 94 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 95 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 96 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), |
| 97 |
SV("{}"), |
| 98 |
SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 99 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 100 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 101 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); |
| 102 |
|
| 103 |
check(SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 104 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 105 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 106 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 107 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 108 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 109 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 110 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), |
| 111 |
SV("{}"), |
| 112 |
SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 113 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 114 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 115 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 116 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 117 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 118 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 119 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); |
| 120 |
|
| 121 |
check( |
| 122 |
SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 123 |
"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 |
SV("{}"), |
| 139 |
SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 140 |
"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 |
|
| 156 |
// *** copy + push_back *** |
| 157 |
|
| 158 |
check(SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 159 |
"X"), |
| 160 |
SV("{}X"), |
| 161 |
SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); |
| 162 |
|
| 163 |
check(SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 164 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 165 |
"X"), |
| 166 |
SV("{}X"), |
| 167 |
SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 168 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); |
| 169 |
|
| 170 |
check(SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 171 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 172 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 173 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 174 |
"X"), |
| 175 |
SV("{}X"), |
| 176 |
SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 177 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 178 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 179 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); |
| 180 |
|
| 181 |
check(SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 182 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 183 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 184 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 185 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 186 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 187 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 188 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 189 |
"X"), |
| 190 |
SV("{}X"), |
| 191 |
SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 192 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 193 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 194 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 195 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 196 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 197 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 198 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); |
| 199 |
|
| 200 |
check( |
| 201 |
SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 202 |
"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 |
"X"), |
| 218 |
SV("{}X"), |
| 219 |
SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 220 |
"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 |
|
| 236 |
// *** push_back + copy *** |
| 237 |
|
| 238 |
check(SV("X" |
| 239 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), |
| 240 |
SV("X{}"), |
| 241 |
SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); |
| 242 |
|
| 243 |
check(SV("X" |
| 244 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 245 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), |
| 246 |
SV("X{}"), |
| 247 |
SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 248 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); |
| 249 |
|
| 250 |
check(SV("X" |
| 251 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 252 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 253 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 254 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), |
| 255 |
SV("X{}"), |
| 256 |
SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 257 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 258 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 259 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); |
| 260 |
|
| 261 |
check(SV("X" |
| 262 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 263 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 264 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 265 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 266 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 267 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 268 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 269 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), |
| 270 |
SV("X{}"), |
| 271 |
SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 272 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 273 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 274 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 275 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 276 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 277 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 278 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); |
| 279 |
|
| 280 |
check( |
| 281 |
SV("X" |
| 282 |
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 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 |
SV("X{}"), |
| 299 |
SV("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 300 |
"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 |
} |
| 316 |
|
| 317 |
template <class CharT, class TestFunction> |
| 318 |
void format_test_buffer_full(TestFunction check) { |
| 319 |
// *** fill *** |
| 320 |
check(SV("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"), SV("{:|<64}"), SV("")); |
| 321 |
|
| 322 |
check(SV("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 323 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"), |
| 324 |
SV("{:|<128}"), |
| 325 |
SV("")); |
| 326 |
|
| 327 |
check(SV("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 328 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 329 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 330 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"), |
| 331 |
SV("{:|<256}"), |
| 332 |
SV("")); |
| 333 |
|
| 334 |
check(SV("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 335 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 336 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 337 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 338 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 339 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 340 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 341 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"), |
| 342 |
SV("{:|<512}"), |
| 343 |
SV("")); |
| 344 |
|
| 345 |
check(SV("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 346 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 347 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 348 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 349 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 350 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 351 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 352 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 353 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 354 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 355 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 356 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 357 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 358 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 359 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 360 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"), |
| 361 |
SV("{:|<1024}"), |
| 362 |
SV("")); |
| 363 |
|
| 364 |
// *** fill + push_back *** |
| 365 |
|
| 366 |
check(SV("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 367 |
"X"), |
| 368 |
SV("{:|<64}X"), |
| 369 |
SV("")); |
| 370 |
|
| 371 |
check(SV("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 372 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 373 |
"X"), |
| 374 |
SV("{:|<128}X"), |
| 375 |
SV("")); |
| 376 |
|
| 377 |
check(SV("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 378 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 379 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 380 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 381 |
"X"), |
| 382 |
SV("{:|<256}X"), |
| 383 |
SV("")); |
| 384 |
|
| 385 |
check(SV("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 386 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 387 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 388 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 389 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 390 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 391 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 392 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 393 |
"X"), |
| 394 |
SV("{:|<512}X"), |
| 395 |
SV("")); |
| 396 |
|
| 397 |
check(SV("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 398 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 399 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 400 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 401 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 402 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 403 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 404 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 405 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 406 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 407 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 408 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 409 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 410 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 411 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 412 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 413 |
"X"), |
| 414 |
SV("{:|<1024}X"), |
| 415 |
SV("")); |
| 416 |
|
| 417 |
// *** push_back + fill *** |
| 418 |
|
| 419 |
check(SV("X" |
| 420 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"), |
| 421 |
SV("X{:|<64}"), |
| 422 |
SV("")); |
| 423 |
|
| 424 |
check(SV("X" |
| 425 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 426 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"), |
| 427 |
SV("X{:|<128}"), |
| 428 |
SV("")); |
| 429 |
|
| 430 |
check(SV("X" |
| 431 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 432 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 433 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 434 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"), |
| 435 |
SV("X{:|<256}"), |
| 436 |
SV("")); |
| 437 |
|
| 438 |
check(SV("X" |
| 439 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 440 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 441 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 442 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 443 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 444 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 445 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 446 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"), |
| 447 |
SV("X{:|<512}"), |
| 448 |
SV("")); |
| 449 |
|
| 450 |
check(SV("X" |
| 451 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 452 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 453 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 454 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 455 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 456 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 457 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 458 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 459 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 460 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 461 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 462 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 463 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 464 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 465 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" |
| 466 |
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"), |
| 467 |
SV("X{:|<1024}"), |
| 468 |
SV("")); |
| 469 |
} |
| 470 |
|
| 471 |
// Using a const ref for world and universe so a string literal will be a character array. |
| 472 |
// When passed as character array W and U have different types. |
| 473 |
template <class CharT, class W, class U, class TestFunction, class ExceptionTest> |
| 474 |
void format_test_string(const W& world, const U& universe, TestFunction check, ExceptionTest check_exception) { |
| 475 |
|
| 476 |
// *** Valid input tests *** |
| 477 |
// Unused argument is ignored. TODO FMT what does the Standard mandate? |
| 478 |
check(SV("hello world"), SV("hello {}"), world, universe); |
| 479 |
check(SV("hello world and universe"), SV("hello {} and {}"), world, universe); |
| 480 |
check(SV("hello world"), SV("hello {0}"), world, universe); |
| 481 |
check(SV("hello universe"), SV("hello {1}"), world, universe); |
| 482 |
check(SV("hello universe and world"), SV("hello {1} and {0}"), world, universe); |
| 483 |
|
| 484 |
check(SV("hello world"), SV("hello {:_>}"), world); |
| 485 |
check(SV("hello world "), SV("hello {:8}"), 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 |
|
| 491 |
// The fill character ':' is allowed here (P0645) but not in ranges (P2286). |
| 492 |
check(SV("hello :::world"), SV("hello {::>8}"), world); |
| 493 |
check(SV("hello <<<world"), SV("hello {:<>8}"), world); |
| 494 |
check(SV("hello ^^^world"), SV("hello {:^>8}"), world); |
| 495 |
|
| 496 |
check(SV("hello $world"), SV("hello {:$>{}}"), world, 6); |
| 497 |
check(SV("hello $world"), SV("hello {0:$>{1}}"), world, 6); |
| 498 |
check(SV("hello $world"), SV("hello {1:$>{0}}"), 6, world); |
| 499 |
|
| 500 |
check(SV("hello world"), SV("hello {:.5}"), world); |
| 501 |
check(SV("hello unive"), SV("hello {:.5}"), universe); |
| 502 |
|
| 503 |
check(SV("hello univer"), SV("hello {:.{}}"), universe, 6); |
| 504 |
check(SV("hello univer"), SV("hello {0:.{1}}"), universe, 6); |
| 505 |
check(SV("hello univer"), SV("hello {1:.{0}}"), 6, universe); |
| 506 |
|
| 507 |
check(SV("hello %world%"), SV("hello {:%^7.7}"), world); |
| 508 |
check(SV("hello univers"), SV("hello {:%^7.7}"), universe); |
| 509 |
check(SV("hello %world%"), SV("hello {:%^{}.{}}"), world, 7, 7); |
| 510 |
check(SV("hello %world%"), SV("hello {0:%^{1}.{2}}"), world, 7, 7); |
| 511 |
check(SV("hello %world%"), SV("hello {0:%^{2}.{1}}"), world, 7, 7); |
| 512 |
check(SV("hello %world%"), SV("hello {1:%^{0}.{2}}"), 7, world, 7); |
| 513 |
|
| 514 |
check(SV("hello world"), SV("hello {:_>s}"), world); |
| 515 |
check(SV("hello $world"), SV("hello {:$>{}s}"), world, 6); |
| 516 |
check(SV("hello world"), SV("hello {:.5s}"), world); |
| 517 |
check(SV("hello univer"), SV("hello {:.{}s}"), universe, 6); |
| 518 |
check(SV("hello %world%"), SV("hello {:%^7.7s}"), world); |
| 519 |
|
| 520 |
check(SV("hello #####uni"), SV("hello {:#>8.3s}"), universe); |
| 521 |
check(SV("hello ##uni###"), SV("hello {:#^8.3s}"), universe); |
| 522 |
check(SV("hello uni#####"), SV("hello {:#<8.3s}"), universe); |
| 523 |
|
| 524 |
// *** sign *** |
| 525 |
check_exception("The format specifier should consume the input or end with a '}'", SV("hello {:-}"), world); |
| 526 |
|
| 527 |
// *** alternate form *** |
| 528 |
check_exception("The format specifier should consume the input or end with a '}'", SV("hello {:#}"), world); |
| 529 |
|
| 530 |
// *** zero-padding *** |
| 531 |
check_exception("The width option should not have a leading zero", SV("hello {:0}"), world); |
| 532 |
|
| 533 |
// *** width *** |
| 534 |
// Width 0 allowed, but not useful for string arguments. |
| 535 |
check(SV("hello world"), SV("hello {:{}}"), world, 0); |
| 536 |
|
| 537 |
#ifdef _LIBCPP_VERSION |
| 538 |
// This limit isn't specified in the Standard. |
| 539 |
static_assert(std::__format::__number_max == 2'147'483'647, "Update the assert and the test."); |
| 540 |
check_exception("The numeric value of the format specifier is too large", SV("{:2147483648}"), world); |
| 541 |
check_exception("The numeric value of the format specifier is too large", SV("{:5000000000}"), world); |
| 542 |
check_exception("The numeric value of the format specifier is too large", SV("{:10000000000}"), world); |
| 543 |
#endif |
| 544 |
|
| 545 |
check_exception("An argument index may not have a negative value", SV("hello {:{}}"), world, -1); |
| 546 |
check_exception("The value of the argument index exceeds its maximum value", SV("hello {:{}}"), world, unsigned(-1)); |
| 547 |
check_exception( |
| 548 |
"The argument index value is too large for the number of arguments supplied", SV("hello {:{}}"), world); |
| 549 |
check_exception( |
| 550 |
"Replacement argument isn't a standard signed or unsigned integer type", SV("hello {:{}}"), world, universe); |
| 551 |
check_exception("Using manual argument numbering in automatic argument numbering mode", SV("hello {:{0}}"), world, 1); |
| 552 |
check_exception("Using automatic argument numbering in manual argument numbering mode", SV("hello {0:{}}"), world, 1); |
| 553 |
// Arg-id may not have leading zeros. |
| 554 |
check_exception("The argument index is invalid", SV("hello {0:{01}}"), world, 1); |
| 555 |
|
| 556 |
// *** precision *** |
| 557 |
#ifdef _LIBCPP_VERSION |
| 558 |
// This limit isn't specified in the Standard. |
| 559 |
static_assert(std::__format::__number_max == 2'147'483'647, "Update the assert and the test."); |
| 560 |
check_exception("The numeric value of the format specifier is too large", SV("{:.2147483648}"), world); |
| 561 |
check_exception("The numeric value of the format specifier is too large", SV("{:.5000000000}"), world); |
| 562 |
check_exception("The numeric value of the format specifier is too large", SV("{:.10000000000}"), world); |
| 563 |
#endif |
| 564 |
|
| 565 |
// Precision 0 allowed, but not useful for string arguments. |
| 566 |
check(SV("hello "), SV("hello {:.{}}"), world, 0); |
| 567 |
// Precision may have leading zeros. Secondly tests the value is still base 10. |
| 568 |
check(SV("hello 0123456789"), SV("hello {:.000010}"), STR("0123456789abcdef")); |
| 569 |
check_exception("An argument index may not have a negative value", SV("hello {:.{}}"), world, -1); |
| 570 |
check_exception("The value of the argument index exceeds its maximum value", SV("hello {:.{}}"), world, ~0u); |
| 571 |
check_exception( |
| 572 |
"The argument index value is too large for the number of arguments supplied", SV("hello {:.{}}"), world); |
| 573 |
check_exception( |
| 574 |
"Replacement argument isn't a standard signed or unsigned integer type", SV("hello {:.{}}"), world, universe); |
| 575 |
check_exception("Using manual argument numbering in automatic argument numbering mode", SV("hello {:.{0}}"), world, |
| 576 |
1); |
| 577 |
check_exception("Using automatic argument numbering in manual argument numbering mode", SV("hello {0:.{}}"), world, |
| 578 |
1); |
| 579 |
// Arg-id may not have leading zeros. |
| 580 |
check_exception("The argument index is invalid", SV("hello {0:.{01}}"), world, 1); |
| 581 |
|
| 582 |
// *** locale-specific form *** |
| 583 |
check_exception("The format specifier should consume the input or end with a '}'", SV("hello {:L}"), world); |
| 584 |
|
| 585 |
// *** type *** |
| 586 |
#if TEST_STD_VER > 20 |
| 587 |
const char* valid_types = "s?"; |
| 588 |
#else |
| 589 |
const char* valid_types = "s"; |
| 590 |
#endif |
| 591 |
for (const auto& fmt : invalid_types<CharT>(valid_types)) |
| 592 |
check_exception("The type option contains an invalid value for a string formatting argument", fmt, world); |
| 593 |
} |
| 594 |
|
| 595 |
template <class CharT, class TestFunction> |
| 596 |
void format_test_string_unicode([[maybe_unused]] TestFunction check) { |
| 597 |
// unicode.pass.cpp and ascii.pass.cpp have additional tests. |
| 598 |
#ifndef TEST_HAS_NO_UNICODE |
| 599 |
// Make sure all possible types are tested. For clarity don't use macros. |
| 600 |
if constexpr (std::same_as<CharT, char>) { |
| 601 |
const char* c_string = "aßc"; |
| 602 |
check(SV("*aßc*"), SV("{:*^5}"), c_string); |
| 603 |
check(SV("*aß*"), SV("{:*^4.2}"), c_string); |
| 604 |
|
| 605 |
check(SV("*aßc*"), SV("{:*^5}"), const_cast<char*>(c_string)); |
| 606 |
check(SV("*aß*"), SV("{:*^4.2}"), const_cast<char*>(c_string)); |
| 607 |
|
| 608 |
check(SV("*aßc*"), SV("{:*^5}"), "aßc"); |
| 609 |
check(SV("*aß*"), SV("{:*^4.2}"), "aßc"); |
| 610 |
|
| 611 |
check(SV("*aßc*"), SV("{:*^5}"), std::string("aßc")); |
| 612 |
check(SV("*aß*"), SV("{:*^4.2}"), std::string("aßc")); |
| 613 |
|
| 614 |
check(SV("*aßc*"), SV("{:*^5}"), std::string_view("aßc")); |
| 615 |
check(SV("*aß*"), SV("{:*^4.2}"), std::string_view("aßc")); |
| 616 |
} |
| 617 |
# ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 618 |
else { |
| 619 |
const wchar_t* c_string = L"aßc"; |
| 620 |
check(SV("*aßc*"), SV("{:*^5}"), c_string); |
| 621 |
check(SV("*aß*"), SV("{:*^4.2}"), c_string); |
| 622 |
|
| 623 |
check(SV("*aßc*"), SV("{:*^5}"), const_cast<wchar_t*>(c_string)); |
| 624 |
check(SV("*aß*"), SV("{:*^4.2}"), const_cast<wchar_t*>(c_string)); |
| 625 |
|
| 626 |
check(SV("*aßc*"), SV("{:*^5}"), L"aßc"); |
| 627 |
check(SV("*aß*"), SV("{:*^4.2}"), L"aßc"); |
| 628 |
|
| 629 |
check(SV("*aßc*"), SV("{:*^5}"), std::wstring(L"aßc")); |
| 630 |
check(SV("*aß*"), SV("{:*^4.2}"), std::wstring(L"aßc")); |
| 631 |
|
| 632 |
check(SV("*aßc*"), SV("{:*^5}"), std::wstring_view(L"aßc")); |
| 633 |
check(SV("*aß*"), SV("{:*^4.2}"), std::wstring_view(L"aßc")); |
| 634 |
} |
| 635 |
# endif // TEST_HAS_NO_WIDE_CHARACTERS |
| 636 |
|
| 637 |
// ß requires one column |
| 638 |
check(SV("aßc"), SV("{}"), STR("aßc")); |
| 639 |
|
| 640 |
check(SV("aßc"), SV("{:.3}"), STR("aßc")); |
| 641 |
check(SV("aß"), SV("{:.2}"), STR("aßc")); |
| 642 |
check(SV("a"), SV("{:.1}"), STR("aßc")); |
| 643 |
|
| 644 |
check(SV("aßc"), SV("{:3.3}"), STR("aßc")); |
| 645 |
check(SV("aß"), SV("{:2.2}"), STR("aßc")); |
| 646 |
check(SV("a"), SV("{:1.1}"), STR("aßc")); |
| 647 |
|
| 648 |
check(SV("aßc---"), SV("{:-<6}"), STR("aßc")); |
| 649 |
check(SV("-aßc--"), SV("{:-^6}"), STR("aßc")); |
| 650 |
check(SV("---aßc"), SV("{:->6}"), STR("aßc")); |
| 651 |
|
| 652 |
// \u1000 requires two columns |
| 653 |
check(SV("a\u1110c"), SV("{}"), STR("a\u1110c")); |
| 654 |
|
| 655 |
check(SV("a\u1100c"), SV("{:.4}"), STR("a\u1100c")); |
| 656 |
check(SV("a\u1100"), SV("{:.3}"), STR("a\u1100c")); |
| 657 |
check(SV("a"), SV("{:.2}"), STR("a\u1100c")); |
| 658 |
check(SV("a"), SV("{:.1}"), STR("a\u1100c")); |
| 659 |
|
| 660 |
check(SV("a\u1100c"), SV("{:-<4.4}"), STR("a\u1100c")); |
| 661 |
check(SV("a\u1100"), SV("{:-<3.3}"), STR("a\u1100c")); |
| 662 |
check(SV("a-"), SV("{:-<2.2}"), STR("a\u1100c")); |
| 663 |
check(SV("a"), SV("{:-<1.1}"), STR("a\u1100c")); |
| 664 |
|
| 665 |
check(SV("a\u1110c---"), SV("{:-<7}"), STR("a\u1110c")); |
| 666 |
check(SV("-a\u1110c--"), SV("{:-^7}"), STR("a\u1110c")); |
| 667 |
check(SV("---a\u1110c"), SV("{:->7}"), STR("a\u1110c")); |
| 668 |
|
| 669 |
// Examples used in P1868R2 |
| 670 |
check(SV("*\u0041*"), SV("{:*^3}"), STR("\u0041")); // { LATIN CAPITAL LETTER A } |
| 671 |
check(SV("*\u00c1*"), SV("{:*^3}"), STR("\u00c1")); // { LATIN CAPITAL LETTER A WITH ACUTE } |
| 672 |
check(SV("*\u0041\u0301*"), |
| 673 |
SV("{:*^3}"), |
| 674 |
STR("\u0041\u0301")); // { LATIN CAPITAL LETTER A } { COMBINING ACUTE ACCENT } |
| 675 |
check(SV("*\u0132*"), SV("{:*^3}"), STR("\u0132")); // { LATIN CAPITAL LIGATURE IJ } |
| 676 |
check(SV("*\u0394*"), SV("{:*^3}"), STR("\u0394")); // { GREEK CAPITAL LETTER DELTA } |
| 677 |
|
| 678 |
check(SV("*\u0429*"), SV("{:*^3}"), STR("\u0429")); // { CYRILLIC CAPITAL LETTER SHCHA } |
| 679 |
check(SV("*\u05d0*"), SV("{:*^3}"), STR("\u05d0")); // { HEBREW LETTER ALEF } |
| 680 |
check(SV("*\u0634*"), SV("{:*^3}"), STR("\u0634")); // { ARABIC LETTER SHEEN } |
| 681 |
check(SV("*\u3009*"), SV("{:*^4}"), STR("\u3009")); // { RIGHT-POINTING ANGLE BRACKET } |
| 682 |
check(SV("*\u754c*"), SV("{:*^4}"), STR("\u754c")); // { CJK Unified Ideograph-754C } |
| 683 |
check(SV("*\U0001f921*"), SV("{:*^4}"), STR("\U0001f921")); // { UNICORN FACE } |
| 684 |
check(SV("*\U0001f468\u200d\U0001F469\u200d\U0001F467\u200d\U0001F466*"), |
| 685 |
SV("{:*^4}"), |
| 686 |
STR("\U0001f468\u200d\U0001F469\u200d\U0001F467\u200d\U0001F466")); // { Family: Man, Woman, Girl, Boy } |
| 687 |
#endif // TEST_HAS_NO_UNICODE |
| 688 |
} |
| 689 |
|
| 690 |
template <class CharT, class TestFunction, class ExceptionTest> |
| 691 |
void format_string_tests(TestFunction check, ExceptionTest check_exception) { |
| 692 |
std::basic_string<CharT> world = STR("world"); |
| 693 |
std::basic_string<CharT> universe = STR("universe"); |
| 694 |
|
| 695 |
// Test a string literal in a way it won't decay to a pointer. |
| 696 |
if constexpr (std::same_as<CharT, char>) |
| 697 |
format_test_string<CharT>("world", "universe", check, check_exception); |
| 698 |
#ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 699 |
else |
| 700 |
format_test_string<CharT>(L"world", L"universe", check, check_exception); |
| 701 |
#endif |
| 702 |
|
| 703 |
format_test_string<CharT>(world.c_str(), universe.c_str(), check, check_exception); |
| 704 |
format_test_string<CharT>(const_cast<CharT*>(world.c_str()), const_cast<CharT*>(universe.c_str()), check, |
| 705 |
check_exception); |
| 706 |
format_test_string<CharT>(std::basic_string_view<CharT>(world), std::basic_string_view<CharT>(universe), check, |
| 707 |
check_exception); |
| 708 |
format_test_string<CharT>(world, universe, check, check_exception); |
| 709 |
format_test_string_unicode<CharT>(check); |
| 710 |
} |
| 711 |
|
| 712 |
template <class CharT, class TestFunction, class ExceptionTest> |
| 713 |
void format_test_bool(TestFunction check, ExceptionTest check_exception) { |
| 714 |
|
| 715 |
// *** align-fill & width *** |
| 716 |
check(SV("answer is 'true '"), SV("answer is '{:7}'"), true); |
| 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 |
|
| 721 |
check(SV("answer is 'false '"), SV("answer is '{:8s}'"), false); |
| 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 |
|
| 726 |
// The fill character ':' is allowed here (P0645) but not in ranges (P2286). |
| 727 |
check(SV("answer is ':::true'"), SV("answer is '{::>7}'"), true); |
| 728 |
check(SV("answer is 'true:::'"), SV("answer is '{::<7}'"), true); |
| 729 |
check(SV("answer is ':true::'"), SV("answer is '{::^7}'"), true); |
| 730 |
|
| 731 |
check(SV("answer is '---false'"), SV("answer is '{:->8s}'"), false); |
| 732 |
check(SV("answer is 'false---'"), SV("answer is '{:-<8s}'"), false); |
| 733 |
check(SV("answer is '-false--'"), SV("answer is '{:-^8s}'"), false); |
| 734 |
|
| 735 |
// *** Sign *** |
| 736 |
check_exception("The format specifier for a bool does not allow the sign option", SV("{:-}"), true); |
| 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 |
|
| 740 |
check_exception("The format specifier for a bool does not allow the sign option", SV("{:-s}"), true); |
| 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 |
|
| 744 |
// *** alternate form *** |
| 745 |
check_exception("The format specifier for a bool does not allow the alternate form option", SV("{:#}"), true); |
| 746 |
check_exception("The format specifier for a bool does not allow the alternate form option", SV("{:#s}"), true); |
| 747 |
|
| 748 |
// *** zero-padding *** |
| 749 |
check_exception("The format specifier for a bool does not allow the zero-padding option", SV("{:0}"), true); |
| 750 |
check_exception("The format specifier for a bool does not allow the zero-padding option", SV("{:0s}"), true); |
| 751 |
|
| 752 |
// *** precision *** |
| 753 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.}"), true); |
| 754 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.0}"), true); |
| 755 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.42}"), true); |
| 756 |
|
| 757 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.s}"), true); |
| 758 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.0s}"), true); |
| 759 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.42s}"), true); |
| 760 |
|
| 761 |
// *** locale-specific form *** |
| 762 |
// See locale-specific_form.pass.cpp |
| 763 |
|
| 764 |
// *** type *** |
| 765 |
for (const auto& fmt : invalid_types<CharT>("bBdosxX")) |
| 766 |
check_exception("The type option contains an invalid value for a bool formatting argument", fmt, true); |
| 767 |
} |
| 768 |
|
| 769 |
template <class CharT, class TestFunction, class ExceptionTest> |
| 770 |
void format_test_bool_as_integer(TestFunction check, ExceptionTest check_exception) { |
| 771 |
// *** align-fill & width *** |
| 772 |
check(SV("answer is '1'"), SV("answer is '{:<1d}'"), true); |
| 773 |
check(SV("answer is '1 '"), SV("answer is '{:<2d}'"), true); |
| 774 |
check(SV("answer is '0 '"), SV("answer is '{:<2d}'"), false); |
| 775 |
|
| 776 |
check(SV("answer is ' 1'"), SV("answer is '{:6d}'"), true); |
| 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 |
|
| 781 |
// The fill character ':' is allowed here (P0645) but not in ranges (P2286). |
| 782 |
check(SV("answer is ':::::0'"), SV("answer is '{::>6d}'"), false); |
| 783 |
check(SV("answer is '0:::::'"), SV("answer is '{::<6d}'"), false); |
| 784 |
check(SV("answer is '::0:::'"), SV("answer is '{::^6d}'"), false); |
| 785 |
|
| 786 |
// Test whether zero padding is ignored |
| 787 |
check(SV("answer is ' 1'"), SV("answer is '{:>06d}'"), true); |
| 788 |
check(SV("answer is '1 '"), SV("answer is '{:<06d}'"), true); |
| 789 |
check(SV("answer is ' 1 '"), SV("answer is '{:^06d}'"), true); |
| 790 |
|
| 791 |
// *** Sign *** |
| 792 |
check(SV("answer is 1"), SV("answer is {:d}"), true); |
| 793 |
check(SV("answer is 0"), SV("answer is {:-d}"), false); |
| 794 |
check(SV("answer is +1"), SV("answer is {:+d}"), true); |
| 795 |
check(SV("answer is 0"), SV("answer is {: d}"), false); |
| 796 |
|
| 797 |
// *** alternate form *** |
| 798 |
check(SV("answer is +1"), SV("answer is {:+#d}"), true); |
| 799 |
check(SV("answer is +1"), SV("answer is {:+b}"), true); |
| 800 |
check(SV("answer is +0b1"), SV("answer is {:+#b}"), true); |
| 801 |
check(SV("answer is +0B1"), SV("answer is {:+#B}"), true); |
| 802 |
check(SV("answer is +1"), SV("answer is {:+o}"), true); |
| 803 |
check(SV("answer is +01"), SV("answer is {:+#o}"), true); |
| 804 |
check(SV("answer is +1"), SV("answer is {:+x}"), true); |
| 805 |
check(SV("answer is +0x1"), SV("answer is {:+#x}"), true); |
| 806 |
check(SV("answer is +1"), SV("answer is {:+X}"), true); |
| 807 |
check(SV("answer is +0X1"), SV("answer is {:+#X}"), true); |
| 808 |
|
| 809 |
check(SV("answer is 0"), SV("answer is {:#d}"), false); |
| 810 |
check(SV("answer is 0"), SV("answer is {:b}"), false); |
| 811 |
check(SV("answer is 0b0"), SV("answer is {:#b}"), false); |
| 812 |
check(SV("answer is 0B0"), SV("answer is {:#B}"), false); |
| 813 |
check(SV("answer is 0"), SV("answer is {:o}"), false); |
| 814 |
check(SV("answer is 0"), SV("answer is {:#o}"), false); |
| 815 |
check(SV("answer is 0"), SV("answer is {:x}"), false); |
| 816 |
check(SV("answer is 0x0"), SV("answer is {:#x}"), false); |
| 817 |
check(SV("answer is 0"), SV("answer is {:X}"), false); |
| 818 |
check(SV("answer is 0X0"), SV("answer is {:#X}"), false); |
| 819 |
|
| 820 |
// *** zero-padding & width *** |
| 821 |
check(SV("answer is +00000000001"), SV("answer is {:+#012d}"), true); |
| 822 |
check(SV("answer is +00000000001"), SV("answer is {:+012b}"), true); |
| 823 |
check(SV("answer is +0b000000001"), SV("answer is {:+#012b}"), true); |
| 824 |
check(SV("answer is +0B000000001"), SV("answer is {:+#012B}"), true); |
| 825 |
check(SV("answer is +00000000001"), SV("answer is {:+012o}"), true); |
| 826 |
check(SV("answer is +00000000001"), SV("answer is {:+#012o}"), true); |
| 827 |
check(SV("answer is +00000000001"), SV("answer is {:+012x}"), true); |
| 828 |
check(SV("answer is +0x000000001"), SV("answer is {:+#012x}"), true); |
| 829 |
check(SV("answer is +00000000001"), SV("answer is {:+012X}"), true); |
| 830 |
check(SV("answer is +0X000000001"), SV("answer is {:+#012X}"), true); |
| 831 |
|
| 832 |
check(SV("answer is 000000000000"), SV("answer is {:#012d}"), false); |
| 833 |
check(SV("answer is 000000000000"), SV("answer is {:012b}"), false); |
| 834 |
check(SV("answer is 0b0000000000"), SV("answer is {:#012b}"), false); |
| 835 |
check(SV("answer is 0B0000000000"), SV("answer is {:#012B}"), false); |
| 836 |
check(SV("answer is 000000000000"), SV("answer is {:012o}"), false); |
| 837 |
check(SV("answer is 000000000000"), SV("answer is {:#012o}"), false); |
| 838 |
check(SV("answer is 000000000000"), SV("answer is {:012x}"), false); |
| 839 |
check(SV("answer is 0x0000000000"), SV("answer is {:#012x}"), false); |
| 840 |
check(SV("answer is 000000000000"), SV("answer is {:012X}"), false); |
| 841 |
check(SV("answer is 0X0000000000"), SV("answer is {:#012X}"), false); |
| 842 |
|
| 843 |
// *** precision *** |
| 844 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.}"), true); |
| 845 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.0}"), true); |
| 846 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.42}"), true); |
| 847 |
|
| 848 |
// *** locale-specific form *** |
| 849 |
// See locale-specific_form.pass.cpp |
| 850 |
|
| 851 |
// *** type *** |
| 852 |
for (const auto& fmt : invalid_types<CharT>("bBcdosxX")) |
| 853 |
check_exception("The type option contains an invalid value for a bool formatting argument", fmt, true); |
| 854 |
} |
| 855 |
|
| 856 |
template <class I, class CharT, class TestFunction, class ExceptionTest> |
| 857 |
void format_test_integer_as_integer(TestFunction check, ExceptionTest check_exception) { |
| 858 |
// *** align-fill & width *** |
| 859 |
check(SV("answer is '42'"), SV("answer is '{:<1}'"), I(42)); |
| 860 |
check(SV("answer is '42'"), SV("answer is '{:<2}'"), I(42)); |
| 861 |
check(SV("answer is '42 '"), SV("answer is '{:<3}'"), I(42)); |
| 862 |
|
| 863 |
check(SV("answer is ' 42'"), SV("answer is '{:7}'"), I(42)); |
| 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 |
|
| 868 |
// The fill character ':' is allowed here (P0645) but not in ranges (P2286). |
| 869 |
check(SV("answer is ':::::42'"), SV("answer is '{::>7}'"), I(42)); |
| 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 |
|
| 873 |
// Test whether zero padding is ignored |
| 874 |
check(SV("answer is ' 42'"), SV("answer is '{:>07}'"), I(42)); |
| 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 |
|
| 878 |
// *** Sign *** |
| 879 |
if constexpr (std::signed_integral<I>) |
| 880 |
check(SV("answer is -42"), SV("answer is {}"), I(-42)); |
| 881 |
check(SV("answer is 0"), SV("answer is {}"), I(0)); |
| 882 |
check(SV("answer is 42"), SV("answer is {}"), I(42)); |
| 883 |
|
| 884 |
if constexpr (std::signed_integral<I>) |
| 885 |
check(SV("answer is -42"), SV("answer is {:-}"), I(-42)); |
| 886 |
check(SV("answer is 0"), SV("answer is {:-}"), I(0)); |
| 887 |
check(SV("answer is 42"), SV("answer is {:-}"), I(42)); |
| 888 |
|
| 889 |
if constexpr (std::signed_integral<I>) |
| 890 |
check(SV("answer is -42"), SV("answer is {:+}"), I(-42)); |
| 891 |
check(SV("answer is +0"), SV("answer is {:+}"), I(0)); |
| 892 |
check(SV("answer is +42"), SV("answer is {:+}"), I(42)); |
| 893 |
|
| 894 |
if constexpr (std::signed_integral<I>) |
| 895 |
check(SV("answer is -42"), SV("answer is {: }"), I(-42)); |
| 896 |
check(SV("answer is 0"), SV("answer is {: }"), I(0)); |
| 897 |
check(SV("answer is 42"), SV("answer is {: }"), I(42)); |
| 898 |
|
| 899 |
// *** alternate form *** |
| 900 |
if constexpr (std::signed_integral<I>) { |
| 901 |
check(SV("answer is -42"), SV("answer is {:#}"), I(-42)); |
| 902 |
check(SV("answer is -42"), SV("answer is {:#d}"), I(-42)); |
| 903 |
check(SV("answer is -101010"), SV("answer is {:b}"), I(-42)); |
| 904 |
check(SV("answer is -0b101010"), SV("answer is {:#b}"), I(-42)); |
| 905 |
check(SV("answer is -0B101010"), SV("answer is {:#B}"), I(-42)); |
| 906 |
check(SV("answer is -52"), SV("answer is {:o}"), I(-42)); |
| 907 |
check(SV("answer is -052"), SV("answer is {:#o}"), I(-42)); |
| 908 |
check(SV("answer is -2a"), SV("answer is {:x}"), I(-42)); |
| 909 |
check(SV("answer is -0x2a"), SV("answer is {:#x}"), I(-42)); |
| 910 |
check(SV("answer is -2A"), SV("answer is {:X}"), I(-42)); |
| 911 |
check(SV("answer is -0X2A"), SV("answer is {:#X}"), I(-42)); |
| 912 |
} |
| 913 |
check(SV("answer is 0"), SV("answer is {:#}"), I(0)); |
| 914 |
check(SV("answer is 0"), SV("answer is {:#d}"), I(0)); |
| 915 |
check(SV("answer is 0"), SV("answer is {:b}"), I(0)); |
| 916 |
check(SV("answer is 0b0"), SV("answer is {:#b}"), I(0)); |
| 917 |
check(SV("answer is 0B0"), SV("answer is {:#B}"), I(0)); |
| 918 |
check(SV("answer is 0"), SV("answer is {:o}"), I(0)); |
| 919 |
check(SV("answer is 0"), SV("answer is {:#o}"), I(0)); |
| 920 |
check(SV("answer is 0"), SV("answer is {:x}"), I(0)); |
| 921 |
check(SV("answer is 0x0"), SV("answer is {:#x}"), I(0)); |
| 922 |
check(SV("answer is 0"), SV("answer is {:X}"), I(0)); |
| 923 |
check(SV("answer is 0X0"), SV("answer is {:#X}"), I(0)); |
| 924 |
|
| 925 |
check(SV("answer is +42"), SV("answer is {:+#}"), I(42)); |
| 926 |
check(SV("answer is +42"), SV("answer is {:+#d}"), I(42)); |
| 927 |
check(SV("answer is +101010"), SV("answer is {:+b}"), I(42)); |
| 928 |
check(SV("answer is +0b101010"), SV("answer is {:+#b}"), I(42)); |
| 929 |
check(SV("answer is +0B101010"), SV("answer is {:+#B}"), I(42)); |
| 930 |
check(SV("answer is +52"), SV("answer is {:+o}"), I(42)); |
| 931 |
check(SV("answer is +052"), SV("answer is {:+#o}"), I(42)); |
| 932 |
check(SV("answer is +2a"), SV("answer is {:+x}"), I(42)); |
| 933 |
check(SV("answer is +0x2a"), SV("answer is {:+#x}"), I(42)); |
| 934 |
check(SV("answer is +2A"), SV("answer is {:+X}"), I(42)); |
| 935 |
check(SV("answer is +0X2A"), SV("answer is {:+#X}"), I(42)); |
| 936 |
|
| 937 |
// *** zero-padding & width *** |
| 938 |
if constexpr (std::signed_integral<I>) { |
| 939 |
check(SV("answer is -00000000042"), SV("answer is {:#012}"), I(-42)); |
| 940 |
check(SV("answer is -00000000042"), SV("answer is {:#012d}"), I(-42)); |
| 941 |
check(SV("answer is -00000101010"), SV("answer is {:012b}"), I(-42)); |
| 942 |
check(SV("answer is -0b000101010"), SV("answer is {:#012b}"), I(-42)); |
| 943 |
check(SV("answer is -0B000101010"), SV("answer is {:#012B}"), I(-42)); |
| 944 |
check(SV("answer is -00000000052"), SV("answer is {:012o}"), I(-42)); |
| 945 |
check(SV("answer is -00000000052"), SV("answer is {:#012o}"), I(-42)); |
| 946 |
check(SV("answer is -0000000002a"), SV("answer is {:012x}"), I(-42)); |
| 947 |
check(SV("answer is -0x00000002a"), SV("answer is {:#012x}"), I(-42)); |
| 948 |
check(SV("answer is -0000000002A"), SV("answer is {:012X}"), I(-42)); |
| 949 |
check(SV("answer is -0X00000002A"), SV("answer is {:#012X}"), I(-42)); |
| 950 |
} |
| 951 |
|
| 952 |
check(SV("answer is 000000000000"), SV("answer is {:#012}"), I(0)); |
| 953 |
check(SV("answer is 000000000000"), SV("answer is {:#012d}"), I(0)); |
| 954 |
check(SV("answer is 000000000000"), SV("answer is {:012b}"), I(0)); |
| 955 |
check(SV("answer is 0b0000000000"), SV("answer is {:#012b}"), I(0)); |
| 956 |
check(SV("answer is 0B0000000000"), SV("answer is {:#012B}"), I(0)); |
| 957 |
check(SV("answer is 000000000000"), SV("answer is {:012o}"), I(0)); |
| 958 |
check(SV("answer is 000000000000"), SV("answer is {:#012o}"), I(0)); |
| 959 |
check(SV("answer is 000000000000"), SV("answer is {:012x}"), I(0)); |
| 960 |
check(SV("answer is 0x0000000000"), SV("answer is {:#012x}"), I(0)); |
| 961 |
check(SV("answer is 000000000000"), SV("answer is {:012X}"), I(0)); |
| 962 |
check(SV("answer is 0X0000000000"), SV("answer is {:#012X}"), I(0)); |
| 963 |
|
| 964 |
check(SV("answer is +00000000042"), SV("answer is {:+#012}"), I(42)); |
| 965 |
check(SV("answer is +00000000042"), SV("answer is {:+#012d}"), I(42)); |
| 966 |
check(SV("answer is +00000101010"), SV("answer is {:+012b}"), I(42)); |
| 967 |
check(SV("answer is +0b000101010"), SV("answer is {:+#012b}"), I(42)); |
| 968 |
check(SV("answer is +0B000101010"), SV("answer is {:+#012B}"), I(42)); |
| 969 |
check(SV("answer is +00000000052"), SV("answer is {:+012o}"), I(42)); |
| 970 |
check(SV("answer is +00000000052"), SV("answer is {:+#012o}"), I(42)); |
| 971 |
check(SV("answer is +0000000002a"), SV("answer is {:+012x}"), I(42)); |
| 972 |
check(SV("answer is +0x00000002a"), SV("answer is {:+#012x}"), I(42)); |
| 973 |
check(SV("answer is +0000000002A"), SV("answer is {:+012X}"), I(42)); |
| 974 |
check(SV("answer is +0X00000002A"), SV("answer is {:+#012X}"), I(42)); |
| 975 |
|
| 976 |
// *** precision *** |
| 977 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.}"), I(0)); |
| 978 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.0}"), I(0)); |
| 979 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.42}"), I(0)); |
| 980 |
|
| 981 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.{}}"), I(0)); |
| 982 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.{}}"), I(0), true); |
| 983 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.{}}"), I(0), 1.0); |
| 984 |
|
| 985 |
// *** locale-specific form *** |
| 986 |
// See locale-specific_form.pass.cpp |
| 987 |
|
| 988 |
// *** type *** |
| 989 |
for (const auto& fmt : invalid_types<CharT>("bBcdoxX")) |
| 990 |
check_exception("The type option contains an invalid value for an integer formatting argument", fmt, I(0)); |
| 991 |
} |
| 992 |
|
| 993 |
template <class I, class CharT, class TestFunction, class ExceptionTest> |
| 994 |
void format_test_integer_as_char(TestFunction check, ExceptionTest check_exception) { |
| 995 |
// *** align-fill & width *** |
| 996 |
check(SV("answer is '* '"), SV("answer is '{:6c}'"), I(42)); |
| 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 |
|
| 1001 |
// The fill character ':' is allowed here (P0645) but not in ranges (P2286). |
| 1002 |
check(SV("answer is ':::::*'"), SV("answer is '{::>6c}'"), I(42)); |
| 1003 |
check(SV("answer is '*:::::'"), SV("answer is '{::<6c}'"), I(42)); |
| 1004 |
check(SV("answer is '::*:::'"), SV("answer is '{::^6c}'"), I(42)); |
| 1005 |
|
| 1006 |
// *** Sign *** |
| 1007 |
check(SV("answer is *"), SV("answer is {:c}"), I(42)); |
| 1008 |
check_exception("The format specifier for an integer does not allow the sign option", 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 |
|
| 1012 |
// *** alternate form *** |
| 1013 |
check_exception( |
| 1014 |
"The format specifier for an integer does not allow the alternate form option", SV("answer is {:#c}"), I(42)); |
| 1015 |
|
| 1016 |
// *** zero-padding & width *** |
| 1017 |
check_exception( |
| 1018 |
"The format specifier for an integer does not allow the zero-padding option", SV("answer is {:01c}"), I(42)); |
| 1019 |
|
| 1020 |
// *** precision *** |
| 1021 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.c}"), I(0)); |
| 1022 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.0c}"), I(0)); |
| 1023 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.42c}"), I(0)); |
| 1024 |
|
| 1025 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.{}c}"), I(0)); |
| 1026 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.{}c}"), I(0), true); |
| 1027 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.{}c}"), I(0), 1.0); |
| 1028 |
|
| 1029 |
// *** locale-specific form *** |
| 1030 |
// Note it has no effect but it's allowed. |
| 1031 |
check(SV("answer is '*'"), SV("answer is '{:Lc}'"), I(42)); |
| 1032 |
|
| 1033 |
// *** type *** |
| 1034 |
for (const auto& fmt : invalid_types<CharT>("bBcdoxX")) |
| 1035 |
check_exception("The type option contains an invalid value for an integer formatting argument", fmt, I(42)); |
| 1036 |
|
| 1037 |
// *** Validate range *** |
| 1038 |
// The code has some duplications to keep the if statement readable. |
| 1039 |
if constexpr (std::signed_integral<CharT>) { |
| 1040 |
if constexpr (std::signed_integral<I> && sizeof(I) > sizeof(CharT)) { |
| 1041 |
check_exception("Integral value outside the range of the char type", SV("{:c}"), std::numeric_limits<I>::min()); |
| 1042 |
check_exception("Integral value outside the range of the char type", SV("{:c}"), std::numeric_limits<I>::max()); |
| 1043 |
} else if constexpr (std::unsigned_integral<I> && sizeof(I) >= sizeof(CharT)) { |
| 1044 |
check_exception("Integral value outside the range of the char type", SV("{:c}"), std::numeric_limits<I>::max()); |
| 1045 |
} |
| 1046 |
} else if constexpr (sizeof(I) > sizeof(CharT)) { |
| 1047 |
check_exception("Integral value outside the range of the char type", SV("{:c}"), std::numeric_limits<I>::max()); |
| 1048 |
} |
| 1049 |
} |
| 1050 |
|
| 1051 |
template <class I, class CharT, class TestFunction, class ExceptionTest> |
| 1052 |
void format_test_integer(TestFunction check, ExceptionTest check_exception) { |
| 1053 |
format_test_integer_as_integer<I, CharT>(check, check_exception); |
| 1054 |
format_test_integer_as_char<I, CharT>(check, check_exception); |
| 1055 |
} |
| 1056 |
|
| 1057 |
template <class CharT, class TestFunction, class ExceptionTest> |
| 1058 |
void format_test_signed_integer(TestFunction check, ExceptionTest check_exception) { |
| 1059 |
format_test_integer<signed char, CharT>(check, check_exception); |
| 1060 |
format_test_integer<short, CharT>(check, check_exception); |
| 1061 |
format_test_integer<int, CharT>(check, check_exception); |
| 1062 |
format_test_integer<long, CharT>(check, check_exception); |
| 1063 |
format_test_integer<long long, CharT>(check, check_exception); |
| 1064 |
#ifndef TEST_HAS_NO_INT128 |
| 1065 |
format_test_integer<__int128_t, CharT>(check, check_exception); |
| 1066 |
#endif |
| 1067 |
// *** check the minima and maxima *** |
| 1068 |
check(SV("-0b10000000"), SV("{:#b}"), std::numeric_limits<std::int8_t>::min()); |
| 1069 |
check(SV("-0200"), SV("{:#o}"), std::numeric_limits<std::int8_t>::min()); |
| 1070 |
check(SV("-128"), SV("{:#}"), std::numeric_limits<std::int8_t>::min()); |
| 1071 |
check(SV("-0x80"), SV("{:#x}"), std::numeric_limits<std::int8_t>::min()); |
| 1072 |
|
| 1073 |
check(SV("-0b1000000000000000"), SV("{:#b}"), std::numeric_limits<std::int16_t>::min()); |
| 1074 |
check(SV("-0100000"), SV("{:#o}"), std::numeric_limits<std::int16_t>::min()); |
| 1075 |
check(SV("-32768"), SV("{:#}"), std::numeric_limits<std::int16_t>::min()); |
| 1076 |
check(SV("-0x8000"), SV("{:#x}"), std::numeric_limits<std::int16_t>::min()); |
| 1077 |
|
| 1078 |
check(SV("-0b10000000000000000000000000000000"), SV("{:#b}"), std::numeric_limits<std::int32_t>::min()); |
| 1079 |
check(SV("-020000000000"), SV("{:#o}"), std::numeric_limits<std::int32_t>::min()); |
| 1080 |
check(SV("-2147483648"), SV("{:#}"), std::numeric_limits<std::int32_t>::min()); |
| 1081 |
check(SV("-0x80000000"), SV("{:#x}"), std::numeric_limits<std::int32_t>::min()); |
| 1082 |
|
| 1083 |
check(SV("-0b1000000000000000000000000000000000000000000000000000000000000000"), |
| 1084 |
SV("{:#b}"), |
| 1085 |
std::numeric_limits<std::int64_t>::min()); |
| 1086 |
check(SV("-01000000000000000000000"), SV("{:#o}"), std::numeric_limits<std::int64_t>::min()); |
| 1087 |
check(SV("-9223372036854775808"), SV("{:#}"), std::numeric_limits<std::int64_t>::min()); |
| 1088 |
check(SV("-0x8000000000000000"), SV("{:#x}"), std::numeric_limits<std::int64_t>::min()); |
| 1089 |
|
| 1090 |
#ifndef TEST_HAS_NO_INT128 |
| 1091 |
check(SV("-0b1000000000000000000000000000000000000000000000000000000000000000" |
| 1092 |
"0000000000000000000000000000000000000000000000000000000000000000"), |
| 1093 |
SV("{:#b}"), |
| 1094 |
std::numeric_limits<__int128_t>::min()); |
| 1095 |
check(SV("-02000000000000000000000000000000000000000000"), SV("{:#o}"), std::numeric_limits<__int128_t>::min()); |
| 1096 |
check(SV("-170141183460469231731687303715884105728"), SV("{:#}"), std::numeric_limits<__int128_t>::min()); |
| 1097 |
check(SV("-0x80000000000000000000000000000000"), SV("{:#x}"), std::numeric_limits<__int128_t>::min()); |
| 1098 |
#endif |
| 1099 |
|
| 1100 |
check(SV("0b1111111"), SV("{:#b}"), std::numeric_limits<std::int8_t>::max()); |
| 1101 |
check(SV("0177"), SV("{:#o}"), std::numeric_limits<std::int8_t>::max()); |
| 1102 |
check(SV("127"), SV("{:#}"), std::numeric_limits<std::int8_t>::max()); |
| 1103 |
check(SV("0x7f"), SV("{:#x}"), std::numeric_limits<std::int8_t>::max()); |
| 1104 |
|
| 1105 |
check(SV("0b111111111111111"), SV("{:#b}"), std::numeric_limits<std::int16_t>::max()); |
| 1106 |
check(SV("077777"), SV("{:#o}"), std::numeric_limits<std::int16_t>::max()); |
| 1107 |
check(SV("32767"), SV("{:#}"), std::numeric_limits<std::int16_t>::max()); |
| 1108 |
check(SV("0x7fff"), SV("{:#x}"), std::numeric_limits<std::int16_t>::max()); |
| 1109 |
|
| 1110 |
check(SV("0b1111111111111111111111111111111"), SV("{:#b}"), std::numeric_limits<std::int32_t>::max()); |
| 1111 |
check(SV("017777777777"), SV("{:#o}"), std::numeric_limits<std::int32_t>::max()); |
| 1112 |
check(SV("2147483647"), SV("{:#}"), std::numeric_limits<std::int32_t>::max()); |
| 1113 |
check(SV("0x7fffffff"), SV("{:#x}"), std::numeric_limits<std::int32_t>::max()); |
| 1114 |
|
| 1115 |
check(SV("0b111111111111111111111111111111111111111111111111111111111111111"), |
| 1116 |
SV("{:#b}"), |
| 1117 |
std::numeric_limits<std::int64_t>::max()); |
| 1118 |
check(SV("0777777777777777777777"), SV("{:#o}"), std::numeric_limits<std::int64_t>::max()); |
| 1119 |
check(SV("9223372036854775807"), SV("{:#}"), std::numeric_limits<std::int64_t>::max()); |
| 1120 |
check(SV("0x7fffffffffffffff"), SV("{:#x}"), std::numeric_limits<std::int64_t>::max()); |
| 1121 |
|
| 1122 |
#ifndef TEST_HAS_NO_INT128 |
| 1123 |
check(SV("0b111111111111111111111111111111111111111111111111111111111111111" |
| 1124 |
"1111111111111111111111111111111111111111111111111111111111111111"), |
| 1125 |
SV("{:#b}"), |
| 1126 |
std::numeric_limits<__int128_t>::max()); |
| 1127 |
check(SV("01777777777777777777777777777777777777777777"), SV("{:#o}"), std::numeric_limits<__int128_t>::max()); |
| 1128 |
check(SV("170141183460469231731687303715884105727"), SV("{:#}"), std::numeric_limits<__int128_t>::max()); |
| 1129 |
check(SV("0x7fffffffffffffffffffffffffffffff"), SV("{:#x}"), std::numeric_limits<__int128_t>::max()); |
| 1130 |
#endif |
| 1131 |
} |
| 1132 |
|
| 1133 |
template <class CharT, class TestFunction, class ExceptionTest> |
| 1134 |
void format_test_unsigned_integer(TestFunction check, ExceptionTest check_exception) { |
| 1135 |
format_test_integer<unsigned char, CharT>(check, check_exception); |
| 1136 |
format_test_integer<unsigned short, CharT>(check, check_exception); |
| 1137 |
format_test_integer<unsigned, CharT>(check, check_exception); |
| 1138 |
format_test_integer<unsigned long, CharT>(check, check_exception); |
| 1139 |
format_test_integer<unsigned long long, CharT>(check, check_exception); |
| 1140 |
#ifndef TEST_HAS_NO_INT128 |
| 1141 |
format_test_integer<__uint128_t, CharT>(check, check_exception); |
| 1142 |
#endif |
| 1143 |
// *** test the maxima *** |
| 1144 |
check(SV("0b11111111"), SV("{:#b}"), std::numeric_limits<std::uint8_t>::max()); |
| 1145 |
check(SV("0377"), SV("{:#o}"), std::numeric_limits<std::uint8_t>::max()); |
| 1146 |
check(SV("255"), SV("{:#}"), std::numeric_limits<std::uint8_t>::max()); |
| 1147 |
check(SV("0xff"), SV("{:#x}"), std::numeric_limits<std::uint8_t>::max()); |
| 1148 |
|
| 1149 |
check(SV("0b1111111111111111"), SV("{:#b}"), std::numeric_limits<std::uint16_t>::max()); |
| 1150 |
check(SV("0177777"), SV("{:#o}"), std::numeric_limits<std::uint16_t>::max()); |
| 1151 |
check(SV("65535"), SV("{:#}"), std::numeric_limits<std::uint16_t>::max()); |
| 1152 |
check(SV("0xffff"), SV("{:#x}"), std::numeric_limits<std::uint16_t>::max()); |
| 1153 |
|
| 1154 |
check(SV("0b11111111111111111111111111111111"), SV("{:#b}"), std::numeric_limits<std::uint32_t>::max()); |
| 1155 |
check(SV("037777777777"), SV("{:#o}"), std::numeric_limits<std::uint32_t>::max()); |
| 1156 |
check(SV("4294967295"), SV("{:#}"), std::numeric_limits<std::uint32_t>::max()); |
| 1157 |
check(SV("0xffffffff"), SV("{:#x}"), std::numeric_limits<std::uint32_t>::max()); |
| 1158 |
|
| 1159 |
check(SV("0b1111111111111111111111111111111111111111111111111111111111111111"), |
| 1160 |
SV("{:#b}"), |
| 1161 |
std::numeric_limits<std::uint64_t>::max()); |
| 1162 |
check(SV("01777777777777777777777"), SV("{:#o}"), std::numeric_limits<std::uint64_t>::max()); |
| 1163 |
check(SV("18446744073709551615"), SV("{:#}"), std::numeric_limits<std::uint64_t>::max()); |
| 1164 |
check(SV("0xffffffffffffffff"), SV("{:#x}"), std::numeric_limits<std::uint64_t>::max()); |
| 1165 |
|
| 1166 |
#ifndef TEST_HAS_NO_INT128 |
| 1167 |
check(SV("0b1111111111111111111111111111111111111111111111111111111111111111" |
| 1168 |
"1111111111111111111111111111111111111111111111111111111111111111"), |
| 1169 |
SV("{:#b}"), |
| 1170 |
std::numeric_limits<__uint128_t>::max()); |
| 1171 |
check(SV("03777777777777777777777777777777777777777777"), SV("{:#o}"), std::numeric_limits<__uint128_t>::max()); |
| 1172 |
check(SV("340282366920938463463374607431768211455"), SV("{:#}"), std::numeric_limits<__uint128_t>::max()); |
| 1173 |
check(SV("0xffffffffffffffffffffffffffffffff"), SV("{:#x}"), std::numeric_limits<__uint128_t>::max()); |
| 1174 |
#endif |
| 1175 |
} |
| 1176 |
|
| 1177 |
template <class CharT, class TestFunction, class ExceptionTest> |
| 1178 |
void format_test_char(TestFunction check, ExceptionTest check_exception) { |
| 1179 |
|
| 1180 |
// ***** Char type ***** |
| 1181 |
// *** align-fill & width *** |
| 1182 |
check(SV("answer is '* '"), SV("answer is '{:6}'"), CharT('*')); |
| 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 |
|
| 1187 |
check(SV("answer is '* '"), SV("answer is '{:6c}'"), CharT('*')); |
| 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 |
|
| 1192 |
// The fill character ':' is allowed here (P0645) but not in ranges (P2286). |
| 1193 |
check(SV("answer is ':::::*'"), SV("answer is '{::>6}'"), CharT('*')); |
| 1194 |
check(SV("answer is '*:::::'"), SV("answer is '{::<6}'"), CharT('*')); |
| 1195 |
check(SV("answer is '::*:::'"), SV("answer is '{::^6}'"), CharT('*')); |
| 1196 |
|
| 1197 |
check(SV("answer is '-----*'"), SV("answer is '{:->6c}'"), CharT('*')); |
| 1198 |
check(SV("answer is '*-----'"), SV("answer is '{:-<6c}'"), CharT('*')); |
| 1199 |
check(SV("answer is '--*---'"), SV("answer is '{:-^6c}'"), CharT('*')); |
| 1200 |
|
| 1201 |
// *** Sign *** |
| 1202 |
check_exception("The format specifier for a character does not allow the sign option", SV("{:-}"), CharT('*')); |
| 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 |
|
| 1206 |
check_exception("The format specifier for a character does not allow the sign option", SV("{:-c}"), CharT('*')); |
| 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 |
|
| 1210 |
// *** alternate form *** |
| 1211 |
check_exception( |
| 1212 |
"The format specifier for a character does not allow the alternate form option", SV("{:#}"), CharT('*')); |
| 1213 |
check_exception( |
| 1214 |
"The format specifier for a character does not allow the alternate form option", SV("{:#c}"), CharT('*')); |
| 1215 |
|
| 1216 |
// *** zero-padding *** |
| 1217 |
check_exception( |
| 1218 |
"The format specifier for a character does not allow the zero-padding option", SV("{:0}"), CharT('*')); |
| 1219 |
check_exception( |
| 1220 |
"The format specifier for a character does not allow the zero-padding option", SV("{:0c}"), CharT('*')); |
| 1221 |
|
| 1222 |
// *** precision *** |
| 1223 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.}"), CharT('*')); |
| 1224 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.0}"), CharT('*')); |
| 1225 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.42}"), CharT('*')); |
| 1226 |
|
| 1227 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.c}"), CharT('*')); |
| 1228 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.0c}"), CharT('*')); |
| 1229 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.42c}"), CharT('*')); |
| 1230 |
|
| 1231 |
// *** locale-specific form *** |
| 1232 |
// Note it has no effect but it's allowed. |
| 1233 |
check(SV("answer is '*'"), SV("answer is '{:L}'"), '*'); |
| 1234 |
check(SV("answer is '*'"), SV("answer is '{:Lc}'"), '*'); |
| 1235 |
|
| 1236 |
// *** type *** |
| 1237 |
#if TEST_STD_VER > 20 |
| 1238 |
const char* valid_types = "bBcdoxX?"; |
| 1239 |
#else |
| 1240 |
const char* valid_types = "bBcdoxX"; |
| 1241 |
#endif |
| 1242 |
for (const auto& fmt : invalid_types<CharT>(valid_types)) |
| 1243 |
check_exception("The type option contains an invalid value for a character formatting argument", fmt, CharT('*')); |
| 1244 |
} |
| 1245 |
|
| 1246 |
template <class CharT, class TestFunction, class ExceptionTest> |
| 1247 |
void format_test_char_as_integer(TestFunction check, ExceptionTest check_exception) { |
| 1248 |
// *** align-fill & width *** |
| 1249 |
check(SV("answer is '42'"), SV("answer is '{:<1d}'"), CharT('*')); |
| 1250 |
|
| 1251 |
check(SV("answer is '42'"), SV("answer is '{:<2d}'"), CharT('*')); |
| 1252 |
check(SV("answer is '42 '"), SV("answer is '{:<3d}'"), CharT('*')); |
| 1253 |
|
| 1254 |
check(SV("answer is ' 42'"), SV("answer is '{:7d}'"), CharT('*')); |
| 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 |
|
| 1259 |
// The fill character ':' is allowed here (P0645) but not in ranges (P2286). |
| 1260 |
check(SV("answer is ':::::42'"), SV("answer is '{::>7d}'"), CharT('*')); |
| 1261 |
check(SV("answer is '42:::::'"), SV("answer is '{::<7d}'"), CharT('*')); |
| 1262 |
check(SV("answer is '::42:::'"), SV("answer is '{::^7d}'"), CharT('*')); |
| 1263 |
|
| 1264 |
// Test whether zero padding is ignored |
| 1265 |
check(SV("answer is ' 42'"), SV("answer is '{:>07d}'"), CharT('*')); |
| 1266 |
check(SV("answer is '42 '"), SV("answer is '{:<07d}'"), CharT('*')); |
| 1267 |
check(SV("answer is ' 42 '"), SV("answer is '{:^07d}'"), CharT('*')); |
| 1268 |
|
| 1269 |
// *** Sign *** |
| 1270 |
check(SV("answer is 42"), SV("answer is {:d}"), CharT('*')); |
| 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 |
|
| 1275 |
// *** alternate form *** |
| 1276 |
check(SV("answer is +42"), SV("answer is {:+#d}"), CharT('*')); |
| 1277 |
check(SV("answer is +101010"), SV("answer is {:+b}"), CharT('*')); |
| 1278 |
check(SV("answer is +0b101010"), SV("answer is {:+#b}"), CharT('*')); |
| 1279 |
check(SV("answer is +0B101010"), SV("answer is {:+#B}"), CharT('*')); |
| 1280 |
check(SV("answer is +52"), SV("answer is {:+o}"), CharT('*')); |
| 1281 |
check(SV("answer is +052"), SV("answer is {:+#o}"), CharT('*')); |
| 1282 |
check(SV("answer is +2a"), SV("answer is {:+x}"), CharT('*')); |
| 1283 |
check(SV("answer is +0x2a"), SV("answer is {:+#x}"), CharT('*')); |
| 1284 |
check(SV("answer is +2A"), SV("answer is {:+X}"), CharT('*')); |
| 1285 |
check(SV("answer is +0X2A"), SV("answer is {:+#X}"), CharT('*')); |
| 1286 |
|
| 1287 |
// *** zero-padding & width *** |
| 1288 |
check(SV("answer is +00000000042"), SV("answer is {:+#012d}"), CharT('*')); |
| 1289 |
check(SV("answer is +00000101010"), SV("answer is {:+012b}"), CharT('*')); |
| 1290 |
check(SV("answer is +0b000101010"), SV("answer is {:+#012b}"), CharT('*')); |
| 1291 |
check(SV("answer is +0B000101010"), SV("answer is {:+#012B}"), CharT('*')); |
| 1292 |
check(SV("answer is +00000000052"), SV("answer is {:+012o}"), CharT('*')); |
| 1293 |
check(SV("answer is +00000000052"), SV("answer is {:+#012o}"), CharT('*')); |
| 1294 |
check(SV("answer is +0000000002a"), SV("answer is {:+012x}"), CharT('*')); |
| 1295 |
check(SV("answer is +0x00000002a"), SV("answer is {:+#012x}"), CharT('*')); |
| 1296 |
check(SV("answer is +0000000002A"), SV("answer is {:+012X}"), CharT('*')); |
| 1297 |
|
| 1298 |
check(SV("answer is +0X00000002A"), SV("answer is {:+#012X}"), CharT('*')); |
| 1299 |
|
| 1300 |
// *** precision *** |
| 1301 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.d}"), CharT('*')); |
| 1302 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.0d}"), CharT('*')); |
| 1303 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.42d}"), CharT('*')); |
| 1304 |
|
| 1305 |
// *** locale-specific form *** |
| 1306 |
// See locale-specific_form.pass.cpp |
| 1307 |
|
| 1308 |
// *** type *** |
| 1309 |
#if TEST_STD_VER > 20 |
| 1310 |
const char* valid_types = "bBcdoxX?"; |
| 1311 |
#else |
| 1312 |
const char* valid_types = "bBcdoxX"; |
| 1313 |
#endif |
| 1314 |
for (const auto& fmt : invalid_types<CharT>(valid_types)) |
| 1315 |
check_exception("The type option contains an invalid value for a character formatting argument", fmt, CharT('*')); |
| 1316 |
} |
| 1317 |
|
| 1318 |
template <class F, class CharT, class TestFunction> |
| 1319 |
void format_test_floating_point_hex_lower_case(TestFunction check) { |
| 1320 |
auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" |
| 1321 |
auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" |
| 1322 |
|
| 1323 |
// Test whether the hexadecimal letters are the proper case. |
| 1324 |
// The precision is too large for float, so two tests are used. |
| 1325 |
check(SV("answer is '1.abcp+0'"), SV("answer is '{:a}'"), F(0x1.abcp+0)); |
| 1326 |
check(SV("answer is '1.defp+0'"), SV("answer is '{:a}'"), F(0x1.defp+0)); |
| 1327 |
|
| 1328 |
// *** align-fill & width *** |
| 1329 |
check(SV("answer is ' 1p-2'"), SV("answer is '{:7a}'"), F(0.25)); |
| 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 |
|
| 1334 |
// The fill character ':' is allowed here (P0645) but not in ranges (P2286). |
| 1335 |
check(SV("answer is ':::1p-3'"), SV("answer is '{::>7a}'"), F(125e-3)); |
| 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 |
|
| 1339 |
check(SV("answer is '***inf'"), SV("answer is '{:*>6a}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1343 |
check(SV("answer is '###-inf'"), SV("answer is '{:#>7a}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1347 |
check(SV("answer is '^^^nan'"), SV("answer is '{:^>6a}'"), nan_pos); |
| 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 |
|
| 1351 |
check(SV("answer is '000-nan'"), SV("answer is '{:0>7a}'"), nan_neg); |
| 1352 |
check(SV("answer is '-nan000'"), SV("answer is '{:0<7a}'"), nan_neg); |
| 1353 |
check(SV("answer is '0-nan00'"), SV("answer is '{:0^7a}'"), nan_neg); |
| 1354 |
|
| 1355 |
// Test whether zero padding is ignored |
| 1356 |
check(SV("answer is ' 1p-2'"), SV("answer is '{:>07a}'"), F(0.25)); |
| 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 |
|
| 1360 |
// *** Sign *** |
| 1361 |
check(SV("answer is '0p+0'"), SV("answer is '{:a}'"), F(0)); |
| 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 |
|
| 1366 |
check(SV("answer is '-0p+0'"), SV("answer is '{:a}'"), F(-0.)); |
| 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 |
|
| 1371 |
// [format.string.std]/5 The sign option applies to floating-point infinity and NaN. |
| 1372 |
check(SV("answer is 'inf'"), SV("answer is '{:a}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1377 |
check(SV("answer is '-inf'"), SV("answer is '{:a}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1382 |
check(SV("answer is 'nan'"), SV("answer is '{:a}'"), nan_pos); |
| 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 |
|
| 1387 |
check(SV("answer is '-nan'"), SV("answer is '{:a}'"), nan_neg); |
| 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 |
|
| 1392 |
// *** alternate form *** |
| 1393 |
// When precision is zero there's no decimal point except when the alternate form is specified. |
| 1394 |
check(SV("answer is '0p+0'"), SV("answer is '{:a}'"), F(0)); |
| 1395 |
check(SV("answer is '0.p+0'"), SV("answer is '{:#a}'"), F(0)); |
| 1396 |
|
| 1397 |
check(SV("answer is '1p+1'"), SV("answer is '{:.0a}'"), F(2.5)); |
| 1398 |
check(SV("answer is '1.p+1'"), SV("answer is '{:#.0a}'"), F(2.5)); |
| 1399 |
check(SV("answer is '1.4p+1'"), SV("answer is '{:#a}'"), F(2.5)); |
| 1400 |
|
| 1401 |
check(SV("answer is 'inf'"), SV("answer is '{:#a}'"), std::numeric_limits<F>::infinity()); |
| 1402 |
check(SV("answer is '-inf'"), SV("answer is '{:#a}'"), -std::numeric_limits<F>::infinity()); |
| 1403 |
|
| 1404 |
check(SV("answer is 'nan'"), SV("answer is '{:#a}'"), nan_pos); |
| 1405 |
check(SV("answer is '-nan'"), SV("answer is '{:#a}'"), nan_neg); |
| 1406 |
|
| 1407 |
// *** zero-padding & width *** |
| 1408 |
check(SV("answer is '1p-5'"), SV("answer is '{:04a}'"), 0.03125); |
| 1409 |
check(SV("answer is '+1p-5'"), SV("answer is '{:+05a}'"), 0.03125); |
| 1410 |
check(SV("answer is '+01p-5'"), SV("answer is '{:+06a}'"), 0.03125); |
| 1411 |
|
| 1412 |
check(SV("answer is '0001p-5'"), SV("answer is '{:07a}'"), 0.03125); |
| 1413 |
check(SV("answer is '0001p-5'"), SV("answer is '{:-07a}'"), 0.03125); |
| 1414 |
check(SV("answer is '+001p-5'"), SV("answer is '{:+07a}'"), 0.03125); |
| 1415 |
check(SV("answer is ' 001p-5'"), SV("answer is '{: 07a}'"), 0.03125); |
| 1416 |
|
| 1417 |
check(SV("answer is ' inf'"), SV("answer is '{:010a}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1422 |
check(SV("answer is ' -inf'"), SV("answer is '{:010a}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1427 |
check(SV("answer is ' nan'"), SV("answer is '{:010a}'"), nan_pos); |
| 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 |
|
| 1432 |
check(SV("answer is ' -nan'"), SV("answer is '{:010a}'"), nan_neg); |
| 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 |
|
| 1437 |
// *** precision *** |
| 1438 |
// See format_test_floating_point_hex_lower_case_precision |
| 1439 |
|
| 1440 |
// *** locale-specific form *** |
| 1441 |
// See locale-specific_form.pass.cpp |
| 1442 |
} |
| 1443 |
|
| 1444 |
template <class F, class CharT, class TestFunction> |
| 1445 |
void format_test_floating_point_hex_upper_case(TestFunction check) { |
| 1446 |
auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" |
| 1447 |
auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" |
| 1448 |
|
| 1449 |
// Test whether the hexadecimal letters are the proper case. |
| 1450 |
// The precision is too large for float, so two tests are used. |
| 1451 |
check(SV("answer is '1.ABCP+0'"), SV("answer is '{:A}'"), F(0x1.abcp+0)); |
| 1452 |
check(SV("answer is '1.DEFP+0'"), SV("answer is '{:A}'"), F(0x1.defp+0)); |
| 1453 |
|
| 1454 |
// *** align-fill & width *** |
| 1455 |
check(SV("answer is ' 1P-2'"), SV("answer is '{:7A}'"), F(0.25)); |
| 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 |
|
| 1460 |
check(SV("answer is '---1P-3'"), SV("answer is '{:->7A}'"), F(125e-3)); |
| 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 |
|
| 1464 |
check(SV("answer is '***INF'"), SV("answer is '{:*>6A}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1468 |
check(SV("answer is '###-INF'"), SV("answer is '{:#>7A}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1472 |
check(SV("answer is '^^^NAN'"), SV("answer is '{:^>6A}'"), nan_pos); |
| 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 |
|
| 1476 |
check(SV("answer is '000-NAN'"), SV("answer is '{:0>7A}'"), nan_neg); |
| 1477 |
check(SV("answer is '-NAN000'"), SV("answer is '{:0<7A}'"), nan_neg); |
| 1478 |
check(SV("answer is '0-NAN00'"), SV("answer is '{:0^7A}'"), nan_neg); |
| 1479 |
|
| 1480 |
// Test whether zero padding is ignored |
| 1481 |
check(SV("answer is ' 1P-2'"), SV("answer is '{:>07A}'"), F(0.25)); |
| 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 |
|
| 1485 |
// *** Sign *** |
| 1486 |
check(SV("answer is '0P+0'"), SV("answer is '{:A}'"), F(0)); |
| 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 |
|
| 1491 |
check(SV("answer is '-0P+0'"), SV("answer is '{:A}'"), F(-0.)); |
| 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 |
|
| 1496 |
// [format.string.std]/5 The sign option applies to floating-point infinity and NaN. |
| 1497 |
check(SV("answer is 'INF'"), SV("answer is '{:A}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1502 |
check(SV("answer is '-INF'"), SV("answer is '{:A}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1507 |
check(SV("answer is 'NAN'"), SV("answer is '{:A}'"), nan_pos); |
| 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 |
|
| 1512 |
check(SV("answer is '-NAN'"), SV("answer is '{:A}'"), nan_neg); |
| 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 |
|
| 1517 |
// *** alternate form *** |
| 1518 |
// When precision is zero there's no decimal point except when the alternate form is specified. |
| 1519 |
check(SV("answer is '0P+0'"), SV("answer is '{:A}'"), F(0)); |
| 1520 |
check(SV("answer is '0.P+0'"), SV("answer is '{:#A}'"), F(0)); |
| 1521 |
|
| 1522 |
check(SV("answer is '1P+1'"), SV("answer is '{:.0A}'"), F(2.5)); |
| 1523 |
check(SV("answer is '1.P+1'"), SV("answer is '{:#.0A}'"), F(2.5)); |
| 1524 |
check(SV("answer is '1.4P+1'"), SV("answer is '{:#A}'"), F(2.5)); |
| 1525 |
|
| 1526 |
check(SV("answer is 'INF'"), SV("answer is '{:#A}'"), std::numeric_limits<F>::infinity()); |
| 1527 |
check(SV("answer is '-INF'"), SV("answer is '{:#A}'"), -std::numeric_limits<F>::infinity()); |
| 1528 |
|
| 1529 |
check(SV("answer is 'NAN'"), SV("answer is '{:#A}'"), nan_pos); |
| 1530 |
check(SV("answer is '-NAN'"), SV("answer is '{:#A}'"), nan_neg); |
| 1531 |
|
| 1532 |
// *** zero-padding & width *** |
| 1533 |
check(SV("answer is '1P-5'"), SV("answer is '{:04A}'"), 0.03125); |
| 1534 |
check(SV("answer is '+1P-5'"), SV("answer is '{:+05A}'"), 0.03125); |
| 1535 |
check(SV("answer is '+01P-5'"), SV("answer is '{:+06A}'"), 0.03125); |
| 1536 |
|
| 1537 |
check(SV("answer is '0001P-5'"), SV("answer is '{:07A}'"), 0.03125); |
| 1538 |
check(SV("answer is '0001P-5'"), SV("answer is '{:-07A}'"), 0.03125); |
| 1539 |
check(SV("answer is '+001P-5'"), SV("answer is '{:+07A}'"), 0.03125); |
| 1540 |
check(SV("answer is ' 001P-5'"), SV("answer is '{: 07A}'"), 0.03125); |
| 1541 |
|
| 1542 |
check(SV("answer is ' INF'"), SV("answer is '{:010A}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1547 |
check(SV("answer is ' -INF'"), SV("answer is '{:010A}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1552 |
check(SV("answer is ' NAN'"), SV("answer is '{:010A}'"), nan_pos); |
| 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 |
|
| 1557 |
check(SV("answer is ' -NAN'"), SV("answer is '{:010A}'"), nan_neg); |
| 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 |
|
| 1562 |
// *** precision *** |
| 1563 |
// See format_test_floating_point_hex_upper_case_precision |
| 1564 |
|
| 1565 |
// *** locale-specific form *** |
| 1566 |
// See locale-specific_form.pass.cpp |
| 1567 |
} |
| 1568 |
|
| 1569 |
template <class F, class CharT, class TestFunction> |
| 1570 |
void format_test_floating_point_hex_lower_case_precision(TestFunction check) { |
| 1571 |
auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" |
| 1572 |
auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" |
| 1573 |
|
| 1574 |
// *** align-fill & width *** |
| 1575 |
check(SV("answer is ' 1.000000p-2'"), SV("answer is '{:14.6a}'"), F(0.25)); |
| 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 |
|
| 1580 |
check(SV("answer is '---1.000000p-3'"), SV("answer is '{:->14.6a}'"), F(125e-3)); |
| 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 |
|
| 1584 |
check(SV("answer is '***inf'"), SV("answer is '{:*>6.6a}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1588 |
check(SV("answer is '###-inf'"), SV("answer is '{:#>7.6a}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1592 |
check(SV("answer is '^^^nan'"), SV("answer is '{:^>6.6a}'"), nan_pos); |
| 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 |
|
| 1596 |
check(SV("answer is '000-nan'"), SV("answer is '{:0>7.6a}'"), nan_neg); |
| 1597 |
check(SV("answer is '-nan000'"), SV("answer is '{:0<7.6a}'"), nan_neg); |
| 1598 |
check(SV("answer is '0-nan00'"), SV("answer is '{:0^7.6a}'"), nan_neg); |
| 1599 |
|
| 1600 |
// Test whether zero padding is ignored |
| 1601 |
check(SV("answer is ' 1.000000p-2'"), SV("answer is '{:>014.6a}'"), F(0.25)); |
| 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 |
|
| 1605 |
// *** Sign *** |
| 1606 |
check(SV("answer is '0.000000p+0'"), SV("answer is '{:.6a}'"), F(0)); |
| 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 |
|
| 1611 |
check(SV("answer is '-0.000000p+0'"), SV("answer is '{:.6a}'"), F(-0.)); |
| 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 |
|
| 1616 |
// [format.string.std]/5 The sign option applies to floating-point infinity and NaN. |
| 1617 |
check(SV("answer is 'inf'"), SV("answer is '{:.6a}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1622 |
check(SV("answer is '-inf'"), SV("answer is '{:.6a}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1627 |
check(SV("answer is 'nan'"), SV("answer is '{:.6a}'"), nan_pos); |
| 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 |
|
| 1632 |
check(SV("answer is '-nan'"), SV("answer is '{:.6a}'"), nan_neg); |
| 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 |
|
| 1637 |
// *** alternate form *** |
| 1638 |
check(SV("answer is '1.400000p+1'"), SV("answer is '{:#.6a}'"), F(2.5)); |
| 1639 |
|
| 1640 |
check(SV("answer is 'inf'"), SV("answer is '{:#.6a}'"), std::numeric_limits<F>::infinity()); |
| 1641 |
check(SV("answer is '-inf'"), SV("answer is '{:#.6a}'"), -std::numeric_limits<F>::infinity()); |
| 1642 |
|
| 1643 |
check(SV("answer is 'nan'"), SV("answer is '{:#.6a}'"), nan_pos); |
| 1644 |
check(SV("answer is '-nan'"), SV("answer is '{:#.6a}'"), nan_neg); |
| 1645 |
|
| 1646 |
// *** zero-padding & width *** |
| 1647 |
check(SV("answer is '1.000000p-5'"), SV("answer is '{:011.6a}'"), 0.03125); |
| 1648 |
check(SV("answer is '+1.000000p-5'"), SV("answer is '{:+012.6a}'"), 0.03125); |
| 1649 |
check(SV("answer is '+01.000000p-5'"), SV("answer is '{:+013.6a}'"), 0.03125); |
| 1650 |
|
| 1651 |
check(SV("answer is '0001.000000p-5'"), SV("answer is '{:014.6a}'"), 0.03125); |
| 1652 |
check(SV("answer is '0001.000000p-5'"), SV("answer is '{:-014.6a}'"), 0.03125); |
| 1653 |
check(SV("answer is '+001.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 |
|
| 1656 |
check(SV("answer is ' inf'"), SV("answer is '{:010.6a}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1661 |
check(SV("answer is ' -inf'"), SV("answer is '{:010.6a}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1666 |
check(SV("answer is ' nan'"), SV("answer is '{:010.6a}'"), nan_pos); |
| 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 |
|
| 1671 |
check(SV("answer is ' -nan'"), SV("answer is '{:010.6a}'"), nan_neg); |
| 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 |
|
| 1676 |
// *** locale-specific form *** |
| 1677 |
// See locale-specific_form.pass.cpp |
| 1678 |
} |
| 1679 |
|
| 1680 |
template <class F, class CharT, class TestFunction> |
| 1681 |
void format_test_floating_point_hex_upper_case_precision(TestFunction check) { |
| 1682 |
auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" |
| 1683 |
auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" |
| 1684 |
|
| 1685 |
// *** align-fill & width *** |
| 1686 |
check(SV("answer is ' 1.000000P-2'"), SV("answer is '{:14.6A}'"), F(0.25)); |
| 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 |
|
| 1691 |
check(SV("answer is '---1.000000P-3'"), SV("answer is '{:->14.6A}'"), F(125e-3)); |
| 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 |
|
| 1695 |
check(SV("answer is '***INF'"), SV("answer is '{:*>6.6A}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1699 |
check(SV("answer is '###-INF'"), SV("answer is '{:#>7.6A}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1703 |
check(SV("answer is '^^^NAN'"), SV("answer is '{:^>6.6A}'"), nan_pos); |
| 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 |
|
| 1707 |
check(SV("answer is '000-NAN'"), SV("answer is '{:0>7.6A}'"), nan_neg); |
| 1708 |
check(SV("answer is '-NAN000'"), SV("answer is '{:0<7.6A}'"), nan_neg); |
| 1709 |
check(SV("answer is '0-NAN00'"), SV("answer is '{:0^7.6A}'"), nan_neg); |
| 1710 |
|
| 1711 |
// Test whether zero padding is ignored |
| 1712 |
check(SV("answer is ' 1.000000P-2'"), SV("answer is '{:>014.6A}'"), F(0.25)); |
| 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 |
|
| 1716 |
// *** Sign *** |
| 1717 |
check(SV("answer is '0.000000P+0'"), SV("answer is '{:.6A}'"), F(0)); |
| 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 |
|
| 1722 |
check(SV("answer is '-0.000000P+0'"), SV("answer is '{:.6A}'"), F(-0.)); |
| 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 |
|
| 1727 |
// [format.string.std]/5 The sign option applies to floating-point infinity and NaN. |
| 1728 |
check(SV("answer is 'INF'"), SV("answer is '{:.6A}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1733 |
check(SV("answer is '-INF'"), SV("answer is '{:.6A}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1738 |
check(SV("answer is 'NAN'"), SV("answer is '{:.6A}'"), nan_pos); |
| 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 |
|
| 1743 |
check(SV("answer is '-NAN'"), SV("answer is '{:.6A}'"), nan_neg); |
| 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 |
|
| 1748 |
// *** alternate form *** |
| 1749 |
check(SV("answer is '1.400000P+1'"), SV("answer is '{:#.6A}'"), F(2.5)); |
| 1750 |
|
| 1751 |
check(SV("answer is 'INF'"), SV("answer is '{:#.6A}'"), std::numeric_limits<F>::infinity()); |
| 1752 |
check(SV("answer is '-INF'"), SV("answer is '{:#.6A}'"), -std::numeric_limits<F>::infinity()); |
| 1753 |
|
| 1754 |
check(SV("answer is 'NAN'"), SV("answer is '{:#.6A}'"), nan_pos); |
| 1755 |
check(SV("answer is '-NAN'"), SV("answer is '{:#.6A}'"), nan_neg); |
| 1756 |
|
| 1757 |
// *** zero-padding & width *** |
| 1758 |
check(SV("answer is '1.000000P-5'"), SV("answer is '{:011.6A}'"), 0.03125); |
| 1759 |
check(SV("answer is '+1.000000P-5'"), SV("answer is '{:+012.6A}'"), 0.03125); |
| 1760 |
check(SV("answer is '+01.000000P-5'"), SV("answer is '{:+013.6A}'"), 0.03125); |
| 1761 |
|
| 1762 |
check(SV("answer is '0001.000000P-5'"), SV("answer is '{:014.6A}'"), 0.03125); |
| 1763 |
check(SV("answer is '0001.000000P-5'"), SV("answer is '{:-014.6A}'"), 0.03125); |
| 1764 |
check(SV("answer is '+001.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 |
|
| 1767 |
check(SV("answer is ' INF'"), SV("answer is '{:010.6A}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1772 |
check(SV("answer is ' -INF'"), SV("answer is '{:010.6A}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1777 |
check(SV("answer is ' NAN'"), SV("answer is '{:010.6A}'"), nan_pos); |
| 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 |
|
| 1782 |
check(SV("answer is ' -NAN'"), SV("answer is '{:010.6A}'"), nan_neg); |
| 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 |
|
| 1787 |
// *** locale-specific form *** |
| 1788 |
// See locale-specific_form.pass.cpp |
| 1789 |
} |
| 1790 |
|
| 1791 |
template <class F, class CharT, class TestFunction> |
| 1792 |
void format_test_floating_point_scientific_lower_case(TestFunction check) { |
| 1793 |
auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" |
| 1794 |
auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" |
| 1795 |
|
| 1796 |
// *** align-fill & width *** |
| 1797 |
check(SV("answer is ' 2.500000e-01'"), SV("answer is '{:15e}'"), F(0.25)); |
| 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 |
|
| 1802 |
check(SV("answer is '---1.250000e-01'"), SV("answer is '{:->15e}'"), F(125e-3)); |
| 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 |
|
| 1806 |
check(SV("answer is '***inf'"), SV("answer is '{:*>6e}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1810 |
check(SV("answer is '###-inf'"), SV("answer is '{:#>7e}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1814 |
check(SV("answer is '^^^nan'"), SV("answer is '{:^>6e}'"), nan_pos); |
| 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 |
|
| 1818 |
check(SV("answer is '000-nan'"), SV("answer is '{:0>7e}'"), nan_neg); |
| 1819 |
check(SV("answer is '-nan000'"), SV("answer is '{:0<7e}'"), nan_neg); |
| 1820 |
check(SV("answer is '0-nan00'"), SV("answer is '{:0^7e}'"), nan_neg); |
| 1821 |
|
| 1822 |
// Test whether zero padding is ignored |
| 1823 |
check(SV("answer is ' 2.500000e-01'"), SV("answer is '{:>015e}'"), F(0.25)); |
| 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 |
|
| 1827 |
// *** Sign *** |
| 1828 |
check(SV("answer is '0.000000e+00'"), SV("answer is '{:e}'"), F(0)); |
| 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 |
|
| 1833 |
check(SV("answer is '-0.000000e+00'"), SV("answer is '{:e}'"), F(-0.)); |
| 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 |
|
| 1838 |
// [format.string.std]/5 The sign option applies to floating-point infinity and NaN. |
| 1839 |
check(SV("answer is 'inf'"), SV("answer is '{:e}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1844 |
check(SV("answer is '-inf'"), SV("answer is '{:e}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1849 |
check(SV("answer is 'nan'"), SV("answer is '{:e}'"), nan_pos); |
| 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 |
|
| 1854 |
check(SV("answer is '-nan'"), SV("answer is '{:e}'"), nan_neg); |
| 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 |
|
| 1859 |
// *** alternate form ** |
| 1860 |
// When precision is zero there's no decimal point except when the alternate form is specified. |
| 1861 |
check(SV("answer is '0e+00'"), SV("answer is '{:.0e}'"), F(0)); |
| 1862 |
check(SV("answer is '0.e+00'"), SV("answer is '{:#.0e}'"), F(0)); |
| 1863 |
|
| 1864 |
check(SV("answer is '0.000000e+00'"), SV("answer is '{:#e}'"), F(0)); |
| 1865 |
check(SV("answer is '2.500000e+00'"), SV("answer is '{:#e}'"), F(2.5)); |
| 1866 |
|
| 1867 |
check(SV("answer is 'inf'"), SV("answer is '{:#e}'"), std::numeric_limits<F>::infinity()); |
| 1868 |
check(SV("answer is '-inf'"), SV("answer is '{:#e}'"), -std::numeric_limits<F>::infinity()); |
| 1869 |
|
| 1870 |
check(SV("answer is 'nan'"), SV("answer is '{:#e}'"), nan_pos); |
| 1871 |
check(SV("answer is '-nan'"), SV("answer is '{:#e}'"), nan_neg); |
| 1872 |
|
| 1873 |
// *** zero-padding & width *** |
| 1874 |
check(SV("answer is '3.125000e-02'"), SV("answer is '{:07e}'"), 0.03125); |
| 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 '{:+08e}'"), 0.03125); |
| 1877 |
check(SV("answer is '+3.125000e-02'"), SV("answer is '{:+09e}'"), 0.03125); |
| 1878 |
|
| 1879 |
check(SV("answer is '003.125000e-02'"), SV("answer is '{:014e}'"), 0.03125); |
| 1880 |
check(SV("answer is '003.125000e-02'"), SV("answer is '{:-014e}'"), 0.03125); |
| 1881 |
check(SV("answer is '+03.125000e-02'"), SV("answer is '{:+014e}'"), 0.03125); |
| 1882 |
check(SV("answer is ' 03.125000e-02'"), SV("answer is '{: 014e}'"), 0.03125); |
| 1883 |
|
| 1884 |
check(SV("answer is ' inf'"), SV("answer is '{:010e}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1889 |
check(SV("answer is ' -inf'"), SV("answer is '{:010e}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1894 |
check(SV("answer is ' nan'"), SV("answer is '{:010e}'"), nan_pos); |
| 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 |
|
| 1899 |
check(SV("answer is ' -nan'"), SV("answer is '{:010e}'"), nan_neg); |
| 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 |
|
| 1904 |
// *** precision *** |
| 1905 |
check(SV("answer is '3e-02'"), SV("answer is '{:.0e}'"), 0.03125); |
| 1906 |
check(SV("answer is '3.1e-02'"), SV("answer is '{:.1e}'"), 0.03125); |
| 1907 |
check(SV("answer is '3.125e-02'"), SV("answer is '{:.3e}'"), 0.03125); |
| 1908 |
check(SV("answer is '3.1250000000e-02'"), SV("answer is '{:.10e}'"), 0.03125); |
| 1909 |
|
| 1910 |
// *** locale-specific form *** |
| 1911 |
// See locale-specific_form.pass.cpp |
| 1912 |
} |
| 1913 |
|
| 1914 |
template <class F, class CharT, class TestFunction> |
| 1915 |
void format_test_floating_point_scientific_upper_case(TestFunction check) { |
| 1916 |
auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" |
| 1917 |
auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" |
| 1918 |
|
| 1919 |
// *** align-fill & width *** |
| 1920 |
check(SV("answer is ' 2.500000E-01'"), SV("answer is '{:15E}'"), F(0.25)); |
| 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 |
|
| 1925 |
check(SV("answer is '---1.250000E-01'"), SV("answer is '{:->15E}'"), F(125e-3)); |
| 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 |
|
| 1929 |
check(SV("answer is '***INF'"), SV("answer is '{:*>6E}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1933 |
check(SV("answer is '###-INF'"), SV("answer is '{:#>7E}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1937 |
check(SV("answer is '^^^NAN'"), SV("answer is '{:^>6E}'"), nan_pos); |
| 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 |
|
| 1941 |
check(SV("answer is '000-NAN'"), SV("answer is '{:0>7E}'"), nan_neg); |
| 1942 |
check(SV("answer is '-NAN000'"), SV("answer is '{:0<7E}'"), nan_neg); |
| 1943 |
check(SV("answer is '0-NAN00'"), SV("answer is '{:0^7E}'"), nan_neg); |
| 1944 |
|
| 1945 |
// Test whether zero padding is ignored |
| 1946 |
check(SV("answer is ' 2.500000E-01'"), SV("answer is '{:>015E}'"), F(0.25)); |
| 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 |
|
| 1950 |
// *** Sign *** |
| 1951 |
check(SV("answer is '0.000000E+00'"), SV("answer is '{:E}'"), F(0)); |
| 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 |
|
| 1956 |
check(SV("answer is '-0.000000E+00'"), SV("answer is '{:E}'"), F(-0.)); |
| 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 |
|
| 1961 |
// [format.string.std]/5 The sign option applies to floating-point infinity and NaN. |
| 1962 |
check(SV("answer is 'INF'"), SV("answer is '{:E}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1967 |
check(SV("answer is '-INF'"), SV("answer is '{:E}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 1972 |
check(SV("answer is 'NAN'"), SV("answer is '{:E}'"), nan_pos); |
| 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 |
|
| 1977 |
check(SV("answer is '-NAN'"), SV("answer is '{:E}'"), nan_neg); |
| 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 |
|
| 1982 |
// *** alternate form ** |
| 1983 |
// When precision is zero there's no decimal point except when the alternate form is specified. |
| 1984 |
check(SV("answer is '0E+00'"), SV("answer is '{:.0E}'"), F(0)); |
| 1985 |
check(SV("answer is '0.E+00'"), SV("answer is '{:#.0E}'"), F(0)); |
| 1986 |
|
| 1987 |
check(SV("answer is '0.000000E+00'"), SV("answer is '{:#E}'"), F(0)); |
| 1988 |
check(SV("answer is '2.500000E+00'"), SV("answer is '{:#E}'"), F(2.5)); |
| 1989 |
|
| 1990 |
check(SV("answer is 'INF'"), SV("answer is '{:#E}'"), std::numeric_limits<F>::infinity()); |
| 1991 |
check(SV("answer is '-INF'"), SV("answer is '{:#E}'"), -std::numeric_limits<F>::infinity()); |
| 1992 |
|
| 1993 |
check(SV("answer is 'NAN'"), SV("answer is '{:#E}'"), nan_pos); |
| 1994 |
check(SV("answer is '-NAN'"), SV("answer is '{:#E}'"), nan_neg); |
| 1995 |
|
| 1996 |
// *** zero-padding & width *** |
| 1997 |
check(SV("answer is '3.125000E-02'"), SV("answer is '{:07E}'"), 0.03125); |
| 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 '{:+08E}'"), 0.03125); |
| 2000 |
check(SV("answer is '+3.125000E-02'"), SV("answer is '{:+09E}'"), 0.03125); |
| 2001 |
|
| 2002 |
check(SV("answer is '003.125000E-02'"), SV("answer is '{:014E}'"), 0.03125); |
| 2003 |
check(SV("answer is '003.125000E-02'"), SV("answer is '{:-014E}'"), 0.03125); |
| 2004 |
check(SV("answer is '+03.125000E-02'"), SV("answer is '{:+014E}'"), 0.03125); |
| 2005 |
check(SV("answer is ' 03.125000E-02'"), SV("answer is '{: 014E}'"), 0.03125); |
| 2006 |
|
| 2007 |
check(SV("answer is ' INF'"), SV("answer is '{:010E}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2012 |
check(SV("answer is ' -INF'"), SV("answer is '{:010E}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2017 |
check(SV("answer is ' NAN'"), SV("answer is '{:010E}'"), nan_pos); |
| 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 |
|
| 2022 |
check(SV("answer is ' -NAN'"), SV("answer is '{:010E}'"), nan_neg); |
| 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 |
|
| 2027 |
// *** precision *** |
| 2028 |
check(SV("answer is '3E-02'"), SV("answer is '{:.0E}'"), 0.03125); |
| 2029 |
check(SV("answer is '3.1E-02'"), SV("answer is '{:.1E}'"), 0.03125); |
| 2030 |
check(SV("answer is '3.125E-02'"), SV("answer is '{:.3E}'"), 0.03125); |
| 2031 |
check(SV("answer is '3.1250000000E-02'"), SV("answer is '{:.10E}'"), 0.03125); |
| 2032 |
|
| 2033 |
// *** locale-specific form *** |
| 2034 |
// See locale-specific_form.pass.cpp |
| 2035 |
} |
| 2036 |
|
| 2037 |
template <class F, class CharT, class TestFunction> |
| 2038 |
void format_test_floating_point_fixed_lower_case(TestFunction check) { |
| 2039 |
auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" |
| 2040 |
auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" |
| 2041 |
|
| 2042 |
// *** align-fill & width *** |
| 2043 |
check(SV("answer is ' 0.250000'"), SV("answer is '{:11f}'"), F(0.25)); |
| 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 |
|
| 2048 |
check(SV("answer is '---0.125000'"), SV("answer is '{:->11f}'"), F(125e-3)); |
| 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 |
|
| 2052 |
check(SV("answer is '***inf'"), SV("answer is '{:*>6f}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2056 |
check(SV("answer is '###-inf'"), SV("answer is '{:#>7f}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2060 |
check(SV("answer is '^^^nan'"), SV("answer is '{:^>6f}'"), nan_pos); |
| 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 |
|
| 2064 |
check(SV("answer is '000-nan'"), SV("answer is '{:0>7f}'"), nan_neg); |
| 2065 |
check(SV("answer is '-nan000'"), SV("answer is '{:0<7f}'"), nan_neg); |
| 2066 |
check(SV("answer is '0-nan00'"), SV("answer is '{:0^7f}'"), nan_neg); |
| 2067 |
|
| 2068 |
// Test whether zero padding is ignored |
| 2069 |
check(SV("answer is ' 0.250000'"), SV("answer is '{:>011f}'"), F(0.25)); |
| 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 |
|
| 2073 |
// *** Sign *** |
| 2074 |
check(SV("answer is '0.000000'"), SV("answer is '{:f}'"), F(0)); |
| 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 |
|
| 2079 |
check(SV("answer is '-0.000000'"), SV("answer is '{:f}'"), F(-0.)); |
| 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 |
|
| 2084 |
// [format.string.std]/5 The sign option applies to floating-point infinity and NaN. |
| 2085 |
check(SV("answer is 'inf'"), SV("answer is '{:f}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2090 |
check(SV("answer is '-inf'"), SV("answer is '{:f}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2095 |
check(SV("answer is 'nan'"), SV("answer is '{:f}'"), nan_pos); |
| 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 |
|
| 2100 |
check(SV("answer is '-nan'"), SV("answer is '{:f}'"), nan_neg); |
| 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 |
|
| 2105 |
// *** alternate form ** |
| 2106 |
// When precision is zero there's no decimal point except when the alternate form is specified. |
| 2107 |
check(SV("answer is '0'"), SV("answer is '{:.0f}'"), F(0)); |
| 2108 |
check(SV("answer is '0.'"), SV("answer is '{:#.0f}'"), F(0)); |
| 2109 |
|
| 2110 |
check(SV("answer is '0.000000'"), SV("answer is '{:#f}'"), F(0)); |
| 2111 |
check(SV("answer is '2.500000'"), SV("answer is '{:#f}'"), F(2.5)); |
| 2112 |
|
| 2113 |
check(SV("answer is 'inf'"), SV("answer is '{:#f}'"), std::numeric_limits<F>::infinity()); |
| 2114 |
check(SV("answer is '-inf'"), SV("answer is '{:#f}'"), -std::numeric_limits<F>::infinity()); |
| 2115 |
|
| 2116 |
check(SV("answer is 'nan'"), SV("answer is '{:#f}'"), nan_pos); |
| 2117 |
check(SV("answer is '-nan'"), SV("answer is '{:#f}'"), nan_neg); |
| 2118 |
|
| 2119 |
// *** zero-padding & width *** |
| 2120 |
check(SV("answer is '0.031250'"), SV("answer is '{:07f}'"), 0.03125); |
| 2121 |
check(SV("answer is '+0.031250'"), SV("answer is '{:+07f}'"), 0.03125); |
| 2122 |
check(SV("answer is '+0.031250'"), SV("answer is '{:+08f}'"), 0.03125); |
| 2123 |
check(SV("answer is '+0.031250'"), SV("answer is '{:+09f}'"), 0.03125); |
| 2124 |
|
| 2125 |
check(SV("answer is '000.031250'"), SV("answer is '{:010f}'"), 0.03125); |
| 2126 |
check(SV("answer is '000.031250'"), SV("answer is '{:-010f}'"), 0.03125); |
| 2127 |
check(SV("answer is '+00.031250'"), SV("answer is '{:+010f}'"), 0.03125); |
| 2128 |
check(SV("answer is ' 00.031250'"), SV("answer is '{: 010f}'"), 0.03125); |
| 2129 |
|
| 2130 |
check(SV("answer is ' inf'"), SV("answer is '{:010f}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2135 |
check(SV("answer is ' -inf'"), SV("answer is '{:010f}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2140 |
check(SV("answer is ' nan'"), SV("answer is '{:010f}'"), nan_pos); |
| 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 |
|
| 2145 |
check(SV("answer is ' -nan'"), SV("answer is '{:010f}'"), nan_neg); |
| 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 |
|
| 2150 |
// *** precision *** |
| 2151 |
check(SV("answer is '0'"), SV("answer is '{:.0f}'"), 0.03125); |
| 2152 |
check(SV("answer is '0.0'"), SV("answer is '{:.1f}'"), 0.03125); |
| 2153 |
check(SV("answer is '0.03125'"), SV("answer is '{:.5f}'"), 0.03125); |
| 2154 |
check(SV("answer is '0.0312500000'"), SV("answer is '{:.10f}'"), 0.03125); |
| 2155 |
|
| 2156 |
// *** locale-specific form *** |
| 2157 |
// See locale-specific_form.pass.cpp |
| 2158 |
} |
| 2159 |
|
| 2160 |
template <class F, class CharT, class TestFunction> |
| 2161 |
void format_test_floating_point_fixed_upper_case(TestFunction check) { |
| 2162 |
auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" |
| 2163 |
auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" |
| 2164 |
|
| 2165 |
// *** align-fill & width *** |
| 2166 |
check(SV("answer is ' 0.250000'"), SV("answer is '{:11F}'"), F(0.25)); |
| 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 |
|
| 2171 |
check(SV("answer is '---0.125000'"), SV("answer is '{:->11F}'"), F(125e-3)); |
| 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 |
|
| 2175 |
check(SV("answer is '***INF'"), SV("answer is '{:*>6F}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2179 |
check(SV("answer is '###-INF'"), SV("answer is '{:#>7F}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2183 |
check(SV("answer is '^^^NAN'"), SV("answer is '{:^>6F}'"), nan_pos); |
| 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 |
|
| 2187 |
check(SV("answer is '000-NAN'"), SV("answer is '{:0>7F}'"), nan_neg); |
| 2188 |
check(SV("answer is '-NAN000'"), SV("answer is '{:0<7F}'"), nan_neg); |
| 2189 |
check(SV("answer is '0-NAN00'"), SV("answer is '{:0^7F}'"), nan_neg); |
| 2190 |
|
| 2191 |
// Test whether zero padding is ignored |
| 2192 |
check(SV("answer is ' 0.250000'"), SV("answer is '{:>011F}'"), F(0.25)); |
| 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 |
|
| 2196 |
// *** Sign *** |
| 2197 |
check(SV("answer is '0.000000'"), SV("answer is '{:F}'"), F(0)); |
| 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 |
|
| 2202 |
check(SV("answer is '-0.000000'"), SV("answer is '{:F}'"), F(-0.)); |
| 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 |
|
| 2207 |
// [format.string.std]/5 The sign option applies to floating-point infinity and NaN. |
| 2208 |
check(SV("answer is 'INF'"), SV("answer is '{:F}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2213 |
check(SV("answer is '-INF'"), SV("answer is '{:F}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2218 |
check(SV("answer is 'NAN'"), SV("answer is '{:F}'"), nan_pos); |
| 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 |
|
| 2223 |
check(SV("answer is '-NAN'"), SV("answer is '{:F}'"), nan_neg); |
| 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 |
|
| 2228 |
// *** alternate form ** |
| 2229 |
// When precision is zero there's no decimal point except when the alternate form is specified. |
| 2230 |
check(SV("answer is '0'"), SV("answer is '{:.0F}'"), F(0)); |
| 2231 |
check(SV("answer is '0.'"), SV("answer is '{:#.0F}'"), F(0)); |
| 2232 |
|
| 2233 |
check(SV("answer is '0.000000'"), SV("answer is '{:#F}'"), F(0)); |
| 2234 |
check(SV("answer is '2.500000'"), SV("answer is '{:#F}'"), F(2.5)); |
| 2235 |
|
| 2236 |
check(SV("answer is 'INF'"), SV("answer is '{:#F}'"), std::numeric_limits<F>::infinity()); |
| 2237 |
check(SV("answer is '-INF'"), SV("answer is '{:#F}'"), -std::numeric_limits<F>::infinity()); |
| 2238 |
|
| 2239 |
check(SV("answer is 'NAN'"), SV("answer is '{:#F}'"), nan_pos); |
| 2240 |
check(SV("answer is '-NAN'"), SV("answer is '{:#F}'"), nan_neg); |
| 2241 |
|
| 2242 |
// *** zero-padding & width *** |
| 2243 |
check(SV("answer is '0.031250'"), SV("answer is '{:07F}'"), 0.03125); |
| 2244 |
check(SV("answer is '+0.031250'"), SV("answer is '{:+07F}'"), 0.03125); |
| 2245 |
check(SV("answer is '+0.031250'"), SV("answer is '{:+08F}'"), 0.03125); |
| 2246 |
check(SV("answer is '+0.031250'"), SV("answer is '{:+09F}'"), 0.03125); |
| 2247 |
|
| 2248 |
check(SV("answer is '000.031250'"), SV("answer is '{:010F}'"), 0.03125); |
| 2249 |
check(SV("answer is '000.031250'"), SV("answer is '{:-010F}'"), 0.03125); |
| 2250 |
check(SV("answer is '+00.031250'"), SV("answer is '{:+010F}'"), 0.03125); |
| 2251 |
check(SV("answer is ' 00.031250'"), SV("answer is '{: 010F}'"), 0.03125); |
| 2252 |
|
| 2253 |
check(SV("answer is ' INF'"), SV("answer is '{:010F}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2258 |
check(SV("answer is ' -INF'"), SV("answer is '{:010F}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2263 |
check(SV("answer is ' NAN'"), SV("answer is '{:010F}'"), nan_pos); |
| 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 |
|
| 2268 |
check(SV("answer is ' -NAN'"), SV("answer is '{:010F}'"), nan_neg); |
| 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 |
|
| 2273 |
// *** precision *** |
| 2274 |
check(SV("answer is '0'"), SV("answer is '{:.0F}'"), 0.03125); |
| 2275 |
check(SV("answer is '0.0'"), SV("answer is '{:.1F}'"), 0.03125); |
| 2276 |
check(SV("answer is '0.03125'"), SV("answer is '{:.5F}'"), 0.03125); |
| 2277 |
check(SV("answer is '0.0312500000'"), SV("answer is '{:.10F}'"), 0.03125); |
| 2278 |
|
| 2279 |
// *** locale-specific form *** |
| 2280 |
// See locale-specific_form.pass.cpp |
| 2281 |
} |
| 2282 |
|
| 2283 |
template <class F, class CharT, class TestFunction> |
| 2284 |
void format_test_floating_point_general_lower_case(TestFunction check) { |
| 2285 |
auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" |
| 2286 |
auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" |
| 2287 |
|
| 2288 |
// *** align-fill & width *** |
| 2289 |
check(SV("answer is ' 0.25'"), SV("answer is '{:7g}'"), F(0.25)); |
| 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 |
|
| 2294 |
check(SV("answer is '---0.125'"), SV("answer is '{:->8g}'"), F(125e-3)); |
| 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 |
|
| 2298 |
check(SV("answer is '***inf'"), SV("answer is '{:*>6g}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2302 |
check(SV("answer is '###-inf'"), SV("answer is '{:#>7g}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2306 |
check(SV("answer is '^^^nan'"), SV("answer is '{:^>6g}'"), nan_pos); |
| 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 |
|
| 2310 |
check(SV("answer is '000-nan'"), SV("answer is '{:0>7g}'"), nan_neg); |
| 2311 |
check(SV("answer is '-nan000'"), SV("answer is '{:0<7g}'"), nan_neg); |
| 2312 |
check(SV("answer is '0-nan00'"), SV("answer is '{:0^7g}'"), nan_neg); |
| 2313 |
|
| 2314 |
// Test whether zero padding is ignored |
| 2315 |
check(SV("answer is ' 0.25'"), SV("answer is '{:>07g}'"), F(0.25)); |
| 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 |
|
| 2319 |
// *** Sign *** |
| 2320 |
check(SV("answer is '0'"), SV("answer is '{:g}'"), F(0)); |
| 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 |
|
| 2325 |
check(SV("answer is '-0'"), SV("answer is '{:g}'"), F(-0.)); |
| 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 |
|
| 2330 |
// [format.string.std]/5 The sign option applies to floating-point infinity and NaN. |
| 2331 |
check(SV("answer is 'inf'"), SV("answer is '{:g}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2336 |
check(SV("answer is '-inf'"), SV("answer is '{:g}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2341 |
check(SV("answer is 'nan'"), SV("answer is '{:g}'"), nan_pos); |
| 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 |
|
| 2346 |
check(SV("answer is '-nan'"), SV("answer is '{:g}'"), nan_neg); |
| 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 |
|
| 2351 |
// *** alternate form ** |
| 2352 |
// When precision is zero there's no decimal point except when the alternate form is specified. |
| 2353 |
check(SV("answer is '0'"), SV("answer is '{:.0g}'"), F(0)); |
| 2354 |
check(SV("answer is '0.'"), SV("answer is '{:#.0g}'"), F(0)); |
| 2355 |
|
| 2356 |
check(SV("answer is '0.00000'"), SV("answer is '{:#g}'"), F(0)); |
| 2357 |
check(SV("answer is '2.50000'"), SV("answer is '{:#g}'"), F(2.5)); |
| 2358 |
|
| 2359 |
check(SV("answer is 'inf'"), SV("answer is '{:#g}'"), std::numeric_limits<F>::infinity()); |
| 2360 |
check(SV("answer is '-inf'"), SV("answer is '{:#g}'"), -std::numeric_limits<F>::infinity()); |
| 2361 |
|
| 2362 |
check(SV("answer is 'nan'"), SV("answer is '{:#g}'"), nan_pos); |
| 2363 |
check(SV("answer is '-nan'"), SV("answer is '{:#g}'"), nan_neg); |
| 2364 |
|
| 2365 |
// *** zero-padding & width *** |
| 2366 |
check(SV("answer is '0.03125'"), SV("answer is '{:06g}'"), 0.03125); |
| 2367 |
check(SV("answer is '+0.03125'"), SV("answer is '{:+06g}'"), 0.03125); |
| 2368 |
check(SV("answer is '+0.03125'"), SV("answer is '{:+07g}'"), 0.03125); |
| 2369 |
check(SV("answer is '+0.03125'"), SV("answer is '{:+08g}'"), 0.03125); |
| 2370 |
|
| 2371 |
check(SV("answer is '000.03125'"), SV("answer is '{:09g}'"), 0.03125); |
| 2372 |
check(SV("answer is '000.03125'"), SV("answer is '{:-09g}'"), 0.03125); |
| 2373 |
check(SV("answer is '+00.03125'"), SV("answer is '{:+09g}'"), 0.03125); |
| 2374 |
check(SV("answer is ' 00.03125'"), SV("answer is '{: 09g}'"), 0.03125); |
| 2375 |
|
| 2376 |
check(SV("answer is ' inf'"), SV("answer is '{:010g}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2381 |
check(SV("answer is ' -inf'"), SV("answer is '{:010g}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2386 |
check(SV("answer is ' nan'"), SV("answer is '{:010g}'"), nan_pos); |
| 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 |
|
| 2391 |
check(SV("answer is ' -nan'"), SV("answer is '{:010g}'"), nan_neg); |
| 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 |
|
| 2396 |
// *** precision *** |
| 2397 |
check(SV("answer is '0.03'"), SV("answer is '{:.0g}'"), 0.03125); |
| 2398 |
check(SV("answer is '0.03'"), SV("answer is '{:.1g}'"), 0.03125); |
| 2399 |
check(SV("answer is '0.031'"), SV("answer is '{:.2g}'"), 0.03125); |
| 2400 |
check(SV("answer is '0.0312'"), SV("answer is '{:.3g}'"), 0.03125); |
| 2401 |
check(SV("answer is '0.03125'"), SV("answer is '{:.4g}'"), 0.03125); |
| 2402 |
check(SV("answer is '0.03125'"), SV("answer is '{:.5g}'"), 0.03125); |
| 2403 |
check(SV("answer is '0.03125'"), SV("answer is '{:.10g}'"), 0.03125); |
| 2404 |
|
| 2405 |
// *** precision & alternate form *** |
| 2406 |
|
| 2407 |
// Output validated with printf("%#xg") |
| 2408 |
check(SV("answer is '1.'"), SV("answer is '{:#.{}g}'"), 1.2, 0); |
| 2409 |
check(SV("answer is '1.'"), SV("answer is '{:#.{}g}'"), 1.2, 1); |
| 2410 |
check(SV("answer is '1.2'"), SV("answer is '{:#.{}g}'"), 1.2, 2); |
| 2411 |
check(SV("answer is '1.20'"), SV("answer is '{:#.{}g}'"), 1.2, 3); |
| 2412 |
check(SV("answer is '1.200'"), SV("answer is '{:#.{}g}'"), 1.2, 4); |
| 2413 |
check(SV("answer is '1.2000'"), SV("answer is '{:#.{}g}'"), 1.2, 5); |
| 2414 |
check(SV("answer is '1.20000'"), SV("answer is '{:#.{}g}'"), 1.2, 6); |
| 2415 |
|
| 2416 |
check(SV("answer is '1.e+03'"), SV("answer is '{:#.{}g}'"), 1200.0, 0); |
| 2417 |
check(SV("answer is '1.e+03'"), SV("answer is '{:#.{}g}'"), 1200.0, 1); |
| 2418 |
check(SV("answer is '1.2e+03'"), SV("answer is '{:#.{}g}'"), 1200.0, 2); |
| 2419 |
check(SV("answer is '1.20e+03'"), SV("answer is '{:#.{}g}'"), 1200.0, 3); |
| 2420 |
check(SV("answer is '1200.'"), SV("answer is '{:#.{}g}'"), 1200.0, 4); |
| 2421 |
check(SV("answer is '1200.0'"), SV("answer is '{:#.{}g}'"), 1200.0, 5); |
| 2422 |
check(SV("answer is '1200.00'"), SV("answer is '{:#.{}g}'"), 1200.0, 6); |
| 2423 |
|
| 2424 |
check(SV("answer is '1.e+06'"), SV("answer is '{:#.{}g}'"), 1200000.0, 0); |
| 2425 |
check(SV("answer is '1.e+06'"), SV("answer is '{:#.{}g}'"), 1200000.0, 1); |
| 2426 |
check(SV("answer is '1.2e+06'"), SV("answer is '{:#.{}g}'"), 1200000.0, 2); |
| 2427 |
check(SV("answer is '1.20e+06'"), SV("answer is '{:#.{}g}'"), 1200000.0, 3); |
| 2428 |
check(SV("answer is '1.200e+06'"), SV("answer is '{:#.{}g}'"), 1200000.0, 4); |
| 2429 |
check(SV("answer is '1.2000e+06'"), SV("answer is '{:#.{}g}'"), 1200000.0, 5); |
| 2430 |
check(SV("answer is '1.20000e+06'"), SV("answer is '{:#.{}g}'"), 1200000.0, 6); |
| 2431 |
|
| 2432 |
// *** locale-specific form *** |
| 2433 |
// See locale-specific_form.pass.cpp |
| 2434 |
} |
| 2435 |
|
| 2436 |
template <class F, class CharT, class TestFunction> |
| 2437 |
void format_test_floating_point_general_upper_case(TestFunction check) { |
| 2438 |
auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" |
| 2439 |
auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" |
| 2440 |
|
| 2441 |
// *** align-fill & width *** |
| 2442 |
check(SV("answer is ' 0.25'"), SV("answer is '{:7G}'"), F(0.25)); |
| 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 |
|
| 2447 |
check(SV("answer is '---0.125'"), SV("answer is '{:->8G}'"), F(125e-3)); |
| 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 |
|
| 2451 |
check(SV("answer is '***INF'"), SV("answer is '{:*>6G}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2455 |
check(SV("answer is '###-INF'"), SV("answer is '{:#>7G}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2459 |
check(SV("answer is '^^^NAN'"), SV("answer is '{:^>6G}'"), nan_pos); |
| 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 |
|
| 2463 |
check(SV("answer is '000-NAN'"), SV("answer is '{:0>7G}'"), nan_neg); |
| 2464 |
check(SV("answer is '-NAN000'"), SV("answer is '{:0<7G}'"), nan_neg); |
| 2465 |
check(SV("answer is '0-NAN00'"), SV("answer is '{:0^7G}'"), nan_neg); |
| 2466 |
|
| 2467 |
// Test whether zero padding is ignored |
| 2468 |
check(SV("answer is ' 0.25'"), SV("answer is '{:>07G}'"), F(0.25)); |
| 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 |
|
| 2472 |
// *** Sign *** |
| 2473 |
check(SV("answer is '0'"), SV("answer is '{:G}'"), F(0)); |
| 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 |
|
| 2478 |
check(SV("answer is '-0'"), SV("answer is '{:G}'"), F(-0.)); |
| 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 |
|
| 2483 |
// [format.string.std]/5 The sign option applies to floating-point infinity and NaN. |
| 2484 |
check(SV("answer is 'INF'"), SV("answer is '{:G}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2489 |
check(SV("answer is '-INF'"), SV("answer is '{:G}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2494 |
check(SV("answer is 'NAN'"), SV("answer is '{:G}'"), nan_pos); |
| 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 |
|
| 2499 |
check(SV("answer is '-NAN'"), SV("answer is '{:G}'"), nan_neg); |
| 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 |
|
| 2504 |
// *** alternate form ** |
| 2505 |
// When precision is zero there's no decimal point except when the alternate form is specified. |
| 2506 |
check(SV("answer is '0'"), SV("answer is '{:.0G}'"), F(0)); |
| 2507 |
check(SV("answer is '0.'"), SV("answer is '{:#.0G}'"), F(0)); |
| 2508 |
|
| 2509 |
check(SV("answer is '0.00000'"), SV("answer is '{:#G}'"), F(0)); |
| 2510 |
check(SV("answer is '2.50000'"), SV("answer is '{:#G}'"), F(2.5)); |
| 2511 |
|
| 2512 |
check(SV("answer is 'INF'"), SV("answer is '{:#G}'"), std::numeric_limits<F>::infinity()); |
| 2513 |
check(SV("answer is '-INF'"), SV("answer is '{:#G}'"), -std::numeric_limits<F>::infinity()); |
| 2514 |
|
| 2515 |
check(SV("answer is 'NAN'"), SV("answer is '{:#G}'"), nan_pos); |
| 2516 |
check(SV("answer is '-NAN'"), SV("answer is '{:#G}'"), nan_neg); |
| 2517 |
|
| 2518 |
// *** zero-padding & width *** |
| 2519 |
check(SV("answer is '0.03125'"), SV("answer is '{:06G}'"), 0.03125); |
| 2520 |
check(SV("answer is '+0.03125'"), SV("answer is '{:+06G}'"), 0.03125); |
| 2521 |
check(SV("answer is '+0.03125'"), SV("answer is '{:+07G}'"), 0.03125); |
| 2522 |
check(SV("answer is '+0.03125'"), SV("answer is '{:+08G}'"), 0.03125); |
| 2523 |
|
| 2524 |
check(SV("answer is '000.03125'"), SV("answer is '{:09G}'"), 0.03125); |
| 2525 |
check(SV("answer is '000.03125'"), SV("answer is '{:-09G}'"), 0.03125); |
| 2526 |
check(SV("answer is '+00.03125'"), SV("answer is '{:+09G}'"), 0.03125); |
| 2527 |
check(SV("answer is ' 00.03125'"), SV("answer is '{: 09G}'"), 0.03125); |
| 2528 |
|
| 2529 |
check(SV("answer is ' INF'"), SV("answer is '{:010G}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2534 |
check(SV("answer is ' -INF'"), SV("answer is '{:010G}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2539 |
check(SV("answer is ' NAN'"), SV("answer is '{:010G}'"), nan_pos); |
| 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 |
|
| 2544 |
check(SV("answer is ' -NAN'"), SV("answer is '{:010G}'"), nan_neg); |
| 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 |
|
| 2549 |
// *** precision *** |
| 2550 |
check(SV("answer is '0.03'"), SV("answer is '{:.0G}'"), 0.03125); |
| 2551 |
check(SV("answer is '0.03'"), SV("answer is '{:.1G}'"), 0.03125); |
| 2552 |
check(SV("answer is '0.031'"), SV("answer is '{:.2G}'"), 0.03125); |
| 2553 |
check(SV("answer is '0.0312'"), SV("answer is '{:.3G}'"), 0.03125); |
| 2554 |
check(SV("answer is '0.03125'"), SV("answer is '{:.4G}'"), 0.03125); |
| 2555 |
check(SV("answer is '0.03125'"), SV("answer is '{:.5G}'"), 0.03125); |
| 2556 |
check(SV("answer is '0.03125'"), SV("answer is '{:.10G}'"), 0.03125); |
| 2557 |
|
| 2558 |
// *** precision & alternate form *** |
| 2559 |
|
| 2560 |
// Output validated with printf("%#xg") |
| 2561 |
check(SV("answer is '1.'"), SV("answer is '{:#.{}G}'"), 1.2, 0); |
| 2562 |
check(SV("answer is '1.'"), SV("answer is '{:#.{}G}'"), 1.2, 1); |
| 2563 |
check(SV("answer is '1.2'"), SV("answer is '{:#.{}G}'"), 1.2, 2); |
| 2564 |
check(SV("answer is '1.20'"), SV("answer is '{:#.{}G}'"), 1.2, 3); |
| 2565 |
check(SV("answer is '1.200'"), SV("answer is '{:#.{}G}'"), 1.2, 4); |
| 2566 |
check(SV("answer is '1.2000'"), SV("answer is '{:#.{}G}'"), 1.2, 5); |
| 2567 |
check(SV("answer is '1.20000'"), SV("answer is '{:#.{}G}'"), 1.2, 6); |
| 2568 |
|
| 2569 |
check(SV("answer is '1.E+03'"), SV("answer is '{:#.{}G}'"), 1200.0, 0); |
| 2570 |
check(SV("answer is '1.E+03'"), SV("answer is '{:#.{}G}'"), 1200.0, 1); |
| 2571 |
check(SV("answer is '1.2E+03'"), SV("answer is '{:#.{}G}'"), 1200.0, 2); |
| 2572 |
check(SV("answer is '1.20E+03'"), SV("answer is '{:#.{}G}'"), 1200.0, 3); |
| 2573 |
check(SV("answer is '1200.'"), SV("answer is '{:#.{}G}'"), 1200.0, 4); |
| 2574 |
check(SV("answer is '1200.0'"), SV("answer is '{:#.{}G}'"), 1200.0, 5); |
| 2575 |
check(SV("answer is '1200.00'"), SV("answer is '{:#.{}G}'"), 1200.0, 6); |
| 2576 |
|
| 2577 |
check(SV("answer is '1.E+06'"), SV("answer is '{:#.{}G}'"), 1200000.0, 0); |
| 2578 |
check(SV("answer is '1.E+06'"), SV("answer is '{:#.{}G}'"), 1200000.0, 1); |
| 2579 |
check(SV("answer is '1.2E+06'"), SV("answer is '{:#.{}G}'"), 1200000.0, 2); |
| 2580 |
check(SV("answer is '1.20E+06'"), SV("answer is '{:#.{}G}'"), 1200000.0, 3); |
| 2581 |
check(SV("answer is '1.200E+06'"), SV("answer is '{:#.{}G}'"), 1200000.0, 4); |
| 2582 |
check(SV("answer is '1.2000E+06'"), SV("answer is '{:#.{}G}'"), 1200000.0, 5); |
| 2583 |
check(SV("answer is '1.20000E+06'"), SV("answer is '{:#.{}G}'"), 1200000.0, 6); |
| 2584 |
|
| 2585 |
// *** locale-specific form *** |
| 2586 |
// See locale-specific_form.pass.cpp |
| 2587 |
} |
| 2588 |
|
| 2589 |
template <class F, class CharT, class TestFunction> |
| 2590 |
void format_test_floating_point_default(TestFunction check) { |
| 2591 |
auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" |
| 2592 |
auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" |
| 2593 |
|
| 2594 |
// *** align-fill & width *** |
| 2595 |
check(SV("answer is ' 0.25'"), SV("answer is '{:7}'"), F(0.25)); |
| 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 |
|
| 2600 |
check(SV("answer is '---0.125'"), SV("answer is '{:->8}'"), F(125e-3)); |
| 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 |
|
| 2604 |
check(SV("answer is '***inf'"), SV("answer is '{:*>6}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2608 |
check(SV("answer is '###-inf'"), SV("answer is '{:#>7}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2612 |
check(SV("answer is '^^^nan'"), SV("answer is '{:^>6}'"), nan_pos); |
| 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 |
|
| 2616 |
check(SV("answer is '000-nan'"), SV("answer is '{:0>7}'"), nan_neg); |
| 2617 |
check(SV("answer is '-nan000'"), SV("answer is '{:0<7}'"), nan_neg); |
| 2618 |
check(SV("answer is '0-nan00'"), SV("answer is '{:0^7}'"), nan_neg); |
| 2619 |
|
| 2620 |
// Test whether zero padding is ignored |
| 2621 |
check(SV("answer is ' 0.25'"), SV("answer is '{:>07}'"), F(0.25)); |
| 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 |
|
| 2625 |
// *** Sign *** |
| 2626 |
check(SV("answer is '0'"), SV("answer is '{:}'"), F(0)); |
| 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 |
|
| 2631 |
check(SV("answer is '-0'"), SV("answer is '{:}'"), F(-0.)); |
| 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 |
|
| 2636 |
// [format.string.std]/5 The sign option applies to floating-point infinity and NaN. |
| 2637 |
check(SV("answer is 'inf'"), SV("answer is '{:}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2642 |
check(SV("answer is '-inf'"), SV("answer is '{:}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2647 |
check(SV("answer is 'nan'"), SV("answer is '{:}'"), nan_pos); |
| 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 |
|
| 2652 |
check(SV("answer is '-nan'"), SV("answer is '{:}'"), nan_neg); |
| 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 |
|
| 2657 |
// *** alternate form *** |
| 2658 |
check(SV("answer is '0.'"), SV("answer is '{:#}'"), F(0)); |
| 2659 |
check(SV("answer is '2.5'"), SV("answer is '{:#}'"), F(2.5)); |
| 2660 |
|
| 2661 |
check(SV("answer is 'inf'"), SV("answer is '{:#}'"), std::numeric_limits<F>::infinity()); |
| 2662 |
check(SV("answer is '-inf'"), SV("answer is '{:#}'"), -std::numeric_limits<F>::infinity()); |
| 2663 |
|
| 2664 |
check(SV("answer is 'nan'"), SV("answer is '{:#}'"), nan_pos); |
| 2665 |
check(SV("answer is '-nan'"), SV("answer is '{:#}'"), nan_neg); |
| 2666 |
|
| 2667 |
// *** zero-padding & width *** |
| 2668 |
check(SV("answer is '0.03125'"), SV("answer is '{:07}'"), 0.03125); |
| 2669 |
check(SV("answer is '+0.03125'"), SV("answer is '{:+07}'"), 0.03125); |
| 2670 |
check(SV("answer is '+0.03125'"), SV("answer is '{:+08}'"), 0.03125); |
| 2671 |
check(SV("answer is '+00.03125'"), SV("answer is '{:+09}'"), 0.03125); |
| 2672 |
|
| 2673 |
check(SV("answer is '0000.03125'"), SV("answer is '{:010}'"), 0.03125); |
| 2674 |
check(SV("answer is '0000.03125'"), SV("answer is '{:-010}'"), 0.03125); |
| 2675 |
check(SV("answer is '+000.03125'"), SV("answer is '{:+010}'"), 0.03125); |
| 2676 |
check(SV("answer is ' 000.03125'"), SV("answer is '{: 010}'"), 0.03125); |
| 2677 |
|
| 2678 |
check(SV("answer is ' inf'"), SV("answer is '{:010}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2683 |
check(SV("answer is ' -inf'"), SV("answer is '{:010}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2688 |
check(SV("answer is ' nan'"), SV("answer is '{:010}'"), nan_pos); |
| 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 |
|
| 2693 |
check(SV("answer is ' -nan'"), SV("answer is '{:010}'"), nan_neg); |
| 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 |
|
| 2698 |
// *** precision *** |
| 2699 |
// See format_test_floating_point_default_precision |
| 2700 |
|
| 2701 |
// *** locale-specific form *** |
| 2702 |
// See locale-specific_form.pass.cpp |
| 2703 |
} |
| 2704 |
|
| 2705 |
template <class F, class CharT, class TestFunction> |
| 2706 |
void format_test_floating_point_default_precision(TestFunction check) { |
| 2707 |
|
| 2708 |
auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan" |
| 2709 |
auto nan_neg = std::copysign(nan_pos, static_cast<decltype(nan_pos)>(-1.0)); // "-nan" |
| 2710 |
|
| 2711 |
// *** align-fill & width *** |
| 2712 |
check(SV("answer is ' 0.25'"), SV("answer is '{:7.6}'"), F(0.25)); |
| 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 |
|
| 2717 |
check(SV("answer is '---0.125'"), SV("answer is '{:->8.6}'"), F(125e-3)); |
| 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 |
|
| 2721 |
check(SV("answer is '***inf'"), SV("answer is '{:*>6.6}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2725 |
check(SV("answer is '###-inf'"), SV("answer is '{:#>7.6}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2729 |
check(SV("answer is '^^^nan'"), SV("answer is '{:^>6.6}'"), nan_pos); |
| 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 |
|
| 2733 |
check(SV("answer is '000-nan'"), SV("answer is '{:0>7.6}'"), nan_neg); |
| 2734 |
check(SV("answer is '-nan000'"), SV("answer is '{:0<7.6}'"), nan_neg); |
| 2735 |
check(SV("answer is '0-nan00'"), SV("answer is '{:0^7.6}'"), nan_neg); |
| 2736 |
|
| 2737 |
// Test whether zero padding is ignored |
| 2738 |
check(SV("answer is ' 0.25'"), SV("answer is '{:>07.6}'"), F(0.25)); |
| 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 |
|
| 2742 |
// *** Sign *** |
| 2743 |
check(SV("answer is '0'"), SV("answer is '{:.6}'"), F(0)); |
| 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 |
|
| 2748 |
check(SV("answer is '-0'"), SV("answer is '{:.6}'"), F(-0.)); |
| 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 |
|
| 2753 |
// [format.string.std]/5 The sign option applies to floating-point infinity and NaN. |
| 2754 |
check(SV("answer is 'inf'"), SV("answer is '{:.6}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2759 |
check(SV("answer is '-inf'"), SV("answer is '{:.6}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2764 |
check(SV("answer is 'nan'"), SV("answer is '{:.6}'"), nan_pos); |
| 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 |
|
| 2769 |
check(SV("answer is '-nan'"), SV("answer is '{:.6}'"), nan_neg); |
| 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 |
|
| 2774 |
// *** alternate form ** |
| 2775 |
// When precision is zero there's no decimal point except when the alternate form is specified. |
| 2776 |
// Note unlike the g and G option the trailing zeros are still removed. |
| 2777 |
check(SV("answer is '0'"), SV("answer is '{:.0}'"), F(0)); |
| 2778 |
check(SV("answer is '0.'"), SV("answer is '{:#.0}'"), F(0)); |
| 2779 |
|
| 2780 |
check(SV("answer is '0.'"), SV("answer is '{:#.6}'"), F(0)); |
| 2781 |
check(SV("answer is '2.5'"), SV("answer is '{:#.6}'"), F(2.5)); |
| 2782 |
|
| 2783 |
check(SV("answer is 'inf'"), SV("answer is '{:#.6}'"), std::numeric_limits<F>::infinity()); |
| 2784 |
check(SV("answer is '-inf'"), SV("answer is '{:#.6}'"), -std::numeric_limits<F>::infinity()); |
| 2785 |
|
| 2786 |
check(SV("answer is 'nan'"), SV("answer is '{:#.6}'"), nan_pos); |
| 2787 |
check(SV("answer is '-nan'"), SV("answer is '{:#.6}'"), nan_neg); |
| 2788 |
|
| 2789 |
// *** zero-padding & width *** |
| 2790 |
check(SV("answer is '0.03125'"), SV("answer is '{:06.6}'"), 0.03125); |
| 2791 |
check(SV("answer is '+0.03125'"), SV("answer is '{:+06.6}'"), 0.03125); |
| 2792 |
check(SV("answer is '+0.03125'"), SV("answer is '{:+07.6}'"), 0.03125); |
| 2793 |
check(SV("answer is '+0.03125'"), SV("answer is '{:+08.6}'"), 0.03125); |
| 2794 |
|
| 2795 |
check(SV("answer is '000.03125'"), SV("answer is '{:09.6}'"), 0.03125); |
| 2796 |
check(SV("answer is '000.03125'"), SV("answer is '{:-09.6}'"), 0.03125); |
| 2797 |
check(SV("answer is '+00.03125'"), SV("answer is '{:+09.6}'"), 0.03125); |
| 2798 |
check(SV("answer is ' 00.03125'"), SV("answer is '{: 09.6}'"), 0.03125); |
| 2799 |
|
| 2800 |
check(SV("answer is ' inf'"), SV("answer is '{:010.6}'"), std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2805 |
check(SV("answer is ' -inf'"), SV("answer is '{:010.6}'"), -std::numeric_limits<F>::infinity()); |
| 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 |
|
| 2810 |
check(SV("answer is ' nan'"), SV("answer is '{:010.6}'"), nan_pos); |
| 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 |
|
| 2815 |
check(SV("answer is ' -nan'"), SV("answer is '{:010.6}'"), nan_neg); |
| 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 |
|
| 2820 |
// *** precision *** |
| 2821 |
check(SV("answer is '0.03'"), SV("answer is '{:.0}'"), 0.03125); |
| 2822 |
check(SV("answer is '0.03'"), SV("answer is '{:.1}'"), 0.03125); |
| 2823 |
check(SV("answer is '0.031'"), SV("answer is '{:.2}'"), 0.03125); |
| 2824 |
check(SV("answer is '0.0312'"), SV("answer is '{:.3}'"), 0.03125); |
| 2825 |
check(SV("answer is '0.03125'"), SV("answer is '{:.4}'"), 0.03125); |
| 2826 |
check(SV("answer is '0.03125'"), SV("answer is '{:.5}'"), 0.03125); |
| 2827 |
check(SV("answer is '0.03125'"), SV("answer is '{:.10}'"), 0.03125); |
| 2828 |
|
| 2829 |
// *** precision & alternate form *** |
| 2830 |
|
| 2831 |
check(SV("answer is '1.'"), SV("answer is '{:#.{}}'"), 1.2, 0); |
| 2832 |
check(SV("answer is '1.'"), SV("answer is '{:#.{}}'"), 1.2, 1); |
| 2833 |
check(SV("answer is '1.2'"), SV("answer is '{:#.{}}'"), 1.2, 2); |
| 2834 |
check(SV("answer is '1.2'"), SV("answer is '{:#.{}}'"), 1.2, 3); |
| 2835 |
check(SV("answer is '1.2'"), SV("answer is '{:#.{}}'"), 1.2, 4); |
| 2836 |
check(SV("answer is '1.2'"), SV("answer is '{:#.{}}'"), 1.2, 5); |
| 2837 |
check(SV("answer is '1.2'"), SV("answer is '{:#.{}}'"), 1.2, 6); |
| 2838 |
|
| 2839 |
check(SV("answer is '1.e+03'"), SV("answer is '{:#.{}}'"), 1200.0, 0); |
| 2840 |
check(SV("answer is '1.e+03'"), SV("answer is '{:#.{}}'"), 1200.0, 1); |
| 2841 |
check(SV("answer is '1.2e+03'"), SV("answer is '{:#.{}}'"), 1200.0, 2); |
| 2842 |
check(SV("answer is '1.2e+03'"), SV("answer is '{:#.{}}'"), 1200.0, 3); |
| 2843 |
check(SV("answer is '1200.'"), SV("answer is '{:#.{}}'"), 1200.0, 4); |
| 2844 |
check(SV("answer is '1200.'"), SV("answer is '{:#.{}}'"), 1200.0, 5); |
| 2845 |
check(SV("answer is '1200.'"), SV("answer is '{:#.{}}'"), 1200.0, 6); |
| 2846 |
|
| 2847 |
check(SV("answer is '1.e+06'"), SV("answer is '{:#.{}}'"), 1200000.0, 0); |
| 2848 |
check(SV("answer is '1.e+06'"), SV("answer is '{:#.{}}'"), 1200000.0, 1); |
| 2849 |
check(SV("answer is '1.2e+06'"), SV("answer is '{:#.{}}'"), 1200000.0, 2); |
| 2850 |
check(SV("answer is '1.2e+06'"), SV("answer is '{:#.{}}'"), 1200000.0, 3); |
| 2851 |
check(SV("answer is '1.2e+06'"), SV("answer is '{:#.{}}'"), 1200000.0, 4); |
| 2852 |
check(SV("answer is '1.2e+06'"), SV("answer is '{:#.{}}'"), 1200000.0, 5); |
| 2853 |
check(SV("answer is '1.2e+06'"), SV("answer is '{:#.{}}'"), 1200000.0, 6); |
| 2854 |
|
| 2855 |
// *** locale-specific form *** |
| 2856 |
// See locale-specific_form.pass.cpp |
| 2857 |
} |
| 2858 |
|
| 2859 |
template <class F, class CharT, class TestFunction> |
| 2860 |
void format_test_floating_point_PR58714(TestFunction check) { |
| 2861 |
check(SV("+1234"), SV("{:+}"), F(1234.0)); |
| 2862 |
check(SV("+1.348p+10"), SV("{:+a}"), F(1234.0)); |
| 2863 |
check(SV("+1.234000e+03"), SV("{:+e}"), F(1234.0)); |
| 2864 |
check(SV("+1234.000000"), SV("{:+f}"), F(1234.0)); |
| 2865 |
check(SV("+1234"), SV("{:+g}"), F(1234.0)); |
| 2866 |
|
| 2867 |
check(SV("1234."), SV("{:#}"), F(1234.0)); |
| 2868 |
check(SV("1.348p+10"), SV("{:#a}"), F(1234.0)); |
| 2869 |
check(SV("1.234000e+03"), SV("{:#e}"), F(1234.0)); |
| 2870 |
check(SV("1234.000000"), SV("{:#f}"), F(1234.0)); |
| 2871 |
check(SV("1234.00"), SV("{:#g}"), F(1234.0)); |
| 2872 |
|
| 2873 |
check(SV("4.e+30"), SV("{:#}"), F(4.0e+30)); |
| 2874 |
check(SV("1.p+102"), SV("{:#a}"), F(0x4.0p+100)); |
| 2875 |
check(SV("4.000000e+30"), SV("{:#e}"), F(4.0e+30)); |
| 2876 |
check(SV("5070602400912917605986812821504.000000"), SV("{:#f}"), F(0x4.0p+100)); |
| 2877 |
check(SV("4.00000e+30"), SV("{:#g}"), F(4.0e+30)); |
| 2878 |
|
| 2879 |
check(SV("1234."), SV("{:#.6}"), F(1234.0)); // # does not restore zeros |
| 2880 |
check(SV("1.348000p+10"), SV("{:#.6a}"), F(1234.0)); |
| 2881 |
check(SV("1.234000e+03"), SV("{:#.6e}"), F(1234.0)); |
| 2882 |
check(SV("1234.000000"), SV("{:#.6f}"), F(1234.0)); |
| 2883 |
check(SV("1234.00"), SV("{:#.6g}"), F(1234.0)); |
| 2884 |
|
| 2885 |
check(SV("-1234."), SV("{:#}"), F(-1234.0)); |
| 2886 |
check(SV("-1.348p+10"), SV("{:#a}"), F(-1234.0)); |
| 2887 |
check(SV("-1.234000e+03"), SV("{:#e}"), F(-1234.0)); |
| 2888 |
check(SV("-1234.000000"), SV("{:#f}"), F(-1234.0)); |
| 2889 |
check(SV("-1234.00"), SV("{:#g}"), F(-1234.0)); |
| 2890 |
|
| 2891 |
check(SV("-1234."), SV("{:#.6}"), F(-1234.0)); // # does not restore zeros |
| 2892 |
check(SV("-1.348000p+10"), SV("{:#.6a}"), F(-1234.0)); |
| 2893 |
check(SV("-1.234000e+03"), SV("{:#.6e}"), F(-1234.0)); |
| 2894 |
check(SV("-1234.000000"), SV("{:#.6f}"), F(-1234.0)); |
| 2895 |
check(SV("-1234.00"), SV("{:#.6g}"), F(-1234.0)); |
| 2896 |
|
| 2897 |
check(SV("+1234."), SV("{:+#}"), F(1234.0)); |
| 2898 |
check(SV("+1.348p+10"), SV("{:+#a}"), F(1234.0)); |
| 2899 |
check(SV("+1.234000e+03"), SV("{:+#e}"), F(1234.0)); |
| 2900 |
check(SV("+1234.000000"), SV("{:+#f}"), F(1234.0)); |
| 2901 |
check(SV("+1234.00"), SV("{:+#g}"), F(1234.0)); |
| 2902 |
|
| 2903 |
check(SV("+1234."), SV("{:+#.6}"), F(1234.0)); // # does not restore zeros |
| 2904 |
check(SV("+1.348000p+10"), SV("{:+#.6a}"), F(1234.0)); |
| 2905 |
check(SV("+1.234000e+03"), SV("{:+#.6e}"), F(1234.0)); |
| 2906 |
check(SV("+1234.000000"), SV("{:+#.6f}"), F(1234.0)); |
| 2907 |
check(SV("+1234.00"), SV("{:+#.6g}"), F(1234.0)); |
| 2908 |
} |
| 2909 |
|
| 2910 |
template <class F, class CharT, class TestFunction, class ExceptionTest> |
| 2911 |
void format_test_floating_point(TestFunction check, ExceptionTest check_exception) { |
| 2912 |
format_test_floating_point_hex_lower_case<F, CharT>(check); |
| 2913 |
format_test_floating_point_hex_upper_case<F, CharT>(check); |
| 2914 |
format_test_floating_point_hex_lower_case_precision<F, CharT>(check); |
| 2915 |
format_test_floating_point_hex_upper_case_precision<F, CharT>(check); |
| 2916 |
|
| 2917 |
format_test_floating_point_scientific_lower_case<F, CharT>(check); |
| 2918 |
format_test_floating_point_scientific_upper_case<F, CharT>(check); |
| 2919 |
|
| 2920 |
format_test_floating_point_fixed_lower_case<F, CharT>(check); |
| 2921 |
format_test_floating_point_fixed_upper_case<F, CharT>(check); |
| 2922 |
|
| 2923 |
format_test_floating_point_general_lower_case<F, CharT>(check); |
| 2924 |
format_test_floating_point_general_upper_case<F, CharT>(check); |
| 2925 |
|
| 2926 |
format_test_floating_point_default<F, CharT>(check); |
| 2927 |
format_test_floating_point_default_precision<F, CharT>(check); |
| 2928 |
|
| 2929 |
format_test_floating_point_PR58714<F, CharT>(check); |
| 2930 |
|
| 2931 |
// *** type *** |
| 2932 |
for (const auto& fmt : invalid_types<CharT>("aAeEfFgG")) |
| 2933 |
check_exception("The type option contains an invalid value for a floating-point formatting argument", fmt, F(1)); |
| 2934 |
} |
| 2935 |
|
| 2936 |
template <class CharT, class TestFunction, class ExceptionTest> |
| 2937 |
void format_test_floating_point(TestFunction check, ExceptionTest check_exception) { |
| 2938 |
format_test_floating_point<float, CharT>(check, check_exception); |
| 2939 |
format_test_floating_point<double, CharT>(check, check_exception); |
| 2940 |
format_test_floating_point<long double, CharT>(check, check_exception); |
| 2941 |
} |
| 2942 |
|
| 2943 |
template <class P, class CharT, class TestFunction, class ExceptionTest> |
| 2944 |
void format_test_pointer(TestFunction check, ExceptionTest check_exception) { |
| 2945 |
// *** align-fill & width *** |
| 2946 |
check(SV("answer is ' 0x0'"), SV("answer is '{:6}'"), P(nullptr)); |
| 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 |
|
| 2951 |
// The fill character ':' is allowed here (P0645) but not in ranges (P2286). |
| 2952 |
check(SV("answer is ':::0x0'"), SV("answer is '{::>6}'"), P(nullptr)); |
| 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 |
|
| 2956 |
// Test whether zero padding is ignored |
| 2957 |
check(SV("answer is ':::0x0'"), SV("answer is '{::>06}'"), P(nullptr)); |
| 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 |
|
| 2961 |
// *** Sign *** |
| 2962 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:-}"), P(nullptr)); |
| 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 |
|
| 2966 |
// *** alternate form *** |
| 2967 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:#}"), P(nullptr)); |
| 2968 |
|
| 2969 |
// *** zero-padding *** |
| 2970 |
check(SV("answer is '0x0000'"), SV("answer is '{:06}'"), P(nullptr)); |
| 2971 |
check(SV("answer is '0x0000'"), SV("answer is '{:06p}'"), P(nullptr)); |
| 2972 |
check(SV("answer is '0X0000'"), SV("answer is '{:06P}'"), P(nullptr)); |
| 2973 |
|
| 2974 |
// *** precision *** |
| 2975 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.}"), nullptr); |
| 2976 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.0}"), nullptr); |
| 2977 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.42}"), nullptr); |
| 2978 |
|
| 2979 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.{}}"), nullptr); |
| 2980 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.{}}"), nullptr, true); |
| 2981 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:.{}}"), nullptr, 1.0); |
| 2982 |
|
| 2983 |
// *** locale-specific form *** |
| 2984 |
check_exception("The format specifier should consume the input or end with a '}'", SV("{:L}"), P(nullptr)); |
| 2985 |
|
| 2986 |
// *** type *** |
| 2987 |
for (const auto& fmt : invalid_types<CharT>("pP")) |
| 2988 |
check_exception("The type option contains an invalid value for a pointer formatting argument", fmt, P(nullptr)); |
| 2989 |
} |
| 2990 |
|
| 2991 |
template <class CharT, class TestFunction, class ExceptionTest> |
| 2992 |
void format_test_handle(TestFunction check, ExceptionTest check_exception) { |
| 2993 |
// *** Valid permutations *** |
| 2994 |
check(SV("answer is '0xaaaa'"), SV("answer is '{}'"), status::foo); |
| 2995 |
check(SV("answer is '0xaaaa'"), SV("answer is '{:x}'"), status::foo); |
| 2996 |
check(SV("answer is '0XAAAA'"), SV("answer is '{:X}'"), status::foo); |
| 2997 |
check(SV("answer is 'foo'"), SV("answer is '{:s}'"), status::foo); |
| 2998 |
|
| 2999 |
check(SV("answer is '0x5555'"), SV("answer is '{}'"), status::bar); |
| 3000 |
check(SV("answer is '0x5555'"), SV("answer is '{:x}'"), status::bar); |
| 3001 |
check(SV("answer is '0X5555'"), SV("answer is '{:X}'"), status::bar); |
| 3002 |
check(SV("answer is 'bar'"), SV("answer is '{:s}'"), status::bar); |
| 3003 |
|
| 3004 |
check(SV("answer is '0xaa55'"), SV("answer is '{}'"), status::foobar); |
| 3005 |
check(SV("answer is '0xaa55'"), SV("answer is '{:x}'"), status::foobar); |
| 3006 |
check(SV("answer is '0XAA55'"), SV("answer is '{:X}'"), status::foobar); |
| 3007 |
check(SV("answer is 'foobar'"), SV("answer is '{:s}'"), status::foobar); |
| 3008 |
|
| 3009 |
// P2418 Changed the argument from a const reference to a forwarding reference. |
| 3010 |
// This mainly affects handle classes, however since we use an abstraction |
| 3011 |
// layer here it's "tricky" to verify whether this test would do the "right" |
| 3012 |
// thing. So these tests are done separately. |
| 3013 |
|
| 3014 |
// *** type *** |
| 3015 |
for (const auto& fmt : invalid_types<CharT>("xXs")) |
| 3016 |
check_exception("The type option contains an invalid value for a status formatting argument", fmt, status::foo); |
| 3017 |
} |
| 3018 |
|
| 3019 |
template <class CharT, class TestFunction, class ExceptionTest> |
| 3020 |
void format_test_pointer(TestFunction check, ExceptionTest check_exception) { |
| 3021 |
format_test_pointer<std::nullptr_t, CharT>(check, check_exception); |
| 3022 |
format_test_pointer<void*, CharT>(check, check_exception); |
| 3023 |
format_test_pointer<const void*, CharT>(check, check_exception); |
| 3024 |
} |
| 3025 |
|
| 3026 |
/// Tests special buffer functions with a "large" input. |
| 3027 |
/// |
| 3028 |
/// This is a test specific for libc++, however the code should behave the same |
| 3029 |
/// on all implementations. |
| 3030 |
/// In \c __format::__output_buffer there are some special functions to optimize |
| 3031 |
/// outputting multiple characters, \c __copy, \c __transform, \c __fill. This |
| 3032 |
/// test validates whether the functions behave properly when the output size |
| 3033 |
/// doesn't fit in its internal buffer. |
| 3034 |
template <class CharT, class TestFunction> |
| 3035 |
void format_test_buffer_optimizations(TestFunction check) { |
| 3036 |
#ifdef _LIBCPP_VERSION |
| 3037 |
// Used to validate our test sets are the proper size. |
| 3038 |
// To test the chunked operations it needs to be larger than the internal |
| 3039 |
// buffer. Picked a nice looking number. |
| 3040 |
constexpr int minimum = 3 * std::__format::__internal_storage<CharT>::__buffer_size; |
| 3041 |
#else |
| 3042 |
constexpr int minimum = 1; |
| 3043 |
#endif |
| 3044 |
|
| 3045 |
// Copy |
| 3046 |
std::basic_string<CharT> str = STR( |
| 3047 |
"The quick brown fox jumps over the lazy dog." |
| 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 |
assert(str.size() > minimum); |
| 3078 |
check(std::basic_string_view<CharT>{str}, SV("{}"), str); |
| 3079 |
|
| 3080 |
// Fill |
| 3081 |
std::basic_string<CharT> fill(minimum, CharT('*')); |
| 3082 |
check(std::basic_string_view<CharT>{str + fill}, SV("{:*<{}}"), str, str.size() + minimum); |
| 3083 |
check(std::basic_string_view<CharT>{fill + str + fill}, SV("{:*^{}}"), str, minimum + str.size() + minimum); |
| 3084 |
check(std::basic_string_view<CharT>{fill + str}, SV("{:*>{}}"), str, minimum + str.size()); |
| 3085 |
} |
| 3086 |
|
| 3087 |
template <class CharT, execution_modus modus, class TestFunction, class ExceptionTest> |
| 3088 |
void format_tests(TestFunction check, ExceptionTest check_exception) { |
| 3089 |
// *** Test escaping *** |
| 3090 |
check(SV("{"), SV("{{")); |
| 3091 |
check(SV("}"), SV("}}")); |
| 3092 |
check(SV("{:^}"), SV("{{:^}}")); |
| 3093 |
check(SV("{: ^}"), SV("{{:{}^}}"), CharT(' ')); |
| 3094 |
check(SV("{:{}^}"), SV("{{:{{}}^}}")); |
| 3095 |
check(SV("{:{ }^}"), SV("{{:{{{}}}^}}"), CharT(' ')); |
| 3096 |
|
| 3097 |
// *** Test argument ID *** |
| 3098 |
check(SV("hello false true"), SV("hello {0:} {1:}"), false, true); |
| 3099 |
check(SV("hello true false"), SV("hello {1:} {0:}"), false, true); |
| 3100 |
|
| 3101 |
// *** Test many arguments *** |
| 3102 |
|
| 3103 |
// [format.args]/1 |
| 3104 |
// An instance of basic_format_args provides access to formatting arguments. |
| 3105 |
// Implementations should optimize the representation of basic_format_args |
| 3106 |
// for a small number of formatting arguments. |
| 3107 |
// |
| 3108 |
// These's no guidances what "a small number of formatting arguments" is. |
| 3109 |
// - fmtlib uses a 15 elements |
| 3110 |
// - libc++ uses 12 elements |
| 3111 |
// - MSVC STL uses a different approach regardless of the number of arguments |
| 3112 |
// - libstdc++ has no implementation yet |
| 3113 |
// fmtlib and libc++ use a similar approach, this approach can support 16 |
| 3114 |
// elements (based on design choices both support less elements). This test |
| 3115 |
// makes sure "the large number of formatting arguments" code path is tested. |
| 3116 |
check( |
| 3117 |
SV("1234567890\t1234567890"), |
| 3118 |
SV("{}{}{}{}{}{}{}{}{}{}\t{}{}{}{}{}{}{}{}{}{}"), |
| 3119 |
1, |
| 3120 |
2, |
| 3121 |
3, |
| 3122 |
4, |
| 3123 |
5, |
| 3124 |
6, |
| 3125 |
7, |
| 3126 |
8, |
| 3127 |
9, |
| 3128 |
0, |
| 3129 |
1, |
| 3130 |
2, |
| 3131 |
3, |
| 3132 |
4, |
| 3133 |
5, |
| 3134 |
6, |
| 3135 |
7, |
| 3136 |
8, |
| 3137 |
9, |
| 3138 |
0); |
| 3139 |
|
| 3140 |
// *** Test buffer boundaries format strings *** |
| 3141 |
if constexpr (modus == execution_modus::full) { |
| 3142 |
format_test_buffer_copy<CharT>(check); |
| 3143 |
format_test_buffer_full<CharT>(check); |
| 3144 |
} |
| 3145 |
|
| 3146 |
// *** Test invalid format strings *** |
| 3147 |
check_exception("The format string terminates at a '{'", SV("{")); |
| 3148 |
check_exception("The argument index value is too large for the number of arguments supplied", SV("{:")); |
| 3149 |
check_exception("The replacement field misses a terminating '}'", SV("{:"), 42); |
| 3150 |
|
| 3151 |
check_exception("The argument index should end with a ':' or a '}'", SV("{0")); |
| 3152 |
check_exception("The argument index value is too large for the number of arguments supplied", SV("{0:")); |
| 3153 |
check_exception("The replacement field misses a terminating '}'", SV("{0:"), 42); |
| 3154 |
|
| 3155 |
check_exception("The format string contains an invalid escape sequence", SV("}")); |
| 3156 |
check_exception("The format string contains an invalid escape sequence", SV("{:}-}"), 42); |
| 3157 |
|
| 3158 |
check_exception("The format string contains an invalid escape sequence", SV("} ")); |
| 3159 |
check_exception("The argument index starts with an invalid character", SV("{-"), 42); |
| 3160 |
check_exception("The argument index value is too large for the number of arguments supplied", SV("hello {}")); |
| 3161 |
check_exception("The argument index value is too large for the number of arguments supplied", SV("hello {0}")); |
| 3162 |
check_exception("The argument index value is too large for the number of arguments supplied", SV("hello {1}"), 42); |
| 3163 |
|
| 3164 |
// *** Test char format argument *** |
| 3165 |
// The `char` to `wchar_t` formatting is tested separately. |
| 3166 |
check(SV("hello 09azAZ!"), |
| 3167 |
SV("hello {}{}{}{}{}{}{}"), |
| 3168 |
CharT('0'), |
| 3169 |
CharT('9'), |
| 3170 |
CharT('a'), |
| 3171 |
CharT('z'), |
| 3172 |
CharT('A'), |
| 3173 |
CharT('Z'), |
| 3174 |
CharT('!')); |
| 3175 |
if constexpr (modus == execution_modus::full) { |
| 3176 |
format_test_char<CharT>(check, check_exception); |
| 3177 |
format_test_char_as_integer<CharT>(check, check_exception); |
| 3178 |
} |
| 3179 |
|
| 3180 |
// *** Test string format argument *** |
| 3181 |
{ |
| 3182 |
CharT buffer[] = {CharT('0'), CharT('9'), CharT('a'), CharT('z'), CharT('A'), CharT('Z'), CharT('!'), 0}; |
| 3183 |
CharT* data = buffer; |
| 3184 |
check(SV("hello 09azAZ!"), SV("hello {}"), data); |
| 3185 |
} |
| 3186 |
{ |
| 3187 |
CharT buffer[] = {CharT('0'), CharT('9'), CharT('a'), CharT('z'), CharT('A'), CharT('Z'), CharT('!'), 0}; |
| 3188 |
const CharT* data = buffer; |
| 3189 |
check(SV("hello 09azAZ!"), SV("hello {}"), data); |
| 3190 |
} |
| 3191 |
{ |
| 3192 |
std::basic_string<CharT> data = STR("world"); |
| 3193 |
check(SV("hello world"), SV("hello {}"), data); |
| 3194 |
} |
| 3195 |
{ |
| 3196 |
std::basic_string<CharT> buffer = STR("world"); |
| 3197 |
std::basic_string_view<CharT> data = buffer; |
| 3198 |
check(SV("hello world"), SV("hello {}"), data); |
| 3199 |
} |
| 3200 |
if constexpr (modus == execution_modus::full) |
| 3201 |
format_string_tests<CharT>(check, check_exception); |
| 3202 |
|
| 3203 |
// *** Test Boolean format argument *** |
| 3204 |
check(SV("hello false true"), SV("hello {} {}"), false, true); |
| 3205 |
|
| 3206 |
if constexpr (modus == execution_modus::full) { |
| 3207 |
format_test_bool<CharT>(check, check_exception); |
| 3208 |
format_test_bool_as_integer<CharT>(check, check_exception); |
| 3209 |
} |
| 3210 |
// *** Test signed integral format argument *** |
| 3211 |
check(SV("hello 42"), SV("hello {}"), static_cast<signed char>(42)); |
| 3212 |
check(SV("hello 42"), SV("hello {}"), static_cast<short>(42)); |
| 3213 |
check(SV("hello 42"), SV("hello {}"), static_cast<int>(42)); |
| 3214 |
check(SV("hello 42"), SV("hello {}"), static_cast<long>(42)); |
| 3215 |
check(SV("hello 42"), SV("hello {}"), static_cast<long long>(42)); |
| 3216 |
#ifndef TEST_HAS_NO_INT128 |
| 3217 |
check(SV("hello 42"), SV("hello {}"), static_cast<__int128_t>(42)); |
| 3218 |
#endif |
| 3219 |
|
| 3220 |
if constexpr (modus == execution_modus::full) |
| 3221 |
format_test_signed_integer<CharT>(check, check_exception); |
| 3222 |
|
| 3223 |
// ** Test unsigned integral format argument *** |
| 3224 |
check(SV("hello 42"), SV("hello {}"), static_cast<unsigned char>(42)); |
| 3225 |
check(SV("hello 42"), SV("hello {}"), static_cast<unsigned short>(42)); |
| 3226 |
check(SV("hello 42"), SV("hello {}"), static_cast<unsigned>(42)); |
| 3227 |
check(SV("hello 42"), SV("hello {}"), static_cast<unsigned long>(42)); |
| 3228 |
check(SV("hello 42"), SV("hello {}"), static_cast<unsigned long long>(42)); |
| 3229 |
#ifndef TEST_HAS_NO_INT128 |
| 3230 |
check(SV("hello 42"), SV("hello {}"), static_cast<__uint128_t>(42)); |
| 3231 |
#endif |
| 3232 |
if constexpr (modus == execution_modus::full) |
| 3233 |
format_test_unsigned_integer<CharT>(check, check_exception); |
| 3234 |
|
| 3235 |
// *** Test floating point format argument *** |
| 3236 |
check(SV("hello 42"), SV("hello {}"), static_cast<float>(42)); |
| 3237 |
check(SV("hello 42"), SV("hello {}"), static_cast<double>(42)); |
| 3238 |
check(SV("hello 42"), SV("hello {}"), static_cast<long double>(42)); |
| 3239 |
if constexpr (modus == execution_modus::full) |
| 3240 |
format_test_floating_point<CharT>(check, check_exception); |
| 3241 |
|
| 3242 |
// *** Test pointer formatter argument *** |
| 3243 |
check(SV("hello 0x0"), SV("hello {}"), nullptr); |
| 3244 |
check(SV("hello 0x42"), SV("hello {}"), reinterpret_cast<void*>(0x42)); |
| 3245 |
check(SV("hello 0x42"), SV("hello {}"), reinterpret_cast<const void*>(0x42)); |
| 3246 |
if constexpr (modus == execution_modus::full) |
| 3247 |
format_test_pointer<CharT>(check, check_exception); |
| 3248 |
|
| 3249 |
// *** Test handle formatter argument *** |
| 3250 |
format_test_handle<CharT>(check, check_exception); |
| 3251 |
|
| 3252 |
// *** Test the internal buffer optimizations *** |
| 3253 |
if constexpr (modus == execution_modus::full) |
| 3254 |
format_test_buffer_optimizations<CharT>(check); |
| 3255 |
} |
| 3256 |
|
| 3257 |
#ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 3258 |
template <class TestFunction> |
| 3259 |
void format_tests_char_to_wchar_t(TestFunction check) { |
| 3260 |
using CharT = wchar_t; |
| 3261 |
check(SV("hello 09azA"), SV("hello {}{}{}{}{}"), '0', '9', 'a', 'z', 'A'); |
| 3262 |
} |
| 3263 |
#endif |
| 3264 |
|
| 3265 |
#endif // TEST_STD_UTILITIES_FORMAT_FORMAT_FUNCTIONS_FORMAT_TESTS_H |