diff options
author | James McCoy <jamessan@jamessan.com> | 2017-03-06 10:44:07 -0500 |
---|---|---|
committer | James McCoy <jamessan@jamessan.com> | 2017-03-06 15:09:40 -0500 |
commit | 7217360e349ff787933d91b55efdfeb435eb45cb (patch) | |
tree | 942deed0e32eab2ecfd56f97f078a56a266cb50f /test/unit/message_spec.lua | |
parent | 483e8257e5a28893bcd1de089715f82798d0f93a (diff) | |
download | rneovim-7217360e349ff787933d91b55efdfeb435eb45cb.tar.gz rneovim-7217360e349ff787933d91b55efdfeb435eb45cb.tar.bz2 rneovim-7217360e349ff787933d91b55efdfeb435eb45cb.zip |
vim-patch:7.4.2051
Problem: No proper testing of trunc_string().
Solution: Add a unittest for message.c.
https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Diffstat (limited to 'test/unit/message_spec.lua')
-rw-r--r-- | test/unit/message_spec.lua | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/test/unit/message_spec.lua b/test/unit/message_spec.lua new file mode 100644 index 0000000000..23d342c027 --- /dev/null +++ b/test/unit/message_spec.lua @@ -0,0 +1,49 @@ +local helpers = require("test.unit.helpers") + +local ffi = helpers.ffi +local eq = helpers.eq +local to_cstr = helpers.to_cstr + +local cimp = helpers.cimport('./src/nvim/message.h') + +describe('trunc_string', function() + local buffer = ffi.typeof('char_u[40]') + + local function test_inplace(s, expected) + local buf = buffer() + ffi.C.strcpy(buf, s) + cimp.trunc_string(buf, buf, 20, 40) + eq(expected, ffi.string(buf)) + end + + local function test_copy(s, expected) + local buf = buffer() + cimp.trunc_string(to_cstr(s), buf, 20, 40) + eq(expected, ffi.string(buf)) + end + + local permutations = { + { ['desc'] = 'in-place', ['func'] = test_inplace }, + { ['desc'] = 'by copy', ['func'] = test_copy }, + } + + for _,t in ipairs(permutations) do + describe('populates buf '..t.desc, function() + it('with a small string', function() + t.func('text', 'text') + end) + + it('with a medium string', function() + t.func('a short text', 'a short text') + end) + + it('with a string exactly the truncate size', function() + t.func('a text tha just fits', 'a text tha just fits') + end) + + it('with a string that must be truncated', function() + t.func('a text that nott fits', 'a text t...nott fits') + end) + end) + end +end) |