Mercurial > vim
comparison src/testdir/test_matchfuzzy.vim @ 23475:79fd5217b125 v8.2.2280
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Commit: https://github.com/vim/vim/commit/9d19e4f4ba55f8bef18d4991abdf740ff6472dba
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 2 18:31:32 2021 +0100
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Problem: Fuzzy matching doesn't give access to the scores.
Solution: Return the scores with a third list. (Yegappan Lakshmanan,
closes #7596)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 02 Jan 2021 18:45:03 +0100 |
parents | 875bd7c04533 |
children | 2ade724b3f45 |
comparison
equal
deleted
inserted
replaced
23474:e4906ec48336 | 23475:79fd5217b125 |
---|---|
91 let &encoding = save_enc | 91 let &encoding = save_enc |
92 endfunc | 92 endfunc |
93 | 93 |
94 " Test for the matchfuzzypos() function | 94 " Test for the matchfuzzypos() function |
95 func Test_matchfuzzypos() | 95 func Test_matchfuzzypos() |
96 call assert_equal([['curl', 'world'], [[2,3], [2,3]]], matchfuzzypos(['world', 'curl'], 'rl')) | 96 call assert_equal([['curl', 'world'], [[2,3], [2,3]], [128, 127]], matchfuzzypos(['world', 'curl'], 'rl')) |
97 call assert_equal([['curl', 'world'], [[2,3], [2,3]]], matchfuzzypos(['world', 'one', 'curl'], 'rl')) | 97 call assert_equal([['curl', 'world'], [[2,3], [2,3]], [128, 127]], matchfuzzypos(['world', 'one', 'curl'], 'rl')) |
98 call assert_equal([['hello', 'hello world hello world'], | 98 call assert_equal([['hello', 'hello world hello world'], |
99 \ [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4]]], | 99 \ [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4]], [275, 257]], |
100 \ matchfuzzypos(['hello world hello world', 'hello', 'world'], 'hello')) | 100 \ matchfuzzypos(['hello world hello world', 'hello', 'world'], 'hello')) |
101 call assert_equal([['aaaaaaa'], [[0, 1, 2]]], matchfuzzypos(['aaaaaaa'], 'aaa')) | 101 call assert_equal([['aaaaaaa'], [[0, 1, 2]], [191]], matchfuzzypos(['aaaaaaa'], 'aaa')) |
102 call assert_equal([['a b'], [[0, 3]]], matchfuzzypos(['a b'], 'a b')) | 102 call assert_equal([['a b'], [[0, 3]], [219]], matchfuzzypos(['a b'], 'a b')) |
103 call assert_equal([['a b'], [[0, 3]]], matchfuzzypos(['a b'], 'a b')) | 103 call assert_equal([['a b'], [[0, 3]], [219]], matchfuzzypos(['a b'], 'a b')) |
104 call assert_equal([['a b'], [[0]]], matchfuzzypos(['a b'], ' a ')) | 104 call assert_equal([['a b'], [[0]], [112]], matchfuzzypos(['a b'], ' a ')) |
105 call assert_equal([[], []], matchfuzzypos(['a b'], ' ')) | 105 call assert_equal([[], [], []], matchfuzzypos(['a b'], ' ')) |
106 call assert_equal([[], []], matchfuzzypos(['world', 'curl'], 'ab')) | 106 call assert_equal([[], [], []], matchfuzzypos(['world', 'curl'], 'ab')) |
107 let x = matchfuzzypos([repeat('a', 256)], repeat('a', 256)) | 107 let x = matchfuzzypos([repeat('a', 256)], repeat('a', 256)) |
108 call assert_equal(range(256), x[1][0]) | 108 call assert_equal(range(256), x[1][0]) |
109 call assert_equal([[], []], matchfuzzypos([repeat('a', 300)], repeat('a', 257))) | 109 call assert_equal([[], [], []], matchfuzzypos([repeat('a', 300)], repeat('a', 257))) |
110 call assert_equal([[], []], matchfuzzypos([], 'abc')) | 110 call assert_equal([[], [], []], matchfuzzypos([], 'abc')) |
111 | 111 |
112 " match in a long string | 112 " match in a long string |
113 call assert_equal([[repeat('x', 300) .. 'abc'], [[300, 301, 302]]], | 113 call assert_equal([[repeat('x', 300) .. 'abc'], [[300, 301, 302]], [-135]], |
114 \ matchfuzzypos([repeat('x', 300) .. 'abc'], 'abc')) | 114 \ matchfuzzypos([repeat('x', 300) .. 'abc'], 'abc')) |
115 | 115 |
116 " preference for camel case match | 116 " preference for camel case match |
117 call assert_equal([['xabcxxaBc'], [[6, 7, 8]]], matchfuzzypos(['xabcxxaBc'], 'abc')) | 117 call assert_equal([['xabcxxaBc'], [[6, 7, 8]], [189]], matchfuzzypos(['xabcxxaBc'], 'abc')) |
118 " preference for match after a separator (_ or space) | 118 " preference for match after a separator (_ or space) |
119 call assert_equal([['xabx_ab'], [[5, 6]]], matchfuzzypos(['xabx_ab'], 'ab')) | 119 call assert_equal([['xabx_ab'], [[5, 6]], [145]], matchfuzzypos(['xabx_ab'], 'ab')) |
120 " preference for leading letter match | 120 " preference for leading letter match |
121 call assert_equal([['abcxabc'], [[0, 1]]], matchfuzzypos(['abcxabc'], 'ab')) | 121 call assert_equal([['abcxabc'], [[0, 1]], [150]], matchfuzzypos(['abcxabc'], 'ab')) |
122 " preference for sequential match | 122 " preference for sequential match |
123 call assert_equal([['aobncedone'], [[7, 8, 9]]], matchfuzzypos(['aobncedone'], 'one')) | 123 call assert_equal([['aobncedone'], [[7, 8, 9]], [158]], matchfuzzypos(['aobncedone'], 'one')) |
124 " best recursive match | 124 " best recursive match |
125 call assert_equal([['xoone'], [[2, 3, 4]]], matchfuzzypos(['xoone'], 'one')) | 125 call assert_equal([['xoone'], [[2, 3, 4]], [168]], matchfuzzypos(['xoone'], 'one')) |
126 | 126 |
127 " match multiple words (separated by space) | 127 " match multiple words (separated by space) |
128 call assert_equal([['foo bar baz'], [[8, 9, 10, 0, 1, 2]]], ['foo bar baz', 'foo', 'foo bar', 'baz bar']->matchfuzzypos('baz foo')) | 128 call assert_equal([['foo bar baz'], [[8, 9, 10, 0, 1, 2]], [369]], ['foo bar baz', 'foo', 'foo bar', 'baz bar']->matchfuzzypos('baz foo')) |
129 call assert_equal([[], []], ['foo bar baz', 'foo', 'foo bar', 'baz bar']->matchfuzzypos('one two')) | 129 call assert_equal([[], [], []], ['foo bar baz', 'foo', 'foo bar', 'baz bar']->matchfuzzypos('one two')) |
130 call assert_equal([[], []], ['foo bar']->matchfuzzypos(" \t ")) | 130 call assert_equal([[], [], []], ['foo bar']->matchfuzzypos(" \t ")) |
131 call assert_equal([['grace'], [[1, 2, 3, 4, 2, 3, 4, 0, 1, 2, 3, 4]]], ['grace']->matchfuzzypos('race ace grace')) | 131 call assert_equal([['grace'], [[1, 2, 3, 4, 2, 3, 4, 0, 1, 2, 3, 4]], [657]], ['grace']->matchfuzzypos('race ace grace')) |
132 | 132 |
133 let l = [{'id' : 5, 'val' : 'crayon'}, {'id' : 6, 'val' : 'camera'}] | 133 let l = [{'id' : 5, 'val' : 'crayon'}, {'id' : 6, 'val' : 'camera'}] |
134 call assert_equal([[{'id' : 6, 'val' : 'camera'}], [[0, 1, 2]]], | 134 call assert_equal([[{'id' : 6, 'val' : 'camera'}], [[0, 1, 2]], [192]], |
135 \ matchfuzzypos(l, 'cam', {'text_cb' : {v -> v.val}})) | 135 \ matchfuzzypos(l, 'cam', {'text_cb' : {v -> v.val}})) |
136 call assert_equal([[{'id' : 6, 'val' : 'camera'}], [[0, 1, 2]]], | 136 call assert_equal([[{'id' : 6, 'val' : 'camera'}], [[0, 1, 2]], [192]], |
137 \ matchfuzzypos(l, 'cam', {'key' : 'val'})) | 137 \ matchfuzzypos(l, 'cam', {'key' : 'val'})) |
138 call assert_equal([[], []], matchfuzzypos(l, 'day', {'text_cb' : {v -> v.val}})) | 138 call assert_equal([[], [], []], matchfuzzypos(l, 'day', {'text_cb' : {v -> v.val}})) |
139 call assert_equal([[], []], matchfuzzypos(l, 'day', {'key' : 'val'})) | 139 call assert_equal([[], [], []], matchfuzzypos(l, 'day', {'key' : 'val'})) |
140 call assert_fails("let x = matchfuzzypos(l, 'cam', 'random')", 'E715:') | 140 call assert_fails("let x = matchfuzzypos(l, 'cam', 'random')", 'E715:') |
141 call assert_equal([[], []], matchfuzzypos(l, 'day', {'text_cb' : {v -> []}})) | 141 call assert_equal([[], [], []], matchfuzzypos(l, 'day', {'text_cb' : {v -> []}})) |
142 call assert_equal([[], []], matchfuzzypos(l, 'day', {'text_cb' : {v -> 1}})) | 142 call assert_equal([[], [], []], matchfuzzypos(l, 'day', {'text_cb' : {v -> 1}})) |
143 call assert_fails("let x = matchfuzzypos(l, 'day', {'text_cb' : {a, b -> 1}})", 'E119:') | 143 call assert_fails("let x = matchfuzzypos(l, 'day', {'text_cb' : {a, b -> 1}})", 'E119:') |
144 call assert_equal([[], []], matchfuzzypos(l, 'cam')) | 144 call assert_equal([[], [], []], matchfuzzypos(l, 'cam')) |
145 call assert_fails("let x = matchfuzzypos(l, 'cam', {'text_cb' : []})", 'E921:') | 145 call assert_fails("let x = matchfuzzypos(l, 'cam', {'text_cb' : []})", 'E921:') |
146 call assert_fails("let x = matchfuzzypos(l, 'foo', {'key' : []})", 'E730:') | 146 call assert_fails("let x = matchfuzzypos(l, 'foo', {'key' : []})", 'E730:') |
147 call assert_fails("let x = matchfuzzypos(l, 'cam', test_null_dict())", 'E715:') | 147 call assert_fails("let x = matchfuzzypos(l, 'cam', test_null_dict())", 'E715:') |
148 call assert_fails("let x = matchfuzzypos(l, 'foo', {'key' : test_null_string()})", 'E475:') | 148 call assert_fails("let x = matchfuzzypos(l, 'foo', {'key' : test_null_string()})", 'E475:') |
149 call assert_fails("let x = matchfuzzypos(l, 'foo', {'text_cb' : test_null_function()})", 'E475:') | 149 call assert_fails("let x = matchfuzzypos(l, 'foo', {'text_cb' : test_null_function()})", 'E475:') |
191 endfunc | 191 endfunc |
192 | 192 |
193 " Test for matchfuzzypos() with multibyte characters | 193 " Test for matchfuzzypos() with multibyte characters |
194 func Test_matchfuzzypos_mbyte() | 194 func Test_matchfuzzypos_mbyte() |
195 CheckFeature multi_lang | 195 CheckFeature multi_lang |
196 call assert_equal([['こんにちは世界'], [[0, 1, 2, 3, 4]]], | 196 call assert_equal([['こんにちは世界'], [[0, 1, 2, 3, 4]], [273]], |
197 \ matchfuzzypos(['こんにちは世界'], 'こんにちは')) | 197 \ matchfuzzypos(['こんにちは世界'], 'こんにちは')) |
198 call assert_equal([['ンヹㄇヺヴ'], [[1, 3]]], matchfuzzypos(['ンヹㄇヺヴ'], 'ヹヺ')) | 198 call assert_equal([['ンヹㄇヺヴ'], [[1, 3]], [88]], matchfuzzypos(['ンヹㄇヺヴ'], 'ヹヺ')) |
199 " reverse the order of characters | 199 " reverse the order of characters |
200 call assert_equal([[], []], matchfuzzypos(['ンヹㄇヺヴ'], 'ヺヹ')) | 200 call assert_equal([[], [], []], matchfuzzypos(['ンヹㄇヺヴ'], 'ヺヹ')) |
201 call assert_equal([['αβΩxxx', 'xαxβxΩx'], [[0, 1, 2], [1, 3, 5]]], | 201 call assert_equal([['αβΩxxx', 'xαxβxΩx'], [[0, 1, 2], [1, 3, 5]], [222, 113]], |
202 \ matchfuzzypos(['αβΩxxx', 'xαxβxΩx'], 'αβΩ')) | 202 \ matchfuzzypos(['αβΩxxx', 'xαxβxΩx'], 'αβΩ')) |
203 call assert_equal([['ππbbππ', 'πππbbbπππ', 'ππππbbbbππππ', 'πbπ'], | 203 call assert_equal([['ππbbππ', 'πππbbbπππ', 'ππππbbbbππππ', 'πbπ'], |
204 \ [[0, 1], [0, 1], [0, 1], [0, 2]]], | 204 \ [[0, 1], [0, 1], [0, 1], [0, 2]], [151, 148, 145, 110]], |
205 \ matchfuzzypos(['πbπ', 'ππbbππ', 'πππbbbπππ', 'ππππbbbbππππ'], 'ππ')) | 205 \ matchfuzzypos(['πbπ', 'ππbbππ', 'πππbbbπππ', 'ππππbbbbππππ'], 'ππ')) |
206 call assert_equal([['ααααααα'], [[0, 1, 2]]], | 206 call assert_equal([['ααααααα'], [[0, 1, 2]], [191]], |
207 \ matchfuzzypos(['ααααααα'], 'ααα')) | 207 \ matchfuzzypos(['ααααααα'], 'ααα')) |
208 | 208 |
209 call assert_equal([[], []], matchfuzzypos(['ンヹㄇ', 'ŗŝţ'], 'fffifl')) | 209 call assert_equal([[], [], []], matchfuzzypos(['ンヹㄇ', 'ŗŝţ'], 'fffifl')) |
210 let x = matchfuzzypos([repeat('Ψ', 256)], repeat('Ψ', 256)) | 210 let x = matchfuzzypos([repeat('Ψ', 256)], repeat('Ψ', 256)) |
211 call assert_equal(range(256), x[1][0]) | 211 call assert_equal(range(256), x[1][0]) |
212 call assert_equal([[], []], matchfuzzypos([repeat('✓', 300)], repeat('✓', 257))) | 212 call assert_equal([[], [], []], matchfuzzypos([repeat('✓', 300)], repeat('✓', 257))) |
213 | 213 |
214 " match multiple words (separated by space) | 214 " match multiple words (separated by space) |
215 call assert_equal([['세 마리의 작은 돼지'], [[9, 10, 2, 3, 4]]], ['세 마리의 작은 돼지', '마리의', '마리의 작은', '작은 돼지']->matchfuzzypos('돼지 마리의')) | 215 call assert_equal([['세 마리의 작은 돼지'], [[9, 10, 2, 3, 4]], [328]], ['세 마리의 작은 돼지', '마리의', '마리의 작은', '작은 돼지']->matchfuzzypos('돼지 마리의')) |
216 call assert_equal([[], []], ['세 마리의 작은 돼지', '마리의', '마리의 작은', '작은 돼지']->matchfuzzypos('파란 하늘')) | 216 call assert_equal([[], [], []], ['세 마리의 작은 돼지', '마리의', '마리의 작은', '작은 돼지']->matchfuzzypos('파란 하늘')) |
217 | 217 |
218 " match in a long string | 218 " match in a long string |
219 call assert_equal([[repeat('ぶ', 300) .. 'ẼẼẼ'], [[300, 301, 302]]], | 219 call assert_equal([[repeat('ぶ', 300) .. 'ẼẼẼ'], [[300, 301, 302]], [-135]], |
220 \ matchfuzzypos([repeat('ぶ', 300) .. 'ẼẼẼ'], 'ẼẼẼ')) | 220 \ matchfuzzypos([repeat('ぶ', 300) .. 'ẼẼẼ'], 'ẼẼẼ')) |
221 " preference for camel case match | 221 " preference for camel case match |
222 call assert_equal([['xѳѵҁxxѳѴҁ'], [[6, 7, 8]]], matchfuzzypos(['xѳѵҁxxѳѴҁ'], 'ѳѵҁ')) | 222 call assert_equal([['xѳѵҁxxѳѴҁ'], [[6, 7, 8]], [189]], matchfuzzypos(['xѳѵҁxxѳѴҁ'], 'ѳѵҁ')) |
223 " preference for match after a separator (_ or space) | 223 " preference for match after a separator (_ or space) |
224 call assert_equal([['xちだx_ちだ'], [[5, 6]]], matchfuzzypos(['xちだx_ちだ'], 'ちだ')) | 224 call assert_equal([['xちだx_ちだ'], [[5, 6]], [145]], matchfuzzypos(['xちだx_ちだ'], 'ちだ')) |
225 " preference for leading letter match | 225 " preference for leading letter match |
226 call assert_equal([['ѳѵҁxѳѵҁ'], [[0, 1]]], matchfuzzypos(['ѳѵҁxѳѵҁ'], 'ѳѵ')) | 226 call assert_equal([['ѳѵҁxѳѵҁ'], [[0, 1]], [150]], matchfuzzypos(['ѳѵҁxѳѵҁ'], 'ѳѵ')) |
227 " preference for sequential match | 227 " preference for sequential match |
228 call assert_equal([['aンbヹcㄇdンヹㄇ'], [[7, 8, 9]]], matchfuzzypos(['aンbヹcㄇdンヹㄇ'], 'ンヹㄇ')) | 228 call assert_equal([['aンbヹcㄇdンヹㄇ'], [[7, 8, 9]], [158]], matchfuzzypos(['aンbヹcㄇdンヹㄇ'], 'ンヹㄇ')) |
229 " best recursive match | 229 " best recursive match |
230 call assert_equal([['xффйд'], [[2, 3, 4]]], matchfuzzypos(['xффйд'], 'фйд')) | 230 call assert_equal([['xффйд'], [[2, 3, 4]], [168]], matchfuzzypos(['xффйд'], 'фйд')) |
231 endfunc | 231 endfunc |
232 | 232 |
233 " vim: shiftwidth=2 sts=2 expandtab | 233 " vim: shiftwidth=2 sts=2 expandtab |