LeechCraft  0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
ctstringtest.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Distributed under the Boost Software License, Version 1.0.
6  * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7  **********************************************************************/
8 
9 #include "ctstringtest.h"
10 #include <QtTest>
11 #include <ctstring.h>
12 #include <ctstringutils.h>
13 
14 QTEST_APPLESS_MAIN (LC::Util::CtStringTest)
15 
16 namespace LC::Util
17 {
18 #define TEST_STR "test string"
19  void CtStringTest::testConstruction ()
20  {
21  constexpr CtString s { TEST_STR };
22  QCOMPARE (ToString<s> (), QString { TEST_STR });
23  }
24 
25  void CtStringTest::testUnsizedConstruction ()
26  {
27  constexpr auto getStr = [] () constexpr { return TEST_STR; };
28 
29  constexpr auto s = CtString<StringBufSize (getStr ())>::FromUnsized (getStr ());
30  QCOMPARE (ToString<s> (), QString { TEST_STR });
31  }
32 
33  void CtStringTest::testUDL ()
34  {
35  constexpr auto s = "test string"_ct;
36  QCOMPARE (ToString<s> (), QString { TEST_STR });
37  }
38 
39  void CtStringTest::testConcat ()
40  {
41  constexpr auto s1 = "hello, "_ct;
42  constexpr auto s2 = "world!"_ct;
43  constexpr auto s3 = " how's life?"_ct;
44 
45  constexpr auto concat = s1 + s2 + s3;
46  const QString expected { "hello, world! how's life?" };
47  QCOMPARE (ToString<concat> (), expected);
48 
49  QCOMPARE (ToString<"hello, "_ct + "world!" + " how's life?"> (), expected);
50 
51  QCOMPARE (ToString<"hello, " + "world!"_ct + " how's life?"> (), expected);
52  }
53 
54  void CtStringTest::testReplaceAll ()
55  {
56  constexpr auto s1 = "Hello, _! The _ is nice!"_ct;
57  constexpr auto s2 = "world"_ct;
58  constexpr auto s3 = ReplaceAll<s1, '_'> (s2);
59  QCOMPARE (ToString<s3> (), "Hello, world! The world is nice!");
60  }
61 
62  void CtStringTest::testNub ()
63  {
64  constexpr static std::tuple input { "hello"_ct, "world"_ct, "hello"_ct, "lc"_ct, "what's"_ct, "up"_ct, "lc"_ct, "lc"_ct };
65  constexpr std::tuple expected { "hello"_ct, "world"_ct, "lc"_ct, "what's"_ct, "up"_ct };
66 
67  constexpr static auto F = [&] { return input; };
68  constexpr auto nubbed = Nub<F>();
69  static_assert (nubbed == expected);
70  }
71 
72  constexpr bool TestUB ()
73  {
74  [[maybe_unused]] constexpr auto str = "hello, " + "world!"_ct + " how's life?";
75  return true;
76  }
77 
78  static_assert (TestUB ());
79 }
#define TEST_STR
constexpr bool TestUB()
constexpr detail::ExprTree< detail::ExprType::LeafStaticPlaceholder, detail::MemberPtrs< Ptrs... > > tuple
Definition: oral.h:1086
CtString(RawStr< N, Char >) -> CtString< N - 1, Char >
static constexpr auto FromUnsized(const Char *s) noexcept
Definition: ctstring.h:47