| 1 |
/* SPDX-FileCopyrightText: 2016 - Sébastien Wilmet <[email protected]> |
| 2 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
*/ |
| 4 |
|
| 5 |
#include <gspell/gspell.h> |
| 6 |
#include "gspell/gspell-utils.h" |
| 7 |
|
| 8 |
static void |
| 9 |
test_check_word (void) |
| 10 |
{ |
| 11 |
const GspellLanguage *lang; |
| 12 |
GspellChecker *checker; |
| 13 |
gboolean correctly_spelled; |
| 14 |
GError *error = NULL; |
| 15 |
|
| 16 |
lang = gspell_language_lookup ("en_US"); |
| 17 |
g_assert_true (lang != NULL); |
| 18 |
|
| 19 |
checker = gspell_checker_new (lang); |
| 20 |
|
| 21 |
correctly_spelled = gspell_checker_check_word (checker, "hello", -1, &error); |
| 22 |
g_assert_no_error (error); |
| 23 |
g_assert_true (correctly_spelled); |
| 24 |
|
| 25 |
correctly_spelled = gspell_checker_check_word (checker, "tkbqzat", -1, &error); |
| 26 |
g_assert_no_error (error); |
| 27 |
g_assert_true (!correctly_spelled); |
| 28 |
|
| 29 |
g_object_unref (checker); |
| 30 |
} |
| 31 |
|
| 32 |
static void |
| 33 |
test_apostrophes (void) |
| 34 |
{ |
| 35 |
const GspellLanguage *lang; |
| 36 |
GspellChecker *checker; |
| 37 |
gboolean correctly_spelled; |
| 38 |
gunichar apostrophe_char; |
| 39 |
GError *error = NULL; |
| 40 |
|
| 41 |
lang = gspell_language_lookup ("en_US"); |
| 42 |
g_assert_true (lang != NULL); |
| 43 |
|
| 44 |
checker = gspell_checker_new (lang); |
| 45 |
|
| 46 |
/* Apostrophe U+0027 */ |
| 47 |
|
| 48 |
apostrophe_char = g_utf8_get_char ("'"); |
| 49 |
g_assert_cmpint (apostrophe_char, ==, '\''); |
| 50 |
|
| 51 |
correctly_spelled = gspell_checker_check_word (checker, "doesn't", -1, &error); |
| 52 |
g_assert_no_error (error); |
| 53 |
g_assert_true (correctly_spelled); |
| 54 |
|
| 55 |
/* Modifier Letter Apostrophe U+02BC */ |
| 56 |
|
| 57 |
apostrophe_char = g_utf8_get_char ("\xCA\xBC"); |
| 58 |
g_assert_cmpint (apostrophe_char, ==, _GSPELL_MODIFIER_LETTER_APOSTROPHE); |
| 59 |
|
| 60 |
correctly_spelled = gspell_checker_check_word (checker, "doesn\xCA\xBCt", -1, &error); |
| 61 |
g_assert_no_error (error); |
| 62 |
g_assert_true (correctly_spelled); |
| 63 |
|
| 64 |
/* Right Single Quotation Mark U+2019 */ |
| 65 |
|
| 66 |
apostrophe_char = g_utf8_get_char ("\xE2\x80\x99"); |
| 67 |
g_assert_cmpint (apostrophe_char, ==, _GSPELL_RIGHT_SINGLE_QUOTATION_MARK); |
| 68 |
|
| 69 |
correctly_spelled = gspell_checker_check_word (checker, "doesn\xE2\x80\x99t", -1, &error); |
| 70 |
g_assert_no_error (error); |
| 71 |
g_assert_true (correctly_spelled); |
| 72 |
|
| 73 |
g_object_unref (checker); |
| 74 |
} |
| 75 |
|
| 76 |
static void |
| 77 |
test_dashes (void) |
| 78 |
{ |
| 79 |
const GspellLanguage *lang; |
| 80 |
GspellChecker *checker; |
| 81 |
gboolean correctly_spelled; |
| 82 |
GError *error = NULL; |
| 83 |
|
| 84 |
lang = gspell_language_lookup ("en_US"); |
| 85 |
g_assert_true (lang != NULL); |
| 86 |
|
| 87 |
checker = gspell_checker_new (lang); |
| 88 |
|
| 89 |
/* This unit test fails with the aspell enchant backend, but aspell can |
| 90 |
* be considered deprecated, it is better to use hunspell, so WONTFIX. |
| 91 |
* For more details, see: |
| 92 |
* https://bugzilla.gnome.org/show_bug.cgi?id=772406 |
| 93 |
*/ |
| 94 |
correctly_spelled = gspell_checker_check_word (checker, "spell-checking", -1, &error); |
| 95 |
g_assert_no_error (error); |
| 96 |
g_assert_true (correctly_spelled); |
| 97 |
|
| 98 |
correctly_spelled = gspell_checker_check_word (checker, "nrst-auie", -1, &error); |
| 99 |
g_assert_no_error (error); |
| 100 |
g_assert_true (!correctly_spelled); |
| 101 |
|
| 102 |
g_object_unref (checker); |
| 103 |
} |
| 104 |
|
| 105 |
gint |
| 106 |
main (gint argc, |
| 107 |
gchar **argv) |
| 108 |
{ |
| 109 |
gtk_test_init (&argc, &argv); |
| 110 |
|
| 111 |
g_test_add_func ("/checker/check_word", test_check_word); |
| 112 |
g_test_add_func ("/checker/apostrophes", test_apostrophes); |
| 113 |
g_test_add_func ("/checker/dashes", test_dashes); |
| 114 |
|
| 115 |
return g_test_run (); |
| 116 |
} |