LeechCraft 0.6.70-17609-g3dde4097dd
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
eithertest.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 "eithertest.h"
10#include <QtTest>
11#include <either.h>
12#include <void.h>
13#include <functor.h>
14
15QTEST_MAIN (LC::Util::EitherTest)
16
17namespace LC
18{
19namespace Util
20{
22
23 void EitherTest::testBasicLeft ()
24 {
25 const SomeEither_t left { Left (1) };
26 QCOMPARE (left.IsLeft (), true);
27 QCOMPARE (left.IsRight (), false);
28 QCOMPARE (left.GetLeft (), 1);
29
30 bool hadCaught = false;
31 try
32 {
33 left.GetRight ();
34 }
35 catch (const std::exception&)
36 {
37 hadCaught = true;
38 }
39 QCOMPARE (hadCaught, true);
40 }
41
42 void EitherTest::testBasicRight ()
43 {
44 const SomeEither_t right { "foo" };
45 QCOMPARE (right.IsLeft (), false);
46 QCOMPARE (right.IsRight (), true);
47 QCOMPARE (right.GetRight (), QString { "foo" });
48
49 bool hadCaught = false;
50 try
51 {
52 right.GetLeft ();
53 }
54 catch (const std::exception&)
55 {
56 hadCaught = true;
57 }
58 QCOMPARE (hadCaught, true);
59 }
60}
61}
const L & GetLeft() const
Definition either.h:93
bool IsRight() const
Definition either.h:88
bool IsLeft() const
Definition either.h:83
const R & GetRight() const
Definition either.h:100
Either< int, QString > SomeEither_t
Definition constants.h:15