diff options
| author | Florian Hahn <florian.hahn@arm.com> | 2018-07-24 10:32:54 +0000 |
|---|---|---|
| committer | Florian Hahn <florian.hahn@arm.com> | 2018-07-24 10:32:54 +0000 |
| commit | 6698f9b7db5a3fd56be148934bf299590ada0243 (patch) | |
| tree | 4ea7007df0d79b2eef6d1a0a8797e1b6d3f9eef2 /llvm/unittests/ADT | |
| parent | e95f4bf31bef9aa6fa854ac2ce8ef1ce8aa9cfac (diff) | |
| download | bcm5719-llvm-6698f9b7db5a3fd56be148934bf299590ada0243.tar.gz bcm5719-llvm-6698f9b7db5a3fd56be148934bf299590ada0243.zip | |
Recommit r334887: [SmallSet] Add SmallSetIterator.
Updated to make sure we properly construct/destroy SetIter if it has a
non-trivial ctors/dtors, like in MSVC.
llvm-svn: 337818
Diffstat (limited to 'llvm/unittests/ADT')
| -rw-r--r-- | llvm/unittests/ADT/SmallSetTest.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/SmallSetTest.cpp b/llvm/unittests/ADT/SmallSetTest.cpp index 7608e65674e..d78a72b38f8 100644 --- a/llvm/unittests/ADT/SmallSetTest.cpp +++ b/llvm/unittests/ADT/SmallSetTest.cpp @@ -13,6 +13,7 @@ #include "llvm/ADT/SmallSet.h" #include "gtest/gtest.h" +#include <string> using namespace llvm; @@ -68,3 +69,81 @@ TEST(SmallSetTest, Erase) { EXPECT_EQ(0u, s1.count(8)); } + +TEST(SmallSetTest, IteratorInt) { + SmallSet<int, 4> s1; + + // Test the 'small' case. + for (int i = 0; i < 3; i++) + s1.insert(i); + + std::vector<int> V(s1.begin(), s1.end()); + // Make sure the elements are in the expected order. + std::sort(V.begin(), V.end()); + for (int i = 0; i < 3; i++) + EXPECT_EQ(i, V[i]); + + // Test the 'big' case by adding a few more elements to switch to std::set + // internally. + for (int i = 3; i < 6; i++) + s1.insert(i); + + V.assign(s1.begin(), s1.end()); + // Make sure the elements are in the expected order. + std::sort(V.begin(), V.end()); + for (int i = 0; i < 6; i++) + EXPECT_EQ(i, V[i]); +} + +TEST(SmallSetTest, IteratorString) { + // Test SmallSetIterator for SmallSet with a type with non-trivial + // ctors/dtors. + SmallSet<std::string, 2> s1; + + s1.insert("str 1"); + s1.insert("str 2"); + s1.insert("str 1"); + + std::vector<std::string> V(s1.begin(), s1.end()); + std::sort(V.begin(), V.end()); + EXPECT_EQ(2u, s1.size()); + EXPECT_EQ("str 1", V[0]); + EXPECT_EQ("str 2", V[1]); + + s1.insert("str 4"); + s1.insert("str 0"); + s1.insert("str 4"); + + V.assign(s1.begin(), s1.end()); + // Make sure the elements are in the expected order. + std::sort(V.begin(), V.end()); + EXPECT_EQ(4u, s1.size()); + EXPECT_EQ("str 0", V[0]); + EXPECT_EQ("str 1", V[1]); + EXPECT_EQ("str 2", V[2]); + EXPECT_EQ("str 4", V[3]); +} + +TEST(SmallSetTest, IteratorIncMoveCopy) { + // Test SmallSetIterator for SmallSet with a type with non-trivial + // ctors/dtors. + SmallSet<std::string, 2> s1; + + s1.insert("str 1"); + s1.insert("str 2"); + + auto Iter = s1.begin(); + EXPECT_EQ("str 1", *Iter); + ++Iter; + EXPECT_EQ("str 2", *Iter); + + s1.insert("str 4"); + s1.insert("str 0"); + auto Iter2 = s1.begin(); + Iter = std::move(Iter2); + EXPECT_EQ("str 0", *Iter); + + auto Iter3 = s1.end(); + Iter3 = Iter2; + EXPECT_EQ(Iter3, Iter2); +} |

