[gspell/wip/apostrophe: 29/30] apostrophes: write unit tests



commit cb59c7c6938fcdb005593911a985ecd4dd5ccf6d
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Feb 13 17:21:06 2016 +0100

    apostrophes: write unit tests

 testsuite/Makefile.am      |    3 ++
 testsuite/test-checker.c   |   31 +++++++++++++++++-
 testsuite/test-text-iter.c |   76 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 108 insertions(+), 2 deletions(-)
---
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index 88b31c7..a9f3768 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -18,4 +18,7 @@ test_checker_SOURCES = test-checker.c
 UNIT_TEST_PROGS += test-inline-checker-text-buffer
 test_inline_checker_text_buffer_SOURCES = test-inline-checker-text-buffer.c
 
+UNIT_TEST_PROGS += test-text-iter
+test_text_iter_SOURCES = test-text-iter.c
+
 -include $(top_srcdir)/git.mk
diff --git a/testsuite/test-checker.c b/testsuite/test-checker.c
index a7357d0..3a8b81a 100644
--- a/testsuite/test-checker.c
+++ b/testsuite/test-checker.c
@@ -34,11 +34,37 @@ test_check_word (void)
 
        correctly_spelled = gspell_checker_check_word (checker, "hello", -1, &error);
        g_assert_no_error (error);
-       g_assert_true (correctly_spelled);
+       g_assert (correctly_spelled);
 
        correctly_spelled = gspell_checker_check_word (checker, "tkbqzat", -1, &error);
        g_assert_no_error (error);
-       g_assert_false (correctly_spelled);
+       g_assert (!correctly_spelled);
+
+       g_object_unref (checker);
+}
+
+static void
+test_apostrophes (void)
+{
+       const GspellLanguage *lang;
+       GspellChecker *checker;
+       gboolean correctly_spelled;
+       gunichar apostrophe_char;
+       GError *error = NULL;
+
+       lang = gspell_language_lookup ("en_US");
+       g_assert (lang != NULL);
+
+       checker = gspell_checker_new (lang);
+
+       /* Apostrophe U+0027 */
+
+       apostrophe_char = g_utf8_get_char ("'");
+       g_assert_cmpint (apostrophe_char, ==, '\'');
+
+       correctly_spelled = gspell_checker_check_word (checker, "doesn't", -1, &error);
+       g_assert_no_error (error);
+       g_assert (correctly_spelled);
 
        g_object_unref (checker);
 }
@@ -50,6 +76,7 @@ main (gint    argc,
        gtk_test_init (&argc, &argv);
 
        g_test_add_func ("/checker/check_word", test_check_word);
+       g_test_add_func ("/checker/apostrophes", test_apostrophes);
 
        return g_test_run ();
 }
diff --git a/testsuite/test-text-iter.c b/testsuite/test-text-iter.c
new file mode 100644
index 0000000..3278a8e
--- /dev/null
+++ b/testsuite/test-text-iter.c
@@ -0,0 +1,76 @@
+/*
+ * This file is part of gspell, a spell-checking library.
+ *
+ * Copyright 2016 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gspell/gspell-text-iter.h"
+
+static void
+check_forward_word_end (const gchar *text,
+                       gint         initial_offset,
+                       gint         expected_result_offset,
+                       gboolean     expected_ret)
+{
+       GtkTextBuffer *buffer;
+       GtkTextIter iter;
+       gboolean ret;
+       gint result_offset;
+
+       buffer = gtk_text_buffer_new (NULL);
+       gtk_text_buffer_set_text (buffer, text, -1);
+
+       gtk_text_buffer_get_iter_at_offset (buffer, &iter, initial_offset);
+       ret = _gspell_text_iter_forward_word_end (&iter);
+       g_assert_cmpint (ret, ==, expected_ret);
+
+       result_offset = gtk_text_iter_get_offset (&iter);
+       g_assert_cmpint (result_offset, ==, expected_result_offset);
+
+       g_object_unref (buffer);
+}
+
+static void
+test_forward_word_end (void)
+{
+       check_forward_word_end (" don't ", 0, 6, TRUE);
+       check_forward_word_end (" don't ", 1, 6, TRUE);
+       check_forward_word_end (" don't ", 2, 6, TRUE);
+       check_forward_word_end (" don't ", 4, 6, TRUE);
+       check_forward_word_end (" don't ", 5, 6, TRUE);
+       check_forward_word_end (" don't ", 6, 6, FALSE);
+       check_forward_word_end (" don't", 0, 6, FALSE);
+
+       /* "goin'" is a valid word, but it is not supported yet. */
+       check_forward_word_end (" goin' ", 0, 5, TRUE);
+       check_forward_word_end (" goin' ", 1, 5, TRUE);
+       check_forward_word_end (" goin' ", 2, 5, TRUE);
+       check_forward_word_end (" goin' ", 4, 5, TRUE);
+       check_forward_word_end (" goin' ", 5, 5, FALSE);
+       check_forward_word_end (" goin' ", 6, 6, FALSE);
+       check_forward_word_end (" goin' ", 7, 7, FALSE);
+}
+
+gint
+main (gint    argc,
+      gchar **argv)
+{
+       gtk_test_init (&argc, &argv);
+
+       g_test_add_func ("/text-iter/forward-word-end", test_forward_word_end);
+
+       return g_test_run ();
+}


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