Skip to content

Commit 33232eb

Browse files
committed
Let's not make testing hard: use shiftwidth() wrapper
This is also required for the old Vim on Travis!
1 parent 9035725 commit 33232eb

3 files changed

+35
-27
lines changed

tests/_setup.vader

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Execute (Setup):
2+
" so it is clear what values later tests are working with
3+
setglobal noexpandtab tabstop=8 softtabstop=0 shiftwidth=8
4+
5+
if exists('*shiftwidth')
6+
function! Shiftwidth()
7+
return shiftwidth()
8+
endfunction
9+
else
10+
Log "WARNING: shiftwidth() not available!"
11+
function! Shiftwidth()
12+
return &shiftwidth
13+
endfunction
14+
endif

tests/config-options-are-respected.vader

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
Execute (reset indent options to initial values):
2-
" so it is clear what values later tests are working with
3-
setglobal noexpandtab tabstop=8 softtabstop=0 shiftwidth=8
1+
Include: _setup.vader
42

53
Execute (g:detectindent_preferred_indent is respected):
64
let g:detectindent_preferred_indent = 4
@@ -9,7 +7,7 @@ Execute (g:detectindent_preferred_indent is respected):
97
" expect no change in expandtab
108
AssertEqual 0, &expandtab
119
" shiftwidth is 8 without the option; expect a difference
12-
AssertEqual 4, shiftwidth()
10+
AssertEqual 4, Shiftwidth()
1311
bdelete
1412
unlet g:detectindent_preferred_indent
1513

@@ -20,7 +18,7 @@ Execute (g:detectindent_min_indent is respected for space indentation):
2018
" expect no change in expandtab
2119
AssertEqual 1, &expandtab
2220
" shiftwidth is 2 without the option; expect a difference
23-
AssertEqual 4, shiftwidth()
21+
AssertEqual 4, Shiftwidth()
2422
bdelete
2523
unlet g:detectindent_min_indent
2624

@@ -31,7 +29,7 @@ Execute (g:detectindent_max_indent is respected for space indentation):
3129
" expect no change in expandtab
3230
AssertEqual 1, &expandtab
3331
" shiftwidth is 2 without the option; expect a difference
34-
AssertEqual 1, shiftwidth()
32+
AssertEqual 1, Shiftwidth()
3533
bdelete
3634
unlet g:detectindent_max_indent
3735

