My dotfiles. Period.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. "=============================================================================
  2. " $Id: function.vim 520 2012-03-19 18:09:15Z luc.hermitte $
  3. " File: tests/lh/function.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: 03rd Nov 2008
  10. " Last Update: $Date: 2012-03-19 19:09:15 +0100 (Mon, 19 Mar 2012) $
  11. "------------------------------------------------------------------------
  12. " Description:
  13. " Tests for autoload/lh/function.vim
  14. "
  15. "------------------------------------------------------------------------
  16. " Installation: «install details»
  17. " History: «history»
  18. " TODO: «missing features»
  19. " }}}1
  20. "=============================================================================
  21. UTSuite [lh-vim-lib] Testing lh#function plugin
  22. runtime autoload/lh/function.vim
  23. let s:cpo_save=&cpo
  24. set cpo&vim
  25. "------------------------------------------------------------------------
  26. function! Test(...)
  27. let nb = len(a:000)
  28. " echo "test(".nb.':' .join(a:000, ' -- ')')'
  29. let i =0
  30. while i!= len(a:000)
  31. echo "Test: type(".i.")=".type(a:000[i]).' --> '. string(a:000[i])
  32. let i += 1
  33. endwhile
  34. endfunction
  35. function! Print(...)
  36. let res = lh#list#accumulate([1,2,'foo'], 'string', 'join(v:1_, " ## ")')
  37. return res
  38. endfunction
  39. function! Id(...)
  40. return copy(a:000)
  41. endfunction
  42. function! s:TestId()
  43. let r = Id(1, 'string', [0], [[1]], {'ffo':42}, function('exists'), 1.2)
  44. Assert! len(r) == 7
  45. Assert! should#be#number (r[0])
  46. Assert! should#be#string (r[1])
  47. Assert! should#be#list (r[2])
  48. Assert! should#be#list (r[3])
  49. Assert! should#be#dict (r[4])
  50. Assert! should#be#funcref(r[5])
  51. Assert! should#be#float (r[6])
  52. Assert r[0] == 1
  53. Assert r[1] == 'string'
  54. Assert r[2] == [0]
  55. Assert r[3] == [[1]]
  56. Assert r[4].ffo == 42
  57. Assert r[5] == function('exists')
  58. Assert r[6] == 1.2
  59. endfunction
  60. function! s:Test_bind()
  61. " lh#function#bind + lh#function#execute
  62. let rev4 = lh#function#bind(function('Id'), 'v:4_', 42, 'v:3_', 'v:2_', 'v:1_')
  63. let r = lh#function#execute(rev4, 1,'two','three', [4,5])
  64. Assert! len(r) == 5
  65. Assert! should#be#list (r[0])
  66. Assert! should#be#number (r[1])
  67. Assert! should#be#string (r[2])
  68. Assert! should#be#string (r[3])
  69. Assert! should#be#number (r[4])
  70. Assert r[0] == [4,5]
  71. Assert r[1] == 42
  72. Assert r[2] == 'three'
  73. Assert r[3] == 'two'
  74. Assert r[4] == 1
  75. endfunction
  76. function! s:Test_bind_compound_vars()
  77. " lh#function#bind + lh#function#execute
  78. let rev4 = lh#function#bind(function('Id'), 'v:4_', 'v:1_ . v:2_', 'v:3_', 'v:2_', 'v:1_')
  79. let r = lh#function#execute(rev4, 1,'two','three', [4,5])
  80. Assert! len(r) == 5
  81. Assert! should#be#list (r[0])
  82. Assert! should#be#string (r[1])
  83. Assert! should#be#string (r[2])
  84. Assert! should#be#string (r[3])
  85. Assert! should#be#number (r[4])
  86. Assert r[0] == [4,5]
  87. Assert r[1] == '1two'
  88. Assert r[2] == 'three'
  89. Assert r[3] == 'two'
  90. Assert r[4] == 1
  91. endfunction
  92. function! s:Test_execute_func_string_name()
  93. " function name as string
  94. let r = lh#function#execute('Id', 1,'two',3)
  95. Assert! len(r) == 3
  96. Assert! should#be#number (r[0])
  97. Assert! should#be#string (r[1])
  98. Assert! should#be#number (r[2])
  99. Assert r[0] == 1
  100. Assert r[1] == 'two'
  101. Assert r[2] == 3
  102. endfunction
  103. function! s:Test_execute_string_expr()
  104. " exp as binded-string
  105. let r = lh#function#execute('Id(12,len(v:2_).v:2_, 42, v:3_, v:1_)', 1,'two',3)
  106. Assert! len(r) == 5
  107. Assert! should#be#number (r[0])
  108. Assert! should#be#string (r[1])
  109. Assert! should#be#number (r[2])
  110. Assert! should#be#number (r[3])
  111. Assert! should#be#number (r[4])
  112. Assert r[0] == 12
  113. Assert r[1] == len('two').'two'
  114. Assert r[2] == 42
  115. Assert r[3] == 3
  116. Assert r[4] == 1
  117. endfunction
  118. function! s:Test_execute_func()
  119. " calling a function() + bind
  120. let r = lh#function#execute(function('Id'), 1,'two','v:1_',['a',42])
  121. Assert! len(r) == 4
  122. Assert! should#be#number (r[0])
  123. Assert! should#be#string (r[1])
  124. Assert! should#be#string (r[2])
  125. Assert! should#be#list (r[3])
  126. Assert r[0] == 1
  127. Assert r[1] == 'two'
  128. Assert r[2] == 'v:1_'
  129. Assert r[3] == ['a', 42]
  130. endfunction
  131. "------------------------------------------------------------------------
  132. function! s:Test_bind_func_string_name_AND_execute()
  133. " function name as string
  134. let rev3 = lh#function#bind('Id', 'v:3_', 12, 'v:2_', 'v:1_')
  135. let r = lh#function#execute(rev3, 1,'two',3)
  136. Assert! len(r) == 4
  137. Assert! should#be#number (r[0])
  138. Assert! should#be#number (r[1])
  139. Assert! should#be#string (r[2])
  140. Assert! should#be#number (r[3])
  141. Assert r[0] == 3
  142. Assert r[1] == 12
  143. Assert r[2] == 'two'
  144. Assert r[3] == 1
  145. endfunction
  146. function! s:Test_bind_string_expr_AND_execute()
  147. " expressions as string
  148. let rev3 = lh#function#bind('Id(12,len(v:2_).v:2_, 42, v:3_, v:1_)')
  149. let r = lh#function#execute(rev3, 1,'two',3)
  150. Assert! len(r) == 5
  151. Assert! should#be#number (r[0])
  152. Assert! should#be#string (r[1])
  153. Assert! should#be#number (r[2])
  154. Assert! should#be#number (r[3])
  155. Assert! should#be#number (r[4])
  156. Assert r[0] == 12
  157. Assert r[1] == len('two').'two'
  158. Assert r[2] == 42
  159. Assert r[3] == 3
  160. Assert r[4] == 1
  161. endfunction
  162. function! s:Test_double_bind_func_name()
  163. let f1 = lh#function#bind('Id', 1, 2, 'v:1_', 4, 'v:2_')
  164. " Comment "f1=".string(f1)
  165. let r = lh#function#execute(f1, 3, 5)
  166. Assert! len(r) == 5
  167. let i = 0
  168. while i != len(r)
  169. Assert! should#be#number (r[i])
  170. Assert r[i] == i+1
  171. let i += 1
  172. endwhile
  173. " f2
  174. let f2 = lh#function#bind(f1, 'v:1_', 5)
  175. " Comment "f2=f1(v:1_, 5)=".string(f2)
  176. let r = lh#function#execute(f2, 3)
  177. Assert! len(r) == 5
  178. let i = 0
  179. while i != len(r)
  180. Assert! should#be#number (r[i])
  181. " echo "?? ".(r[i])."==".(i+1)
  182. Assert r[i] == i+1
  183. let i += 1
  184. endwhile
  185. endfunction
  186. function! s:Test_double_bind_func()
  187. let f1 = lh#function#bind(function('Id'), 1, 2, 'v:1_', 4, 'v:2_')
  188. " Comment "f1=".string(f1)
  189. let r = lh#function#execute(f1, 3, 5)
  190. Assert! len(r) == 5
  191. let i = 0
  192. while i != len(r)
  193. Assert! should#be#number (r[i])
  194. Assert r[i] == i+1
  195. let i += 1
  196. endwhile
  197. " f2
  198. let f2 = lh#function#bind(f1, 'v:1_', 5)
  199. " Comment "f2=f1(v:1_, 5)=".string(f2)
  200. let r = lh#function#execute(f2, 3)
  201. Assert! len(r) == 5
  202. let i = 0
  203. while i != len(r)
  204. Assert! should#be#number (r[i])
  205. Assert r[i] == i+1
  206. let i += 1
  207. endwhile
  208. endfunction
  209. function! s:Test_double_bind_func_cplx()
  210. let g:bar = "bar"
  211. let f1 = lh#function#bind(function('Id'), 1, 2, 'v:1_', 4, 'v:2_', 'v:3_', 'v:4_', 'v:5_', 'v:6_', 'v:7_')
  212. " Comment "2bcpl# f1=".string(f1)
  213. let f2 = lh#function#bind(f1, 'len(g:bar.v:1_)+v:1_', [1,2], '[v:1_, v:2_]', 4,5,6,7)
  214. " let f2 = lh#function#bind(f1, 'v:1_', 5, 'foo', g:bar, 'len(g:bar.v:1_)+v:1_', [1,2], '[v:1_, v:2_]')
  215. " Comment "2bcpl# f2=f1(v:1_, 5)=".string(f2)
  216. let r = lh#function#execute(f2, 42, "foo")
  217. Assert! 0 && "not ready"
  218. Comment "2bcpl# ".string(r)
  219. endfunction
  220. function! s:Test_double_bind_expr()
  221. let f1 = lh#function#bind('Id(1, 2, v:1_, v:3_, v:2_)')
  222. Comment "2be# f1=".string(f1)
  223. let r = lh#function#execute(f1, 3, 5, 4)
  224. Comment "2be# ".string(r)
  225. Assert! len(r) == 5
  226. let i = 0
  227. while i != len(r)
  228. Assert! should#be#number (r[i])
  229. Assert r[i] == i+1
  230. let i += 1
  231. endwhile
  232. " f2
  233. let f2 = lh#function#bind(f1, 'v:1_', '"foo"', [])
  234. Comment "2be# f2=f1(v:1_, 5)=".string(f2)
  235. let r = lh#function#execute(f2, 3)
  236. Comment "2be# ".string(r)
  237. Assert! len(r) == 5
  238. let i = 0
  239. while i != len(r)-2
  240. Assert! should#be#number (r[i])
  241. Assert r[i] == i+1
  242. let i += 1
  243. endwhile
  244. Assert! should#be#list (r[-2])
  245. Assert r[-2] == []
  246. Assert! should#be#string (r[-1])
  247. Assert r[-1] == 'foo'
  248. endfunction
  249. "todo: write double-binded tests for all kind of binded parameters:
  250. " 'len(g:bar)'
  251. " 42
  252. " []
  253. " v:1_ + len(v:2_.v:3_)
  254. " '"foo"'
  255. " v:1_
  256. "------------------------------------------------------------------------
  257. let &cpo=s:cpo_save
  258. "=============================================================================
  259. " vim600: set fdm=marker: