lua: Use #var instead of deprecated table.getn(var)

This commit is contained in:
James McCoy 2020-07-31 01:33:42 -04:00
parent 817522b231
commit 55a885c179
No known key found for this signature in database
GPG Key ID: DFE691AE331BA3DB
2 changed files with 28 additions and 28 deletions

View File

@ -204,13 +204,13 @@ describe('API/extmarks', function()
eq({marks[2], positions[2][1], positions[2][2]}, rv[2]) eq({marks[2], positions[2][1], positions[2][2]}, rv[2])
-- nextrange with `limit` -- nextrange with `limit`
rv = get_extmarks(ns, marks[1], marks[3], {limit=2}) rv = get_extmarks(ns, marks[1], marks[3], {limit=2})
eq(2, table.getn(rv)) eq(2, #rv)
-- nextrange with positional when mark exists at position -- nextrange with positional when mark exists at position
rv = get_extmarks(ns, positions[1], positions[3]) rv = get_extmarks(ns, positions[1], positions[3])
eq({marks[1], positions[1][1], positions[1][2]}, rv[1]) eq({marks[1], positions[1][1], positions[1][2]}, rv[1])
eq({marks[2], positions[2][1], positions[2][2]}, rv[2]) eq({marks[2], positions[2][1], positions[2][2]}, rv[2])
rv = get_extmarks(ns, positions[2], positions[3]) rv = get_extmarks(ns, positions[2], positions[3])
eq(2, table.getn(rv)) eq(2, #rv)
-- nextrange with positional index (no mark at position) -- nextrange with positional index (no mark at position)
local lower = {positions[1][1], positions[2][2] -1} local lower = {positions[1][1], positions[2][2] -1}
local upper = {positions[2][1], positions[3][2] - 1} local upper = {positions[2][1], positions[3][2] - 1}
@ -248,14 +248,14 @@ describe('API/extmarks', function()
eq({marks[1], positions[1][1], positions[1][2]}, rv[3]) eq({marks[1], positions[1][1], positions[1][2]}, rv[3])
-- prevrange with limit -- prevrange with limit
rv = get_extmarks(ns, marks[3], marks[1], {limit=2}) rv = get_extmarks(ns, marks[3], marks[1], {limit=2})
eq(2, table.getn(rv)) eq(2, #rv)
-- prevrange with positional when mark exists at position -- prevrange with positional when mark exists at position
rv = get_extmarks(ns, positions[3], positions[1]) rv = get_extmarks(ns, positions[3], positions[1])
eq({{marks[3], positions[3][1], positions[3][2]}, eq({{marks[3], positions[3][1], positions[3][2]},
{marks[2], positions[2][1], positions[2][2]}, {marks[2], positions[2][1], positions[2][2]},
{marks[1], positions[1][1], positions[1][2]}}, rv) {marks[1], positions[1][1], positions[1][2]}}, rv)
rv = get_extmarks(ns, positions[2], positions[1]) rv = get_extmarks(ns, positions[2], positions[1])
eq(2, table.getn(rv)) eq(2, #rv)
-- prevrange with positional index (no mark at position) -- prevrange with positional index (no mark at position)
lower = {positions[2][1], positions[2][2] + 1} lower = {positions[2][1], positions[2][2] + 1}
upper = {positions[3][1], positions[3][2] + 1} upper = {positions[3][1], positions[3][2] + 1}
@ -282,19 +282,19 @@ describe('API/extmarks', function()
end end
local rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=1}) local rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=1})
eq(1, table.getn(rv)) eq(1, #rv)
rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=2}) rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=2})
eq(2, table.getn(rv)) eq(2, #rv)
rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=3}) rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=3})
eq(3, table.getn(rv)) eq(3, #rv)
-- now in reverse -- now in reverse
rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=1}) rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=1})
eq(1, table.getn(rv)) eq(1, #rv)
rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=2}) rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=2})
eq(2, table.getn(rv)) eq(2, #rv)
rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=3}) rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=3})
eq(3, table.getn(rv)) eq(3, #rv)
end) end)
it('get_marks works when mark col > upper col', function() it('get_marks works when mark col > upper col', function()
@ -798,17 +798,17 @@ describe('API/extmarks', function()
feed("u") feed("u")
local rv = get_extmarks(ns, {0, 0}, {-1, -1}) local rv = get_extmarks(ns, {0, 0}, {-1, -1})
eq(3, table.getn(rv)) eq(3, #rv)
feed("<c-r>") feed("<c-r>")
rv = get_extmarks(ns, {0, 0}, {-1, -1}) rv = get_extmarks(ns, {0, 0}, {-1, -1})
eq(3, table.getn(rv)) eq(3, #rv)
-- Test updates -- Test updates
feed('o<esc>') feed('o<esc>')
set_extmark(ns, marks[1], positions[1][1], positions[1][2]) set_extmark(ns, marks[1], positions[1][1], positions[1][2])
rv = get_extmarks(ns, marks[1], marks[1], {limit=1}) rv = get_extmarks(ns, marks[1], marks[1], {limit=1})
eq(1, table.getn(rv)) eq(1, #rv)
feed("u") feed("u")
feed("<c-r>") feed("<c-r>")
-- old value is NOT kept in history -- old value is NOT kept in history
@ -820,10 +820,10 @@ describe('API/extmarks', function()
feed("u") feed("u")
rv = get_extmarks(ns, {0, 0}, {-1, -1}) rv = get_extmarks(ns, {0, 0}, {-1, -1})
-- undo does NOT restore deleted marks -- undo does NOT restore deleted marks
eq(2, table.getn(rv)) eq(2, #rv)
feed("<c-r>") feed("<c-r>")
rv = get_extmarks(ns, {0, 0}, {-1, -1}) rv = get_extmarks(ns, {0, 0}, {-1, -1})
eq(2, table.getn(rv)) eq(2, #rv)
end) end)
it('undo and redo of marks deleted during edits', function() it('undo and redo of marks deleted during edits', function()
@ -840,9 +840,9 @@ describe('API/extmarks', function()
rv = set_extmark(ns2, marks[1], positions[1][1], positions[1][2]) rv = set_extmark(ns2, marks[1], positions[1][1], positions[1][2])
eq(1, rv) eq(1, rv)
rv = get_extmarks(ns, {0, 0}, {-1, -1}) rv = get_extmarks(ns, {0, 0}, {-1, -1})
eq(1, table.getn(rv)) eq(1, #rv)
rv = get_extmarks(ns2, {0, 0}, {-1, -1}) rv = get_extmarks(ns2, {0, 0}, {-1, -1})
eq(1, table.getn(rv)) eq(1, #rv)
-- Set more marks for testing the ranges -- Set more marks for testing the ranges
set_extmark(ns, marks[2], positions[2][1], positions[2][2]) set_extmark(ns, marks[2], positions[2][1], positions[2][2])
@ -852,32 +852,32 @@ describe('API/extmarks', function()
-- get_next (limit set) -- get_next (limit set)
rv = get_extmarks(ns, {0, 0}, positions[2], {limit=1}) rv = get_extmarks(ns, {0, 0}, positions[2], {limit=1})
eq(1, table.getn(rv)) eq(1, #rv)
rv = get_extmarks(ns2, {0, 0}, positions[2], {limit=1}) rv = get_extmarks(ns2, {0, 0}, positions[2], {limit=1})
eq(1, table.getn(rv)) eq(1, #rv)
-- get_prev (limit set) -- get_prev (limit set)
rv = get_extmarks(ns, positions[1], {0, 0}, {limit=1}) rv = get_extmarks(ns, positions[1], {0, 0}, {limit=1})
eq(1, table.getn(rv)) eq(1, #rv)
rv = get_extmarks(ns2, positions[1], {0, 0}, {limit=1}) rv = get_extmarks(ns2, positions[1], {0, 0}, {limit=1})
eq(1, table.getn(rv)) eq(1, #rv)
-- get_next (no limit) -- get_next (no limit)
rv = get_extmarks(ns, positions[1], positions[2]) rv = get_extmarks(ns, positions[1], positions[2])
eq(2, table.getn(rv)) eq(2, #rv)
rv = get_extmarks(ns2, positions[1], positions[2]) rv = get_extmarks(ns2, positions[1], positions[2])
eq(2, table.getn(rv)) eq(2, #rv)
-- get_prev (no limit) -- get_prev (no limit)
rv = get_extmarks(ns, positions[2], positions[1]) rv = get_extmarks(ns, positions[2], positions[1])
eq(2, table.getn(rv)) eq(2, #rv)
rv = get_extmarks(ns2, positions[2], positions[1]) rv = get_extmarks(ns2, positions[2], positions[1])
eq(2, table.getn(rv)) eq(2, #rv)
curbufmeths.del_extmark(ns, marks[1]) curbufmeths.del_extmark(ns, marks[1])
rv = get_extmarks(ns, {0, 0}, {-1, -1}) rv = get_extmarks(ns, {0, 0}, {-1, -1})
eq(2, table.getn(rv)) eq(2, #rv)
curbufmeths.del_extmark(ns2, marks[1]) curbufmeths.del_extmark(ns2, marks[1])
rv = get_extmarks(ns2, {0, 0}, {-1, -1}) rv = get_extmarks(ns2, {0, 0}, {-1, -1})
eq(2, table.getn(rv)) eq(2, #rv)
end) end)
it('mark set can create unique identifiers', function() it('mark set can create unique identifiers', function()

View File

@ -172,7 +172,7 @@ describe('env.c', function()
i = i + 1 i = i + 1
name = cimp.os_getenvname_at_index(i) name = cimp.os_getenvname_at_index(i)
end end
eq(true, (table.getn(names)) > 0) eq(true, #names > 0)
eq(true, found_name) eq(true, found_name)
end) end)