+2016-06-07 David Malcolm <dmalcolm@redhat.com>
+
+ * spellcheck.c (selftest::test_find_closest_string): New function.
+ (spellcheck_c_tests): Call the above.
+
2016-06-07 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
* simplify-rtx.c (simplify_cond_clz_ctz): Delete 'mode' local
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. */
("Lorem ipsum dolor sit amet, consectetur adipiscing elit,",
"All your base are belong to us",
44);
+
+ test_find_closest_string ();
}
} // namespace selftest