OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "ios/chrome/common/string_util.h" |
| 6 |
| 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" |
| 11 |
| 12 namespace { |
| 13 |
| 14 TEST(StringUtilTest, ParseStringWithLink) { |
| 15 NSArray* const all_test_data = @[ |
| 16 @{ |
| 17 @"input" : @"Text without link.", |
| 18 @"expected" : @"Text without link.", |
| 19 @"link range" : [NSValue valueWithRange:NSMakeRange(NSNotFound, 0)] |
| 20 }, |
| 21 @{ |
| 22 @"input" : @"Text with empty link BEGIN_LINK END_LINK.", |
| 23 @"expected" : @"Text with empty link .", |
| 24 @"link range" : [NSValue valueWithRange:NSMakeRange(21, 0)] |
| 25 }, |
| 26 @{ |
| 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)] |
| 30 }, |
| 31 @{ |
| 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)] |
| 35 }, |
| 36 @{ |
| 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)] |
| 40 } |
| 41 ]; |
| 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]; |
| 46 |
| 47 EXPECT_NSEQ(expected_text, ParseStringWithLink(input_text, nullptr)); |
| 48 |
| 49 // Initialize |range| with some values that are not equal to the expected |
| 50 // ones. |
| 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); |
| 55 } |
| 56 } |
| 57 |
| 58 } // namespace |
OLD | NEW |