builder.vimspec 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. Describe builder.vim
  2. Describe active builder
  3. Before each
  4. let s:builder = airline#builder#new({'active': 1})
  5. End
  6. It should start with an empty statusline
  7. let stl = s:builder.build()
  8. Assert Equals(stl, '')
  9. End
  10. It should transition colors from one to the next
  11. call s:builder.add_section('Normal', 'hello')
  12. call s:builder.add_section('Search', 'world')
  13. let stl = s:builder.build()
  14. Assert Match(stl,'%#Normal#hello%#Normal_to_Search#%#Search#world')
  15. End
  16. It should reuse highlight group if background colors match
  17. highlight Foo1 ctermfg=1 ctermbg=2
  18. highlight Foo2 ctermfg=1 ctermbg=2
  19. call s:builder.add_section('Foo1', 'hello')
  20. call s:builder.add_section('Foo2', 'world')
  21. let stl = s:builder.build()
  22. Assert Match(stl, '%#Foo1#helloworld')
  23. End
  24. It should switch highlight groups if foreground colors differ
  25. highlight Foo1 ctermfg=1 ctermbg=2
  26. highlight Foo2 ctermfg=2 ctermbg=2
  27. call s:builder.add_section('Foo1', 'hello')
  28. call s:builder.add_section('Foo2', 'world')
  29. let stl = s:builder.build()
  30. Assert Match(stl, '%#Foo1#hello%#Foo1_to_Foo2#%#Foo2#world')
  31. End
  32. It should split left/right sections
  33. call s:builder.split()
  34. let stl = s:builder.build()
  35. Assert Match(stl, '%=')
  36. End
  37. It after split, sections use the right separator
  38. call s:builder.split()
  39. call s:builder.add_section('Normal', 'hello')
  40. call s:builder.add_section('Search', 'world')
  41. let stl = s:builder.build()
  42. Assert Match(stl, 'hello%#Normal_to_Search#%#Search#world')
  43. End
  44. It should not repeat the same highlight group
  45. call s:builder.add_section('Normal', 'hello')
  46. call s:builder.add_section('Normal', 'hello')
  47. let stl = s:builder.build()
  48. Assert Match(stl, '%#Normal#hellohello')
  49. End
  50. It should replace accent groups with the specified group
  51. call s:builder.add_section('Normal', '%#__accent_foo#hello')
  52. let stl = s:builder.build()
  53. Assert Match(stl, '%#Normal#%#Normal_foo#hello')
  54. End
  55. It should replace two accent groups with correct groups
  56. call s:builder.add_section('Normal', '%#__accent_foo#hello%#__accent_bar#world')
  57. let stl = s:builder.build()
  58. Assert Match(stl, '%#Normal_foo#hello%#Normal_bar#world')
  59. End
  60. It should special restore group should go back to previous group
  61. call s:builder.add_section('Normal', '%#__restore__#')
  62. let stl = s:builder.build()
  63. Assert NotMatch(stl, '%#__restore__#')
  64. Assert Match(stl, '%#Normal#')
  65. End
  66. It should blend colors from the left through the split to the right
  67. call s:builder.add_section('Normal', 'hello')
  68. call s:builder.split()
  69. call s:builder.add_section('Search', 'world')
  70. let stl = s:builder.build()
  71. Assert Match(stl, 'Normal_to_Search')
  72. End
  73. End
  74. Describe inactive builder
  75. Before each
  76. let s:builder = airline#builder#new({'active': 0})
  77. End
  78. It should transition colors from one to the next
  79. call s:builder.add_section('Normal', 'hello')
  80. call s:builder.add_section('Search', 'world')
  81. let stl = s:builder.build()
  82. Assert Match(stl, '%#Normal_inactive#hello%#Normal_to_Search_inactive#%#Search_inactive#world')
  83. End
  84. It should not render accents
  85. call s:builder.add_section('Normal', '%#__accent_foo#hello%#foo#foo%#__accent_bar#world')
  86. let stl = s:builder.build()
  87. Assert Equals(stl, '%#Normal_inactive#hello%#foo_inactive#fooworld')
  88. End
  89. End
  90. End