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

Unified Diff: ios/chrome/common/string_util_unittest.mm

Issue 1073863005: Upstream string_util function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: test deps Created 5 years, 8 months 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
« no previous file with comments | « ios/chrome/common/string_util.mm ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/common/string_util_unittest.mm
diff --git a/ios/chrome/common/string_util_unittest.mm b/ios/chrome/common/string_util_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..fb70beca80959c0a7345046150c2ee8e448cff12
--- /dev/null
+++ b/ios/chrome/common/string_util_unittest.mm
@@ -0,0 +1,58 @@
+// Copyright 2013 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/chrome/common/string_util.h"
+
+#include "base/mac/scoped_nsobject.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/gtest_mac.h"
+#include "testing/platform_test.h"
+
+namespace {
+
+TEST(StringUtilTest, ParseStringWithLink) {
+ NSArray* const all_test_data = @[
+ @{
+ @"input" : @"Text without link.",
+ @"expected" : @"Text without link.",
+ @"link range" : [NSValue valueWithRange:NSMakeRange(NSNotFound, 0)]
+ },
+ @{
+ @"input" : @"Text with empty link BEGIN_LINK END_LINK.",
+ @"expected" : @"Text with empty link .",
+ @"link range" : [NSValue valueWithRange:NSMakeRange(21, 0)]
+ },
+ @{
+ @"input" : @"Text with BEGIN_LINK and no end link.",
+ @"expected" : @"Text with BEGIN_LINK and no end link.",
+ @"link range" : [NSValue valueWithRange:NSMakeRange(NSNotFound, 0)]
+ },
+ @{
+ @"input" : @"Text with valid BEGIN_LINK link END_LINK and spaces.",
+ @"expected" : @"Text with valid link and spaces.",
+ @"link range" : [NSValue valueWithRange:NSMakeRange(16, 4)]
+ },
+ @{
+ @"input" : @"Text with valid BEGIN_LINKlinkEND_LINK and no spaces.",
+ @"expected" : @"Text with valid link and no spaces.",
+ @"link range" : [NSValue valueWithRange:NSMakeRange(16, 4)]
+ }
+ ];
+ for (NSDictionary* test_data : all_test_data) {
+ NSString* input_text = test_data[@"input"];
+ NSString* expected_text = test_data[@"expected"];
+ NSRange expected_range = [test_data[@"link range"] rangeValue];
+
+ EXPECT_NSEQ(expected_text, ParseStringWithLink(input_text, nullptr));
+
+ // Initialize |range| with some values that are not equal to the expected
+ // ones.
+ NSRange range = NSMakeRange(1000, 2000);
+ EXPECT_NSEQ(expected_text, ParseStringWithLink(input_text, &range));
+ EXPECT_EQ(expected_range.location, range.location);
+ EXPECT_EQ(expected_range.length, range.length);
+ }
+}
+
+} // namespace
« no previous file with comments | « ios/chrome/common/string_util.mm ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698