Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(941)

Unified Diff: ios/web/string_util_unittest.cc

Issue 780873002: Upstream iOS web code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix gyp Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/web/string_util_unittest.cc
diff --git a/ios/web/string_util_unittest.cc b/ios/web/string_util_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4899a92222794edf47e8173d4f1ab7f104b33169
--- /dev/null
+++ b/ios/web/string_util_unittest.cc
@@ -0,0 +1,45 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ios/web/public/string_util.h"
+
+#include "base/strings/utf_string_conversions.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace web {
+
+// Tests that a regular sentence is clipped correctly.
+TEST(StringByClippingLastWordTest, ClipRegularSentence) {
+ const base::string16 kInput =
+ base::UTF8ToUTF16("\nSome text here and there.");
+ EXPECT_EQ(kInput, GetStringByClippingLastWord(kInput, 100));
+}
+
+// Tests that a long sentence exceeding some length is clipped correctly.
+TEST(StringByClippingLastWordTest, ClipLongSentence) {
+ // An arbitrary length.
+ const size_t kStringLength = 10;
+ base::string16 string(kStringLength, 'a');
+ string.append(base::UTF8ToUTF16(" b cdefghijklmnopqrstuvwxyz"));
+ // The string should be cut at the last whitespace, after the 'b' character.
+ base::string16 result =
+ GetStringByClippingLastWord(string, kStringLength + 3);
+ EXPECT_EQ(kStringLength + 2, result.size());
+ EXPECT_EQ(0u, string.find_first_of(result));
+}
+
+// Tests that a block of text with no space is truncated to kLongStringLength.
+TEST(StringByClippingLastWordTest, ClipLongTextContentNoSpace) {
+ // Very long string.
+ const size_t kLongStringLength = 65536;
+ // A string slightly longer than |kLongStringLength|.
+ base::string16 long_string(kLongStringLength + 10, 'a');
+ // Block of text with no space should be truncated to kLongStringLength.
+ base::string16 result =
+ GetStringByClippingLastWord(long_string, kLongStringLength);
+ EXPECT_EQ(kLongStringLength, result.size());
+ EXPECT_EQ(0u, long_string.find_first_of(result));
+}
+
+} // namespace web

Powered by Google App Engine
This is Rietveld 408576698