Commit c82ea0c0 authored by Sébastien Wilmet's avatar Sébastien Wilmet

testsuite: more tests for _gspell_text_iter functions

parent 8fc26a4d
......@@ -20,10 +20,11 @@
#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)
check_word_move (gboolean forward,
const gchar *text,
gint initial_offset,
gint expected_result_offset,
gboolean expected_ret)
{
GtkTextBuffer *buffer;
GtkTextIter iter;
......@@ -34,7 +35,16 @@ check_forward_word_end (const gchar *text,
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);
if (forward)
{
ret = _gspell_text_iter_forward_word_end (&iter);
}
else
{
ret = _gspell_text_iter_backward_word_start (&iter);
}
g_assert_cmpint (ret, ==, expected_ret);
result_offset = gtk_text_iter_get_offset (&iter);
......@@ -46,22 +56,131 @@ check_forward_word_end (const gchar *text,
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 i;
for (i = 0; i <= 5; i++)
{
check_word_move (TRUE, " don't ", i, 6, TRUE);
}
check_word_move (TRUE, " don't ", 6, 6, FALSE);
check_word_move (TRUE, " don't", 0, 6, FALSE);
/* "goin'" is a valid word, but not yet supported. */
for (i = 0; i <= 4; i++)
{
check_word_move (TRUE, " goin' ", i, 5, TRUE);
}
check_word_move (TRUE, " goin' ", 5, 5, FALSE);
check_word_move (TRUE, " goin' ", 6, 6, FALSE);
check_word_move (TRUE, " goin' ", 7, 7, FALSE);
/* Several apostrophes in the same word. */
for (i = 0; i <= 11; i++)
{
check_word_move (TRUE, " rock'n'roll ", i, 12, TRUE);
}
check_word_move (TRUE, " rock'n'roll ", 12, 12, FALSE);
check_word_move (TRUE, " rock'n'roll", 0, 12, FALSE);
}
static void
test_backward_word_start (void)
{
gint i;
for (i = 7; i >= 2; i--)
{
check_word_move (FALSE, " don't ", i, 1, TRUE);
}
check_word_move (FALSE, " don't ", 1, 1, FALSE);
check_word_move (FALSE, " don't ", 0, 0, FALSE);
/* "'til" is a valid word, but not yet supported. */
for (i = 6; i >= 3; i--)
{
check_word_move (FALSE, " 'til ", i, 2, TRUE);
}
check_word_move (FALSE, " 'til ", 2, 2, FALSE);
check_word_move (FALSE, " 'til ", 1, 1, FALSE);
check_word_move (FALSE, " 'til ", 0, 0, FALSE);
/* Several apostrophes in the same word. */
for (i = 13; i >= 2; i--)
{
check_word_move (FALSE, " rock'n'roll ", i, 1, TRUE);
}
check_word_move (FALSE, " rock'n'roll ", 1, 1, FALSE);
check_word_move (FALSE, " rock'n'roll ", 0, 0, FALSE);
}
static void
check_properties (GtkTextBuffer *buffer,
gint offset,
gboolean expected_starts_word,
gboolean expected_ends_word,
gboolean expected_inside_word)
{
GtkTextIter iter;
gtk_text_buffer_get_iter_at_offset (buffer, &iter, offset);
g_assert_cmpint (expected_starts_word, ==, _gspell_text_iter_starts_word (&iter));
g_assert_cmpint (expected_ends_word, ==, _gspell_text_iter_ends_word (&iter));
g_assert_cmpint (expected_inside_word, ==, _gspell_text_iter_inside_word (&iter));
}
static void
test_properties (void)
{
GtkTextBuffer *buffer;
gint i;
buffer = gtk_text_buffer_new (NULL);
gtk_text_buffer_set_text (buffer, " don't ", -1);
check_properties (buffer, 0, FALSE, FALSE, FALSE);
check_properties (buffer, 1, TRUE, FALSE, TRUE);
for (i = 2; i <= 5; i++)
{
check_properties (buffer, i, FALSE, FALSE, TRUE);
}
check_properties (buffer, 6, FALSE, TRUE, FALSE);
check_properties (buffer, 7, FALSE, FALSE, FALSE);
/* "goin'" is a valid word, but not yet supported. */
gtk_text_buffer_set_text (buffer, " goin' ", -1);
check_properties (buffer, 0, FALSE, FALSE, FALSE);
check_properties (buffer, 1, TRUE, FALSE, TRUE);
for (i = 2; i <= 4; i++)
{
check_properties (buffer, i, FALSE, FALSE, TRUE);
}
check_properties (buffer, 5, FALSE, TRUE, FALSE);
check_properties (buffer, 6, FALSE, FALSE, FALSE);
check_properties (buffer, 7, FALSE, FALSE, FALSE);
/* "'til" is a valid word, but not yet supported. */
gtk_text_buffer_set_text (buffer, " 'til ", -1);
check_properties (buffer, 0, FALSE, FALSE, FALSE);
check_properties (buffer, 1, FALSE, FALSE, FALSE);
check_properties (buffer, 2, TRUE, FALSE, TRUE);
check_properties (buffer, 3, FALSE, FALSE, TRUE);
check_properties (buffer, 4, FALSE, FALSE, TRUE);
check_properties (buffer, 5, FALSE, TRUE, FALSE);
check_properties (buffer, 6, FALSE, FALSE, FALSE);
/* Several apostrophes in the same word. */
gtk_text_buffer_set_text (buffer, " rock'n'roll ", -1);
check_properties (buffer, 0, FALSE, FALSE, FALSE);
check_properties (buffer, 1, TRUE, FALSE, TRUE);
for (i = 2; i <= 11; i++)
{
check_properties (buffer, i, FALSE, FALSE, TRUE);
}
check_properties (buffer, 12, FALSE, TRUE, FALSE);
check_properties (buffer, 13, FALSE, FALSE, FALSE);
g_object_unref (buffer);
}
gint
......@@ -71,6 +190,8 @@ main (gint argc,
gtk_test_init (&argc, &argv);
g_test_add_func ("/text-iter/forward-word-end", test_forward_word_end);
g_test_add_func ("/text-iter/backward-word-start", test_backward_word_start);
g_test_add_func ("/text-iter/starts-ends-inside-word", test_properties);
return g_test_run ();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment