diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2015-11-15 16:48:13 -0500 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2015-11-15 16:48:13 -0500 |
commit | 91c5135f7145ccced93fad797f227a2fff3edab9 (patch) | |
tree | 024d3fbbc2a09536a3ba51add4cf54956e5976fe /test/unit | |
parent | 9b8ac827b4b6486d9d0bdf374b998f37f7b7442a (diff) | |
parent | eed4df33f93a49af0cdfd67a9bdb2495be9e6998 (diff) | |
download | rneovim-91c5135f7145ccced93fad797f227a2fff3edab9.tar.gz rneovim-91c5135f7145ccced93fad797f227a2fff3edab9.tar.bz2 rneovim-91c5135f7145ccced93fad797f227a2fff3edab9.zip |
Merge pull request #3339 from war1025/dev/clean_build_stl_str_hl
Clean up buffer.c build_stl_str_hl
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/buffer_spec.lua | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/test/unit/buffer_spec.lua b/test/unit/buffer_spec.lua index e0e2b827e9..05fba684d6 100644 --- a/test/unit/buffer_spec.lua +++ b/test/unit/buffer_spec.lua @@ -1,9 +1,15 @@ + +local assert = require("luassert") local helpers = require("test.unit.helpers") local to_cstr = helpers.to_cstr 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 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 option = helpers.cimport("./src/nvim/option.h") @@ -206,4 +212,95 @@ describe('buffer functions', function() close_buffer(NULL, buf2, buffer.DOBUF_WIPE, 0) 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) |