HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //home/ubuntu/neovim/test/functional/vimscript/reltime_spec.lua
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
local matches = t.matches
local reltime, reltimestr, reltimefloat = fn.reltime, fn.reltimestr, fn.reltimefloat

describe('reltimestr(), reltimefloat()', function()
  before_each(clear)

  it('acceptance', function()
    local now = reltime()
    command('sleep 10m')
    local later = reltime()
    local elapsed = reltime(now)

    neq('0.0', reltimestr(elapsed))
    ok(reltimefloat(elapsed) > 0.0)
    -- original vim test for < 0.1, but easily fails on travis
    matches('0%.', reltimestr(elapsed))
    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('0.0', reltimestr(differs))
    ok(reltimefloat(differs) > 0.0)
    -- original vim test for < 0.1, but easily fails on travis
    matches('0%.', reltimestr(differs))
    ok(reltimefloat(differs) < 1.0)
  end)

  it('(start - end) returns negative #10452', function()
    local older_time = reltime()
    command('sleep 1m')
    local newer_time = reltime()

    -- Start/end swapped: should be something like -0.002123.
    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)

    -- Not swapped: should be something like 0.002123.
    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)
  end)
end)