robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

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