neovim

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

test_file_size.vim (1636B)


      1 " Inserts 2 million lines with consecutive integers starting from 1
      2 " (essentially, the output of GNU's seq 1 2000000), writes them to Xtest
      3 " and writes its cksum to test.out.
      4 "
      5 " We need 2 million lines to trigger a call to mf_hash_grow().  If it would mess
      6 " up the lines the checksum would differ.
      7 "
      8 " cksum is part of POSIX and so should be available on most Unixes.
      9 " If it isn't available then the test will be skipped.
     10 func Test_File_Size()
     11  if !executable('cksum')
     12      return
     13  endif
     14 
     15  new
     16  set fileformat=unix undolevels=-1
     17  for i in range(1, 2000000, 100)
     18      call append(i, range(i, i + 99))
     19  endfor
     20 
     21  1delete
     22  w! Xtest
     23  let res = systemlist('cksum Xtest')[0]
     24  let res = substitute(res, "\r", "", "")
     25  call assert_equal('3678979763 14888896 Xtest', res)
     26 
     27  enew!
     28  call delete('Xtest')
     29  set fileformat& undolevels&
     30 endfunc
     31 
     32 " Test for writing and reading a file of over 100 Kbyte
     33 func Test_File_Read_Write()
     34  enew!
     35 
     36  " Create a file with the following contents
     37  " 1 line: "This is the start"
     38  " 3001 lines: "This is the leader"
     39  " 1 line: "This is the middle"
     40  " 3001 lines: "This is the trailer"
     41  " 1 line: "This is the end"
     42  call append(0, "This is the start")
     43  call append(1, repeat(["This is the leader"], 3001))
     44  call append(3002, "This is the middle")
     45  call append(3003, repeat(["This is the trailer"], 3001))
     46  call append(6004, "This is the end")
     47 
     48  write! Xtest
     49  enew!
     50  edit! Xtest
     51 
     52  call assert_equal("This is the start", getline(1))
     53  call assert_equal("This is the middle", getline(3003))
     54  call assert_equal("This is the end", getline(6005))
     55 
     56  enew!
     57  call delete("Xtest")
     58 endfunc