aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/stubs/stringpiece_unittest.cc
diff options
context:
space:
mode:
authorGravatar Jisi Liu <jisi.liu@gmail.com>2015-10-05 11:59:43 -0700
committerGravatar Jisi Liu <jisi.liu@gmail.com>2015-10-05 11:59:43 -0700
commit46e8ff63cb67a6520711da5317aaaef04d0414d0 (patch)
tree64370726fe469f8dfca7b14f8b8cb80b6cc856f6 /src/google/protobuf/stubs/stringpiece_unittest.cc
parent0087da9d4775f79c67362cc89c653f3a33a9bae2 (diff)
Down-integrate from google internal.
Diffstat (limited to 'src/google/protobuf/stubs/stringpiece_unittest.cc')
-rw-r--r--src/google/protobuf/stubs/stringpiece_unittest.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/google/protobuf/stubs/stringpiece_unittest.cc b/src/google/protobuf/stubs/stringpiece_unittest.cc
index 9b5dae13..1cb7d12b 100644
--- a/src/google/protobuf/stubs/stringpiece_unittest.cc
+++ b/src/google/protobuf/stubs/stringpiece_unittest.cc
@@ -30,6 +30,7 @@
#include <google/protobuf/stubs/stringpiece.h>
#include <iterator>
+#include <hash_set>
#include <map>
#include <string>
#include <utility>
@@ -745,6 +746,23 @@ TEST(StringPiece, Comparisons2) {
EXPECT_TRUE(abc.ends_with("nopqrstuvwxyz"));
}
+TEST(StringPiece, HashFunction) {
+ hash_set<StringPiece> set;
+
+ set.insert(StringPiece("hello"));
+ EXPECT_EQ(1, set.size());
+
+ // Insert a StringPiece of the same value again and should NOT increment
+ // size of the set.
+ set.insert(StringPiece("hello"));
+ EXPECT_EQ(1, set.size());
+
+ // Insert a StringPiece with different value and check that size of the set
+ // has been increment by one.
+ set.insert(StringPiece("world"));
+ EXPECT_EQ(2, set.size());
+}
+
TEST(ComparisonOpsTest, StringCompareNotAmbiguous) {
EXPECT_EQ("hello", string("hello"));
EXPECT_LT("hello", string("world"));