summaryrefslogtreecommitdiff
path: root/test/command/auto-require.lua
blob: c2c0935f93576d98c6288a5b085e5ff99b931793 (plain)
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
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.removeAll()
            files.setText('', text)
            EditResult = nil
            local row, fmt = findInsertRow('')
            applyAutoRequire('', row, name, name, fmt)
            assert(util.equal(EditResult, expect))
        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'
}

client.editText = originEditText