libhext: C++ Library Documentation  1.0.8-3ad0ae4
ContainsWordsTest.h
Go to the documentation of this file.
1 // Copyright 2015, 2016 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 #include "hext/Visibility.h"
24 
25 #include <string>
26 #include <vector>
27 
28 
29 namespace hext {
30 
31 
32 /// Tests whether a string contains all given words.
33 /// Word boundaries are the beginning and end of subject, and spaces.
34 ///
35 /// @par Example:
36 /// ~~~~~~~~~~~~~
37 /// ContainsWordTest cw("foo baz bar");
38 ///
39 /// assert( cw.test("bar baz foo"));
40 /// assert( cw.test("bar boing baz foo boing"));
41 /// assert(!cw.test("foobaz bar"));
42 /// assert(!cw.test("foo bar"));
43 /// ~~~~~~~~~~~~~
45  : public Cloneable<ContainsWordsTest, ValueTest>
46 {
47 public:
48  /// Constructs a ContainsWordsTest that succeeds for subjects that contain all
49  /// words given in a string.
50  ///
51  /// @param words: A string that contains space-separated words.
52  explicit ContainsWordsTest(std::string words);
53 
54  /// Constructs a ContainsWordsTest that succeeds for subjects that contain all
55  /// words given in a vector.
56  ///
57  /// @param words: A vector of words.
58  explicit ContainsWordsTest(std::vector<std::string> words) noexcept;
59 
60  /// Returns true if subject contains all given words.
61  ///
62  /// @param subject: The string that is to be tested.
63  bool test(const char * subject) const override;
64 
65 private:
66  /// A vector of words that a subject must contain.
67  std::vector<std::string> words_;
68 };
69 
70 
71 } // namespace hext
72 
73 
74 #endif // HEXT_CONTAINS_WORDS_TEST_H_INCLUDED
75 
Defines template hext::Cloneable.
Declares hext::ValueTest.
Defines HEXT_PUBLIC and HEXT_PRIVATE.
#define HEXT_PUBLIC
Definition: Visibility.h:26
Curiously recurring template pattern that extends a base class to provide a virtual method Cloneable:...
Definition: Cloneable.h:37
Tests whether a string contains all given words.
ContainsWordsTest(std::vector< std::string > words) noexcept
Constructs a ContainsWordsTest that succeeds for subjects that contain all words given in a vector.
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.