All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
ContainsWordsTest.h
Go to the documentation of this file.
1 // Copyright 2015 Thomas Trapp
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef HEXT_CONTAINS_WORDS_TEST_H_INCLUDED
16 #define HEXT_CONTAINS_WORDS_TEST_H_INCLUDED
17 
18 /// @file
19 /// Declares hext::ContainsWordsTest
20 
21 #include "hext/Cloneable.h"
22 #include "hext/ValueTest.h"
23 
24 #include <string>
25 #include <vector>
26 
27 
28 namespace hext {
29 
30 
31 /// Tests whether a string contains all given words.
32 /// Word boundaries are the beginning and end of subject, and spaces.
33 ///
34 /// @par Example:
35 /// ~~~~~~~~~~~~~
36 /// ContainsWordTest cw("foo baz bar");
37 ///
38 /// assert( cw.test("bar baz foo"));
39 /// assert( cw.test("bar boing baz foo boing"));
40 /// assert(!cw.test("foobaz bar"));
41 /// assert(!cw.test("foo bar"));
42 /// ~~~~~~~~~~~~~
43 class ContainsWordsTest final : public Cloneable<ContainsWordsTest, ValueTest>
44 {
45 public:
46  /// Constructs a ContainsWordsTest that succeeds for subjects that contain all
47  /// words given in a string.
48  ///
49  /// @param words: A string that contains space-separated words.
50  explicit ContainsWordsTest(std::string words);
51 
52  /// Constructs a ContainsWordsTest that succeeds for subjects that contain all
53  /// words given in a vector.
54  ///
55  /// @param words: A vector of words.
56  explicit ContainsWordsTest(std::vector<std::string> words) noexcept;
57 
58  /// Returns true if subject contains all given words.
59  ///
60  /// @param subject: The string that is to be tested.
61  bool test(const char * subject) const override;
62 
63 private:
64  /// A vector of words that a subject must contain.
65  std::vector<std::string> words_;
66 };
67 
68 
69 } // namespace hext
70 
71 
72 #endif // HEXT_CONTAINS_WORDS_TEST_H_INCLUDED
73 
Tests whether a string contains all given words.
ContainsWordsTest(std::string words)
Constructs a ContainsWordsTest that succeeds for subjects that contain all words given in a string...
bool test(const char *subject) const override
Returns true if subject contains all given words.
Curiously recurring template pattern that extends a base class to provide a virtual method Cloneable:...
Definition: Cloneable.h:34
Declares hext::ValueTest.
Defines template hext::Cloneable.