Merge pull request #3339 from war1025/dev/clean_build_stl_str_hl

Clean up buffer.c build_stl_str_hl
This commit is contained in:
Justin M. Keyes 2015-11-15 16:48:13 -05:00
commit 91c5135f71
2 changed files with 751 additions and 350 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,15 @@
local assert = require("luassert")
local helpers = require("test.unit.helpers") local helpers = require("test.unit.helpers")
local to_cstr = helpers.to_cstr local to_cstr = helpers.to_cstr
local eq = helpers.eq local eq = helpers.eq
local neq = helpers.neq
local globals = helpers.cimport("./src/nvim/globals.h")
local buffer = helpers.cimport("./src/nvim/buffer.h") local buffer = helpers.cimport("./src/nvim/buffer.h")
local fileio = helpers.cimport("./src/nvim/fileio.h")
local ex_docmd = helpers.cimport("./src/nvim/ex_docmd.h")
local window = helpers.cimport("./src/nvim/window.h") local window = helpers.cimport("./src/nvim/window.h")
local option = helpers.cimport("./src/nvim/option.h") local option = helpers.cimport("./src/nvim/option.h")
@ -206,4 +212,95 @@ describe('buffer functions', function()
close_buffer(NULL, buf2, buffer.DOBUF_WIPE, 0) close_buffer(NULL, buf2, buffer.DOBUF_WIPE, 0)
end) end)
end) end)
describe('build_stl_str_hl', function()
output_buffer = to_cstr(string.rep(" ", 100))
local build_stl_str_hl = function(pat)
return buffer.build_stl_str_hl(globals.curwin,
output_buffer,
100,
to_cstr(pat),
false,
32,
80,
NULL,
NULL)
end
it('should copy plain text', function()
local width = build_stl_str_hl("this is a test")
eq(14, width)
eq("this is a test", helpers.ffi.string(output_buffer, width))
end)
it('should print no file name', function()
local width = build_stl_str_hl("%f")
eq(9, width)
eq("[No Name]", helpers.ffi.string(output_buffer, width))
end)
it('should print the relative file name', function()
buffer.setfname(globals.curbuf, to_cstr("Makefile"), NULL, 1)
local width = build_stl_str_hl("%f")
eq(8, width)
eq("Makefile", helpers.ffi.string(output_buffer, width))
end)
it('should print the full file name', function()
buffer.setfname(globals.curbuf, to_cstr("Makefile"), NULL, 1)
local width = build_stl_str_hl("%F")
assert.is_true(8 < width)
neq(NULL, string.find(helpers.ffi.string(output_buffer, width), "Makefile"))
end)
it('should print the tail file name', function()
buffer.setfname(globals.curbuf, to_cstr("src/nvim/buffer.c"), NULL, 1)
local width = build_stl_str_hl("%t")
eq(8, width)
eq("buffer.c", helpers.ffi.string(output_buffer, width))
end)
it('should print the buffer number', function()
buffer.setfname(globals.curbuf, to_cstr("src/nvim/buffer.c"), NULL, 1)
local width = build_stl_str_hl("%n")
eq(1, width)
eq("1", helpers.ffi.string(output_buffer, width))
end)
it('should print the current line number in the buffer', function()
buffer.setfname(globals.curbuf, to_cstr("test/unit/buffer_spec.lua"), NULL, 1)
local width = build_stl_str_hl("%l")
eq(1, width)
eq("0", helpers.ffi.string(output_buffer, width))
end)
it('should print the number of lines in the buffer', function()
buffer.setfname(globals.curbuf, to_cstr("test/unit/buffer_spec.lua"), NULL, 1)
local width = build_stl_str_hl("%L")
eq(1, width)
eq("1", helpers.ffi.string(output_buffer, width))
end)
end)
end) end)