Skip to content

Commit

Permalink
add tests for clever-s feature closes #41
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmk committed Jan 31, 2014
1 parent 7bca5bf commit 557fbf3
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
5 changes: 3 additions & 2 deletions autoload/sneak/streak.vim
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,16 @@ func! s:do_streak(s, st)
call s:after()

let v = sneak#util#isvisualop(a:st.op)
let mappedto = maparg(choice, v ? 'x' : 'n')

if choice == "\<Tab>" && overflow[0] > 0
call cursor(overflow[0], overflow[1])
return 1 "overflow => decorate next N matches
elseif -1 != index(["\<Esc>", "\<Space>", "\<CR>"], choice)
return 0 "exit streak-mode.
elseif maparg(choice, v ? 'x' : 'n') =~# '<Plug>V\?Sneak.\?\(Fwd\|Next\|Forward\)'
elseif mappedto =~# '<Plug>V\?Sneak.\?\(Fwd\|Next\|Forward\)'
call sneak#rpt(v, 1, 0)
elseif maparg(choice, v ? 'x' : 'n') =~# '<Plug>V\?Sneak.\?\(Bck\|Previous\|Backward\)'
elseif mappedto =~# '<Plug>V\?Sneak.\?\(Bck\|Previous\|Backward\)'
call sneak#rpt(v, 1, 1)
elseif !has_key(s:matchmap, choice) "press _any_ invalid key to escape.
call feedkeys(choice) "exit streak-mode and fall through to Vim.
Expand Down
56 changes: 56 additions & 0 deletions tests/test.vader
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,38 @@ Expect:
| batch_size | Fixnum | nil | number of maximum items to be assigned at once |
| logger | Logger | nil | logger instance for debug logs |

###########################################################
# clever-s _not_ in streak-mode

Given:
abcdef abcdef abcdef
abcdef abcdef abcdef
abcdef abcdef abcdef

Do (clever-s):
sabsax

Expect:
abcdef abcdef axbcdef
abcdef abcdef abcdef
abcdef abcdef abcdef

Do (clever-s):
sab3sax

Expect:
abcdef abcdef abcdef
abcdef axbcdef abcdef
abcdef abcdef abcdef

Do (clever-s):
sabsssssssSSax

Expect:
abcdef abcdef abcdef
abcdef abcdef abcdef
axbcdef abcdef abcdef

###########################################################

Given:
Expand Down Expand Up @@ -321,6 +353,30 @@ Expect:
abcdef ``=2Bd-a3/+ =QWEOIJ/+ ~~~!!! ! { } abc AAaab
abcdef ``=2Bd-a3/+ abCDef ``=2Bd-a3/+

# sadly we must force-exit via <Space> because feedkeys() in do_streak()
# breaks macros/Vader
Do (clever-s, streak-mode):
sab\<Space>2six

Expect:
abcdef ``=2Bd-a3/+ abCDef ``=2Bd-a3/+
`=QWEOIJ/+ ~~~!!! ! { } abc AAaxab
abcdef ``=2Bd-a3/+ abCDef ``=2Bd-a3/+

Do (clever-s, visual-mode, streak-mode):
vsabsd

Expect:
bc AAaab
abcdef ``=2Bd-a3/+ abCDef ``=2Bd-a3/+

Do (clever-s, backwards clever-s, visual-mode, streak-mode):
jvsabsssZd

Expect:
abcdef ``=2Bd-a3/+ abCDef ``=2Bd-a3/+
bcdef ``=2Bd-a3/+ abCDef ``=2Bd-a3/+

Execute (cleanup):
let g:sneak#streak = 0
call sneak#init()
Expand Down

0 comments on commit 557fbf3

Please sign in to comment.