aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/vim_spec.lua
diff options
context:
space:
mode:
authorMichael Lingelbach <m.j.lbach@gmail.com>2021-10-30 10:30:40 -0700
committerGitHub <noreply@github.com>2021-10-30 10:30:40 -0700
commit2230b578d1d36728d156f82fb0e1a44c1f810b8c (patch)
treea4f94d41d9b89fc54b5b58ffdcbd1826757ed860 /test/functional/lua/vim_spec.lua
parent97ae0ab4d8e4cdc5be2dab43e328f0a9d248b30a (diff)
downloadrneovim-2230b578d1d36728d156f82fb0e1a44c1f810b8c.tar.gz
rneovim-2230b578d1d36728d156f82fb0e1a44c1f810b8c.tar.bz2
rneovim-2230b578d1d36728d156f82fb0e1a44c1f810b8c.zip
feat: add vim.str_utf_{start,end} (#16129)
vim.str_utf_{start,end} return the offset from the current position to the start and end of the current utf-character (nearest codepoint) respectively.
Diffstat (limited to 'test/functional/lua/vim_spec.lua')
-rw-r--r--test/functional/lua/vim_spec.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index 8c691b1121..5f903e7d5f 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -179,6 +179,31 @@ describe('lua stdlib', function()
end
end)
+ it("vim.str_utf_start", function()
+ exec_lua([[_G.test_text = "xy åäö ɧ 汉语 ↥ 🤦x🦄 å بِيَّ"]])
+ local expected_positions = {0,0,0,0,-1,0,-1,0,-1,0,0,-1,0,0,-1,-2,0,-1,-2,0,0,-1,-2,0,0,-1,-2,-3,0,0,-1,-2,-3,0,0,0,-1,0,0,-1,0,-1,0,-1,0,-1,0,-1}
+ eq(expected_positions, exec_lua([[
+ local start_codepoint_positions = {}
+ for idx = 1, #_G.test_text do
+ table.insert(start_codepoint_positions, vim.str_utf_start(_G.test_text, idx))
+ end
+ return start_codepoint_positions
+ ]]))
+ end)
+
+ it("vim.str_utf_end", function()
+ exec_lua([[_G.test_text = "xy åäö ɧ 汉语 ↥ 🤦x🦄 å بِيَّ"]])
+ local expected_positions = {0,0,0,1,0,1,0,1,0,0,1,0,0,2,1,0,2,1,0,0,2,1,0,0,3,2,1,0,0,3,2,1,0,0,0,1,0,0,1,0,1,0,1,0,1,0,1,0 }
+ eq(expected_positions, exec_lua([[
+ local end_codepoint_positions = {}
+ for idx = 1, #_G.test_text do
+ table.insert(end_codepoint_positions, vim.str_utf_end(_G.test_text, idx))
+ end
+ return end_codepoint_positions
+ ]]))
+ end)
+
+
it("vim.str_utf_pos", function()
exec_lua([[_G.test_text = "xy åäö ɧ 汉语 ↥ 🤦x🦄 å بِيَّ"]])
local expected_positions = { 1,2,3,4,6,8,10,11,13,14,17,20,21,24,25,29,30,34,35,36,38,39,41,43,45,47 }