]> jfr.im git - irc/weechat/weechat.git/commitdiff
core: remove unused argument "pos" from function gui_input_insert_string, add tests...
authorSébastien Helleu <redacted>
Sat, 17 Dec 2022 14:20:23 +0000 (15:20 +0100)
committerSébastien Helleu <redacted>
Sun, 18 Dec 2022 13:13:14 +0000 (14:13 +0100)
ChangeLog.adoc
src/gui/curses/gui-curses-key.c
src/gui/curses/gui-curses-mouse.c
src/gui/gui-chat.c
src/gui/gui-cursor.c
src/gui/gui-input.c
src/gui/gui-input.h
src/gui/gui-key.c
src/gui/gui-window.c
tests/unit/gui/test-gui-input.cpp

index 599b22eaca75fbf7f608f30b80796c4b83b89777..185d8143e9795370a6fb51929d56215d6f81a742 100644 (file)
@@ -43,6 +43,7 @@ Bug fixes::
 
 Tests::
 
+  * gui: add tests on input functions
   * scripts: add tests on config functions
 
 Build::
index 6ca0f48b6828a879195d983ca94f3a7a9393e845..218940305224b8ce4d6156ce1d8d51fc83db979a 100644 (file)
@@ -441,8 +441,7 @@ gui_key_flush (int paste)
             {
                 if (!paste || !undo_done)
                     gui_buffer_undo_snap (gui_current_window->buffer);
-                gui_input_insert_string (gui_current_window->buffer,
-                                         key_str, -1);
+                gui_input_insert_string (gui_current_window->buffer, key_str);
                 gui_input_text_changed_modifier_and_signal (gui_current_window->buffer,
                                                             (!paste || !undo_done) ? 1 : 0,
                                                             1); /* stop completion */
index e49482b6285ee34b95372e1d84a359437c2226e3..3a6325e0997ac13dce064040d824e7c180eaa5f8 100644 (file)
@@ -203,8 +203,7 @@ gui_mouse_grab_end (const char *mouse_key)
             snprintf (mouse_key_input, sizeof (mouse_key_input),
                       "%s", mouse_key);
         }
-        gui_input_insert_string (gui_current_window->buffer,
-                                 mouse_key_input, -1);
+        gui_input_insert_string (gui_current_window->buffer, mouse_key_input);
         gui_input_text_changed_modifier_and_signal (gui_current_window->buffer,
                                                     1, /* save undo */
                                                     1); /* stop completion */
index 26d82aaf34a1719dd71da70271795abab706ab31..7f63523d9f2d367deacd058ff58841fba07a8e0f 100644 (file)
@@ -1108,7 +1108,7 @@ gui_chat_hsignal_quote_line_cb (const void *pointer, void *data,
                   (ptr_prefix && ptr_prefix[0] && is_nick) ? CONFIG_STRING(config_look_quote_nick_suffix) : "",
                   (ptr_prefix && ptr_prefix[0]) ? " " : "",
                   message);
-        gui_input_insert_string (gui_current_window->buffer, str, -1);
+        gui_input_insert_string (gui_current_window->buffer, str);
         gui_input_text_changed_modifier_and_signal (gui_current_window->buffer,
                                                     1, /* save undo */
                                                     1); /* stop completion */
index 07ffda7c4b5e6dd207910fa7c329c99aa99ccf88..29452db4482e44f0b40396a12e52d686a7be1a1d 100644 (file)
@@ -143,7 +143,7 @@ gui_cursor_display_debug_info ()
                   focus_info->chat,
                   focus_info->chat_word);
         gui_input_delete_line (gui_current_window->buffer);
-        gui_input_insert_string (gui_current_window->buffer, str_info, -1);
+        gui_input_insert_string (gui_current_window->buffer, str_info);
         gui_focus_free_info (focus_info);
     }
 }
