File: search.vader

package info (click to toggle)
vim-vimwiki 2024.01.24-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,692 kB
  • sloc: sh: 313; makefile: 2
file content (73 lines) | stat: -rw-r--r-- 2,808 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
Execute (Setup search testing wrapper):
  function! TestSearch(search_command, test_name)
    " Note: after each search, the location list of the current window (0)
    " will contain the search results. A non-empty list indicates success.
    " Search for a single word (a pattern with no spaces)
    if v:version < 704
      Log 'Cheating for old vim version, do not want to reverse bug'
      return
    endif

    " Execute command and grab output
    redir => output
    silent execute a:search_command
    redir END

    " The location list should not be empty
    Assert !empty(getloclist(0)), a:test_name.": no location list result"

    " The location list should contains entries
    Assert match(output, '\d of \d') > -1, a:test_name.": no result message"

    " Tests that VimwikiSearch is quoting the pattern correctly.
    " If not, Vim will see anything after the first space in the pattern
    " as a file name and attempt to open it.
    Assert match(output, 'Cannot open file') == -1, "'open file': unquoted pattern?"

    return output
  endfunction

Execute (Search test wiki):
  " Open test wiki
  edit test/resources/testwiki/index.wiki

  " Make sure we opened the test wiki successfully by checking the
  " title (first line) and filetype.
  AssertEqual "= Test Wiki =", getline(1)
  AssertEqual "vimwiki", &filetype

  call TestSearch('VimwikiSearch foo',        'pattern with no spaces')
  call TestSearch('VimwikiSearch foo bar',    'pattern with spaces')
  call TestSearch('VimwikiSearch foo\bar',    'pattern with ''\''')
  call TestSearch('VimwikiSearch baz{13}',    'pattern with literal {}')
  call TestSearch('VimwikiSearch /\vbuz{5}/', 'proper regex')
  call TestSearch('VWS foo bar',              'use VWS abbreviation')

Execute (Search space path wiki):
  " Open wiki with spaces in path to test fname escaping
  edit test/resources/testwiki\ space/index.wiki

  " Make sure we opened the space path wiki successfully
  AssertEqual "= Space Path Wiki =", getline(1)

  call TestSearch('VimwikiSearch foo', 'simple search in space path wiki')

Execute (Search failure message):
  " Important note: No search tests will succeed after this.
  " The failed search will cause a Vim error to be thrown and
  " any search with lvimgrep within Vader will result in an
  " empty location list and empty messages queue. It is
  " difficult to tell if the search itself is failing or if it
  " is just an inability to view the results.

  " Open test wiki again
  edit test/resources/testwiki/index.wiki

  " Now test a negative search and make sure we are returning
  " the expected VimWiki error.
  redir => output
  silent VimwikiSearch not_exist
  redir END
  if v:version > 703
    Assert match(output, 'Vimwiki: Search: No match found.') > -1, "expected custom error"
  endif