21 #ifndef _GRINGO_TEST_TESTS_HH
22 #define _GRINGO_TEST_TESTS_HH
24 #include <cppunit/TestFixture.h>
25 #include <cppunit/TestAssert.h>
26 #include <cppunit/extensions/HelperMacros.h>
30 #include <unordered_map>
39 std::ostream &operator<<(std::ostream &out, std::unique_ptr<T>
const &
x);
41 std::ostream &
operator<<(std::ostream &
out, std::vector<T...>
const &
x);
43 std::ostream &
operator<<(std::ostream &out, std::set<T...>
const &x);
44 template <
class T,
class U>
45 std::ostream &operator<<(std::ostream &out, std::pair<T, U>
const &
x);
47 std::ostream &
operator<<(std::ostream &out, std::tuple<T...>
const &x);
49 std::ostream &
operator<<(std::ostream &out, std::map<T...>
const &x);
51 std::ostream &
operator<<(std::ostream &out, std::unordered_map<T...>
const &x);
64 std::ostream &operator<<(std::ostream &out, std::unique_ptr<T>
const &
x) {
69 template <
class T,
class U>
70 std::ostream &operator<<(std::ostream &out, std::pair<T, U>
const &
x) {
71 out <<
"(" <<
x.first <<
"," <<
x.second <<
")";
76 std::ostream &
operator<<(std::ostream &
out, std::vector<T...>
const &vec) {
78 auto it(vec.begin()),
end(vec.end());
81 for (++it; it !=
end; ++it) { out <<
"," << *it; }
90 auto it(x.begin()),
end(x.end());
93 for (++it; it !=
end; ++it) { out <<
"," << *it; }
103 template <
class... T>
105 out << std::get<
sizeof...(T) - N>(x) <<
",";
106 print<N-1>()(out, x);
111 template <
class... T>
113 out << std::get<
sizeof...(T) - 1>(x);
118 template <
class... T>
119 void operator()(std::ostream &, std::tuple<T...>
const &)
const { }
123 template <
class... T>
131 template <
class... T>
133 std::vector<std::pair<std::string, std::string>> vals;
134 for (
auto const &y : x) { vals.emplace_back(
to_string(y.first),
to_string(y.second)); }
135 std::sort(vals.begin(), vals.end());
137 auto it = vals.begin(),
end = vals.end();
139 out << it->first <<
":" << it->second;
140 for (++it; it !=
end; ++it) { out <<
"," << it->first <<
":" << it->second; }
146 template <
class... T>
149 auto it = x.begin(),
end = x.end();
151 out << it->first <<
":" << it->second;
152 for (++it; it !=
end; ++it) { out <<
"," << it->first <<
":" << it->second; }
160 std::stringstream ss;
169 inline std::string &
replace_all(std::string &haystack, std::string
const &needle, std::string
const &replace) {
172 index = haystack.find(needle, index);
173 if (index == std::string::npos)
break;
174 haystack.replace(index, needle.length(), replace);
175 index += replace.length();
180 inline std::string
replace_all(std::string &&haystack, std::string
const &needle, std::string
const &replace) {
182 return std::move(haystack);
187 namespace Gringo {
namespace Test {
193 template <int,
class, int,
class...>
196 template <
class, int, int, int,
class...>
199 template <
class V,
int S1,
int S2,
int S3,
class A,
class... T>
203 emplacer<V, S1-1, S2, S3, T..., A>()(v, std::forward<T>(args)..., std::forward<A>(
a));
207 template <
class V,
int S2,
int S3,
class A,
class... T>
211 emplacer<V, 0, S2-1, S3, T...>()(v, std::forward<T>(args)...);
215 template <
class V,
int S3,
class A,
class... T>
219 emplacer<V, 0, 0, S3-1, T..., A>()(v, std::forward<T>(args)..., std::forward<A>(
a));
223 template <
class V,
class A,
class... T>
226 v.emplace_back(std::forward<A>(
a), std::forward<T>(args)...);
230 template <
int N,
class V,
int I,
class A,
class... T>
233 walker<N, V, I-1, T...>()(v, std::forward<T>(args)...);
237 template <
int N,
class V,
class A,
class... T>
240 emplacer<V, N,
sizeof...(T)+1-N, N, A, T...>()(v, std::forward<A>(
a), std::forward<T>(args)...);
241 walker<N, V, N-1, T...>()(v, std::forward<T>(args)...);
246 template <
class V,
class A,
class... T>
249 v.emplace_back(std::forward<A>(
a));
250 walker<1, V, 0, T...>()(v, std::forward<T>(args)...);
254 template <
int N,
class V,
int I>
262 template <
class V,
class... T>
269 template <
int N,
class V,
class... T>
282 : messages_(messages) { }
288 virtual void print(std::string
const &msg) { messages_.emplace_back(msg); }
291 std::vector<std::string> &messages_;
306 std::unique_ptr<MessagePrinter> oldPrinter;
318 #endif // _GRINGO_TEST_TESTS_HH
void operator()(std::ostream &out, std::tuple< T...> const &x) const
Definition: tests.hh:104
std::ostream & operator<<(std::ostream &out, std::unique_ptr< T > const &x)
Definition: tests.hh:64
std::ostream & operator<<(std::ostream &out, TestFlyweight::Dummy const &dummy)
Definition: flyweight.cc:216
std::string to_string(T const &x)
Definition: tests.hh:159
V init(T &&...args)
Definition: tests.hh:263
virtual void print(std::string const &msg)
Definition: tests.hh:288
tuple a
Definition: pyclingo.py:6
void operator()(V &v, A &&a, T &&...args) const
Definition: tests.hh:225
virtual bool hasError() const
Definition: tests.hh:285
Warnings
Definition: logger.hh:36
virtual ~TestMessagePrinter()
Definition: tests.hh:289
virtual bool check(Warnings)
Definition: tests.hh:284
virtual void disable(Warnings)
Definition: tests.hh:287
void clear()
Definition: tests.hh:300
TestMessagePrinter(std::vector< std::string > &messages)
Definition: tests.hh:281
std::unique_ptr< MessagePrinter > & message_printer()
Definition: logger.hh:78
Messages()
Definition: tests.hh:296
void operator()(V &v, A &&a, T &&...args) const
Definition: tests.hh:201
~Messages()
Definition: tests.hh:301
void operator()(V &v, A &&a, T &&...args) const
Definition: tests.hh:248
std::string & replace_all(std::string &haystack, std::string const &needle, std::string const &replace)
Definition: tests.hh:169
void operator()(std::ostream &, std::tuple< T...> const &) const
Definition: tests.hh:119
void operator()(V &) const
Definition: tests.hh:257
void operator()(std::ostream &out, std::tuple< T...> const &x) const
Definition: tests.hh:112
void operator()(V &v, A &&a, T &&...args) const
Definition: tests.hh:239
int x
Definition: utility.cc:65
uint32 index(Var v)
Returns the index of variable v.
Definition: literal.h:173
Errors
Definition: logger.hh:46
virtual bool check(Errors)
Definition: tests.hh:283
std::vector< std::string > messages
Definition: tests.hh:304
void operator()(V &v, A &&, T &&...args) const
Definition: tests.hh:209
void operator()(V &v, A &&, T &&...args) const
Definition: tests.hh:232
LparseOutputter & out
Definition: output.cc:685
virtual void enable(Warnings)
Definition: tests.hh:286
void operator()(V &v, A &&a, T &&...args) const
Definition: tests.hh:217
int end
Definition: literals.cc:62