forked from niuiic/blink-cmp-rg.nvim
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathget_prefix_spec.lua
156 lines (141 loc) · 6.93 KB
/
get_prefix_spec.lua
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
local assert = require("luassert")
local blink_ripgrep = require("blink-ripgrep")
describe("match_prefix", function()
it("for simple strings", function()
assert.are_same(blink_ripgrep.match_prefix("hello"), "hello")
assert.are_same(blink_ripgrep.match_prefix("abc123"), "abc123")
assert.are_same(blink_ripgrep.match_prefix("abc-123"), "abc-123")
assert.are_same(blink_ripgrep.match_prefix("abc_123"), "abc_123")
end)
it(
"matches when there is one nonmatching piece of input in the beginning",
function()
assert.are_same(blink_ripgrep.match_prefix(".hello"), "hello")
assert.are_same(blink_ripgrep.match_prefix(",hello"), "hello")
assert.are_same(
blink_ripgrep.match_prefix(".,,!@!@$@%<<@$<hello"),
"hello"
)
assert.are_same(blink_ripgrep.match_prefix(" hello"), "hello")
assert.are_same(blink_ripgrep.match_prefix("random_text hello"), "hello")
assert.are_same(blink_ripgrep.match_prefix("-- hello"), "hello")
assert.are_same(blink_ripgrep.match_prefix("-- abc123"), "abc123")
assert.are_same(blink_ripgrep.match_prefix("-- abc-123"), "abc-123")
assert.are_same(blink_ripgrep.match_prefix("-- abc_123"), "abc_123")
end
)
it("matches when there is nonmatching input at the end", function()
assert.are_same(blink_ripgrep.match_prefix(".hello)"), "hello")
assert.are_same(blink_ripgrep.match_prefix(",hello)"), "hello")
assert.are_same(
blink_ripgrep.match_prefix(".,,!@!@$@%<<@$<hello)"),
"hello"
)
assert.are_same(blink_ripgrep.match_prefix(" hello)"), "hello")
assert.are_same(blink_ripgrep.match_prefix("random_text hello)"), "hello")
assert.are_same(blink_ripgrep.match_prefix("-- hello)"), "hello")
assert.are_same(blink_ripgrep.match_prefix("-- abc123)"), "abc123")
assert.are_same(blink_ripgrep.match_prefix("-- abc-123)"), "abc-123")
assert.are_same(blink_ripgrep.match_prefix("-- abc_123)"), "abc_123")
end)
it("matches when word_characters are in the front", function()
assert.are_same(blink_ripgrep.match_prefix("--hello)"), "hello")
assert.are_same(blink_ripgrep.match_prefix("__hello)"), "hello")
end)
it(
"matches when there is nonmatching input at the beginning and at the end",
function()
assert.are_same(blink_ripgrep.match_prefix('"hello"'), "hello")
end
)
it(
"matches when there are multiple nonmatching pieces of input in the beginning",
function()
assert.are_same(blink_ripgrep.match_prefix(".hello.hello"), "hello")
assert.are_same(blink_ripgrep.match_prefix(",hello,hello"), "hello")
assert.are_same(
blink_ripgrep.match_prefix(".,,!@!@$@%<<@$<hello.,,!@!@$@%<<@$<hello"),
"hello"
)
assert.are_same(blink_ripgrep.match_prefix(" hello hello"), "hello")
assert.are_same(
blink_ripgrep.match_prefix("random_text hello hello"),
"hello"
)
assert.are_same(blink_ripgrep.match_prefix("-- hello hello"), "hello")
assert.are_same(blink_ripgrep.match_prefix("-- abc123 abc123"), "abc123")
assert.are_same(
blink_ripgrep.match_prefix("-- abc-123 abc-123"),
"abc-123"
)
assert.are_same(
blink_ripgrep.match_prefix("-- abc_123 abc_123"),
"abc_123"
)
end
)
it("for multipart strings", function()
-- three parts
assert.are_same(
blink_ripgrep.match_prefix("hello-world-today"),
"hello-world-today"
)
-- three parts with numbers
assert.are_same(
blink_ripgrep.match_prefix("abc123-def456-ghi789"),
"abc123-def456-ghi789"
)
-- multiple parts with mixed dashes and underscores
assert.are_same(
blink_ripgrep.match_prefix("abc-123_def-456_ghi-789"),
"abc-123_def-456_ghi-789"
)
end)
it("matches unicode characters", function()
-- umlauts and other special characters
assert.are_same(blink_ripgrep.match_prefix("yöllä"), "yöllä") -- Finnish word with 'ö' and 'ä'
assert.are_same(blink_ripgrep.match_prefix("über"), "über") -- German word with 'ü'
assert.are_same(blink_ripgrep.match_prefix("übermensch"), "übermensch") -- German compound word with 'ü'
assert.are_same(blink_ripgrep.match_prefix("mañana"), "mañana") -- Spanish word with 'ñ'
assert.are_same(blink_ripgrep.match_prefix("Ångström"), "Ångström") -- Swedish word with 'Å' and 'ö'
assert.are_same(blink_ripgrep.match_prefix("Straße"), "Straße") -- German word with 'ß'
assert.are_same(blink_ripgrep.match_prefix("český"), "český") -- Czech word with 'č'
assert.are_same(blink_ripgrep.match_prefix("naïve"), "naïve") -- French word with 'ï'
assert.are_same(blink_ripgrep.match_prefix("façade"), "façade") -- French word with 'ç'
assert.are_same(blink_ripgrep.match_prefix("résumé"), "résumé") -- French word with 'é'
assert.are_same(blink_ripgrep.match_prefix("космос"), "космос") -- Russian word with Cyrillic characters
assert.are_same(blink_ripgrep.match_prefix("你好"), "你好") -- Chinese characters
assert.are_same(blink_ripgrep.match_prefix("日本語"), "日本語") -- Japanese characters
assert.are_same(blink_ripgrep.match_prefix("한국어"), "한국어") -- Korean characters
assert.are_same(blink_ripgrep.match_prefix("τοπική"), "τοπική") -- Greek word with 'π' and 'ή'
end)
it("matches emoji", function()
-- because why not 😄
assert.are_same(blink_ripgrep.match_prefix("👍👎"), "👍👎")
assert.are_same(blink_ripgrep.match_prefix("👍-👎"), "👍-👎")
end)
it("does not include punctuation characters", function()
assert.are_same(blink_ripgrep.match_prefix("!hello"), "hello")
assert.are_same(blink_ripgrep.match_prefix("?world"), "world")
assert.are_same(blink_ripgrep.match_prefix("#hashtag"), "hashtag")
assert.are_same(blink_ripgrep.match_prefix("$money"), "money")
assert.are_same(blink_ripgrep.match_prefix("%value"), "value")
assert.are_same(blink_ripgrep.match_prefix("&and"), "and")
assert.are_same(blink_ripgrep.match_prefix("*star"), "star")
assert.are_same(blink_ripgrep.match_prefix("@email"), "email")
assert.are_same(blink_ripgrep.match_prefix("~tilde"), "tilde")
assert.are_same(blink_ripgrep.match_prefix(";semicolon"), "semicolon")
assert.are_same(blink_ripgrep.match_prefix(":colon"), "colon")
end)
it("does not include whitespace and control characters", function()
assert.are_same(blink_ripgrep.match_prefix(" hello"), "hello")
assert.are_same(blink_ripgrep.match_prefix("world "), "world")
assert.are_same(blink_ripgrep.match_prefix("\t\ttext"), "text")
assert.are_same(blink_ripgrep.match_prefix("\nnewline"), "newline")
end)
it("includes symbols", function()
assert.are_same(blink_ripgrep.match_prefix("©copyright"), "©copyright")
assert.are_same(blink_ripgrep.match_prefix("®registered"), "®registered")
assert.are_same(blink_ripgrep.match_prefix("™trademark"), "™trademark")
end)
end)