encoding_spec.lua 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local clear, feed = n.clear, 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. t.matches('E519%:', t.pcall_err(n.command, 'set encoding=latin1'))
  14. eq('utf-8', eval('&encoding'))
  15. -- check nvim is still in utf-8 mode
  16. eq(3, eval('strwidth("Bär")'))
  17. end)
  18. it('cannot be changed before startup', function()
  19. clear('--cmd', 'set enc=latin1')
  20. -- error message expected
  21. feed('<cr>')
  22. neq(nil, string.find(eval('v:errmsg'), '^E519:'))
  23. eq('utf-8', eval('&encoding'))
  24. eq(3, eval('strwidth("Bär")'))
  25. end)
  26. it('can be set to utf-8 without error', function()
  27. n.command('set encoding=utf-8')
  28. eq('', eval('v:errmsg'))
  29. clear('--cmd', 'set enc=utf-8')
  30. eq('', eval('v:errmsg'))
  31. end)
  32. end)