forked from zbirenbaum/copilot.lua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_suggestion_util.lua
More file actions
112 lines (91 loc) · 3.51 KB
/
Copy pathtest_suggestion_util.lua
File metadata and controls
112 lines (91 loc) · 3.51 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
local u = require("copilot.suggestion.utils")
local eq = MiniTest.expect.equality
local T = MiniTest.new_set({
hooks = {
pre_once = function() end,
pre_case = function() end,
},
})
T["suggestion_utils()"] = MiniTest.new_set()
T["suggestion_utils()"]["get_display_adjustments"] = MiniTest.new_set()
T["suggestion_utils()"]["get_display_adjustments"]["basic non-whitespace match"] = function()
local result, outdent = u.get_display_adjustments("7 8 9", 0, 3, "7 ")
eq(result, "8 9")
eq(outdent, 0)
end
T["suggestion_utils()"]["get_display_adjustments"]["whitespace matching indent"] = function()
local result, outdent = u.get_display_adjustments(" if foo:", 0, 3, " ")
eq(result, "if foo:")
eq(outdent, 0)
end
T["suggestion_utils()"]["get_display_adjustments"]["whitespace outdent"] = function()
local result, outdent = u.get_display_adjustments(" if foo:", 0, 5, " ")
eq(result, "if foo:")
eq(outdent, 2)
end
T["suggestion_utils()"]["get_display_adjustments"]["whitespace more indent"] = function()
local result, outdent = u.get_display_adjustments(" if foo:", 0, 3, " ")
eq(result, " if foo:")
eq(outdent, 0)
end
T["suggestion_utils()"]["get_display_adjustments"]["range start > 0 at boundary"] = function()
local result, outdent = u.get_display_adjustments("if foo:", 2, 3, " ")
eq(result, "if foo:")
eq(outdent, 0)
end
T["suggestion_utils()"]["get_display_adjustments"]["range start > 0 past boundary"] = function()
local result, outdent = u.get_display_adjustments("if foo:", 2, 4, " i")
eq(result, "f foo:")
eq(outdent, 0)
end
T["suggestion_utils()"]["get_display_adjustments"]["empty line"] = function()
local result, outdent = u.get_display_adjustments("if foo:", 0, 1, "")
eq(result, "if foo:")
eq(outdent, 0)
end
T["suggestion_utils()"]["get_display_adjustments"]["no match fallback"] = function()
local result, outdent = u.get_display_adjustments("abc", 0, 4, "xyz")
eq(result, "")
eq(outdent, 0)
end
T["suggestion_utils()"]["get_display_adjustments"]["tab whitespace"] = function()
local result, outdent = u.get_display_adjustments("\tif foo:", 0, 2, "\t")
eq(result, "if foo:")
eq(outdent, 0)
end
T["suggestion_utils()"]["remove common suffix"] = function()
local test_cases = {
{ [[event1 = ("test", ),]], [["test2"),]], [["test2"]] },
-- ^
{ [[event2 = ("test", ""),]], [[test2"),]], [[test2]] },
-- ^
{ [[event3 = ("test", ]], [["test2"),]], [["test2"),]] },
-- ^
{ [[event4 = ("test", ]], "", "" },
{ "", [[("test"),]], [[("test"),]] },
}
for _, case in ipairs(test_cases) do
local str, substr, expected = unpack(case)
local result = u.remove_common_suffix(str, substr)
eq(result, expected)
end
end
T["suggestion_utils()"]["both empty strings returns empty"] = function()
eq(u.remove_common_suffix("", ""), "")
end
T["suggestion_utils()"]["no common suffix returns suggestion unchanged"] = function()
eq(u.remove_common_suffix("abc", "xyz"), "xyz")
end
T["suggestion_utils()"]["single char match"] = function()
eq(u.remove_common_suffix("a", "a"), "")
end
T["suggestion_utils()"]["single char differ"] = function()
eq(u.remove_common_suffix("a", "b"), "b")
end
T["suggestion_utils()"]["entire suggestion is suffix of str"] = function()
eq(u.remove_common_suffix("hello world", "world"), "")
end
T["suggestion_utils()"]["suggestion longer than str with common suffix"] = function()
eq(u.remove_common_suffix("ld", "hello world"), "hello wor")
end
return T