My dotfiles. Period.

path.vim 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. "=============================================================================
  2. " $Id: path.vim 520 2012-03-19 18:09:15Z luc.hermitte $
  3. " File: tests/lh/path.vim {{{1
  4. " Author: Luc Hermitte <EMAIL:hermitte {at} free {dot} fr>
  5. " <URL:http://code.google.com/p/lh-vim/>
  6. " License: GPLv3 with exceptions
  7. " <URL:http://code.google.com/p/lh-vim/wiki/License>
  8. " Version: 3.0.0
  9. " Created: 28th May 2009
  10. " Last Update: $Date: 2012-03-19 19:09:15 +0100 (Mon, 19 Mar 2012) $
  11. "------------------------------------------------------------------------
  12. " Description:
  13. " Tests for autoload/lh/path.vim
  14. "
  15. "------------------------------------------------------------------------
  16. " Installation: «install details»
  17. " History: «history»
  18. " TODO: «missing features»
  19. " }}}1
  20. "=============================================================================
  21. UTSuite [lh-vim-lib] Testing lh#path functions
  22. runtime autoload/lh/path.vim
  23. let s:cpo_save=&cpo
  24. set cpo&vim
  25. "------------------------------------------------------------------------
  26. function! s:Test_simplify()
  27. Assert lh#path#simplify('a/b/c') == 'a/b/c'
  28. Assert lh#path#simplify('a/b/./c') == 'a/b/c'
  29. Assert lh#path#simplify('./a/b/./c') == 'a/b/c'
  30. Assert lh#path#simplify('./a/../b/./c') == 'b/c'
  31. Assert lh#path#simplify('../a/../b/./c') == '../b/c'
  32. Assert lh#path#simplify('a\b\c') == 'a\b\c'
  33. Assert lh#path#simplify('a\b\.\c') == 'a\b\c'
  34. Assert lh#path#simplify('.\a\b\.\c') == 'a\b\c'
  35. if exists('+shellslash')
  36. Assert lh#path#simplify('.\a\..\b\.\c') == 'b\c'
  37. Assert lh#path#simplify('..\a\..\b\.\c') == '..\b\c'
  38. endif
  39. endfunction
  40. function! s:Test_strip_common()
  41. let paths = ['foo/bar/file', 'foo/file', 'foo/foo/file']
  42. let expected = [ 'bar/file', 'file', 'foo/file']
  43. Assert lh#path#strip_common(paths) == expected
  44. endfunction
  45. function! s:Test_common()
  46. " Pick one ...
  47. Assert 'foo/' == lh#path#common(['foo/bar/dir', 'foo'])
  48. Assert 'foo/bar/' == lh#path#common(['foo/bar/dir', 'foo/bar'])
  49. Assert 'foo/' == lh#path#common(['foo/bar/dir', 'foo/bar2'])
  50. Assert 'foo' == lh#path#common(['foo/bar/dir', 'foo'])
  51. Assert 'foo/bar' == lh#path#common(['foo/bar/dir', 'foo/bar'])
  52. Assert 'foo' == lh#path#common(['foo/bar/dir', 'foo/bar2'])
  53. endfunction
  54. function! s:Test_strip_start()
  55. let expected = 'template/bar.template'
  56. Assert lh#path#strip_start($HOME.'/.vim/template/bar.template',
  57. \ [ $HOME.'/.vim', $HOME.'/vimfiles', '/usr/local/share/vim' ])
  58. \ == expected
  59. Assert lh#path#strip_start($HOME.'/vimfiles/template/bar.template',
  60. \ [ $HOME.'/.vim', $HOME.'/vimfiles', '/usr/local/share/vim' ])
  61. \ == expected
  62. Assert lh#path#strip_start('/usr/local/share/vim/template/bar.template',
  63. \ [ $HOME.'/.vim', $HOME.'/vimfiles', '/usr/local/share/vim' ])
  64. \ == expected
  65. endfunction
  66. function! s:Test_IsAbsolutePath()
  67. " nix paths
  68. Assert lh#path#is_absolute_path('/usr/local')
  69. Assert lh#path#is_absolute_path($HOME)
  70. Assert ! lh#path#is_absolute_path('./usr/local')
  71. Assert ! lh#path#is_absolute_path('.usr/local')
  72. " windows paths
  73. Assert lh#path#is_absolute_path('e:\usr\local')
  74. Assert ! lh#path#is_absolute_path('.\usr\local')
  75. Assert ! lh#path#is_absolute_path('.usr\local')
  76. " UNC paths
  77. Assert lh#path#is_absolute_path('\\usr\local')
  78. Assert lh#path#is_absolute_path('//usr/local')
  79. endfunction
  80. function! s:Test_IsURL()
  81. " nix paths
  82. Assert ! lh#path#is_url('/usr/local')
  83. Assert ! lh#path#is_url($HOME)
  84. Assert ! lh#path#is_url('./usr/local')
  85. Assert ! lh#path#is_url('.usr/local')
  86. " windows paths
  87. Assert ! lh#path#is_url('e:\usr\local')
  88. Assert ! lh#path#is_url('.\usr\local')
  89. Assert ! lh#path#is_url('.usr\local')
  90. " UNC paths
  91. Assert ! lh#path#is_url('\\usr\local')
  92. Assert ! lh#path#is_url('//usr/local')
  93. " URLs
  94. Assert lh#path#is_url('http://www.usr/local')
  95. Assert lh#path#is_url('https://www.usr/local')
  96. Assert lh#path#is_url('ftp://www.usr/local')
  97. Assert lh#path#is_url('sftp://www.usr/local')
  98. Assert lh#path#is_url('dav://www.usr/local')
  99. Assert lh#path#is_url('fetch://www.usr/local')
  100. Assert lh#path#is_url('file://www.usr/local')
  101. Assert lh#path#is_url('rcp://www.usr/local')
  102. Assert lh#path#is_url('rsynch://www.usr/local')
  103. Assert lh#path#is_url('scp://www.usr/local')
  104. endfunction
  105. function! s:Test_ToRelative()
  106. let pwd = getcwd()
  107. Assert lh#path#to_relative(pwd.'/foo/bar') == 'foo/bar'
  108. Assert lh#path#to_relative(pwd.'/./foo') == 'foo'
  109. Assert lh#path#to_relative(pwd.'/foo/../bar') == 'bar'
  110. " Does not work yet as it returns an absolute path it that case
  111. Assert lh#path#to_relative(pwd.'/../bar') == '../bar'
  112. endfunction
  113. function! s:Test_relative_path()
  114. Assert lh#path#relative_to('foo/bar/dir', 'foo') == '../../'
  115. Assert lh#path#relative_to('foo', 'foo/bar/dir') == 'bar/dir/'
  116. Assert lh#path#relative_to('foo/bar', 'foo/bar2/dir') == '../bar2/dir/'
  117. let pwd = getcwd()
  118. Assert lh#path#relative_to(pwd ,pwd.'/../bar') == '../bar/'
  119. endfunction
  120. function! s:Test_search_vimfiles()
  121. let expected_win = $HOME . '/vimfiles'
  122. let expected_nix = $HOME . '/.vim'
  123. let what = lh#path#to_regex($HOME.'/').'\(vimfiles\|.vim\)'
  124. " Comment what
  125. let z = lh#path#find(&rtp,what)
  126. if has('win16')||has('win32')||has('win64')
  127. Assert z == expected_win
  128. else
  129. Assert z == expected_nix
  130. endif
  131. endfunction
  132. function! s:Test_path_depth()
  133. Assert 0 == lh#path#depth('.')
  134. Assert 0 == lh#path#depth('./')
  135. Assert 0 == lh#path#depth('.\')
  136. Assert 1 == lh#path#depth('toto')
  137. Assert 1 == lh#path#depth('toto/')
  138. Assert 1 == lh#path#depth('toto\')
  139. Assert 1 == lh#path#depth('toto/.')
  140. Assert 1 == lh#path#depth('toto\.')
  141. Assert 1 == lh#path#depth('toto/./.')
  142. Assert 1 == lh#path#depth('toto\.\.')
  143. Assert 0 == lh#path#depth('toto/..')
  144. if exists('+shellslash')
  145. Assert 0 == lh#path#depth('toto\..')
  146. endif
  147. Assert 2 == lh#path#depth('toto/titi/')
  148. Assert 2 == lh#path#depth('toto\titi\')
  149. Assert 2 == lh#path#depth('/toto/titi/')
  150. Assert 2 == lh#path#depth('c:/toto/titi/')
  151. Assert 2 == lh#path#depth('c:\toto/titi/')
  152. " todo: make a choice about "negative" paths like "../../foo"
  153. Assert -1 == lh#path#depth('../../foo')
  154. endfunction
  155. "------------------------------------------------------------------------
  156. let &cpo=s:cpo_save
  157. "=============================================================================
  158. " vim600: set fdm=marker: