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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
local util = require 'utility'
local files = require 'files'
local autoRequire = require 'core.command.autoRequire'
local client = require 'client'
local findInsertRow = util.getUpvalue(autoRequire, 'findInsertRow')
local applyAutoRequire = util.getUpvalue(autoRequire, 'applyAutoRequire')
local originEditText = client.editText
local EditResult
client.editText = function (uri, edits)
EditResult = edits[1]
end
function TEST(text)
return function (name)
return function (expect)
files.setText('', text)
EditResult = nil
local row, fmt = findInsertRow('')
applyAutoRequire('', row, name, name, fmt)
assert(util.equal(EditResult, expect))
files.remove('')
end
end
end
TEST '' 'test' {
start = 0,
finish = 0,
text = 'local test = require "test"\n'
}
TEST [[
local aaaaaa = require 'aaa'
]] 'test' {
start = 10000,
finish = 10000,
text = 'local test = require \'test\'\n'
}
TEST [[
local DEBUG = true
local aaaaaa = require 'aaa'
]] 'test' {
start = 20000,
finish = 20000,
text = 'local test = require \'test\'\n'
}
TEST [[
-- comment
-- comment
local aaaaaa = require 'aaa'
]] 'test' {
start = 30000,
finish = 30000,
text = 'local test = require \'test\'\n'
}
TEST [[
--[=[
comment chunk
]=]
local aaaaaa = require 'aaa'
]] 'test' {
start = 40000,
finish = 40000,
text = 'local test = require \'test\'\n'
}
TEST [[
local offset
local space_size
---@class A
---@field a string
---@field b string
local M = {}
---@return A
function M.new()
end
]] 'test' {
start = 0,
finish = 0,
text = 'local test = require "test"\n'
}
client.editText = originEditText
|