fix(printf): make positional %zd and %zu work (#24722)

This commit is contained in:
zeertzjq
2023-08-15 20:54:28 +08:00
committed by GitHub
parent 842a47d6a4
commit fc14928719
2 changed files with 37 additions and 6 deletions

View File

@@ -150,10 +150,12 @@ describe('vim_snprintf()', function()
local function i(n) return ffi.cast('int', n) end
local function l(n) return ffi.cast('long', n) end
local function u(n) return ffi.cast('unsigned', n) end
local function ll(n) return ffi.cast('long long', n) end
local function z(n) return ffi.cast('ptrdiff_t', n) end
local function u(n) return ffi.cast('unsigned', n) end
local function ul(n) return ffi.cast('unsigned long', n) end
local function ull(n) return ffi.cast('unsigned long long', n) end
local function uz(n) return ffi.cast('size_t', n) end
itp('truncation', function()
for bsize = 0, 14 do
@@ -219,6 +221,15 @@ describe('vim_snprintf()', function()
a('-0.000000', buf, bsize, '%1$f', -0.0)
end
end)
itp('%zd and %zu', function()
local bsize = 20
local buf = ffi.gc(strings.xmalloc(bsize), strings.xfree)
a('-1234567 -7654321', buf, bsize, '%zd %zd', z(-1234567), z(-7654321))
a('-7654321 -1234567', buf, bsize, '%2$zd %1$zd', z(-1234567), z(-7654321))
a('1234567 7654321', buf, bsize, '%zu %zu', uz(1234567), uz(7654321))
a('7654321 1234567', buf, bsize, '%2$zu %1$zu', uz(1234567), uz(7654321))
end)
end)
describe('strcase_save()' , function()