Line data Source code
1 : // Copyright (c) 2026 Made to Order Software Corp. All Rights Reserved
2 : //
3 : // https://snapwebsites.org/project/snapdev
4 : // contact@m2osw.com
5 : //
6 : // This program is free software: you can redistribute it and/or modify
7 : // it under the terms of the GNU General Public License as published by
8 : // the Free Software Foundation, either version 3 of the License, or
9 : // (at your option) any later version.
10 : //
11 : // This program is distributed in the hope that it will be useful,
12 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : // GNU General Public License for more details.
15 : //
16 : // You should have received a copy of the GNU General Public License
17 : // along with this program. If not, see <https://www.gnu.org/licenses/>.
18 :
19 : /** \file
20 : * \brief Verify that the is_string_literal works.
21 : *
22 : * This file makes sure we can compile with the is_string_literal and
23 : * all the different type of strings.
24 : */
25 :
26 : // self
27 : //
28 : #include <snapdev/string_literal_length.h>
29 :
30 : #include "catch_main.h"
31 :
32 :
33 : // last include
34 : //
35 : #include <snapdev/poison.h>
36 :
37 :
38 :
39 : namespace
40 : {
41 :
42 :
43 : constexpr char const g_char_literal[] = "it is!";
44 : constexpr wchar_t const g_wchar_literal[] = L"it is!";
45 : constexpr char8_t const g_char8_literal[] = u8"it is!";
46 : constexpr char16_t const g_char16_literal[] = u"it is!";
47 : constexpr char32_t const g_char32_literal[] = U"it is!";
48 :
49 : constexpr char const * g_char_pointer = "another string";
50 : constexpr wchar_t const * g_wchar_pointer = L"another string";
51 : constexpr char8_t const * g_char8_pointer = u8"another string";
52 : constexpr char16_t const * g_char16_pointer = u"another string";
53 : constexpr char32_t const * g_char32_pointer = U"another string";
54 :
55 :
56 : } // no name namespace
57 :
58 :
59 :
60 4 : CATCH_TEST_CASE("string_literal_length", "[string]")
61 : {
62 4 : CATCH_START_SECTION("string_literal_length: check all inline string literal types")
63 : {
64 1 : CATCH_REQUIRE(snapdev::string_literal_length("it is!") == 6); // char
65 1 : CATCH_REQUIRE(snapdev::string_literal_length(L"it is!") == 6); // wchar_t
66 1 : CATCH_REQUIRE(snapdev::string_literal_length(u8"it is!") == 6); // char8_t
67 1 : CATCH_REQUIRE(snapdev::string_literal_length(u"it is!") == 6); // char16_t
68 1 : CATCH_REQUIRE(snapdev::string_literal_length(U"it is!") == 6); // char32_t
69 :
70 : // to test other types that should not match one of the string types above
71 : //constexpr float const a[5] = {};
72 : //CATCH_REQUIRE(snapdev::string_literal_length(a) == 6);
73 : }
74 4 : CATCH_END_SECTION()
75 :
76 4 : CATCH_START_SECTION("string_literal_length: check all constexpr string literal lengths")
77 : {
78 1 : CATCH_REQUIRE(snapdev::string_literal_length(g_char_literal) == 6); // char
79 1 : CATCH_REQUIRE(snapdev::string_literal_length(g_wchar_literal) == 6); // wchar_t
80 1 : CATCH_REQUIRE(snapdev::string_literal_length(g_char8_literal) == 6); // char8_t
81 1 : CATCH_REQUIRE(snapdev::string_literal_length(g_char16_literal) == 6); // char16_t
82 1 : CATCH_REQUIRE(snapdev::string_literal_length(g_char32_literal) == 6); // char32_t
83 : }
84 4 : CATCH_END_SECTION()
85 :
86 4 : CATCH_START_SECTION("string_literal_length: check all constexpr string lengths")
87 : {
88 1 : CATCH_REQUIRE(snapdev::string_length(g_char_literal) == 6); // char
89 1 : CATCH_REQUIRE(snapdev::string_length(g_wchar_literal) == 6); // wchar_t
90 1 : CATCH_REQUIRE(snapdev::string_length(g_char8_literal) == 6); // char8_t
91 1 : CATCH_REQUIRE(snapdev::string_length(g_char16_literal) == 6); // char16_t
92 1 : CATCH_REQUIRE(snapdev::string_length(g_char32_literal) == 6); // char32_t
93 : }
94 4 : CATCH_END_SECTION()
95 :
96 4 : CATCH_START_SECTION("string_literal_length: check all constexpr string pointers")
97 : {
98 1 : CATCH_REQUIRE(snapdev::string_length(g_char_pointer) == 14); // char
99 1 : CATCH_REQUIRE(snapdev::string_length(g_wchar_pointer) == 14); // wchar_t
100 1 : CATCH_REQUIRE(snapdev::string_length(g_char8_pointer) == 14); // char8_t
101 1 : CATCH_REQUIRE(snapdev::string_length(g_char16_pointer) == 14); // char16_t
102 1 : CATCH_REQUIRE(snapdev::string_length(g_char32_pointer) == 14); // char32_t
103 : }
104 4 : CATCH_END_SECTION()
105 4 : }
106 :
107 :
108 :
109 : // vim: ts=4 sw=4 et
|