From e5d329552f020e0af199fec2df1438d848282a59 Mon Sep 17 00:00:00 2001 From: burnettk Date: Sat, 13 Sep 2014 00:13:01 -0400 Subject: [PATCH] support a directory structure/filename convention documented by google --- plugin/angular.vim | 19 ++++++++++++++----- spec/alternate_spec.rb | 2 ++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/plugin/angular.vim b/plugin/angular.vim index 584dfa2..f6b2fcf 100644 --- a/plugin/angular.vim +++ b/plugin/angular.vim @@ -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] diff --git a/spec/alternate_spec.rb b/spec/alternate_spec.rb index 7e4dbc3..0c3fe1c 100644 --- a/spec/alternate_spec.rb +++ b/spec/alternate_spec.rb @@ -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