vim-airline/test/builder.vimspec

108 lines
3.5 KiB
Plaintext
Raw Normal View History

2022-06-05 17:21:40 +08:00
Describe builder.vim
Describe active builder
Before each
let s:builder = airline#builder#new({'active': 1})
End
2022-10-01 11:25:47 +08:00
2022-06-05 17:21:40 +08:00
It should start with an empty statusline
let stl = s:builder.build()
Assert Equals(stl, '')
End
2022-10-01 11:25:47 +08:00
2022-06-05 17:21:40 +08:00
It should transition colors from one to the next
call s:builder.add_section('Normal', 'hello')
call s:builder.add_section('Search', 'world')
let stl = s:builder.build()
Assert Match(stl,'%#Normal#hello%#Normal_to_Search#%#Search#world')
End
2022-10-01 11:25:47 +08:00
2022-06-11 01:40:32 +08:00
It should reuse highlight group if background colors match
2022-06-05 17:21:40 +08:00
highlight Foo1 ctermfg=1 ctermbg=2
highlight Foo2 ctermfg=1 ctermbg=2
call s:builder.add_section('Foo1', 'hello')
call s:builder.add_section('Foo2', 'world')
let stl = s:builder.build()
Assert Match(stl, '%#Foo1#helloworld')
End
2022-10-01 11:25:47 +08:00
2022-06-05 17:21:40 +08:00
It should switch highlight groups if foreground colors differ
highlight Foo1 ctermfg=1 ctermbg=2
highlight Foo2 ctermfg=2 ctermbg=2
call s:builder.add_section('Foo1', 'hello')
call s:builder.add_section('Foo2', 'world')
let stl = s:builder.build()
Assert Match(stl, '%#Foo1#hello%#Foo1_to_Foo2#%#Foo2#world')
End
2022-10-01 11:25:47 +08:00
2022-06-05 17:21:40 +08:00
It should split left/right sections
call s:builder.split()
let stl = s:builder.build()
Assert Match(stl, '%=')
End
2022-10-01 11:25:47 +08:00
2022-06-05 17:21:40 +08:00
It after split, sections use the right separator
call s:builder.split()
call s:builder.add_section('Normal', 'hello')
call s:builder.add_section('Search', 'world')
let stl = s:builder.build()
Assert Match(stl, 'hello%#Normal_to_Search#%#Search#world')
End
2022-10-01 11:25:47 +08:00
2022-06-05 17:21:40 +08:00
It should not repeat the same highlight group
call s:builder.add_section('Normal', 'hello')
call s:builder.add_section('Normal', 'hello')
let stl = s:builder.build()
Assert Match(stl, '%#Normal#hellohello')
End
2022-10-01 11:25:47 +08:00
2022-06-05 17:21:40 +08:00
It should replace accent groups with the specified group
call s:builder.add_section('Normal', '%#__accent_foo#hello')
let stl = s:builder.build()
Assert Match(stl, '%#Normal#%#Normal_foo#hello')
End
2022-10-01 11:25:47 +08:00
2022-06-05 17:21:40 +08:00
It should replace two accent groups with correct groups
call s:builder.add_section('Normal', '%#__accent_foo#hello%#__accent_bar#world')
let stl = s:builder.build()
Assert Match(stl, '%#Normal_foo#hello%#Normal_bar#world')
End
2022-10-01 11:25:47 +08:00
2022-06-05 17:21:40 +08:00
It should special restore group should go back to previous group
call s:builder.add_section('Normal', '%#__restore__#')
let stl = s:builder.build()
Assert NotMatch(stl, '%#__restore__#')
Assert Match(stl, '%#Normal#')
End
2022-10-01 11:25:47 +08:00
2022-06-05 17:21:40 +08:00
It should blend colors from the left through the split to the right
call s:builder.add_section('Normal', 'hello')
call s:builder.split()
call s:builder.add_section('Search', 'world')
let stl = s:builder.build()
Assert Match(stl, 'Normal_to_Search')
End
End
Describe inactive builder
Before each
let s:builder = airline#builder#new({'active': 0})
End
It should transition colors from one to the next
call s:builder.add_section('Normal', 'hello')
call s:builder.add_section('Search', 'world')
let stl = s:builder.build()
Assert Match(stl, '%#Normal_inactive#hello%#Normal_to_Search_inactive#%#Search_inactive#world')
End
It should not render accents
call s:builder.add_section('Normal', '%#__accent_foo#hello%#foo#foo%#__accent_bar#world')
let stl = s:builder.build()
Assert Equals(stl, '%#Normal_inactive#hello%#foo_inactive#fooworld')
End
End
End