2016-05-07 12:11:36 -07:00
|
|
|
-- Test for wordcount() function
|
|
|
|
|
2016-04-23 16:53:11 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2016-05-07 12:11:36 -07:00
|
|
|
local feed, insert, source = helpers.feed, helpers.insert, helpers.source
|
2017-04-08 14:12:26 -07:00
|
|
|
local clear, command = helpers.clear, helpers.command
|
2016-05-07 12:11:36 -07:00
|
|
|
local eq, eval = helpers.eq, helpers.eval
|
2020-10-19 11:17:51 -07:00
|
|
|
local poke_eventloop = helpers.poke_eventloop
|
2016-05-07 12:11:36 -07:00
|
|
|
|
|
|
|
describe('wordcount', function()
|
|
|
|
before_each(clear)
|
|
|
|
|
|
|
|
it('is working', function()
|
2017-04-08 16:36:49 -07:00
|
|
|
command('set selection=inclusive fileformat=unix fileformats=unix')
|
2016-05-10 11:58:49 -07:00
|
|
|
|
2016-05-07 12:11:36 -07:00
|
|
|
insert([=[
|
|
|
|
RESULT test:]=])
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2016-05-07 12:11:36 -07:00
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('new')
|
2016-05-07 12:11:36 -07:00
|
|
|
source([=[
|
|
|
|
function DoRecordWin(...)
|
|
|
|
wincmd k
|
|
|
|
if exists("a:1")
|
|
|
|
call cursor(a:1)
|
|
|
|
endif
|
|
|
|
let result=[]
|
|
|
|
call add(result, getline(1, '$'))
|
|
|
|
call add(result, wordcount())
|
|
|
|
wincmd j
|
|
|
|
return result
|
|
|
|
endfunction
|
|
|
|
]=])
|
|
|
|
|
|
|
|
source([=[
|
|
|
|
function PutInWindow(args)
|
|
|
|
wincmd k
|
|
|
|
%d _
|
|
|
|
call append(1, a:args)
|
|
|
|
wincmd j
|
|
|
|
endfunction
|
|
|
|
]=])
|
|
|
|
|
|
|
|
source([=[
|
|
|
|
function! STL()
|
|
|
|
if mode() =~? 'V'
|
|
|
|
let g:visual_stat=wordcount()
|
|
|
|
endif
|
|
|
|
return string(wordcount())
|
|
|
|
endfunction
|
|
|
|
]=])
|
|
|
|
|
|
|
|
-- Test 1: empty window
|
2022-04-25 20:35:05 -07:00
|
|
|
eq(eval([=[
|
2016-05-07 12:11:36 -07:00
|
|
|
[[''], {'chars': 0, 'cursor_chars': 0, 'words': 0, 'cursor_words': 0, 'bytes': 0, 'cursor_bytes': 0}]
|
2022-04-25 20:35:05 -07:00
|
|
|
]=]),
|
|
|
|
eval('DoRecordWin()')
|
2016-05-07 12:11:36 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
-- Test 2: some words, cursor at start
|
2017-04-08 14:12:26 -07:00
|
|
|
command([[call PutInWindow('one two three')]])
|
2022-04-25 20:35:05 -07:00
|
|
|
eq(eval([=[
|
2016-05-07 12:11:36 -07:00
|
|
|
[['', 'one two three'], {'chars': 15, 'cursor_chars': 1, 'words': 3, 'cursor_words': 0, 'bytes': 15, 'cursor_bytes': 1}]
|
2022-04-25 20:35:05 -07:00
|
|
|
]=]),
|
|
|
|
eval('DoRecordWin([1, 1, 0])')
|
2016-05-07 12:11:36 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
-- Test 3: some words, cursor at end
|
2017-04-08 14:12:26 -07:00
|
|
|
command([[call PutInWindow('one two three')]])
|
2022-04-25 20:35:05 -07:00
|
|
|
eq(eval([=[
|
2016-05-07 12:11:36 -07:00
|
|
|
[['', 'one two three'], {'chars': 15, 'cursor_chars': 14, 'words': 3, 'cursor_words': 3, 'bytes': 15, 'cursor_bytes': 14}]
|
2022-04-25 20:35:05 -07:00
|
|
|
]=]),
|
|
|
|
eval('DoRecordWin([2, 99, 0])')
|
2016-05-07 12:11:36 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
-- Test 4: some words, cursor at end, ve=all
|
2017-04-08 14:12:26 -07:00
|
|
|
command('set ve=all')
|
|
|
|
command([[call PutInWindow('one two three')]])
|
2022-04-25 20:35:05 -07:00
|
|
|
eq(eval([=[
|
2016-05-07 12:11:36 -07:00
|
|
|
[['', 'one two three'], {'chars': 15, 'cursor_chars': 15, 'words': 3, 'cursor_words': 3, 'bytes': 15, 'cursor_bytes': 15}]
|
2022-04-25 20:35:05 -07:00
|
|
|
]=]),
|
|
|
|
eval('DoRecordWin([2,99,0])')
|
2016-05-07 12:11:36 -07:00
|
|
|
)
|
2017-04-08 14:12:26 -07:00
|
|
|
command('set ve=')
|
2016-05-07 12:11:36 -07:00
|
|
|
|
|
|
|
-- Test 5: several lines with words
|
2017-04-08 14:12:26 -07:00
|
|
|
command([=[call PutInWindow(['one two three', 'one two three', 'one two three'])]=])
|
2022-04-25 20:35:05 -07:00
|
|
|
eq(eval([=[
|
2016-05-07 12:11:36 -07:00
|
|
|
[['', 'one two three', 'one two three', 'one two three'], {'chars': 43, 'cursor_chars': 42, 'words': 9, 'cursor_words': 9, 'bytes': 43, 'cursor_bytes': 42}]
|
2022-04-25 20:35:05 -07:00
|
|
|
]=]),
|
|
|
|
eval('DoRecordWin([4,99,0])')
|
2016-05-07 12:11:36 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
-- Test 6: one line with BOM set
|
2017-04-08 14:12:26 -07:00
|
|
|
command([[call PutInWindow('one two three')]])
|
|
|
|
command('wincmd k')
|
|
|
|
command('set bomb')
|
|
|
|
command('wincmd j')
|
2022-04-25 20:35:05 -07:00
|
|
|
eq(eval([=[
|
2016-05-07 12:11:36 -07:00
|
|
|
[['', 'one two three'], {'chars': 15, 'cursor_chars': 14, 'words': 3, 'cursor_words': 3, 'bytes': 18, 'cursor_bytes': 14}]
|
2022-04-25 20:35:05 -07:00
|
|
|
]=]),
|
|
|
|
eval('DoRecordWin([2,99,0])')
|
2016-05-07 12:11:36 -07:00
|
|
|
)
|
2017-04-08 14:12:26 -07:00
|
|
|
command('wincmd k')
|
|
|
|
command('set nobomb')
|
|
|
|
command('wincmd j')
|
2016-05-07 12:11:36 -07:00
|
|
|
|
|
|
|
-- Test 7: one line with multibyte words
|
2017-04-08 14:12:26 -07:00
|
|
|
command([=[call PutInWindow(['Äne M¤ne Müh'])]=])
|
2022-04-25 20:35:05 -07:00
|
|
|
eq(eval([=[
|
2016-05-07 12:11:36 -07:00
|
|
|
[['', 'Äne M¤ne Müh'], {'chars': 14, 'cursor_chars': 13, 'words': 3, 'cursor_words': 3, 'bytes': 17, 'cursor_bytes': 16}]
|
2022-04-25 20:35:05 -07:00
|
|
|
]=]),
|
|
|
|
eval('DoRecordWin([2,99,0])')
|
2016-05-07 12:11:36 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
-- Test 8: several lines with multibyte words
|
2017-04-08 14:12:26 -07:00
|
|
|
command([=[call PutInWindow(['Äne M¤ne Müh', 'und raus bist dü!'])]=])
|
2022-04-25 20:35:05 -07:00
|
|
|
eq(eval([=[
|
2016-05-07 12:11:36 -07:00
|
|
|
[['', 'Äne M¤ne Müh', 'und raus bist dü!'], {'chars': 32, 'cursor_chars': 31, 'words': 7, 'cursor_words': 7, 'bytes': 36, 'cursor_bytes': 35}]
|
2022-04-25 20:35:05 -07:00
|
|
|
]=]),
|
|
|
|
eval('DoRecordWin([3,99,0])')
|
2016-05-07 12:11:36 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
-- Test 9: visual mode, complete buffer
|
2017-04-08 14:12:26 -07:00
|
|
|
command([=[call PutInWindow(['Äne M¤ne Müh', 'und raus bist dü!'])]=])
|
|
|
|
command('wincmd k')
|
|
|
|
command('set ls=2 stl=%{STL()}')
|
2016-05-07 12:11:36 -07:00
|
|
|
-- -- Start visual mode quickly and select complete buffer.
|
2017-04-08 14:12:26 -07:00
|
|
|
command('0')
|
2016-05-07 12:11:36 -07:00
|
|
|
feed('V2jy<cr>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('set stl= ls=1')
|
|
|
|
command('let log=DoRecordWin([3,99,0])')
|
|
|
|
command('let log[1]=g:visual_stat')
|
2022-04-25 20:35:05 -07:00
|
|
|
eq(eval([=[
|
2016-05-07 12:11:36 -07:00
|
|
|
[['', 'Äne M¤ne Müh', 'und raus bist dü!'], {'chars': 32, 'words': 7, 'bytes': 36, 'visual_chars': 32, 'visual_words': 7, 'visual_bytes': 36}]
|
2022-04-25 20:35:05 -07:00
|
|
|
]=]),
|
|
|
|
eval('log')
|
2016-05-07 12:11:36 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
-- Test 10: visual mode (empty)
|
2017-04-08 14:12:26 -07:00
|
|
|
command([=[call PutInWindow(['Äne M¤ne Müh', 'und raus bist dü!'])]=])
|
|
|
|
command('wincmd k')
|
|
|
|
command('set ls=2 stl=%{STL()}')
|
2016-05-07 12:11:36 -07:00
|
|
|
-- Start visual mode quickly and select complete buffer.
|
2017-04-08 14:12:26 -07:00
|
|
|
command('0')
|
2016-05-07 12:11:36 -07:00
|
|
|
feed('v$y<cr>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('set stl= ls=1')
|
|
|
|
command('let log=DoRecordWin([3,99,0])')
|
|
|
|
command('let log[1]=g:visual_stat')
|
2022-04-25 20:35:05 -07:00
|
|
|
eq(eval([=[
|
2016-05-07 12:11:36 -07:00
|
|
|
[['', 'Äne M¤ne Müh', 'und raus bist dü!'], {'chars': 32, 'words': 7, 'bytes': 36, 'visual_chars': 1, 'visual_words': 0, 'visual_bytes': 1}]
|
2022-04-25 20:35:05 -07:00
|
|
|
]=]),
|
|
|
|
eval('log')
|
2016-05-07 12:11:36 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
-- Test 11: visual mode, single line
|
2017-04-08 14:12:26 -07:00
|
|
|
command([=[call PutInWindow(['Äne M¤ne Müh', 'und raus bist dü!'])]=])
|
|
|
|
command('wincmd k')
|
|
|
|
command('set ls=2 stl=%{STL()}')
|
2016-05-07 12:11:36 -07:00
|
|
|
-- Start visual mode quickly and select complete buffer.
|
2017-04-08 14:12:26 -07:00
|
|
|
command('2')
|
2016-05-07 12:11:36 -07:00
|
|
|
feed('0v$y<cr>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('set stl= ls=1')
|
|
|
|
command('let log=DoRecordWin([3,99,0])')
|
|
|
|
command('let log[1]=g:visual_stat')
|
2022-04-25 20:35:05 -07:00
|
|
|
eq(eval([=[
|
2016-05-07 12:11:36 -07:00
|
|
|
[['', 'Äne M¤ne Müh', 'und raus bist dü!'], {'chars': 32, 'words': 7, 'bytes': 36, 'visual_chars': 13, 'visual_words': 3, 'visual_bytes': 16}]
|
2022-04-25 20:35:05 -07:00
|
|
|
]=]),
|
|
|
|
eval('log')
|
2016-05-07 12:11:36 -07:00
|
|
|
)
|
|
|
|
end)
|
|
|
|
end)
|