index c7784047adcd1ce1607c883b1fdfed3199757995..6fb3785751fbae27062cd3a567971564e37971e8 100644 (file)
@@ -236,28 +236,22 @@ gui_input_set_pos (struct t_gui_buffer *buffer, int pos)
 }
 
 /*
- * Inserts a string into the input buffer.
- *
- * If pos == -1, string is inserted at cursor position.
+ * Inserts a string into the input buffer at cursor position.
  */
 
 void
-gui_input_insert_string (struct t_gui_buffer *buffer, const char *string,
-                         int pos)
+gui_input_insert_string (struct t_gui_buffer *buffer, const char *string)
 {
     int size, length;
     char *string_utf8, *ptr_start;
 
-    if (!buffer->input)
+    if (!buffer->input || !string)
         return;
 
     string_utf8 = strdup (string);
     if (!string_utf8)
         return;
 
-    if (pos == -1)
-        pos = buffer->input_buffer_pos;
-
     utf8_normalize (string_utf8, '?');
 
     size = strlen (string_utf8);
@@ -270,11 +264,10 @@ gui_input_insert_string (struct t_gui_buffer *buffer, const char *string,
         buffer->input_buffer[buffer->input_buffer_size] = '\0';
 
         /* move end of string to the right */
-        ptr_start = (char *)utf8_add_offset (buffer->input_buffer, pos);
+        ptr_start = (char *)utf8_add_offset (buffer->input_buffer, buffer->input_buffer_pos);
         memmove (ptr_start + size, ptr_start, strlen (ptr_start));
 
         /* insert new string */
-        ptr_start = (char *)utf8_add_offset (buffer->input_buffer, pos);
         memcpy (ptr_start, string_utf8, size);
 
         buffer->input_buffer_pos += length;
@@ -384,8 +377,7 @@ gui_input_clipboard_paste (struct t_gui_buffer *buffer)
     if (buffer->input && gui_input_clipboard)
     {
         gui_buffer_undo_snap (buffer);
-        gui_input_insert_string (buffer,
-                                 gui_input_clipboard, -1);
+        gui_input_insert_string (buffer, gui_input_clipboard);
         gui_input_text_changed_modifier_and_signal (buffer,
                                                     1, /* save undo */
                                                     1); /* stop completion */
@@ -508,8 +500,7 @@ gui_input_complete (struct t_gui_buffer *buffer)
         if (buffer->input_buffer[utf8_real_pos (buffer->input_buffer,
                                                 buffer->input_buffer_pos)] != ' ')
         {
-            gui_input_insert_string (buffer, " ",
-                                     buffer->input_buffer_pos);
+            gui_input_insert_string (buffer, " ");
         }
         else
             buffer->input_buffer_pos++;
@@ -1893,7 +1884,7 @@ gui_input_insert (struct t_gui_buffer *buffer, const char *args)
 
     gui_buffer_undo_snap (buffer);
     args2 = string_convert_escaped_chars (args);
-    gui_input_insert_string (buffer, (args2) ? args2 : args, -1);
+    gui_input_insert_string (buffer, (args2) ? args2 : args);
     gui_input_text_changed_modifier_and_signal (buffer,
                                                 1, /* save undo */
                                                 1); /* stop completion */
index 3fafb73571073ab4b52acd128611a4dfd54c4804..9aedf0ea1c148d59923ec837bbb7a4e1b6791f5a 100644 (file)
@@ -36,7 +36,7 @@ extern void gui_input_text_changed_modifier_and_signal (struct t_gui_buffer *buf
                                                         int stop_completion);
 extern void gui_input_set_pos (struct t_gui_buffer *buffer, int pos);
 extern void gui_input_insert_string (struct t_gui_buffer *buffer,
-                                     const char *string, int pos);
+                                     const char *string);
 extern void gui_input_move_to_buffer (struct t_gui_buffer *from_buffer,
                                       struct t_gui_buffer *to_buffer);
 extern void gui_input_clipboard_paste (struct t_gui_buffer *buffer);
index c33b11b483b8f0f46e0323a40bb5cb8ad31db775..4d31716c773bfd3ccfdf40c8cd14e8743359c132 100644 (file)
@@ -234,7 +234,7 @@ gui_key_grab_end_timer_cb (const void *pointer, void *data,
         /* add expanded key to input buffer */
         if (gui_current_window->buffer->input)
         {
-            gui_input_insert_string (gui_current_window->buffer, expanded_key, -1);
+            gui_input_insert_string (gui_current_window->buffer, expanded_key);
             if (gui_key_grab_command)
             {
                 /* add command bound to key (if found) */
@@ -242,8 +242,8 @@ gui_key_grab_end_timer_cb (const void *pointer, void *data,
                                           gui_key_combo_buffer);
                 if (ptr_key)
                 {
-                    gui_input_insert_string (gui_current_window->buffer, " ", -1);
-                    gui_input_insert_string (gui_current_window->buffer, ptr_key->command, -1);
+                    gui_input_insert_string (gui_current_window->buffer, " ");
+                    gui_input_insert_string (gui_current_window->buffer, ptr_key->command);
                 }
             }
             gui_input_text_changed_modifier_and_signal (gui_current_window->buffer,
index 2280e6fce83b11b34b63b9255001ce7d55be7145..34fe35871e83d9d3f3756d9fb4d5d05f630fe938 100644 (file)
@@ -1734,7 +1734,7 @@ gui_window_search_end (struct t_gui_window *window)
     if (window->buffer->text_search_input)
     {
         gui_input_insert_string (window->buffer,
-                                 window->buffer->text_search_input, -1);
+                                 window->buffer->text_search_input);
         gui_input_text_changed_modifier_and_signal (window->buffer,
                                                     0, /* save undo */
                                                     1); /* stop completion */
index eb6d6e2d808c7354f891de8758d54a661d8a1563..8bc444a01a63366bbdfa03f401825f75bd1540d9 100644 (file)
@@ -116,7 +116,36 @@ TEST(GuiInput, SearchSignal)
 
 TEST(GuiInput, InsertString)
 {
-    /* TODO: write tests */
+    gui_input_replace_input (gui_buffers, "");
+    LONGS_EQUAL(0, gui_buffers->input_buffer_pos);
+    STRCMP_EQUAL("", gui_buffers->input_buffer);
+
+    gui_input_insert_string (gui_buffers, NULL);
+    LONGS_EQUAL(0, gui_buffers->input_buffer_pos);
+    STRCMP_EQUAL("", gui_buffers->input_buffer);
+
+    gui_input_insert_string (gui_buffers, "");
+    STRCMP_EQUAL("", gui_buffers->input_buffer);
+    LONGS_EQUAL(0, gui_buffers->input_buffer_size);
+    LONGS_EQUAL(0, gui_buffers->input_buffer_length);
+    LONGS_EQUAL(0, gui_buffers->input_buffer_pos);
+
+    gui_input_insert_string (gui_buffers, "noël");
+    STRCMP_EQUAL("noël", gui_buffers->input_buffer);
+    LONGS_EQUAL(5, gui_buffers->input_buffer_size);
+    LONGS_EQUAL(4, gui_buffers->input_buffer_length);
+    LONGS_EQUAL(4, gui_buffers->input_buffer_pos);
+
+    gui_input_set_pos (gui_buffers, 3);
+    LONGS_EQUAL(5, gui_buffers->input_buffer_size);
+    LONGS_EQUAL(4, gui_buffers->input_buffer_length);
+    LONGS_EQUAL(3, gui_buffers->input_buffer_pos);
+
+    gui_input_insert_string (gui_buffers, "ï");
+    STRCMP_EQUAL("noëïl", gui_buffers->input_buffer);
+    LONGS_EQUAL(7, gui_buffers->input_buffer_size);
+    LONGS_EQUAL(5, gui_buffers->input_buffer_length);
+    LONGS_EQUAL(4, gui_buffers->input_buffer_pos);
 }
 
 /*