]> git.madduck.net Git - etc/vim.git/blob - test/test_loclist_binary_search.vader

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / test / test_loclist_binary_search.vader
1 Before:
2   let g:loclist = [
3   \ {'bufnr': 1, 'lnum': 2, 'col': 10},
4   \ {'bufnr': 1, 'lnum': 3, 'col': 2},
5   \ {'bufnr': 1, 'lnum': 3, 'col': 10},
6   \ {'bufnr': 1, 'lnum': 3, 'col': 12},
7   \ {'bufnr': 1, 'lnum': 3, 'col': 25},
8   \ {'bufnr': 1, 'lnum': 5, 'col': 4},
9   \ {'bufnr': 1, 'lnum': 5, 'col': 5},
10   \ {'bufnr': 1, 'lnum': 9, 'col': 5},
11   \ {'bufnr': 1, 'lnum': 10, 'col': 1},
12   \ {'bufnr': 2, 'lnum': 7, 'col': 10},
13   \ {'bufnr': 2, 'lnum': 9, 'col': 2},
14   \ {'bufnr': 2, 'lnum': 10, 'col': 2},
15   \ {'bufnr': 2, 'lnum': 11, 'col': 2},
16   \]
17
18 After:
19   unlet g:loclist
20
21 Execute(Exact column matches should be correct):
22   AssertEqual 1, ale#util#BinarySearch(g:loclist, 1, 3, 2)
23
24 Execute(Off lines, there should be no match):
25   AssertEqual -1, ale#util#BinarySearch(g:loclist, 1, 4, 2)
26
27 Execute(Near column matches should be taken):
28   AssertEqual 2, ale#util#BinarySearch(g:loclist, 1, 3, 11)
29   AssertEqual 3, ale#util#BinarySearch(g:loclist, 1, 3, 13)
30
31 Execute(Columns before should be taken when the cursor is far ahead):
32   AssertEqual 4, ale#util#BinarySearch(g:loclist, 1, 3, 300)
33
34 Execute(The only problems on lines in later columns should be matched):
35   AssertEqual 7, ale#util#BinarySearch(g:loclist, 1, 9, 1)
36
37 Execute(The only problems on lines in earlier columns should be matched):
38   AssertEqual 8, ale#util#BinarySearch(g:loclist, 1, 10, 30)
39
40 Execute(Lines for other buffers should not be matched):
41   AssertEqual -1, ale#util#BinarySearch(g:loclist, 1, 7, 10)
42
43 Execute(Searches for buffers later in the list should work):
44   AssertEqual 10, ale#util#BinarySearch(g:loclist, 2, 9, 10)
45
46 Execute(Searches should work with just one item):
47   let g:loclist = [{'bufnr': 1, 'lnum': 3, 'col': 10}]
48
49   AssertEqual 0, ale#util#BinarySearch(g:loclist, 1, 3, 2)
50
51 Execute(Searches should return the last item on a single column):
52   let g:loclist = [
53   \ {'bufnr': 1, 'lnum': 1, 'col': 10, 'type': 'W'},
54   \ {'bufnr': 1, 'lnum': 1, 'col': 10, 'type': 'E'},
55   \ {'bufnr': 1, 'lnum': 1, 'col': 11, 'type': 'W'},
56   \ {'bufnr': 1, 'lnum': 1, 'col': 11, 'type': 'E'},
57   \ {'bufnr': 1, 'lnum': 1, 'col': 20, 'type': 'W'},
58   \ {'bufnr': 1, 'lnum': 1, 'col': 20, 'type': 'E'},
59   \]
60
61   " We should return the index for the last item at some column to the right.
62   AssertEqual 1, ale#util#BinarySearch(g:loclist, 1, 1, 1)
63   " We should return the index for the last item at the column we are on.
64   AssertEqual 3, ale#util#BinarySearch(g:loclist, 1, 1, 11)
65   " We should prefer items to the left of the cursor, over the right.
66   AssertEqual 3, ale#util#BinarySearch(g:loclist, 1, 1, 19)