test_file_size.vim 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. new
  15. set fileformat=unix undolevels=-1
  16. for i in range(1, 2000000, 100)
  17. call append(i, range(i, i + 99))
  18. endfor
  19. 1delete
  20. w! Xtest
  21. let res = systemlist('cksum Xtest')[0]
  22. let res = substitute(res, "\r", "", "")
  23. call assert_equal('3678979763 14888896 Xtest', res)
  24. enew!
  25. call delete('Xtest')
  26. set fileformat& undolevels&
  27. endfunc
  28. " Test for writing and reading a file of over 100 Kbyte
  29. func Test_File_Read_Write()
  30. enew!
  31. " Create a file with the following contents
  32. " 1 line: "This is the start"
  33. " 3001 lines: "This is the leader"
  34. " 1 line: "This is the middle"
  35. " 3001 lines: "This is the trailer"
  36. " 1 line: "This is the end"
  37. call append(0, "This is the start")
  38. call append(1, repeat(["This is the leader"], 3001))
  39. call append(3002, "This is the middle")
  40. call append(3003, repeat(["This is the trailer"], 3001))
  41. call append(6004, "This is the end")
  42. write! Xtest
  43. enew!
  44. edit! Xtest
  45. call assert_equal("This is the start", getline(1))
  46. call assert_equal("This is the middle", getline(3003))
  47. call assert_equal("This is the end", getline(6005))
  48. enew!
  49. call delete("Xtest")
  50. endfunc