[gtksourceview/wip/fix-bug-search-context] SearchContext: fix bug look-ahead regex



commit 59756d6a36a10f3d8fe62606c6e75e6ca39db5cd
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Aug 20 14:34:32 2015 +0200

    SearchContext: fix bug look-ahead regex
    
    https://bugzilla.gnome.org/show_bug.cgi?id=752719

 tests/test-search-context.c |   67 +++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 64 insertions(+), 3 deletions(-)
---
diff --git a/tests/test-search-context.c b/tests/test-search-context.c
index 8a2cafe..5238090 100644
--- a/tests/test-search-context.c
+++ b/tests/test-search-context.c
@@ -921,7 +921,7 @@ test_replace_all (void)
 }
 
 static void
-test_regex (void)
+test_regex_basics (void)
 {
        GtkSourceBuffer *source_buffer = gtk_source_buffer_new (NULL);
        GtkTextBuffer *text_buffer = GTK_TEXT_BUFFER (source_buffer);
@@ -1060,6 +1060,66 @@ test_regex_at_word_boundaries (void)
 }
 
 static void
+test_regex_occurence_position (void)
+{
+       GtkSourceBuffer *source_buffer = gtk_source_buffer_new (NULL);
+       GtkTextBuffer *text_buffer = GTK_TEXT_BUFFER (source_buffer);
+       GtkSourceSearchSettings *settings = gtk_source_search_settings_new ();
+       GtkSourceSearchContext *context = gtk_source_search_context_new (source_buffer, settings);
+       GtkTextIter iter;
+       GtkTextIter match_start;
+       GtkTextIter match_end;
+       gint count;
+       gint pos;
+       gint offset;
+       gboolean found;
+
+       gtk_text_buffer_set_text (text_buffer, "12\n23\n123\nblah", -1);
+
+       gtk_source_search_settings_set_regex_enabled (settings, TRUE);
+
+       /* Look behind */
+       gtk_source_search_settings_set_search_text (settings, "(?<=1)23");
+       flush_queue ();
+       count = gtk_source_search_context_get_occurrences_count (context);
+       g_assert_cmpint (count, ==, 1);
+
+       gtk_text_buffer_get_start_iter (text_buffer, &iter);
+       found = gtk_source_search_context_forward (context, &iter, &match_start, &match_end);
+       g_assert (found);
+
+       offset = gtk_text_iter_get_offset (&match_start);
+       g_assert_cmpint (offset, ==, 7);
+       offset = gtk_text_iter_get_offset (&match_end);
+       g_assert_cmpint (offset, ==, 9);
+
+       pos = gtk_source_search_context_get_occurrence_position (context, &match_start, &match_end);
+       g_assert_cmpint (pos, ==, 1);
+
+       /* Look ahead */
+       gtk_source_search_settings_set_search_text (settings, "12(?=3)");
+       flush_queue ();
+       count = gtk_source_search_context_get_occurrences_count (context);
+       g_assert_cmpint (count, ==, 1);
+
+       gtk_text_buffer_get_start_iter (text_buffer, &iter);
+       found = gtk_source_search_context_forward (context, &iter, &match_start, &match_end);
+       g_assert (found);
+
+       offset = gtk_text_iter_get_offset (&match_start);
+       g_assert_cmpint (offset, ==, 6);
+       offset = gtk_text_iter_get_offset (&match_end);
+       g_assert_cmpint (offset, ==, 8);
+
+       pos = gtk_source_search_context_get_occurrence_position (context, &match_start, &match_end);
+       g_assert_cmpint (pos, ==, 1);
+
+       g_object_unref (source_buffer);
+       g_object_unref (settings);
+       g_object_unref (context);
+}
+
+static void
 test_destroy_buffer_during_search (void)
 {
        GtkSourceBuffer *source_buffer = gtk_source_buffer_new (NULL);
@@ -1106,8 +1166,9 @@ main (int argc, char **argv)
        g_test_add_func ("/Search/occurrence-position", test_occurrence_position);
        g_test_add_func ("/Search/replace", test_replace);
        g_test_add_func ("/Search/replace", test_replace_all);
-       g_test_add_func ("/Search/regex", test_regex);
-       g_test_add_func ("/Search/regex-at-word-boundaries", test_regex_at_word_boundaries);
+       g_test_add_func ("/Search/regex/basics", test_regex_basics);
+       g_test_add_func ("/Search/regex/at-word-boundaries", test_regex_at_word_boundaries);
+       g_test_add_func ("/Search/regex/occurence-position", test_regex_occurence_position);
        g_test_add_func ("/Search/destroy-buffer-during-search", test_destroy_buffer_during_search);
 
        return g_test_run ();


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