@@ -29,9 +29,10 @@ function! GetBuffer()
29
29
return join (getline (1 , ' $' ), " \n " )
30
30
endfunction
31
31
32
- function ! ClangFormat (line1, line2)
32
+ function ! ClangFormat (line1, line2, ... )
33
33
let opt = printf (" -lines=%d:%d -style='{BasedOnStyle: Google, IndentWidth: %d, UseTab: %s}' " , a: line1 , a: line2 , &l: shiftwidth , &l: expandtab== 1 ? " false" : " true" )
34
- let cmd = g: clang_format #command .opt .' ./' .s: root_dir .' t/test.cpp --'
34
+ let file = a: 0 == 0 ? ' test.cpp' : a: 1
35
+ let cmd = g: clang_format #command .opt .' ./' .s: root_dir .' t/' . file . ' --'
35
36
return Chomp (system (cmd))
36
37
endfunction
37
38
" }}}
@@ -77,13 +78,15 @@ describe 'default settings'
77
78
Expect exists (' g:clang_format#extra_args' ) to_be_true
78
79
Expect exists (' g:clang_format#code_style' ) to_be_true
79
80
Expect exists (' g:clang_format#style_options' ) to_be_true
81
+ Expect exists (' g:clang_format#filetype_style_options' ) to_be_true
80
82
Expect exists (' g:clang_format#command' ) to_be_true
81
83
Expect exists (' g:clang_format#detect_style_file' ) to_be_true
82
84
Expect exists (' g:clang_format#auto_format' ) to_be_true
83
85
Expect exists (' g:clang_format#auto_format_on_insert_leave' ) to_be_true
84
86
Expect g: clang_format #extra_args to_be_empty
85
87
Expect g: clang_format #code_style == # ' google'
86
88
Expect g: clang_format #style_options to_be_empty
89
+ Expect g: clang_format #filetype_style_options to_be_empty
87
90
Expect executable (g: clang_format #command ) to_be_true
88
91
Expect g: clang_format #detect_style_file to_be_true
89
92
end
@@ -213,41 +216,65 @@ end
213
216
" test for :ClangFormat {{{
214
217
describe ' :ClangFormat'
215
218
216
- before
217
- let g: clang_format #detect_style_file = 0
218
- new
219
- execute ' silent' ' edit!' ' ./' .s: root_dir .' t/test.cpp'
220
- end
221
-
222
- after
223
- bdelete !
224
- end
225
-
226
- it ' formats the whole code in normal mode'
227
- let by_clang_format_command = ClangFormat (1 , line (' $' ))
228
- ClangFormat
229
- let buffer = GetBuffer ()
230
- Expect by_clang_format_command == # buffer
231
- end
219
+ describe ' with filetype cpp'
220
+
221
+ before
222
+ let g: clang_format #detect_style_file = 0
223
+ new
224
+ execute ' silent' ' edit!' ' ./' .s: root_dir .' t/test.cpp'
225
+ end
226
+
227
+ after
228
+ bdelete !
229
+ end
230
+
231
+ it ' formats the whole code in normal mode'
232
+ let by_clang_format_command = ClangFormat (1 , line (' $' ))
233
+ ClangFormat
234
+ let buffer = GetBuffer ()
235
+ Expect by_clang_format_command == # buffer
236
+ end
237
+
238
+ it ' formats selected code in visual mode'
239
+ " format for statement
240
+ let by_clang_format_command = ClangFormat (11 , 13 )
241
+ " move to for statement block
242
+ execute 11
243
+ normal ! VjjV
244
+ ' <,' >ClangFormat
245
+ let buffer = GetBuffer ()
246
+ Expect by_clang_format_command == # buffer
247
+ end
248
+
249
+ it ' doesn'' t move cursor'
250
+ execute ' normal!' (1 + line (' $' )).' gg'
251
+ let pos = getpos (' .' )
252
+ ClangFormat
253
+ Expect pos == getpos (' .' )
254
+ end
255
+
256
+ end
257
+
258
+ describe ' with filetype javascript'
259
+
260
+ before
261
+ let g: clang_format #detect_style_file = 0
262
+ new
263
+ execute ' silent' ' edit!' ' ./' .s: root_dir .' t/test.js'
264
+ end
265
+
266
+ after
267
+ bdelete !
268
+ end
269
+
270
+ it ' formats the whole code in normal mode'
271
+ let by_clang_format_command = ClangFormat (1 , line (' $' ), ' test.js' )
272
+ ClangFormat
273
+ let buffer = GetBuffer ()
274
+ Expect by_clang_format_command == # buffer
275
+ end
232
276
233
- it ' formats selected code in visual mode'
234
- " format for statement
235
- let by_clang_format_command = ClangFormat (11 , 13 )
236
- " move to for statement block
237
- execute 11
238
- normal ! VjjV
239
- ' <,' >ClangFormat
240
- let buffer = GetBuffer ()
241
- Expect by_clang_format_command == # buffer
242
277
end
243
-
244
- it ' doesn'' t move cursor'
245
- execute ' normal!' (1 + line (' $' )).' gg'
246
- let pos = getpos (' .' )
247
- ClangFormat
248
- Expect pos == getpos (' .' )
249
- end
250
-
251
278
end
252
279
" }}}
253
280
0 commit comments