"Fossies" - the Fresh Open Source Software Archive

Member "neovim-0.3.8/test/functional/legacy/029_join_spec.lua" (3 Jul 2019, 10553 Bytes) of package /linux/misc/neovim-0.3.8.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Lua source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 -- Test for joining lines with marks in them (and with 'joinspaces' set/reset)
    2 
    3 local helpers = require('test.functional.helpers')(after_each)
    4 
    5 local feed = helpers.feed
    6 local clear = helpers.clear
    7 local insert = helpers.insert
    8 local expect = helpers.expect
    9 local feed_command = helpers.feed_command
   10 
   11 describe('joining lines', function()
   12   before_each(clear)
   13 
   14   -- luacheck: ignore 613 (Trailing whitespaces in a string)
   15   -- luacheck: ignore 611 (Line contains only whitespaces)
   16   it("keeps marks with different 'joinspaces' settings", function()
   17     insert([[
   18       firstline
   19       asdfasdf.
   20       asdf
   21       asdfasdf. 
   22       asdf
   23       asdfasdf.  
   24       asdf
   25       asdfasdf. 
   26       asdf
   27       asdfasdf.     
   28       asdf
   29       asdfasdf.  
   30       asdf
   31       asdfasdf.     
   32       asdf
   33       asdfasdf
   34       asdf
   35       asdfasdf 
   36       asdf
   37       asdfasdf  
   38       asdf
   39       asdfasdf  
   40       asdf
   41       asdfasdf   
   42       asdf
   43       asdfasdf  
   44       asdf
   45       asdfasdf      
   46       asdf
   47       zx cvn.
   48       as dfg?
   49       hjkl iop!
   50       ert
   51       ]])
   52 
   53     -- Switch off 'joinspaces', then join some lines in the buffer using "J".
   54     -- Also set a few marks and record their movement when joining lines.
   55     feed_command('set nojoinspaces')
   56     feed_command('/firstline/')
   57     feed('j"td/^$/<cr>')
   58     feed('PJjJjJjJjJjJjJjJjJjJjJjJjJjJ')
   59     feed('j05lmx2j06lmy2k4Jy3l$p`xyl$p`yy2l$p')
   60 
   61     -- Do the same with 'joinspaces' on.
   62     feed_command('set joinspaces')
   63     feed('j"tp')
   64     feed('JjJjJjJjJjJjJjJjJjJjJjJjJjJ')
   65     feed('j05lmx2j06lmy2k4Jy3l$p`xyl$p`yy2l$po<esc>')
   66 
   67     feed_command('1d')
   68 
   69     expect([[
   70       asdfasdf. asdf
   71       asdfasdf. asdf
   72       asdfasdf.  asdf
   73       asdfasdf. asdf
   74       asdfasdf.     asdf
   75       asdfasdf.  asdf
   76       asdfasdf.     asdf
   77       asdfasdf asdf
   78       asdfasdf asdf
   79       asdfasdf  asdf
   80       asdfasdf  asdf
   81       asdfasdf   asdf
   82       asdfasdf  asdf
   83       asdfasdf      asdf
   84       zx cvn. as dfg? hjkl iop! ert ernop
   85       
   86       asdfasdf.  asdf
   87       asdfasdf.  asdf
   88       asdfasdf.  asdf
   89       asdfasdf. asdf
   90       asdfasdf.     asdf
   91       asdfasdf.  asdf
   92       asdfasdf.     asdf
   93       asdfasdf asdf
   94       asdfasdf asdf
   95       asdfasdf  asdf
   96       asdfasdf  asdf
   97       asdfasdf   asdf
   98       asdfasdf  asdf
   99       asdfasdf      asdf
  100       zx cvn.  as dfg?  hjkl iop!  ert  enop
  101       ]])
  102   end)
  103 
  104   it("removes comment leaders with 'joinspaces' off", function()
  105     insert([[
  106       {
  107       
  108       /*
  109        * Make sure the previous comment leader is not removed.
  110        */
  111       
  112       /*
  113        * Make sure the previous comment leader is not removed.
  114        */
  115       
  116       // Should the next comment leader be left alone?
  117       // Yes.
  118       
  119       // Should the next comment leader be left alone?
  120       // Yes.
  121       
  122       /* Here the comment leader should be left intact. */
  123       // And so should this one.
  124       
  125       /* Here the comment leader should be left intact. */
  126       // And so should this one.
  127       
  128       if (condition) // Remove the next comment leader!
  129                      // OK, I will.
  130           action();
  131       
  132       if (condition) // Remove the next comment leader!
  133                      // OK, I will.
  134           action();
  135       }
  136       ]])
  137 
  138     feed_command('/^{/+1')
  139     feed_command('set comments=s1:/*,mb:*,ex:*/,://')
  140     feed_command('set nojoinspaces')
  141     feed_command('set backspace=eol,start')
  142 
  143     -- With 'joinspaces' switched off, join lines using both "J" and :join and
  144     -- verify that comment leaders are stripped or kept as appropriate.
  145     feed_command('.,+3join')
  146     feed('j4J<cr>')
  147     feed_command('.,+2join')
  148     feed('j3J<cr>')
  149     feed_command('.,+2join')
  150     feed('j3J<cr>')
  151     feed_command('.,+2join')
  152     feed('jj3J<cr>')
  153 
  154     expect([[
  155       {
  156       /* Make sure the previous comment leader is not removed. */
  157       /* Make sure the previous comment leader is not removed. */
  158       // Should the next comment leader be left alone? Yes.
  159       // Should the next comment leader be left alone? Yes.
  160       /* Here the comment leader should be left intact. */ // And so should this one.
  161       /* Here the comment leader should be left intact. */ // And so should this one.
  162       if (condition) // Remove the next comment leader! OK, I will.
  163           action();
  164       if (condition) // Remove the next comment leader! OK, I will.
  165           action();
  166       }
  167       ]])
  168   end)
  169 
  170   -- This test case has nothing to do with joining lines.
  171   it("Ctrl-u and 'backspace' compatibility", function()
  172     -- Notice that the buffer text, which is intended to helpfully hint at
  173     -- what's being done in the test, is off by one line. (For example, "this
  174     -- should be deleted" should not be deleted, but the line below it should,
  175     -- and is.) This is likely a mistake, but was kept here for consistency.
  176     insert([[
  177       1 this shouldn't be deleted
  178       2 this shouldn't be deleted
  179       3 this shouldn't be deleted
  180       4 this should be deleted
  181       5 this shouldn't be deleted
  182       6 this shouldn't be deleted
  183       7 this shouldn't be deleted
  184       8 this shouldn't be deleted (not touched yet)
  185       ]])
  186 
  187     -- As mentioned above, we mimic the wrong initial cursor position in the old
  188     -- test by advancing one line further.
  189     feed_command([[/^\d\+ this]], '+1')
  190 
  191     -- Test with the default 'backspace' setting.
  192     feed('Avim1<c-u><esc><cr>')
  193     feed('Avim2<c-g>u<c-u><esc><cr>')
  194     feed_command('set cpo-=<')
  195     feed_command('inoremap <c-u> <left><c-u>')
  196     feed('Avim3<c-u><esc><cr>')
  197     feed_command('iunmap <c-u>')
  198     feed('Avim4<c-u><c-u><esc><cr>')
  199 
  200     -- Test with 'backspace' set to the compatible setting.
  201     feed_command('set backspace=')
  202     feed('A vim5<esc>A<c-u><c-u><esc><cr>')
  203     feed('A vim6<esc>Azwei<c-g>u<c-u><esc><cr>')
  204     feed_command('inoremap <c-u> <left><c-u>')
  205     feed('A vim7<c-u><c-u><esc><cr>')
  206 
  207     expect([[
  208       1 this shouldn't be deleted
  209       2 this shouldn't be deleted
  210       3 this shouldn't be deleted
  211       4 this should be deleted3
  212       
  213       6 this shouldn't be deleted vim5
  214       7 this shouldn't be deleted vim6
  215       8 this shouldn't be deleted (not touched yet) vim7
  216       ]])
  217   end)
  218 
  219   it("removes comment leaders with 'joinspaces' on", function()
  220     insert([[
  221       {
  222       
  223       /*
  224        * Make sure the previous comment leader is not removed.
  225        */
  226       
  227       /*
  228        * Make sure the previous comment leader is not removed.
  229        */
  230       
  231       /* List:
  232        * - item1
  233        *   foo bar baz
  234        *   foo bar baz
  235        * - item2
  236        *   foo bar baz
  237        *   foo bar baz
  238        */
  239       
  240       /* List:
  241        * - item1
  242        *   foo bar baz
  243        *   foo bar baz
  244        * - item2
  245        *   foo bar baz
  246        *   foo bar baz
  247        */
  248       
  249       // Should the next comment leader be left alone?
  250       // Yes.
  251       
  252       // Should the next comment leader be left alone?
  253       // Yes.
  254       
  255       /* Here the comment leader should be left intact. */
  256       // And so should this one.
  257       
  258       /* Here the comment leader should be left intact. */
  259       // And so should this one.
  260       
  261       if (condition) // Remove the next comment leader!
  262                      // OK, I will.
  263           action();
  264       
  265       if (condition) // Remove the next comment leader!
  266                      // OK, I will.
  267           action();
  268       
  269       int i = 7 /* foo *// 3
  270        // comment
  271        ;
  272       
  273       int i = 7 /* foo *// 3
  274        // comment
  275        ;
  276       
  277       ># Note that the last character of the ending comment leader (left angle
  278        # bracket) is a comment leader itself. Make sure that this comment leader is
  279        # not removed from the next line #<
  280       < On this line a new comment is opened which spans 2 lines. This comment should
  281       < retain its comment leader.
  282       
  283       ># Note that the last character of the ending comment leader (left angle
  284        # bracket) is a comment leader itself. Make sure that this comment leader is
  285        # not removed from the next line #<
  286       < On this line a new comment is opened which spans 2 lines. This comment should
  287       < retain its comment leader.
  288       
  289       }
  290       ]])
  291 
  292     feed_command('/^{/+1')
  293     feed_command([[set comments=sO:*\ -,mO:*\ \ ,exO:*/]])
  294     feed_command('set comments+=s1:/*,mb:*,ex:*/,://')
  295     feed_command('set comments+=s1:>#,mb:#,ex:#<,:<')
  296     feed_command('set backspace=eol,start')
  297 
  298     -- With 'joinspaces' on (the default setting), again join lines and verify
  299     -- that comment leaders are stripped or kept as appropriate.
  300     feed_command('.,+3join')
  301     feed('j4J<cr>')
  302     feed_command('.,+8join')
  303     feed('j9J<cr>')
  304     feed_command('.,+2join')
  305     feed('j3J<cr>')
  306     feed_command('.,+2join')
  307     feed('j3J<cr>')
  308     feed_command('.,+2join')
  309     feed('jj3J<cr>')
  310     feed('j')
  311     feed_command('.,+2join')
  312     feed('jj3J<cr>')
  313     feed('j')
  314     feed_command('.,+5join')
  315     feed('j6J<cr>')
  316     feed('oSome code!<cr>// Make sure backspacing does not remove this comment leader.<esc>0i<bs><esc>')
  317 
  318     expect([[
  319       {
  320       /* Make sure the previous comment leader is not removed.  */
  321       /* Make sure the previous comment leader is not removed.  */
  322       /* List: item1 foo bar baz foo bar baz item2 foo bar baz foo bar baz */
  323       /* List: item1 foo bar baz foo bar baz item2 foo bar baz foo bar baz */
  324       // Should the next comment leader be left alone?  Yes.
  325       // Should the next comment leader be left alone?  Yes.
  326       /* Here the comment leader should be left intact. */ // And so should this one.
  327       /* Here the comment leader should be left intact. */ // And so should this one.
  328       if (condition) // Remove the next comment leader!  OK, I will.
  329           action();
  330       if (condition) // Remove the next comment leader!  OK, I will.
  331           action();
  332       int i = 7 /* foo *// 3 // comment
  333        ;
  334       int i = 7 /* foo *// 3 // comment
  335        ;
  336       ># Note that the last character of the ending comment leader (left angle bracket) is a comment leader itself. Make sure that this comment leader is not removed from the next line #< < On this line a new comment is opened which spans 2 lines. This comment should retain its comment leader.
  337       ># Note that the last character of the ending comment leader (left angle bracket) is a comment leader itself. Make sure that this comment leader is not removed from the next line #< < On this line a new comment is opened which spans 2 lines. This comment should retain its comment leader.
  338       
  339       Some code!// Make sure backspacing does not remove this comment leader.
  340       }
  341       ]])
  342   end)
  343 end)