Create test/variable.vim
Add s:suite.g_repl_filetype_repl_is_valid()
This commit is contained in:
parent
dd286da039
commit
e23365bca9
@ -23,6 +23,19 @@ function! repl#run_repl() abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Example:
|
||||
" if you didn't set g:repl_filetype_repl
|
||||
" echo repl#get_filetype_repl('python')
|
||||
" => {'repl': 'python', 'opt': '-i'}
|
||||
function! repl#get_filetype_repl(filetype) abort
|
||||
if !exists('g:repl_filetype_repl')
|
||||
return g:repl#default_filetype_repl[a:filetype]
|
||||
endif
|
||||
let l:filetype_repl = deepcopy(g:repl#default_filetype_repl)
|
||||
call extend(l:filetype_repl, g:repl_filetype_repl)
|
||||
return l:filetype_repl[a:filetype]
|
||||
endfunction
|
||||
|
||||
"-------------------"
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
@ -39,13 +39,12 @@ function! repl#erlang#open_repl() abort
|
||||
cd %:p:h
|
||||
endif
|
||||
|
||||
let l:repl = get(g:, 'repl_filetype_repl.erlang.repl', g:repl#default_filetype_repl.erlang['repl'])
|
||||
let l:opt = get(g:, 'repl_filetype_repl.erlang.opt', g:repl#default_filetype_repl.erlang['opt'])
|
||||
if !executable(l:repl)
|
||||
call repl#echo_error(printf("You don't have repl: '%s'", l:repl))
|
||||
let l:repl = repl#get_filetype_repl('erlang')
|
||||
if !executable(l:repl['repl'])
|
||||
call repl#echo_error(printf("You don't have repl: '%s'", l:repl['repl']))
|
||||
return
|
||||
endif
|
||||
let l:args = printf('%s %s %s', l:repl, l:opt, l:module_file)
|
||||
let l:args = printf('%s %s %s', l:repl['repl'], l:repl['opt'], l:module_file)
|
||||
let l:vimshell_interactive = ':VimShellInteractive' . printf("--split='%s'", g:repl_split_command)
|
||||
|
||||
execute l:vimshell_interactive l:args
|
||||
|
@ -10,13 +10,12 @@ function! repl#haskell#open_repl() abort
|
||||
let l:module_file = expand('%:p')
|
||||
endif
|
||||
|
||||
let l:repl = get(g:, 'repl_filetype_repl.haskell.repl', g:repl#default_filetype_repl.haskell['repl'])
|
||||
let l:opt = get(g:, 'repl_filetype_repl.haskell.opt', g:repl#default_filetype_repl.haskell['opt'])
|
||||
if !executable(l:repl)
|
||||
call repl#echo_error(printf("You don't have repl: '%s'", l:repl))
|
||||
let l:repl = repl#get_filetype_repl('haskell')
|
||||
if !executable(l:repl['repl'])
|
||||
call repl#echo_error(printf("You don't have repl: '%s'", l:repl['repl']))
|
||||
return
|
||||
endif
|
||||
let l:args = printf('%s %s %s', l:repl, l:opt, l:module_file)
|
||||
let l:args = printf('%s %s %s', l:repl['repl'], l:repl['opt'], l:module_file)
|
||||
let l:vimshell_interactive = ':VimShellInteractive' . printf("--split='%s'", g:repl_split_command)
|
||||
execute l:vimshell_interactive l:args
|
||||
endfunction
|
||||
|
@ -10,13 +10,12 @@ function! repl#python#open_repl() abort
|
||||
let l:module_file = expand('%:p')
|
||||
endif
|
||||
|
||||
let l:repl = get(g:, 'repl_filetype_repl.python.repl', g:repl#default_filetype_repl.python['repl'])
|
||||
let l:opt = get(g:, 'repl_filetype_repl.python.opt', g:repl#default_filetype_repl.python['opt'])
|
||||
if !executable(l:repl)
|
||||
call repl#echo_error(printf("You don't have repl: '%s'", l:repl))
|
||||
let l:repl = repl#get_filetype_repl('python')
|
||||
if !executable(l:repl['repl'])
|
||||
call repl#echo_error(printf("You don't have repl: '%s'", l:repl['repl']))
|
||||
return
|
||||
endif
|
||||
let l:args = printf('%s %s %s', l:repl, l:opt, l:module_file)
|
||||
let l:args = printf('%s %s %s', l:repl['repl'], l:repl['opt'], l:module_file)
|
||||
let l:vimshell_interactive = ':VimShellInteractive' . printf("--split='%s'", g:repl_split_command)
|
||||
execute l:vimshell_interactive l:args
|
||||
endfunction
|
||||
|
@ -9,13 +9,12 @@ function! repl#ruby#open_repl() abort
|
||||
let l:module_file = expand('%:p')
|
||||
endif
|
||||
|
||||
let l:repl = get(g:, 'repl_filetype_repl.ruby.repl', g:repl#default_filetype_repl.ruby['repl'])
|
||||
let l:opt = get(g:, 'repl_filetype_repl.ruby.opt', g:repl#default_filetype_repl.ruby['opt'])
|
||||
if !executable(l:repl)
|
||||
call repl#echo_error(printf("You don't have repl: '%s'", l:repl))
|
||||
let l:repl = repl#get_filetype_repl('ruby')
|
||||
if !executable(l:repl['repl'])
|
||||
call repl#echo_error(printf("You don't have repl: '%s'", l:repl['repl']))
|
||||
return
|
||||
endif
|
||||
let l:args = printf('%s %s %s', l:repl, l:opt, l:module_file)
|
||||
let l:args = printf('%s %s %s', l:repl['repl'], l:repl['opt'], l:module_file)
|
||||
let l:vimshell_interactive = ':VimShellInteractive' . printf("--split='%s'", g:repl_split_command)
|
||||
execute l:vimshell_interactive l:args
|
||||
endfunction
|
||||
|
@ -26,7 +26,6 @@ let g:repl#default_filetype_repl = {
|
||||
\ 'opt' : ''
|
||||
\ }
|
||||
\}
|
||||
call extend(g:repl#default_filetype_repl, get(g:, 'repl_filetype_repl', {}))
|
||||
|
||||
" 'split' or 'vertical split'
|
||||
let g:repl_split_command = get(g:, 'repl_split_command', 'split')
|
||||
|
@ -1,4 +1,4 @@
|
||||
let s:suite = themis#suite('can_open')
|
||||
let s:suite = themis#suite('can_open')
|
||||
|
||||
function! s:suite.after_each()
|
||||
call UnletReplUserVariables()
|
||||
@ -16,8 +16,3 @@ function! s:suite.some_repl()
|
||||
" but repl.vim don't throw some exception
|
||||
new | setfiletype unknown | Repl
|
||||
endfunction
|
||||
|
||||
function! s:suite.some_repl_with_split_command()
|
||||
let g:repl_split_command = 'vertical split'
|
||||
call s:suite.some_repl()
|
||||
endfunction
|
||||
|
32
test/variable.vim
Normal file
32
test/variable.vim
Normal file
@ -0,0 +1,32 @@
|
||||
let s:suite = themis#suite('variable')
|
||||
let s:assert = themis#helper('assert')
|
||||
|
||||
function! s:suite.after_each()
|
||||
call UnletReplUserVariables()
|
||||
endfunction
|
||||
|
||||
"-------------------"
|
||||
|
||||
function! s:suite.g_repl_filetype_repl_is_valid()
|
||||
let l:TARGET_FILETYPE = 'ruby' | lockvar l:TARGET_FILETYPE
|
||||
|
||||
" Default value
|
||||
let l:DEFAULT_REPL_NAME = g:repl#default_filetype_repl[l:TARGET_FILETYPE]['repl'] | lockvar l:DEFAULT_REPL_NAME
|
||||
let l:DEFAULT_REPL_OPT = g:repl#default_filetype_repl[l:TARGET_FILETYPE]['opt'] | lockvar l:DEFAULT_REPL_OPT
|
||||
let l:filetype_repl = repl#get_filetype_repl(l:TARGET_FILETYPE)
|
||||
call s:assert.equals(l:filetype_repl['repl'], l:DEFAULT_REPL_NAME)
|
||||
call s:assert.equals(l:filetype_repl['opt'], l:DEFAULT_REPL_OPT)
|
||||
|
||||
" Not a default value
|
||||
let l:REPL_NAME = 'dummy' | lockvar l:REPL_NAME
|
||||
let l:REPL_OPT = '--dummy' | lockvar l:REPL_OPT
|
||||
let g:repl_filetype_repl = {
|
||||
\ l:TARGET_FILETYPE : {
|
||||
\ 'repl' : l:REPL_NAME,
|
||||
\ 'opt' : l:REPL_OPT
|
||||
\ }
|
||||
\}
|
||||
let l:filetype_repl = repl#get_filetype_repl(l:TARGET_FILETYPE)
|
||||
call s:assert.equals(l:filetype_repl['repl'], l:REPL_NAME)
|
||||
call s:assert.equals(l:filetype_repl['opt'], l:REPL_OPT)
|
||||
endfunction
|
Reference in New Issue
Block a user