[gnome-builder/gnome-builder-3-30] tests: add tests for fuzzy matching
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/gnome-builder-3-30] tests: add tests for fuzzy matching
- Date: Thu, 25 Oct 2018 19:01:17 +0000 (UTC)
commit 67db5497552a1a2f590405ac7248efce9c5457b5
Author: Christian Hergert <chergert redhat com>
Date: Thu Oct 25 11:59:12 2018 -0700
tests: add tests for fuzzy matching
Related to #673
src/tests/meson.build | 6 ++++
src/tests/test-completion-fuzzy.c | 70 +++++++++++++++++++++++++++++++++++++++
2 files changed, 76 insertions(+)
---
diff --git a/src/tests/meson.build b/src/tests/meson.build
index 42c0e6d28..0a8dc8567 100644
--- a/src/tests/meson.build
+++ b/src/tests/meson.build
@@ -197,3 +197,9 @@ test_hdr_format = executable('test-hdr-format', [
c_args: ide_test_cflags,
dependencies: [ ide_test_deps ],
)
+
+test_completion_fuzzy = executable('test-completion-fuzzy', 'test-completion-fuzzy.c',
+ c_args: ide_test_cflags,
+ dependencies: [ ide_test_deps ],
+)
+test('test-completion-fuzzy', test_completion_fuzzy, env: ide_test_env)
diff --git a/src/tests/test-completion-fuzzy.c b/src/tests/test-completion-fuzzy.c
new file mode 100644
index 000000000..00fa0262f
--- /dev/null
+++ b/src/tests/test-completion-fuzzy.c
@@ -0,0 +1,70 @@
+/* test-completion-fuzzy.c
+ *
+ * Copyright 2018 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include <ide.h>
+
+static void
+test_fuzzy_match (void)
+{
+ static const struct {
+ const gchar *haystack;
+ const gchar *casefold;
+ } success[] = {
+ { "endianness", "end" },
+ { "Endianness", "end" },
+ { "Endianness", "End" },
+ { "GtkWidget", "gtkw" },
+ };
+ static const struct {
+ const gchar *haystack;
+ const gchar *casefold;
+ } failure[] = {
+ { "endianness", "z" },
+ { "Endianness", "Endj" },
+ { "Endianness", "endk" },
+ };
+ guint priority;
+ gboolean r;
+
+ for (guint i = 0; i < G_N_ELEMENTS (success); i++)
+ {
+ r = ide_completion_fuzzy_match (success[i].haystack,
+ success[i].casefold,
+ &priority);
+ g_assert_true (r);
+ }
+
+ for (guint i = 0; i < G_N_ELEMENTS (failure); i++)
+ {
+ r = ide_completion_fuzzy_match (failure[i].haystack,
+ failure[i].casefold,
+ &priority);
+ g_assert_false (r);
+ }
+}
+
+gint
+main (gint argc,
+ gchar *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+ g_test_add_func ("/Ide/Completion/fuzzy_match", test_fuzzy_match);
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]