mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 20:55:18 -07:00
test: port kword_test to Lua for utf_char2bytes()
Use LuaJIT FFI to create char pointer. Validate output with utf_ptr2char(), vim_iswordc() and vim_iswordp(). Use const for LuaJIT string-to-char conversion.
This commit is contained in:
parent
6ff892165a
commit
3e4a058b01
@ -826,7 +826,7 @@ bool vim_isIDc(int c)
|
||||
/// For multi-byte characters mb_get_class() is used (builtin rules).
|
||||
///
|
||||
/// @param c character to check
|
||||
bool vim_iswordc(int c)
|
||||
bool vim_iswordc(const int c)
|
||||
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
|
||||
{
|
||||
return vim_iswordc_buf(c, curbuf);
|
||||
@ -852,7 +852,7 @@ bool vim_iswordc_tab(const int c, const uint64_t *const chartab)
|
||||
///
|
||||
/// @param c character to check
|
||||
/// @param buf buffer whose keywords to use
|
||||
bool vim_iswordc_buf(int c, buf_T *buf)
|
||||
bool vim_iswordc_buf(const int c, buf_T *const buf)
|
||||
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(2)
|
||||
{
|
||||
return vim_iswordc_tab(c, buf->b_chartab);
|
||||
@ -863,7 +863,7 @@ bool vim_iswordc_buf(int c, buf_T *buf)
|
||||
/// @param p pointer to the multi-byte character
|
||||
///
|
||||
/// @return true if "p" points to a keyword character.
|
||||
bool vim_iswordp(char_u *p)
|
||||
bool vim_iswordp(const char_u *const p)
|
||||
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
return vim_iswordp_buf(p, curbuf);
|
||||
@ -876,7 +876,7 @@ bool vim_iswordp(char_u *p)
|
||||
/// @param buf buffer whose keywords to use
|
||||
///
|
||||
/// @return true if "p" points to a keyword character.
|
||||
bool vim_iswordp_buf(char_u *p, buf_T *buf)
|
||||
bool vim_iswordp_buf(const char_u *const p, buf_T *const buf)
|
||||
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
int c = *p;
|
||||
|
@ -5,6 +5,7 @@ local ffi = helpers.ffi
|
||||
local eq = helpers.eq
|
||||
|
||||
local mbyte = helpers.cimport("./src/nvim/mbyte.h")
|
||||
local charset = helpers.cimport('./src/nvim/charset.h')
|
||||
|
||||
describe('mbyte', function()
|
||||
|
||||
@ -42,6 +43,15 @@ describe('mbyte', function()
|
||||
-- Sequences with more than four bytes
|
||||
end)
|
||||
|
||||
itp('utf_char2bytes', function()
|
||||
local char_p = ffi.typeof('char[?]')
|
||||
for c = 0, 0xFFFF do
|
||||
local p = char_p(4, 0)
|
||||
mbyte.utf_char2bytes(c, p)
|
||||
eq(c, mbyte.utf_ptr2char(p))
|
||||
eq(charset.vim_iswordc(c), charset.vim_iswordp(p))
|
||||
end
|
||||
end)
|
||||
|
||||
describe('utfc_ptr2char_len', function()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user