Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 1 | Test for user functions. |
| 2 | Also test an <expr> mapping calling a function. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3 | |
| 4 | STARTTEST |
| 5 | :so small.vim |
| 6 | :function Table(title, ...) |
| 7 | : let ret = a:title |
| 8 | : let idx = 1 |
| 9 | : while idx <= a:0 |
| 10 | : exe "let ret = ret . a:" . idx |
| 11 | : let idx = idx + 1 |
| 12 | : endwhile |
| 13 | : return ret |
| 14 | :endfunction |
| 15 | :function Compute(n1, n2, divname) |
| 16 | : if a:n2 == 0 |
| 17 | : return "fail" |
| 18 | : endif |
| 19 | : exe "let g:" . a:divname . " = ". a:n1 / a:n2 |
| 20 | : return "ok" |
| 21 | :endfunction |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 22 | :func Expr1() |
| 23 | : normal! v |
| 24 | : return "111" |
| 25 | :endfunc |
| 26 | :func Expr2() |
| 27 | : call search('XX', 'b') |
| 28 | : return "222" |
| 29 | :endfunc |
| 30 | :func ListItem() |
| 31 | : let g:counter += 1 |
| 32 | : return g:counter . '. ' |
| 33 | :endfunc |
| 34 | :func ListReset() |
| 35 | : let g:counter = 0 |
| 36 | : return '' |
| 37 | :endfunc |
| 38 | :let counter = 0 |
| 39 | :inoremap <expr> ( ListItem() |
| 40 | :inoremap <expr> [ ListReset() |
| 41 | :imap <expr> + Expr1() |
| 42 | :imap <expr> * Expr2() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 43 | :let retval = "nop" |
| 44 | /^here |
| 45 | C=Table("xxx", 4, "asdf") |
| 46 | =Compute(45, 0, "retval") |
| 47 | =retval |
| 48 | =Compute(45, 5, "retval") |
| 49 | =retval |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 50 | |
| 51 | XX+-XX |
| 52 | ---*--- |
| 53 | (one |
| 54 | (two |
Bram Moolenaar | 9d2c8c1 | 2007-09-25 16:00:00 +0000 | [diff] [blame^] | 55 | [(one again:$-5,$w! test.out |
| 56 | :delfunc Table |
| 57 | :delfunc Compute |
| 58 | :delfunc Expr1 |
| 59 | :delfunc Expr2 |
| 60 | :delfunc ListItem |
| 61 | :delfunc ListReset |
| 62 | :unlet retval counter |
| 63 | :q! |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 64 | ENDTEST |
| 65 | |
| 66 | here |