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)
5  2018, 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/test/test-helper.hpp"
21 #include "lib/util.hpp"
22 
23 #include <string>
24 
25 
26 using lumiera::error::LUMIERA_ERROR_INVALID;
27 
28 
29 namespace util {
30 namespace test {
31 
32 
33  class UtilParseBool_test : public Test
34  {
35  virtual void
36  run (Arg)
37  {
38  CHECK (boolVal ("true"));
39  CHECK (boolVal ("True"));
40  CHECK (boolVal ("TRUE"));
41  CHECK (boolVal ("tRuE"));
42  CHECK (boolVal ("yes"));
43  CHECK (boolVal ("Yes"));
44  CHECK (boolVal ("YES"));
45  CHECK (boolVal ("1"));
46  CHECK (boolVal ("+"));
47 
48  CHECK (not boolVal ("false"));
49  CHECK (not boolVal ("False"));
50  CHECK (not boolVal ("FALSE"));
51  CHECK (not boolVal ("fAlSe"));
52  CHECK (not boolVal ("no"));
53  CHECK (not boolVal ("No"));
54  CHECK (not boolVal ("NO"));
55  CHECK (not boolVal ("0"));
56  CHECK (not boolVal ("-"));
57 
58  CHECK (boolVal ("yes "));
59  CHECK (boolVal (" Yes"));
60  CHECK (boolVal (" + "));
61  CHECK (not boolVal (" \n0 "));
62 
63  VERIFY_ERROR (INVALID, boolVal("") );
64  VERIFY_ERROR (INVALID, boolVal(" ") );
65  VERIFY_ERROR (INVALID, boolVal("Ja") );
66  VERIFY_ERROR (INVALID, boolVal("truth") );
67  VERIFY_ERROR (INVALID, boolVal("falsehood"));
68  VERIFY_ERROR (INVALID, boolVal("11") );
69  VERIFY_ERROR (INVALID, boolVal("+1") );
70  VERIFY_ERROR (INVALID, boolVal("↯") );
71 
72 
73  CHECK (isYes ("true"));
74  CHECK (isYes ("True"));
75  CHECK (isYes ("tRuE"));
76  CHECK (isYes ("TRUE"));
77  CHECK (isYes ("yes"));
78  CHECK (isYes ("Yes"));
79  CHECK (isYes ("1"));
80  CHECK (isYes ("+"));
81 
82  CHECK (isYes (" True "));
83  CHECK (isYes (" \n\n 1 \t "));
84 
85  CHECK (not isYes (" True and False"));
86  CHECK (not isYes ("+2"));
87  CHECK (not isYes ("no"));
88  CHECK (not isYes ("1010"));
89  CHECK (not isYes ("↯"));
90  CHECK (not isYes (" "));
91  CHECK (not isYes (""));
92  }
93  };
94 
95  LAUNCHER (UtilParseBool_test, "unit common");
96 
97 
98 }} // namespace util::test
99 
bool isYes(string const &textForm) noexcept
check the given text if it can be interpreted as affirmative answer (bool true).
Definition: util.cpp:107
Definition: run.hpp:40
#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:98
Simplistic 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.