diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2012-06-17 12:46:13 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2012-06-17 12:46:13 +0000 |
commit | d45f7b6b5dd36b4732dff82ab7c8a856a7b36ae0 (patch) | |
tree | e0a6d00ad7a21a36ffa447e962cbe57479cf1d84 /unittests | |
parent | b4bec53f367614132290425cb4805a2d5696153a (diff) | |
download | external_llvm-d45f7b6b5dd36b4732dff82ab7c8a856a7b36ae0.zip external_llvm-d45f7b6b5dd36b4732dff82ab7c8a856a7b36ae0.tar.gz external_llvm-d45f7b6b5dd36b4732dff82ab7c8a856a7b36ae0.tar.bz2 |
Bring the return value of SmallVector::insert in line with std::vector::insert.
It always returns the iterator for the first inserted element, or the passed in
iterator if the inserted range was empty. Flesh out the unit test more and fix
all the cases it uncovered so far.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158645 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/ADT/SmallVectorTest.cpp | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/unittests/ADT/SmallVectorTest.cpp b/unittests/ADT/SmallVectorTest.cpp index 8f6d2f4..d35e5bc 100644 --- a/unittests/ADT/SmallVectorTest.cpp +++ b/unittests/ADT/SmallVectorTest.cpp @@ -342,7 +342,9 @@ TEST_F(SmallVectorTest, InsertTest) { SCOPED_TRACE("InsertTest"); makeSequence(theVector, 1, 3); - theVector.insert(theVector.begin() + 1, Constructable(77)); + VectorType::iterator I = + theVector.insert(theVector.begin() + 1, Constructable(77)); + EXPECT_EQ(theVector.begin() + 1, I); assertValuesInOrder(theVector, 4u, 1, 77, 2, 3); } @@ -351,24 +353,48 @@ TEST_F(SmallVectorTest, InsertRepeatedTest) { SCOPED_TRACE("InsertRepeatedTest"); makeSequence(theVector, 10, 15); - theVector.insert(theVector.begin() + 1, 2, Constructable(16)); + VectorType::iterator I = + theVector.insert(theVector.begin() + 1, 2, Constructable(16)); + EXPECT_EQ(theVector.begin() + 1, I); assertValuesInOrder(theVector, 8u, 10, 16, 16, 11, 12, 13, 14, 15); + // Insert at end. + I = theVector.insert(theVector.end(), 2, Constructable(16)); + EXPECT_EQ(theVector.begin() + 8, I); + assertValuesInOrder(theVector, 10u, 10, 16, 16, 11, 12, 13, 14, 15, 16, 16); + + // Empty insert. EXPECT_EQ(theVector.end(), theVector.insert(theVector.end(), 0, Constructable(42))); + EXPECT_EQ(theVector.begin() + 1, + theVector.insert(theVector.begin() + 1, 0, Constructable(42))); } // Insert range. TEST_F(SmallVectorTest, InsertRangeTest) { - SCOPED_TRACE("InsertRepeatedTest"); + SCOPED_TRACE("InsertRangeTest"); + + Constructable Arr[3] = + { Constructable(77), Constructable(77), Constructable(77) }; makeSequence(theVector, 1, 3); - theVector.insert(theVector.begin() + 1, 3, Constructable(77)); + VectorType::iterator I = + theVector.insert(theVector.begin() + 1, Arr, Arr+3); + EXPECT_EQ(theVector.begin() + 1, I); assertValuesInOrder(theVector, 6u, 1, 77, 77, 77, 2, 3); + // Insert at end. + I = theVector.insert(theVector.end(), Arr, Arr+3); + EXPECT_EQ(theVector.begin() + 6, I); + assertValuesInOrder(theVector, 9u, 1, 77, 77, 77, 2, 3, 77, 77, 77); + + // Empty insert. EXPECT_EQ(theVector.end(), theVector.insert(theVector.end(), theVector.begin(), theVector.begin())); + EXPECT_EQ(theVector.begin() + 1, theVector.insert(theVector.begin() + 1, + theVector.begin(), + theVector.begin())); } // Comparison tests. |