[gnome-text-editor] spellcheck: more robust testing



commit 30b771951e6b78500f928488498029a822790ef8
Author: Christian Hergert <chergert redhat com>
Date:   Thu Aug 5 13:10:24 2021 -0700

    spellcheck: more robust testing
    
     * Force locale and setup UTF-8 for "C"
     * Try to process some (hopefully) highlighted syntax in the buffer
       which has context classes assigned.

 src/meson.build         |  2 +-
 src/test-spell-cursor.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+), 1 deletion(-)
---
diff --git a/src/meson.build b/src/meson.build
index 460c5b7..eb26248 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -93,7 +93,7 @@ editor = executable('gnome-text-editor', editor_sources + editor_enums + [build_
 )
 
 test_spell_cursor = executable('test-spell-cursor', 'test-spell-cursor.c',
-  dependencies: libgtk_dep,
+  dependencies: [libgtk_dep, libgtksourceview_dep],
   include_directories: [include_directories('..')],
 )
 test('test-spell-cursor', test_spell_cursor)
diff --git a/src/test-spell-cursor.c b/src/test-spell-cursor.c
index 9edc860..727952d 100644
--- a/src/test-spell-cursor.c
+++ b/src/test-spell-cursor.c
@@ -1,8 +1,53 @@
+/* test-spell-cursor.c
+ *
+ * Copyright 2021 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 <locale.h>
+#include <glib/gi18n.h>
+#include <gtksourceview/gtksource.h>
+
 #include "editor-spell-cursor.c"
 #include "cjhtextregion.c"
 
 static const char *test_text = "this is a series of words";
 static const char *test_text_2 = "it's possible we're going to have join-words.";
+static const char *test_text_3 = "\
+/* ide-buffer.c\
+ *\
+ * Copyright 2018-2019 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\
+ */\
+";
 
 static char *
 next_word (EditorSpellCursor *cursor)
@@ -50,6 +95,48 @@ test_cursor (void)
   _cjh_text_region_free (region);
 }
 
+static void
+test_cursor2 (void)
+{
+  g_autoptr(GtkTextBuffer) buffer = GTK_TEXT_BUFFER (gtk_source_buffer_new (NULL));
+  GtkWindow *window;
+  GtkSourceView *view;
+  CjhTextRegion *region = _cjh_text_region_new (NULL, NULL);
+  g_autoptr(EditorSpellCursor) cursor = editor_spell_cursor_new (buffer, region, NULL, NULL);
+  GtkSourceLanguage *l = gtk_source_language_manager_get_language (gtk_source_language_manager_get_default 
(), "c");
+  static const char *words[] = {
+    "ide", "buffer", "c",
+    "Copyright", "2018", "2019", "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",
+  };
+
+  gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (buffer), l);
+  gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (buffer), TRUE);
+  gtk_text_buffer_set_text (buffer, test_text_3, -1);
+  _cjh_text_region_insert (region, 0, strlen (test_text_3), NULL);
+
+  window = g_object_new (GTK_TYPE_WINDOW, NULL);
+  view = GTK_SOURCE_VIEW (gtk_source_view_new ());
+  gtk_text_view_set_buffer (GTK_TEXT_VIEW (view), buffer);
+  gtk_window_set_child (window, GTK_WIDGET (view));
+  gtk_window_present (window);
+
+  while (g_main_context_pending (NULL))
+    g_main_context_iteration (NULL, TRUE);
+
+  for (guint i = 0; i < G_N_ELEMENTS (words); i++)
+    {
+      char *word = next_word (cursor);
+      g_assert_cmpstr (word, ==, words[i]);
+      g_free (word);
+    }
+
+  _cjh_text_region_free (region);
+}
+
 static void
 test_cursor_in_word (void)
 {
@@ -121,8 +208,17 @@ int
 main (int argc,
       char *argv[])
 {
+  setlocale (LC_ALL, "C");
+  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+  textdomain (GETTEXT_PACKAGE);
+
+  gtk_init ();
+  gtk_source_init ();
+
   g_test_init (&argc, &argv, NULL);
   g_test_add_func ("/Spelling/Cursor/basic", test_cursor);
+  g_test_add_func ("/Spelling/Cursor/basic2", test_cursor2);
   g_test_add_func ("/Spelling/Cursor/in_word", test_cursor_in_word);
   g_test_add_func ("/Spelling/Cursor/join_words", test_cursor_join_words);
   return g_test_run ();


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