encoding_spec.lua (1075B)
1 local t = require('test.testutil') 2 local n = require('test.functional.testnvim')() 3 4 local clear, feed = n.clear, n.feed 5 local eq, neq, eval = t.eq, t.neq, n.eval 6 7 describe('&encoding', function() 8 before_each(function() 9 clear() 10 -- sanity check: tests should run with encoding=utf-8 11 eq('utf-8', eval('&encoding')) 12 eq(3, eval('strwidth("Bär")')) 13 end) 14 15 it('cannot be changed after setup', function() 16 t.matches('E519%:', t.pcall_err(n.command, 'set encoding=latin1')) 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 22 it('cannot be changed before startup', function() 23 clear('--cmd', 'set enc=latin1') 24 -- error message expected 25 feed('<cr>') 26 neq(nil, string.find(eval('v:errmsg'), '^E519:')) 27 eq('utf-8', eval('&encoding')) 28 eq(3, eval('strwidth("Bär")')) 29 end) 30 31 it('can be set to utf-8 without error', function() 32 n.command('set encoding=utf-8') 33 eq('', eval('v:errmsg')) 34 35 clear('--cmd', 'set enc=utf-8') 36 eq('', eval('v:errmsg')) 37 end) 38 end)