neovim

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

indent_spec.lua (1709B)


      1 local t = require('test.unit.testutil')
      2 local itp = t.gen_itp(it)
      3 
      4 local to_cstr = t.to_cstr
      5 local ffi = t.ffi
      6 local eq = t.eq
      7 
      8 local indent = t.cimport('./src/nvim/indent.h')
      9 local globals = t.cimport('./src/nvim/globals.h')
     10 
     11 describe('get_sts_value', function()
     12  itp([[returns 'softtabstop' when it is non-negative]], function()
     13    globals.curbuf.b_p_sts = 5
     14    eq(5, indent.get_sts_value())
     15 
     16    globals.curbuf.b_p_sts = 0
     17    eq(0, indent.get_sts_value())
     18  end)
     19 
     20  itp([[returns "effective shiftwidth" when 'softtabstop' is negative]], function()
     21    local shiftwidth = 2
     22    globals.curbuf.b_p_sw = shiftwidth
     23    local tabstop = 5
     24    globals.curbuf.b_p_ts = tabstop
     25    globals.curbuf.b_p_sts = -2
     26    eq(shiftwidth, indent.get_sts_value())
     27 
     28    shiftwidth = 0
     29    globals.curbuf.b_p_sw = shiftwidth
     30    eq(tabstop, indent.get_sts_value())
     31  end)
     32 end)
     33 
     34 describe('indent_size_ts()', function()
     35  itp('works for spaces', function()
     36    local line = to_cstr((' '):rep(7) .. 'a ')
     37    eq(7, indent.indent_size_ts(line, 100, nil))
     38  end)
     39 
     40  itp('works for tabs and spaces', function()
     41    local line = to_cstr('   \t  \t \t\t   a ')
     42    eq(19, indent.indent_size_ts(line, 4, nil))
     43  end)
     44 
     45  itp('works for tabs and spaces with empty vts', function()
     46    local vts = ffi.new('int[1]') -- zero initialized => first element (size) == 0
     47    local line = to_cstr('   \t  \t \t\t       a ')
     48    eq(23, indent.indent_size_ts(line, 4, vts))
     49  end)
     50 
     51  itp('works for tabs and spaces with vts', function()
     52    local vts = ffi.new('int[3]')
     53    vts[0] = 2 -- zero indexed
     54    vts[1] = 7
     55    vts[2] = 2
     56 
     57    local line = to_cstr('      \t  \t \t\t   a ')
     58    eq(18, indent.indent_size_ts(line, 4, vts))
     59  end)
     60 end)