1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
-- luacheck: globals describe it assert
---@diagnostic disable-next-line: undefined-field
local eq = assert.are.same
local RequestStatus = require("99.ops.request_status")
local Mark = require("99.ops.marks")
local test_utils = require("99.test.test_utils")
local Point = require("99.geo").Point
describe("request_status", function()
it("setting lines and status line", function()
local buffer =
test_utils.create_file({ "", "function foo() end" }, "lua", 1, 1)
local point = Point:from_1_based(1, 1)
local mark = Mark.mark_point(buffer, point)
local status = RequestStatus.new(2000000, 3, "TITLE", mark)
eq({ "⠙ TITLE" }, status:get())
status:push("foo")
status:push("bar")
eq({ "⠙ TITLE", "foo", "bar" }, status:get())
status:push("baz")
eq({ "⠙ TITLE", "bar", "baz" }, status:get())
end)
it("using callback function", function()
local calls = {}
local status = RequestStatus.new(100, 3, "TITLE", function(status_lines)
table.insert(calls, status_lines)
end)
status:start()
vim.wait(200, function()
return #calls == 1
end)
eq(1, #calls)
eq({ "⠹ TITLE" }, calls[1])
calls = {}
status:push("bar")
vim.wait(200, function()
return #calls == 1
end)
eq(1, #calls)
eq({ "⠸ TITLE", "bar" }, calls[1])
end)
end)
|