mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:7.4.2051
Problem: No proper testing of trunc_string().
Solution: Add a unittest for message.c.
502ae4ba63
This commit is contained in:
parent
483e8257e5
commit
7217360e34
@ -257,7 +257,7 @@ void trunc_string(char_u *s, char_u *buf, int room, int buflen)
|
||||
return;
|
||||
}
|
||||
n = ptr2cells(s + e);
|
||||
if (len + n >= half)
|
||||
if (len + n > half)
|
||||
break;
|
||||
len += n;
|
||||
buf[e] = s[e];
|
||||
|
@ -389,7 +389,7 @@ static int included_patches[] = {
|
||||
// 2054 NA
|
||||
// 2053 NA
|
||||
// 2052 NA
|
||||
// 2051,
|
||||
2051,
|
||||
2050,
|
||||
2049,
|
||||
// 2048 NA
|
||||
|
@ -482,7 +482,7 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
Already...st change |
|
||||
Already ...t change |
|
||||
]])
|
||||
else
|
||||
screen:expect([[
|
||||
@ -495,7 +495,7 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
Already...st change |
|
||||
Already ...t change |
|
||||
]])
|
||||
end
|
||||
end
|
||||
@ -534,7 +534,7 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
Already...st change |
|
||||
Already ...t change |
|
||||
]])
|
||||
else
|
||||
screen:expect([[
|
||||
@ -547,7 +547,7 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
Already...st change |
|
||||
Already ...t change |
|
||||
]])
|
||||
end
|
||||
|
||||
@ -574,7 +574,7 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
Already...st change |
|
||||
Already ...t change |
|
||||
]])
|
||||
else
|
||||
screen:expect([[
|
||||
@ -587,7 +587,7 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
Already...st change |
|
||||
Already ...t change |
|
||||
]])
|
||||
end
|
||||
screen:detach()
|
||||
@ -616,7 +616,7 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
Already...st change |
|
||||
Already ...t change |
|
||||
]])
|
||||
else
|
||||
screen:expect([[
|
||||
@ -629,7 +629,7 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
Already...st change |
|
||||
Already ...t change |
|
||||
]])
|
||||
end
|
||||
|
||||
@ -653,7 +653,7 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
Already...st change |
|
||||
Already ...t change |
|
||||
]])
|
||||
end
|
||||
screen:detach()
|
||||
|
49
test/unit/message_spec.lua
Normal file
49
test/unit/message_spec.lua
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user