aboutsummaryrefslogtreecommitdiff
path: root/test/unit/strings_spec.lua
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2025-02-05 23:09:29 +0000
committerJosh Rahm <joshuarahm@gmail.com>2025-02-05 23:09:29 +0000
commitd5f194ce780c95821a855aca3c19426576d28ae0 (patch)
treed45f461b19f9118ad2bb1f440a7a08973ad18832 /test/unit/strings_spec.lua
parentc5d770d311841ea5230426cc4c868e8db27300a8 (diff)
parent44740e561fc93afe3ebecfd3618bda2d2abeafb0 (diff)
downloadrneovim-d5f194ce780c95821a855aca3c19426576d28ae0.tar.gz
rneovim-d5f194ce780c95821a855aca3c19426576d28ae0.tar.bz2
rneovim-d5f194ce780c95821a855aca3c19426576d28ae0.zip
Merge remote-tracking branch 'upstream/master' into mix_20240309HEADrahm
Diffstat (limited to 'test/unit/strings_spec.lua')
-rw-r--r--test/unit/strings_spec.lua26
1 files changed, 21 insertions, 5 deletions
diff --git a/test/unit/strings_spec.lua b/test/unit/strings_spec.lua
index 25cdc27b28..2b7a4d6261 100644
--- a/test/unit/strings_spec.lua
+++ b/test/unit/strings_spec.lua
@@ -1,6 +1,7 @@
local t = require('test.unit.testutil')
local itp = t.gen_itp(it)
+local child_call_once = t.child_call_once
local cimport = t.cimport
local eq = t.eq
local ffi = t.ffi
@@ -8,6 +9,12 @@ local to_cstr = t.to_cstr
local strings = cimport('stdlib.h', './src/nvim/strings.h', './src/nvim/memory.h')
+local UVARNUM_TYPE
+
+child_call_once(function()
+ UVARNUM_TYPE = ffi.typeof('uvarnumber_T')
+end)
+
describe('vim_strsave_escaped()', function()
local vim_strsave_escaped = function(s, chars)
local res = strings.vim_strsave_escaped(to_cstr(s), to_cstr(chars))
@@ -140,13 +147,22 @@ end)
describe('vim_snprintf()', function()
local function a(expected, buf, bsize, fmt, ...)
- eq(#expected, strings.vim_snprintf(buf, bsize, fmt, ...))
+ local args = { ... }
+ local ctx = string.format('snprintf(buf, %d, "%s"', bsize, fmt)
+ for _, x in ipairs(args) do
+ ctx = ctx .. ', ' .. tostring(x)
+ end
+ ctx = ctx .. string.format(') = %s', expected)
+ eq(#expected, strings.vim_snprintf(buf, bsize, fmt, ...), ctx)
if bsize > 0 then
local actual = ffi.string(buf, math.min(#expected + 1, bsize))
eq(expected:sub(1, bsize - 1) .. '\0', actual)
end
end
+ local function uv(n)
+ return ffi.cast(UVARNUM_TYPE, n)
+ end
local function i(n)
return ffi.cast('int', n)
end
@@ -181,7 +197,7 @@ describe('vim_snprintf()', function()
a(' 1234567', buf, bsize, '%9ld', l(1234567))
a('1234567 ', buf, bsize, '%-9ld', l(1234567))
a('deadbeef', buf, bsize, '%x', u(0xdeadbeef))
- a('001100', buf, bsize, '%06b', u(12))
+ a('001100', buf, bsize, '%06b', uv(12))
a('one two', buf, bsize, '%s %s', 'one', 'two')
a('1.234000', buf, bsize, '%f', 1.234)
a('1.234000e+00', buf, bsize, '%e', 1.234)
@@ -223,10 +239,10 @@ describe('vim_snprintf()', function()
a('three one two', buf, bsize, '%3$s %1$s %2$s', 'one', 'two', 'three')
a('1234567', buf, bsize, '%1$d', i(1234567))
a('deadbeef', buf, bsize, '%1$x', u(0xdeadbeef))
- a('001100', buf, bsize, '%2$0*1$b', i(6), u(12))
- a('001100', buf, bsize, '%1$0.*2$b', u(12), i(6))
+ a('001100', buf, bsize, '%2$0*1$b', i(6), uv(12))
+ a('001100', buf, bsize, '%1$0.*2$b', uv(12), i(6))
a('one two', buf, bsize, '%1$s %2$s', 'one', 'two')
- a('001100', buf, bsize, '%06b', u(12))
+ a('001100', buf, bsize, '%06b', uv(12))
a('two one', buf, bsize, '%2$s %1$s', 'one', 'two')
a('1.234000', buf, bsize, '%1$f', 1.234)
a('1.234000e+00', buf, bsize, '%1$e', 1.234)