aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/lib/strings/str_util_test.cc
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2018-03-16 10:10:16 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-03-16 10:14:17 -0700
commit386ba370d41e8872a9db0d45239d7b00c14ef309 (patch)
treeb7aa83e59e1345fcc1fbf6cb89db5601966c91b3 /tensorflow/core/lib/strings/str_util_test.cc
parenta0bd058ad1406585634330772bfda76fd27d87d7 (diff)
Added StrContains, StartsWith, and EndsWith functions to str_util.h.
Marked contains, starts_with, ends_with, and consume StringPiece methods as deprecated. This will allow tensorflow::StringPiece to be more easily replaced with absl::string_view (once the deprecated methods are removed) as absl::string_view does not contain those methods. PiperOrigin-RevId: 189355316
Diffstat (limited to 'tensorflow/core/lib/strings/str_util_test.cc')
-rw-r--r--tensorflow/core/lib/strings/str_util_test.cc52
1 files changed, 52 insertions, 0 deletions
diff --git a/tensorflow/core/lib/strings/str_util_test.cc b/tensorflow/core/lib/strings/str_util_test.cc
index 6d461241f7..63643c3e8e 100644
--- a/tensorflow/core/lib/strings/str_util_test.cc
+++ b/tensorflow/core/lib/strings/str_util_test.cc
@@ -430,4 +430,56 @@ TEST(StringReplace, EmptyStringReplaceAll) {
EXPECT_EQ("", str_util::StringReplace("", "a", "X", /*replace_all=*/true));
}
+TEST(StartsWith, Basic) {
+ const string s1(
+ "123"
+ "\0"
+ "456",
+ 7);
+ const StringPiece a("foobar");
+ const StringPiece b(s1);
+ const StringPiece e;
+ EXPECT_TRUE(str_util::StartsWith(a, a));
+ EXPECT_TRUE(str_util::StartsWith(a, "foo"));
+ EXPECT_TRUE(str_util::StartsWith(a, e));
+ EXPECT_TRUE(str_util::StartsWith(b, s1));
+ EXPECT_TRUE(str_util::StartsWith(b, b));
+ EXPECT_TRUE(str_util::StartsWith(b, e));
+ EXPECT_TRUE(str_util::StartsWith(e, ""));
+ EXPECT_FALSE(str_util::StartsWith(a, b));
+ EXPECT_FALSE(str_util::StartsWith(b, a));
+ EXPECT_FALSE(str_util::StartsWith(e, a));
+}
+
+TEST(EndsWith, Basic) {
+ const string s1(
+ "123"
+ "\0"
+ "456",
+ 7);
+ const StringPiece a("foobar");
+ const StringPiece b(s1);
+ const StringPiece e;
+ EXPECT_TRUE(str_util::EndsWith(a, a));
+ EXPECT_TRUE(str_util::EndsWith(a, "bar"));
+ EXPECT_TRUE(str_util::EndsWith(a, e));
+ EXPECT_TRUE(str_util::EndsWith(b, s1));
+ EXPECT_TRUE(str_util::EndsWith(b, b));
+ EXPECT_TRUE(str_util::EndsWith(b, e));
+ EXPECT_TRUE(str_util::EndsWith(e, ""));
+ EXPECT_FALSE(str_util::EndsWith(a, b));
+ EXPECT_FALSE(str_util::EndsWith(b, a));
+ EXPECT_FALSE(str_util::EndsWith(e, a));
+}
+
+TEST(StrContains, Basic) {
+ StringPiece a("abcdefg");
+ StringPiece b("abcd");
+ StringPiece c("efg");
+ StringPiece d("gh");
+ EXPECT_TRUE(str_util::StrContains(a, b));
+ EXPECT_TRUE(str_util::StrContains(a, c));
+ EXPECT_TRUE(!str_util::StrContains(a, d));
+}
+
} // namespace tensorflow