indent_spec.lua 1.7 KB

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