Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
format-cout-test.cpp
Go to the documentation of this file.
1/*
2 FormatCOUT(Test) - validate automatic string conversion in output
3
4 Copyright (C)
5 2016, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12* *****************************************************************/
13
19#include "lib/test/run.hpp"
20
21#include "lib/p.hpp"
22#include "lib/diff/gen-node.hpp"
23
24#include "lib/meta/util.hpp"
25#include "lib/meta/trait.hpp"
26#include "lib/format-cout.hpp"
27
28#include <string>
29
30using lib::P;
31using lib::makeP;
33
34using std::string;
35
36
37namespace util {
38namespace test {
39
40 namespace { // test fixture
41
44 {
45 uint neigh_ = 42;
46 };
47
48
54
55 template<typename T>
57 template<typename T>
58 using BasicallyCString = std::is_convertible<T, const char*>;
59
60
61#define SHOW_CHECK(_EXPR_) cout << STRINGIFY(_EXPR_) << "\t : " << (_EXPR_::value? "Yes":"No") << endl;
62#define ANALYSE(_TYPE_) \
63 cout << "Type: " STRINGIFY(_TYPE_) " ......"<<endl; \
64 SHOW_CHECK (is_StringLike<_TYPE_>); \
65 SHOW_CHECK (BasicallyString<_TYPE_>); \
66 SHOW_CHECK (BasicallyCString<_TYPE_>); \
67 SHOW_CHECK (std::is_arithmetic<_TYPE_>); \
68 SHOW_CHECK (can_lexical2string<_TYPE_>); \
69 SHOW_CHECK (can_convertToString<_TYPE_>); \
70 SHOW_CHECK (use_StringConversion4Stream<_TYPE_>);
71
72
73 void
75 {
76 using CharLit = decltype("literal");
77 using CharPtr = const char*;
78 using StringPtr = string *;
79 using StringRef = string &;
80 using StringRRef = string &&;
81 using StrConstRef = string const&;
82 using GenNodePtr = GenNode*;
83 using GenNodeRef = GenNode&;
84 using GenNodeRRef = GenNode&&;
85
86 ANALYSE (int);
87 ANALYSE (char);
88 ANALYSE (double);
89 ANALYSE (int64_t);
90 ANALYSE (string);
91 ANALYSE (StringPtr);
92 ANALYSE (StringRef);
93 ANALYSE (StringRRef);
94 ANALYSE (StrConstRef);
95 ANALYSE (CharLit);
96 ANALYSE (CharPtr)
100 ANALYSE (GenNodePtr)
101 ANALYSE (GenNodeRef)
102 ANALYSE (GenNodeRRef)
104 cout << "───────────────────────────╼━━━━━━━━━━╾───────────────────────────"<<endl;
105 }
106 }//(end)fixture
107
108
109
110
111 /***************************************************************************/
132 : public Test
133 {
134 void
135 run (Arg)
136 {
137 showTraits();
138
139 auto silent = makeP<Reticent>();
140 auto chatty = makeP<GenNode>("Hui", "Buh");
141
142 cout << "smart-ptr, no string conv..." << silent <<endl;
143 cout << "smart-ptr, custom conv......" << chatty <<endl;
144
145 cout << "reference, no string conv..." << *silent <<endl;
146 cout << "reference, custom conv......" << *chatty <<endl;
147 cout << "pointer, custom conv......" << chatty.get() <<endl;
148
149 chatty.reset();
150 cout << "smart-ptr, NULL pointee....." << chatty <<endl;
151 cout << "pointer, NULL pointee....." << chatty.get() <<endl;
152 }
153 };
154
155 LAUNCHER (FormatCOUT_test, "unit common");
156
157
158}} // namespace util::test
159
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition p.hpp:77
#define ANALYSE(_TYPE_)
Automatically use custom string conversion in C++ stream output.
Generic building block for tree shaped (meta)data structures.
unsigned int uint
Definition integral.hpp:29
Simple and lightweight helpers for metaprogramming and type detection.
P< X > makeP(ARGS &&... ctorArgs)
Helper to create and manage by lib::P.
Definition p.hpp:142
Test runner and basic definitions for tests.
std::is_convertible< T, const char * > BasicallyCString
Customised refcounting smart pointer.
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
generic data element node within a tree
Definition gen-node.hpp:224
detect possibility of a conversion to string.
types able to be lexically converted to string representation
Definition trait.hpp:377
detect various flavours of string / text data
Definition trait.hpp:354
compare for unadorned base type, disregarding const and references
Definition trait.hpp:337
when to use custom string conversions for output streams
Definition trait.hpp:400
Helpers for type detection, type rewriting and metaprogramming.