@@ -42,7 +40,7 @@ Execute (g:detectindent_max_indent is respected for mixed-space-and-tab indentat
4240
" expect no change in expandtab
4341
AssertEqual 0, &expandtab
4442
" shiftwidth should be 8 (though is currently 40) without the option; expect a difference
45-
AssertEqual 6, shiftwidth()
43+
AssertEqual 6, Shiftwidth()
4644
bdelete
4745
unlet g:detectindent_max_indent
4846

@@ -57,7 +55,7 @@ Execute (g:detectindent_max_indent is ignored in favor of global options for pur
5755
" expect no change in expandtab
5856
AssertEqual 0, &expandtab
5957
" expect no change in shiftwidth
60-
AssertEqual 8, shiftwidth()
58+
AssertEqual 8, Shiftwidth()
6159
bdelete
6260
unlet g:detectindent_max_indent
6361

@@ -69,7 +67,7 @@ Execute (g:detect_min_indent and max_indent, when combined, override too-low det
6967
tabnew tests/fixtures/jSnake-demo.html
7068
DetectIndent
7169
" shiftwidth is 2 without the two options; expect min_indent to be the deciding factor
72-
AssertEqual 3, shiftwidth()
70+
AssertEqual 3, Shiftwidth()
7371
unlet g:detectindent_min_indent
7472
unlet g:detectindent_max_indent
7573
bdelete
+14-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
Execute (reset indent options to initial values):
2-
" so it is clear what values later tests are working with
3-
setglobal noexpandtab tabstop=8 softtabstop=0 shiftwidth=8
4-
5-
" Compatibility warning: these tests inspect `shiftwidth()`. If you get errors because your Vim is too old to have `shiftwidth()`, replace them locally with `&shiftwidth`. I use `shiftwidth()` instead of `&shiftwidth` to support possible future usage of the 0 value for 'shiftwidth', and to make the writers of language indent plugins aware of the need to migrate from checking `&sw` to checking `shiftwidth()`.
1+
Include: _setup.vader
62

73
After:
84
" close the file that was just tested and its tab, and forget about it
@@ -15,7 +11,7 @@ Execute (Coursera-The_Hardware-Software_Interface-lab1-bits.c: expandtab):
1511
Execute (TODO: Coursera-The_Hardware-Software_Interface-lab1-bits.c: shiftwidth):
1612
tabnew tests/fixtures/Coursera-The_Hardware-Software_Interface-lab1-bits.c
1713
DetectIndent
18-
AssertEqual 2, shiftwidth()
14+
AssertEqual 2, Shiftwidth()
1915

2016
Execute (FountainMusic-FMDisplayItem.c: expandtab):
2117
tabnew tests/fixtures/FountainMusic-FMDisplayItem.c
@@ -24,55 +20,55 @@ Execute (FountainMusic-FMDisplayItem.c: expandtab):
2420
Execute (TODO: FountainMusic-FMDisplayItem.c: shiftwidth):
2521
tabnew tests/fixtures/FountainMusic-FMDisplayItem.c
2622
DetectIndent
27-
AssertEqual 8, shiftwidth()
23+
AssertEqual 8, Shiftwidth()
2824

2925
Execute (FountainMusic-FMDisplayItem.h):
3026
tabnew tests/fixtures/FountainMusic-FMDisplayItem.h
3127
DetectIndent
3228
AssertEqual 0, &expandtab
33-
AssertEqual 8, shiftwidth()
29+
AssertEqual 8, Shiftwidth()
3430

3531
Execute (GameOfLife.plaid – badly mixed indentation):
3632
tabnew tests/fixtures/GameOfLife.plaid
3733
DetectIndent
3834
AssertEqual 0, &expandtab
39-
AssertEqual 2, shiftwidth()
35+
AssertEqual 2, Shiftwidth()
4036

4137
Execute (general-level-1.indentc):
4238
tabnew tests/fixtures/general-level-1.indentc
4339
DetectIndent
4440
AssertEqual 0, &expandtab
45-
AssertEqual 8, shiftwidth()
41+
AssertEqual 8, Shiftwidth()
4642

4743
Execute (haml-action_view.haml):
4844
tabnew tests/fixtures/haml-action_view.haml
4945
DetectIndent
5046
AssertEqual 1, &expandtab
51-
AssertEqual 2, shiftwidth()
47+
AssertEqual 2, Shiftwidth()
5248

5349
Execute (haml-render_layout.haml):
5450
tabnew tests/fixtures/haml-render_layout.haml
5551
DetectIndent
5652
AssertEqual 1, &expandtab
57-
AssertEqual 2, shiftwidth()
53+
AssertEqual 2, Shiftwidth()
5854

5955
Execute (jSnake-demo.html):
6056
tabnew tests/fixtures/jSnake-demo.html
6157
DetectIndent
6258
AssertEqual 1, &expandtab
63-
AssertEqual 2, shiftwidth()
59+
AssertEqual 2, Shiftwidth()
6460

6561
Execute (jSnake-snake3.js):
6662
tabnew tests/fixtures/jSnake-snake3.js
6763
DetectIndent
6864
AssertEqual 1, &expandtab
69-
AssertEqual 2, shiftwidth()
65+
AssertEqual 2, Shiftwidth()
7066

7167
Execute (parslet-scope.rb):
7268
tabnew tests/fixtures/parslet-scope.rb
7369
DetectIndent
7470
AssertEqual 1, &expandtab
75-
AssertEqual 2, shiftwidth()
71+
AssertEqual 2, Shiftwidth()
7672

7773
Execute (TODO: semver.md – no indentation at all: expandtab):
7874
tabnew tests/fixtures/semver.md
@@ -81,7 +77,7 @@ Execute (TODO: semver.md – no indentation at all: expandtab):
8177
Execute (TODO: semver.md – no indentation at all: shiftwidth):
8278
tabnew tests/fixtures/semver.md
8379
DetectIndent
84-
AssertEqual 8, shiftwidth()
80+
AssertEqual 8, Shiftwidth()
8581

8682
Execute (starbuzz_beverage_cost_calculator-core.clj: expandtab):
8783
tabnew tests/fixtures/starbuzz_beverage_cost_calculator-core.clj
@@ -90,7 +86,7 @@ Execute (starbuzz_beverage_cost_calculator-core.clj: expandtab):
9086
Execute (TODO: starbuzz_beverage_cost_calculator-core.clj: shiftwidth):
9187
tabnew tests/fixtures/starbuzz_beverage_cost_calculator-core.clj
9288
DetectIndent
93-
AssertEqual 2, shiftwidth()
89+
AssertEqual 2, Shiftwidth()
9490

9591
Execute (vared.fish: expandtab):
9692
tabnew tests/fixtures/vared.fish
@@ -99,4 +95,4 @@ Execute (vared.fish: expandtab):
9995
Execute (TODO: vared.fish: shiftwidth):
10096
tabnew tests/fixtures/vared.fish
10197
DetectIndent
102-
AssertEqual 8, shiftwidth()
98+
AssertEqual 8, Shiftwidth()

0 commit comments

Comments
 (0)