[gtksourceview/wip/chergert/fix-190: 2/3] testsuite: add failing test for move-words




commit be351c4ccef5e4e2376366fa7dd18307a5090d23
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jul 28 15:07:55 2021 -0700

    testsuite: add failing test for move-words
    
    This is the test case we needed from #190 to actually verify a bug fix.

 testsuite/test-buffer.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
---
diff --git a/testsuite/test-buffer.c b/testsuite/test-buffer.c
index 44bce205..1850def7 100644
--- a/testsuite/test-buffer.c
+++ b/testsuite/test-buffer.c
@@ -295,6 +295,56 @@ test_sort_lines (void)
        g_object_unref (buffer);
 }
 
+static void
+do_test_move_words (GtkSourceView      *view,
+                    GtkSourceBuffer    *buffer,
+                    const gchar        *text,
+                    const gchar        *expected,
+                    gint                start_offset,
+                    gint                end_offset,
+                    gint                step)
+{
+       GtkTextIter start;
+       GtkTextIter end;
+       gchar *changed;
+
+       gtk_text_buffer_set_text (GTK_TEXT_BUFFER (buffer), text, -1);
+
+       gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (buffer), &start, start_offset);
+       gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (buffer), &end, end_offset);
+       gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer), &start, &end);
+
+       g_signal_emit_by_name (view, "move-words", step);
+
+       gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (buffer), &start, &end);
+       changed = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (buffer), &start, &end, TRUE);
+
+       g_assert_cmpstr (changed, ==, expected);
+
+       g_free (changed);
+}
+
+static void
+test_move_words (void)
+{
+       GtkSourceView *view;
+       GtkSourceBuffer *buffer;
+
+       buffer = gtk_source_buffer_new (NULL);
+       view = g_object_ref_sink (GTK_SOURCE_VIEW (gtk_source_view_new ()));
+
+       gtk_text_view_set_buffer (GTK_TEXT_VIEW (view), GTK_TEXT_BUFFER (buffer));
+
+       do_test_move_words (view, buffer, "a > b", "a b >", 2, 3, 1);
+       do_test_move_words (view, buffer, "a>b", "ab>", 1, 2, 1);
+       do_test_move_words (view, buffer, "a>b", ">ab", 1, 2, -1);
+       do_test_move_words (view, buffer, "what is this word.", "what word this is.", 13, 17, -2);
+       do_test_move_words (view, buffer, "what word this is.", "what is this word.", 5, 9, 2);
+
+       g_object_unref (buffer);
+       g_object_unref (view);
+}
+
 static void
 do_test_bracket_matching (GtkSourceBuffer           *source_buffer,
                          const gchar               *text,
@@ -450,6 +500,7 @@ main (int argc, char** argv)
        g_test_add_func ("/Buffer/change-case", test_change_case);
        g_test_add_func ("/Buffer/join-lines", test_join_lines);
        g_test_add_func ("/Buffer/sort-lines", test_sort_lines);
+       g_test_add_func ("/Buffer/move-words", test_move_words);
        g_test_add_func ("/Buffer/bracket-matching", test_bracket_matching);
 
        return g_test_run();


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