Mercurial > vim
annotate src/testdir/test_matchfuzzy.vim @ 32627:eeed0045eff4 v9.0.1645
patch 9.0.1645: zserio files are not recognized
Commit: https://github.com/vim/vim/commit/2b994da57a0ac6ec0ec09fe3783f48ecd2bce610
Author: =?UTF-8?q?Dominique=20Pell=C3=A9?= <dominique.pelle@gmail.com>
Date: Thu Jun 22 14:36:39 2023 +0100
patch 9.0.1645: zserio files are not recognized
Problem: zserio files are not recognized.
Solution: Add a pattern for zserio files. (Dominique Pell?,
closes #12544)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 22 Jun 2023 15:45:04 +0200 |
parents | 9c034274034b |
children | 448aef880252 |
rev | line source |
---|---|
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 " Tests for fuzzy matching |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 source shared.vim |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 source check.vim |
32335
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
5 source term_util.vim |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 " Test for matchfuzzy() |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 func Test_matchfuzzy() |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 call assert_fails('call matchfuzzy(10, "abc")', 'E686:') |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 call assert_fails('call matchfuzzy(["abc"], [])', 'E730:') |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 call assert_fails("let x = matchfuzzy(test_null_list(), 'foo')", 'E686:') |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 call assert_fails('call matchfuzzy(["abc"], test_null_string())', 'E475:') |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 call assert_equal([], matchfuzzy([], 'abc')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 call assert_equal([], matchfuzzy(['abc'], '')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 call assert_equal(['abc'], matchfuzzy(['abc', 10], 'ac')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 call assert_equal([], matchfuzzy([10, 20], 'ac')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 call assert_equal(['abc'], matchfuzzy(['abc'], 'abc')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 call assert_equal(['crayon', 'camera'], matchfuzzy(['camera', 'crayon'], 'cra')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 call assert_equal(['aabbaa', 'aaabbbaaa', 'aaaabbbbaaaa', 'aba'], matchfuzzy(['aba', 'aabbaa', 'aaabbbaaa', 'aaaabbbbaaaa'], 'aa')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 call assert_equal(['one'], matchfuzzy(['one', 'two'], 'one')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 call assert_equal(['oneTwo', 'onetwo'], matchfuzzy(['onetwo', 'oneTwo'], 'oneTwo')) |
22647
0dd527d9c62d
patch 8.2.1872: matchfuzzy() does not prefer sequential matches
Bram Moolenaar <Bram@vim.org>
parents:
22355
diff
changeset
|
22 call assert_equal(['onetwo', 'one_two'], matchfuzzy(['onetwo', 'one_two'], 'oneTwo')) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 call assert_equal(['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'], matchfuzzy(['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'], 'aa')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 call assert_equal(256, matchfuzzy([repeat('a', 256)], repeat('a', 256))[0]->len()) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 call assert_equal([], matchfuzzy([repeat('a', 300)], repeat('a', 257))) |
22689
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
26 " matches with same score should not be reordered |
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
27 let l = ['abc1', 'abc2', 'abc3'] |
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
28 call assert_equal(l, l->matchfuzzy('abc')) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 " Tests for match preferences |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 " preference for camel case match |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 call assert_equal(['oneTwo', 'onetwo'], ['onetwo', 'oneTwo']->matchfuzzy('onetwo')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 " preference for match after a separator (_ or space) |
22689
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
34 call assert_equal(['onetwo', 'one_two', 'one two'], ['onetwo', 'one_two', 'one two']->matchfuzzy('onetwo')) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 " preference for leading letter match |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 call assert_equal(['onetwo', 'xonetwo'], ['xonetwo', 'onetwo']->matchfuzzy('onetwo')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 " preference for sequential match |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 call assert_equal(['onetwo', 'oanbectdweo'], ['oanbectdweo', 'onetwo']->matchfuzzy('onetwo')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 " non-matching leading letter(s) penalty |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 call assert_equal(['xonetwo', 'xxonetwo'], ['xxonetwo', 'xonetwo']->matchfuzzy('onetwo')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 " total non-matching letter(s) penalty |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 call assert_equal(['one', 'onex', 'onexx'], ['onexx', 'one', 'onex']->matchfuzzy('one')) |
22647
0dd527d9c62d
patch 8.2.1872: matchfuzzy() does not prefer sequential matches
Bram Moolenaar <Bram@vim.org>
parents:
22355
diff
changeset
|
43 " prefer complete matches over separator matches |
0dd527d9c62d
patch 8.2.1872: matchfuzzy() does not prefer sequential matches
Bram Moolenaar <Bram@vim.org>
parents:
22355
diff
changeset
|
44 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')) |
22689
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
45 " gap penalty |
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
46 call assert_equal(['xxayybxxxx', 'xxayyybxxx', 'xxayyyybxx'], ['xxayyyybxx', 'xxayyybxxx', 'xxayybxxxx']->matchfuzzy('ab')) |
22746
875bd7c04533
patch 8.2.1921: fuzzy matching does not recognize path separators
Bram Moolenaar <Bram@vim.org>
parents:
22689
diff
changeset
|
47 " path separator vs word separator |
875bd7c04533
patch 8.2.1921: fuzzy matching does not recognize path separators
Bram Moolenaar <Bram@vim.org>
parents:
22689
diff
changeset
|
48 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')) |
22689
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
49 |
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
50 " match multiple words (separated by space) |
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
51 call assert_equal(['foo bar baz'], ['foo bar baz', 'foo', 'foo bar', 'baz bar']->matchfuzzy('baz foo')) |
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
52 call assert_equal([], ['foo bar baz', 'foo', 'foo bar', 'baz bar']->matchfuzzy('one two')) |
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
53 call assert_equal([], ['foo bar']->matchfuzzy(" \t ")) |
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
54 |
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
55 " test for matching a sequence of words |
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
56 call assert_equal(['bar foo'], ['foo bar', 'bar foo', 'foobar', 'barfoo']->matchfuzzy('bar foo', {'matchseq' : 1})) |
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
57 call assert_equal([#{text: 'two one'}], [#{text: 'one two'}, #{text: 'two one'}]->matchfuzzy('two one', #{key: 'text', matchseq: v:true})) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 %bw! |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 eval ['somebuf', 'anotherone', 'needle', 'yetanotherone']->map({_, v -> bufadd(v) + bufload(v)}) |
29375
209420b9d2dd
patch 9.0.0030: matchfuzzy test depends on path of current directory
Bram Moolenaar <Bram@vim.org>
parents:
29194
diff
changeset
|
61 let l = getbufinfo()->map({_, v -> fnamemodify(v.name, ':t')})->matchfuzzy('ndl') |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 call assert_equal(1, len(l)) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 call assert_match('needle', l[0]) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 |
22689
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
65 " Test for fuzzy matching dicts |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 let l = [{'id' : 5, 'val' : 'crayon'}, {'id' : 6, 'val' : 'camera'}] |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 call assert_equal([{'id' : 6, 'val' : 'camera'}], matchfuzzy(l, 'cam', {'text_cb' : {v -> v.val}})) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 call assert_equal([{'id' : 6, 'val' : 'camera'}], matchfuzzy(l, 'cam', {'key' : 'val'})) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 call assert_equal([], matchfuzzy(l, 'day', {'text_cb' : {v -> v.val}})) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 call assert_equal([], matchfuzzy(l, 'day', {'key' : 'val'})) |
29994
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29375
diff
changeset
|
71 call assert_fails("let x = matchfuzzy(l, 'cam', 'random')", 'E1206:') |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 call assert_equal([], matchfuzzy(l, 'day', {'text_cb' : {v -> []}})) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 call assert_equal([], matchfuzzy(l, 'day', {'text_cb' : {v -> 1}})) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 call assert_fails("let x = matchfuzzy(l, 'day', {'text_cb' : {a, b -> 1}})", 'E119:') |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 call assert_equal([], matchfuzzy(l, 'cam')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 call assert_fails("let x = matchfuzzy(l, 'cam', {'text_cb' : []})", 'E921:') |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : []})", 'E730:') |
29994
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29375
diff
changeset
|
78 call assert_fails("let x = matchfuzzy(l, 'cam', test_null_dict())", 'E1297:') |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : test_null_string()})", 'E475:') |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 call assert_fails("let x = matchfuzzy(l, 'foo', {'text_cb' : test_null_function()})", 'E475:') |
22689
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
81 " matches with same score should not be reordered |
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
82 let l = [#{text: 'abc', id: 1}, #{text: 'abc', id: 2}, #{text: 'abc', id: 3}] |
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
83 call assert_equal(l, l->matchfuzzy('abc', #{key: 'text'})) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 let l = [{'id' : 5, 'name' : 'foo'}, {'id' : 6, 'name' : []}, {'id' : 7}] |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
86 call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : 'name'})", 'E730:') |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 " Test in latin1 encoding |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 let save_enc = &encoding |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 set encoding=latin1 |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 call assert_equal(['abc'], matchfuzzy(['abc'], 'abc')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 let &encoding = save_enc |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 endfunc |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 |
22689
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
95 " Test for the matchfuzzypos() function |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 func Test_matchfuzzypos() |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
97 call assert_equal([['curl', 'world'], [[2,3], [2,3]], [128, 127]], matchfuzzypos(['world', 'curl'], 'rl')) |
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
98 call assert_equal([['curl', 'world'], [[2,3], [2,3]], [128, 127]], matchfuzzypos(['world', 'one', 'curl'], 'rl')) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
99 call assert_equal([['hello', 'hello world hello world'], |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
100 \ [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4]], [275, 257]], |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
101 \ matchfuzzypos(['hello world hello world', 'hello', 'world'], 'hello')) |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
102 call assert_equal([['aaaaaaa'], [[0, 1, 2]], [191]], matchfuzzypos(['aaaaaaa'], 'aaa')) |
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
103 call assert_equal([['a b'], [[0, 3]], [219]], matchfuzzypos(['a b'], 'a b')) |
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
104 call assert_equal([['a b'], [[0, 3]], [219]], matchfuzzypos(['a b'], 'a b')) |
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
105 call assert_equal([['a b'], [[0]], [112]], matchfuzzypos(['a b'], ' a ')) |
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
106 call assert_equal([[], [], []], matchfuzzypos(['a b'], ' ')) |
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
107 call assert_equal([[], [], []], matchfuzzypos(['world', 'curl'], 'ab')) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
108 let x = matchfuzzypos([repeat('a', 256)], repeat('a', 256)) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 call assert_equal(range(256), x[1][0]) |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
110 call assert_equal([[], [], []], matchfuzzypos([repeat('a', 300)], repeat('a', 257))) |
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
111 call assert_equal([[], [], []], matchfuzzypos([], 'abc')) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
112 |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
113 " match in a long string |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
114 call assert_equal([[repeat('x', 300) .. 'abc'], [[300, 301, 302]], [-135]], |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
115 \ matchfuzzypos([repeat('x', 300) .. 'abc'], 'abc')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 " preference for camel case match |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
118 call assert_equal([['xabcxxaBc'], [[6, 7, 8]], [189]], matchfuzzypos(['xabcxxaBc'], 'abc')) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
119 " preference for match after a separator (_ or space) |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
120 call assert_equal([['xabx_ab'], [[5, 6]], [145]], matchfuzzypos(['xabx_ab'], 'ab')) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
121 " preference for leading letter match |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
122 call assert_equal([['abcxabc'], [[0, 1]], [150]], matchfuzzypos(['abcxabc'], 'ab')) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
123 " preference for sequential match |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
124 call assert_equal([['aobncedone'], [[7, 8, 9]], [158]], matchfuzzypos(['aobncedone'], 'one')) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 " best recursive match |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
126 call assert_equal([['xoone'], [[2, 3, 4]], [168]], matchfuzzypos(['xoone'], 'one')) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
127 |
22689
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
128 " match multiple words (separated by space) |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
129 call assert_equal([['foo bar baz'], [[8, 9, 10, 0, 1, 2]], [369]], ['foo bar baz', 'foo', 'foo bar', 'baz bar']->matchfuzzypos('baz foo')) |
28831
b5c46d447518
patch 8.2.4939: matchfuzzypos() with "matchseq" does not have all positions
Bram Moolenaar <Bram@vim.org>
parents:
28471
diff
changeset
|
130 call assert_equal([[], [], []], ['foo bar baz', 'foo', 'foo bar', 'baz bar']->matchfuzzypos('baz foo', {'matchseq': 1})) |
b5c46d447518
patch 8.2.4939: matchfuzzypos() with "matchseq" does not have all positions
Bram Moolenaar <Bram@vim.org>
parents:
28471
diff
changeset
|
131 call assert_equal([['foo bar baz'], [[0, 1, 2, 8, 9, 10]], [369]], ['foo bar baz', 'foo', 'foo bar', 'baz bar']->matchfuzzypos('foo baz')) |
b5c46d447518
patch 8.2.4939: matchfuzzypos() with "matchseq" does not have all positions
Bram Moolenaar <Bram@vim.org>
parents:
28471
diff
changeset
|
132 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})) |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
133 call assert_equal([[], [], []], ['foo bar baz', 'foo', 'foo bar', 'baz bar']->matchfuzzypos('one two')) |
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
134 call assert_equal([[], [], []], ['foo bar']->matchfuzzypos(" \t ")) |
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
135 call assert_equal([['grace'], [[1, 2, 3, 4, 2, 3, 4, 0, 1, 2, 3, 4]], [657]], ['grace']->matchfuzzypos('race ace grace')) |
22689
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
136 |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
137 let l = [{'id' : 5, 'val' : 'crayon'}, {'id' : 6, 'val' : 'camera'}] |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
138 call assert_equal([[{'id' : 6, 'val' : 'camera'}], [[0, 1, 2]], [192]], |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
139 \ matchfuzzypos(l, 'cam', {'text_cb' : {v -> v.val}})) |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
140 call assert_equal([[{'id' : 6, 'val' : 'camera'}], [[0, 1, 2]], [192]], |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
141 \ matchfuzzypos(l, 'cam', {'key' : 'val'})) |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
142 call assert_equal([[], [], []], matchfuzzypos(l, 'day', {'text_cb' : {v -> v.val}})) |
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
143 call assert_equal([[], [], []], matchfuzzypos(l, 'day', {'key' : 'val'})) |
29994
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29375
diff
changeset
|
144 call assert_fails("let x = matchfuzzypos(l, 'cam', 'random')", 'E1206:') |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
145 call assert_equal([[], [], []], matchfuzzypos(l, 'day', {'text_cb' : {v -> []}})) |
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
146 call assert_equal([[], [], []], matchfuzzypos(l, 'day', {'text_cb' : {v -> 1}})) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
147 call assert_fails("let x = matchfuzzypos(l, 'day', {'text_cb' : {a, b -> 1}})", 'E119:') |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
148 call assert_equal([[], [], []], matchfuzzypos(l, 'cam')) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
149 call assert_fails("let x = matchfuzzypos(l, 'cam', {'text_cb' : []})", 'E921:') |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
150 call assert_fails("let x = matchfuzzypos(l, 'foo', {'key' : []})", 'E730:') |
29994
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29375
diff
changeset
|
151 call assert_fails("let x = matchfuzzypos(l, 'cam', test_null_dict())", 'E1297:') |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
152 call assert_fails("let x = matchfuzzypos(l, 'foo', {'key' : test_null_string()})", 'E475:') |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
153 call assert_fails("let x = matchfuzzypos(l, 'foo', {'text_cb' : test_null_function()})", 'E475:') |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
154 |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
155 let l = [{'id' : 5, 'name' : 'foo'}, {'id' : 6, 'name' : []}, {'id' : 7}] |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
156 call assert_fails("let x = matchfuzzypos(l, 'foo', {'key' : 'name'})", 'E730:') |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
157 endfunc |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
158 |
22689
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
159 " Test for matchfuzzy() with multibyte characters |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
160 func Test_matchfuzzy_mbyte() |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
161 CheckFeature multi_lang |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
162 call assert_equal(['ンヹㄇヺヴ'], matchfuzzy(['ンヹㄇヺヴ'], 'ヹヺ')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
163 " reverse the order of characters |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
164 call assert_equal([], matchfuzzy(['ンヹㄇヺヴ'], 'ヺヹ')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
165 call assert_equal(['αβΩxxx', 'xαxβxΩx'], |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
166 \ matchfuzzy(['αβΩxxx', 'xαxβxΩx'], 'αβΩ')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
167 call assert_equal(['ππbbππ', 'πππbbbπππ', 'ππππbbbbππππ', 'πbπ'], |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
168 \ matchfuzzy(['πbπ', 'ππbbππ', 'πππbbbπππ', 'ππππbbbbππππ'], 'ππ')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
169 |
22689
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
170 " match multiple words (separated by space) |
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
171 call assert_equal(['세 마리의 작은 돼지'], ['세 마리의 작은 돼지', '마리의', '마리의 작은', '작은 돼지']->matchfuzzy('돼지 마리의')) |
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
172 call assert_equal([], ['세 마리의 작은 돼지', '마리의', '마리의 작은', '작은 돼지']->matchfuzzy('파란 하늘')) |
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
173 |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
174 " preference for camel case match |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
175 call assert_equal(['oneĄwo', 'oneąwo'], |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
176 \ ['oneąwo', 'oneĄwo']->matchfuzzy('oneąwo')) |
22647
0dd527d9c62d
patch 8.2.1872: matchfuzzy() does not prefer sequential matches
Bram Moolenaar <Bram@vim.org>
parents:
22355
diff
changeset
|
177 " preference for complete match then match after separator (_ or space) |
22689
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
178 call assert_equal(['ⅠⅡabㄟㄠ'] + sort(['ⅠⅡa_bㄟㄠ', 'ⅠⅡa bㄟㄠ']), |
22647
0dd527d9c62d
patch 8.2.1872: matchfuzzy() does not prefer sequential matches
Bram Moolenaar <Bram@vim.org>
parents:
22355
diff
changeset
|
179 \ ['ⅠⅡabㄟㄠ', 'ⅠⅡa bㄟㄠ', 'ⅠⅡa_bㄟㄠ']->matchfuzzy('ⅠⅡabㄟㄠ')) |
22689
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
180 " preference for match after a separator (_ or space) |
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
181 call assert_equal(['ㄓㄔabㄟㄠ', 'ㄓㄔa_bㄟㄠ', 'ㄓㄔa bㄟㄠ'], |
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
182 \ ['ㄓㄔa_bㄟㄠ', 'ㄓㄔa bㄟㄠ', 'ㄓㄔabㄟㄠ']->matchfuzzy('ㄓㄔabㄟㄠ')) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
183 " preference for leading letter match |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
184 call assert_equal(['ŗŝţũŵż', 'xŗŝţũŵż'], |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
185 \ ['xŗŝţũŵż', 'ŗŝţũŵż']->matchfuzzy('ŗŝţũŵż')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
186 " preference for sequential match |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
187 call assert_equal(['ㄞㄡㄤfffifl', 'ㄞaㄡbㄤcffdfiefl'], |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
188 \ ['ㄞaㄡbㄤcffdfiefl', 'ㄞㄡㄤfffifl']->matchfuzzy('ㄞㄡㄤfffifl')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
189 " non-matching leading letter(s) penalty |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
190 call assert_equal(['xㄞㄡㄤfffifl', 'xxㄞㄡㄤfffifl'], |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
191 \ ['xxㄞㄡㄤfffifl', 'xㄞㄡㄤfffifl']->matchfuzzy('ㄞㄡㄤfffifl')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
192 " total non-matching letter(s) penalty |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
193 call assert_equal(['ŗŝţ', 'ŗŝţx', 'ŗŝţxx'], |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
194 \ ['ŗŝţxx', 'ŗŝţ', 'ŗŝţx']->matchfuzzy('ŗŝţ')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
195 endfunc |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
196 |
22689
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
197 " Test for matchfuzzypos() with multibyte characters |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
198 func Test_matchfuzzypos_mbyte() |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
199 CheckFeature multi_lang |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
200 call assert_equal([['こんにちは世界'], [[0, 1, 2, 3, 4]], [273]], |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
201 \ matchfuzzypos(['こんにちは世界'], 'こんにちは')) |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
202 call assert_equal([['ンヹㄇヺヴ'], [[1, 3]], [88]], matchfuzzypos(['ンヹㄇヺヴ'], 'ヹヺ')) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
203 " reverse the order of characters |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
204 call assert_equal([[], [], []], matchfuzzypos(['ンヹㄇヺヴ'], 'ヺヹ')) |
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
205 call assert_equal([['αβΩxxx', 'xαxβxΩx'], [[0, 1, 2], [1, 3, 5]], [222, 113]], |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
206 \ matchfuzzypos(['αβΩxxx', 'xαxβxΩx'], 'αβΩ')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
207 call assert_equal([['ππbbππ', 'πππbbbπππ', 'ππππbbbbππππ', 'πbπ'], |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
208 \ [[0, 1], [0, 1], [0, 1], [0, 2]], [151, 148, 145, 110]], |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
209 \ matchfuzzypos(['πbπ', 'ππbbππ', 'πππbbbπππ', 'ππππbbbbππππ'], 'ππ')) |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
210 call assert_equal([['ααααααα'], [[0, 1, 2]], [191]], |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
211 \ matchfuzzypos(['ααααααα'], 'ααα')) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
212 |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
213 call assert_equal([[], [], []], matchfuzzypos(['ンヹㄇ', 'ŗŝţ'], 'fffifl')) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
214 let x = matchfuzzypos([repeat('Ψ', 256)], repeat('Ψ', 256)) |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
215 call assert_equal(range(256), x[1][0]) |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
216 call assert_equal([[], [], []], matchfuzzypos([repeat('✓', 300)], repeat('✓', 257))) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
217 |
22689
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
218 " match multiple words (separated by space) |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
219 call assert_equal([['세 마리의 작은 돼지'], [[9, 10, 2, 3, 4]], [328]], ['세 마리의 작은 돼지', '마리의', '마리의 작은', '작은 돼지']->matchfuzzypos('돼지 마리의')) |
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
220 call assert_equal([[], [], []], ['세 마리의 작은 돼지', '마리의', '마리의 작은', '작은 돼지']->matchfuzzypos('파란 하늘')) |
22689
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
221 |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
222 " match in a long string |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
223 call assert_equal([[repeat('ぶ', 300) .. 'ẼẼẼ'], [[300, 301, 302]], [-135]], |
22689
f8bf2c122452
patch 8.2.1893: fuzzy matching does not support multiple words
Bram Moolenaar <Bram@vim.org>
parents:
22647
diff
changeset
|
224 \ matchfuzzypos([repeat('ぶ', 300) .. 'ẼẼẼ'], 'ẼẼẼ')) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
225 " preference for camel case match |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
226 call assert_equal([['xѳѵҁxxѳѴҁ'], [[6, 7, 8]], [189]], matchfuzzypos(['xѳѵҁxxѳѴҁ'], 'ѳѵҁ')) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
227 " preference for match after a separator (_ or space) |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
228 call assert_equal([['xちだx_ちだ'], [[5, 6]], [145]], matchfuzzypos(['xちだx_ちだ'], 'ちだ')) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
229 " preference for leading letter match |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
230 call assert_equal([['ѳѵҁxѳѵҁ'], [[0, 1]], [150]], matchfuzzypos(['ѳѵҁxѳѵҁ'], 'ѳѵ')) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
231 " preference for sequential match |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
232 call assert_equal([['aンbヹcㄇdンヹㄇ'], [[7, 8, 9]], [158]], matchfuzzypos(['aンbヹcㄇdンヹㄇ'], 'ンヹㄇ')) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
233 " best recursive match |
23475
79fd5217b125
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Bram Moolenaar <Bram@vim.org>
parents:
22746
diff
changeset
|
234 call assert_equal([['xффйд'], [[2, 3, 4]], [168]], matchfuzzypos(['xффйд'], 'фйд')) |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
235 endfunc |
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
236 |
28471
2ade724b3f45
patch 8.2.4760: using matchfuzzy() on a long list can take a while
Bram Moolenaar <Bram@vim.org>
parents:
23475
diff
changeset
|
237 " Test for matchfuzzy() with limit |
2ade724b3f45
patch 8.2.4760: using matchfuzzy() on a long list can take a while
Bram Moolenaar <Bram@vim.org>
parents:
23475
diff
changeset
|
238 func Test_matchfuzzy_limit() |
2ade724b3f45
patch 8.2.4760: using matchfuzzy() on a long list can take a while
Bram Moolenaar <Bram@vim.org>
parents:
23475
diff
changeset
|
239 let x = ['1', '2', '3', '2'] |
2ade724b3f45
patch 8.2.4760: using matchfuzzy() on a long list can take a while
Bram Moolenaar <Bram@vim.org>
parents:
23475
diff
changeset
|
240 call assert_equal(['2', '2'], x->matchfuzzy('2')) |
2ade724b3f45
patch 8.2.4760: using matchfuzzy() on a long list can take a while
Bram Moolenaar <Bram@vim.org>
parents:
23475
diff
changeset
|
241 call assert_equal(['2', '2'], x->matchfuzzy('2', #{})) |
2ade724b3f45
patch 8.2.4760: using matchfuzzy() on a long list can take a while
Bram Moolenaar <Bram@vim.org>
parents:
23475
diff
changeset
|
242 call assert_equal(['2', '2'], x->matchfuzzy('2', #{limit: 0})) |
2ade724b3f45
patch 8.2.4760: using matchfuzzy() on a long list can take a while
Bram Moolenaar <Bram@vim.org>
parents:
23475
diff
changeset
|
243 call assert_equal(['2'], x->matchfuzzy('2', #{limit: 1})) |
2ade724b3f45
patch 8.2.4760: using matchfuzzy() on a long list can take a while
Bram Moolenaar <Bram@vim.org>
parents:
23475
diff
changeset
|
244 call assert_equal(['2', '2'], x->matchfuzzy('2', #{limit: 2})) |
2ade724b3f45
patch 8.2.4760: using matchfuzzy() on a long list can take a while
Bram Moolenaar <Bram@vim.org>
parents:
23475
diff
changeset
|
245 call assert_equal(['2', '2'], x->matchfuzzy('2', #{limit: 3})) |
2ade724b3f45
patch 8.2.4760: using matchfuzzy() on a long list can take a while
Bram Moolenaar <Bram@vim.org>
parents:
23475
diff
changeset
|
246 call assert_fails("call matchfuzzy(x, '2', #{limit: '2'})", 'E475:') |
29194
f92f658585e6
patch 8.2.5116: "limit" option of matchfuzzy() not always respected
Bram Moolenaar <Bram@vim.org>
parents:
28831
diff
changeset
|
247 |
f92f658585e6
patch 8.2.5116: "limit" option of matchfuzzy() not always respected
Bram Moolenaar <Bram@vim.org>
parents:
28831
diff
changeset
|
248 let l = [{'id': 5, 'val': 'crayon'}, {'id': 6, 'val': 'camera'}] |
f92f658585e6
patch 8.2.5116: "limit" option of matchfuzzy() not always respected
Bram Moolenaar <Bram@vim.org>
parents:
28831
diff
changeset
|
249 call assert_equal([{'id': 5, 'val': 'crayon'}, {'id': 6, 'val': 'camera'}], l->matchfuzzy('c', #{text_cb: {v -> v.val}})) |
f92f658585e6
patch 8.2.5116: "limit" option of matchfuzzy() not always respected
Bram Moolenaar <Bram@vim.org>
parents:
28831
diff
changeset
|
250 call assert_equal([{'id': 5, 'val': 'crayon'}, {'id': 6, 'val': 'camera'}], l->matchfuzzy('c', #{key: 'val'})) |
f92f658585e6
patch 8.2.5116: "limit" option of matchfuzzy() not always respected
Bram Moolenaar <Bram@vim.org>
parents:
28831
diff
changeset
|
251 call assert_equal([{'id': 5, 'val': 'crayon'}, {'id': 6, 'val': 'camera'}], l->matchfuzzy('c', #{text_cb: {v -> v.val}, limit: 0})) |
f92f658585e6
patch 8.2.5116: "limit" option of matchfuzzy() not always respected
Bram Moolenaar <Bram@vim.org>
parents:
28831
diff
changeset
|
252 call assert_equal([{'id': 5, 'val': 'crayon'}, {'id': 6, 'val': 'camera'}], l->matchfuzzy('c', #{key: 'val', limit: 0})) |
f92f658585e6
patch 8.2.5116: "limit" option of matchfuzzy() not always respected
Bram Moolenaar <Bram@vim.org>
parents:
28831
diff
changeset
|
253 call assert_equal([{'id': 5, 'val': 'crayon'}], l->matchfuzzy('c', #{text_cb: {v -> v.val}, limit: 1})) |
f92f658585e6
patch 8.2.5116: "limit" option of matchfuzzy() not always respected
Bram Moolenaar <Bram@vim.org>
parents:
28831
diff
changeset
|
254 call assert_equal([{'id': 5, 'val': 'crayon'}], l->matchfuzzy('c', #{key: 'val', limit: 1})) |
28471
2ade724b3f45
patch 8.2.4760: using matchfuzzy() on a long list can take a while
Bram Moolenaar <Bram@vim.org>
parents:
23475
diff
changeset
|
255 endfunc |
2ade724b3f45
patch 8.2.4760: using matchfuzzy() on a long list can take a while
Bram Moolenaar <Bram@vim.org>
parents:
23475
diff
changeset
|
256 |
32335
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
257 " This was using uninitialized memory |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
258 func Test_matchfuzzy_initialized() |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
259 CheckRunVimInTerminal |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
260 |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
261 " This can take a very long time (esp. when using valgrind). Run in a |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
262 " separate Vim instance and kill it after two seconds. We only check for |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
263 " memory errors. |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
264 let lines =<< trim END |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
265 lvimgrep [ss [fg* |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
266 END |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
267 call writefile(lines, 'XTest_matchfuzzy', 'D') |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
268 |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
269 let buf = RunVimInTerminal('-u NONE -X -Z', {}) |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
270 call term_sendkeys(buf, ":source XTest_matchfuzzy\n") |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
271 call TermWait(buf, 2000) |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
272 |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
273 let job = term_getjob(buf) |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
274 if job_status(job) == "run" |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
275 call job_stop(job, "int") |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
276 call TermWait(buf, 50) |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
277 endif |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
278 |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
279 " clean up |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
280 call StopVimInTerminal(buf) |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
281 endfunc |
9c034274034b
patch 9.0.1499: using uninitialized memory with fuzzy matching
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
282 |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
283 " vim: shiftwidth=2 sts=2 expandtab |