1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ios/chrome/common/string_util.h"
7 #include "base/mac/scoped_nsobject.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "testing/gtest_mac.h"
10 #include "testing/platform_test.h"
14 TEST(StringUtilTest, ParseStringWithLink) {
15 NSArray* const all_test_data = @[
17 @"input" : @"Text without link.",
18 @"expected" : @"Text without link.",
19 @"link range" : [NSValue valueWithRange:NSMakeRange(NSNotFound, 0)]
22 @"input" : @"Text with empty link BEGIN_LINK END_LINK.",
23 @"expected" : @"Text with empty link .",
24 @"link range" : [NSValue valueWithRange:NSMakeRange(21, 0)]
27 @"input" : @"Text with BEGIN_LINK and no end link.",
28 @"expected" : @"Text with BEGIN_LINK and no end link.",
29 @"link range" : [NSValue valueWithRange:NSMakeRange(NSNotFound, 0)]
32 @"input" : @"Text with valid BEGIN_LINK link END_LINK and spaces.",
33 @"expected" : @"Text with valid link and spaces.",
34 @"link range" : [NSValue valueWithRange:NSMakeRange(16, 4)]
37 @"input" : @"Text with valid BEGIN_LINKlinkEND_LINK and no spaces.",
38 @"expected" : @"Text with valid link and no spaces.",
39 @"link range" : [NSValue valueWithRange:NSMakeRange(16, 4)]
42 for (NSDictionary* test_data : all_test_data) {
43 NSString* input_text = test_data[@"input"];
44 NSString* expected_text = test_data[@"expected"];
45 NSRange expected_range = [test_data[@"link range"] rangeValue];
47 EXPECT_NSEQ(expected_text, ParseStringWithLink(input_text, nullptr));
49 // Initialize |range| with some values that are not equal to the expected
51 NSRange range = NSMakeRange(1000, 2000);
52 EXPECT_NSEQ(expected_text, ParseStringWithLink(input_text, &range));
53 EXPECT_EQ(expected_range.location, range.location);
54 EXPECT_EQ(expected_range.length, range.length);