Skip to content

Commit ca25dac

Browse files
committed
Fix burnettk#15. Support 1) convention with test dir and 2) custom path arrays
1 parent d2c66a8 commit ca25dac

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

plugin/angular.vim

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,39 @@ endfunction
155155
function! s:Alternate(cmd) abort
156156
let l:currentpath = expand('%')
157157
let l:possiblepathsforalternatefile = []
158+
158159
for possiblenewpath in [s:SubStr(l:currentpath, ".js", "_test.js"), s:SubStr(l:currentpath, "_test.js", ".js")]
159160
if possiblenewpath != l:currentpath
160-
let l:possiblepathsforalternatefile = [possiblenewpath]
161+
let l:possiblepathsforalternatefile = l:possiblepathsforalternatefile + [possiblenewpath]
161162
endif
162163
endfor
163164

165+
" handle a test subdirectory just above the leaf node
166+
let l:possiblenewpath = s:SubStr(l:currentpath, "/test/", "/")
167+
if possiblenewpath != l:currentpath
168+
let l:possiblepathsforalternatefile = l:possiblepathsforalternatefile + [s:SubStr(possiblenewpath, '.spec.js', '.js')]
169+
else
170+
let l:lastslashindex = strridx(l:currentpath, '/')
171+
let l:possibletestpath = strpart(l:currentpath, 0, l:lastslashindex) . '/test' . s:SubStr(strpart(l:currentpath, l:lastslashindex), '.js', '.spec.js')
172+
let l:possiblepathsforalternatefile = l:possiblepathsforalternatefile + [l:possibletestpath]
173+
endif
174+
164175
if exists('g:angular_source_directory')
165-
let l:possiblesrcpaths = [g:angular_source_directory]
176+
if type(g:angular_source_directory) == type([])
177+
let l:possiblesrcpaths = g:angular_source_directory
178+
else
179+
let l:possiblesrcpaths = [g:angular_source_directory]
180+
endif
166181
else
167182
let l:possiblesrcpaths = ['app/src', 'app/js', 'app/scripts', 'public/js', 'frontend/src']
168183
endif
169184

170185
if exists('g:angular_test_directory')
171-
let l:possibletestpaths = [g:angular_test_directory]
186+
if type(g:angular_test_directory) == type([])
187+
let l:possibletestpaths = g:angular_test_directory
188+
else
189+
let l:possibletestpaths = [g:angular_test_directory]
190+
endif
172191
else
173192
let l:possibletestpaths = ['test/unit', 'test/spec', 'test/karma/unit', 'tests/frontend']
174193
endif

spec/alternate_spec.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
should_alternate_between('app/js/poo.js', 'test/spec/poo.spec.js')
2424
should_alternate_between('app/js/poo.js', 'test/spec/pooSpec.js')
2525

26+
should_alternate_between('app/foo/foo.controller.js', 'app/foo/test/foo.controller.spec.js')
27+
should_alternate_between('app/bar/bar.service.js', 'app/bar/test/bar.service.spec.js')
28+
2629
should_alternate_between('app/scripts/controllers/poo.js', 'test/spec/controllers/poo.js') # yoeman
2730
should_alternate_between('public/js/controllers/piles.js', 'test/karma/unit/controllers/piles.spec.js') # mean framework
2831
should_alternate_between('frontend/src/poo.js', 'tests/frontend/poo.spec.js') # Pull Request 6 supporting nkoehring's convention
@@ -42,7 +45,14 @@
4245
should_alternate_between('WebContent/js/poo.js', 'test/spec/pooSpec.js')
4346
end
4447

45-
specify "pairs that should work when test directory is configured by user" do
48+
specify "with multiple src directories configured by user" do
49+
assume_vimrc 'let g:angular_source_directory = ["WebContent/js", "app/src"]'
50+
51+
should_alternate_between('WebContent/js/poo.js', 'test/unit/poo.js')
52+
should_alternate_between('app/src/poo.js', 'test/unit/pooSpec.js')
53+
end
54+
55+
specify "pairs that should work when one test directory is configured by user" do
4656
assume_vimrc 'let g:angular_test_directory = "test/units"'
4757

4858
should_alternate_between('app/js/poo.js', 'test/units/poo.js')
@@ -54,6 +64,13 @@
5464
should_alternate_between('app/src/poo.js', 'test/units/pooSpec.js')
5565
end
5666

67+
specify "with multiple test directories configured by user" do
68+
assume_vimrc 'let g:angular_test_directory = ["test/unit", "test/spec"]'
69+
70+
should_alternate_between('app/js/poo.js', 'test/unit/poo.js')
71+
should_alternate_between('app/src/poo.js', 'test/spec/pooSpec.js')
72+
end
73+
5774
specify "pairs should not all work" do
5875
file_a = 'app/junk/poo.js'
5976
file_b = 'test/unit/poo.js'

0 commit comments

Comments
 (0)