test_sleep.vim 773 B

12345678910111213141516171819202122232425262728
  1. " Test for sleep and sleep! commands
  2. func! s:get_time_ms()
  3. let timestr = reltimestr(reltime())
  4. let dotidx = stridx(timestr, '.')
  5. let sec = str2nr(timestr[:dotidx])
  6. let msec = str2nr(timestr[dotidx + 1:])
  7. return (sec * 1000) + (msec / 1000)
  8. endfunc
  9. func! s:assert_takes_longer(cmd, time_ms)
  10. let start = s:get_time_ms()
  11. execute a:cmd
  12. let end = s:get_time_ms()
  13. call assert_true(end - start >=# a:time_ms)
  14. endfun
  15. func! Test_sleep_bang()
  16. call s:assert_takes_longer('sleep 50m', 50)
  17. call s:assert_takes_longer('sleep! 50m', 50)
  18. call s:assert_takes_longer('sl 50m', 50)
  19. call s:assert_takes_longer('sl! 50m', 50)
  20. call s:assert_takes_longer('1sleep', 1000)
  21. call s:assert_takes_longer('normal 1gs', 1000)
  22. endfunc
  23. " vim: shiftwidth=2 sts=2 expandtab