diff options
author | Wayne Rowcliffe <war1025@gmail.com> | 2015-09-21 19:52:08 -0500 |
---|---|---|
committer | Wayne Rowcliffe <war1025@gmail.com> | 2015-11-11 21:19:52 -0600 |
commit | 70f6b0f33825f3ceac43bb00581caa57a5050009 (patch) | |
tree | 32cd39d75701c5c3277b0f195ac093d2f073f9d2 /test/unit/buffer_spec.lua | |
parent | a9dfcb7e02a0b1268c46a1bacd3f29031265a777 (diff) | |
download | rneovim-70f6b0f33825f3ceac43bb00581caa57a5050009.tar.gz rneovim-70f6b0f33825f3ceac43bb00581caa57a5050009.tar.bz2 rneovim-70f6b0f33825f3ceac43bb00581caa57a5050009.zip |
Start adding unit tests
Diffstat (limited to 'test/unit/buffer_spec.lua')
-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) |