Hamcrest-Qt  0.0.1
Hamcrest matchers for C++/Qt
 All Classes Namespaces Functions
substringmatcher.h
1 #ifndef HAMCRESTQT_SUBSTRINGMATCHER_H
2 #define HAMCRESTQT_SUBSTRINGMATCHER_H
3 
4 #include <QString>
5 #include "basematcher.h"
6 
7 namespace HamcrestQt {
8 
9 class SubstringMatcher : public BaseMatcher<QString>
10 {
11 public:
12  virtual bool matches(const QString &item) const
13  {
14  return evalSubstringOf(item);
15  }
16 
17  virtual void describeTo(Description &description) const
18  {
19  description.appendText("a string ")
20  .appendText(relationship())
21  .appendText(" ")
22  .appendValue(substring);
23  }
24 
25  virtual void describeMismatch(const QString &item, Description &description) const
26  {
27  description.appendText("was \"").appendText(item).appendText("\"");
28  }
29 
30 protected:
31  explicit SubstringMatcher(const QString &str) : substring(str) {}
32 
33  virtual bool evalSubstringOf(const QString &str) const = 0;
34  virtual QString relationship() const = 0;
35 
36 protected:
37  QString substring;
38 };
39 
40 } // namespace HamcrestQt
41 
42 #endif // HAMCRESTQT_SUBSTRINGMATCHER_H
A description of a Matcher.
Definition: description.h:17
virtual void describeTo(Description &description) const
Generates a description of the object.
Definition: substringmatcher.h:17
virtual bool matches(const QString &item) const
Evaluates the matcher for argument item.
Definition: substringmatcher.h:12
Description & appendValue(const T &value)
Appends an arbitrary value to the description.
Definition: description.h:90
Definition: substringmatcher.h:9
BaseClass for all Matcher implementations.
Definition: basematcher.h:17
virtual Description & appendText(const QString &text)=0
Appends some plain text to the description.
virtual void describeMismatch(const QString &item, Description &description) const
Generate a description of why the matcher has not accepted the item.
Definition: substringmatcher.h:25