Files
neovim/test/functional/eval/reltime_spec.lua
Justin M. Keyes bab24a88ab viml/profile: revert proftime_T to unsigned type #10521
- reltimestr(): Produce negative value by comparing the unsigned
  proftime_T value to INT64_MAX.

https://github.com/neovim/neovim/issues/10452#issuecomment-511155132
1. The interfaces of nearly all platforms return uint64_t. INT64_MAX is
   only half of that.
2. Low-level interfaces like this typically define that there is no
   fixed starting point. The only guarantees are that it's (a)
   monotonically increasing at a rate that (b) matches real time.

ref 06af88cd72
fix #10452
2019-07-16 20:10:08 +02:00

51 lines
1.6 KiB
Lua

local helpers = require('test.functional.helpers')(after_each)
local clear, eq, ok = helpers.clear, helpers.eq, helpers.ok
local neq, command, funcs = helpers.neq, helpers.command, helpers.funcs
local reltime, reltimestr, reltimefloat = funcs.reltime, funcs.reltimestr, funcs.reltimefloat
describe('reltimestr(), reltimefloat()', function()
before_each(clear)
it('Checks', function()
local now = reltime()
command('sleep 10m')
local later = reltime()
local elapsed = reltime(now)
neq(reltimestr(elapsed), '0.0')
ok(reltimefloat(elapsed) > 0.0)
-- original vim test for < 0.1, but easily fails on travis
ok(nil ~= string.match(reltimestr(elapsed), "0%."))
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)
neq(reltimestr(differs), '0.0')
ok(reltimefloat(differs) > 0.0)
-- original vim test for < 0.1, but easily fails on travis
ok(nil ~= string.match(reltimestr(differs), "0%."))
ok(reltimefloat(differs) < 1.0)
end)
it('reltime() allows negative result #10452', function()
local older_time = reltime()
command('sleep 1m')
local newer_time = reltime()
-- Start/end swapped: should be something like -0.002123.
local rv = tonumber(reltimestr(reltime(newer_time, older_time)))
ok(rv < 0 and rv > -10)
-- Not swapped: should be something like 0.002123.
rv = tonumber(reltimestr(reltime(older_time, newer_time)))
ok(rv > 0 and rv < 10)
end)
end)