Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
|
Mark P
2017/01/06 06:06:09
Don't change copyright years for existing files.
mattreynolds
2017/01/06 18:03:50
Done.
| |
| 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 "components/bookmarks/browser/titled_url_match.h" | |
| 6 | |
| 7 #include "base/macros.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 using bookmarks::TitledUrlMatch; | |
|
sky
2017/01/06 16:32:54
Put this code in the bookmarks namespace (as other
mattreynolds
2017/01/06 18:03:50
Done.
| |
| 12 using MatchPositions = bookmarks::TitledUrlMatch::MatchPositions; | |
| 13 | |
| 14 TEST(TitledUrlMatchTest, EmptyOffsetsForEmptyMatchPositions) { | |
| 15 auto offsets = TitledUrlMatch::OffsetsFromMatchPositions(MatchPositions()); | |
| 16 EXPECT_TRUE(offsets.empty()); | |
| 17 } | |
| 18 | |
| 19 TEST(TitledUrlMatchTest, OffsetsFromMatchPositions) { | |
| 20 MatchPositions match_positions = {{1, 3}, {4, 5}, {10, 15}}; | |
| 21 std::vector<size_t> expected_offsets = {1, 3, 4, 5, 10, 15}; | |
| 22 auto offsets = TitledUrlMatch::OffsetsFromMatchPositions(match_positions); | |
| 23 EXPECT_TRUE( | |
| 24 std::equal(offsets.begin(), offsets.end(), expected_offsets.begin())); | |
| 25 } | |
| 26 | |
| 27 TEST(TitledUrlMatchTest, ReplaceOffsetsInEmptyMatchPositions) { | |
| 28 auto match_positions = TitledUrlMatch::ReplaceOffsetsInMatchPositions( | |
| 29 MatchPositions(), std::vector<size_t>()); | |
| 30 EXPECT_TRUE(match_positions.empty()); | |
| 31 } | |
| 32 | |
| 33 TEST(TitledUrlMatchTest, ReplaceOffsetsInMatchPositions) { | |
| 34 MatchPositions orig_match_positions = {{1, 3}, {4, 5}, {10, 15}}; | |
| 35 std::vector<size_t> offsets = {0, 2, 3, 4, 9, 14}; | |
| 36 MatchPositions expected_match_positions = {{0, 2}, {3, 4}, {9, 14}}; | |
| 37 auto match_positions = TitledUrlMatch::ReplaceOffsetsInMatchPositions( | |
| 38 orig_match_positions, offsets); | |
| 39 EXPECT_TRUE(std::equal(match_positions.begin(), match_positions.end(), | |
| 40 expected_match_positions.begin())); | |
| 41 } | |
| 42 | |
| 43 TEST(TitledUrlMatchTest, ReplaceOffsetsRemovesItemsWithNposOffsets) { | |
| 44 MatchPositions orig_match_positions = {{1, 3}, {4, 5}, {10, 15}, {17, 20}}; | |
| 45 std::vector<size_t> offsets = {0, | |
| 46 base::string16::npos, | |
| 47 base::string16::npos, | |
| 48 4, | |
| 49 base::string16::npos, | |
| 50 base::string16::npos, | |
| 51 17, | |
| 52 20}; | |
| 53 MatchPositions expected_match_positions = {{17, 20}}; | |
| 54 auto match_positions = TitledUrlMatch::ReplaceOffsetsInMatchPositions( | |
| 55 orig_match_positions, offsets); | |
| 56 EXPECT_TRUE(std::equal(match_positions.begin(), match_positions.end(), | |
| 57 expected_match_positions.begin())); | |
| 58 } | |
| OLD | NEW |