From 8681d4d49ed596a99423925852dde644358043e1 Mon Sep 17 00:00:00 2001 From: kazukazuinaina Date: Sun, 5 Jun 2022 18:21:40 +0900 Subject: [PATCH 1/9] [adopt] vim-themis --- .github/workflows/ci.yml | 52 ++++++---------- .gitignore | 2 +- test/.themisrc | 28 +++++++++ test/airline.vimspec | 64 +++++++++++++++++++ test/builder.vimspec | 107 ++++++++++++++++++++++++++++++++ test/commands.vimspec | 50 +++++++++++++++ test/extensions_default.vimspec | 47 ++++++++++++++ test/extensions_tabline.vimspec | 17 +++++ test/highlighter.vimspec | 28 +++++++++ 9 files changed, 362 insertions(+), 33 deletions(-) create mode 100644 test/.themisrc create mode 100644 test/airline.vimspec create mode 100644 test/builder.vimspec create mode 100644 test/commands.vimspec create mode 100644 test/extensions_default.vimspec create mode 100644 test/extensions_tabline.vimspec create mode 100644 test/highlighter.vimspec diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 20e32c52..eaa32be6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,10 +3,10 @@ name: CI on: push: branches: - - master + - master pull_request: branches: - - master + - master jobs: test: @@ -14,38 +14,26 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - vim_version: - - 'v8.2.2000' - - 'v8.2.1000' - - 'v8.2.0000' - - 'v8.1.0000' - - 'v8.0.0000' - - 'v7.4' - + vim: + - v8.2.1000 + - v8.2.0000 + - v8.1.0000 + - v8.0.0000 + - v7.4 steps: - name: Checkout code - uses: actions/checkout@master - - - name: Setup Ruby - uses: ruby/setup-ruby@v1 + uses: actions/checkout@v2 + - name: Checkout vim-themis + uses: actions/checkout@v2 with: - ruby-version: '3.0' - - - name: Setup Bundle - run: | - gem install bundler - bundle install --jobs 4 --retry 3 - + repository: thinca/vim-themis + path: vim-themis - name: Setup Vim - uses: thinca/action-setup-vim@v1 + uses: rhysd/action-setup-vim@v1 + id: vim with: - vim_version: ${{ matrix.vim_version }} - - - name: Install Dependencies - run: | - curl -f -L "https://raw.githubusercontent.com/vim-airline/vim-airline-themes/master/autoload/airline/themes/simple.vim" -o autoload/airline/themes/simple.vim - curl -f -L "https://raw.githubusercontent.com/vim-airline/vim-airline-themes/master/autoload/airline/themes/molokai.vim" -o autoload/airline/themes/molokai.vim - mkdir colors && curl -f -L 'https://raw.githubusercontent.com/tomasr/molokai/master/colors/molokai.vim' -o colors/molokai.vim - - - name: Run Test - run: rake ci + version: ${{ matrix.vim }} + - name: Test + env: + THEMIS_VIM: ${{ steps.vim.outputs.executable }} + run: ./vim-themis/bin/themis --reporter spec diff --git a/.gitignore b/.gitignore index 593ebde4..14a0d7d8 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ doc/tags *.swp .bundle vendor - +test/.deps diff --git a/test/.themisrc b/test/.themisrc new file mode 100644 index 00000000..3edae029 --- /dev/null +++ b/test/.themisrc @@ -0,0 +1,28 @@ +let s:helper = themis#helper('assert') +let s:deps = themis#helper('deps') + +call themis#helper('command').with(s:helper) +call s:deps.git('vim-airline/vim-airline-themes') +call s:deps.git('tomasr/molokai') + +function! MyFuncref(...) + call a:1.add_raw('hello world') + return 1 +endfunction + +function! MyIgnoreFuncref(...) + return -1 +endfunction + +function! MyAppend1(...) + call a:1.add_raw('hello') +endfunction + +function! MyAppend2(...) + call a:1.add_raw('world') +endfunction + +let g:airline#extensions#default#layout = [ + \ [ 'c', 'a', 'b', 'warning' ], + \ [ 'x', 'z', 'y' ] + \ ] diff --git a/test/airline.vimspec b/test/airline.vimspec new file mode 100644 index 00000000..951fcd09 --- /dev/null +++ b/test/airline.vimspec @@ -0,0 +1,64 @@ +Describe airline.vim + Before + let g:airline_statusline_funcrefs = [] + End + + It should run user funcrefs first + call airline#add_statusline_func('MyFuncref') + let &statusline = '' + call airline#update_statusline() + Assert Match(airline#statusline(1), 'hello world') + End + + It should not change the statusline with -1 + call airline#add_statusline_funcref(function('MyIgnoreFuncref')) + let &statusline = 'foo' + call airline#update_statusline() + Assert Equals(&statusline, 'foo') + End + + It should support multiple chained funcrefs + call airline#add_statusline_func('MyAppend1') + call airline#add_statusline_func('MyAppend2') + call airline#update_statusline() + Assert Match(airline#statusline(1), 'helloworld') + End + + It should allow users to redefine sections + let g:airline_section_a = airline#section#create(['mode', 'mode']) + call airline#update_statusline() + Assert Match(airline#statusline(1), '%{airline#util#wrap(airline#parts#mode(),0)}%#airline_a#%#airline_a_bold#%{airline#util#wrap(airline#parts#mode(),0)}%#airline_a#') + End + + It should remove funcrefs properly + let c = len(g:airline_statusline_funcrefs) + call airline#add_statusline_func('MyIgnoreFuncref') + call airline#remove_statusline_func('MyIgnoreFuncref') + Assert Equals(len(g:airline_statusline_funcrefs), c) + End + + It should overwrite the statusline with active and inactive splits + wincmd s + Assert NotMatch(airline#statusline(1), 'inactive') + Assert Match(airline#statusline(2), 'inactive') + wincmd c + End + + It should collapse the inactive split if the variable is set true + let g:airline_inactive_collapse = 1 + wincmd s + Assert NotMatch(getwinvar(2, '&statusline'), 'airline#parts#mode') + wincmd c + end + + It should collapse the inactive split if the variable is set false + let g:airline_inactive_collapse = 0 + wincmd s + Assert NotEquals(getwinvar(2, '&statusline'), 'airline#parts#mode') + wincmd c + End + + It should include check_mode + Assert Match(airline#statusline(1), 'airline#check_mode') + End +End diff --git a/test/builder.vimspec b/test/builder.vimspec new file mode 100644 index 00000000..49b90b71 --- /dev/null +++ b/test/builder.vimspec @@ -0,0 +1,107 @@ +Describe builder.vim + Describe active builder + Before each + let s:builder = airline#builder#new({'active': 1}) + End + + It should start with an empty statusline + let stl = s:builder.build() + Assert Equals(stl, '') + 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#hello%#Normal_to_Search#%#Search#world') + End + + + It 'should reuse highlight group if background colors match' + 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 + + + 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 + + It should split left/right sections + call s:builder.split() + let stl = s:builder.build() + Assert Match(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('Search', 'world') + let stl = s:builder.build() + Assert Match(stl, 'hello%#Normal_to_Search#%#Search#world') + End + + 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 + + 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 + + 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 + + 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 + + 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 diff --git a/test/commands.vimspec b/test/commands.vimspec new file mode 100644 index 00000000..dfc41efd --- /dev/null +++ b/test/commands.vimspec @@ -0,0 +1,50 @@ +Describe commands.vim + + It should toggle off and on + execute 'AirlineToggle' + Assert False(exists('#airline')) + execute 'AirlineToggle' + Assert True(exists('#airline')) + End + + It should toggle whitespace off + call airline#extensions#load() + execute 'AirlineToggleWhitespace' + Assert False(exists('#airline_whitespace')) + End + + It should toggle whitespace on + call airline#extensions#load() + execute 'AirlineToggleWhitespace' + Assert True(exists('#airline_whitespace')) + End + + It should display theme name "simple" + execute 'AirlineTheme simple' + Assert Equals(g:airline_theme, 'simple') + End + + It should display theme name "dark"' + execute 'AirlineTheme dark' + Assert Equals(g:airline_theme, 'dark') + End + + It should display theme name "dark" because specifying a name that does not exist + execute 'AirlineTheme doesnotexist' + Assert Equals(g:airline_theme, 'dark') + End + + It should display theme name molokai + colors molokai + Assert Equals(g:airline_theme, 'molokai') + End + + It should have a refresh command + Assert Equals(exists(':AirlineRefresh'), 2) + End + + It should have a extensions command + Assert Equals(exists(':AirlineExtensions'), 2) + End + +End diff --git a/test/extensions_default.vimspec b/test/extensions_default.vimspec new file mode 100644 index 00000000..6fc5aeb4 --- /dev/null +++ b/test/extensions_default.vimspec @@ -0,0 +1,47 @@ +Describe extensions_default.vim + Before + let g:airline#extensions#default#layout = [ + \ [ 'c', 'a', 'b', 'warning' ], + \ [ 'x', 'z', 'y' ] + \ ] + + let s:builder = airline#builder#new({'active': 1}) + End + + It should use the layout airline_a_to_airline_b + call airline#extensions#default#apply(s:builder, { 'winnr': 1, 'active': 1 }) + let stl = s:builder.build() + Assert Match(stl, 'airline_c_to_airline_a') + end + + It should use the layout airline_a_to_airline_b + call airline#extensions#default#apply(s:builder, { 'winnr': 1, 'active': 1 }) + let stl = s:builder.build() + Assert Match(stl, 'airline_a_to_airline_b') + End + + It should use the layout airline_b_to_airline_warning + call airline#extensions#default#apply(s:builder, { 'winnr': 1, 'active': 1 }) + let stl = s:builder.build() + Assert Match(stl, 'airline_b_to_airline_warning') + end + + it should use the layout airline_x_to_airline_z + call airline#extensions#default#apply(s:builder, { 'winnr': 1, 'active': 1 }) + let stl = s:builder.build() + Assert Match(stl, 'airline_x_to_airline_z') + end + + it should use the layout airline_z_to_airline_y + call airline#extensions#default#apply(s:builder, { 'winnr': 1, 'active': 1 }) + let stl = s:builder.build() + Assert Match(stl, 'airline_z_to_airline_y') + end + + it should only render warning section in active splits + wincmd s + Assert Match(airline#statusline(1), 'warning') + Assert NotMatch(airline#statusline(2), 'warning') + wincmd c + end +end diff --git a/test/extensions_tabline.vimspec b/test/extensions_tabline.vimspec new file mode 100644 index 00000000..969f1be6 --- /dev/null +++ b/test/extensions_tabline.vimspec @@ -0,0 +1,17 @@ +Describe extensions_tabline.vim + Before all + :%bd + End + + It should use a tabline + e! file1 + Assert Match(airline#extensions#tabline#get(), '%#airline_tabsel# %(%{airline#extensions#tabline#get_buffer_name(\d)}%) |%=%#airline_tabfill_to_airline_tabfill#%#airline_tabfill# buffers' ) + End + + It Trigger on BufDelete autocommands + e! file1 + sp file2 + bd + Assert Match(airline#extensions#tabline#get(), '%#airline_tabsel# %(%{airline#extensions#tabline#get_buffer_name(\d)}%) |%=%#airline_tabfill_to_airline_tabfill#%#airline_tabfill# buffers' ) + End +End diff --git a/test/highlighter.vimspec b/test/highlighter.vimspec new file mode 100644 index 00000000..83773a8d --- /dev/null +++ b/test/highlighter.vimspec @@ -0,0 +1,28 @@ +Describe highlighter.vim + It should create separator highlight groups + hi highlighter1 ctermfg=1 ctermbg=2 + hi highlighter2 ctermfg=3 ctermbg=4 + call airline#highlighter#add_separator('highlighter1', 'highlighter2', 0) + let hl = airline#highlighter#get_highlight('highlighter1_to_highlighter2') + Assert Equal([ 'NONE', 'NONE', '4', '2', '' ], hl) + End + + if exists("+termguicolors") + It should create separator highlight groups with termguicolors + set termguicolors + hi highlighter1 guifg=#cd0000 guibg=#00cd00 ctermfg=1 ctermbg=2 + hi highlighter2 guifg=#cdcd00 guibg=#0000ee ctermfg=3 ctermbg=4 + call airline#highlighter#add_separator('highlighter1', 'highlighter2', 0) + let hl = airline#highlighter#get_highlight('highlighter1_to_highlighter2') + Assert Equal(['#0000ee', '#00cd00', '4', '2', '' ], hl) + End + endif + + It should populate accent colors + Assert False(exists('g:airline#themes#dark#palette.normal.airline_c_red')) + call airline#themes#patch(g:airline#themes#dark#palette) + call airline#highlighter#add_accent('red') + call airline#highlighter#highlight(['normal']) + Assert NotEqual(0, hlID('airline_c_red')) + End +End From 9fad2c3fc4d23798dacf93ac3f01961fae5f3f04 Mon Sep 17 00:00:00 2001 From: kazukazuinaina Date: Sun, 5 Jun 2022 18:19:25 +0900 Subject: [PATCH 2/9] ci: correctly checkout vim-flavor using https:// Currently, the CI throws: The unauthenticated git protocol on port 9418 is no longer supported. Please see https://github.blog/2021-09-01-improving-git-protocol-security-github/ for more information. So update vim-flavor to 4.0.1 which uses https:// links instead of un-authenticated git protocol. Unfortunately, we have to update ruby to version 3.0 with that. Let's see if this works. --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eaa32be6..d8f8729f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,19 +20,23 @@ jobs: - v8.1.0000 - v8.0.0000 - v7.4 + steps: - name: Checkout code uses: actions/checkout@v2 + - name: Checkout vim-themis uses: actions/checkout@v2 with: repository: thinca/vim-themis path: vim-themis + - name: Setup Vim uses: rhysd/action-setup-vim@v1 id: vim with: version: ${{ matrix.vim }} + - name: Test env: THEMIS_VIM: ${{ steps.vim.outputs.executable }} From 1a7d5464484d9c41a69cbf8abe505979f1c8c7fc Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Sat, 21 May 2022 21:57:01 +0200 Subject: [PATCH 3/9] fugitive: remove old fugitive test As mentioned by @tpope, remove the old test for the autoloaded function fugitivie#head() and instead use consistently FugitiveHead() everywhere [delete] %bd command [add] init.vimspec [update] init.vimspec [add] parts.vim [add] section.vimspec [add] themes.vimspec [add] util.vimspec [delete] vim-vspec --- Gemfile | 2 - Rakefile | 14 ---- t/airline.vim | 86 ------------------------ t/builder.vim | 107 ------------------------------ t/commands.vim | 52 --------------- t/extensions_default.vim | 50 -------------- t/extensions_tabline.vim | 21 ------ t/highlighter.vim | 31 --------- t/init.vim | 114 -------------------------------- t/parts.vim | 58 ---------------- t/section.vim | 80 ---------------------- t/themes.vim | 91 ------------------------- t/util.vim | 67 ------------------- test/extensions_tabline.vimspec | 3 - test/init.vimspec | 109 ++++++++++++++++++++++++++++++ test/parts.vimspec | 58 ++++++++++++++++ test/section.vimspec | 77 +++++++++++++++++++++ test/themes.vimspec | 91 +++++++++++++++++++++++++ test/util.vimspec | 69 +++++++++++++++++++ 19 files changed, 404 insertions(+), 776 deletions(-) delete mode 100644 Gemfile delete mode 100644 Rakefile delete mode 100644 t/airline.vim delete mode 100644 t/builder.vim delete mode 100644 t/commands.vim delete mode 100644 t/extensions_default.vim delete mode 100644 t/extensions_tabline.vim delete mode 100644 t/highlighter.vim delete mode 100644 t/init.vim delete mode 100644 t/parts.vim delete mode 100644 t/section.vim delete mode 100644 t/themes.vim delete mode 100644 t/util.vim create mode 100644 test/init.vimspec create mode 100644 test/parts.vimspec create mode 100644 test/section.vimspec create mode 100644 test/themes.vimspec create mode 100644 test/util.vimspec diff --git a/Gemfile b/Gemfile deleted file mode 100644 index 9f127bd4..00000000 --- a/Gemfile +++ /dev/null @@ -1,2 +0,0 @@ -source 'https://rubygems.org' -gem 'vim-flavor', '~> 4.0.1' diff --git a/Rakefile b/Rakefile deleted file mode 100644 index 741cfc25..00000000 --- a/Rakefile +++ /dev/null @@ -1,14 +0,0 @@ -#!/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/t/airline.vim b/t/airline.vim deleted file mode 100644 index 9b5af994..00000000 --- a/t/airline.vim +++ /dev/null @@ -1,86 +0,0 @@ -let g:airline_theme = 'dark' - -source plugin/airline.vim -doautocmd VimEnter - -function! MyFuncref(...) - call a:1.add_raw('hello world') - return 1 -endfunction - -function! MyIgnoreFuncref(...) - return -1 -endfunction - -function! MyAppend1(...) - call a:1.add_raw('hello') -endfunction - -function! MyAppend2(...) - call a:1.add_raw('world') -endfunction - -describe 'airline' - before - let g:airline_statusline_funcrefs = [] - end - - it 'should run user funcrefs first' - call airline#add_statusline_func('MyFuncref') - let &statusline = '' - call airline#update_statusline() - Expect airline#statusline(1) =~ 'hello world' - end - - it 'should not change the statusline with -1' - call airline#add_statusline_funcref(function('MyIgnoreFuncref')) - let &statusline = 'foo' - call airline#update_statusline() - Expect &statusline == 'foo' - end - - it 'should support multiple chained funcrefs' - call airline#add_statusline_func('MyAppend1') - call airline#add_statusline_func('MyAppend2') - call airline#update_statusline() - Expect airline#statusline(1) =~ 'helloworld' - end - - it 'should allow users to redefine sections' - let g:airline_section_a = airline#section#create(['mode', 'mode']) - call airline#update_statusline() - Expect airline#statusline(1) =~ '%{airline#util#wrap(airline#parts#mode(),0)}%#airline_a#%#airline_a_bold#%{airline#util#wrap(airline#parts#mode(),0)}%#airline_a#' - end - - it 'should remove funcrefs properly' - let c = len(g:airline_statusline_funcrefs) - call airline#add_statusline_func('MyIgnoreFuncref') - call airline#remove_statusline_func('MyIgnoreFuncref') - Expect len(g:airline_statusline_funcrefs) == c - end - - it 'should overwrite the statusline with active and inactive splits' - wincmd s - Expect airline#statusline(1) !~ 'inactive' - Expect airline#statusline(2) =~ 'inactive' - wincmd c - end - - it 'should collapse the inactive split if the variable is set true' - let g:airline_inactive_collapse = 1 - wincmd s - Expect airline#statusline(2) !~ 'airline#parts#mode' - wincmd c - end - - it 'should not collapse the inactive split if the variable is set false' - let g:airline_inactive_collapse = 0 - wincmd s - Expect airline#statusline(2) =~ 'airline#parts#mode' - wincmd c - end - - it 'should include check_mode' - Expect airline#statusline(1) =~ 'airline#check_mode' - end -end diff --git a/t/builder.vim b/t/builder.vim deleted file mode 100644 index 81283129..00000000 --- a/t/builder.vim +++ /dev/null @@ -1,107 +0,0 @@ -let g:airline_theme = 'dark' -call airline#init#bootstrap() - -describe 'active builder' - before - let s:builder = airline#builder#new({'active': 1}) - end - - it 'should start with an empty statusline' - let stl = s:builder.build() - Expect stl == '' - 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() - Expect stl =~ '%#Normal#hello%#Normal_to_Search#%#Search#world' - end - - it 'should reuse highlight group if background colors match' - call airline#highlighter#reset_hlcache() - 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() - Expect stl =~ '%#Foo1#helloworld' - end - - it 'should switch highlight groups if foreground colors differ' - call airline#highlighter#reset_hlcache() - 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() - Expect stl =~ '%#Foo1#hello%#Foo1_to_Foo2#%#Foo2#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('Search', 'world') - let stl = s:builder.build() - Expect stl =~ 'hello%#Normal_to_Search#%#Search#world' - end - - 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() - Expect stl == '%#Normal#hellohello' - end - - it 'should replace accent groups with the specified group' - call s:builder.add_section('Normal', '%#__accent_foo#hello') - let stl = s:builder.build() - Expect stl == '%#Normal#%#Normal_foo#hello' - end - - 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() - Expect stl =~ '%#Normal_foo#hello%#Normal_bar#world' - end - - it 'should special restore group should go back to previous group' - call s:builder.add_section('Normal', '%#__restore__#') - let stl = s:builder.build() - Expect stl !~ '%#__restore__#' - Expect stl =~ '%#Normal#' - end - - 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() - Expect stl =~ 'Normal_to_Search' - 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('Search', 'world') - let stl = s:builder.build() - Expect 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() - Expect stl == '%#Normal_inactive#hello%#foo_inactive#fooworld' - end -end diff --git a/t/commands.vim b/t/commands.vim deleted file mode 100644 index fe3ad2cc..00000000 --- a/t/commands.vim +++ /dev/null @@ -1,52 +0,0 @@ -source plugin/airline.vim -doautocmd VimEnter - -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' - call airline#extensions#load() - execute 'AirlineToggleWhitespace' - Expect exists('#airline_whitespace') to_be_false - end - - it 'should toggle whitespace on' - call airline#extensions#load() - execute 'AirlineToggleWhitespace' - Expect exists('#airline_whitespace') to_be_true - end - - it 'should display theme name "simple"' - execute 'AirlineTheme simple' - Expect g:airline_theme == 'simple' - end - - it 'should display theme name "dark"' - execute 'AirlineTheme dark' - Expect g:airline_theme == 'dark' - end - - it 'should display theme name "dark" because specifying a name that does not exist' - execute 'AirlineTheme doesnotexist' - Expect g:airline_theme == 'dark' - end - - it 'should display theme name molokai' - colors molokai - Expect g:airline_theme == 'molokai' - end - - it 'should have a refresh command' - Expect exists(':AirlineRefresh') to_be_true - end - - it 'should have a extensions command' - Expect exists(':AirlineExtensions') to_be_true - end - -end diff --git a/t/extensions_default.vim b/t/extensions_default.vim deleted file mode 100644 index f2b07bce..00000000 --- a/t/extensions_default.vim +++ /dev/null @@ -1,50 +0,0 @@ -let g:airline#extensions#default#layout = [ - \ [ 'c', 'a', 'b', 'warning' ], - \ [ 'x', 'z', 'y' ] - \ ] - -source plugin/airline.vim -doautocmd VimEnter - -describe 'default' - before - let s:builder = airline#builder#new({'active': 1}) - end - - it 'should use the layout "airline_a_to_airline_b"' - call airline#extensions#default#apply(s:builder, { 'winnr': 1, 'active': 1 }) - let stl = s:builder.build() - Expect stl =~ 'airline_c_to_airline_a' - end - - it 'should use the layout "airline_a_to_airline_b"' - call airline#extensions#default#apply(s:builder, { 'winnr': 1, 'active': 1 }) - let stl = s:builder.build() - Expect stl =~ 'airline_a_to_airline_b' - end - - it 'should use the layout "airline_b_to_airline_warning"' - call airline#extensions#default#apply(s:builder, { 'winnr': 1, 'active': 1 }) - let stl = s:builder.build() - Expect stl =~ 'airline_b_to_airline_warning' - end - - it 'should use the layout "airline_x_to_airline_z"' - call airline#extensions#default#apply(s:builder, { 'winnr': 1, 'active': 1 }) - let stl = s:builder.build() - Expect stl =~ 'airline_x_to_airline_z' - end - - it 'should use the layout "airline_z_to_airline_y"' - call airline#extensions#default#apply(s:builder, { 'winnr': 1, 'active': 1 }) - let stl = s:builder.build() - Expect stl =~ 'airline_z_to_airline_y' - end - - it 'should only render warning section in active splits' - wincmd s - Expect airline#statusline(1) =~ 'warning' - Expect airline#statusline(2) !~ 'warning' - wincmd c - end -end diff --git a/t/extensions_tabline.vim b/t/extensions_tabline.vim deleted file mode 100644 index 31f0c8d8..00000000 --- a/t/extensions_tabline.vim +++ /dev/null @@ -1,21 +0,0 @@ -let g:airline#extensions#tabline#enabled = 1 - -source plugin/airline.vim -doautocmd VimEnter - -describe 'default' - - it 'should use a tabline' - e! CHANGELOG.md - sp CONTRIBUTING.md - Expect airline#extensions#tabline#get() =~# '%#airline_tab# %(%{airline#extensions#tabline#get_buffer_name(\d)}%) %#airline_tab_to_airline_tabsel# %#airline_tabsel#%(%{airline#extensions#tabline#get_buffer_name(\d)}%) %#airline_tabsel_to_airline_tabfill# %#airline_tabfill#%=%#airline_tabfill_to_airline_tabfill#%#airline_tabfill#%#airline_tabfill_to_airline_tablabel_right#%#airline_tablabel_right# buffers ' - end - - it 'Trigger on BufDelete autocommands' - e! CHANGELOG.md - sp CONTRIBUTING.md - sp README.md - 2bd - Expect airline#extensions#tabline#get() =~# '%#airline_tab# %(%{airline#extensions#tabline#get_buffer_name(\d)}%) | %(%{airline#extensions#tabline#get_buffer_name(\d)}%) %#airline_tab_to_airline_tabsel# %#airline_tabsel#%(%{airline#extensions#tabline#get_buffer_name(\d)}%) %#airline_tabsel_to_airline_tabfill# %#airline_tabfill#%=%#airline_tabfill_to_airline_tabfill#%#airline_tabfill#%#airline_tabfill_to_airline_tablabel_right#%#airline_tablabel_right# buffers ' - end -end diff --git a/t/highlighter.vim b/t/highlighter.vim deleted file mode 100644 index 36356e8d..00000000 --- a/t/highlighter.vim +++ /dev/null @@ -1,31 +0,0 @@ -let g:airline_theme = 'dark' - -describe 'highlighter' - it 'should create separator highlight groups' - hi Foo1 ctermfg=1 ctermbg=2 - hi Foo2 ctermfg=3 ctermbg=4 - call airline#highlighter#add_separator('Foo1', 'Foo2', 0) - let hl = airline#highlighter#get_highlight('Foo1_to_Foo2') - Expect hl == [ 'NONE', 'NONE', '4', '2', '' ] - end - - if exists("+termguicolors") - it 'should create separator highlight groups with termguicolors' - set termguicolors - hi Foo1 guifg=#cd0000 guibg=#00cd00 ctermfg=1 ctermbg=2 - hi Foo2 guifg=#cdcd00 guibg=#0000ee ctermfg=3 ctermbg=4 - call airline#highlighter#add_separator('Foo1', 'Foo2', 0) - let hl = airline#highlighter#get_highlight('Foo1_to_Foo2') - Expect hl == [ '#0000ee', '#00cd00', '4', '2', '' ] - end - endif - - it 'should populate accent colors' - Expect exists('g:airline#themes#dark#palette.normal.airline_c_red') to_be_false - Expect hlID('airline_c_red') == 0 - call airline#themes#patch(g:airline#themes#dark#palette) - call airline#highlighter#add_accent('red') - call airline#highlighter#highlight(['normal']) - Expect hlID('airline_c_red') != 0 - end -end diff --git a/t/init.vim b/t/init.vim deleted file mode 100644 index f6b8734a..00000000 --- a/t/init.vim +++ /dev/null @@ -1,114 +0,0 @@ -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 - -call airline#init#bootstrap() - -describe 'init sections' - before - call s:clear() - call airline#init#sections() - end - - after - call s:clear() - end - - it 'section a should have mode, paste, spell, iminsert' - Expect g:airline_section_a =~ 'mode' - Expect g:airline_section_a =~ 'paste' - Expect g:airline_section_a =~ 'spell' - 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 and coc_status' - Expect g:airline_section_c == '%<%f%m %#__accent_red#%{airline#util#wrap(airline#parts#readonly(),0)}%#__restore__#%#__accent_bold#%#__restore__#%#__accent_bold#%#__restore__#' - end - - it 'section c should be path and coc_status' - set autochdir - call s:clear() - call airline#init#sections() - Expect g:airline_section_c == '%<%F%m %#__accent_red#%{airline#util#wrap(airline#parts#readonly(),0)}%#__restore__#%#__accent_bold#%#__restore__#%#__accent_bold#%#__restore__#' - end - - it 'section x should be filetype' - Expect g:airline_section_x == '%#__accent_bold#%#__restore__#%{airline#util#prepend("",0)}%{airline#util#prepend("",0)}%{airline#util#prepend("",0)}%{airline#util#prepend("",0)}%{airline#util#prepend("",0)}%{airline#util#wrap(airline#parts#filetype(),0)}' - 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 =~ '%p%%' - Expect g:airline_section_z =~ '%l' - Expect g:airline_section_z =~ '%v' - end - - it 'section gutter should be blank unless csv extension is installed' - " Note: the csv extension uses only the window local variable - Expect g:airline_section_gutter =~ '%=' - end - - it 'section warning should be blank' - Expect g:airline_section_warning =~ '' - 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('ale_error_count').raw == '' - Expect airline#parts#get('ale_warning_count').raw == '' - Expect airline#parts#get('lsp_error_count').raw == '' - Expect airline#parts#get('lsp_warning_count').raw == '' - Expect airline#parts#get('nvimlsp_error_count').raw == '' - Expect airline#parts#get('nvimlsp_warning_count').raw == '' - Expect airline#parts#get('hunks').raw == '' - Expect airline#parts#get('branch').raw == '' - Expect airline#parts#get('eclim').raw == '' - Expect airline#parts#get('neomake_error_count').raw == '' - Expect airline#parts#get('neomake_warning_count').raw == '' - Expect airline#parts#get('obsession').raw == '' - Expect airline#parts#get('syntastic-err').raw == '' - Expect airline#parts#get('syntastic-warn').raw == '' - Expect airline#parts#get('tagbar').raw == '' - Expect airline#parts#get('whitespace').raw == '' - Expect airline#parts#get('windowswap').raw == '' - Expect airline#parts#get('ycm_error_count').raw == '' - Expect airline#parts#get('ycm_warning_count').raw == '' - Expect airline#parts#get('languageclient_error_count').raw == '' - Expect airline#parts#get('languageclient_warning_count').raw == '' - Expect airline#parts#get('coc_status').raw == '' - Expect airline#parts#get('coc_current_function').raw == '' - Expect airline#parts#get('vista').raw == '' - Expect airline#parts#get('coc_warning_count').raw == '' - Expect airline#parts#get('coc_error_count').raw == '' - Expect airline#parts#get('battery').raw == '' - end -end - -describe 'init parts' - it 'should not redefine parts already defined' - call airline#parts#define_raw('linenr', 'bar') - call airline#init#sections() - Expect g:airline_section_z =~ 'bar' - end -end diff --git a/t/parts.vim b/t/parts.vim deleted file mode 100644 index 32dd94af..00000000 --- a/t/parts.vim +++ /dev/null @@ -1,58 +0,0 @@ -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 - - it 'can define a minwidth' - call airline#parts#define_minwidth('mw', 123) - Expect airline#parts#get('mw').minwidth == 123 - end - - it 'can define a condition' - call airline#parts#define_condition('part', '1') - Expect airline#parts#get('part').condition == '1' - end - - it 'can define a accent' - call airline#parts#define_accent('part', 'red') - Expect airline#parts#get('part').accent == 'red' - end - - it 'value should be blank' - Expect airline#parts#filetype() == '' - end - - it 'can overwrite a filetype' - set ft=aaa - Expect airline#parts#filetype() == 'aaa' - end - - it 'can overwrite a filetype' - "GitHub actions's vim's column is smaller than 90 - set ft=aaaa - if &columns >= 90 - Expect airline#parts#filetype() == 'aaaa' - else - Expect airline#parts#filetype() == 'aaa…' - endif - end - -end diff --git a/t/section.vim b/t/section.vim deleted file mode 100644 index 50717a7d..00000000 --- a/t/section.vim +++ /dev/null @@ -1,80 +0,0 @@ -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') - end - - it 'should be able to reference default parts' - let s = airline#section#create(['paste']) - Expect s == '%{airline#util#wrap(airline#parts#paste(),0)}' - end - - it 'should create sections with no separators' - let s = airline#section#create(['text', 'raw', 'func']) - Expect s == '%{airline#util#wrap("text",0)}raw%{airline#util#wrap(SectionSpec(),0)}' - end - - it 'should create left sections with separators' - let s = airline#section#create_left(['text', 'text']) - Expect s == '%{airline#util#wrap("text",0)}%{airline#util#append("text",0)}' - end - - it 'should create right sections with separators' - let s = airline#section#create_right(['text', 'text']) - Expect s == '%{airline#util#prepend("text",0)}%{airline#util#wrap("text",0)}' - end - - it 'should prefix with accent group if provided and restore afterwards' - call airline#parts#define('hi', { - \ 'raw': 'hello', - \ 'accent': 'red', - \ }) - let s = airline#section#create(['hi']) - Expect s == '%#__accent_red#hello%#__restore__#' - end - - it 'should accent functions' - call airline#parts#define_function('hi', 'Hello') - call airline#parts#define_accent('hi', 'bold') - let s = airline#section#create(['hi']) - Expect s == '%#__accent_bold#%{airline#util#wrap(Hello(),0)}%#__restore__#' - end - - it 'should parse out a section from the distro' - call airline#extensions#load() - let s = airline#section#create(['whitespace']) - Expect s =~ 'airline#extensions#whitespace#check' - end - - it 'should use parts as is if they are not found' - let s = airline#section#create(['asdf', 'func']) - Expect s == 'asdf%{airline#util#wrap(SectionSpec(),0)}' - end - - it 'should force add separators for raw and missing keys' - let s = airline#section#create_left(['asdf', 'raw']) - Expect s == 'asdf raw' - let s = airline#section#create_left(['asdf', 'aaaa', 'raw']) - Expect s == 'asdf aaaa raw' - let s = airline#section#create_right(['raw', '%f']) - Expect s == 'raw %f' - let s = airline#section#create_right(['%t', 'asdf', '%{getcwd()}']) - Expect s == '%t asdf %{getcwd()}' - end - - it 'should empty out parts that do not pass their condition' - call airline#parts#define_text('conditional', 'conditional') - call airline#parts#define_condition('conditional', '0') - let s = airline#section#create(['conditional']) - Expect s == '%{0 ? airline#util#wrap("conditional",0) : ""}' - end - - it 'should not draw two separators after another' - let s = airline#section#create_right(['ffenc','%{strftime("%H:%M")}']) - Expect s == '%{airline#util#prepend(airline#parts#ffenc(),0)}%{strftime("%H:%M")}' - end -end diff --git a/t/themes.vim b/t/themes.vim deleted file mode 100644 index 6e50d08f..00000000 --- a/t/themes.vim +++ /dev/null @@ -1,91 +0,0 @@ -describe 'themes' - after - highlight clear Foo - highlight clear Normal - end - - it 'should extract correct colors' - call airline#highlighter#reset_hlcache() - highlight Foo ctermfg=1 ctermbg=2 - let colors = airline#themes#get_highlight('Foo') - Expect colors[0] == 'NONE' - Expect colors[1] == 'NONE' - Expect colors[2] == '1' - Expect colors[3] == '2' - end - - if exists("+termguicolors") - it 'should extract correct colors with termguicolors' - call airline#highlighter#reset_hlcache() - set termguicolors - highlight Foo guifg=#cd0000 guibg=#00cd00 ctermfg=1 ctermbg=2 - let colors = airline#themes#get_highlight('Foo') - Expect colors[0] == '#cd0000' - Expect colors[1] == '#00cd00' - Expect colors[2] == '1' - Expect colors[3] == '2' - end - endif - - it 'should extract from normal if colors unavailable' - call airline#highlighter#reset_hlcache() - highlight Normal ctermfg=100 ctermbg=200 - highlight Foo ctermbg=2 - let colors = airline#themes#get_highlight('Foo') - Expect colors[0] == 'NONE' - Expect colors[1] == 'NONE' - Expect colors[2] == '100' - Expect colors[3] == '2' - end - - it 'should flip target group if it is reversed' - call airline#highlighter#reset_hlcache() - highlight Foo ctermbg=222 ctermfg=103 cterm=reverse - let colors = airline#themes#get_highlight('Foo') - Expect colors[0] == 'NONE' - Expect colors[1] == 'NONE' - Expect colors[2] == '222' - Expect colors[3] == '103' - end - - it 'should pass args through correctly' - call airline#highlighter#reset_hlcache() - hi clear Normal - let hl = airline#themes#get_highlight('Foo', 'bold', 'italic') - Expect hl == ['NONE', 'NONE', 'NONE', 'NONE', 'bold,italic'] - - let hl = airline#themes#get_highlight2(['Foo','bg'], ['Foo','fg'], 'italic', 'bold') - Expect hl == ['NONE', 'NONE', 'NONE', 'NONE', 'italic,bold'] - end - - it 'should generate color map with mirroring' - let map = airline#themes#generate_color_map( - \ [ 1, 1, 1, 1, '1' ], - \ [ 2, 2, 2, 2, '2' ], - \ [ 3, 3, 3, 3, '3' ], - \ ) - Expect map.airline_a[0] == 1 - Expect map.airline_b[0] == 2 - Expect map.airline_c[0] == 3 - Expect map.airline_x[0] == 3 - Expect map.airline_y[0] == 2 - Expect map.airline_z[0] == 1 - end - - it 'should generate color map with full set of colors' - let map = airline#themes#generate_color_map( - \ [ 1, 1, 1, 1, '1' ], - \ [ 2, 2, 2, 2, '2' ], - \ [ 3, 3, 3, 3, '3' ], - \ [ 4, 4, 4, 4, '4' ], - \ [ 5, 5, 5, 5, '5' ], - \ [ 6, 6, 6, 6, '6' ], - \ ) - Expect map.airline_a[0] == 1 - Expect map.airline_b[0] == 2 - Expect map.airline_c[0] == 3 - Expect map.airline_x[0] == 4 - Expect map.airline_y[0] == 5 - Expect map.airline_z[0] == 6 - end -end diff --git a/t/util.vim b/t/util.vim deleted file mode 100644 index dd93e5d2..00000000 --- a/t/util.vim +++ /dev/null @@ -1,67 +0,0 @@ -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('', 0) == '' - Expect airline#util#append('1', 0) == ' 1' - end - - it 'should be same &columns' - let g:airline_statusline_ontop = 1 - Expect airline#util#winwidth() == &columns - end - - it 'should be same winwidth(0)' - let g:airline_statusline_ontop = 0 - Expect airline#util#winwidth() == winwidth(0) - end - - it 'should be same winwidth(30)' - Expect airline#util#winwidth(30, 0) == winwidth(30) - end - - it 'has prepend wrapper function' - Expect airline#util#prepend('', 0) == '' - Expect airline#util#prepend('1', 0) == '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 - - it 'should ignore minwidth if less than 0' - Expect airline#util#append('foo', -1) == ' foo' - Expect airline#util#prepend('foo', -1) == 'foo ' - Expect airline#util#wrap('foo', -1) == 'foo' - end - - it 'should return empty if winwidth() > minwidth' - Expect airline#util#append('foo', 99999) == '' - Expect airline#util#prepend('foo', 99999) == '' - Expect airline#util#wrap('foo', 99999) == '' - end -end diff --git a/test/extensions_tabline.vimspec b/test/extensions_tabline.vimspec index 969f1be6..36a6bc4b 100644 --- a/test/extensions_tabline.vimspec +++ b/test/extensions_tabline.vimspec @@ -1,7 +1,4 @@ Describe extensions_tabline.vim - Before all - :%bd - End It should use a tabline e! file1 diff --git a/test/init.vimspec b/test/init.vimspec new file mode 100644 index 00000000..4b111d67 --- /dev/null +++ b/test/init.vimspec @@ -0,0 +1,109 @@ +Describe init.vim + function! s:clear() + for key in s:sections + unlet! g:airline_section_{key} + endfor + endfunction + + let s:sections = ['a', 'b', 'c', 'gutter', 'x', 'y', 'z', 'warning'] + call airline#init#bootstrap() + + Before each + call s:clear() + call airline#init#sections() + End + + It section a should have mode, paste, spell, iminsert + Assert Match(g:airline_section_a, 'mode') + Assert Match(g:airline_section_a, 'paste') + Assert Match(g:airline_section_a, 'spell') + Assert Match(g:airline_section_a, 'iminsert') + End + + It section b should be blank because no extensions are installed + Assert Equals(g:airline_section_b, '') + End + + It section c should be file and coc_status + set noautochdir + call airline#init#sections() + Assert Equals(g:airline_section_c, '%<%f%m %#__accent_red#%{airline#util#wrap(airline#parts#readonly(),0)}%#__restore__#%#__accent_bold#%#__restore__#%#__accent_bold#%#__restore__#') + End + + It section c should be path and coc_status + set autochdir + call s:clear() + call airline#init#sections() + Assert Equals(g:airline_section_c, '%<%F%m %#__accent_red#%{airline#util#wrap(airline#parts#readonly(),0)}%#__restore__#%#__accent_bold#%#__restore__#%#__accent_bold#%#__restore__#') + End + + It section x should be filetype + Assert Equals(g:airline_section_x, '%#__accent_bold#%#__restore__#%{airline#util#prepend("",0)}%{airline#util#prepend("",0)}%{airline#util#prepend("",0)}%{airline#util#prepend("",0)}%{airline#util#prepend("",0)}%{airline#util#wrap(airline#parts#filetype(),0)}') + End + + It section y should be fenc and ff + Assert Equals(g:airline_section_y, '%{airline#util#wrap(airline#parts#ffenc(),0)}') + End + + It section z should be line numbers + Assert Match(g:airline_section_z, '%p%%') + Assert Match(g:airline_section_z, '%l') + Assert Match(g:airline_section_z, '%v') + End + + It section gutter should be blank unless csv extension is installed + " Note: the csv extension uses only the window local variable + Assert Equals(g:airline_section_gutter, '%=') + End + + It section warning should be blank + Assert Match(g:airline_section_warning, '') + 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 + Assert Equals(g:airline_section_{s}, s) + endfor + End + + It all default statusline extensions should be blank + Assert Equals(airline#parts#get('ale_error_count').raw, '') + Assert Equals(airline#parts#get('ale_warning_count').raw, '') + Assert Equals(airline#parts#get('lsp_error_count').raw, '') + Assert Equals(airline#parts#get('lsp_warning_count').raw, '') + Assert Equals(airline#parts#get('nvimlsp_error_count').raw, '') + Assert Equals(airline#parts#get('nvimlsp_warning_count').raw, '') + Assert Equals(airline#parts#get('hunks').raw, '') + Assert Equals(airline#parts#get('branch').raw, '') + Assert Equals(airline#parts#get('eclim').raw, '') + Assert Equals(airline#parts#get('neomake_error_count').raw, '') + Assert Equals(airline#parts#get('neomake_warning_count').raw, '') + Assert Equals(airline#parts#get('obsession').raw, '') + Assert Equals(airline#parts#get('syntastic-err').raw, '') + Assert Equals(airline#parts#get('syntastic-warn').raw, '') + Assert Equals(airline#parts#get('tagbar').raw , '') + Assert Equals(airline#parts#get('whitespace').raw, '') + Assert Equals(airline#parts#get('windowswap').raw , '') + Assert Equals(airline#parts#get('ycm_error_count').raw, '') + Assert Equals(airline#parts#get('ycm_warning_count').raw, '') + Assert Equals(airline#parts#get('languageclient_error_count').raw, '') + Assert Equals(airline#parts#get('languageclient_warning_count').raw, '') + Assert Equals(airline#parts#get('coc_status').raw, '') + Assert Equals(airline#parts#get('coc_current_function').raw, '') + Assert Equals(airline#parts#get('vista').raw, '') + Assert Equals(airline#parts#get('coc_warning_count').raw, '') + Assert Equals(airline#parts#get('coc_error_count').raw, '') + Assert Equals(airline#parts#get('battery').raw, '') + End + + it should not redefine parts already defined + call airline#parts#define_raw('linenr', 'bar') + call s:clear() + call airline#init#sections() + Assert Match(g:airline_section_z, 'bar') + End +End diff --git a/test/parts.vimspec b/test/parts.vimspec new file mode 100644 index 00000000..01a774c8 --- /dev/null +++ b/test/parts.vimspec @@ -0,0 +1,58 @@ +Describe parts.vim + + It overwrItes existing values + call airline#parts#define('foo', { 'test': '123' }) + Assert Equals(airline#parts#get('foo').test, '123') + call airline#parts#define('foo', { 'test': '321' }) + Assert Equals(airline#parts#get('foo').test, '321') + End + + It can define a function part + call airline#parts#define_function('func', 'bar') + Assert Equals(airline#parts#get('func').function, 'bar') + End + + It can define a text part + call airline#parts#define_text('text', 'bar') + Assert Equals(airline#parts#get('text').text, 'bar') + End + + It can define a raw part + call airline#parts#define_raw('raw', 'bar') + Assert Equals(airline#parts#get('raw').raw, 'bar') + End + + It can define a minwidth + call airline#parts#define_minwidth('mw', 123) + Assert Equals(airline#parts#get('mw').minwidth, 123) + End + + It 'can define a condition' + call airline#parts#define_condition('part', '1') + Assert Equals(airline#parts#get('part').condition, '1') + End + + It 'can define a accent' + call airline#parts#define_accent('part', 'red') + Assert Equals(airline#parts#get('part').accent, 'red') + End + + It 'value should be blank' + Assert Equals(airline#parts#filetype(), '') + End + + It 'can overwrIte a filetype' + set ft=aaa + Assert Equals(airline#parts#filetype(), 'aaa') + End + + It 'can overwrite a filetype' + "GItHub actions's vim's column is smaller than 90 + set ft=aaaa + if &columns >= 90 + Assert Equals(airline#parts#filetype(), 'aaaa') + else + Assert Equals(airline#parts#filetype(), 'aaa…') + endif + End +End diff --git a/test/section.vimspec b/test/section.vimspec new file mode 100644 index 00000000..0a9fd6ed --- /dev/null +++ b/test/section.vimspec @@ -0,0 +1,77 @@ +Describe section + Before + call airline#parts#define_text('text', 'text') + call airline#parts#define_raw('raw', 'raw') + call airline#parts#define_function('func', 'SectionSpec') + End + + It should be able to reference default parts + let s = airline#section#create(['paste']) + Assert Equals(s, '%{airline#util#wrap(airline#parts#paste(),0)}') + End + + It should create sections wIth no separators + let s = airline#section#create(['text', 'raw', 'func']) + Assert Equals(s, '%{airline#util#wrap("text",0)}raw%{airline#util#wrap(SectionSpec(),0)}') + End + + It should create left sections with separators + let s = airline#section#create_left(['text', 'text']) + Assert Equals(s, '%{airline#util#wrap("text",0)}%{airline#util#append("text",0)}') + End + + It should create right sections wIth separators + let s = airline#section#create_right(['text', 'text']) + Assert Equals(s, '%{airline#util#prepend("text",0)}%{airline#util#wrap("text",0)}') + End + + It should prefix with accent group if provided and restore afterwards + call airline#parts#define('hi', { + \ 'raw': 'hello', + \ 'accent': 'red', + \ }) + let s = airline#section#create(['hi']) + Assert Equals(s, '%#__accent_red#hello%#__restore__#') + End + + It should accent functions + call airline#parts#define_function('hi', 'Hello') + call airline#parts#define_accent('hi', 'bold') + let s = airline#section#create(['hi']) + Assert Equals(s, '%#__accent_bold#%{airline#util#wrap(Hello(),0)}%#__restore__#') + End + + It should parse out a section from the distro + call airline#extensions#load() + let s = airline#section#create(['whitespace']) + Assert Match(s, 'airline#extensions#whitespace#check') + End + + It should use parts as is if they are not found + let s = airline#section#create(['asdf', 'func']) + Assert Equals(s, 'asdf%{airline#util#wrap(SectionSpec(),0)}') + End + + It should force add separators for raw and missing keys + let s = airline#section#create_left(['asdf', 'raw']) + Assert Equals(s, 'asdf raw') + let s = airline#section#create_left(['asdf', 'aaaa', 'raw']) + Assert Equals(s, 'asdf aaaa raw') + let s = airline#section#create_right(['raw', '%f']) + Assert Equals(s, 'raw %f') + let s = airline#section#create_right(['%t', 'asdf', '%{getcwd()}']) + Assert Equals(s, '%t asdf %{getcwd()}') + End + + It should empty out parts that do not pass their condition + call airline#parts#define_text('conditional', 'conditional') + call airline#parts#define_condition('conditional', '0') + let s = airline#section#create(['conditional']) + Assert Equals(s, '%{0 ? airline#util#wrap("conditional",0) : ""}') + End + + It should not draw two separators after another + let s = airline#section#create_right(['ffenc','%{strftime("%H:%M")}']) + Assert Equals(s, '%{airline#util#prepend(airline#parts#ffenc(),0)}%{strftime("%H:%M")}') + End +End diff --git a/test/themes.vimspec b/test/themes.vimspec new file mode 100644 index 00000000..2a3cfab8 --- /dev/null +++ b/test/themes.vimspec @@ -0,0 +1,91 @@ +Describe themes.vim + After each + highlight clear Foo + highlight clear Normal + End + + It should extract correct colors + call airline#highlighter#reset_hlcache() + highlight Foo ctermfg=1 ctermbg=2 + let colors = airline#themes#get_highlight('Foo') + Assert Equals(colors[0], 'NONE') + Assert Equals(colors[1], 'NONE') + Assert Equals(colors[2], '1') + Assert Equals(colors[3], '2') + End + + if exists("+termguicolors") + It should extract correct colors with termguicolors + call airline#highlighter#reset_hlcache() + set termguicolors + highlight Foo guifg=#cd0000 guibg=#00cd00 ctermfg=1 ctermbg=2 + let colors = airline#themes#get_highlight('Foo') + Assert Equals(colors[0], '#cd0000') + Assert Equals(colors[1], '#00cd00') + Assert Equals(colors[2], '1') + Assert Equals(colors[3], '2') + End + endif + + It should extract from normal if colors unavailable + call airline#highlighter#reset_hlcache() + highlight Normal ctermfg=100 ctermbg=200 + highlight Foo ctermbg=2 + let colors = airline#themes#get_highlight('Foo') + Assert Equals(colors[0], 'NONE') + Assert Equals(colors[1], 'NONE') + Assert Equals(colors[2], '100') + Assert Equals(colors[3], '2') + End + + It should flip target group if It is reversed + call airline#highlighter#reset_hlcache() + highlight Foo ctermbg=222 ctermfg=103 cterm=reverse + let colors = airline#themes#get_highlight('Foo') + Assert Equals(colors[0], 'NONE') + Assert Equals(colors[1], 'NONE') + Assert Equals(colors[2], '222') + Assert Equals(colors[3], '103') + End + + It should pass args through correctly + call airline#highlighter#reset_hlcache() + hi clear Normal + let hl = airline#themes#get_highlight('Foo', 'bold', 'italic') + Assert Equals(hl, ['NONE', 'NONE', 'NONE', 'NONE', 'bold,italic']) + + let hl = airline#themes#get_highlight2(['Foo','bg'], ['Foo','fg'], 'italic', 'bold') + Assert Equals(hl, ['NONE', 'NONE', 'NONE', 'NONE', 'italic,bold']) + End + + It should generate color map with mirroring + let map = airline#themes#generate_color_map( + \ [ 1, 1, 1, 1, '1' ], + \ [ 2, 2, 2, 2, '2' ], + \ [ 3, 3, 3, 3, '3' ], + \ ) + Assert Equals(map.airline_a[0], 1) + Assert Equals(map.airline_b[0], 2) + Assert Equals(map.airline_c[0], 3) + Assert Equals(map.airline_x[0], 3) + Assert Equals(map.airline_y[0], 2) + Assert Equals(map.airline_z[0], 1) + End + + It should generate color map with full set of colors + let map = airline#themes#generate_color_map( + \ [ 1, 1, 1, 1, '1' ], + \ [ 2, 2, 2, 2, '2' ], + \ [ 3, 3, 3, 3, '3' ], + \ [ 4, 4, 4, 4, '4' ], + \ [ 5, 5, 5, 5, '5' ], + \ [ 6, 6, 6, 6, '6' ], + \ ) + Assert Equals(map.airline_a[0], 1) + Assert Equals(map.airline_b[0], 2) + Assert Equals(map.airline_c[0], 3) + Assert Equals(map.airline_x[0], 4) + Assert Equals(map.airline_y[0], 5) + Assert Equals(map.airline_z[0], 6) + End +End diff --git a/test/util.vimspec b/test/util.vimspec new file mode 100644 index 00000000..56679c33 --- /dev/null +++ b/test/util.vimspec @@ -0,0 +1,69 @@ +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 each + let g:count = 0 + End + + It has append wrapper function + Assert Equals(airline#util#append('', 0), '') + Assert Equals(airline#util#append('1', 0), ' 1') + End + + It should be same &columns + let g:airline_statusline_ontop = 1 + Assert Equals(airline#util#winwidth(), &columns) + End + + It should be same winwidth(0) + let g:airline_statusline_ontop = 0 + Assert Equals(airline#util#winwidth(), winwidth(0)) + End + + It should be same winwidth(30) + Assert Equals(airline#util#winwidth(30, 0), winwidth(30)) + End + + It has prepend wrapper function + Assert Equals(airline#util#prepend('', 0), '') + Assert Equals(airline#util#prepend('1', 0), '1 ') + End + + It has getwinvar function + Assert Equals(airline#util#getwinvar(1, 'asdf', '123'), '123') + call setwinvar(1, 'vspec', 'is cool') + Assert Equals(airline#util#getwinvar(1, 'vspec', ''), 'is cool') + End + + It has exec funcrefs helper functions + call airline#util#exec_funcrefs([function('Util1'), function('Util2')]) + Assert Equals(g:count, 3) + + call airline#util#exec_funcrefs([function('Util3')], 1, 2, 3, 4) + Assert Equals(g:count, 4) + End + + It should ignore minwidth if less than 0 + Assert Equals(airline#util#append('foo', -1), ' foo') + Assert Equals(airline#util#prepend('foo', -1), 'foo ') + Assert Equals(airline#util#wrap('foo', -1), 'foo') + End + + It should return empty if winwidth() > minwidth + Assert Equals(airline#util#append('foo', 99999), '') + Assert Equals(airline#util#prepend('foo', 99999), '') + Assert Equals(airline#util#wrap('foo', 99999), '') + End +End From 8cd5dd1f348f234fa7c9ea2c53fbf547666c7a1e Mon Sep 17 00:00:00 2001 From: kazukazuinaina Date: Fri, 10 Jun 2022 02:26:53 +0900 Subject: [PATCH 4/9] [update] CONTRIBUTING.md --- CONTRIBUTING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 96d083ce..ab46e879 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,6 +5,7 @@ Contributions and pull requests are welcome. Please take note of the following * Adhere to the existing style as much as possible; notably, 2 space indents and long-form keywords. * Keep the history clean! Squash your branches before you submit a pull request. `pull --rebase` is your friend. * Any changes to the core should be tested against Vim 7.4. +* Contributers should install [thinca/vim-themis](https://github.com/thinca/vim-themis) to run tests before sending a PR if they applied some modification to the code. PRs which does not pass tests won't be accepted. # Bugs From 5b5d940f871ccde2c4ed36d86bd741790e122799 Mon Sep 17 00:00:00 2001 From: IK <36619465+kazukazuinaina@users.noreply.github.com> Date: Sat, 11 Jun 2022 02:37:04 +0900 Subject: [PATCH 5/9] Update .github/workflows/ci.yml Co-authored-by: uhooi --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d8f8729f..8eb2b716 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Checkout vim-themis uses: actions/checkout@v2 From ee80fd85cd6fafbb4e2ab27b4e808661b4e8366d Mon Sep 17 00:00:00 2001 From: IK <36619465+kazukazuinaina@users.noreply.github.com> Date: Sat, 11 Jun 2022 02:37:12 +0900 Subject: [PATCH 6/9] Update .github/workflows/ci.yml Co-authored-by: uhooi --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8eb2b716..775203f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,7 @@ jobs: uses: actions/checkout@v3 - name: Checkout vim-themis - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: repository: thinca/vim-themis path: vim-themis From 1080056bca8569d74ebef455b24c29180c4d5602 Mon Sep 17 00:00:00 2001 From: kazukazuinaina Date: Sat, 11 Jun 2022 02:40:32 +0900 Subject: [PATCH 7/9] [delete] single quote --- test/builder.vimspec | 2 +- test/parts.vimspec | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/builder.vimspec b/test/builder.vimspec index 49b90b71..8a1309d9 100644 --- a/test/builder.vimspec +++ b/test/builder.vimspec @@ -17,7 +17,7 @@ Describe builder.vim End - It 'should reuse highlight group if background colors match' + It should reuse highlight group if background colors match highlight Foo1 ctermfg=1 ctermbg=2 highlight Foo2 ctermfg=1 ctermbg=2 call s:builder.add_section('Foo1', 'hello') diff --git a/test/parts.vimspec b/test/parts.vimspec index 01a774c8..75a4dc61 100644 --- a/test/parts.vimspec +++ b/test/parts.vimspec @@ -27,26 +27,26 @@ Describe parts.vim Assert Equals(airline#parts#get('mw').minwidth, 123) End - It 'can define a condition' + It can define a condition call airline#parts#define_condition('part', '1') Assert Equals(airline#parts#get('part').condition, '1') End - It 'can define a accent' + It can define a accent call airline#parts#define_accent('part', 'red') Assert Equals(airline#parts#get('part').accent, 'red') End - It 'value should be blank' + It value should be blank Assert Equals(airline#parts#filetype(), '') End - It 'can overwrIte a filetype' + It can overwrIte a filetype set ft=aaa Assert Equals(airline#parts#filetype(), 'aaa') End - It 'can overwrite a filetype' + It can overwrite a filetype "GItHub actions's vim's column is smaller than 90 set ft=aaaa if &columns >= 90 From 219c47ab9f8dae2d24013db59430e8b9527e7955 Mon Sep 17 00:00:00 2001 From: kazukazuinaina Date: Sun, 12 Jun 2022 03:28:51 +0900 Subject: [PATCH 8/9] [add] Test section in README --- CONTRIBUTING.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ab46e879..da691749 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,18 @@ Contributions and pull requests are welcome. Please take note of the following * Adhere to the existing style as much as possible; notably, 2 space indents and long-form keywords. * Keep the history clean! Squash your branches before you submit a pull request. `pull --rebase` is your friend. * Any changes to the core should be tested against Vim 7.4. -* Contributers should install [thinca/vim-themis](https://github.com/thinca/vim-themis) to run tests before sending a PR if they applied some modification to the code. PRs which does not pass tests won't be accepted. + +# Testing + +Contributers should install [thinca/vim-themis](https://github.com/thinca/vim-themis) to run tests before sending a PR if they applied some modification to the code. PRs which does not pass tests won't be accepted. + +## Installation + +``` +$ cd /path/to/vim-airline +$ git submodule add https://github.com/thinca/vim-themis ./.themis-bin +$ ./path/to/themis-bin/bin/themis path/to/vim-airline/test --reporter spec +``` # Bugs From 6105d0d74e06314b56dea32cf6d2c5771d492224 Mon Sep 17 00:00:00 2001 From: kazukazuinaina Date: Sun, 3 Jul 2022 17:03:33 +0900 Subject: [PATCH 9/9] [update] CONTRIBUTING.md --- CONTRIBUTING.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index da691749..b591d485 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,11 +10,16 @@ Contributions and pull requests are welcome. Please take note of the following Contributers should install [thinca/vim-themis](https://github.com/thinca/vim-themis) to run tests before sending a PR if they applied some modification to the code. PRs which does not pass tests won't be accepted. -## Installation +## 1. Installation ``` $ cd /path/to/vim-airline $ git submodule add https://github.com/thinca/vim-themis ./.themis-bin +``` + +## 2. running test + +``` $ ./path/to/themis-bin/bin/themis path/to/vim-airline/test --reporter spec ```