test_unlet.vim 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. " Tests for :unlet
  2. func Test_read_only()
  3. " these caused a crash
  4. call assert_fails('unlet v:count', 'E795:')
  5. call assert_fails('unlet v:errmsg', 'E795:')
  6. endfunc
  7. func Test_existing()
  8. let does_exist = 1
  9. call assert_true(exists('does_exist'))
  10. unlet does_exist
  11. call assert_false(exists('does_exist'))
  12. endfunc
  13. func Test_not_existing()
  14. unlet! does_not_exist
  15. call assert_fails('unlet does_not_exist', 'E108:')
  16. endfunc
  17. func Test_unlet_fails()
  18. call assert_fails('unlet v:["count"]', 'E46:')
  19. call assert_fails('unlet $', 'E475:')
  20. let v = {}
  21. call assert_fails('unlet v[:]', 'E719:')
  22. let l = []
  23. call assert_fails("unlet l['k'", 'E111:')
  24. let d = {'k' : 1}
  25. call assert_fails("unlet d.k2", 'E716:')
  26. call assert_fails("unlet {a};", 'E488:')
  27. endfunc
  28. func Test_unlet_env()
  29. let envcmd = has('win32') ? 'set' : 'env'
  30. let $FOOBAR = 'test'
  31. let found = 0
  32. for kv in split(system(envcmd), "\r*\n")
  33. if kv == 'FOOBAR=test'
  34. let found = 1
  35. endif
  36. endfor
  37. call assert_equal(1, found)
  38. unlet $FOOBAR
  39. let found = 0
  40. for kv in split(system(envcmd), "\r*\n")
  41. if kv == 'FOOBAR=test'
  42. let found = 1
  43. endif
  44. endfor
  45. call assert_equal(0, found)
  46. unlet $MUST_NOT_BE_AN_ERROR
  47. endfunc
  48. func Test_unlet_complete()
  49. let g:FOOBAR = 1
  50. call feedkeys(":unlet g:FOO\t\n", 'tx')
  51. call assert_true(!exists('g:FOOBAR'))
  52. let $FOOBAR = 1
  53. call feedkeys(":unlet $FOO\t\n", 'tx')
  54. call assert_true(!exists('$FOOBAR') || empty($FOOBAR))
  55. endfunc
  56. " vim: shiftwidth=2 sts=2 expandtab