| 1 |
/* SPDX-FileCopyrightText: 2016 - Sébastien Wilmet <[email protected]> |
| 2 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
*/ |
| 4 |
|
| 5 |
#include "gspell/gspell-utils.h" |
| 6 |
|
| 7 |
static void |
| 8 |
test_is_number (void) |
| 9 |
{ |
| 10 |
gboolean is_number; |
| 11 |
|
| 12 |
is_number = _gspell_utils_is_number ("123", -1); |
| 13 |
g_assert_true (is_number); |
| 14 |
|
| 15 |
is_number = _gspell_utils_is_number ("123", 3); |
| 16 |
g_assert_true (is_number); |
| 17 |
|
| 18 |
is_number = _gspell_utils_is_number ("123a4", 3); |
| 19 |
g_assert_true (is_number); |
| 20 |
|
| 21 |
is_number = _gspell_utils_is_number ("123a4", -1); |
| 22 |
g_assert_true (!is_number); |
| 23 |
|
| 24 |
is_number = _gspell_utils_is_number ("h4ck1ng", -1); |
| 25 |
g_assert_true (!is_number); |
| 26 |
} |
| 27 |
|
| 28 |
static void |
| 29 |
test_str_replace (void) |
| 30 |
{ |
| 31 |
gchar *result; |
| 32 |
|
| 33 |
result = _gspell_utils_str_replace ("$filename", "$filename", "blah"); |
| 34 |
g_assert_cmpstr (result, ==, "blah"); |
| 35 |
g_free (result); |
| 36 |
|
| 37 |
result = _gspell_utils_str_replace ("$shortname.pdf", "$shortname", "blah"); |
| 38 |
g_assert_cmpstr (result, ==, "blah.pdf"); |
| 39 |
g_free (result); |
| 40 |
|
| 41 |
result = _gspell_utils_str_replace ("abcdabcd", "ab", "r"); |
| 42 |
g_assert_cmpstr (result, ==, "rcdrcd"); |
| 43 |
g_free (result); |
| 44 |
|
| 45 |
result = _gspell_utils_str_replace ("abcd", "ef", "r"); |
| 46 |
g_assert_cmpstr (result, ==, "abcd"); |
| 47 |
g_free (result); |
| 48 |
} |
| 49 |
|
| 50 |
static void |
| 51 |
test_str_to_ascii_apostrophe (void) |
| 52 |
{ |
| 53 |
gchar *result = NULL; |
| 54 |
gboolean ret; |
| 55 |
|
| 56 |
ret = _gspell_utils_str_to_ascii_apostrophe ("rock'n'roll", -1, &result); |
| 57 |
g_assert_true (!ret); |
| 58 |
g_assert_true (result == NULL); |
| 59 |
|
| 60 |
ret = _gspell_utils_str_to_ascii_apostrophe ("rock\xCA\xBCn\xCA\xBCroll", -1, &result); |
| 61 |
g_assert_true (ret); |
| 62 |
g_assert_cmpstr (result, ==, "rock'n'roll"); |
| 63 |
g_free (result); |
| 64 |
result = NULL; |
| 65 |
|
| 66 |
ret = _gspell_utils_str_to_ascii_apostrophe ("rock\xE2\x80\x99n\xE2\x80\x99roll", -1, &result); |
| 67 |
g_assert_true (ret); |
| 68 |
g_assert_cmpstr (result, ==, "rock'n'roll"); |
| 69 |
g_free (result); |
| 70 |
result = NULL; |
| 71 |
|
| 72 |
ret = _gspell_utils_str_to_ascii_apostrophe ("rock\xCA\xBCn\xE2\x80\x99roll", -1, &result); |
| 73 |
g_assert_true (ret); |
| 74 |
g_assert_cmpstr (result, ==, "rock'n'roll"); |
| 75 |
g_free (result); |
| 76 |
result = NULL; |
| 77 |
|
| 78 |
ret = _gspell_utils_str_to_ascii_apostrophe ("rock\xCA\xBCn\xE2\x80\x99roll", 7, &result); |
| 79 |
g_assert_true (ret); |
| 80 |
g_assert_cmpstr (result, ==, "rock'n"); |
| 81 |
g_free (result); |
| 82 |
result = NULL; |
| 83 |
|
| 84 |
ret = _gspell_utils_str_to_ascii_apostrophe ("rock\xCA\xBCn\xE2\x80\x99roll", 4, &result); |
| 85 |
g_assert_true (!ret); |
| 86 |
g_assert_true (result == NULL); |
| 87 |
} |
| 88 |
|
| 89 |
gint |
| 90 |
main (gint argc, |
| 91 |
gchar **argv) |
| 92 |
{ |
| 93 |
gtk_test_init (&argc, &argv); |
| 94 |
|
| 95 |
g_test_add_func ("/utils/is_number", test_is_number); |
| 96 |
g_test_add_func ("/utils/str_replace", test_str_replace); |
| 97 |
g_test_add_func ("/utils/str_to_ascii_apostrophe", test_str_to_ascii_apostrophe); |
| 98 |
|
| 99 |
return g_test_run (); |
| 100 |
} |