diff options
author | Alon Zakai <azakai@google.com> | 2024-11-26 09:05:48 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-26 09:05:48 -0800 |
commit | cc97853b5f03e8c8441159e68ecb2262beee166f (patch) | |
tree | ecf63827f726ff0401aa47a250539138b77a6a3c /test/gtest/arena.cpp | |
parent | f7afec956917c51071867f5b1b487111f1a1ef60 (diff) | |
download | binaryen-cc97853b5f03e8c8441159e68ecb2262beee166f.tar.gz binaryen-cc97853b5f03e8c8441159e68ecb2262beee166f.tar.bz2 binaryen-cc97853b5f03e8c8441159e68ecb2262beee166f.zip |
Fix ArenaVector::swap (#7115)
This was never right for over a decade, and just never used I suppose... it should
have been called "take" since it grabbed data from the other item and then set
that other item to empty. Fix it so it swaps properly.
Diffstat (limited to 'test/gtest/arena.cpp')
-rw-r--r-- | test/gtest/arena.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/gtest/arena.cpp b/test/gtest/arena.cpp new file mode 100644 index 000000000..7453ea9f6 --- /dev/null +++ b/test/gtest/arena.cpp @@ -0,0 +1,39 @@ +#include "mixed_arena.h" +#include "gtest/gtest.h" + +using ArenaTest = ::testing::Test; + +TEST_F(ArenaTest, Swap) { + MixedArena arena; + + ArenaVector<int> a(arena); + a.push_back(10); + a.push_back(20); + + ArenaVector<int> b(arena); + + EXPECT_EQ(a.size(), 2U); + EXPECT_EQ(b.size(), 0U); + + a.swap(b); + + EXPECT_EQ(a.size(), 0U); + EXPECT_EQ(b.size(), 2U); + + a.swap(b); + + EXPECT_EQ(a.size(), 2U); + EXPECT_EQ(b.size(), 0U); + + // Now reverse a and b. The swap should be the same. + + b.swap(a); + + EXPECT_EQ(a.size(), 0U); + EXPECT_EQ(b.size(), 2U); + + b.swap(a); + + EXPECT_EQ(a.size(), 2U); + EXPECT_EQ(b.size(), 0U); +} |