test_completion_filtering.vader
1 Before: 2 Save g:ale_completion_excluded_words 3 4 let g:ale_completion_excluded_words = [] 5 6 After: 7 Restore 8 9 unlet! b:ale_completion_excluded_words 10 unlet! b:suggestions 11 12 Execute(Prefix filtering should work for Lists of strings): 13 AssertEqual 14 \ ['FooBar', 'foo'], 15 \ ale#completion#Filter(bufnr(''), '', ['FooBar', 'FongBar', 'baz', 'foo'], 'foo', 0) 16 AssertEqual 17 \ ['FooBar', 'FongBar', 'baz', 'foo'], 18 \ ale#completion#Filter(bufnr(''), '', ['FooBar', 'FongBar', 'baz', 'foo'], '.', 0) 19 AssertEqual 20 \ ['FooBar', 'FongBar', 'baz', 'foo'], 21 \ ale#completion#Filter(bufnr(''), '', ['FooBar', 'FongBar', 'baz', 'foo'], '', 0) 22 23 Execute(Exact filtering should work): 24 AssertEqual 25 \ ['foo'], 26 \ ale#completion#Filter(bufnr(''), '', ['FooBar', 'FongBar', 'baz', 'foo'], 'foo', 1) 27 AssertEqual 28 \ ['FooBar', 'FongBar', 'baz', 'foo'], 29 \ ale#completion#Filter(bufnr(''), '', ['FooBar', 'FongBar', 'baz', 'foo'], '.', 1) 30 AssertEqual 31 \ ['Foo'], 32 \ ale#completion#Filter(bufnr(''), '', ['FooBar', 'FongBar', 'Foo', 'foo'], 'Foo', 1) 33 34 Execute(Prefix filtering should work for completion items): 35 AssertEqual 36 \ [{'word': 'FooBar'}, {'word': 'foo'}], 37 \ ale#completion#Filter( 38 \ bufnr(''), 39 \ '', 40 \ [ 41 \ {'word': 'FooBar'}, 42 \ {'word': 'FongBar'}, 43 \ {'word': 'baz'}, 44 \ {'word': 'foo'}, 45 \ ], 46 \ 'foo', 47 \ 0, 48 \ ) 49 50 AssertEqual 51 \ [ 52 \ {'word': 'FooBar'}, 53 \ {'word': 'FongBar'}, 54 \ {'word': 'baz'}, 55 \ {'word': 'foo'}, 56 \ ], 57 \ ale#completion#Filter( 58 \ bufnr(''), 59 \ '', 60 \ [ 61 \ {'word': 'FooBar'}, 62 \ {'word': 'FongBar'}, 63 \ {'word': 'baz'}, 64 \ {'word': 'foo'}, 65 \ ], 66 \ '.', 67 \ 0, 68 \ ) 69 70 Execute(Excluding words from completion results should work): 71 let b:ale_completion_excluded_words = ['it', 'describe'] 72 73 AssertEqual 74 \ [{'word': 'Italian'}], 75 \ ale#completion#Filter( 76 \ bufnr(''), 77 \ '', 78 \ [ 79 \ {'word': 'Italian'}, 80 \ {'word': 'it'}, 81 \ ], 82 \ 'it', 83 \ 0, 84 \ ) 85 86 AssertEqual 87 \ [{'word': 'Deutsch'}], 88 \ ale#completion#Filter( 89 \ bufnr(''), 90 \ '', 91 \ [ 92 \ {'word': 'describe'}, 93 \ {'word': 'Deutsch'}, 94 \ ], 95 \ 'de', 96 \ 0, 97 \ ) 98 99 AssertEqual 100 \ [{'word': 'Deutsch'}], 101 \ ale#completion#Filter( 102 \ bufnr(''), 103 \ '', 104 \ [ 105 \ {'word': 'describe'}, 106 \ {'word': 'Deutsch'}, 107 \ ], 108 \ '.', 109 \ 0, 110 \ ) 111 112 Execute(Excluding words from completion results should work with lists of Strings): 113 let b:ale_completion_excluded_words = ['it', 'describe'] 114 115 AssertEqual 116 \ ['Italian'], 117 \ ale#completion#Filter(bufnr(''), '', ['Italian', 'it'], 'it', 0) 118 AssertEqual 119 \ ['Deutsch'], 120 \ ale#completion#Filter(bufnr(''), '', ['describe', 'Deutsch'], 'de', 0) 121 AssertEqual 122 \ ['Deutsch'], 123 \ ale#completion#Filter(bufnr(''), '', ['describe', 'Deutsch'], '.', 0) 124 AssertEqual 125 \ ['Deutsch'], 126 \ ale#completion#Filter(bufnr(''), '', ['Deutsch'], '', 0) 127 128 Execute(Filtering shouldn't modify the original list): 129 let b:ale_completion_excluded_words = ['it', 'describe'] 130 let b:suggestions = [{'word': 'describe'}] 131 132 AssertEqual [], ale#completion#Filter(bufnr(''), '', b:suggestions, '.', 0) 133 AssertEqual b:suggestions, [{'word': 'describe'}] 134 AssertEqual [], ale#completion#Filter(bufnr(''), '', b:suggestions, 'de', 0) 135 AssertEqual b:suggestions, [{'word': 'describe'}] 136 137 Execute(Filtering should respect filetype triggers): 138 let b:suggestions = [{'word': 'describe'}] 139 140 AssertEqual b:suggestions, ale#completion#Filter(bufnr(''), '', b:suggestions, '.', 0) 141 AssertEqual b:suggestions, ale#completion#Filter(bufnr(''), 'rust', b:suggestions, '.', 0) 142 AssertEqual b:suggestions, ale#completion#Filter(bufnr(''), 'rust', b:suggestions, '::', 0)