[gnome-builder] test-snippet: exercise snippet movements more
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] test-snippet: exercise snippet movements more
- Date: Fri, 11 Nov 2016 03:17:28 +0000 (UTC)
commit d95f64849c02ac6aab8d838c62b3e0ad4155c075
Author: Christian Hergert <chergert redhat com>
Date: Wed Nov 9 20:01:23 2016 -0800
test-snippet: exercise snippet movements more
This is a bit tricky, since we need to make sure events flush and what
not. But things seem to be working.
tests/test-snippet.c | 120 +++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 108 insertions(+), 12 deletions(-)
---
diff --git a/tests/test-snippet.c b/tests/test-snippet.c
index 7ea8dd4..1e499eb 100644
--- a/tests/test-snippet.c
+++ b/tests/test-snippet.c
@@ -23,6 +23,22 @@
#include "snippets/ide-source-snippet-private.h"
#include "util/ide-gdk.h"
+static void
+dump_selection (IdeSourceView *view)
+{
+ GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+ GtkTextIter begin;
+ GtkTextIter end;
+
+ gtk_text_buffer_get_selection_bounds (buffer, &begin, &end);
+
+ g_message ("Selection: %d:%d to %d:%d\n",
+ gtk_text_iter_get_line (&begin) + 1,
+ gtk_text_iter_get_line_offset (&begin) + 1,
+ gtk_text_iter_get_line (&end) + 1,
+ gtk_text_iter_get_line_offset (&end) + 1);
+}
+
static gboolean
mark_done (gpointer data)
{
@@ -72,6 +88,70 @@ emit_and_pump_loop (gpointer instance,
}
static void
+on_event (GdkFrameClock *clock,
+ gpointer data)
+{
+ *(gint *)data += 1;
+}
+
+static void
+send_event_and_wait_for_flush (GdkEventKey *event)
+{
+ GdkFrameClock *clock = gdk_window_get_frame_clock (event->window);
+ gint events = 0;
+
+ g_signal_connect (clock, "after-paint", G_CALLBACK (on_event), &events);
+ g_signal_connect (clock, "before-paint", G_CALLBACK (on_event), &events);
+
+ gtk_main_do_event ((GdkEvent *)event);
+
+ while (events < 2 || gtk_events_pending ())
+ gtk_main_iteration ();
+
+ g_signal_handlers_disconnect_by_func (clock, on_event, &events);
+}
+
+static void
+move_next (IdeSourceView *view)
+{
+ GdkWindow *window;
+ GdkEventKey *event;
+
+ g_assert (IDE_IS_SOURCE_VIEW (view));
+
+ while (gtk_events_pending ())
+ gtk_main_iteration ();
+
+ window = gtk_text_view_get_window (GTK_TEXT_VIEW (view), GTK_TEXT_WINDOW_TEXT);
+ event = ide_gdk_synthesize_event_key (window, '\t');
+ event->keyval = GDK_KEY_Tab;
+ send_event_and_wait_for_flush (event);
+ gdk_event_free ((GdkEvent *)event);
+
+ pump_loop ();
+}
+
+static void
+move_previous (IdeSourceView *view)
+{
+ GdkWindow *window;
+ GdkEventKey *event;
+
+ g_assert (IDE_IS_SOURCE_VIEW (view));
+
+ while (gtk_events_pending ())
+ gtk_main_iteration ();
+
+ window = gtk_text_view_get_window (GTK_TEXT_VIEW (view), GTK_TEXT_WINDOW_TEXT);
+ event = ide_gdk_synthesize_event_key (window, '\t');
+ event->keyval = GDK_KEY_ISO_Left_Tab;
+ send_event_and_wait_for_flush (event);
+ gdk_event_free ((GdkEvent *)event);
+
+ pump_loop ();
+}
+
+static void
new_context_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
@@ -145,10 +225,14 @@ new_context_cb (GObject *object,
gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (view));
gtk_window_present (GTK_WINDOW (window));
+ gtk_source_completion_block_interactive (gtk_source_view_get_completion (GTK_SOURCE_VIEW (view)));
+
ide_source_view_push_snippet (view, snippet, NULL);
pump_loop ();
+ ide_source_snippet_dump (snippet);
+
g_assert_cmpstr ("this is\nchunk 1 ", ==, ide_source_snippet_chunk_get_text (chunk1));
g_assert_cmpstr ("this is tab stop 1", ==, ide_source_snippet_chunk_get_text (chunk2));
g_assert_cmpstr (",\nthis is chunk 3", ==, ide_source_snippet_chunk_get_text (chunk3));
@@ -166,6 +250,8 @@ new_context_cb (GObject *object,
emit_and_pump_loop (view, "backspace");
emit_and_pump_loop (view, "insert-at-cursor", "this is tab stop 1, edit 1");
+ ide_source_snippet_dump (snippet);
+
g_assert_cmpstr ("this is\nchunk 1 ", ==, ide_source_snippet_chunk_get_text (chunk1));
g_assert_cmpstr ("this is tab stop 1, edit 1", ==, ide_source_snippet_chunk_get_text (chunk2));
g_assert_cmpstr (",\nthis is chunk 3", ==, ide_source_snippet_chunk_get_text (chunk3));
@@ -173,21 +259,27 @@ new_context_cb (GObject *object,
g_assert_cmpstr ("this is tab stop 2", ==, ide_source_snippet_chunk_get_text (chunk5));
/* Now move to our second tab stop, but exercise forward/backward/forward */
- g_assert (ide_source_snippet_move_next (snippet));
- g_assert (ide_source_snippet_move_previous (snippet));
- g_assert (ide_source_snippet_move_next (snippet));
- g_assert (ide_source_snippet_move_previous (snippet));
- g_assert (ide_source_snippet_move_next (snippet));
+ move_next (view);
+ move_previous (view);
+ move_next (view);
+ move_previous (view);
+ move_next (view);
+
+ ide_source_snippet_dump (snippet);
+
+ dump_selection (view);
/* Now tweak tab stop 2 values, and see what happens */
- //emit_and_pump_loop (view, "backspace");
- //emit_and_pump_loop (view, "insert-at-cursor", "this is tab stop 2, edit 1");
+ emit_and_pump_loop (view, "backspace");
+ emit_and_pump_loop (view, "insert-at-cursor", "this is tab stop 2, edit 1");
- //g_assert_cmpstr ("this is\nchunk 1 ", ==, ide_source_snippet_chunk_get_text (chunk1));
- //g_assert_cmpstr ("this is tab stop 1, edit 1", ==, ide_source_snippet_chunk_get_text (chunk2));
- //g_assert_cmpstr (",\nthis is chunk 3", ==, ide_source_snippet_chunk_get_text (chunk3));
- //g_assert_cmpstr ("this is tab stop 1, edit 1", ==, ide_source_snippet_chunk_get_text (chunk4));
- //g_assert_cmpstr ("this is tab stop 2, edit 1", ==, ide_source_snippet_chunk_get_text (chunk5));
+ ide_source_snippet_dump (snippet);
+
+ g_assert_cmpstr ("this is\nchunk 1 ", ==, ide_source_snippet_chunk_get_text (chunk1));
+ g_assert_cmpstr ("this is tab stop 1, edit 1", ==, ide_source_snippet_chunk_get_text (chunk2));
+ g_assert_cmpstr (",\nthis is chunk 3", ==, ide_source_snippet_chunk_get_text (chunk3));
+ g_assert_cmpstr ("this is tab stop 1, edit 1", ==, ide_source_snippet_chunk_get_text (chunk4));
+ g_assert_cmpstr ("this is tab stop 2, edit 1", ==, ide_source_snippet_chunk_get_text (chunk5));
g_task_return_boolean (task, TRUE);
}
@@ -198,8 +290,12 @@ test_snippets_basic (GCancellable *cancellable,
gpointer user_data)
{
g_autoptr(GFile) project_file = NULL;
+ g_autoptr(GSettings) settings = NULL;
GTask *task;
+ settings = g_settings_new ("org.gnome.builder.code-insight");
+ g_settings_set_boolean (settings, "semantic-highlighting", FALSE);
+
task = g_task_new (NULL, cancellable, callback, user_data);
project_file = g_file_new_for_path (TEST_DATA_DIR"/project1/configure.ac");
ide_context_new_async (project_file, NULL, new_context_cb, task);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]