2022-01-01 09:40:28 -07:00
|
|
|
|
" Tests for fuzzy matching
|
|
|
|
|
|
|
|
|
|
source shared.vim
|
|
|
|
|
source check.vim
|
|
|
|
|
|
|
|
|
|
" Test for matchfuzzy()
|
|
|
|
|
func Test_matchfuzzy()
|
|
|
|
|
call assert_fails('call matchfuzzy(10, "abc")', 'E686:')
|
|
|
|
|
" Needs v8.2.1183; match the final error that's thrown for now
|
|
|
|
|
" call assert_fails('call matchfuzzy(["abc"], [])', 'E730:')
|
|
|
|
|
call assert_fails('call matchfuzzy(["abc"], [])', 'E475:')
|
|
|
|
|
call assert_fails("let x = matchfuzzy(v:_null_list, 'foo')", 'E686:')
|
|
|
|
|
call assert_fails('call matchfuzzy(["abc"], v:_null_string)', 'E475:')
|
|
|
|
|
call assert_equal([], matchfuzzy([], 'abc'))
|
|
|
|
|
call assert_equal([], matchfuzzy(['abc'], ''))
|
|
|
|
|
call assert_equal(['abc'], matchfuzzy(['abc', 10], 'ac'))
|
|
|
|
|
call assert_equal([], matchfuzzy([10, 20], 'ac'))
|
|
|
|
|
call assert_equal(['abc'], matchfuzzy(['abc'], 'abc'))
|
|
|
|
|
call assert_equal(['crayon', 'camera'], matchfuzzy(['camera', 'crayon'], 'cra'))
|
|
|
|
|
call assert_equal(['aabbaa', 'aaabbbaaa', 'aaaabbbbaaaa', 'aba'], matchfuzzy(['aba', 'aabbaa', 'aaabbbaaa', 'aaaabbbbaaaa'], 'aa'))
|
|
|
|
|
call assert_equal(['one'], matchfuzzy(['one', 'two'], 'one'))
|
|
|
|
|
call assert_equal(['oneTwo', 'onetwo'], matchfuzzy(['onetwo', 'oneTwo'], 'oneTwo'))
|
2022-01-01 14:12:53 -07:00
|
|
|
|
call assert_equal(['onetwo', 'one_two'], matchfuzzy(['onetwo', 'one_two'], 'oneTwo'))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
call assert_equal(['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'], matchfuzzy(['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'], 'aa'))
|
|
|
|
|
call assert_equal(256, matchfuzzy([repeat('a', 256)], repeat('a', 256))[0]->len())
|
|
|
|
|
call assert_equal([], matchfuzzy([repeat('a', 300)], repeat('a', 257)))
|
2022-01-01 14:25:41 -07:00
|
|
|
|
" matches with same score should not be reordered
|
|
|
|
|
let l = ['abc1', 'abc2', 'abc3']
|
|
|
|
|
call assert_equal(l, l->matchfuzzy('abc'))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
|
|
|
|
|
" Tests for match preferences
|
|
|
|
|
" preference for camel case match
|
|
|
|
|
call assert_equal(['oneTwo', 'onetwo'], ['onetwo', 'oneTwo']->matchfuzzy('onetwo'))
|
|
|
|
|
" preference for match after a separator (_ or space)
|
2022-01-01 14:25:41 -07:00
|
|
|
|
call assert_equal(['onetwo', 'one_two', 'one two'], ['onetwo', 'one_two', 'one two']->matchfuzzy('onetwo'))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
" preference for leading letter match
|
|
|
|
|
call assert_equal(['onetwo', 'xonetwo'], ['xonetwo', 'onetwo']->matchfuzzy('onetwo'))
|
|
|
|
|
" preference for sequential match
|
|
|
|
|
call assert_equal(['onetwo', 'oanbectdweo'], ['oanbectdweo', 'onetwo']->matchfuzzy('onetwo'))
|
|
|
|
|
" non-matching leading letter(s) penalty
|
|
|
|
|
call assert_equal(['xonetwo', 'xxonetwo'], ['xxonetwo', 'xonetwo']->matchfuzzy('onetwo'))
|
|
|
|
|
" total non-matching letter(s) penalty
|
|
|
|
|
call assert_equal(['one', 'onex', 'onexx'], ['onexx', 'one', 'onex']->matchfuzzy('one'))
|
2022-01-01 14:12:53 -07:00
|
|
|
|
" prefer complete matches over separator matches
|
|
|
|
|
call assert_equal(['.vim/vimrc', '.vim/vimrc_colors', '.vim/v_i_m_r_c'], ['.vim/vimrc', '.vim/vimrc_colors', '.vim/v_i_m_r_c']->matchfuzzy('vimrc'))
|
2022-01-01 14:25:41 -07:00
|
|
|
|
" gap penalty
|
|
|
|
|
call assert_equal(['xxayybxxxx', 'xxayyybxxx', 'xxayyyybxx'], ['xxayyyybxx', 'xxayyybxxx', 'xxayybxxxx']->matchfuzzy('ab'))
|
2022-01-01 15:35:43 -07:00
|
|
|
|
" path separator vs word separator
|
|
|
|
|
call assert_equal(['color/setup.vim', 'color\\setup.vim', 'color setup.vim', 'color_setup.vim', 'colorsetup.vim'], matchfuzzy(['colorsetup.vim', 'color setup.vim', 'color/setup.vim', 'color_setup.vim', 'color\\setup.vim'], 'setup.vim'))
|
2022-01-01 14:25:41 -07:00
|
|
|
|
|
|
|
|
|
" match multiple words (separated by space)
|
|
|
|
|
call assert_equal(['foo bar baz'], ['foo bar baz', 'foo', 'foo bar', 'baz bar']->matchfuzzy('baz foo'))
|
|
|
|
|
call assert_equal([], ['foo bar baz', 'foo', 'foo bar', 'baz bar']->matchfuzzy('one two'))
|
|
|
|
|
call assert_equal([], ['foo bar']->matchfuzzy(" \t "))
|
|
|
|
|
|
|
|
|
|
" test for matching a sequence of words
|
|
|
|
|
call assert_equal(['bar foo'], ['foo bar', 'bar foo', 'foobar', 'barfoo']->matchfuzzy('bar foo', {'matchseq' : 1}))
|
|
|
|
|
call assert_equal([#{text: 'two one'}], [#{text: 'one two'}, #{text: 'two one'}]->matchfuzzy('two one', #{key: 'text', matchseq: v:true}))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
|
|
|
|
|
%bw!
|
|
|
|
|
eval ['somebuf', 'anotherone', 'needle', 'yetanotherone']->map({_, v -> bufadd(v) + bufload(v)})
|
2022-07-02 15:01:51 -07:00
|
|
|
|
let l = getbufinfo()->map({_, v -> fnamemodify(v.name, ':t')})->matchfuzzy('ndl')
|
2022-01-01 09:40:28 -07:00
|
|
|
|
call assert_equal(1, len(l))
|
|
|
|
|
call assert_match('needle', l[0])
|
|
|
|
|
|
2022-01-01 14:25:41 -07:00
|
|
|
|
" Test for fuzzy matching dicts
|
2022-01-01 09:40:28 -07:00
|
|
|
|
let l = [{'id' : 5, 'val' : 'crayon'}, {'id' : 6, 'val' : 'camera'}]
|
|
|
|
|
call assert_equal([{'id' : 6, 'val' : 'camera'}], matchfuzzy(l, 'cam', {'text_cb' : {v -> v.val}}))
|
|
|
|
|
call assert_equal([{'id' : 6, 'val' : 'camera'}], matchfuzzy(l, 'cam', {'key' : 'val'}))
|
|
|
|
|
call assert_equal([], matchfuzzy(l, 'day', {'text_cb' : {v -> v.val}}))
|
|
|
|
|
call assert_equal([], matchfuzzy(l, 'day', {'key' : 'val'}))
|
|
|
|
|
call assert_fails("let x = matchfuzzy(l, 'cam', 'random')", 'E715:')
|
|
|
|
|
call assert_equal([], matchfuzzy(l, 'day', {'text_cb' : {v -> []}}))
|
|
|
|
|
call assert_equal([], matchfuzzy(l, 'day', {'text_cb' : {v -> 1}}))
|
|
|
|
|
call assert_fails("let x = matchfuzzy(l, 'day', {'text_cb' : {a, b -> 1}})", 'E119:')
|
|
|
|
|
call assert_equal([], matchfuzzy(l, 'cam'))
|
|
|
|
|
" Nvim's callback implementation is different, so E6000 is expected instead,
|
|
|
|
|
" but we need v8.2.1183 to assert it
|
|
|
|
|
" call assert_fails("let x = matchfuzzy(l, 'cam', {'text_cb' : []})", 'E921:')
|
|
|
|
|
" call assert_fails("let x = matchfuzzy(l, 'cam', {'text_cb' : []})", 'E6000:')
|
|
|
|
|
call assert_fails("let x = matchfuzzy(l, 'cam', {'text_cb' : []})", 'E475:')
|
|
|
|
|
" call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : []})", 'E730:')
|
|
|
|
|
call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : []})", 'E475:')
|
|
|
|
|
call assert_fails("let x = matchfuzzy(l, 'cam', v:_null_dict)", 'E715:')
|
|
|
|
|
call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : v:_null_string})", 'E475:')
|
|
|
|
|
" Nvim doesn't have null functions
|
|
|
|
|
" call assert_fails("let x = matchfuzzy(l, 'foo', {'text_cb' : test_null_function()})", 'E475:')
|
2022-01-01 14:25:41 -07:00
|
|
|
|
" matches with same score should not be reordered
|
|
|
|
|
let l = [#{text: 'abc', id: 1}, #{text: 'abc', id: 2}, #{text: 'abc', id: 3}]
|
|
|
|
|
call assert_equal(l, l->matchfuzzy('abc', #{key: 'text'}))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
|
|
|
|
|
let l = [{'id' : 5, 'name' : 'foo'}, {'id' : 6, 'name' : []}, {'id' : 7}]
|
|
|
|
|
call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : 'name'})", 'E730:')
|
|
|
|
|
|
|
|
|
|
" Test in latin1 encoding
|
|
|
|
|
let save_enc = &encoding
|
|
|
|
|
" Nvim supports utf-8 encoding only
|
|
|
|
|
" set encoding=latin1
|
|
|
|
|
call assert_equal(['abc'], matchfuzzy(['abc'], 'abc'))
|
|
|
|
|
let &encoding = save_enc
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-01-01 14:25:41 -07:00
|
|
|
|
" Test for the matchfuzzypos() function
|
2022-01-01 09:40:28 -07:00
|
|
|
|
func Test_matchfuzzypos()
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([['curl', 'world'], [[2,3], [2,3]], [128, 127]], matchfuzzypos(['world', 'curl'], 'rl'))
|
|
|
|
|
call assert_equal([['curl', 'world'], [[2,3], [2,3]], [128, 127]], matchfuzzypos(['world', 'one', 'curl'], 'rl'))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
call assert_equal([['hello', 'hello world hello world'],
|
2022-01-01 15:40:42 -07:00
|
|
|
|
\ [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4]], [275, 257]],
|
2022-01-01 09:40:28 -07:00
|
|
|
|
\ matchfuzzypos(['hello world hello world', 'hello', 'world'], 'hello'))
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([['aaaaaaa'], [[0, 1, 2]], [191]], matchfuzzypos(['aaaaaaa'], 'aaa'))
|
|
|
|
|
call assert_equal([['a b'], [[0, 3]], [219]], matchfuzzypos(['a b'], 'a b'))
|
|
|
|
|
call assert_equal([['a b'], [[0, 3]], [219]], matchfuzzypos(['a b'], 'a b'))
|
|
|
|
|
call assert_equal([['a b'], [[0]], [112]], matchfuzzypos(['a b'], ' a '))
|
|
|
|
|
call assert_equal([[], [], []], matchfuzzypos(['a b'], ' '))
|
|
|
|
|
call assert_equal([[], [], []], matchfuzzypos(['world', 'curl'], 'ab'))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
let x = matchfuzzypos([repeat('a', 256)], repeat('a', 256))
|
|
|
|
|
call assert_equal(range(256), x[1][0])
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([[], [], []], matchfuzzypos([repeat('a', 300)], repeat('a', 257)))
|
|
|
|
|
call assert_equal([[], [], []], matchfuzzypos([], 'abc'))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
|
|
|
|
|
" match in a long string
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([[repeat('x', 300) .. 'abc'], [[300, 301, 302]], [-135]],
|
2022-01-01 09:40:28 -07:00
|
|
|
|
\ matchfuzzypos([repeat('x', 300) .. 'abc'], 'abc'))
|
|
|
|
|
|
|
|
|
|
" preference for camel case match
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([['xabcxxaBc'], [[6, 7, 8]], [189]], matchfuzzypos(['xabcxxaBc'], 'abc'))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
" preference for match after a separator (_ or space)
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([['xabx_ab'], [[5, 6]], [145]], matchfuzzypos(['xabx_ab'], 'ab'))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
" preference for leading letter match
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([['abcxabc'], [[0, 1]], [150]], matchfuzzypos(['abcxabc'], 'ab'))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
" preference for sequential match
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([['aobncedone'], [[7, 8, 9]], [158]], matchfuzzypos(['aobncedone'], 'one'))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
" best recursive match
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([['xoone'], [[2, 3, 4]], [168]], matchfuzzypos(['xoone'], 'one'))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
|
2022-01-01 14:25:41 -07:00
|
|
|
|
" match multiple words (separated by space)
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([['foo bar baz'], [[8, 9, 10, 0, 1, 2]], [369]], ['foo bar baz', 'foo', 'foo bar', 'baz bar']->matchfuzzypos('baz foo'))
|
2022-05-11 06:51:31 -07:00
|
|
|
|
call assert_equal([[], [], []], ['foo bar baz', 'foo', 'foo bar', 'baz bar']->matchfuzzypos('baz foo', {'matchseq': 1}))
|
|
|
|
|
call assert_equal([['foo bar baz'], [[0, 1, 2, 8, 9, 10]], [369]], ['foo bar baz', 'foo', 'foo bar', 'baz bar']->matchfuzzypos('foo baz'))
|
|
|
|
|
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}))
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([[], [], []], ['foo bar baz', 'foo', 'foo bar', 'baz bar']->matchfuzzypos('one two'))
|
|
|
|
|
call assert_equal([[], [], []], ['foo bar']->matchfuzzypos(" \t "))
|
|
|
|
|
call assert_equal([['grace'], [[1, 2, 3, 4, 2, 3, 4, 0, 1, 2, 3, 4]], [657]], ['grace']->matchfuzzypos('race ace grace'))
|
2022-01-01 14:25:41 -07:00
|
|
|
|
|
2022-01-01 09:40:28 -07:00
|
|
|
|
let l = [{'id' : 5, 'val' : 'crayon'}, {'id' : 6, 'val' : 'camera'}]
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([[{'id' : 6, 'val' : 'camera'}], [[0, 1, 2]], [192]],
|
2022-01-01 09:40:28 -07:00
|
|
|
|
\ matchfuzzypos(l, 'cam', {'text_cb' : {v -> v.val}}))
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([[{'id' : 6, 'val' : 'camera'}], [[0, 1, 2]], [192]],
|
2022-01-01 09:40:28 -07:00
|
|
|
|
\ matchfuzzypos(l, 'cam', {'key' : 'val'}))
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([[], [], []], matchfuzzypos(l, 'day', {'text_cb' : {v -> v.val}}))
|
|
|
|
|
call assert_equal([[], [], []], matchfuzzypos(l, 'day', {'key' : 'val'}))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
call assert_fails("let x = matchfuzzypos(l, 'cam', 'random')", 'E715:')
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([[], [], []], matchfuzzypos(l, 'day', {'text_cb' : {v -> []}}))
|
|
|
|
|
call assert_equal([[], [], []], matchfuzzypos(l, 'day', {'text_cb' : {v -> 1}}))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
call assert_fails("let x = matchfuzzypos(l, 'day', {'text_cb' : {a, b -> 1}})", 'E119:')
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([[], [], []], matchfuzzypos(l, 'cam'))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
" Nvim's callback implementation is different, so E6000 is expected instead,
|
|
|
|
|
" but we need v8.2.1183 to assert it
|
|
|
|
|
" call assert_fails("let x = matchfuzzypos(l, 'cam', {'text_cb' : []})", 'E921:')
|
|
|
|
|
" call assert_fails("let x = matchfuzzypos(l, 'cam', {'text_cb' : []})", 'E6000:')
|
|
|
|
|
call assert_fails("let x = matchfuzzypos(l, 'cam', {'text_cb' : []})", 'E475:')
|
|
|
|
|
" call assert_fails("let x = matchfuzzypos(l, 'foo', {'key' : []})", 'E730:')
|
|
|
|
|
call assert_fails("let x = matchfuzzypos(l, 'foo', {'key' : []})", 'E475:')
|
|
|
|
|
call assert_fails("let x = matchfuzzypos(l, 'cam', v:_null_dict)", 'E715:')
|
|
|
|
|
call assert_fails("let x = matchfuzzypos(l, 'foo', {'key' : v:_null_string})", 'E475:')
|
|
|
|
|
" Nvim doesn't have null functions
|
|
|
|
|
" call assert_fails("let x = matchfuzzypos(l, 'foo', {'text_cb' : test_null_function()})", 'E475:')
|
|
|
|
|
|
|
|
|
|
let l = [{'id' : 5, 'name' : 'foo'}, {'id' : 6, 'name' : []}, {'id' : 7}]
|
|
|
|
|
call assert_fails("let x = matchfuzzypos(l, 'foo', {'key' : 'name'})", 'E730:')
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-01-01 14:25:41 -07:00
|
|
|
|
" Test for matchfuzzy() with multibyte characters
|
2022-01-01 09:40:28 -07:00
|
|
|
|
func Test_matchfuzzy_mbyte()
|
|
|
|
|
CheckFeature multi_lang
|
|
|
|
|
call assert_equal(['ンヹㄇヺヴ'], matchfuzzy(['ンヹㄇヺヴ'], 'ヹヺ'))
|
|
|
|
|
" reverse the order of characters
|
|
|
|
|
call assert_equal([], matchfuzzy(['ンヹㄇヺヴ'], 'ヺヹ'))
|
|
|
|
|
call assert_equal(['αβΩxxx', 'xαxβxΩx'],
|
|
|
|
|
\ matchfuzzy(['αβΩxxx', 'xαxβxΩx'], 'αβΩ'))
|
|
|
|
|
call assert_equal(['ππbbππ', 'πππbbbπππ', 'ππππbbbbππππ', 'πbπ'],
|
|
|
|
|
\ matchfuzzy(['πbπ', 'ππbbππ', 'πππbbbπππ', 'ππππbbbbππππ'], 'ππ'))
|
|
|
|
|
|
2022-01-01 14:25:41 -07:00
|
|
|
|
" match multiple words (separated by space)
|
|
|
|
|
call assert_equal(['세 마리의 작은 돼지'], ['세 마리의 작은 돼지', '마리의', '마리의 작은', '작은 돼지']->matchfuzzy('돼지 마리의'))
|
|
|
|
|
call assert_equal([], ['세 마리의 작은 돼지', '마리의', '마리의 작은', '작은 돼지']->matchfuzzy('파란 하늘'))
|
|
|
|
|
|
2022-01-01 09:40:28 -07:00
|
|
|
|
" preference for camel case match
|
|
|
|
|
call assert_equal(['oneĄwo', 'oneąwo'],
|
|
|
|
|
\ ['oneąwo', 'oneĄwo']->matchfuzzy('oneąwo'))
|
2022-01-01 14:12:53 -07:00
|
|
|
|
" preference for complete match then match after separator (_ or space)
|
2022-01-01 14:25:41 -07:00
|
|
|
|
call assert_equal(['ⅠⅡabㄟㄠ'] + sort(['ⅠⅡa_bㄟㄠ', 'ⅠⅡa bㄟㄠ']),
|
2022-01-01 14:12:53 -07:00
|
|
|
|
\ ['ⅠⅡabㄟㄠ', 'ⅠⅡa bㄟㄠ', 'ⅠⅡa_bㄟㄠ']->matchfuzzy('ⅠⅡabㄟㄠ'))
|
2022-01-01 14:25:41 -07:00
|
|
|
|
" preference for match after a separator (_ or space)
|
|
|
|
|
call assert_equal(['ㄓㄔabㄟㄠ', 'ㄓㄔa_bㄟㄠ', 'ㄓㄔa bㄟㄠ'],
|
|
|
|
|
\ ['ㄓㄔa_bㄟㄠ', 'ㄓㄔa bㄟㄠ', 'ㄓㄔabㄟㄠ']->matchfuzzy('ㄓㄔabㄟㄠ'))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
" preference for leading letter match
|
|
|
|
|
call assert_equal(['ŗŝţũŵż', 'xŗŝţũŵż'],
|
|
|
|
|
\ ['xŗŝţũŵż', 'ŗŝţũŵż']->matchfuzzy('ŗŝţũŵż'))
|
|
|
|
|
" preference for sequential match
|
|
|
|
|
call assert_equal(['ㄞㄡㄤfffifl', 'ㄞaㄡbㄤcffdfiefl'],
|
|
|
|
|
\ ['ㄞaㄡbㄤcffdfiefl', 'ㄞㄡㄤfffifl']->matchfuzzy('ㄞㄡㄤfffifl'))
|
|
|
|
|
" non-matching leading letter(s) penalty
|
|
|
|
|
call assert_equal(['xㄞㄡㄤfffifl', 'xxㄞㄡㄤfffifl'],
|
|
|
|
|
\ ['xxㄞㄡㄤfffifl', 'xㄞㄡㄤfffifl']->matchfuzzy('ㄞㄡㄤfffifl'))
|
|
|
|
|
" total non-matching letter(s) penalty
|
|
|
|
|
call assert_equal(['ŗŝţ', 'ŗŝţx', 'ŗŝţxx'],
|
|
|
|
|
\ ['ŗŝţxx', 'ŗŝţ', 'ŗŝţx']->matchfuzzy('ŗŝţ'))
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-01-01 14:25:41 -07:00
|
|
|
|
" Test for matchfuzzypos() with multibyte characters
|
2022-01-01 09:40:28 -07:00
|
|
|
|
func Test_matchfuzzypos_mbyte()
|
|
|
|
|
CheckFeature multi_lang
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([['こんにちは世界'], [[0, 1, 2, 3, 4]], [273]],
|
2022-01-01 09:40:28 -07:00
|
|
|
|
\ matchfuzzypos(['こんにちは世界'], 'こんにちは'))
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([['ンヹㄇヺヴ'], [[1, 3]], [88]], matchfuzzypos(['ンヹㄇヺヴ'], 'ヹヺ'))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
" reverse the order of characters
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([[], [], []], matchfuzzypos(['ンヹㄇヺヴ'], 'ヺヹ'))
|
|
|
|
|
call assert_equal([['αβΩxxx', 'xαxβxΩx'], [[0, 1, 2], [1, 3, 5]], [222, 113]],
|
2022-01-01 09:40:28 -07:00
|
|
|
|
\ matchfuzzypos(['αβΩxxx', 'xαxβxΩx'], 'αβΩ'))
|
|
|
|
|
call assert_equal([['ππbbππ', 'πππbbbπππ', 'ππππbbbbππππ', 'πbπ'],
|
2022-01-01 15:40:42 -07:00
|
|
|
|
\ [[0, 1], [0, 1], [0, 1], [0, 2]], [151, 148, 145, 110]],
|
2022-01-01 09:40:28 -07:00
|
|
|
|
\ matchfuzzypos(['πbπ', 'ππbbππ', 'πππbbbπππ', 'ππππbbbbππππ'], 'ππ'))
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([['ααααααα'], [[0, 1, 2]], [191]],
|
2022-01-01 09:40:28 -07:00
|
|
|
|
\ matchfuzzypos(['ααααααα'], 'ααα'))
|
|
|
|
|
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([[], [], []], matchfuzzypos(['ンヹㄇ', 'ŗŝţ'], 'fffifl'))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
let x = matchfuzzypos([repeat('Ψ', 256)], repeat('Ψ', 256))
|
|
|
|
|
call assert_equal(range(256), x[1][0])
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([[], [], []], matchfuzzypos([repeat('✓', 300)], repeat('✓', 257)))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
|
2022-01-01 14:25:41 -07:00
|
|
|
|
" match multiple words (separated by space)
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([['세 마리의 작은 돼지'], [[9, 10, 2, 3, 4]], [328]], ['세 마리의 작은 돼지', '마리의', '마리의 작은', '작은 돼지']->matchfuzzypos('돼지 마리의'))
|
|
|
|
|
call assert_equal([[], [], []], ['세 마리의 작은 돼지', '마리의', '마리의 작은', '작은 돼지']->matchfuzzypos('파란 하늘'))
|
2022-01-01 14:25:41 -07:00
|
|
|
|
|
2022-01-01 09:40:28 -07:00
|
|
|
|
" match in a long string
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([[repeat('ぶ', 300) .. 'ẼẼẼ'], [[300, 301, 302]], [-135]],
|
2022-01-01 14:25:41 -07:00
|
|
|
|
\ matchfuzzypos([repeat('ぶ', 300) .. 'ẼẼẼ'], 'ẼẼẼ'))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
" preference for camel case match
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([['xѳѵҁxxѳѴҁ'], [[6, 7, 8]], [189]], matchfuzzypos(['xѳѵҁxxѳѴҁ'], 'ѳѵҁ'))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
" preference for match after a separator (_ or space)
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([['xちだx_ちだ'], [[5, 6]], [145]], matchfuzzypos(['xちだx_ちだ'], 'ちだ'))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
" preference for leading letter match
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([['ѳѵҁxѳѵҁ'], [[0, 1]], [150]], matchfuzzypos(['ѳѵҁxѳѵҁ'], 'ѳѵ'))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
" preference for sequential match
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([['aンbヹcㄇdンヹㄇ'], [[7, 8, 9]], [158]], matchfuzzypos(['aンbヹcㄇdンヹㄇ'], 'ンヹㄇ'))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
" best recursive match
|
2022-01-01 15:40:42 -07:00
|
|
|
|
call assert_equal([['xффйд'], [[2, 3, 4]], [168]], matchfuzzypos(['xффйд'], 'фйд'))
|
2022-01-01 09:40:28 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
2022-04-24 17:02:52 -07:00
|
|
|
|
" Test for matchfuzzy() with limit
|
|
|
|
|
func Test_matchfuzzy_limit()
|
|
|
|
|
let x = ['1', '2', '3', '2']
|
|
|
|
|
call assert_equal(['2', '2'], x->matchfuzzy('2'))
|
|
|
|
|
call assert_equal(['2', '2'], x->matchfuzzy('2', #{}))
|
|
|
|
|
call assert_equal(['2', '2'], x->matchfuzzy('2', #{limit: 0}))
|
|
|
|
|
call assert_equal(['2'], x->matchfuzzy('2', #{limit: 1}))
|
|
|
|
|
call assert_equal(['2', '2'], x->matchfuzzy('2', #{limit: 2}))
|
|
|
|
|
call assert_equal(['2', '2'], x->matchfuzzy('2', #{limit: 3}))
|
|
|
|
|
call assert_fails("call matchfuzzy(x, '2', #{limit: '2'})", 'E475:')
|
2022-06-17 22:43:02 -07:00
|
|
|
|
|
|
|
|
|
let l = [{'id': 5, 'val': 'crayon'}, {'id': 6, 'val': 'camera'}]
|
|
|
|
|
call assert_equal([{'id': 5, 'val': 'crayon'}, {'id': 6, 'val': 'camera'}], l->matchfuzzy('c', #{text_cb: {v -> v.val}}))
|
|
|
|
|
call assert_equal([{'id': 5, 'val': 'crayon'}, {'id': 6, 'val': 'camera'}], l->matchfuzzy('c', #{key: 'val'}))
|
|
|
|
|
call assert_equal([{'id': 5, 'val': 'crayon'}, {'id': 6, 'val': 'camera'}], l->matchfuzzy('c', #{text_cb: {v -> v.val}, limit: 0}))
|
|
|
|
|
call assert_equal([{'id': 5, 'val': 'crayon'}, {'id': 6, 'val': 'camera'}], l->matchfuzzy('c', #{key: 'val', limit: 0}))
|
|
|
|
|
call assert_equal([{'id': 5, 'val': 'crayon'}], l->matchfuzzy('c', #{text_cb: {v -> v.val}, limit: 1}))
|
|
|
|
|
call assert_equal([{'id': 5, 'val': 'crayon'}], l->matchfuzzy('c', #{key: 'val', limit: 1}))
|
2022-04-24 17:02:52 -07:00
|
|
|
|
endfunc
|
|
|
|
|
|
2022-01-01 09:40:28 -07:00
|
|
|
|
" vim: shiftwidth=2 sts=2 expandtab
|