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

Unified Diff: tools/gn/string_utils_unittest.cc

Issue 1681363003: Add spell-checking to `gn help`. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move to string_utils, add tests Created 4 years, 10 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
« tools/gn/command_help.cc ('K') | « tools/gn/string_utils.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/string_utils_unittest.cc
diff --git a/tools/gn/string_utils_unittest.cc b/tools/gn/string_utils_unittest.cc
index d62e17e7b81055cf848f8b75a90bb624bfc6ba5b..570997ff1b72bd2f1acbb6c60e9e946dc8444298 100644
--- a/tools/gn/string_utils_unittest.cc
+++ b/tools/gn/string_utils_unittest.cc
@@ -111,3 +111,44 @@ TEST(StringUtils, ExpandStringLiteralExpression) {
EXPECT_TRUE(CheckExpansionCase("${1 + 2}", nullptr, false));
EXPECT_TRUE(CheckExpansionCase("${print(1)}", nullptr, false));
}
+
+TEST(StringUtils, EditDistance) {
+ EXPECT_EQ(3u, EditDistance("doom melon", "dune melon", 100));
+ EXPECT_EQ(2u, EditDistance("doom melon", "dune melon", 1));
+
+ EXPECT_EQ(2u, EditDistance("ab", "ba", 100));
+ EXPECT_EQ(2u, EditDistance("ba", "ab", 100));
+
+ EXPECT_EQ(2u, EditDistance("ananas", "banana", 100));
+ EXPECT_EQ(2u, EditDistance("banana", "ananas", 100));
+
+ EXPECT_EQ(2u, EditDistance("unclear", "nuclear", 100));
+ EXPECT_EQ(2u, EditDistance("nuclear", "unclear", 100));
+
+ EXPECT_EQ(3u, EditDistance("chrome", "chromium", 100));
+ EXPECT_EQ(3u, EditDistance("chromium", "chrome", 100));
+
+ EXPECT_EQ(4u, EditDistance("", "abcd", 100));
+ EXPECT_EQ(4u, EditDistance("abcd", "", 100));
+
+ EXPECT_EQ(4u, EditDistance("xxx", "xxxxxxx", 100));
+ EXPECT_EQ(4u, EditDistance("xxxxxxx", "xxx", 100));
+
+ EXPECT_EQ(7u, EditDistance("yyy", "xxxxxxx", 100));
+ EXPECT_EQ(7u, EditDistance("xxxxxxx", "yyy", 100));
+}
+
+TEST(StringUtils, SpellcheckString) {
+ std::vector<base::StringPiece> words;
+ words.push_back("your");
+ words.push_back("bravado");
+ words.push_back("won\'t");
+ words.push_back("help");
+ words.push_back("you");
+ words.push_back("now");
+
+ EXPECT_EQ("help", SpellcheckString("halp", words));
+
+ // barbados has an edit distance of 4 from bravado, so there's no suggestion.
+ EXPECT_TRUE(SpellcheckString("barbados", words).empty());
+}
« tools/gn/command_help.cc ('K') | « tools/gn/string_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698