[gtksourceview] tests: unit-test for listing all snippets



commit b8d535ec76e076aa4ffc0471a3a99c7bfc82ee88
Author: Günther Wagner <info gunibert de>
Date:   Sat Apr 30 15:34:32 2022 +0200

    tests: unit-test for listing all snippets

 tests/snippets/test.snippets | 24 ++++++++++++++++++++++++
 tests/test-snippets.c        | 35 +++++++++++++++++++++++++++++++++--
 2 files changed, 57 insertions(+), 2 deletions(-)
---
diff --git a/tests/snippets/test.snippets b/tests/snippets/test.snippets
new file mode 100644
index 00000000..0b5b23a3
--- /dev/null
+++ b/tests/snippets/test.snippets
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<snippets _group="Test">
+  <snippet _name="Test1" trigger="test1" _description="Testing the parser">
+    <text languages="python;python3;"><![CDATA[# ${1:$TM_FILENAME}
+#
+# Copyright $CURRENT_YEAR ${2:$NAME} <${3:$EMAIL}>
+#
+# 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
+$0]]></text>
+  </snippet>
+</snippets>
diff --git a/tests/test-snippets.c b/tests/test-snippets.c
index 07c839c4..82d8e67a 100644
--- a/tests/test-snippets.c
+++ b/tests/test-snippets.c
@@ -22,10 +22,14 @@
 #include <gtksourceview/gtksource.h>
 #include <gtksourceview/gtksourceinit.h>
 
-static const gchar *search_path[] = {
+static const gchar *data_search_path[] = {
        TOP_SRCDIR"/data/snippets",
        NULL
 };
+static const char *test_search_path[] = {
+       TOP_SRCDIR"/tests/snippets",
+       NULL
+};
 
 static void
 test_simple (void)
@@ -35,7 +39,7 @@ test_simple (void)
        const gchar **groups;
 
        mgr = g_object_new (GTK_SOURCE_TYPE_SNIPPET_MANAGER, NULL);
-       gtk_source_snippet_manager_set_search_path (mgr, search_path);
+       gtk_source_snippet_manager_set_search_path (mgr, data_search_path);
 
        /* Update if you add new groups to data/snippets/ */
        groups = gtk_source_snippet_manager_list_groups (mgr);
@@ -51,6 +55,32 @@ test_simple (void)
        g_assert_finalize_object (mgr);
 }
 
+static void
+test_snippet_fetching (void)
+{
+       GtkSourceSnippetManager *mgr;
+       GListModel *model;
+       guint n_items;
+
+       mgr = g_object_new (GTK_SOURCE_TYPE_SNIPPET_MANAGER, NULL);
+       gtk_source_snippet_manager_set_search_path (mgr, test_search_path);
+
+       model = gtk_source_snippet_manager_list_all (mgr);
+       n_items = g_list_model_get_n_items (model);
+
+       /* Test language id for snippets */
+       for (guint i = 0; i < n_items; i++)
+       {
+               g_autoptr(GtkSourceSnippet) snippet = g_list_model_get_item (model, i);
+               const char *language_id = gtk_source_snippet_get_language_id (snippet);
+
+               g_assert_nonnull (language_id);
+               g_assert_cmpstr (language_id, !=, "");
+       }
+
+       g_assert_finalize_object (mgr);
+}
+
 static void
 test_snippet_parse (void)
 {
@@ -101,6 +131,7 @@ main (gint argc,
 
        g_test_add_func ("/SourceView/Snippets/parse-bundle", test_simple);
        g_test_add_func ("/SourceView/Snippets/new-parsed", test_snippet_parse);
+       g_test_add_func ("/SourceView/Snippets/snippet-fetching", test_snippet_fetching);
        ret = g_test_run ();
 
        gtk_source_finalize ();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]