# Test resolution of as many link types as possible in Markdown syntax

# This relies on the line numbers for each type of link in link_syntax.md and
# link_syntax/nested.md, which seems primitive, but does seem to work.

# Links in a top-level page {{{

Execute (Assure link_syntax.md exists):
  Log "Testing links in a top-level page with native syntax."
  VimwikiIndex 2
  VimwikiGoto link_syntax
  AssertEqual $HOME . '/testmarkdown/link_syntax.md', expand('%')

Do (Check plain wiki page link to index):
  :VimwikiIndex 2\<CR>
  :VimwikiGoto link_syntax\<CR>
  :1\<CR>
  \<CR>
  :AssertEqual $HOME . '/testmarkdown/index.md', expand('%')\<CR>

Do (Check absolute-in-wiki page link to index with leading slash):
  :VimwikiIndex 2\<CR>
  :VimwikiGoto link_syntax\<CR>
  :2\<CR>
  \<CR>
  :AssertEqual $HOME . '/testmarkdown/index.md', expand('%')\<CR>

# //foo "absolute" links - these are also checked in link_generation.vader:
Do (Check absolute-on-filesystem page link to /tmp/some_page with 2 leading slashes):
  :VimwikiIndex 2\<CR>
  :VimwikiGoto link_syntax\<CR>
  :3\<CR>
  \<CR>
  :AssertEqual '/tmp/some_page.md', expand('%')\<CR>

Do (Check absolute-on-filesystem page link to index using tilde for homedir):
  :VimwikiIndex 2\<CR>
  :VimwikiGoto link_syntax\<CR>
  :4\<CR>
  \<CR>
  :AssertEqual $HOME . '/testmarkdown/index.md', expand('%')\<CR>

Do (Check diary link):
  :VimwikiIndex 2\<CR>
  :VimwikiGoto link_syntax\<CR>
  :5\<CR>
  \<CR>
  :AssertEqual $HOME . '/testmarkdown/diary/2020-07-22.md', expand('%')\<CR>

Do (Check link to nested page):
  :VimwikiIndex 2\<CR>
  :VimwikiGoto link_syntax\<CR>
  :6\<CR>
  \<CR>
  :AssertEqual $HOME . '/testmarkdown/link_syntax/nested.md', expand('%')\<CR>

Do (Check relative link to nested page with ./link_syntax/nested):
  :VimwikiIndex 2\<CR>
  :VimwikiGoto link_syntax\<CR>
  :7\<CR>
  \<CR>
  :AssertEqual $HOME . '/testmarkdown/link_syntax/nested.md', expand('%')\<CR>

# }}}

# Links in a nested file {{{

Execute (Assure link_syntax/nested.md exists):
  Log "Testing links in a nested page with native syntax."
  VimwikiIndex 2
  VimwikiGoto link_syntax/nested
  AssertEqual $HOME . '/testmarkdown/link_syntax/nested.md', expand('%')

Do (Nested: Check plain wiki page link to self - link_syntax/nested.md):
  :VimwikiIndex 2\<CR>
  :VimwikiGoto link_syntax/nested\<CR>
  :1\<CR>
  \<CR>
  :AssertEqual $HOME . '/testmarkdown/link_syntax/nested.md', expand('%')\<CR>

Do (Nested: Check absolute-in-wiki page link to index with leading slash):
  :VimwikiIndex 2\<CR>
  :VimwikiGoto link_syntax/nested\<CR>
  :2\<CR>
  \<CR>
  :AssertEqual $HOME . '/testmarkdown/index.md', expand('%')\<CR>

# //foo "absolute" links - these are also checked in link_generation.vader:
Do (Nested: Check absolute-on-filesystem page link to /tmp/some_page with 2 leading slashes):
  :VimwikiIndex 2\<CR>
  :VimwikiGoto link_syntax/nested\<CR>
  :3\<CR>
  \<CR>
  :AssertEqual '/tmp/some_page.md', expand('%')\<CR>

Do (Nested: Check absolute-on-filesystem page link to index using tilde for homedir):
  :VimwikiIndex 2\<CR>
  :VimwikiGoto link_syntax/nested\<CR>
  :4\<CR>
  \<CR>
  :AssertEqual $HOME . '/testmarkdown/index.md', expand('%')\<CR>

Do (Nested: Check diary link):
  :VimwikiIndex 2\<CR>
  :VimwikiGoto link_syntax/nested\<CR>
  :5\<CR>
  \<CR>
  :AssertEqual $HOME . '/testmarkdown/diary/2020-07-22.md', expand('%')\<CR>

Do (Nested: Check relative link to page in parent directory):
  :VimwikiIndex 2\<CR>
  :VimwikiGoto link_syntax/nested\<CR>
  :6\<CR>
  \<CR>
  :AssertEqual $HOME . '/testmarkdown/link_syntax.md', expand('%')\<CR>

# }}}

# To be perfectly honest I don't know why or if this is necessary, but without
# it I was getting leftover tabs for the last file visited here. -- brennen
Execute (Clean):
  call ReloadVimwiki()
