Skip to content

Commit

Permalink
Add custom template tests and fix some bugs
Browse files Browse the repository at this point in the history
There 2 issues have been addressed:

- If the given g:pydocstring_templates_dir is not ended with a slash
'/', auto append it.

- Reduce the need for one local variable (s:tmpldir) since we always
have to use one variable to store template dir.
  • Loading branch information
Le Tien Tai committed Nov 18, 2016
1 parent ed6a468 commit 01ebb67
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 9 deletions.
15 changes: 10 additions & 5 deletions autoload/pydocstring.vim
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ let s:save_cpo = &cpo
set cpo&vim

" Path to docstring template.
if exists('g:pydocstring_templates_dir')
let s:tmpldir = g:pydocstring_templates_dir
else
let s:tmpldir = expand('<sfile>:p:h:h') . '/template/pydocstring/'
if !exists('g:pydocstring_templates_dir')
let g:pydocstring_templates_dir = expand('<sfile>:p:h:h') . '/template/pydocstring/'
endif

" Use comment.txt when cursor is not on def|class keyword.
if !exists('g:pydocstring_enable_comment')
let g:pydocstring_enable_comment = 1
Expand All @@ -31,7 +30,13 @@ let s:regexs = {
\ }

function! s:readtmpl(type)
let path = expand(s:tmpldir . a:type . '.txt')
let tmpldir = g:pydocstring_templates_dir
" Append the back slash if needed.
if g:pydocstring_templates_dir !~ '/$'
let tmpldir = tmpldir . '/'
endif

let path = expand(tmpldir . a:type . '.txt')
if !filereadable(path)
throw 'Template ' . path . ' is not exists.'
endif
Expand Down
59 changes: 55 additions & 4 deletions test/custom-template.vader
Original file line number Diff line number Diff line change
@@ -1,5 +1,56 @@
Do (Test 2):
iThis is the second test file.
# vim:set et sw=4 ts=4 tw=79:
Execute (Setup template dir):
Save g:pydocstring_templates_dir
let g:pydocstring_templates_dir = './test-template/'

Expect (Test 2):
This is the second test file.
Given python (def foo):
def foo():
pass

Execute:
Pydocstring


Expect python:
def foo():
"""foo is """
pass


Given python (def foo with 1 params):
def foo(arg1):
pass

Execute:
Pydocstring

Expect python:
def foo(arg1):
"""foo

arg1:
arg1 is
"""
pass


Given python (def foo with 2 params):
def foo(arg1, arg2):
pass

Execute:
Pydocstring

Expect python:
def foo(arg1, arg2):
"""foo

arg1:
arg1 is
arg2:
arg2 is
"""
pass

Execute (Clear pydocstring_templates_dir):
Restore

0 comments on commit 01ebb67

Please sign in to comment.