Skip to content

Commit a49e295

Browse files
committed
Add tests & Fix tests
1 parent 043df88 commit a49e295

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

test/scratch_buffer.vim

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,15 @@ function! s:suite.before() abort
66
endfunction
77

88
function! s:suite.before_each() abort
9-
" Clean all created scratch files
10-
for i in range(0, 100000)
11-
let file = printf(g:scratch_buffer_tmp_file_pattern, i)
12-
if !filereadable(expand(file))
13-
return
14-
endif
15-
call delete(file)
16-
endfor
9+
" Clean all created scratch files and buffers
10+
ScratchBufferCleanAllOf md
1711
endfunction
1812

1913
function! s:suite.can_make_buffer() abort
2014
ScratchBufferOpen md
2115

2216
const current_file_name = expand('%:p')
23-
const expected = printf(g:scratch_buffer_tmp_file_pattern, 0)
17+
const expected = printf(g:scratch_buffer_tmp_file_pattern, 0) .. '.md'
2418
call s:expect(current_file_name).to_equal(expected)
2519
endfunction
2620

@@ -30,7 +24,7 @@ function! s:suite.can_make_multiple_buffer() abort
3024
ScratchBufferOpen md
3125

3226
const current_file_name = expand('%:p')
33-
const expected = printf(g:scratch_buffer_tmp_file_pattern, 3)
27+
const expected = printf(g:scratch_buffer_tmp_file_pattern, 2) .. '.md'
3428
call s:expect(current_file_name).to_equal(expected)
3529
endfunction
3630

@@ -43,3 +37,36 @@ function! s:suite.accept_buffer_size() abort
4337
ScratchBufferOpen md sp 5
4438
ScratchBufferOpen md vsp 50
4539
endfunction
40+
41+
function! s:suite.wipes_opened_files_and_buffer() abort
42+
ScratchBufferOpen md
43+
write
44+
ScratchBufferOpen md
45+
46+
const all_buffer_names = scratch_buffer#helper#get_all_buffer_names()
47+
48+
const first_file = printf(g:scratch_buffer_tmp_file_pattern, 0) .. '.md'
49+
call s:expect(filereadable(first_file)).to_equal(1)
50+
call s:expect(
51+
\ all_buffer_names->scratch_buffer#helper#contains(first_file),
52+
\ ).not.to_equal(-1)
53+
54+
const second_file = printf(g:scratch_buffer_tmp_file_pattern, 0) .. '.md'
55+
call s:expect(filereadable(second_file)).not.to_equal(1)
56+
call s:expect(
57+
\ all_buffer_names->scratch_buffer#helper#contains(second_file),
58+
\ ).not.to_equal(-1)
59+
60+
" Wipe all
61+
ScratchBufferCleanAllOf
62+
const new_all_buffer_names = scratch_buffer#helper#get_all_buffer_names()
63+
64+
call s:expect(filereadable(first_file)).not.to_equal(1)
65+
call s:expect(
66+
\ new_all_buffer_names->scratch_buffer#helper#contains(first_file),
67+
\ ).not.to_equal(-1)
68+
69+
call s:expect(
70+
\ new_all_buffer_names->scratch_buffer#helper#contains(second_file),
71+
\ ).not.to_equal(-1)
72+
endfunction

0 commit comments

Comments
 (0)