Skip to content

Commit 5e80de3

Browse files
committed
patch 8.0.1048: no test for what 8.0.1020 fixes
Problem: No test for what 8.0.1020 fixes. Solution: Add test_feedinput(). Add a test. (Ozaki Kiichi, closes #2046)
1 parent 00ccf54 commit 5e80de3

5 files changed

Lines changed: 46 additions & 15 deletions

File tree

runtime/doc/eval.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,6 +2410,7 @@ term_wait({buf} [, {time}]) Number wait for screen to be updated
24102410
test_alloc_fail({id}, {countdown}, {repeat})
24112411
none make memory allocation fail
24122412
test_autochdir() none enable 'autochdir' during startup
2413+
test_feedinput() none add key sequence to input buffer
24132414
test_garbagecollect_now() none free memory right now for testing
24142415
test_ignore_error({expr}) none ignore a specific error
24152416
test_null_channel() Channel null value for testing
@@ -8196,6 +8197,11 @@ test_autochdir() *test_autochdir()*
81968197
Set a flag to enable the effect of 'autochdir' before Vim
81978198
startup has finished.
81988199

8200+
test_feedinput({string}) *test_feedinput()*
8201+
Characters in {string} are queued for processing as if they
8202+
were typed by the user. This uses a low level input buffer.
8203+
This function works only when with |+unix| or GUI is running.
8204+
81998205
test_garbagecollect_now() *test_garbagecollect_now()*
82008206
Like garbagecollect(), but executed right away. This must
82018207
only be called directly to avoid any structure to exist

src/evalfunc.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ static void f_tagfiles(typval_T *argvars, typval_T *rettv);
393393
static void f_tempname(typval_T *argvars, typval_T *rettv);
394394
static void f_test_alloc_fail(typval_T *argvars, typval_T *rettv);
395395
static void f_test_autochdir(typval_T *argvars, typval_T *rettv);
396+
static void f_test_feedinput(typval_T *argvars, typval_T *rettv);
396397
static void f_test_override(typval_T *argvars, typval_T *rettv);
397398
static void f_test_garbagecollect_now(typval_T *argvars, typval_T *rettv);
398399
static void f_test_ignore_error(typval_T *argvars, typval_T *rettv);
@@ -851,6 +852,7 @@ static struct fst
851852
#endif
852853
{"test_alloc_fail", 3, 3, f_test_alloc_fail},
853854
{"test_autochdir", 0, 0, f_test_autochdir},
855+
{"test_feedinput", 1, 1, f_test_feedinput},
854856
{"test_garbagecollect_now", 0, 0, f_test_garbagecollect_now},
855857
{"test_ignore_error", 1, 1, f_test_ignore_error},
856858
#ifdef FEAT_JOB_CHANNEL
@@ -12517,6 +12519,23 @@ f_test_autochdir(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
1251712519
#endif
1251812520
}
1251912521

12522+
/*
12523+
* "test_feedinput()"
12524+
*/
12525+
static void
12526+
f_test_feedinput(typval_T *argvars, typval_T *rettv UNUSED)
12527+
{
12528+
#ifdef USE_INPUT_BUF
12529+
char_u *val = get_tv_string_chk(&argvars[0]);
12530+
12531+
if (val != NULL)
12532+
{
12533+
trash_input_buf();
12534+
add_to_input_buf_csi(val, (int)STRLEN(val));
12535+
}
12536+
#endif
12537+
}
12538+
1252012539
/*
1252112540
* "test_disable({name}, {val})" function
1252212541
*/

src/testdir/test_timers.vim

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,5 +206,24 @@ func Test_timer_errors()
206206
call assert_equal(3, g:call_count)
207207
endfunc
208208

209+
func FeedAndPeek(timer)
210+
call test_feedinput('a')
211+
call getchar(1)
212+
endfunc
213+
214+
func Interrupt(timer)
215+
call test_feedinput("\<C-C>")
216+
endfunc
217+
218+
func Test_peek_and_get_char()
219+
if !has('unix') && !has('gui_running')
220+
return
221+
endif
222+
call timer_start(0, 'FeedAndPeek')
223+
let intr = timer_start(100, 'Interrupt')
224+
let c = getchar()
225+
call assert_equal(char2nr('a'), c)
226+
call timer_stop(intr)
227+
endfunc
209228

210229
" vim: shiftwidth=2 sts=2 expandtab

src/ui.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,11 +1651,6 @@ set_input_buf(char_u *p)
16511651
}
16521652
}
16531653

1654-
#if defined(FEAT_GUI) \
1655-
|| defined(FEAT_MOUSE_GPM) || defined(FEAT_SYSMOUSE) \
1656-
|| defined(FEAT_XCLIPBOARD) || defined(VMS) \
1657-
|| defined(FEAT_CLIENTSERVER) \
1658-
|| defined(PROTO)
16591654
/*
16601655
* Add the given bytes to the input buffer
16611656
* Special keys start with CSI. A real CSI must have been translated to
@@ -1676,15 +1671,7 @@ add_to_input_buf(char_u *s, int len)
16761671
while (len--)
16771672
inbuf[inbufcount++] = *s++;
16781673
}
1679-
#endif
16801674

1681-
#if ((defined(FEAT_XIM) || defined(FEAT_DND)) && defined(FEAT_GUI_GTK)) \
1682-
|| defined(FEAT_GUI_MSWIN) \
1683-
|| defined(FEAT_GUI_MAC) \
1684-
|| (defined(FEAT_MBYTE) && defined(FEAT_MBYTE_IME)) \
1685-
|| (defined(FEAT_GUI) && (!defined(USE_ON_FLY_SCROLL) \
1686-
|| defined(FEAT_MENU))) \
1687-
|| defined(PROTO)
16881675
/*
16891676
* Add "str[len]" to the input buffer while escaping CSI bytes.
16901677
*/
@@ -1706,7 +1693,6 @@ add_to_input_buf_csi(char_u *str, int len)
17061693
}
17071694
}
17081695
}
1709-
#endif
17101696

17111697
#if defined(FEAT_HANGULIN) || defined(PROTO)
17121698
void
@@ -1744,7 +1730,6 @@ trash_input_buf(void)
17441730
/*
17451731
* Read as much data from the input buffer as possible up to maxlen, and store
17461732
* it in buf.
1747-
* Note: this function used to be Read() in unix.c
17481733
*/
17491734
int
17501735
read_from_input_buf(char_u *buf, long maxlen)

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ static char *(features[]) =
769769

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
1048,
772774
/**/
773775
1047,
774776
/**/

0 commit comments

Comments
 (0)