jaulib
v1.4.1-17-gd77ace3-dirty
Jau Support Library (C++, Java, ..)
Loading...
Searching...
No Matches
test_stringconv.cpp
Go to the documentation of this file.
1
/*
2
* Author: Sven Gothel <sgothel@jausoft.com>
3
* Copyright (c) 2025 Gothel Software e.K.
4
*
5
* Permission is hereby granted, free of charge, to any person obtaining
6
* a copy of this software and associated documentation files (the
7
* "Software"), to deal in the Software without restriction, including
8
* without limitation the rights to use, copy, modify, merge, publish,
9
* distribute, sublicense, and/or sell copies of the Software, and to
10
* permit persons to whom the Software is furnished to do so, subject to
11
* the following conditions:
12
*
13
* The above copyright notice and this permission notice shall be
14
* included in all copies or substantial portions of the Software.
15
*
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
*/
24
#include <cassert>
25
#include <cstring>
26
27
#include <
jau/basic_types.hpp
>
28
#include <
jau/cpp_lang_util.hpp
>
29
#include <
jau/string_literal.hpp
>
30
#include <jau/test/catch2_ext.hpp>
31
#include <
jau/type_traits_queries.hpp
>
32
33
TEST_CASE
(
"jau::BasicStringLiteral_00"
,
"[jau][std::string][BasicStringLiteral]"
) {
34
static_assert
(
true
==
jau::req::string_literal
<
decltype
(
"lala"
)>);
35
static_assert
(
true
==
jau::req::string_alike
<
decltype
(
"lala"
)>);
36
static_assert
(
true
==
jau::req::string_alike
<
decltype
(std::string_view(
"lala"
))>);
37
static_assert
(
true
==
jau::req::string_alike
<
decltype
(std::string(
"lala"
))>);
38
static_assert
(
true
==
jau::req::string_alike
<
decltype
((
const
char
*)
"lala"
)>);
39
40
{
41
constexpr
const
char
s[] =
"Hello"
;
42
constexpr
const
jau::StringLiteral
sl1 = s;
43
constexpr
const
jau::StringLiteral
sl2 =
"Hello"
;
44
static_assert
( sl1 == sl2 );
45
46
constexpr
const
jau::StringLiteral
sl3 = sl2;
47
static_assert
( sl1 == sl3 );
48
REQUIRE( sl1 == sl3 );
49
50
jau::StringLiteral
sl4 = sl3;
51
REQUIRE( sl1 == sl4 );
52
53
constexpr
const
jau::StringLiteral
sl5 =
"Hello"
;
54
static_assert
( sl1 == sl5 );
55
56
constexpr
const
jau::StringLiteral
sl6 =
"Hello World"
;
57
static_assert
( sl1 != sl6 );
58
REQUIRE( sl1 != sl6 );
59
60
constexpr
const
jau::StringLiteral
sl7 =
" "
;
61
constexpr
const
jau::StringLiteral
sl8 =
"World"
;
62
constexpr
const
jau::StringLiteral
sl9 = sl1 + sl7 + sl8;
63
static_assert
( sl1 != sl9 );
64
REQUIRE( sl1 != sl9 );
65
static_assert
( sl6 == sl9 );
66
REQUIRE( sl6 == sl9 );
67
68
constexpr
const
char
sl7_b[] =
" "
;
69
constexpr
const
jau::StringLiteral
sl10 = sl1 + sl7_b + sl8;
70
static_assert
( sl1 != sl10 );
71
REQUIRE( sl1 != sl10 );
72
static_assert
( sl6 == sl10 );
73
REQUIRE( sl6 == sl10 );
74
75
const
char
sl7_c[] =
" "
;
76
const
jau::StringLiteral
sl11 = sl1 + sl7_c + sl8;
77
REQUIRE( sl1 != sl11 );
78
REQUIRE( sl6 == sl11 );
79
80
constexpr
const
jau::StringLiteral
sl12 = sl1 +
" "
+ sl8;
81
static_assert
( sl1 != sl12 );
82
REQUIRE( sl1 != sl12 );
83
static_assert
( sl6 == sl12 );
84
REQUIRE( sl6 == sl12 );
85
}
86
{
87
constexpr
const
char
s1_c[] =
"Hello"
;
88
constexpr
jau::StringLiteral
sl2 =
"Hello"
;
89
constexpr
jau::StringLiteral
sl1 = s1_c;
90
static_assert
( s1_c == sl2 );
91
REQUIRE( s1_c == sl2 );
92
static_assert
( sl1 == sl2 );
93
REQUIRE( sl1 == sl2 );
94
static_assert
( sl2 == sl1 );
95
REQUIRE( sl2 == sl1 );
96
}
97
}
98
99
basic_types.hpp
jau::req::string_alike
Like a string:
Definition
type_concepts.hpp:135
jau::req::string_literal
A string literal: char (&)[N], jau::StringLiteral.
Definition
type_concepts.hpp:109
cpp_lang_util.hpp
jau::StringLiteral
BasicStringLiteral< char, N > StringLiteral
Definition
string_literal.hpp:168
string_literal.hpp
TEST_CASE
TEST_CASE("jau::BasicStringLiteral_00", "[jau][std::string][BasicStringLiteral]")
Definition
test_stringconv.cpp:33
type_traits_queries.hpp
test
test_stringconv.cpp
Generated by
1.13.2