|
1 | 1 | nnoremap <leader>E :%Eval<CR> |
2 | 2 |
|
3 | 3 | " Rainbow parentheses always on |
4 | | -au BufRead,BufNewFile *.clj RainbowParenthesesToggleAll |
| 4 | +au BufEnter *.clj RainbowParenthesesToggleAll |
| 5 | + |
| 6 | +" Parse implementation namespace from the first line in the test file |
| 7 | +" Example: |
| 8 | +" (ns foo-app.handler-spec) |
| 9 | +" => foo-app.handler |
| 10 | +function! s:GetNamespaceFromTest() |
| 11 | + let regex = "(ns\\s\\+\\(.*\\)-\\(spec\\|test\\)" |
| 12 | + let location = 1 |
| 13 | + let line = getline(location) |
| 14 | + return substitute(line, regex, "\\1", "") |
| 15 | +endfunction |
| 16 | + |
| 17 | +" Reload implementation namespace and eval test file |
| 18 | +function! RunTestWithReload() |
| 19 | + let namespace = s:GetNamespaceFromTest() |
| 20 | + execute 'Require ' . namespace |
| 21 | + %Eval |
| 22 | +endfunction |
| 23 | + |
| 24 | +" Reload implementation, find matching test file, open and eval test |
| 25 | +function! RunTestFromFile() |
| 26 | + Require |
| 27 | + |
| 28 | + let directory = "spec" |
| 29 | + if !isdirectory(directory) |
| 30 | + let directory = "test" |
| 31 | + if !isdirectory(directory) |
| 32 | + echom 'No test directories exist' |
| 33 | + return |
| 34 | + endif |
| 35 | + endif |
| 36 | + |
| 37 | + let path = directory . '/' . expand("%:h:t") . '/' . expand("%:t:r") . '_' . directory . '.clj' |
| 38 | + if !exists(path) |
| 39 | + echom 'Test file does not exist ' . path |
| 40 | + return |
| 41 | + endif |
| 42 | + |
| 43 | + execute 'vsplit ' . path |
| 44 | + %Eval |
| 45 | + wincmd l |
| 46 | +endfunction |
| 47 | + |
| 48 | +function! s:AutoReload() |
| 49 | + Require |
| 50 | +endfunction |
| 51 | + |
| 52 | +autocmd BufRead *.clj nnoremap <buffer> <leader>t :call RunTestFromFile()<CR> |
| 53 | +autocmd BufRead *_spec.clj,*_test.clj nnoremap <buffer> <leader>t :call RunTestWithReload()<CR> |
| 54 | +autocmd BufWritePre *.clj :call s:AutoReload() |
0 commit comments