From ad111087cc96ef321baa5bcb28f2052509f77e80 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 16 Feb 2023 14:27:44 -0500 Subject: [PATCH] Add a test for invisible text navigation This shows that (at least some) things work as expected. See: #1811 --- testsuite/gtk/textiter.c | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/testsuite/gtk/textiter.c b/testsuite/gtk/textiter.c index 8b296b222b..04ee403b26 100644 --- a/testsuite/gtk/textiter.c +++ b/testsuite/gtk/textiter.c @@ -786,6 +786,52 @@ test_backward_line (void) g_object_unref (buffer); } +static void +test_invisible_text (void) +{ + GtkTextBuffer *buffer; + GtkTextIter iter, end; + GtkTextTag *tag; + GtkTextTagTable *tags; + char *text; + + buffer = gtk_text_buffer_new (NULL); + + tag = gtk_text_tag_new ("invisible"); + + tags = gtk_text_buffer_get_tag_table (buffer); + g_object_set (tag, "invisible", TRUE, NULL); + gtk_text_tag_table_add (tags, tag); + gtk_text_buffer_get_start_iter (buffer, &iter); + gtk_text_buffer_insert (buffer, &iter, "one ", -1); + gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "two three", -1, "invisible", NULL); + gtk_text_buffer_insert (buffer, &iter, " four", -1); + + gtk_text_buffer_get_start_iter (buffer, &iter); + gtk_text_buffer_get_end_iter (buffer, &end); + + gtk_text_iter_forward_visible_word_end (&iter); + + text = gtk_text_buffer_get_text (buffer, &iter, &end, TRUE); + g_assert_cmpstr (text, ==, " two three four"); + g_free (text); + + gtk_text_iter_forward_word_end (&iter); + text = gtk_text_buffer_get_text (buffer, &iter, &end, TRUE); + g_assert_cmpstr (text, ==, " three four"); + g_free (text); + + gtk_text_iter_forward_visible_word_end (&iter); + text = gtk_text_buffer_get_text (buffer, &iter, &end, TRUE); + g_assert_cmpstr (text, ==, " four"); + g_free (text); + + gtk_text_iter_forward_visible_word_end (&iter); + g_assert_true (gtk_text_iter_equal (&iter, &end)); + + g_object_unref (buffer); +} + int main (int argc, char** argv) { @@ -803,6 +849,7 @@ main (int argc, char** argv) g_test_add_func ("/TextIter/Visible Cursor Positions", test_visible_cursor_positions); g_test_add_func ("/TextIter/Sentence Boundaries", test_sentence_boundaries); g_test_add_func ("/TextIter/Backward line", test_backward_line); + g_test_add_func ("/TextIter/Invisible text", test_invisible_text); return g_test_run(); }