Skip to content

Commit e5d3295

Browse files
committed
support a directory structure/filename convention documented by google
1 parent 58fd7c0 commit e5d3295

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

plugin/angular.vim

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,30 @@ function! s:FindFileBasedOnAngularServiceUnderCursor(cmd) abort
131131
endif
132132
endfunction
133133

134+
function! s:SubStr(originalstring, pattern, replacement) abort
135+
return substitute(a:originalstring, a:pattern, a:replacement, "")
136+
endfunction
137+
134138
function! s:GenerateTestPaths(currentpath, appbasepath, testbasepath) abort
135-
let l:samefilename = substitute(a:currentpath, a:appbasepath, a:testbasepath, "")
136-
let l:withcamelcasedspecsuffix = substitute(substitute(a:currentpath, a:appbasepath, a:testbasepath, ""), ".js", "Spec.js", "")
137-
let l:withdotspecsuffix = substitute(substitute(a:currentpath, a:appbasepath, a:testbasepath, ""), ".js", ".spec.js", "")
139+
let l:samefilename = s:SubStr(a:currentpath, a:appbasepath, a:testbasepath)
140+
let l:withcamelcasedspecsuffix = s:SubStr(s:SubStr(a:currentpath, a:appbasepath, a:testbasepath), ".js", "Spec.js")
141+
let l:withdotspecsuffix = s:SubStr(s:SubStr(a:currentpath, a:appbasepath, a:testbasepath), ".js", ".spec.js")
138142
return [l:samefilename, l:withcamelcasedspecsuffix, l:withdotspecsuffix]
139143
endfunction
140144

141145
function! s:GenerateSrcPaths(currentpath, appbasepath, testbasepath) abort
142-
return [substitute(substitute(a:currentpath, a:testbasepath, a:appbasepath, ""), "Spec.js", ".js", ""),
143-
\ substitute(substitute(a:currentpath, a:testbasepath, a:appbasepath, ""), ".spec.js", ".js", "")]
146+
return [s:SubStr(s:SubStr(a:currentpath, a:testbasepath, a:appbasepath), "Spec.js", ".js"),
147+
\ s:SubStr(s:SubStr(a:currentpath, a:testbasepath, a:appbasepath), ".spec.js", ".js")]
144148
endfunction
145149

146150
function! s:Alternate(cmd) abort
147151
let l:currentpath = expand('%')
148152
let l:possiblepathsforalternatefile = []
153+
for possiblenewpath in [s:SubStr(l:currentpath, ".js", "_test.js"), s:SubStr(l:currentpath, "_test.js", ".js")]
154+
if possiblenewpath != l:currentpath
155+
let l:possiblepathsforalternatefile = [possiblenewpath]
156+
endif
157+
endfor
149158

150159
if exists('g:angular_source_directory')
151160
let l:possiblesrcpaths = [g:angular_source_directory]

spec/alternate_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
should_alternate_between('app/scripts/controllers/poo.js', 'test/spec/controllers/poo.js') # yoeman
2727
should_alternate_between('public/js/controllers/piles.js', 'test/karma/unit/controllers/piles.spec.js') # mean framework
2828
should_alternate_between('frontend/src/poo.js', 'tests/frontend/poo.spec.js') # Pull Request 6 supporting nkoehring's convention
29+
30+
should_alternate_between('app/components/pane/pane-directive.js', 'app/components/pane/pane-directive_test.js') # "Best Practice Recommendations for Angular App Structure" convention
2931
end
3032

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

0 commit comments

Comments
 (0)