From 281da0dd59fbc5aa7ff1c6f0300c661c1a62cb8c Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Tue, 30 Oct 2018 23:20:23 +0100 Subject: api: implement nvim_buf_get_offset_for_line Like line2byte, but works for any buffer, and uses zero-based indexing (API conventions). --- test/functional/api/buffer_spec.lua | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'test/functional/api/buffer_spec.lua') diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index 271e196103..d3739c74d2 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -301,6 +301,40 @@ describe('api/buf', function() end) end) + describe('get_offset_for_line', function() + local get_offset_for_line = curbufmeths.get_offset_for_line + it('works', function() + curbufmeths.set_lines(0,-1,true,{'Some','exa\000mple', '', 'text'}) + eq(4, curbufmeths.line_count()) + eq(0, get_offset_for_line(0)) + eq(5, get_offset_for_line(1)) + eq(14, get_offset_for_line(2)) + eq(15, get_offset_for_line(3)) + eq(20, get_offset_for_line(4)) + eq({false,'Index out of bounds'}, meth_pcall(get_offset_for_line, 5)) + eq({false,'Index out of bounds'}, meth_pcall(get_offset_for_line, -1)) + + curbufmeths.set_option('eol', false) + curbufmeths.set_option('fixeol', false) + eq(19, get_offset_for_line(4)) + + curbufmeths.set_option('fileformat', 'dos') + eq(0, get_offset_for_line(0)) + eq(6, get_offset_for_line(1)) + eq(16, get_offset_for_line(2)) + eq(18, get_offset_for_line(3)) + eq(22, get_offset_for_line(4)) + curbufmeths.set_option('eol', true) + eq(24, get_offset_for_line(4)) + + command("set hidden") + command("enew") + eq(6, bufmeths.get_offset_for_line(1,1)) + command("bunload! 1") + eq(-1, bufmeths.get_offset_for_line(1,1)) + end) + end) + describe('{get,set,del}_var', function() it('works', function() curbuf('set_var', 'lua', {1, 2, {['3'] = 1}}) -- cgit