Ed Tanous | 9140a67 | 2017-04-24 17:01:32 -0700 | [diff] [blame] | 1 | #include "crow/ci_map.h" |
| 2 | #include <gmock/gmock.h> |
| 3 | #include <gtest/gtest.h> |
| 4 | |
| 5 | using namespace testing; |
| 6 | |
| 7 | TEST(CiMap, MapEmpty) { |
| 8 | crow::ci_map map; |
| 9 | EXPECT_TRUE(map.empty()); |
| 10 | EXPECT_EQ(map.size(), 0); |
| 11 | |
| 12 | map.emplace("foo", "bar"); |
| 13 | |
| 14 | map.clear(); |
| 15 | EXPECT_TRUE(map.empty()); |
| 16 | } |
| 17 | |
| 18 | TEST(CiMap, MapBasicInsert) { |
| 19 | crow::ci_map map; |
| 20 | map.emplace("foo", "bar"); |
| 21 | auto x = map.find("foo"); |
| 22 | ASSERT_NE(x, map.end()); |
| 23 | |
| 24 | EXPECT_EQ(map.find("foo")->first, "foo"); |
| 25 | EXPECT_EQ(map.find("foo")->second, "bar"); |
| 26 | EXPECT_EQ(map.find("FOO")->first, "foo"); |
| 27 | EXPECT_EQ(map.find("FOO")->second, "bar"); |
| 28 | } |
| 29 | |
| 30 | TEST(CiMap, MapManyInsert) { |
| 31 | crow::ci_map map; |
| 32 | map.emplace("foo", "car"); |
| 33 | map.emplace("foo", "boo"); |
| 34 | map.emplace("bar", "cat"); |
| 35 | map.emplace("baz", "bat"); |
| 36 | |
| 37 | EXPECT_EQ(map.size(), 3); |
| 38 | ASSERT_NE(map.find("foo"), map.end()); |
| 39 | EXPECT_EQ(map.find("foo")->first, "foo"); |
| 40 | EXPECT_EQ(map.find("foo")->second, "car"); |
| 41 | |
| 42 | ASSERT_NE(map.find("FOO"), map.end()); |
| 43 | EXPECT_EQ(map.find("FOO")->first, "foo"); |
| 44 | EXPECT_EQ(map.find("FOO")->second, "car"); |
| 45 | |
| 46 | ASSERT_NE(map.find("bar"), map.end()); |
| 47 | EXPECT_EQ(map.find("bar")->first, "bar"); |
| 48 | EXPECT_EQ(map.find("bar")->second, "cat"); |
| 49 | |
| 50 | ASSERT_NE(map.find("BAR"), map.end()); |
| 51 | EXPECT_EQ(map.find("BAR")->first, "bar"); |
| 52 | EXPECT_EQ(map.find("BAR")->second, "cat"); |
| 53 | |
| 54 | ASSERT_NE(map.find("baz"), map.end()); |
| 55 | EXPECT_EQ(map.find("baz")->first, "baz"); |
| 56 | EXPECT_EQ(map.find("baz")->second, "bat"); |
| 57 | |
| 58 | ASSERT_NE(map.find("BAZ"), map.end()); |
| 59 | EXPECT_EQ(map.find("BAZ")->first, "baz"); |
| 60 | EXPECT_EQ(map.find("BAZ")->second, "bat"); |
| 61 | |
| 62 | EXPECT_EQ(map.count("foo"), 1); |
| 63 | EXPECT_EQ(map.count("bar"), 1); |
| 64 | EXPECT_EQ(map.count("baz"), 1); |
| 65 | EXPECT_EQ(map.count("FOO"), 1); |
| 66 | EXPECT_EQ(map.count("BAR"), 1); |
| 67 | EXPECT_EQ(map.count("BAZ"), 1); |
| 68 | } |
| 69 | |
| 70 | TEST(CiMap, MapMultiInsert) { |
| 71 | crow::ci_map map; |
| 72 | map.emplace("foo", "bar1"); |
| 73 | map.emplace("foo", "bar2"); |
| 74 | EXPECT_EQ(map.count("foo"), 1); |
| 75 | EXPECT_EQ(map.count("FOO"), 1); |
| 76 | EXPECT_EQ(map.count("fOo"), 1); |
| 77 | EXPECT_EQ(map.count("FOo"), 1); |
| 78 | } |