"Fossies" - the Fresh Open Source Software Archive

Member "neovim-0.3.8/test/functional/legacy/069_multibyte_formatting_spec.lua" (3 Jul 2019, 6177 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 multibyte text formatting.
    2 -- Also test, that 'mps' with multibyte chars works.
    3 -- And test "ra" on multibyte characters.
    4 -- Also test byteidx() and byteidxcomp()
    5 
    6 local helpers = require('test.functional.helpers')(after_each)
    7 local feed, insert, eq, eval, clear, feed_command, expect = helpers.feed,
    8   helpers.insert, helpers.eq, helpers.eval, helpers.clear, helpers.feed_command,
    9   helpers.expect
   10 
   11 describe('multibyte text', function()
   12   before_each(clear)
   13 
   14   it('formatting with "set fo=t"', function()
   15     insert([[
   16       {
   17       XYZ
   18       abc XYZ
   19       }]])
   20     feed_command('/^{/+1')
   21     feed_command('set tw=2 fo=t')
   22     feed('gqgqjgqgqo<cr>')
   23     feed('XYZ<cr>')
   24     feed('abc XYZ<esc><esc>')
   25     expect([[
   26       {
   27       XYZ
   28       abc
   29       XYZ
   30 
   31       XYZ
   32       abc
   33       XYZ
   34       }]])
   35   end)
   36 
   37   it('formatting with "set fo=tm"', function()
   38     insert([[
   39       {
   40 
   41       Xa
   42       X a
   43       XY
   44       X Y
   45       }]])
   46     feed_command('/^{/+1')
   47     feed_command('set tw=1 fo=tm')
   48     feed('gqgqjgqgqjgqgqjgqgqjgqgqo<cr>')
   49     feed('X<cr>')
   50     feed('Xa<cr>')
   51     feed('X a<cr>')
   52     feed('XY<cr>')
   53     feed('X Y<esc><esc>')
   54     expect([[
   55       {
   56 
   57 
   58       a
   59 
   60       a
   61 
   62 
   63 
   64 
   65 
   66 
   67 
   68       a
   69 
   70       a
   71 
   72 
   73 
   74 
   75       }]])
   76   end)
   77 
   78   it('formatting with "set fo=tm" (part 2)', function()
   79     insert([[
   80       {
   81 
   82       Xa
   83       X a
   84       XY
   85       X Y
   86       aX
   87       abX
   88       abcX
   89       abX c
   90       abXY
   91       }]])
   92     feed_command('/^{/+1')
   93     feed_command('set tw=2 fo=tm')
   94     feed('gqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqo<cr>')
   95     feed('X<cr>')
   96     feed('Xa<cr>')
   97     feed('X a<cr>')
   98     feed('XY<cr>')
   99     feed('X Y<cr>')
  100     feed('aX<cr>')
  101     feed('abX<cr>')
  102     feed('abcX<cr>')
  103     feed('abX c<cr>')
  104     feed('abXY<esc><esc>')
  105     expect([[
  106       {
  107 
  108 
  109       a
  110 
  111       a
  112 
  113 
  114 
  115 
  116       a
  117 
  118       ab
  119 
  120       abc
  121 
  122       ab
  123 
  124       c
  125       ab
  126 
  127 
  128 
  129 
  130 
  131       a
  132 
  133       a
  134 
  135 
  136 
  137 
  138       a
  139 
  140       ab
  141 
  142       abc
  143 
  144       ab
  145 
  146       c
  147       ab
  148 
  149 
  150       }]])
  151   end)
  152 
  153   it('formatting with "set ai fo=tm"', function()
  154     insert([[
  155       {
  156 
  157         Xa
  158       }]])
  159     feed_command('/^{/+1')
  160     feed_command('set ai tw=2 fo=tm')
  161     feed('gqgqjgqgqo<cr>')
  162     feed('X<cr>')
  163     feed('Xa<esc>')
  164     expect([[
  165       {
  166 
  167 
  168         a
  169 
  170 
  171 
  172         a
  173       }]])
  174   end)
  175 
  176   it('formatting with "set ai fo=tm" (part 2)', function()
  177     insert([[
  178       {
  179 
  180         Xa
  181       }]])
  182     feed_command('/^{/+1')
  183     feed_command('set noai tw=2 fo=tm')
  184     feed('gqgqjgqgqo<cr>')
  185     -- Literal spaces will be trimmed from the by feed().
  186     feed('<space><space>X<cr>')
  187     feed('<space><space>Xa<esc>')
  188     expect([[
  189       {
  190 
  191 
  192       a
  193 
  194 
  195 
  196       a
  197       }]])
  198   end)
  199 
  200   it('formatting with "set fo=cqm" and multibyte comments', function()
  201     insert([[
  202       {
  203 
  204       Xa
  205       XaY
  206       XY
  207       XYZ
  208       X Y
  209       X YZ
  210       XX
  211       XXa
  212       XXY
  213       }]])
  214     feed_command('/^{/+1')
  215     feed_command('set tw=2 fo=cqm comments=n:X')
  216     feed('gqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqo<cr>')
  217     feed('X<cr>')
  218     feed('Xa<cr>')
  219     feed('XaY<cr>')
  220     feed('XY<cr>')
  221     feed('XYZ<cr>')
  222     feed('X Y<cr>')
  223     feed('X YZ<cr>')
  224     feed('XX<cr>')
  225     feed('XXa<cr>')
  226     feed('XXY<esc><esc>')
  227     expect([[
  228       {
  229 
  230       Xa
  231       Xa
  232       XY
  233       XY
  234       XY
  235       XZ
  236       X Y
  237       X Y
  238       X Z
  239       XX
  240       XXa
  241       XXY
  242 
  243 
  244       Xa
  245       Xa
  246       XY
  247       XY
  248       XY
  249       XZ
  250       X Y
  251       X Y
  252       X Z
  253       XX
  254       XXa
  255       XXY
  256       }]])
  257   end)
  258 
  259   it('formatting in replace mode', function()
  260     insert([[
  261       {
  262 
  263       }]])
  264     feed_command('/^{/+1')
  265     feed_command('set tw=2 fo=tm')
  266     feed('RXa<esc>')
  267     expect([[
  268       {
  269 
  270       a
  271       }]])
  272   end)
  273 
  274   it("as values of 'mps'", function()
  275     insert([[
  276       {
  277       ‘ two three ’ four
  278       }]])
  279     feed_command('/^{/+1')
  280     feed_command('set mps+=‘:’')
  281     feed('d%<cr>')
  282     expect([[
  283       {
  284        four
  285       }]])
  286   end)
  287 
  288   it('can be replaced with r', function()
  289     insert([[
  290       abba
  291       aab]])
  292     feed('gg0Vjra<cr>')
  293     expect([[
  294       aaaa
  295       aaa]])
  296   end)
  297 
  298   it("doesn't interfere with 'whichwrap'", function()
  299     insert([[
  300       á
  301       x]])
  302     feed_command('set whichwrap+=h')
  303     feed_command('/^x')
  304     feed('dh')
  305     expect([[
  306       áx]])
  307   end)
  308 
  309   it('can be queried with byteidx() and byteidxcomp()', function()
  310     -- One char of two bytes.
  311     feed_command("let a = '.é.'")
  312     -- Normal e with composing char.
  313     feed_command("let b = '.é.'")
  314     eq(0, eval('byteidx(a, 0)'))
  315     eq(1, eval('byteidx(a, 1)'))
  316     eq(3, eval('byteidx(a, 2)'))
  317     eq(4, eval('byteidx(a, 3)'))
  318     eq(-1, eval('byteidx(a, 4)'))
  319     eq(0, eval('byteidx(b, 0)'))
  320     eq(1, eval('byteidx(b, 1)'))
  321     eq(4, eval('byteidx(b, 2)'))
  322     eq(5, eval('byteidx(b, 3)'))
  323     eq(-1, eval('byteidx(b, 4)'))
  324     eq(0, eval('byteidxcomp(a, 0)'))
  325     eq(1, eval('byteidxcomp(a, 1)'))
  326     eq(3, eval('byteidxcomp(a, 2)'))
  327     eq(4, eval('byteidxcomp(a, 3)'))
  328     eq(-1, eval('byteidxcomp(a, 4)'))
  329     eq(0, eval('byteidxcomp(b, 0)'))
  330     eq(1, eval('byteidxcomp(b, 1)'))
  331     eq(2, eval('byteidxcomp(b, 2)'))
  332     eq(4, eval('byteidxcomp(b, 3)'))
  333     eq(5, eval('byteidxcomp(b, 4)'))
  334     eq(-1, eval('byteidxcomp(b, 5)'))
  335   end)
  336 
  337   it('correctly interact with the \zs pattern', function()
  338     eq('a1a2a3a', eval([[substitute('123', '\zs', 'a', 'g')]]))
  339   end)
  340 end)