neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

069_multibyte_formatting_spec.lua (6072B)


      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 t = require('test.testutil')
      7 local n = require('test.functional.testnvim')()
      8 
      9 local feed, insert, eq, eval, clear, feed_command, expect =
     10  n.feed, n.insert, t.eq, n.eval, n.clear, n.feed_command, n.expect
     11 
     12 describe('multibyte text', function()
     13  before_each(clear)
     14 
     15  it('formatting with "set fo=t"', function()
     16    insert([[
     17      {
     18      XYZ
     19      abc XYZ
     20      }]])
     21    feed_command('/^{/+1')
     22    feed_command('set tw=2 fo=t')
     23    feed('gqgqjgqgqo<cr>')
     24    feed('XYZ<cr>')
     25    feed('abc XYZ<esc><esc>')
     26    expect([[
     27      {
     28      XYZ
     29      abc
     30      XYZ
     31 
     32      XYZ
     33      abc
     34      XYZ
     35      }]])
     36  end)
     37 
     38  it('formatting with "set fo=tm"', function()
     39    insert([[
     40      {
     41      
     42      a
     43       a
     44      XY
     45       
     46      }]])
     47    feed_command('/^{/+1')
     48    feed_command('set tw=1 fo=tm')
     49    feed('gqgqjgqgqjgqgqjgqgqjgqgqo<cr>')
     50    feed('X<cr>')
     51    feed('Xa<cr>')
     52    feed('X a<cr>')
     53    feed('XY<cr>')
     54    feed('X Y<esc><esc>')
     55    expect([[
     56      {
     57      
     58      
     59      a
     60      
     61      a
     62      
     63      
     64      
     65      
     66 
     67      
     68      
     69      a
     70      
     71      a
     72      
     73      
     74      
     75      
     76      }]])
     77  end)
     78 
     79  it('formatting with "set fo=tm" (part 2)', function()
     80    insert([[
     81      {
     82      
     83      a
     84       a
     85      XY
     86       
     87      aX
     88      abX
     89      abcX
     90      abX c
     91      abXY
     92      }]])
     93    feed_command('/^{/+1')
     94    feed_command('set tw=2 fo=tm')
     95    feed('gqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqo<cr>')
     96    feed('X<cr>')
     97    feed('Xa<cr>')
     98    feed('X a<cr>')
     99    feed('XY<cr>')
    100    feed('X Y<cr>')
    101    feed('aX<cr>')
    102    feed('abX<cr>')
    103    feed('abcX<cr>')
    104    feed('abX c<cr>')
    105    feed('abXY<esc><esc>')
    106    expect([[
    107      {
    108      
    109      
    110      a
    111      
    112      a
    113      
    114      
    115      
    116      
    117      a
    118      
    119      ab
    120      
    121      abc
    122      
    123      ab
    124      
    125      c
    126      ab
    127      
    128      
    129 
    130      
    131      
    132      a
    133      
    134      a
    135      
    136      
    137      
    138      
    139      a
    140      
    141      ab
    142      
    143      abc
    144      
    145      ab
    146      
    147      c
    148      ab
    149      
    150      
    151      }]])
    152  end)
    153 
    154  it('formatting with "set ai fo=tm"', function()
    155    insert([[
    156      {
    157        
    158        a
    159      }]])
    160    feed_command('/^{/+1')
    161    feed_command('set ai tw=2 fo=tm')
    162    feed('gqgqjgqgqo<cr>')
    163    feed('X<cr>')
    164    feed('Xa<esc>')
    165    expect([[
    166      {
    167        
    168        
    169        a
    170 
    171        
    172        
    173        a
    174      }]])
    175  end)
    176 
    177  it('formatting with "set ai fo=tm" (part 2)', function()
    178    insert([[
    179      {
    180        
    181        a
    182      }]])
    183    feed_command('/^{/+1')
    184    feed_command('set noai tw=2 fo=tm')
    185    feed('gqgqjgqgqo<cr>')
    186    feed('  X<cr>')
    187    feed('  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      a
    205      aY
    206      XY
    207      XYZ
    208       
    209       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      a
    231      a
    232      XY
    233      XY
    234      XY
    235      XZ
    236       
    237       
    238       
    239      XX
    240      XXa
    241      XXY
    242 
    243      
    244      a
    245      a
    246      XY
    247      XY
    248      XY
    249      XZ
    250       
    251       
    252       
    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      bba
    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)