@@ -96,15 +96,15 @@ endfunc
9696
9797" Test for the matchfuzzypos() function
9898func Test_matchfuzzypos ()
99- call assert_equal ([[' curl' , ' world' ], [[2 ,3 ], [2 ,3 ]], [128 , 127 ]], matchfuzzypos ([' world' , ' curl' ], ' rl' ))
100- call assert_equal ([[' curl' , ' world' ], [[2 ,3 ], [2 ,3 ]], [128 , 127 ]], matchfuzzypos ([' world' , ' one' , ' curl' ], ' rl' ))
99+ call assert_equal ([[' curl' , ' world' ], [[2 ,3 ], [2 ,3 ]], [178 , 177 ]], matchfuzzypos ([' world' , ' curl' ], ' rl' ))
100+ call assert_equal ([[' curl' , ' world' ], [[2 ,3 ], [2 ,3 ]], [178 , 177 ]], matchfuzzypos ([' world' , ' one' , ' curl' ], ' rl' ))
101101 call assert_equal ([[' hello' , ' hello world hello world' ],
102- \ [[0 , 1 , 2 , 3 , 4 ], [0 , 1 , 2 , 3 , 4 ]], [375 , 257 ]],
102+ \ [[0 , 1 , 2 , 3 , 4 ], [0 , 1 , 2 , 3 , 4 ]], [500 , 382 ]],
103103 \ matchfuzzypos ([' hello world hello world' , ' hello' , ' world' ], ' hello' ))
104- call assert_equal ([[' aaaaaaa' ], [[0 , 1 , 2 ]], [191 ]], matchfuzzypos ([' aaaaaaa' ], ' aaa' ))
105- call assert_equal ([[' a b' ], [[0 , 3 ]], [219 ]], matchfuzzypos ([' a b' ], ' a b' ))
106- call assert_equal ([[' a b' ], [[0 , 3 ]], [219 ]], matchfuzzypos ([' a b' ], ' a b' ))
107- call assert_equal ([[' a b' ], [[0 ]], [112 ]], matchfuzzypos ([' a b' ], ' a ' ))
104+ call assert_equal ([[' aaaaaaa' ], [[0 , 1 , 2 ]], [266 ]], matchfuzzypos ([' aaaaaaa' ], ' aaa' ))
105+ call assert_equal ([[' a b' ], [[0 , 3 ]], [269 ]], matchfuzzypos ([' a b' ], ' a b' ))
106+ call assert_equal ([[' a b' ], [[0 , 3 ]], [269 ]], matchfuzzypos ([' a b' ], ' a b' ))
107+ call assert_equal ([[' a b' ], [[0 ]], [137 ]], matchfuzzypos ([' a b' ], ' a ' ))
108108 call assert_equal ([[], [], []], matchfuzzypos ([' a b' ], ' ' ))
109109 call assert_equal ([[], [], []], matchfuzzypos ([' world' , ' curl' ], ' ab' ))
110110 let x = matchfuzzypos ([repeat (' a' , 256 )], repeat (' a' , 256 ))
@@ -113,33 +113,33 @@ func Test_matchfuzzypos()
113113 call assert_equal ([[], [], []], matchfuzzypos ([], ' abc' ))
114114
115115 " match in a long string
116- call assert_equal ([[repeat (' x' , 300 ) .. ' abc' ], [[300 , 301 , 302 ]], [-135 ]],
116+ call assert_equal ([[repeat (' x' , 300 ) .. ' abc' ], [[300 , 301 , 302 ]], [-60 ]],
117117 \ matchfuzzypos ([repeat (' x' , 300 ) .. ' abc' ], ' abc' ))
118118
119119 " preference for camel case match
120- call assert_equal ([[' xabcxxaBc' ], [[6 , 7 , 8 ]], [189 ]], matchfuzzypos ([' xabcxxaBc' ], ' abc' ))
120+ call assert_equal ([[' xabcxxaBc' ], [[6 , 7 , 8 ]], [269 ]], matchfuzzypos ([' xabcxxaBc' ], ' abc' ))
121121 " preference for match after a separator (_ or space)
122- call assert_equal ([[' xabx_ab' ], [[5 , 6 ]], [145 ]], matchfuzzypos ([' xabx_ab' ], ' ab' ))
122+ call assert_equal ([[' xabx_ab' ], [[5 , 6 ]], [195 ]], matchfuzzypos ([' xabx_ab' ], ' ab' ))
123123 " preference for leading letter match
124- call assert_equal ([[' abcxabc' ], [[0 , 1 ]], [150 ]], matchfuzzypos ([' abcxabc' ], ' ab' ))
124+ call assert_equal ([[' abcxabc' ], [[0 , 1 ]], [200 ]], matchfuzzypos ([' abcxabc' ], ' ab' ))
125125 " preference for sequential match
126- call assert_equal ([[' aobncedone' ], [[7 , 8 , 9 ]], [158 ]], matchfuzzypos ([' aobncedone' ], ' one' ))
126+ call assert_equal ([[' aobncedone' ], [[7 , 8 , 9 ]], [233 ]], matchfuzzypos ([' aobncedone' ], ' one' ))
127127 " best recursive match
128- call assert_equal ([[' xoone' ], [[2 , 3 , 4 ]], [168 ]], matchfuzzypos ([' xoone' ], ' one' ))
128+ call assert_equal ([[' xoone' ], [[2 , 3 , 4 ]], [243 ]], matchfuzzypos ([' xoone' ], ' one' ))
129129
130130 " match multiple words (separated by space)
131- call assert_equal ([[' foo bar baz' ], [[8 , 9 , 10 , 0 , 1 , 2 ]], [369 ]], [' foo bar baz' , ' foo' , ' foo bar' , ' baz bar' ]- >matchfuzzypos (' baz foo' ))
131+ call assert_equal ([[' foo bar baz' ], [[8 , 9 , 10 , 0 , 1 , 2 ]], [519 ]], [' foo bar baz' , ' foo' , ' foo bar' , ' baz bar' ]- >matchfuzzypos (' baz foo' ))
132132 call assert_equal ([[], [], []], [' foo bar baz' , ' foo' , ' foo bar' , ' baz bar' ]- >matchfuzzypos (' baz foo' , {' matchseq' : 1 }))
133- call assert_equal ([[' foo bar baz' ], [[0 , 1 , 2 , 8 , 9 , 10 ]], [369 ]], [' foo bar baz' , ' foo' , ' foo bar' , ' baz bar' ]- >matchfuzzypos (' foo baz' ))
134- call assert_equal ([[' foo bar baz' ], [[0 , 1 , 2 , 3 , 4 , 5 , 10 ]], [326 ]], [' foo bar baz' , ' foo' , ' foo bar' , ' baz bar' ]- >matchfuzzypos (' foo baz' , {' matchseq' : 1 }))
133+ call assert_equal ([[' foo bar baz' ], [[0 , 1 , 2 , 8 , 9 , 10 ]], [519 ]], [' foo bar baz' , ' foo' , ' foo bar' , ' baz bar' ]- >matchfuzzypos (' foo baz' ))
134+ call assert_equal ([[' foo bar baz' ], [[0 , 1 , 2 , 3 , 4 , 5 , 10 ]], [476 ]], [' foo bar baz' , ' foo' , ' foo bar' , ' baz bar' ]- >matchfuzzypos (' foo baz' , {' matchseq' : 1 }))
135135 call assert_equal ([[], [], []], [' foo bar baz' , ' foo' , ' foo bar' , ' baz bar' ]- >matchfuzzypos (' one two' ))
136136 call assert_equal ([[], [], []], [' foo bar' ]- >matchfuzzypos (" \t " ))
137- call assert_equal ([[' grace' ], [[1 , 2 , 3 , 4 , 2 , 3 , 4 , 0 , 1 , 2 , 3 , 4 ]], [757 ]], [' grace' ]- >matchfuzzypos (' race ace grace' ))
137+ call assert_equal ([[' grace' ], [[1 , 2 , 3 , 4 , 2 , 3 , 4 , 0 , 1 , 2 , 3 , 4 ]], [1057 ]], [' grace' ]- >matchfuzzypos (' race ace grace' ))
138138
139139 let l = [{' id' : 5 , ' val' : ' crayon' }, {' id' : 6 , ' val' : ' camera' }]
140- call assert_equal ([[{' id' : 6 , ' val' : ' camera' }], [[0 , 1 , 2 ]], [192 ]],
140+ call assert_equal ([[{' id' : 6 , ' val' : ' camera' }], [[0 , 1 , 2 ]], [267 ]],
141141 \ matchfuzzypos (l , ' cam' , {' text_cb' : {v - > v .val}}))
142- call assert_equal ([[{' id' : 6 , ' val' : ' camera' }], [[0 , 1 , 2 ]], [192 ]],
142+ call assert_equal ([[{' id' : 6 , ' val' : ' camera' }], [[0 , 1 , 2 ]], [267 ]],
143143 \ matchfuzzypos (l , ' cam' , {' key' : ' val' }))
144144 call assert_equal ([[], [], []], matchfuzzypos (l , ' day' , {' text_cb' : {v - > v .val}}))
145145 call assert_equal ([[], [], []], matchfuzzypos (l , ' day' , {' key' : ' val' }))
@@ -154,6 +154,18 @@ func Test_matchfuzzypos()
154154 call assert_fails (" let x = matchfuzzypos(l, 'foo', {'key' : test_null_string()})" , ' E475:' )
155155 call assert_fails (" let x = matchfuzzypos(l, 'foo', {'text_cb' : test_null_function()})" , ' E475:' )
156156
157+ " case match
158+ call assert_equal ([[' Match' , ' match' ], [[0 , 1 ], [0 , 1 ]], [202 , 177 ]], matchfuzzypos ([' match' , ' Match' ], ' Ma' ))
159+ call assert_equal ([[' match' , ' Match' ], [[0 , 1 ], [0 , 1 ]], [202 , 177 ]], matchfuzzypos ([' Match' , ' match' ], ' ma' ))
160+ " CamelCase has high weight even case match
161+ call assert_equal ([' MyTestCase' , ' mytestcase' ], matchfuzzy ([' mytestcase' , ' MyTestCase' ], ' mtc' ))
162+ call assert_equal ([' MyTestCase' , ' mytestcase' ], matchfuzzy ([' MyTestCase' , ' mytestcase' ], ' mtc' ))
163+ call assert_equal ([' MyTest' , ' Mytest' , ' mytest' , ],matchfuzzy ([' Mytest' , ' mytest' , ' MyTest' ], ' MyT' ))
164+ call assert_equal ([' CamelCaseMatchIngAlg' , ' camelCaseMatchingAlg' , ' camelcasematchingalg' ],
165+ \ matchfuzzy ([' CamelCaseMatchIngAlg' , ' camelcasematchingalg' , ' camelCaseMatchingAlg' ], ' CamelCase' ))
166+ call assert_equal ([' CamelCaseMatchIngAlg' , ' camelCaseMatchingAlg' , ' camelcasematchingalg' ],
167+ \ matchfuzzy ([' CamelCaseMatchIngAlg' , ' camelcasematchingalg' , ' camelCaseMatchingAlg' ], ' CamelcaseM' ))
168+
157169 let l = [{' id' : 5 , ' name' : ' foo' }, {' id' : 6 , ' name' : []}, {' id' : 7 }]
158170 call assert_fails (" let x = matchfuzzypos(l, 'foo', {'key' : 'name'})" , ' E730:' )
159171endfunc
@@ -204,12 +216,12 @@ func Test_matchfuzzypos_mbyte()
204216 call assert_equal ([[' ンヹㄇヺヴ' ], [[1 , 3 ]], [88 ]], matchfuzzypos ([' ンヹㄇヺヴ' ], ' ヹヺ' ))
205217 " reverse the order of characters
206218 call assert_equal ([[], [], []], matchfuzzypos ([' ンヹㄇヺヴ' ], ' ヺヹ' ))
207- call assert_equal ([[' αβΩxxx' , ' xαxβxΩx' ], [[0 , 1 , 2 ], [1 , 3 , 5 ]], [222 , 113 ]],
219+ call assert_equal ([[' αβΩxxx' , ' xαxβxΩx' ], [[0 , 1 , 2 ], [1 , 3 , 5 ]], [252 , 143 ]],
208220 \ matchfuzzypos ([' αβΩxxx' , ' xαxβxΩx' ], ' αβΩ' ))
209221 call assert_equal ([[' ππbbππ' , ' πππbbbπππ' , ' ππππbbbbππππ' , ' πbπ' ],
210- \ [[0 , 1 ], [0 , 1 ], [0 , 1 ], [0 , 2 ]], [151 , 148 , 145 , 110 ]],
222+ \ [[0 , 1 ], [0 , 1 ], [0 , 1 ], [0 , 2 ]], [176 , 173 , 170 , 135 ]],
211223 \ matchfuzzypos ([' πbπ' , ' ππbbππ' , ' πππbbbπππ' , ' ππππbbbbππππ' ], ' ππ' ))
212- call assert_equal ([[' ααααααα' ], [[0 , 1 , 2 ]], [191 ]],
224+ call assert_equal ([[' ααααααα' ], [[0 , 1 , 2 ]], [216 ]],
213225 \ matchfuzzypos ([' ααααααα' ], ' ααα' ))
214226
215227 call assert_equal ([[], [], []], matchfuzzypos ([' ンヹㄇ' , ' ŗŝţ' ], ' fffifl' ))
@@ -222,10 +234,10 @@ func Test_matchfuzzypos_mbyte()
222234 call assert_equal ([[], [], []], [' 세 마리의 작은 돼지' , ' 마리의' , ' 마리의 작은' , ' 작은 돼지' ]- >matchfuzzypos (' 파란 하늘' ))
223235
224236 " match in a long string
225- call assert_equal ([[repeat (' ぶ' , 300 ) .. ' ẼẼẼ' ], [[300 , 301 , 302 ]], [-135 ]],
237+ call assert_equal ([[repeat (' ぶ' , 300 ) .. ' ẼẼẼ' ], [[300 , 301 , 302 ]], [-110 ]],
226238 \ matchfuzzypos ([repeat (' ぶ' , 300 ) .. ' ẼẼẼ' ], ' ẼẼẼ' ))
227239 " preference for camel case match
228- call assert_equal ([[' xѳѵҁxxѳѴҁ' ], [[6 , 7 , 8 ]], [189 ]], matchfuzzypos ([' xѳѵҁxxѳѴҁ' ], ' ѳѵҁ' ))
240+ call assert_equal ([[' xѳѵҁxxѳѴҁ' ], [[6 , 7 , 8 ]], [219 ]], matchfuzzypos ([' xѳѵҁxxѳѴҁ' ], ' ѳѵҁ' ))
229241 " preference for match after a separator (_ or space)
230242 call assert_equal ([[' xちだx_ちだ' ], [[5 , 6 ]], [145 ]], matchfuzzypos ([' xちだx_ちだ' ], ' ちだ' ))
231243 " preference for leading letter match
0 commit comments