encoding_spec.lua 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local clear, feed_command, feed = n.clear, n.feed_command, n.feed
  4. local eq, neq, eval = t.eq, t.neq, n.eval
  5. describe('&encoding', function()
  6. before_each(function()
  7. clear()
  8. -- sanity check: tests should run with encoding=utf-8
  9. eq('utf-8', eval('&encoding'))
  10. eq(3, eval('strwidth("Bär")'))
  11. end)
  12. it('cannot be changed after setup', function()
  13. feed_command('set encoding=latin1')
  14. -- error message expected
  15. feed('<cr>')
  16. neq(nil, string.find(eval('v:errmsg'), '^E519:'))
  17. eq('utf-8', eval('&encoding'))
  18. -- check nvim is still in utf-8 mode
  19. eq(3, eval('strwidth("Bär")'))
  20. end)
  21. it('cannot be changed before startup', function()
  22. clear('--cmd', 'set enc=latin1')
  23. -- error message expected
  24. feed('<cr>')
  25. neq(nil, string.find(eval('v:errmsg'), '^E519:'))
  26. eq('utf-8', eval('&encoding'))
  27. eq(3, eval('strwidth("Bär")'))
  28. end)
  29. it('can be set to utf-8 without error', function()
  30. feed_command('set encoding=utf-8')
  31. eq('', eval('v:errmsg'))
  32. clear('--cmd', 'set enc=utf-8')
  33. eq('', eval('v:errmsg'))
  34. end)
  35. end)