LeechCraft  0.6.70-16373-g319c272718
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  constexpr auto concat2 = "hello, "_ct;
50  QCOMPARE (ToString<concat2 + "world!" + " how's life?"> (), expected);
51  }
52 
53  void CtStringTest::testNub ()
54  {
55  constexpr static std::tuple input { "hello"_ct, "world"_ct, "hello"_ct, "lc"_ct, "what's"_ct, "up"_ct, "lc"_ct, "lc"_ct };
56  constexpr std::tuple expected { "hello"_ct, "world"_ct, "lc"_ct, "what's"_ct, "up"_ct };
57 
58  constexpr static auto F = [&] { return input; };
59  constexpr auto nubbed = Nub<F>();
60  static_assert (nubbed == expected);
61  }
62 }
#define TEST_STR
CtString(RawStr< N, Char >) -> CtString< N - 1, Char >
static constexpr auto FromUnsized(const Char *s) noexcept
Definition: ctstring.h:46