jaulib v1.4.1-17-gd77ace3-dirty
Jau Support Library (C++, Java, ..)
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>
28#include <jau/string_util.hpp>
29#include <jau/test/catch2_ext.hpp>
30#include <jau/type_concepts.hpp>
32
33#ifdef HAS_STD_FORMAT
34 #include <format>
35#endif
36
37using namespace std::literals;
38
39using namespace jau::float_literals;
40
41using namespace jau::int_literals;
42
43TEST_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;
65 opts.setConversion('b');
66 std::cout << "FormatOpts: " << opts << "\n";
67 REQUIRE(2 == opts.radix);
68
69 std::string s;
71
72 jau::cfmt::impl::append_integral(s, s.max_size(), value, negative, opts, inject_dot);
73 REQUIRE(format_exp == s);
74 }
75}
constexpr bool value(const Bool rhs) noexcept
constexpr const size_t default_string_capacity
Default string reserved capacity w/o EOS (511)
@ z
size_t or ssize_t integer
void append_integral(std::string &dest, const size_t dest_maxlen, uint64_t v, const bool negative, const FormatOpts &opts, const bool inject_dot=false)
constexpr bool setConversion(char fmt_literal) noexcept
TEST_CASE("jau_cfmt_append_integral01", "[benchmark][jau][std::string][format_string]")