Skip to content

Commit 5de7c75

Browse files
committed
Allow to strip highlights in tests
This makes the tests more robust, as we can now use assert_equal() instead of the weaker assert_match(). We need to strip highlights, because neovim by default always prefixes the statusline with the 'StatusLine' highlight group in nvim_eval_statusline(), which is not the case for our vim evaluation.
1 parent 731f62d commit 5de7c75

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

tests/test_general.vim

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@ func Read_socket()
2626
endif
2727
endfunc
2828

29+
func Strip_hl(s)
30+
return substitute(a:s, '#\[[^\]]*\]', '', 'g')
31+
endfunc
32+
2933
func Test_autoembed()
3034
call assert_equal('status-left "#(cat #{socket_path}-\\#{session_id}-vimbridge)"', trim(system('tmux show-options status-left')))
3135
endfunc
3236

3337
func Test_socket()
3438
let g:tpipeline_statusline = 'test'
3539
call Read_socket()
36-
call assert_match('test', s:left)
40+
call assert_equal('test', Strip_hl(s:left))
3741
endfunc
3842

3943
func Test_colors()
@@ -47,15 +51,15 @@ endfunc
4751
func Test_focusevents()
4852
let g:tpipeline_statusline = 'focused'
4953
call Read_socket()
50-
call assert_match('focused', s:left)
54+
call assert_equal('focused', Strip_hl(s:left))
5155
" lose focus
5256
call tpipeline#deferred_cleanup()
5357
call Read_socket()
54-
call assert_notmatch('focused', s:left)
58+
call assert_notequal('focused', Strip_hl(s:left))
5559
" gain focus
5660
call tpipeline#forceupdate()
5761
call Read_socket()
58-
call assert_match('focused', s:left)
62+
call assert_equal('focused', Strip_hl(s:left))
5963
endfunc
6064

6165
func Test_rapidfocus()
@@ -64,16 +68,16 @@ func Test_rapidfocus()
6468
call tpipeline#deferred_cleanup()
6569
call tpipeline#forceupdate()
6670
call Read_socket()
67-
call assert_match('focused', s:left)
71+
call assert_equal('focused', Strip_hl(s:left))
6872
endfunc
6973

7074
func Test_split()
7175
let g:tpipeline_statusline = 'LEFT%=RIGHT'
7276
call Read_socket()
73-
call assert_match('LEFT', s:left)
74-
call assert_notmatch('RIGHT', s:left)
75-
call assert_match('RIGHT', s:right)
76-
call assert_notmatch('LEFT', s:right)
77+
call assert_equal('LEFT', Strip_hl(s:left))
78+
call assert_notequal('RIGHT', Strip_hl(s:left))
79+
call assert_equal('RIGHT', Strip_hl(s:right))
80+
call assert_notequal('LEFT', Strip_hl(s:right))
7781
endfunc
7882

7983
" test that if a vim window is much smaller than the console window, that we still use the entire space available
@@ -93,8 +97,8 @@ func Test_small_pane()
9397
" This especially means that the right part is NOT empty.
9498
call Read_socket()
9599
call assert_false(empty(s:right))
96-
call assert_match(left, s:left)
97-
call assert_match(right, s:right)
100+
call assert_equal(left, Strip_hl(s:left))
101+
call assert_equal(right, Strip_hl(s:right))
98102

99103
bd!
100104
endfunc
@@ -104,8 +108,8 @@ func Test_unicode()
104108
let right = "🛠⛏🪚🔩"
105109
let g:tpipeline_statusline = "%#String#" . left . "%=%#Error#" . right
106110
call Read_socket()
107-
call assert_match(left, s:left)
108-
call assert_match(right, s:right)
111+
call assert_equal(left, Strip_hl(s:left))
112+
call assert_equal(right, Strip_hl(s:right))
109113
endfunc
110114

111115
func Test_performance()
@@ -183,11 +187,11 @@ endfunc
183187
func Test_number_evaluation()
184188
let g:tpipeline_statusline = "%{g:ReturnNumber()}"
185189
call Read_socket()
186-
call assert_match(string(g:ReturnNumber()), s:left)
190+
call assert_equal(string(g:ReturnNumber()), Strip_hl(s:left))
187191
endfunc
188192

189193
func Test_quoted_strings()
190194
let g:tpipeline_statusline = '%{eval("g:ReturnNumber()")}'
191195
call Read_socket()
192-
call assert_match(string(g:ReturnNumber()), s:left)
196+
call assert_equal(string(g:ReturnNumber()), Strip_hl(s:left))
193197
endfunc

0 commit comments

Comments
 (0)