Created
July 22, 2015 19:56
-
-
Save lucc/0393a00957dcaa29f434 to your computer and use it in GitHub Desktop.
Test file to check how encoding is handled between nvim and the test suite.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local helpers = require('test.functional.helpers') | |
local clear, feed, execute, expect, eq, eval, wait, insert = helpers.clear, helpers.feed, helpers.execute, helpers.expect, helpers.eq, helpers.eval, helpers.wait, helpers.insert | |
local function diff(text) | |
execute('w! Xtest') | |
wait() | |
local file = io.open('Xtest') | |
local data = file:read('*all') | |
file:close() | |
return eq(text, data) | |
end | |
local function mime(mime_type) | |
execute('w! Xtest') | |
wait() | |
eq(mime_type, io.popen('file --mime-encoding Xtest'):read():sub(8)) | |
end | |
describe('the lua test suite', function() | |
-- This lua source file should be encoded in utf-8. Some of the strings | |
-- below use hex escape sequences to be able to store a different encoding. | |
local ascii = 'ascii characters: AOU aou' | |
-- The escaped characters are the German umlauts of the above "AOU aou". | |
local utf8 = 'utf-8 characters: \xc3\x84\xc3\x96\xc3\x9c \xc3\xa4\xc3\xb6\xc3\xbc' | |
local latin1 = 'latin1 characters: \xc4\xd6\xdc \xe4\xf6\xfc' | |
before_each(clear) | |
teardown(function() | |
--os.remove('Xtest') | |
end) | |
it('can feed() ascii text to nvim and expect() it', function() | |
-- The default fileencoding is utf-8. | |
eq('', eval('&fileencoding')) | |
feed('i'..ascii..'<ESC>') | |
mime('ascii') | |
diff(ascii..'\n') | |
expect(ascii) | |
end) | |
it('can insert() ascii text to nvim and expect() it', function() | |
-- The default fileencoding is utf-8. | |
eq('', eval('&fileencoding')) | |
insert(ascii) | |
mime('ascii') | |
diff(ascii..'\n') | |
expect(ascii) | |
end) | |
it('can feed() utf-8 text to nvim and expect() it', function() | |
-- The default fileencoding is utf-8. | |
eq('', eval('&fileencoding')) | |
feed('i'..utf8..'<ESC>') | |
mime('utf-8') | |
diff(utf8..'\n') | |
expect(utf8) | |
end) | |
it('can insert() utf-8 text to nvim and expect() it', function() | |
-- The default fileencoding is utf-8. | |
eq('', eval('&fileencoding')) | |
insert(utf8) | |
mime('utf-8') | |
diff(utf8..'\n') | |
expect(utf8) | |
end) | |
it('can feed() latin-1 text to nvim and expect() it', function() | |
execute('set fileencoding=latin1') | |
feed('i'..latin1..'<ESC>') | |
mime('iso-8859-1') | |
diff(latin1..'\n') | |
expect(latin1) | |
end) | |
it('can insert() latin-1 text to nvim and expect() it', function() | |
execute('set fileencoding=latin1') | |
insert(latin1) | |
mime('iso-8859-1') | |
diff(latin1..'\n') | |
expect(latin1) | |
end) | |
it('getline() returns utf-8 text', function() | |
-- The default fileencoding is utf-8. | |
eq('', eval('&fileencoding')) | |
insert(utf8) | |
eq(utf8, eval('getline(".")')) | |
end) | |
it('getline() returns latin1 text', function() | |
execute('set fileencoding=latin1') | |
insert(latin1) | |
eq(latin1, eval('getline(".")')) | |
end) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment