mirror of
https://github.com/neovim/neovim.git
synced 2025-10-07 10:26:31 +00: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:
@@ -826,7 +826,7 @@ bool vim_isIDc(int c)
|
|||||||
/// For multi-byte characters mb_get_class() is used (builtin rules).
|
/// For multi-byte characters mb_get_class() is used (builtin rules).
|
||||||
///
|
///
|
||||||
/// @param c character to check
|
/// @param c character to check
|
||||||
bool vim_iswordc(int c)
|
bool vim_iswordc(const int c)
|
||||||
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
|
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
|
||||||
{
|
{
|
||||||
return vim_iswordc_buf(c, curbuf);
|
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 c character to check
|
||||||
/// @param buf buffer whose keywords to use
|
/// @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)
|
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(2)
|
||||||
{
|
{
|
||||||
return vim_iswordc_tab(c, buf->b_chartab);
|
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
|
/// @param p pointer to the multi-byte character
|
||||||
///
|
///
|
||||||
/// @return true if "p" points to a keyword 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
|
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
return vim_iswordp_buf(p, curbuf);
|
return vim_iswordp_buf(p, curbuf);
|
||||||
@@ -876,7 +876,7 @@ bool vim_iswordp(char_u *p)
|
|||||||
/// @param buf buffer whose keywords to use
|
/// @param buf buffer whose keywords to use
|
||||||
///
|
///
|
||||||
/// @return true if "p" points to a keyword character.
|
/// @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
|
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
int c = *p;
|
int c = *p;
|
||||||
|
@@ -5,6 +5,7 @@ local ffi = helpers.ffi
|
|||||||
local eq = helpers.eq
|
local eq = helpers.eq
|
||||||
|
|
||||||
local mbyte = helpers.cimport("./src/nvim/mbyte.h")
|
local mbyte = helpers.cimport("./src/nvim/mbyte.h")
|
||||||
|
local charset = helpers.cimport('./src/nvim/charset.h')
|
||||||
|
|
||||||
describe('mbyte', function()
|
describe('mbyte', function()
|
||||||
|
|
||||||
@@ -42,6 +43,15 @@ describe('mbyte', function()
|
|||||||
-- Sequences with more than four bytes
|
-- Sequences with more than four bytes
|
||||||
end)
|
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()
|
describe('utfc_ptr2char_len', function()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user