|
|
|
@ -57,6 +57,8 @@ GTEST_API_ string JoinAsTuple(const Strings& fields); |
|
|
|
|
|
|
|
|
|
namespace gmock_matchers_test { |
|
|
|
|
|
|
|
|
|
using std::greater; |
|
|
|
|
using std::less; |
|
|
|
|
using std::list; |
|
|
|
|
using std::make_pair; |
|
|
|
|
using std::map; |
|
|
|
@ -118,6 +120,8 @@ using testing::StrNe; |
|
|
|
|
using testing::Truly; |
|
|
|
|
using testing::TypedEq; |
|
|
|
|
using testing::Value; |
|
|
|
|
using testing::WhenSorted; |
|
|
|
|
using testing::WhenSortedBy; |
|
|
|
|
using testing::_; |
|
|
|
|
using testing::internal::DummyMatchResultListener; |
|
|
|
|
using testing::internal::ExplainMatchFailureTupleTo; |
|
|
|
@ -3725,6 +3729,83 @@ TEST(ContainerEqExtraTest, CopiesNativeArrayParameter) { |
|
|
|
|
EXPECT_THAT(a1, m); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(WhenSortedByTest, WorksForEmptyContainer) { |
|
|
|
|
const vector<int> numbers; |
|
|
|
|
EXPECT_THAT(numbers, WhenSortedBy(less<int>(), ElementsAre())); |
|
|
|
|
EXPECT_THAT(numbers, Not(WhenSortedBy(less<int>(), ElementsAre(1)))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(WhenSortedByTest, WorksForNonEmptyContainer) { |
|
|
|
|
vector<unsigned> numbers; |
|
|
|
|
numbers.push_back(3); |
|
|
|
|
numbers.push_back(1); |
|
|
|
|
numbers.push_back(2); |
|
|
|
|
numbers.push_back(2); |
|
|
|
|
EXPECT_THAT(numbers, WhenSortedBy(greater<unsigned>(), |
|
|
|
|
ElementsAre(3, 2, 2, 1))); |
|
|
|
|
EXPECT_THAT(numbers, Not(WhenSortedBy(greater<unsigned>(), |
|
|
|
|
ElementsAre(1, 2, 2, 3)))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(WhenSortedByTest, WorksForNonVectorContainer) { |
|
|
|
|
list<string> words; |
|
|
|
|
words.push_back("say"); |
|
|
|
|
words.push_back("hello"); |
|
|
|
|
words.push_back("world"); |
|
|
|
|
EXPECT_THAT(words, WhenSortedBy(less<string>(), |
|
|
|
|
ElementsAre("hello", "say", "world"))); |
|
|
|
|
EXPECT_THAT(words, Not(WhenSortedBy(less<string>(), |
|
|
|
|
ElementsAre("say", "hello", "world")))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(WhenSortedByTest, WorksForNativeArray) { |
|
|
|
|
const int numbers[] = { 1, 3, 2, 4 }; |
|
|
|
|
const int sorted_numbers[] = { 1, 2, 3, 4 }; |
|
|
|
|
EXPECT_THAT(numbers, WhenSortedBy(less<int>(), ElementsAre(1, 2, 3, 4))); |
|
|
|
|
EXPECT_THAT(numbers, WhenSortedBy(less<int>(), |
|
|
|
|
ElementsAreArray(sorted_numbers))); |
|
|
|
|
EXPECT_THAT(numbers, Not(WhenSortedBy(less<int>(), ElementsAre(1, 3, 2, 4)))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(WhenSortedByTest, CanDescribeSelf) { |
|
|
|
|
const Matcher<vector<int> > m = WhenSortedBy(less<int>(), ElementsAre(1, 2)); |
|
|
|
|
EXPECT_EQ("(when sorted) has 2 elements where\n" |
|
|
|
|
"element #0 is equal to 1,\n" |
|
|
|
|
"element #1 is equal to 2", |
|
|
|
|
Describe(m)); |
|
|
|
|
EXPECT_EQ("(when sorted) doesn't have 2 elements, or\n" |
|
|
|
|
"element #0 isn't equal to 1, or\n" |
|
|
|
|
"element #1 isn't equal to 2", |
|
|
|
|
DescribeNegation(m)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(WhenSortedByTest, ExplainsMatchResult) { |
|
|
|
|
const int a[] = { 2, 1 }; |
|
|
|
|
EXPECT_EQ("which is { 1, 2 } when sorted, whose element #0 doesn't match", |
|
|
|
|
Explain(WhenSortedBy(less<int>(), ElementsAre(2, 3)), a)); |
|
|
|
|
EXPECT_EQ("which is { 1, 2 } when sorted", |
|
|
|
|
Explain(WhenSortedBy(less<int>(), ElementsAre(1, 2)), a)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// WhenSorted() is a simple wrapper on WhenSortedBy(). Hence we don't
|
|
|
|
|
// need to test it as exhaustively as we test the latter.
|
|
|
|
|
|
|
|
|
|
TEST(WhenSortedTest, WorksForEmptyContainer) { |
|
|
|
|
const vector<int> numbers; |
|
|
|
|
EXPECT_THAT(numbers, WhenSorted(ElementsAre())); |
|
|
|
|
EXPECT_THAT(numbers, Not(WhenSorted(ElementsAre(1)))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(WhenSortedTest, WorksForNonEmptyContainer) { |
|
|
|
|
list<string> words; |
|
|
|
|
words.push_back("3"); |
|
|
|
|
words.push_back("1"); |
|
|
|
|
words.push_back("2"); |
|
|
|
|
words.push_back("2"); |
|
|
|
|
EXPECT_THAT(words, WhenSorted(ElementsAre("1", "2", "2", "3"))); |
|
|
|
|
EXPECT_THAT(words, Not(WhenSorted(ElementsAre("3", "1", "2", "2")))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Tests IsReadableTypeName().
|
|
|
|
|
|
|
|
|
|
TEST(IsReadableTypeNameTest, ReturnsTrueForShortNames) { |
|
|
|
|