diff options
author | Jacques Lucke <jacques@blender.org> | 2020-05-04 18:12:12 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-05-04 18:12:23 +0300 |
commit | df16c23832abe423da5e8fee9bd1cabb643e65de (patch) | |
tree | 41c08f1ae284136d31b0c7db9ae554f44fa847f4 /tests/gtests/blenlib | |
parent | ba43c2a040fb92435308c497043f480cb03a3705 (diff) |
Add StringMap.LookupOrAdd and StringMap.LookupOrAddDefault
Diffstat (limited to 'tests/gtests/blenlib')
-rw-r--r-- | tests/gtests/blenlib/BLI_string_map_test.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/gtests/blenlib/BLI_string_map_test.cc b/tests/gtests/blenlib/BLI_string_map_test.cc index 41cda920a89..6acad0ce581 100644 --- a/tests/gtests/blenlib/BLI_string_map_test.cc +++ b/tests/gtests/blenlib/BLI_string_map_test.cc @@ -249,3 +249,27 @@ TEST(string_map, AddOrModify) EXPECT_FALSE(map.add_or_modify("Hello", create_func, modify_func)); EXPECT_EQ(map.lookup("Hello"), 15); } + +TEST(string_map, LookupOrAdd) +{ + StringMap<int> map; + auto return_5 = []() { return 5; }; + auto return_8 = []() { return 8; }; + + int &a = map.lookup_or_add("A", return_5); + EXPECT_EQ(a, 5); + EXPECT_EQ(map.lookup_or_add("A", return_8), 5); + EXPECT_EQ(map.lookup_or_add("B", return_8), 8); +} + +TEST(string_map, LookupOrAddDefault) +{ + StringMap<std::string> map; + + std::string &a = map.lookup_or_add_default("A"); + EXPECT_EQ(a.size(), 0); + a += "Test"; + EXPECT_EQ(a.size(), 4); + std::string &b = map.lookup_or_add_default("A"); + EXPECT_EQ(b, "Test"); +} |