folly copyright 2015 -> copyright 2016
[folly.git] / folly / test / RangeTest.cpp
index f9ffda970cda2588e5dd411fca9f50f45ed60980..104fcac02ee5a9cf2e30a650f74c10e4e6efbd84 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015 Facebook, Inc.
+ * Copyright 2016 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@
 #include <type_traits>
 #include <vector>
 #include <boost/range/concepts.hpp>
+#include <boost/algorithm/string/trim.hpp>
 #include <gtest/gtest.h>
 
 using namespace folly;
@@ -420,6 +421,43 @@ TEST(StringPiece, SuffixEmpty) {
   EXPECT_EQ("", a);
 }
 
+TEST(StringPiece, erase) {
+  StringPiece a("hello");
+  auto b = a.begin();
+  auto e = b + 1;
+  a.erase(b, e);
+  EXPECT_EQ("ello", a);
+
+  e = a.end();
+  b = e - 1;
+  a.erase(b, e);
+  EXPECT_EQ("ell", a);
+
+  b = a.end() - 1;
+  e = a.end() - 1;
+  EXPECT_THROW(a.erase(b, e), std::out_of_range);
+
+  b = a.begin();
+  e = a.end();
+  a.erase(b, e);
+  EXPECT_EQ("", a);
+
+  a = "hello";
+  b = a.begin();
+  e = b + 2;
+  a.erase(b, e);
+  EXPECT_EQ("llo", a);
+
+  b = a.end() - 2;
+  e = a.end();
+  a.erase(b, e);
+  EXPECT_EQ("l", a);
+
+  a = "      hello  ";
+  boost::algorithm::trim(a);
+  EXPECT_EQ(a, "hello");
+}
+
 TEST(StringPiece, split_step_char_delimiter) {
   //              0         1         2
   //              012345678901234567890123456