077_mf_hash_grow_spec.lua 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 calculates its cksum.
  4. -- We need 2 million lines to trigger a call to mf_hash_grow(). If it would mess
  5. -- up the lines the checksum would differ.
  6. -- cksum is part of POSIX and so should be available on most Unixes.
  7. -- If it isn't available then the test will be skipped.
  8. local helpers = require('test.functional.helpers')(after_each)
  9. local feed = helpers.feed
  10. local wait = helpers.wait
  11. local clear = helpers.clear
  12. local expect = helpers.expect
  13. local command = helpers.command
  14. describe('mf_hash_grow()', function()
  15. setup(clear)
  16. -- Check to see if cksum exists, otherwise skip the test
  17. local null = helpers.iswin() and 'nul' or '/dev/null'
  18. if os.execute('cksum --help >' .. null .. ' 2>&1') ~= 0 then
  19. pending('was not tested because cksum was not found', function() end)
  20. else
  21. it('is working', function()
  22. command('set fileformat=unix undolevels=-1')
  23. -- Fill the buffer with numbers 1 - 2000000
  24. command('let i = 1')
  25. command('while i <= 2000000 | call append(i, range(i, i + 99)) | let i += 100 | endwhile')
  26. -- Delete empty first line, save to Xtest, and clear buffer
  27. feed('ggdd<cr>')
  28. wait()
  29. command('w! Xtest')
  30. feed('ggdG<cr>')
  31. wait()
  32. -- Calculate the cksum of Xtest and delete first line
  33. command('r !cksum Xtest')
  34. feed('ggdd<cr>')
  35. -- Assert correct output of cksum.
  36. expect([[
  37. 3678979763 14888896 Xtest]])
  38. end)
  39. end
  40. teardown(function()
  41. os.remove('Xtest')
  42. end)
  43. end)