Gamp
v0.0.7-67-g7798ac4
Gamp: Graphics, Audio, Multimedia and Processing
Loading...
Searching...
No Matches
test_stringfmt_impl.cpp
Go to the documentation of this file.
1
/**
2
* Author: Sven Gothel <sgothel@jausoft.com>
3
* Copyright (c) 2024 Gothel Software e.K.
4
*
5
* ***
6
*
7
* SPDX-License-Identifier: MIT
8
*
9
* This Source Code Form is subject to the terms of the MIT License
10
* If a copy of the MIT was not distributed with this
11
* file, You can obtain one at https://opensource.org/license/mit/.
12
*
13
*/
14
#include <sys/types.h>
15
#include <cassert>
16
#include <cstdint>
17
#include <cstdio>
18
#include <cstring>
19
#include <iostream>
20
21
#include <
jau/basic_types.hpp
>
22
#include <
jau/cpp_lang_util.hpp
>
23
#include <
jau/cpp_pragma.hpp
>
24
#include <
jau/float_types.hpp
>
25
#include <
jau/int_types.hpp
>
26
#include <
jau/string_cfmt.hpp
>
27
#include <
jau/string_literal.hpp
>
28
#include <
jau/string_util.hpp
>
29
#include <jau/test/catch2_ext.hpp>
30
#include <
jau/type_concepts.hpp
>
31
#include <
jau/type_traits_queries.hpp
>
32
33
#ifdef HAS_STD_FORMAT
34
#include <format>
35
#endif
36
37
using namespace
std::literals;
38
39
using namespace
jau::float_literals
;
40
41
using namespace
jau::int_literals
;
42
43
TEST_CASE
(
"jau_cfmt_append_integral01"
,
"[benchmark][jau][std::string][format_string]"
) {
44
// const uint64_t i1 = std::numeric_limits<uint64_t>::max(); // Value = 18446744073709551615 (0xffffffffffffffff)
45
// static constexpr const char *format_check_exp1 = " 0000000018'446'744'073'709'551'615";
46
// static constexpr const char *format_check_exp0 = " 0000000000000018446744073709551615";
47
48
{
49
// Case 1: clang-analyzer-core.uninitialized.Assign: buf_ was written up-to val_digits! (Assigned value is garbage or undefined)
50
// This analysis issue was only produced with preset `debug-clang`, not `release-clang`.
51
static
constexpr
const
char
*format_exp =
"-0"
;
52
// radix 2
53
// no flags_t::uppercase
54
// no flags_t::thousands
55
// no width
56
// no precision
57
// value = 0 ??? -> val_digits 1
58
// negative = true
59
// no inject_dot
60
const
uint64_t
value
= 0;
61
const
bool
negative =
true
;
62
const
bool
inject_dot =
false
;
63
jau::cfmt::FormatOpts
opts;
64
opts.
length_mod
=
jau::cfmt::plength_t::z
;
65
opts.
setConversion
(
'b'
);
66
std::cout <<
"FormatOpts: "
<< opts <<
"\n"
;
67
REQUIRE(2 == opts.
radix
);
68
69
{
70
std::string s;
71
s.reserve(
jau::cfmt::default_string_capacity
+ 1);
72
73
jau::cfmt::impl::append_integral(s, s.max_size(),
value
, negative, opts, inject_dot);
74
REQUIRE(format_exp == s);
75
}
76
{
77
std::string s;
78
s.reserve(
jau::cfmt::default_string_capacity
+ 1);
79
80
jau::cfmt::impl::append_integral_simple(s, s.max_size(),
value
, negative, opts);
81
REQUIRE(format_exp == s);
82
}
83
}
84
}
basic_types.hpp
cpp_lang_util.hpp
cpp_pragma.hpp
float_types.hpp
jau::value
constexpr bool value(const Bool rhs) noexcept
Definition
cpp_lang_util.hpp:541
jau::cfmt::default_string_capacity
constexpr const size_t default_string_capacity
Default string reserved capacity w/o EOS (511)
Definition
string_cfmt.hpp:209
jau::cfmt::plength_t::z
@ z
size_t or ssize_t integer
Definition
string_cfmt.hpp:252
int_types.hpp
jau::float_literals
Definition
float_si_types.hpp:44
jau::int_literals
Definition
int_types.hpp:171
string_cfmt.hpp
string_literal.hpp
string_util.hpp
jau::cfmt::FormatOpts
Definition
string_cfmt.hpp:279
jau::cfmt::FormatOpts::setConversion
constexpr bool setConversion(char fmt_literal) noexcept
Definition
string_cfmt.hpp:338
jau::cfmt::FormatOpts::length_mod
plength_t length_mod
Definition
string_cfmt.hpp:285
jau::cfmt::FormatOpts::radix
uint32_t radix
Definition
string_cfmt.hpp:283
TEST_CASE
TEST_CASE("jau_cfmt_append_integral01", "[benchmark][jau][std::string][format_string]")
Definition
test_stringfmt_impl.cpp:43
type_concepts.hpp
type_traits_queries.hpp
jaulib
test
test_stringfmt_impl.cpp
Generated by
1.13.2