@@ -3025,4 +3025,121 @@ func Test_complete_info_completed()
30253025 set cot &
30263026endfunc
30273027
3028+ function Test_completeopt_preinsert ()
3029+ func Omni_test (findstart, base)
3030+ if a: findstart
3031+ return col (" ." )
3032+ endif
3033+ return [#{word: " fobar" }, #{word: " foobar" }, #{word: " 你的" }, #{word: " 你好世界" }]
3034+ endfunc
3035+ set omnifunc = Omni_test
3036+ set completeopt = menu ,menuone,preinsert
3037+
3038+ new
3039+ call feedkeys (" S\<C-X>\<C-O> f" , ' tx' )
3040+ call assert_equal (" fobar" , getline (' .' ))
3041+ call feedkeys (" \<C-E>\<ESC> " , ' tx' )
3042+
3043+ call feedkeys (" S\<C-X>\<C-O> foo" , ' tx' )
3044+ call assert_equal (" foobar" , getline (' .' ))
3045+ call feedkeys (" \<C-E>\<ESC> " , ' tx' )
3046+
3047+ call feedkeys (" S\<C-X>\<C-O> foo\<BS>\<BS>\<BS> " , ' tx' )
3048+ call assert_equal (" " , getline (' .' ))
3049+ call feedkeys (" \<C-E>\<ESC> " , ' tx' )
3050+
3051+ " delete a character and input new leader
3052+ call feedkeys (" S\<C-X>\<C-O> foo\<BS> b" , ' tx' )
3053+ call assert_equal (" fobar" , getline (' .' ))
3054+ call feedkeys (" \<C-E>\<ESC> " , ' tx' )
3055+
3056+ " delete preinsert when prepare completion
3057+ call feedkeys (" S\<C-X>\<C-O> f\<Space> " , ' tx' )
3058+ call assert_equal (" f " , getline (' .' ))
3059+ call feedkeys (" \<C-E>\<ESC> " , ' tx' )
3060+
3061+ call feedkeys (" S\<C-X>\<C-O> 你" , ' tx' )
3062+ call assert_equal (" 你的" , getline (' .' ))
3063+ call feedkeys (" \<C-E>\<ESC> " , ' tx' )
3064+
3065+ call feedkeys (" S\<C-X>\<C-O> 你好" , ' tx' )
3066+ call assert_equal (" 你好世界" , getline (' .' ))
3067+ call feedkeys (" \<C-E>\<ESC> " , ' tx' )
3068+
3069+ call feedkeys (" Shello wo\<Left>\<Left>\<Left>\<C-X>\<C-O> f" , ' tx' )
3070+ call assert_equal (" hello fobar wo" , getline (' .' ))
3071+ call feedkeys (" \<C-E>\<ESC> " , ' tx' )
3072+
3073+ call feedkeys (" Shello wo\<Left>\<Left>\<Left>\<C-X>\<C-O> f\<BS> " , ' tx' )
3074+ call assert_equal (" hello wo" , getline (' .' ))
3075+ call feedkeys (" \<C-E>\<ESC> " , ' tx' )
3076+
3077+ call feedkeys (" Shello wo\<Left>\<Left>\<Left>\<C-X>\<C-O> foo" , ' tx' )
3078+ call assert_equal (" hello foobar wo" , getline (' .' ))
3079+ call feedkeys (" \<C-E>\<ESC> " , ' tx' )
3080+
3081+ call feedkeys (" Shello wo\<Left>\<Left>\<Left>\<C-X>\<C-O> foo\<BS> b" , ' tx' )
3082+ call assert_equal (" hello fobar wo" , getline (' .' ))
3083+ call feedkeys (" \<C-E>\<ESC> " , ' tx' )
3084+
3085+ " confrim
3086+ call feedkeys (" S\<C-X>\<C-O> f\<C-Y> " , ' tx' )
3087+ call assert_equal (" fobar" , getline (' .' ))
3088+ call assert_equal (5 , col (' .' ))
3089+
3090+ " cancel
3091+ call feedkeys (" S\<C-X>\<C-O> fo\<C-E> " , ' tx' )
3092+ call assert_equal (" fo" , getline (' .' ))
3093+ call assert_equal (2 , col (' .' ))
3094+
3095+ call feedkeys (" S hello hero\<CR> h\<C-X>\<C-N> " , ' tx' )
3096+ call assert_equal (" hello" , getline (' .' ))
3097+ call assert_equal (1 , col (' .' ))
3098+
3099+ call feedkeys (" Sh\<C-X>\<C-N>\<C-Y> " , ' tx' )
3100+ call assert_equal (" hello" , getline (' .' ))
3101+ call assert_equal (5 , col (' .' ))
3102+
3103+ " delete preinsert part
3104+ call feedkeys (" S\<C-X>\<C-O> fo " , ' tx' )
3105+ call assert_equal (" fo " , getline (' .' ))
3106+ call assert_equal (3 , col (' .' ))
3107+
3108+ " whole line
3109+ call feedkeys (" Shello hero\<CR>\<C-X>\<C-L> " , ' tx' )
3110+ call assert_equal (" hello hero" , getline (' .' ))
3111+ call assert_equal (1 , col (' .' ))
3112+
3113+ call feedkeys (" Shello hero\<CR> he\<C-X>\<C-L> " , ' tx' )
3114+ call assert_equal (" hello hero" , getline (' .' ))
3115+ call assert_equal (2 , col (' .' ))
3116+
3117+ " can not work with fuzzy
3118+ set cot += fuzzy
3119+ call feedkeys (" S\<C-X>\<C-O> " , ' tx' )
3120+ call assert_equal (" fobar" , getline (' .' ))
3121+ call assert_equal (5 , col (' .' ))
3122+
3123+ " test for fuzzy and noinsert
3124+ set cot += noinsert
3125+ call feedkeys (" S\<C-X>\<C-O> fb" , ' tx' )
3126+ call assert_equal (" fb" , getline (' .' ))
3127+ call assert_equal (2 , col (' .' ))
3128+
3129+ call feedkeys (" S\<C-X>\<C-O> 你" , ' tx' )
3130+ call assert_equal (" 你" , getline (' .' ))
3131+ call assert_equal (1 , col (' .' ))
3132+
3133+ call feedkeys (" S\<C-X>\<C-O> fb\<C-Y> " , ' tx' )
3134+ call assert_equal (" fobar" , getline (' .' ))
3135+ call assert_equal (5 , col (' .' ))
3136+
3137+ bw !
3138+ bw !
3139+ set cot &
3140+ set omnifunc &
3141+ delfunc Omni_test
3142+ autocmd ! CompleteChanged
3143+ endfunc
3144+
30283145" vim: shiftwidth = 2 sts = 2 expandtab nofoldenable
0 commit comments