2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
|
|
|
|
|
|
|
local clear, eq, ok = n.clear, t.eq, t.ok
|
|
|
|
local neq, command, fn = t.neq, n.command, n.fn
|
2024-04-08 02:03:20 -07:00
|
|
|
local matches = t.matches
|
2024-01-12 10:59:57 -07:00
|
|
|
local reltime, reltimestr, reltimefloat = fn.reltime, fn.reltimestr, fn.reltimefloat
|
2016-04-16 08:48:45 -07:00
|
|
|
|
|
|
|
describe('reltimestr(), reltimefloat()', function()
|
|
|
|
before_each(clear)
|
|
|
|
|
2019-07-20 01:46:09 -07:00
|
|
|
it('acceptance', function()
|
2016-04-16 08:48:45 -07:00
|
|
|
local now = reltime()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('sleep 10m')
|
2016-04-16 08:48:45 -07:00
|
|
|
local later = reltime()
|
|
|
|
local elapsed = reltime(now)
|
|
|
|
|
2022-04-25 20:35:05 -07:00
|
|
|
neq('0.0', reltimestr(elapsed))
|
2016-04-16 08:48:45 -07:00
|
|
|
ok(reltimefloat(elapsed) > 0.0)
|
|
|
|
-- original vim test for < 0.1, but easily fails on travis
|
2024-03-29 18:29:21 -07:00
|
|
|
matches('0%.', reltimestr(elapsed))
|
2016-04-16 08:48:45 -07:00
|
|
|
ok(reltimefloat(elapsed) < 1.0)
|
|
|
|
|
|
|
|
local same = reltime(now, now)
|
|
|
|
local samestr = string.gsub(reltimestr(same), ' ', '')
|
|
|
|
samestr = string.sub(samestr, 1, 5)
|
|
|
|
|
|
|
|
eq('0.000', samestr)
|
|
|
|
eq(0.0, reltimefloat(same))
|
|
|
|
|
|
|
|
local differs = reltime(now, later)
|
2022-04-25 20:35:05 -07:00
|
|
|
neq('0.0', reltimestr(differs))
|
2016-04-16 08:48:45 -07:00
|
|
|
ok(reltimefloat(differs) > 0.0)
|
|
|
|
-- original vim test for < 0.1, but easily fails on travis
|
2024-03-29 18:29:21 -07:00
|
|
|
matches('0%.', reltimestr(differs))
|
2016-04-16 08:48:45 -07:00
|
|
|
ok(reltimefloat(differs) < 1.0)
|
|
|
|
end)
|
2019-07-09 03:08:54 -07:00
|
|
|
|
2019-07-20 01:46:09 -07:00
|
|
|
it('(start - end) returns negative #10452', function()
|
2019-07-09 03:08:54 -07:00
|
|
|
local older_time = reltime()
|
|
|
|
command('sleep 1m')
|
|
|
|
local newer_time = reltime()
|
2019-07-16 11:10:08 -07:00
|
|
|
|
|
|
|
-- Start/end swapped: should be something like -0.002123.
|
2019-07-20 01:46:09 -07:00
|
|
|
local tm_s = tonumber(reltimestr(reltime(newer_time, older_time)))
|
|
|
|
local tm_f = reltimefloat(reltime(newer_time, older_time))
|
|
|
|
ok(tm_s < 0 and tm_s > -10)
|
|
|
|
ok(tm_f < 0 and tm_f > -10)
|
2019-07-16 11:10:08 -07:00
|
|
|
|
|
|
|
-- Not swapped: should be something like 0.002123.
|
2019-07-20 01:46:09 -07:00
|
|
|
tm_s = tonumber(reltimestr(reltime(older_time, newer_time)))
|
|
|
|
tm_f = reltimefloat(reltime(older_time, newer_time))
|
|
|
|
ok(tm_s > 0 and tm_s < 10)
|
|
|
|
ok(tm_f > 0 and tm_f < 10)
|
2019-07-09 03:08:54 -07:00
|
|
|
end)
|
2016-04-16 08:48:45 -07:00
|
|
|
end)
|