Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kamykn committed Nov 22, 2019
1 parent 59e3d9c commit f3e6b9e
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 54 deletions.
92 changes: 49 additions & 43 deletions autoload/spelunker/test/test_toggle.vim
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ let s:save_cpo = &cpo
set cpo&vim

function! spelunker#test#test_toggle#test()
call s:test_toggle() " test global toggle
call s:test_toggle_buffer() " test local toggle
call s:test_is_enabled()
call s:test_is_enabled_global()
call s:test_is_enabled_buffer()

call s:force_enable()
call s:test_toggle() " test global toggle
call s:test_toggle_buffer() " test local toggle

call s:force_enable_global()
endfunction

" toggle_mode
Expand All @@ -31,14 +32,17 @@ function! s:test_toggle()

" highlightがなくなっていることを確認
silent! call spelunker#toggle#toggle()
call assert_equal(1, spelunker#toggle#is_enabled())

let l:result = getmatches()
call assert_equal(1, len(l:result))
call assert_equal('SpelunkerSpellBad', l:result[0]['group'])
call assert_equal('\v[A-Za-z]@<!appl[a-z]@!\C', l:result[0]['pattern'])
call assert_equal(0, l:result[0]['priority'])
return

silent! call spelunker#toggle#toggle()
call assert_equal(0, spelunker#toggle#is_enabled())

let l:result = getmatches()
call assert_equal([], l:result)

Expand All @@ -65,6 +69,7 @@ function! s:test_toggle()

" [case10-1] =====================================
silent! call spelunker#toggle#toggle()
call assert_equal(1, spelunker#toggle#is_enabled())

" spelunker#check_displayed_words spelunker#check "{{{
let g:spelunker_check_type = g:spelunker_check_type_buf_lead_write
Expand Down Expand Up @@ -116,8 +121,9 @@ function! s:test_toggle()
call spelunker#test#open_unit_test_buffer('toggle', 'toggle3_1.txt')
call spelunker#test#init()

call s:force_enable()
call s:force_enable_global()
silent! call spelunker#toggle#toggle()
call assert_equal(0, spelunker#toggle#is_enabled())

call cursor(1, 2)
call assert_equal(0, spelunker#correct())
Expand All @@ -133,7 +139,7 @@ function! s:test_toggle()
call spelunker#test#reload_buffer()
call spelunker#test#init()

call s:force_enable()
call s:force_enable_global()

call cursor(1, 2)
" call assert_equal(0, spelunker#correct())
Expand Down Expand Up @@ -166,18 +172,26 @@ function! s:test_toggle_buffer()
call spelunker#test#open_unit_test_buffer('toggle', 'toggle1_2.txt')
call spelunker#test#init()

call s:force_enable_global()

" toggle off (global enabled, buffer disabled)
silent! call spelunker#toggle#toggle_buffer()
call assert_equal(0, spelunker#toggle#is_enabled())
call assert_equal(0, spelunker#toggle#is_enabled_buffer())

" highlightがなくなっていることを確認
silent! call spelunker#toggle#toggle_buffer()
call assert_equal(1, spelunker#toggle#is_enabled())
call assert_equal(1, spelunker#toggle#is_enabled_buffer())

let l:result = getmatches()
call assert_equal(1, len(l:result))
call assert_equal('SpelunkerSpellBad', l:result[0]['group'])
call assert_equal('\v[A-Za-z]@<!apll[a-z]@!\C', l:result[0]['pattern'])
call assert_equal(0, l:result[0]['priority'])
return
call assert_equal(0, len(l:result))
" call assert_equal('SpelunkerSpellBad', l:result[0]['group'])
" call assert_equal('\v[A-Za-z]@<!apll[a-z]@!\C', l:result[0]['pattern'])
" call assert_equal(0, l:result[0]['priority'])

silent! call spelunker#toggle#toggle_buffer()
call assert_equal(0, spelunker#toggle#is_enabled())

let l:result = getmatches()
call assert_equal([], l:result)

Expand All @@ -204,6 +218,7 @@ function! s:test_toggle_buffer()

" [case10-1] =====================================
silent! call spelunker#toggle#toggle_buffer()
call assert_equal(1, spelunker#toggle#is_enabled())

" spelunker#check_displayed_words spelunker#check "{{{
let g:spelunker_check_type = g:spelunker_check_type_buf_lead_write
Expand Down Expand Up @@ -246,7 +261,7 @@ function! s:test_toggle_buffer()

call assert_equal(1, spelunker#execute_with_target_word('spellwrong!'))
let l:line = spelunker#spellbad#get_spell_bad_list(2, -1)
call assert_equal([''], l:line)
call assert_equal(['misspelt'], l:line)
call execute('spellundo! misspelt')
" }}}

Expand All @@ -255,8 +270,9 @@ function! s:test_toggle_buffer()
call spelunker#test#open_unit_test_buffer('toggle', 'toggle3_2.txt')
call spelunker#test#init()

call s:force_enable()
call s:force_enable_buffer()
silent! call spelunker#toggle#toggle_buffer()
call assert_equal(0, spelunker#toggle#is_enabled())

call cursor(1, 2)
call assert_equal(0, spelunker#correct())
Expand All @@ -272,7 +288,7 @@ function! s:test_toggle_buffer()
call spelunker#test#reload_buffer()
call spelunker#test#init()

call s:force_enable()
call s:force_enable_buffer()

call cursor(1, 2)
" call assert_equal(0, spelunker#correct())
Expand All @@ -297,38 +313,25 @@ function! s:test_toggle_buffer()
call spelunker#test#reload_buffer()
endfunction


" toggle_mode
" 1: global mode
" 2: buffer mode
function! s:toggle(toggle_mode)
if a:toggle_mode == 1
silent! call spelunker#toggle#toggle()
elseif a:toggle_mode == 2
silent! call spelunker#toggle#toggle_buffer()
endif
endfunction

function! s:test_is_enabled()
call spelunker#test#open_unit_test_buffer('toggle', 'toggle1_1.txt')
call spelunker#test#open_unit_test_buffer('toggle', 'is_enabled_1.txt')
call spelunker#test#init()

call assert_equal(1, spelunker#toggle#is_enabled())

" disabled (global)
call spelunker#toggle#toggle()
call assert_equal(1, spelunker#toggle#is_enabled())
call assert_equal(0, spelunker#toggle#is_enabled())

" enabled (global)
call spelunker#toggle#toggle()
call assert_equal(1, spelunker#toggle#is_enabled())

" disabled (global)
call assert_equal(1, spelunker#toggle#is_enabled())
call spelunker#test#open_unit_test_buffer('toggle', 'is_enabled_2.txt')

" disabled (buffer)
call spelunker#toggle#toggle_buffer()
call assert_equal(1, spelunker#toggle#is_enabled())
call assert_equal(0, spelunker#toggle#is_enabled())

" enabled (global)
call spelunker#toggle#toggle_buffer()
Expand All @@ -340,11 +343,11 @@ function! s:test_is_enabled()
call spelunker#toggle#toggle() " disabled (global)
call assert_equal(1, spelunker#toggle#is_enabled())

call s:force_enable()
call s:force_enable_global()
endfunction

function! s:test_is_enabled_global()
call spelunker#test#open_unit_test_buffer('toggle', 'toggle1_1.txt')
call spelunker#test#open_unit_test_buffer('toggle', 'is_enabled_global.txt')
call spelunker#test#init()

" enabled (global)
Expand All @@ -358,29 +361,32 @@ function! s:test_is_enabled_global()
call spelunker#toggle#toggle()
call assert_equal(1, spelunker#toggle#is_enabled_global())

call s:force_enable()
call s:force_enable_global()
endfunction

function! s:test_is_enabled_buffer()
call spelunker#test#open_unit_test_buffer('toggle', 'toggle1_1.txt')
call spelunker#test#open_unit_test_buffer('toggle', 'is_enabled_buffer.txt')
call spelunker#test#init()
call s:force_enable()

call assert_equal(1, spelunker#toggle#is_enabled_buffer())
call s:force_enable_global()

" disabled (global)
" b:enable_spelunker_vim is empty
call assert_equal(0, spelunker#toggle#is_enabled_buffer())

" toggle off (global enabled, buffer disabled)
call spelunker#toggle#toggle_buffer()
call assert_equal(0, spelunker#toggle#is_enabled_buffer())

" enabled (global)
" enable on
call spelunker#toggle#toggle_buffer()
call assert_equal(1, spelunker#toggle#is_enabled_buffer())

call s:force_enable()
endfunction

function! s:force_enable()
function! s:force_enable_global()
let g:enable_spelunker_vim = 1
endfunction

function! s:force_enable_buffer()
let b:enable_spelunker_vim = 1
endfunction

Expand Down
30 changes: 19 additions & 11 deletions autoload/spelunker/toggle.vim
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ set cpo&vim
function! spelunker#toggle#toggle()
let g:enable_spelunker_vim = g:enable_spelunker_vim == 1 ? 0 : 1

" onにするときは今開いているbufferも連動させる
if g:enable_spelunker_vim == 1
let b:enable_spelunker_vim = 1
" 今開いているbufferも連動させる
if exists('b:enable_spelunker_vim')
if g:enable_spelunker_vim == 1
let b:enable_spelunker_vim = 1
else
let b:enable_spelunker_vim = 0
endif
endif

call spelunker#toggle#init_buffer(1, g:enable_spelunker_vim)
Expand All @@ -27,10 +31,12 @@ endfunction

function! spelunker#toggle#toggle_buffer()
if !exists('b:enable_spelunker_vim')
let b:enable_spelunker_vim = 1
" 初回はglobalスコープの方を反転させる
let b:enable_spelunker_vim = g:enable_spelunker_vim == 1 ? 0 : 1
else
let b:enable_spelunker_vim = b:enable_spelunker_vim == 1 ? 0 : 1
endif

let b:enable_spelunker_vim = b:enable_spelunker_vim == 1 ? 0 : 1
call spelunker#toggle#init_buffer(2, b:enable_spelunker_vim)

if b:enable_spelunker_vim == 1
Expand Down Expand Up @@ -65,16 +71,18 @@ function! spelunker#toggle#is_enabled()
return 0
else
" b:enable_spelunker_vimがあればbuffer優先
if spelunker#toggle#is_enabled_buffer() == 0
if spelunker#toggle#is_enabled_buffer() == 1
return 1
else
return 0
endif
endif

if spelunker#toggle#is_enabled_global() == 0
return 0
endif
if spelunker#toggle#is_enabled_global() == 0
return 0
endif

return 1
return 1
endif
endfunction

function! spelunker#toggle#is_enabled_global()
Expand Down
3 changes: 3 additions & 0 deletions test/unit_test/toggle/is_enabled_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
appl
appl

3 changes: 3 additions & 0 deletions test/unit_test/toggle/is_enabled_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
appl
appl

3 changes: 3 additions & 0 deletions test/unit_test/toggle/is_enabled_buffer.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
appl
appl

3 changes: 3 additions & 0 deletions test/unit_test/toggle/is_enabled_global.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
appl
appl

0 comments on commit f3e6b9e

Please sign in to comment.