Lumiera  0.pre.03
»edit your freedom«
util-parse-bool-test.cpp
Go to the documentation of this file.
1 /*
2  UtilParseBool(Test) - derive bool value from text form
3 
4  Copyright (C) Lumiera.org
5  2018, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
28 #include "lib/test/run.hpp"
29 #include "lib/test/test-helper.hpp"
30 #include "lib/util.hpp"
31 
32 #include <string>
33 
34 
35 using lumiera::error::LUMIERA_ERROR_INVALID;
36 
37 
38 namespace util {
39 namespace test {
40 
41 
42  class UtilParseBool_test : public Test
43  {
44  virtual void
45  run (Arg)
46  {
47  CHECK (boolVal ("true"));
48  CHECK (boolVal ("True"));
49  CHECK (boolVal ("TRUE"));
50  CHECK (boolVal ("tRuE"));
51  CHECK (boolVal ("yes"));
52  CHECK (boolVal ("Yes"));
53  CHECK (boolVal ("YES"));
54  CHECK (boolVal ("1"));
55  CHECK (boolVal ("+"));
56 
57  CHECK (not boolVal ("false"));
58  CHECK (not boolVal ("False"));
59  CHECK (not boolVal ("FALSE"));
60  CHECK (not boolVal ("fAlSe"));
61  CHECK (not boolVal ("no"));
62  CHECK (not boolVal ("No"));
63  CHECK (not boolVal ("NO"));
64  CHECK (not boolVal ("0"));
65  CHECK (not boolVal ("-"));
66 
67  CHECK (boolVal ("yes "));
68  CHECK (boolVal (" Yes"));
69  CHECK (boolVal (" + "));
70  CHECK (not boolVal (" \n0 "));
71 
72  VERIFY_ERROR (INVALID, boolVal("") );
73  VERIFY_ERROR (INVALID, boolVal(" ") );
74  VERIFY_ERROR (INVALID, boolVal("Ja") );
75  VERIFY_ERROR (INVALID, boolVal("truth") );
76  VERIFY_ERROR (INVALID, boolVal("falsehood"));
77  VERIFY_ERROR (INVALID, boolVal("11") );
78  VERIFY_ERROR (INVALID, boolVal("+1") );
79  VERIFY_ERROR (INVALID, boolVal("↯") );
80 
81 
82  CHECK (isYes ("true"));
83  CHECK (isYes ("True"));
84  CHECK (isYes ("tRuE"));
85  CHECK (isYes ("TRUE"));
86  CHECK (isYes ("yes"));
87  CHECK (isYes ("Yes"));
88  CHECK (isYes ("1"));
89  CHECK (isYes ("+"));
90 
91  CHECK (isYes (" True "));
92  CHECK (isYes (" \n\n 1 \t "));
93 
94  CHECK (not isYes (" True and False"));
95  CHECK (not isYes ("+2"));
96  CHECK (not isYes ("no"));
97  CHECK (not isYes ("1010"));
98  CHECK (not isYes ("↯"));
99  CHECK (not isYes (" "));
100  CHECK (not isYes (""));
101  }
102  };
103 
104  LAUNCHER (UtilParseBool_test, "unit common");
105 
106 
107 }} // namespace util::test
108 
bool isYes(string const &textForm) noexcept
check the given text if it can be interpreted as affirmative answer (bool true).
Definition: util.cpp:116
Definition: run.hpp:49
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
bool boolVal(string const &textForm)
interpret text representation of a boolean value.
Definition: util.cpp:107
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
A collection of frequently used helper functions to support unit testing.