aboutsummaryrefslogtreecommitdiff
path: root/gcc/spellcheck.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2016-06-07 17:33:04 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2016-06-07 17:33:04 +0000
commit484b59c4826e53507c91291042393160f26d8c71 (patch)
treeac0ddf3e815b120450e7181956aa014f1cc2933f /gcc/spellcheck.c
parente10183dce1d15ab1ca0232f9d5aebffbe7e75728 (diff)
downloadgcc-484b59c4826e53507c91291042393160f26d8c71.zip
gcc-484b59c4826e53507c91291042393160f26d8c71.tar.gz
gcc-484b59c4826e53507c91291042393160f26d8c71.tar.bz2
spellcheck.c: add test_find_closest_string
gcc/ChangeLog: * spellcheck.c (selftest::test_find_closest_string): New function. (spellcheck_c_tests): Call the above. From-SVN: r237181
Diffstat (limited to 'gcc/spellcheck.c')
-rw-r--r--gcc/spellcheck.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/gcc/spellcheck.c b/gcc/spellcheck.c
index ceb6016..11018f0 100644
--- a/gcc/spellcheck.c
+++ b/gcc/spellcheck.c
@@ -198,6 +198,27 @@ levenshtein_distance_unit_test (const char *a, const char *b,
levenshtein_distance_unit_test_oneway (b, a, expected);
}
+/* Verify that find_closest_string is sane. */
+
+static void
+test_find_closest_string ()
+{
+ auto_vec<const char *> candidates;
+
+ /* Verify that it can handle an empty vec. */
+ ASSERT_EQ (NULL, find_closest_string ("", &candidates));
+
+ /* Verify that it works sanely for non-empty vecs. */
+ candidates.safe_push ("apple");
+ candidates.safe_push ("banana");
+ candidates.safe_push ("cherry");
+
+ ASSERT_STREQ ("apple", find_closest_string ("app", &candidates));
+ ASSERT_STREQ ("banana", find_closest_string ("banyan", &candidates));
+ ASSERT_STREQ ("cherry", find_closest_string ("berry", &candidates));
+ ASSERT_EQ (NULL, find_closest_string ("not like the others", &candidates));
+}
+
/* Verify levenshtein_distance for a variety of pairs of pre-canned
inputs, comparing against known-good values. */
@@ -218,6 +239,8 @@ spellcheck_c_tests ()
("Lorem ipsum dolor sit amet, consectetur adipiscing elit,",
"All your base are belong to us",
44);
+
+ test_find_closest_string ();
}
} // namespace selftest