Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-06-10 15:47:16 +0300
committerJacques Lucke <jacques@blender.org>2020-06-10 15:47:22 +0300
commita71f073dfb0277255ac63ab880fff1cf5cb3c699 (patch)
tree1c24a0f63fb6a9f0c61c4218ed4c1d9921b067b1 /tests/gtests/blenlib/BLI_map_test.cc
parent75ce20a00067e05eca575deb74fbf2b5c118c309 (diff)
BLI: add Map.pop_try method
I found this pattern in depsgraph code more than once.
Diffstat (limited to 'tests/gtests/blenlib/BLI_map_test.cc')
-rw-r--r--tests/gtests/blenlib/BLI_map_test.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/gtests/blenlib/BLI_map_test.cc b/tests/gtests/blenlib/BLI_map_test.cc
index aa8903ed8ff..aa064e2f427 100644
--- a/tests/gtests/blenlib/BLI_map_test.cc
+++ b/tests/gtests/blenlib/BLI_map_test.cc
@@ -82,6 +82,23 @@ TEST(map, PopItem)
EXPECT_FALSE(map.contains(1));
}
+TEST(map, PopTry)
+{
+ Map<int, int> map;
+ map.add(1, 5);
+ map.add(2, 7);
+ EXPECT_EQ(map.size(), 2);
+ Optional<int> value = map.pop_try(4);
+ EXPECT_EQ(map.size(), 2);
+ EXPECT_FALSE(value.has_value());
+ value = map.pop_try(2);
+ EXPECT_EQ(map.size(), 1);
+ EXPECT_TRUE(value.has_value());
+ EXPECT_EQ(value.value(), 7);
+ EXPECT_EQ(*map.pop_try(1), 5);
+ EXPECT_EQ(map.size(), 0);
+}
+
TEST(map, PopItemMany)
{
Map<int, int> map;