Skip to content

Commit

Permalink
update r837
Browse files Browse the repository at this point in the history
  • Loading branch information
srz-zumix committed May 11, 2015
1 parent d831db8 commit 4d30a32
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Changes for 1.12.0:

** 追加
* Matcher に MatchesRegex,ContainsRegex を追加
* --iutest_filter=@filter.txt のようにファイルからフィルター指定できるように対応
* Visual Studio 2015 RC 対応
* twilio 対応
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ Documentation
--------------------------------------------------

doc/index.html
[online document](http://iutest.sourceforge.jp/doc/index.html)
[online document](http://iutest.osdn.jp/doc/index.html)


Project page
--------------------------------------------------

[Project page](http://iutest.sourceforge.jp/)
[Project page](http://iutest.osdn.jp/)
[Github](https://github.com/srz-zumix/iutest)
[Google Group](https://groups.google.com/forum/?fromgroups#!forum/g-iutest)

Expand Down
2 changes: 1 addition & 1 deletion doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = iutest
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 1.11.99.5
PROJECT_NUMBER = 1.11.99.6

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
12 changes: 9 additions & 3 deletions include/gtest/switch/iutest_switch_gmock.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//======================================================================
//-----------------------------------------------------------------------
/**
* @file iutest_switch_skip.hpp
* @brief IUTEST_SKIP 切り替え定義 ファイル
* @file iutest_switch_gmock.hpp
* @brief gmock 切り替え定義 ファイル
*
* @author t.shirayanagi
* @par copyright
* Copyright (C) 2012-2014, Takazumi Shirayanagi\n
* Copyright (C) 2012-2015, Takazumi Shirayanagi\n
* This software is released under the new BSD License,
* see LICENSE
*/
Expand Down Expand Up @@ -34,6 +34,7 @@
#undef IUTEST_HAS_MATCHERS
#undef IUTEST_HAS_MATCHER_ALLOF_AND_ANYOF
#undef IUTEST_HAS_MATCHER_ELEMENTSARE
#undef IUTEST_HAS_MATCHER_REGEX

#endif

Expand All @@ -45,6 +46,7 @@
#define IUTEST_HAS_MATCHERS 1
#define IUTEST_HAS_MATCHER_ALLOF_AND_ANYOF 1
#define IUTEST_HAS_MATCHER_ELEMENTSARE 1
#define IUTEST_HAS_MATCHER_REGEX 1

#define IUTEST_ASSERT_THAT ASSERT_THAT
#define IUTEST_EXPECT_THAT EXPECT_THAT
Expand All @@ -61,6 +63,7 @@
#define IUTEST_HAS_MATCHERS 0
#define IUTEST_HAS_MATCHER_ALLOF_AND_ANYOF 0
#define IUTEST_HAS_MATCHER_ELEMENTSARE 0
#define IUTEST_HAS_MATCHER_REGEX 0

#endif

Expand Down Expand Up @@ -110,6 +113,9 @@ namespace matchers
using ::testing::ElementsAre;
using ::testing::ElementsAreArray;

using ::testing::MatchesRegex;
using ::testing::ContainsRegex;

using ::testing::AllOf;
using ::testing::AnyOf;

Expand Down
11 changes: 10 additions & 1 deletion include/iutest_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @author t.shirayanagi
* @par copyright
* Copyright (C) 2012-2014, Takazumi Shirayanagi\n
* Copyright (C) 2012-2015, Takazumi Shirayanagi\n
* This software is released under the new BSD License,
* see LICENSE
*/
Expand Down Expand Up @@ -235,6 +235,15 @@
# endif
#endif

#if !defined(IUTEST_HAS_MATCHER_REGEX)
//! ::iutest::MatchesRegex, ::iutest::ContainsRegex matcher が使用可能かどうか
# if IUTEST_HAS_CXX_HDR_REGEX && IUTEST_HAS_MATCHERS
# define IUTEST_HAS_MATCHER_REGEX 1
# else
# define IUTEST_HAS_MATCHER_REGEX 0
# endif
#endif

#if !defined(IUTEST_HAS_MATCHER_ALLOF_AND_ANYOF)
//! ::iutest::AllOf, ::iutest::AnyOf matcher が使用可能かどうか
# if IUTEST_HAS_TUPLE && IUTEST_HAS_MATCHERS
Expand Down
77 changes: 76 additions & 1 deletion include/iutest_matcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @author t.shirayanagi
* @par copyright
* Copyright (C) 2014, Takazumi Shirayanagi\n
* Copyright (C) 2014-2015, Takazumi Shirayanagi\n
* This software is released under the new BSD License,
* see LICENSE
*/
Expand Down Expand Up @@ -1527,6 +1527,59 @@ class AnythingMatcher : public IMatcher
IUTEST_PP_DISALLOW_ASSIGN(AnythingMatcher);
};

#if IUTEST_HAS_MATCHER_REGEX

/**
* @brief Regex matcher
*/
class RegexMatcher : public IMatcher
{
public:
RegexMatcher(const detail::iuRegex& expected, bool full_match) : m_expected(expected), m_full_match(full_match) {}

public:
template<typename U>
AssertionResult operator ()(const U& actual) const
{
if( Regex(actual) ) return AssertionSuccess();
return AssertionFailure() << WhichIs();
}

public:
::std::string WhichIs(void) const IUTEST_CXX_OVERRIDE
{
iu_global_format_stringstream strm;
if( m_full_match )
{
strm << "MatchesRegex: " << m_expected.pattern();
}
else
{
strm << "ContainsRegex: " << m_expected.pattern();
}
return strm.str();
}
private:
bool Regex(const char* actual)
{
return m_full_match ? m_expected.FullMatch(actual)
: m_expected.PartialMatch(actual);
}
bool Regex(const ::std::string& actual)
{
return m_full_match ? m_expected.FullMatch(actual.c_str())
: m_expected.PartialMatch(actual.c_str());
}

private:
IUTEST_PP_DISALLOW_ASSIGN(RegexMatcher);

detail::iuRegex m_expected;
bool m_full_match;
};

#endif

#if IUTEST_HAS_MATCHER_ALLOF_AND_ANYOF

/**
Expand Down Expand Up @@ -2214,6 +2267,28 @@ detail::AnyMatcher<T> A(void) { return detail::AnyMatcher<T>(); }
*/
const detail::AnythingMatcher _;

#if IUTEST_HAS_MATCHER_REGEX

/**
* @ingroup MATCHERS
* @brief Make MatchesRegex matcher
*/
inline detail::RegexMatcher MatchesRegex(const ::std::string& str)
{
return detail::RegexMatcher(detail::iuRegex(str), true);
}

/**
* @ingroup MATCHERS
* @brief Make ContainsRegex matcher
*/
inline detail::RegexMatcher ContainsRegex(const ::std::string& str)
{
return detail::RegexMatcher(detail::iuRegex(str), false);
}

#endif

#if IUTEST_HAS_MATCHER_ALLOF_AND_ANYOF

#if IUTEST_HAS_VARIADIC_TEMPLATES
Expand Down
7 changes: 4 additions & 3 deletions include/iutest_ver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@

//======================================================================
// define
#define IUTEST_VER 0x01119905u //!< iutest version 1.11.99.5
#define IUTEST_VER 0x01119906u //!< iutest version 1.11.99.6
#define IUTEST_MAJORVER 0x01u //!< Major Version
#define IUTEST_MINORVER 0x11u //!< Minor Version
#define IUTEST_BUILD 0x99u //!< Build
#define IUTEST_REVISION 0x05u //!< Revision
#define IUTEST_REVISION 0x06u //!< Revision

/**
* @mainpage
* @sa @b ProjectHome \n
* sourceforge : http://sourceforge.jp/projects/iutest/ \n
* OSDN : http://osdn.jp/projects/iutest/ \n
* github : https://github.com/srz-zumix/iutest \n
* google group: https://groups.google.com/forum/?fromgroups#!forum/g-iutest \n
*
Expand Down Expand Up @@ -115,6 +115,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<ul>
<li>v1.12.0.0
<ul>
<li>Matcher に MatchesRegex,ContainsRegex を追加</li>
<li>--iutest_filter=@filter.txt のようにファイルからフィルター指定できるように対応</li>
<li>Visual Studio 2015 Preview 対応</li>
<li>twilio 対応</li>
Expand Down
32 changes: 31 additions & 1 deletion test/iutest_matcher_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @author t.shirayanagi
* @par copyright
* Copyright (C) 2014, Takazumi Shirayanagi\n
* Copyright (C) 2014-2015, Takazumi Shirayanagi\n
* This software is released under the new BSD License,
* see LICENSE
*/
Expand Down Expand Up @@ -567,6 +567,36 @@ IUTEST(MatcherFailure, ElementsAre)

#endif

#if IUTEST_HAS_MATCHER_REGEX

IUTEST(Matcher, MatchesRegex)
{
::std::string s = "greeeeeen";
IUTEST_EXPECT_THAT(s, MatchesRegex("gre+n"));
IUTEST_EXPECT_THAT("hogeeeeeet", MatchesRegex("hoge+t"));
}

IUTEST(Matcher, ContainsRegex)
{
::std::string s = "greeeeeen";
IUTEST_EXPECT_THAT(s, MatchesRegex("e"));
IUTEST_EXPECT_THAT("hogeeeeeet", ContainsRegex("hoge+"));
}

IUTEST(MatcherFailure, MatchesRegex)
{
CHECK_FAILURE( IUTEST_ASSERT_THAT("hogeeeeeet"
, MatchesRegex("hoge+"), "MatchesRegex: hoge+");
}

IUTEST(MatcherFailure, ContainsRegex)
{
CHECK_FAILURE( IUTEST_ASSERT_THAT("hoge"
, MatchesRegex("hoge+"), "ContainsRegex: hoge+");
}

#endif


#if IUTEST_HAS_MATCHER_ALLOF_AND_ANYOF

Expand Down

0 comments on commit 4d30a32

Please sign in to comment.