Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
type-display-test.cpp
Go to the documentation of this file.
1/*
2 TypeDisplay(Test) - human readable simplified display of C++ types
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#include "lib/meta/util.hpp"
21#include "lib/format-cout.hpp"
22
23#include <string>
24
25
26using std::string;
27
28
29namespace lib {
30namespace meta{
31namespace test{
32
33 namespace { // test fixture
34
35 template<class T>
36 struct Outer
37 {
38 struct Inner { };
39
40 static const T*
42 {
43 return nullptr;
44 }
45 };
46
47 struct Space { };
48
49 auto CHALLENGE_1 = "some::arbitrary::BullShit<oh::RLY>*";
50 auto CHALLENGE_2 = "lib::Contrived<lib::meta::Barely,true>::ClusterFuck<const std::string& (const std::vector<steam::mobject::oh::RLY* const>)>";
51 auto CHALLENGE_3 = "std::function<special::(anonymous namespace)::Shit(lib::P<steam::asset::Clip, std::shared_ptr<steam::asset::Clip>>)>";
52
53 }//(end)fixture
54
55
56
57
58 /***************************************************************************/
85 : public Test
86 {
87 void
88 run (Arg)
89 {
90 cout << "-----input----------------------"<<endl;
91 cout << CHALLENGE_1 <<endl;
92 cout << CHALLENGE_2 <<endl;
93 cout << CHALLENGE_3 <<endl;
94
95 cout << "-----human-readable-------------"<<endl;
96 cout << humanReadableTypeID (CHALLENGE_1) <<endl;
97 cout << humanReadableTypeID (CHALLENGE_2) <<endl;
98 cout << humanReadableTypeID (CHALLENGE_3) <<endl;
99
100 cout << "-----primary-component----------" <<endl;
101 cout << primaryTypeComponent (CHALLENGE_1) <<endl;
102 cout << primaryTypeComponent (CHALLENGE_2) <<endl;
103 cout << primaryTypeComponent (CHALLENGE_3) <<endl;
104
105 cout << "-----sanitised-ID---------------" <<endl;
106 cout << sanitisedFullTypeName (CHALLENGE_1) <<endl;
107 cout << sanitisedFullTypeName (CHALLENGE_2) <<endl;
108 cout << sanitisedFullTypeName (CHALLENGE_3) <<endl;
109
110
112 auto magic = ship.cloak;
113 CHECK (typeStr(&magic) == "Space const* (*)(Outer<Space>::Inner&&)");
114 CHECK (typeSymbol(&magic) == "Function");
115
116 CHECK (typeStr <Outer<decltype(this)>::Inner>() == "Outer<test::TypeDisplay_test*>::Inner");
117 CHECK (typeSymbol<Outer<decltype(this)>::Inner>() == "Inner" );
118
119 CHECK (primaryTypeComponent("") == "void" );
120 CHECK (primaryTypeComponent("Sym&") == "Sym" );
121 CHECK (primaryTypeComponent("Sym const *") == "Sym" );
122 CHECK (primaryTypeComponent("Sym const * const") == "Sym" );
123 CHECK (primaryTypeComponent("Sym§$<>%&/'* const") == "Sym§$<>%&/'"); // adornments stripped, but rest retained as-is
124 CHECK (primaryTypeComponent("Sym§$<>%&/)&* const") == "Function" ); // types ending with braces are classified as "Function"
125 CHECK (primaryTypeComponent("Sym <§$&ää>") == "Sym " ); // note the trailing whitespace
126 CHECK (primaryTypeComponent("One<§$&ää>::Two") == "Two" );
127 CHECK (primaryTypeComponent("One::Two<§$&ää>") == "Two" );
128 CHECK (primaryTypeComponent("One::Two<§$&ää>") == "Two" );
129 CHECK (primaryTypeComponent("Sym<<xx>") == "Sym<" ); // unbalanced braces
130 CHECK (primaryTypeComponent("Sym<>xx>") == "void" ); // opening brace never found
131 CHECK (primaryTypeComponent("<x>xx>*") == "void" );
132 CHECK (primaryTypeComponent("<x<xx>*") == "<x" );
133
134 CHECK (sanitisedSymbol("bäälü9a/(6f*a☹☢☀s☭el_88☠") == "blafasel_88"); // note: picking up only valid identifier fragments
135
136 }
137 };
138
139 LAUNCHER (TypeDisplay_test, "unit common");
140
141
142}}} // namespace lib::meta::test
143
Automatically use custom string conversion in C++ stream output.
Simple and lightweight helpers for metaprogramming and type detection.
string sanitisedFullTypeName(lib::Literal rawName)
build a sanitised ID from full type name
std::string typeStr(TY const *obj=nullptr) noexcept
failsafe human readable type display
string humanReadableTypeID(Literal rawType)
pretty-print an internal C++ type representation
string primaryTypeComponent(Literal rawType)
extract core name component from a raw type spec
enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition meta/util.hpp:87
string sanitisedSymbol(string const &text)
condense a string and retain only valid identifiers
Implementation namespace for support and library code.
Test runner and basic definitions for tests.
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116