Skip to content

Commit

Permalink
support a directory structure/filename convention documented by google
Browse files Browse the repository at this point in the history
  • Loading branch information
burnettk committed Sep 13, 2014
1 parent 58fd7c0 commit e5d3295
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 14 additions & 5 deletions plugin/angular.vim
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,30 @@ function! s:FindFileBasedOnAngularServiceUnderCursor(cmd) abort
endif
endfunction

function! s:SubStr(originalstring, pattern, replacement) abort
return substitute(a:originalstring, a:pattern, a:replacement, "")
endfunction

function! s:GenerateTestPaths(currentpath, appbasepath, testbasepath) abort
let l:samefilename = substitute(a:currentpath, a:appbasepath, a:testbasepath, "")
let l:withcamelcasedspecsuffix = substitute(substitute(a:currentpath, a:appbasepath, a:testbasepath, ""), ".js", "Spec.js", "")
let l:withdotspecsuffix = substitute(substitute(a:currentpath, a:appbasepath, a:testbasepath, ""), ".js", ".spec.js", "")
let l:samefilename = s:SubStr(a:currentpath, a:appbasepath, a:testbasepath)
let l:withcamelcasedspecsuffix = s:SubStr(s:SubStr(a:currentpath, a:appbasepath, a:testbasepath), ".js", "Spec.js")
let l:withdotspecsuffix = s:SubStr(s:SubStr(a:currentpath, a:appbasepath, a:testbasepath), ".js", ".spec.js")
return [l:samefilename, l:withcamelcasedspecsuffix, l:withdotspecsuffix]
endfunction

function! s:GenerateSrcPaths(currentpath, appbasepath, testbasepath) abort
return [substitute(substitute(a:currentpath, a:testbasepath, a:appbasepath, ""), "Spec.js", ".js", ""),
\ substitute(substitute(a:currentpath, a:testbasepath, a:appbasepath, ""), ".spec.js", ".js", "")]
return [s:SubStr(s:SubStr(a:currentpath, a:testbasepath, a:appbasepath), "Spec.js", ".js"),
\ s:SubStr(s:SubStr(a:currentpath, a:testbasepath, a:appbasepath), ".spec.js", ".js")]
endfunction

function! s:Alternate(cmd) abort
let l:currentpath = expand('%')
let l:possiblepathsforalternatefile = []
for possiblenewpath in [s:SubStr(l:currentpath, ".js", "_test.js"), s:SubStr(l:currentpath, "_test.js", ".js")]
if possiblenewpath != l:currentpath
let l:possiblepathsforalternatefile = [possiblenewpath]
endif
endfor

if exists('g:angular_source_directory')
let l:possiblesrcpaths = [g:angular_source_directory]
Expand Down
2 changes: 2 additions & 0 deletions spec/alternate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
should_alternate_between('app/scripts/controllers/poo.js', 'test/spec/controllers/poo.js') # yoeman
should_alternate_between('public/js/controllers/piles.js', 'test/karma/unit/controllers/piles.spec.js') # mean framework
should_alternate_between('frontend/src/poo.js', 'tests/frontend/poo.spec.js') # Pull Request 6 supporting nkoehring's convention

should_alternate_between('app/components/pane/pane-directive.js', 'app/components/pane/pane-directive_test.js') # "Best Practice Recommendations for Angular App Structure" convention
end

specify "pairs that should work when src directory is configured by user" do
Expand Down

0 comments on commit e5d3295

Please sign in to comment.