diff --git a/.gitignore b/.gitignore index 926ccaaf..296f094e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ doc/tags +*.lock +.vim-flavor diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..9ed483e7 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: ruby +rvm: + - 1.9.3 +script: rake ci diff --git a/Gemfile b/Gemfile new file mode 100644 index 00000000..088f22e3 --- /dev/null +++ b/Gemfile @@ -0,0 +1,2 @@ +source 'https://rubygems.org' +gem 'vim-flavor', '~> 1.1' diff --git a/README.md b/README.md index 9c1b80c1..b39209b2 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ Lean & mean statusline for vim that's light as air. * Supports 7.2 as the minimum Vim version. * Stable release cycle; bleeding edge changes happen on the `dev` branch, and after they have gone through a [full regression test][33] will eventually be merged in the stable master branch. Releases typically occur every 2 weeks. +[![Build Status](https://travis-ci.org/bling/vim-airline.png)](https://travis-ci.org/bling/vim-airline) + ## Straightforward customization If you don't like the defaults, you can replace all sections with standard `statusline` syntax. Give your statusline that you've built over the years a face lift. diff --git a/Rakefile b/Rakefile new file mode 100644 index 00000000..741cfc25 --- /dev/null +++ b/Rakefile @@ -0,0 +1,14 @@ +#!/usr/bin/env rake + +task :default => [:test] + +task :ci => [:dump, :test] + +task :dump do + sh 'vim --version' +end + +task :test do + sh 'bundle exec vim-flavor test' +end + diff --git a/autoload/airline/extensions/branch.vim b/autoload/airline/extensions/branch.vim index a746ea60..0aa3da50 100644 --- a/autoload/airline/extensions/branch.vim +++ b/autoload/airline/extensions/branch.vim @@ -27,10 +27,12 @@ function! airline#extensions#branch#get_head() endif endif - return empty(head) ? s:empty_message : s:symbol.' '.head + return empty(head) + \ ? s:empty_message + \ : printf('%s%s', empty(s:symbol) ? '' : s:symbol.' ', head) endfunction function! airline#extensions#branch#init(ext) - let g:airline_parts.branch = '%{airline#extensions#branch#get_head()}' + call airline#parts#define_function('branch', 'airline#extensions#branch#get_head') endfunction diff --git a/autoload/airline/extensions/bufferline.vim b/autoload/airline/extensions/bufferline.vim index 4a6e014d..cc13ec0d 100644 --- a/autoload/airline/extensions/bufferline.vim +++ b/autoload/airline/extensions/bufferline.vim @@ -14,5 +14,6 @@ function! airline#extensions#bufferline#init(ext) let g:bufferline_separator = ' ' endif - let g:airline_parts.file = '%{bufferline#refresh_status()}'.bufferline#get_status_string() + call airline#parts#define_raw('file', '%{bufferline#refresh_status()}'.bufferline#get_status_string()) endfunction + diff --git a/autoload/airline/extensions/example.vim b/autoload/airline/extensions/example.vim index d522bd68..0f571f22 100644 --- a/autoload/airline/extensions/example.vim +++ b/autoload/airline/extensions/example.vim @@ -11,7 +11,7 @@ function! airline#extensions#example#init(ext) " Here we define a new part for the plugin. This allows users to place this " extension in arbitrary locations. - let g:airline_parts.cats = '%{airline#extensions#example#get_cats()}' + call airline#parts#define_raw('cats', '%{airline#extensions#example#get_cats()}') " Next up we add a funcref so that we can run some code prior to the " statusline getting modifed. @@ -28,7 +28,7 @@ function! airline#extensions#example#apply(...) " Let's use a helper function. It will take care of ensuring that the " window-local override exists (and create one based on the global " airline_section if not), and prepend to it. - call airline#extensions#prepend_to_section('x', g:airline_parts.cats) + call airline#extensions#prepend_to_section('x', airline#parts#get('cats').raw) endif endfunction diff --git a/autoload/airline/extensions/hunks.vim b/autoload/airline/extensions/hunks.vim index 66403b14..803dfafe 100644 --- a/autoload/airline/extensions/hunks.vim +++ b/autoload/airline/extensions/hunks.vim @@ -54,6 +54,6 @@ function! airline#extensions#hunks#get_hunks() endfunction function! airline#extensions#hunks#init(ext) - let g:airline_parts.hunks = '%{airline#extensions#hunks#get_hunks()}' + call airline#parts#define_function('hunks', 'airline#extensions#hunks#get_hunks') endfunction diff --git a/autoload/airline/extensions/syntastic.vim b/autoload/airline/extensions/syntastic.vim index 24308c53..a91ec664 100644 --- a/autoload/airline/extensions/syntastic.vim +++ b/autoload/airline/extensions/syntastic.vim @@ -10,6 +10,6 @@ function! airline#extensions#syntastic#get_warnings() endfunction function! airline#extensions#syntastic#init(ext) - let g:airline_parts.syntastic = '%{airline#extensions#syntastic#get_warnings()}' + call airline#parts#define_function('syntastic', 'airline#extensions#syntastic#get_warnings') endfunction diff --git a/autoload/airline/extensions/tagbar.vim b/autoload/airline/extensions/tagbar.vim index bf7efee9..214d443e 100644 --- a/autoload/airline/extensions/tagbar.vim +++ b/autoload/airline/extensions/tagbar.vim @@ -16,11 +16,17 @@ function! airline#extensions#tagbar#inactive_apply(...) endif endfunction +function! airline#extensions#tagbar#currenttag() + if get(w:, 'airline_active', 0) + return tagbar#currenttag('%s', '') + endif + return '' +endfunction + function! airline#extensions#tagbar#init(ext) call a:ext.add_inactive_statusline_func('airline#extensions#tagbar#inactive_apply') let g:tagbar_status_func = 'airline#extensions#tagbar#get_status' - let g:airline_parts.tagbar = '%(%{get(w:,"airline_active",0) ? tagbar#currenttag("%s","") : ""} ' - \ .g:airline_right_alt_sep.' %)' + call airline#parts#define_function('tagbar', 'airline#extensions#tagbar#currenttag') endfunction diff --git a/autoload/airline/extensions/whitespace.vim b/autoload/airline/extensions/whitespace.vim index 0aa8fbe2..3766f4ea 100644 --- a/autoload/airline/extensions/whitespace.vim +++ b/autoload/airline/extensions/whitespace.vim @@ -56,6 +56,7 @@ endfunction! function! airline#extensions#whitespace#toggle() if s:enabled autocmd! airline_whitespace CursorHold,BufWritePost + augroup! airline_whitespace let s:enabled = 0 else call airline#extensions#whitespace#init() @@ -65,7 +66,7 @@ function! airline#extensions#whitespace#toggle() endfunction function! airline#extensions#whitespace#init(...) - let g:airline_parts.whitespace = '%{airline#extensions#whitespace#check()}' + call airline#parts#define_function('whitespace', 'airline#extensions#whitespace#check') unlet! b:airline_whitespace_check augroup airline_whitespace diff --git a/autoload/airline/init.vim b/autoload/airline/init.vim new file mode 100644 index 00000000..50551f40 --- /dev/null +++ b/autoload/airline/init.vim @@ -0,0 +1,94 @@ +" MIT License. Copyright (c) 2013 Bailey Ling. +" vim: et ts=2 sts=2 sw=2 + +function! s:check_defined(variable, default) + if !exists(a:variable) + let {a:variable} = a:default + endif +endfunction + +function! airline#init#bootstrap() + call s:check_defined('g:airline_left_sep', get(g:, 'airline_powerline_fonts', 0)?"":">") + call s:check_defined('g:airline_left_alt_sep', get(g:, 'airline_powerline_fonts', 0)?"":">") + call s:check_defined('g:airline_right_sep', get(g:, 'airline_powerline_fonts', 0)?"":"<") + call s:check_defined('g:airline_right_alt_sep', get(g:, 'airline_powerline_fonts', 0)?"":"<") + call s:check_defined('g:airline_detect_modified', 1) + call s:check_defined('g:airline_detect_paste', 1) + call s:check_defined('g:airline_detect_iminsert', 0) + call s:check_defined('g:airline_inactive_collapse', 1) + call s:check_defined('g:airline_exclude_filenames', ['DebuggerWatch','DebuggerStack','DebuggerStatus']) + call s:check_defined('g:airline_exclude_filetypes', []) + call s:check_defined('g:airline_exclude_preview', 0) + + call s:check_defined('g:airline_mode_map', {}) + call extend(g:airline_mode_map, { + \ '__' : '------', + \ 'n' : 'NORMAL', + \ 'i' : 'INSERT', + \ 'R' : 'REPLACE', + \ 'v' : 'VISUAL', + \ 'V' : 'V-LINE', + \ 'c' : 'COMMAND', + \ '' : 'V-BLOCK', + \ 's' : 'SELECT', + \ 'S' : 'S-LINE', + \ '' : 'S-BLOCK', + \ }, 'keep') + + call s:check_defined('g:airline_theme_map', {}) + call extend(g:airline_theme_map, { + \ 'Tomorrow.*': 'tomorrow', + \ 'mo[l|n]okai': 'molokai', + \ 'wombat.*': 'wombat', + \ '.*solarized.*': 'solarized', + \ }, 'keep') + + call s:check_defined('g:airline_symbols', {}) + call extend(g:airline_symbols, { + \ 'paste': get(g:, 'airline_paste_symbol', 'PASTE'), + \ 'readonly': get(g:, 'airline_readonly_symbol', get(g:, 'airline_powerline_fonts', 0) ? '' : 'RO'), + \ 'whitespace': get(g:, 'airline_powerline_fonts', 0) ? '✹' : '!', + \ 'linenr': get(g:, 'airline_linecolumn_prefix', get(g:, 'airline_powerline_fonts', 0) ? '' : ':' ), + \ 'branch': get(g:, 'airline_branch_prefix', get(g:, 'airline_powerline_fonts', 0) ? '' : ''), + \ }, 'keep') + + call airline#parts#define_function('mode', 'airline#parts#mode') + call airline#parts#define_function('iminsert', 'airline#parts#iminsert') + call airline#parts#define_function('paste', 'airline#parts#paste') + call airline#parts#define('readonly', { + \ 'function': 'airline#parts#readonly', + \ 'highlight': 'airline_file', + \ }) + call airline#parts#define_raw('file', '%f%m') + call airline#parts#define_raw('ffenc', '%{printf("%s%s",&fenc,strlen(&ff)>0?"[".&ff."]":"")}') + + call airline#parts#define_empty(['hunks', 'branch', 'tagbar', 'syntastic']) + + call airline#extensions#load() + + if !exists('g:airline_section_a') + let g:airline_section_a = airline#section#create_left(['mode', 'paste', 'iminsert']) + endif + if !exists('g:airline_section_b') + let g:airline_section_b = airline#section#create(['hunks', 'branch']) + endif + if !exists('g:airline_section_c') + let g:airline_section_c = airline#section#create(['%<', 'file']) + endif + if !exists('g:airline_section_gutter') + let g:airline_section_gutter = airline#section#create([' ', 'readonly', '%=']) + endif + if !exists('g:airline_section_x') + let g:airline_section_x = airline#section#create_right(['tagbar', '%{&filetype}']) + endif + if !exists('g:airline_section_y') + let g:airline_section_y = airline#section#create_right(['ffenc']) + endif + if !exists('g:airline_section_z') + let g:airline_section_z = airline#section#create_right(['%3p%% %{g:airline_symbols.linenr} %3l:%3c ']) + endif + if !exists('g:airline_section_warning') + let g:airline_section_warning = airline#section#create(['syntastic', 'whitespace']) + endif +endfunction + diff --git a/autoload/airline/parts.vim b/autoload/airline/parts.vim index 0c7ece9d..39041f8d 100644 --- a/autoload/airline/parts.vim +++ b/autoload/airline/parts.vim @@ -1,13 +1,46 @@ " MIT License. Copyright (c) 2013 Bailey Ling. " vim: et ts=2 sts=2 sw=2 +let s:parts = {} + +function! airline#parts#define(key, config) + let s:parts[a:key] = get(s:parts, a:key, {}) + call extend(s:parts[a:key], a:config) +endfunction + +function! airline#parts#define_function(key, name) + call airline#parts#define(a:key, { 'function': a:name }) +endfunction + +function! airline#parts#define_text(key, text) + call airline#parts#define(a:key, { 'text': a:text }) +endfunction + +function! airline#parts#define_raw(key, raw) + call airline#parts#define(a:key, { 'raw': a:raw }) +endfunction + +function! airline#parts#define_empty(keys) + for key in a:keys + call airline#parts#define_raw(key, '') + endfor +endfunction + +function! airline#parts#get(key) + return get(s:parts, a:key, {}) +endfunction + +function! airline#parts#mode() + return get(w:, 'airline_current_mode', '') +endfunction + function! airline#parts#paste() - return g:airline_detect_paste && &paste ? ' '.g:airline_symbols.paste : '' + return g:airline_detect_paste && &paste ? g:airline_symbols.paste : '' endfunction function! airline#parts#iminsert() if g:airline_detect_iminsert && &iminsert && exists('b:keymap_name') - return ' '.g:airline_left_alt_sep.' '.toupper(b:keymap_name) + return toupper(b:keymap_name) endif return '' endfunction diff --git a/autoload/airline/section.vim b/autoload/airline/section.vim new file mode 100644 index 00000000..1c7e7897 --- /dev/null +++ b/autoload/airline/section.vim @@ -0,0 +1,52 @@ +" MIT License. Copyright (c) 2013 Bailey Ling. +" vim: et ts=2 sts=2 sw=2 + +function! s:get_val(key, append) + let part = airline#parts#get(a:key) + + let val = '' + if exists('part.highlight') + let val .= '%#'.(part.highlight).'#' + endif + + if exists('part.function') + let func = (part.function).'()' + elseif exists('part.text') + let func = '"'.(part.text).'"' + elseif exists('part.raw') + return val.(part.raw) + else + return a:key + endif + + if a:append > 0 + let val .= '%{airline#util#append('.func.')}' + elseif a:append < 0 + let val .= '%{airline#util#prepend('.func.')}' + else + let val .= '%{'.func.'}' + endif + return val +endfunction + +function! airline#section#create(parts) + return join(map(a:parts, 's:get_val(v:val, 0)'), '') +endfunction + +function! airline#section#create_left(parts) + let _ = s:get_val(a:parts[0], 0) + for i in range(1, len(a:parts) - 1) + let _ .= s:get_val(a:parts[i], 1) + endfor + return _ +endfunction + +function! airline#section#create_right(parts) + let _ = '' + for i in range(0, len(a:parts) - 2) + let _ .= s:get_val(a:parts[i], -1) + endfor + let _ .= s:get_val(a:parts[-1], 0) + return _ +endfunction + diff --git a/autoload/airline/util.vim b/autoload/airline/util.vim index 35816989..e7b27f8d 100644 --- a/autoload/airline/util.vim +++ b/autoload/airline/util.vim @@ -1,6 +1,14 @@ " MIT License. Copyright (c) 2013 Bailey Ling. " vim: et ts=2 sts=2 sw=2 +function! airline#util#append(text) + return empty(a:text) ? '' : ' '.g:airline_left_alt_sep.' '.a:text +endfunction + +function! airline#util#prepend(text) + return empty(a:text) ? '' : a:text.' '.g:airline_right_alt_sep.' ' +endfunction + if v:version >= 704 function! airline#util#getwinvar(winnr, key, def) return getwinvar(a:winnr, a:key, a:def) diff --git a/doc/airline.txt b/doc/airline.txt index 9bf7ef0e..1b05d7b8 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -391,9 +391,6 @@ For contributions into the plugin, here are the following guidelines: b. Configuration variables for the extension should reside in the extension, e.g. `g:airline#extensions#foo_plugin#bar_variable`. - c. A value should be added to the `g:airline_parts` dictionary such that - the extension can be arbitrarily positioned. - See the source of |example.vim| for a working extension. ============================================================================== diff --git a/plugin/airline.vim b/plugin/airline.vim index 0547d4d1..055c065a 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -8,86 +8,13 @@ let g:loaded_airline = 1 " autocmd VimEnter * call airline#deprecation#check() -function! s:check_defined(variable, default) - if !exists(a:variable) - let {a:variable} = a:default - endif -endfunction - let s:airline_initialized = 0 let s:airline_theme_defined = 0 function! s:init() if !s:airline_initialized let s:airline_initialized = 1 - call s:check_defined('g:airline_left_sep', get(g:, 'airline_powerline_fonts', 0)?"":">") - call s:check_defined('g:airline_left_alt_sep', get(g:, 'airline_powerline_fonts', 0)?"":">") - call s:check_defined('g:airline_right_sep', get(g:, 'airline_powerline_fonts', 0)?"":"<") - call s:check_defined('g:airline_right_alt_sep', get(g:, 'airline_powerline_fonts', 0)?"":"<") - call s:check_defined('g:airline_detect_modified', 1) - call s:check_defined('g:airline_detect_paste', 1) - call s:check_defined('g:airline_detect_iminsert', 0) - call s:check_defined('g:airline_inactive_collapse', 1) - call s:check_defined('g:airline_exclude_filenames', ['DebuggerWatch','DebuggerStack','DebuggerStatus']) - call s:check_defined('g:airline_exclude_filetypes', []) - call s:check_defined('g:airline_exclude_preview', 0) - - call s:check_defined('g:airline_symbols', {}) - call extend(g:airline_symbols, { - \ 'paste': get(g:, 'airline_paste_symbol', g:airline_left_alt_sep.' PASTE'), - \ 'readonly': get(g:, 'airline_readonly_symbol', get(g:, 'airline_powerline_fonts', 0) ? '' : 'RO'), - \ 'whitespace': get(g:, 'airline_powerline_fonts', 0) ? '✹' : '!', - \ 'linenr': get(g:, 'airline_linecolumn_prefix', get(g:, 'airline_powerline_fonts', 0) ? '' : ':' ), - \ 'branch': get(g:, 'airline_branch_prefix', get(g:, 'airline_powerline_fonts', 0) ? '' : ''), - \ }, 'keep') - - call s:check_defined('g:airline_parts', {}) - call extend(g:airline_parts, { - \ 'mode': '%{get(w:,"airline_current_mode","")}', - \ 'iminsert': '%{airline#parts#iminsert()}', - \ 'paste': '%{airline#parts#paste()}', - \ 'readonly': '%#airline_file#%{airline#parts#readonly()}', - \ 'ffenc': '%{printf("%s%s",&fenc,strlen(&ff)>0?"[".&ff."]":"")}', - \ 'file': '%f%m', - \ 'hunks': '', - \ 'branch': '', - \ 'tagbar': '', - \ 'syntastic': '', - \ 'whitespace': '', - \ }, 'keep') - - call s:check_defined('g:airline_mode_map', {}) - call extend(g:airline_mode_map, { - \ '__' : '------', - \ 'n' : 'NORMAL', - \ 'i' : 'INSERT', - \ 'R' : 'REPLACE', - \ 'v' : 'VISUAL', - \ 'V' : 'V-LINE', - \ 'c' : 'COMMAND', - \ '' : 'V-BLOCK', - \ 's' : 'SELECT', - \ 'S' : 'S-LINE', - \ '' : 'S-BLOCK', - \ }, 'keep') - - call s:check_defined('g:airline_theme_map', {}) - call extend(g:airline_theme_map, { - \ 'Tomorrow.*': 'tomorrow', - \ 'mo[l|n]okai': 'molokai', - \ 'wombat.*': 'wombat', - \ '.*solarized.*': 'solarized', - \ }, 'keep') - - call airline#extensions#load() - call s:check_defined('g:airline_section_a', (g:airline_parts.mode).(g:airline_parts.paste).(g:airline_parts.iminsert)) - call s:check_defined('g:airline_section_b', (g:airline_parts.hunks).(g:airline_parts.branch)) - call s:check_defined('g:airline_section_c', '%<'.(g:airline_parts.file)) - call s:check_defined('g:airline_section_gutter', ' '.(g:airline_parts.readonly).'%=') - call s:check_defined('g:airline_section_x', (g:airline_parts.tagbar).'%{&filetype}') - call s:check_defined('g:airline_section_y', g:airline_parts.ffenc) - call s:check_defined('g:airline_section_z', '%3p%% %{g:airline_symbols.linenr} %3l:%3c ') - call s:check_defined('g:airline_section_warning', (g:airline_parts.syntastic).(g:airline_parts.whitespace)) + call airline#init#bootstrap() let s:airline_theme_defined = exists('g:airline_theme') if s:airline_theme_defined || !airline#switch_matching_theme() @@ -127,47 +54,48 @@ function! s:airline_toggle() au! augroup END augroup! airline - if exists("s:stl") - let &stl = s:stl - endif - else - let s:stl = &stl - augroup airline - autocmd! - autocmd CmdwinEnter * - \ call airline#add_statusline_func('airline#cmdwinenter') - \ | call on_window_changed() - autocmd CmdwinLeave * call airline#remove_statusline_func('airline#cmdwinenter') - - autocmd ColorScheme * call on_colorscheme_changed() - autocmd WinEnter,BufWinEnter,FileType,BufUnload,ShellCmdPost,VimResized * - \ call on_window_changed() - - autocmd BufWritePost */autoload/airline/themes/*.vim - \ exec 'source '.split(globpath(&rtp, 'autoload/airline/themes/'.g:airline_theme.'.vim', 1), "\n")[0] - \ | call airline#load_theme() - augroup END - if s:airline_initialized - call on_window_changed() - endif + if exists("s:stl") + let &stl = s:stl endif - endfunction + else + let s:stl = &stl + augroup airline + autocmd! - function! s:get_airline_themes(a, l, p) - let files = split(globpath(&rtp, 'autoload/airline/themes/'.a:a.'*'), "\n") - return map(files, 'fnamemodify(v:val, ":t:r")') - endfunction - function! s:airline_theme(...) - if a:0 - call airline#switch_theme(a:1) - else - echo g:airline_theme + autocmd CmdwinEnter * + \ call airline#add_statusline_func('airline#cmdwinenter') + \ | call on_window_changed() + autocmd CmdwinLeave * call airline#remove_statusline_func('airline#cmdwinenter') + + autocmd ColorScheme * call on_colorscheme_changed() + autocmd WinEnter,BufWinEnter,FileType,BufUnload,ShellCmdPost,VimResized * + \ call on_window_changed() + + autocmd BufWritePost */autoload/airline/themes/*.vim + \ exec 'source '.split(globpath(&rtp, 'autoload/airline/themes/'.g:airline_theme.'.vim', 1), "\n")[0] + \ | call airline#load_theme() + augroup END + if s:airline_initialized + call on_window_changed() endif - endfunction - command! -nargs=? -complete=customlist,get_airline_themes AirlineTheme call airline_theme() - command! AirlineToggleWhitespace call airline#extensions#whitespace#toggle() - command! AirlineToggle call airline_toggle() + endif +endfunction - call airline_toggle() +function! s:get_airline_themes(a, l, p) + let files = split(globpath(&rtp, 'autoload/airline/themes/'.a:a.'*'), "\n") + return map(files, 'fnamemodify(v:val, ":t:r")') +endfunction +function! s:airline_theme(...) + if a:0 + call airline#switch_theme(a:1) + else + echo g:airline_theme + endif +endfunction +command! -nargs=? -complete=customlist,get_airline_themes AirlineTheme call airline_theme() +command! AirlineToggleWhitespace call airline#extensions#whitespace#toggle() +command! AirlineToggle call airline_toggle() + +call airline_toggle() diff --git a/t/builder.vim b/t/builder.vim new file mode 100644 index 00000000..b96d8deb --- /dev/null +++ b/t/builder.vim @@ -0,0 +1,47 @@ +call airline#init#bootstrap() + +describe 'active builder' + before + let s:builder = airline#builder#new({'active': 1}) + end + + it 'should have a call to check mode' + let stl = s:builder.build() + Expect stl =~ '%{airline#check_mode()}' + end + + it 'should transition colors from one to the next' + call s:builder.add_section('Normal', 'hello') + call s:builder.add_section('NonText', 'world') + let stl = s:builder.build() + Expect stl =~ '%#Normal#hello%#Normal_to_NonText#>%#NonText#world' + end + + it 'should split left/right sections' + call s:builder.split() + let stl = s:builder.build() + Expect stl =~ '%=' + end + + it 'after split, sections use the right separator' + call s:builder.split() + call s:builder.add_section('Normal', 'hello') + call s:builder.add_section('NonText', 'world') + let stl = s:builder.build() + Expect stl =~ '%#Normal#hello%#Normal_to_NonText#<%#NonText#world' + end +end + +describe 'inactive builder' + before + 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('NonText', 'world') + let stl = s:builder.build() + Expect stl =~ '%#Normal_inactive#hello%#Normal_to_NonText_inactive#>%#NonText_inactive#world' + end +end + diff --git a/t/commands.vim b/t/commands.vim new file mode 100644 index 00000000..8038ffd3 --- /dev/null +++ b/t/commands.vim @@ -0,0 +1,26 @@ +call airline#init#bootstrap() +source plugin/airline.vim + +describe 'commands' + it 'should toggle off and on' + execute 'AirlineToggle' + Expect exists('#airline') to_be_false + execute 'AirlineToggle' + Expect exists('#airline') to_be_true + end + + it 'should toggle whitespace off and on' + execute 'AirlineToggleWhitespace' + Expect exists('#airline_whitespace') to_be_false + execute 'AirlineToggleWhitespace' + Expect exists('#airline_whitespace') to_be_true + end + + it 'should display theme name with no args' + execute 'AirlineTheme simple' + Expect g:airline_theme == 'simple' + execute 'AirlineTheme dark' + Expect g:airline_theme == 'dark' + end +end + diff --git a/t/extensions_default.vim b/t/extensions_default.vim new file mode 100644 index 00000000..9eb80235 --- /dev/null +++ b/t/extensions_default.vim @@ -0,0 +1,22 @@ +call airline#init#bootstrap() + +describe 'default' + before + let s:builder = airline#builder#new({'active': 1}) + end + + it 'should use the layout' + let g:airline#extensions#default#layout = [ + \ [ 'c', 'a', 'b', 'warning' ], + \ [ 'x', 'z', 'y' ] + \ ] + call airline#extensions#default#apply(s:builder, { 'winnr': 1, 'active': 1 }) + let stl = s:builder.build() + Expect stl =~ 'airline_c_to_airline_a' + Expect stl =~ 'airline_a_to_airline_b' + Expect stl =~ 'airline_b_to_airline_warning' + Expect stl =~ 'airline_x_to_airline_z' + Expect stl =~ 'airline_z_to_airline_y' + end +end + diff --git a/t/init.vim b/t/init.vim new file mode 100644 index 00000000..f5293811 --- /dev/null +++ b/t/init.vim @@ -0,0 +1,65 @@ +let s:sections = ['a', 'b', 'c', 'gutter', 'x', 'y', 'z', 'warning'] + +function! s:clear() + for key in s:sections + unlet! g:airline_section_{key} + endfor +endfunction + +describe 'init' + before + call s:clear() + call airline#init#bootstrap() + end + + after + call s:clear() + end + + it 'section a should have mode, paste, iminsert' + Expect g:airline_section_a =~ 'mode' + Expect g:airline_section_a =~ 'paste' + Expect g:airline_section_a =~ 'iminsert' + end + + it 'section b should be blank because no extensions are installed' + Expect g:airline_section_b == '' + end + + it 'section c should be file' + Expect g:airline_section_c == '%<%f%m' + end + + it 'section x should be filetype' + Expect g:airline_section_x =~ '&filetype' + end + + it 'section y should be fenc and ff' + Expect g:airline_section_y =~ 'ff' + Expect g:airline_section_y =~ 'fenc' + end + + it 'section z should be line numbers' + Expect g:airline_section_z =~ '%3p%%' + Expect g:airline_section_z =~ '%3l' + Expect g:airline_section_z =~ '%3c' + end + + it 'should not redefine sections already defined' + for s in s:sections + let g:airline_section_{s} = s + endfor + call airline#init#bootstrap() + for s in s:sections + Expect g:airline_section_{s} == s + endfor + end + + it 'all default statusline extensions should be blank' + Expect airline#parts#get('hunks').raw == '' + Expect airline#parts#get('branch').raw == '' + Expect airline#parts#get('tagbar').raw == '' + Expect airline#parts#get('syntastic').raw == '' + end +end + diff --git a/t/parts.vim b/t/parts.vim new file mode 100644 index 00000000..03fee1eb --- /dev/null +++ b/t/parts.vim @@ -0,0 +1,24 @@ +describe 'parts' + it 'overwrites existing values' + call airline#parts#define('foo', { 'test': '123' }) + Expect airline#parts#get('foo').test == '123' + call airline#parts#define('foo', { 'test': '321' }) + Expect airline#parts#get('foo').test == '321' + end + + it 'can define a function part' + call airline#parts#define_function('func', 'bar') + Expect airline#parts#get('func').function == 'bar' + end + + it 'can define a text part' + call airline#parts#define_text('text', 'bar') + Expect airline#parts#get('text').text == 'bar' + end + + it 'can define a raw part' + call airline#parts#define_raw('raw', 'bar') + Expect airline#parts#get('raw').raw == 'bar' + end +end + diff --git a/t/section.vim b/t/section.vim new file mode 100644 index 00000000..433dc0a2 --- /dev/null +++ b/t/section.vim @@ -0,0 +1,37 @@ +call airline#init#bootstrap() + +function! SectionSpec() +endfunction + +describe 'section' + before + call airline#parts#define_text('text', 'text') + call airline#parts#define_raw('raw', 'raw') + call airline#parts#define_function('func', 'SectionSpec') + call airline#parts#define('hi', { + \ 'raw': 'hello', + \ 'highlight': 'hlgroup', + \ }) + end + + it 'should create sections with no separators' + let s = airline#section#create(['text', 'raw', 'func']) + Expect s == '%{"text"}raw%{SectionSpec()}' + end + + it 'should create left sections with separators' + let s = airline#section#create_left(['text', 'text']) + Expect s == '%{"text"}%{airline#util#append("text")}' + end + + it 'should create right sections with separators' + let s = airline#section#create_right(['text', 'text']) + Expect s == '%{airline#util#prepend("text")}%{"text"}' + end + + it 'should prefix with highlight group if provided' + let s = airline#section#create(['hi']) + Expect s == '%#hlgroup#hello' + end +end + diff --git a/t/util.vim b/t/util.vim new file mode 100644 index 00000000..60606c7c --- /dev/null +++ b/t/util.vim @@ -0,0 +1,42 @@ +call airline#init#bootstrap() + +function! Util1() + let g:count += 1 +endfunction +function! Util2() + let g:count += 2 +endfunction +function! Util3(...) + let g:count = a:0 +endfunction + +describe 'util' + before + let g:count = 0 + end + + it 'has append wrapper function' + Expect airline#util#append('') == '' + Expect airline#util#append('1') == ' > 1' + end + + it 'has prepend wrapper function' + Expect airline#util#prepend('') == '' + Expect airline#util#prepend('1') == '1 < ' + end + + it 'has getwinvar function' + Expect airline#util#getwinvar(1, 'asdf', '123') == '123' + call setwinvar(1, 'vspec', 'is cool') + Expect airline#util#getwinvar(1, 'vspec', '') == 'is cool' + end + + it 'has exec funcrefs helper functions' + call airline#util#exec_funcrefs([function('Util1'), function('Util2')]) + Expect g:count == 3 + + call airline#util#exec_funcrefs([function('Util3')], 1, 2, 3, 4) + Expect g:count == 4 + end +end +