OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/gn/string_utils.h" | 5 #include "tools/gn/string_utils.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 EXPECT_TRUE(CheckExpansionCase("hello #${onescope.two}", nullptr, false)); | 104 EXPECT_TRUE(CheckExpansionCase("hello #${onescope.two}", nullptr, false)); |
105 | 105 |
106 // Accessing the list. | 106 // Accessing the list. |
107 EXPECT_TRUE(CheckExpansionCase("hello #${onelist[0]}", "hello #1", true)); | 107 EXPECT_TRUE(CheckExpansionCase("hello #${onelist[0]}", "hello #1", true)); |
108 EXPECT_TRUE(CheckExpansionCase("hello #${onelist[1]}", nullptr, false)); | 108 EXPECT_TRUE(CheckExpansionCase("hello #${onelist[1]}", nullptr, false)); |
109 | 109 |
110 // Trying some other (otherwise valid) expressions should fail. | 110 // Trying some other (otherwise valid) expressions should fail. |
111 EXPECT_TRUE(CheckExpansionCase("${1 + 2}", nullptr, false)); | 111 EXPECT_TRUE(CheckExpansionCase("${1 + 2}", nullptr, false)); |
112 EXPECT_TRUE(CheckExpansionCase("${print(1)}", nullptr, false)); | 112 EXPECT_TRUE(CheckExpansionCase("${print(1)}", nullptr, false)); |
113 } | 113 } |
| 114 |
| 115 TEST(StringUtils, EditDistance) { |
| 116 EXPECT_EQ(3u, EditDistance("doom melon", "dune melon", 100)); |
| 117 EXPECT_EQ(2u, EditDistance("doom melon", "dune melon", 1)); |
| 118 |
| 119 EXPECT_EQ(2u, EditDistance("ab", "ba", 100)); |
| 120 EXPECT_EQ(2u, EditDistance("ba", "ab", 100)); |
| 121 |
| 122 EXPECT_EQ(2u, EditDistance("ananas", "banana", 100)); |
| 123 EXPECT_EQ(2u, EditDistance("banana", "ananas", 100)); |
| 124 |
| 125 EXPECT_EQ(2u, EditDistance("unclear", "nuclear", 100)); |
| 126 EXPECT_EQ(2u, EditDistance("nuclear", "unclear", 100)); |
| 127 |
| 128 EXPECT_EQ(3u, EditDistance("chrome", "chromium", 100)); |
| 129 EXPECT_EQ(3u, EditDistance("chromium", "chrome", 100)); |
| 130 |
| 131 EXPECT_EQ(4u, EditDistance("", "abcd", 100)); |
| 132 EXPECT_EQ(4u, EditDistance("abcd", "", 100)); |
| 133 |
| 134 EXPECT_EQ(4u, EditDistance("xxx", "xxxxxxx", 100)); |
| 135 EXPECT_EQ(4u, EditDistance("xxxxxxx", "xxx", 100)); |
| 136 |
| 137 EXPECT_EQ(7u, EditDistance("yyy", "xxxxxxx", 100)); |
| 138 EXPECT_EQ(7u, EditDistance("xxxxxxx", "yyy", 100)); |
| 139 } |
| 140 |
| 141 TEST(StringUtils, SpellcheckString) { |
| 142 std::vector<base::StringPiece> words; |
| 143 words.push_back("your"); |
| 144 words.push_back("bravado"); |
| 145 words.push_back("won\'t"); |
| 146 words.push_back("help"); |
| 147 words.push_back("you"); |
| 148 words.push_back("now"); |
| 149 |
| 150 EXPECT_EQ("help", SpellcheckString("halp", words)); |
| 151 |
| 152 // barbados has an edit distance of 4 from bravado, so there's no suggestion. |
| 153 EXPECT_TRUE(SpellcheckString("barbados", words).empty()); |
| 154 } |
OLD | NEW |