204TEST_CASE(
"single_conversion",
"[jau][std::string][jau::cfmt]") {
207 int32_t i32_u = 1234;
211 void *p1a = (
void *)0xaabbccdd_u64;
212 void *p1b = (
void *)0x11223344aabbccdd_u64;
213 void *p2a = (
void *)0x112233aabbccdd_u64;
214 void *p2b = (
void *)0xaabbcc_u64;
215 void *p3a = (
void *)0x112233aabbccdd_u64;
216 void *p3b = (
void *)0xaabbcc_u64;
217 const char sl1[] =
"Hallo";
218 std::string s2 =
"World";
219 std::string_view s2sv = s2;
220 const char *s2p = s2.c_str();
223 double value = 123.45;
224 const int expval = std::ilogb(
value);
225 const double frac =
value / std::scalbn(1.0, expval);
227 fprintf(stderr,
"JAU:10 v %f = %f * 2^%d -> 0x%0" PRIx64
"p%d\n",
value, frac, expval, significand, expval);
230 fprintf(stderr,
"JAU:11 v %f = %f * 2^%d -> 0x%0" PRIx64
"p%d\n",
value, frac, expval2, significand, expval2);
233 float value = 123.45f;
234 const int expval = std::ilogb(
value);
235 const double frac =
value / std::scalbn(1.0, expval);
237 fprintf(stderr,
"JAU:20 v %f = %f * 2^%d -> 0x%0" PRIx32
"p%d\n",
value, frac, expval, significand, expval);
240 fprintf(stderr,
"JAU:21 v %f = %f * 2^%d -> 0x%0" PRIx32
"p%d\n",
value, frac, expval2, significand, expval2);
243 float ivalue = 123.45f;
244 double value = ivalue;
245 const int expval = std::ilogb(
value);
246 const double frac =
value / std::scalbn(1.0, expval);
248 fprintf(stderr,
"JAU:30 v %f = %f * 2^%d -> 0x%0" PRIx64
"p%d\n",
value, frac, expval, significand, expval);
251 fprintf(stderr,
"JAU:31 v %f = %f * 2^%d -> 0x%0" PRIx64
"p%d\n",
value, frac, expval2, significand, expval2);
272 checkFormat(__LINE__,
"p3b %p %0p", &i32_u, &i32_u);
321 const char *str =
nullptr;
323 const char limiter =
'3';
324 const char *limiter_pos =
nullptr;
325 char *endptr =
nullptr;
327 jau_format_check(
"Value end not '%c' @ idx %zd, %p != %p, in: %p '%s' len %zu", limiter, endptr - str, endptr, limiter_pos, str, str, str_len);
328 jau_format_checkLine(
"Value end not '%c' @ idx %zd, %p != %p, in: %p '%s' len %zu", limiter, endptr - str, endptr, limiter_pos, str, str, str_len);
348 enum enum1_unsigned_t { jau1_alpha, jau1_beta, jau1_gamma };
349 enum1_unsigned_t e1_u = jau1_alpha;
351 enum enum2_signed_t { jau2_alpha=-1, jau_beta, jau_gamma };
352 enum2_signed_t e2_s = jau2_alpha;
354 enum class enum3_signed_t { alpha=-1, beta, gamma };
355 enum3_signed_t e3_s = enum3_signed_t::alpha;
361 enum4_unsigned_t e4_u = jau_CAP_CLEAR;
363 static_assert(
true == std::is_enum_v<
decltype(e1_u)>);
364 static_assert(
true == std::is_unsigned_v<std::underlying_type_t<
decltype(e1_u)>>);
366 static_assert(
true == std::is_enum_v<
decltype(e2_s)>);
367 static_assert(
true == std::is_signed_v<std::underlying_type_t<
decltype(e2_s)>>);
369 static_assert(
true == std::is_enum_v<
decltype(e3_s)>);
370 static_assert(
true == std::is_signed_v<std::underlying_type_t<
decltype(e3_s)>>);
372 static_assert(
true == std::is_enum_v<
decltype(e4_u)>);
373 static_assert(
true == std::is_unsigned_v<std::underlying_type_t<
decltype(e4_u)>>);
378 static_assert(4 ==
jau::cfmt::check(
"%u, %d, %d, %u\n", e1_u, e2_s, e3_s, e4_u));
387TEST_CASE(
"integral_conversion",
"[jau][std::string][jau::cfmt]") {
388 static constexpr const char *format_check_exp1 =
"format_check: -1, 2, -3, 4, -5, 6, -7, 8, -9, 10";
389 static constexpr const char *format_check_exp2 =
"format_check: -1, 02, -03, 0004, -0005, 000006, -000007, 00000008, -00000009, 0000000010";
405 jau_format_check(
"format_check: %hhd, %hhu, %hd, %hu, %d, %u, %ld, %lu, %zd, %zu", i1, i2, i3, i4, i5, i6, i7, i8, i9, i10);
406 CHECK(format_check_exp1 ==
jau::format_string(
"format_check: %hhd, %hhu, %hd, %hu, %d, %u, %ld, %lu, %zd, %zu", i1, i2, i3, i4, i5, i6, i7, i8, i9, i10));
408 jau_format_check(
"format_check: %01hhd, %02hhu, %03hd, %04hu, %05d, %06u, %07ld, %08lu, %09zd, %010zu", i1, i2, i3, i4, i5, i6, i7, i8, i9, i10);
409 CHECK(format_check_exp2 ==
jau::format_string(
"format_check: %01hhd, %02hhu, %03hd, %04hu, %05d, %06u, %07ld, %08lu, %09zd, %010zu", i1, i2, i3, i4, i5, i6, i7, i8, i9, i10));
Result formatR(std::string &s, size_t maxLen, std::string_view fmt, const Targs &...args) noexcept
Strict format with type validation of arguments against the format string, appending to the given des...