Skip to content

Commit 3f9a777

Browse files
committed
Fix :q! on test input
1 parent 798f9ce commit 3f9a777

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

autoload/leetcode.vim

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ function! s:HandleProblemListCR() abort
512512
return
513513
endif
514514

515-
if line_nr >= b:leetcode_difficulty_start_line &&
515+
if line_nr >= b:leetcode_difficulty_start_line &&
516516
\ line_nr < b:leetcode_difficulty_end_line
517517
let difficulty_slug = expand('<cWORD>')
518518
let difficulty_slug = s:TagName(difficulty_slug)
@@ -606,7 +606,7 @@ endfunction
606606
function! s:ProblemIdFromNr(nr)
607607
let content = getline(a:nr)
608608
let items = split(content, '|')
609-
if len(items) < 2
609+
if len(items) < 2
610610
return -1
611611
endif
612612
let strid = trim(items[1], ' ')
@@ -872,8 +872,7 @@ function! s:AskTestInputAndRunTest(problem, filetype, code) abort
872872
let default_test_input = s:saved_test_input[slug]
873873
else
874874
let default_test_input = ['# Test Input'] +
875-
\ split(a:problem['testcase'], '\n', 1) +
876-
\ ['', '# Delete or comment out all lines to abort']
875+
\ split(a:problem['testcase'], '\n', 1)
877876
let s:saved_test_input[slug] = default_test_input
878877
endif
879878

@@ -895,16 +894,21 @@ function! s:RunTest() abort
895894
let code = s:leetcode_code
896895
let filetype = s:leetcode_filetype
897896

898-
let test_input = getline('1', '$')
899-
let s:saved_test_input[problem['slug']] = test_input
900-
let test_input = filter(copy(test_input), 'v:val !~# s:comment_pattern')
897+
" Load the buffer from the disk. If the user executed :q!, the buffer
898+
" will be cleared since the file is empty.
899+
edit!
900+
901+
let raw_test_input = getline('1', '$')
902+
let test_input = filter(copy(raw_test_input), 'v:val !~# s:comment_pattern')
901903
let test_input = join(test_input, "\n")
902904

903905
if test_input == ''
904906
echo 'Abort testing because the test input is empty'
905907
return
906908
endif
907909

910+
let s:saved_test_input[problem['slug']] = raw_test_input
911+
908912
let args = {'problem_id': problem['id'],
909913
\ 'title': problem['title'],
910914
\ 'slug': problem['slug'],
@@ -1275,7 +1279,7 @@ function! s:FormatIntoColumns(words) abort
12751279
endif
12761280

12771281
let num_rows = float2nr(ceil(len(a:words) / num_columns))
1278-
if num_rows == 0
1282+
if num_rows == 0
12791283
let num_rows = 1
12801284
endif
12811285
let lines = []
@@ -1315,7 +1319,7 @@ function! s:UpdateSubmitState(result)
13151319
endif
13161320

13171321
for problem in problems
1318-
if problem['title'] ==# a:result['title']
1322+
if problem['title'] ==# a:result['title']
13191323
let problem['state'] = state
13201324
break
13211325
endif

0 commit comments

Comments
 (0)