neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

test_charsearch.vim (2701B)


      1 " Test for character search commands - t, T, f, F, ; and ,
      2 
      3 func Test_charsearch()
      4  enew!
      5  call append(0, ['Xabcdefghijkemnopqretuvwxyz',
      6       \ 'Yabcdefghijkemnopqretuvwxyz',
      7       \ 'Zabcdefghijkemnokqretkvwxyz'])
      8  " check that "fe" and ";" work
      9  1
     10  normal! ylfep;;p,,p
     11  call assert_equal('XabcdeXfghijkeXmnopqreXtuvwxyz', getline(1))
     12  " check that save/restore works
     13  2
     14  normal! ylfep
     15  let csave = getcharsearch()
     16  normal! fip
     17  call setcharsearch(csave)
     18  normal! ;p;p
     19  call assert_equal('YabcdeYfghiYjkeYmnopqreYtuvwxyz', getline(2))
     20 
     21  " check that setcharsearch() changes the settings.
     22  3
     23  normal! ylfep
     24  eval {'char': 'k'}->setcharsearch()
     25  normal! ;p
     26  call setcharsearch({'forward': 0})
     27  normal! $;p
     28  call setcharsearch({'until': 1})
     29  set cpo-=;
     30  normal! ;;p
     31  call assert_equal('ZabcdeZfghijkZZemnokqretkZvwxyz', getline(3))
     32 
     33  " check that repeating a search before and after a line fails
     34  normal 3Gfv
     35  call assert_beeps('normal ;')
     36  call assert_beeps('normal ,')
     37 
     38  " clear the character search
     39  call setcharsearch({'char' : ''})
     40  call assert_equal('', getcharsearch().char)
     41  call assert_beeps('normal ;')
     42  call assert_beeps('normal ,')
     43 
     44  call assert_fails("call setcharsearch([])", 'E1206:')
     45  enew!
     46 endfunc
     47 
     48 " Test for character search in virtual edit mode with <Tab>
     49 func Test_csearch_virtualedit()
     50  new
     51  set virtualedit=all
     52  call setline(1, "a\tb")
     53  normal! tb
     54  call assert_equal([0, 1, 2, 6], getpos('.'))
     55  set virtualedit&
     56  bw!
     57 endfunc
     58 
     59 " Test for character search failure in latin1 encoding
     60 func Test_charsearch_latin1()
     61  new
     62  let save_enc = &encoding
     63  " set encoding=latin1
     64  call setline(1, 'abcdefghijk')
     65  call assert_beeps('normal fz')
     66  call assert_beeps('normal tx')
     67  call assert_beeps('normal $Fz')
     68  call assert_beeps('normal $Tx')
     69  let &encoding = save_enc
     70  bw!
     71 endfunc
     72 
     73 " Test for using character search to find a multibyte character with composing
     74 " characters.
     75 func Test_charsearch_composing_char()
     76  new
     77  call setline(1, "one two thq\u0328\u0301r\u0328\u0301ree")
     78  call feedkeys("fr\u0328\u0301", 'xt')
     79  call assert_equal([0, 1, 16, 0, 12], getcurpos())
     80 
     81  " use character search with a multi-byte character followed by a
     82  " non-composing character
     83  call setline(1, "abc deȉf ghi")
     84  call feedkeys("ggcf\u0209\u0210", 'xt')
     85  call assert_equal("\u0210f ghi", getline(1))
     86  bw!
     87 endfunc
     88 
     89 " Test for character search with 'hkmap'
     90 func Test_charsearch_hkmap()
     91  throw "Skipped: Nvim does not support 'hkmap'"
     92  new
     93  set hkmap
     94  call setline(1, "ùðáâ÷ëòéïçìêöî")
     95  call feedkeys("fë", 'xt')
     96  call assert_equal([0, 1, 11, 0, 6], getcurpos())
     97  set hkmap&
     98  bw!
     99 endfunc
    100 
    101 " vim: shiftwidth=2 sts=2 expandtab