Skip to content

Commit

Permalink
fix assumed filename is empty (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Apr 9, 2017
1 parent 3b0b1c8 commit 890ca5d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions autoload/clang_format.vim
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ endfunction
function! s:success(result)
return (s:has_vimproc() ? vimproc#get_last_status() : v:shell_error) == 0
\ && a:result !~# '^YAML:\d\+:\d\+: error: unknown key '
\ && a:result !~# '^\n\?$'
endfunction

function! s:error_message(result)
Expand Down Expand Up @@ -193,7 +192,10 @@ function! clang_format#format(line1, line2)
else
let args .= ' -style=file '
endif
let args .= printf('-assume-filename=%s ', s:shellescape(escape(expand('%'), " \t")))
let filename = expand('%')
if filename !=# ''
let args .= printf('-assume-filename=%s ', s:shellescape(escape(filename, " \t")))
endif
let args .= g:clang_format#extra_args
let clang_format = printf('%s %s --', s:shellescape(g:clang_format#command), args)
return s:system(clang_format, join(getline(1, '$'), "\n"))
Expand Down
24 changes: 24 additions & 0 deletions t/clang_format_spec.vim
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ describe 'g:clang_format#auto_formatexpr'
end
" }}}

" test for undo {{{
describe 'undo formatting text'
before
let g:clang_format#detect_style_file = 0
Expand All @@ -443,3 +444,26 @@ describe 'undo formatting text'
Expect prev ==# buf
end
end
" }}}

" test for empty buffer {{{
describe 'empty buffer'
before
let g:clang_format#detect_style_file = 0
new
end

after
bdelete!
end

it 'can format empty buffer'
ClangFormat
end

it 'can format a buffer containing only new lines'
call setline('.', ['', '', ''])
ClangFormat
end
end
" }}}"

0 comments on commit 890ca5d

Please sign in to comment.