option_spec.lua 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. local helpers = require("test.unit.helpers")(after_each)
  2. local itp = helpers.gen_itp(it)
  3. local to_cstr = helpers.to_cstr
  4. local eq = helpers.eq
  5. local option = helpers.cimport("./src/nvim/option.h")
  6. local globals = helpers.cimport("./src/nvim/globals.h")
  7. local check_ff_value = function(ff)
  8. return option.check_ff_value(to_cstr(ff))
  9. end
  10. describe('check_ff_value', function()
  11. itp('views empty string as valid', function()
  12. eq(1, check_ff_value(""))
  13. end)
  14. itp('views "unix", "dos" and "mac" as valid', function()
  15. eq(1, check_ff_value("unix"))
  16. eq(1, check_ff_value("dos"))
  17. eq(1, check_ff_value("mac"))
  18. end)
  19. itp('views "foo" as invalid', function()
  20. eq(0, check_ff_value("foo"))
  21. end)
  22. end)
  23. describe('get_sts_value', function()
  24. itp([[returns 'softtabstop' when it is non-negative]], function()
  25. globals.curbuf.b_p_sts = 5
  26. eq(5, option.get_sts_value())
  27. globals.curbuf.b_p_sts = 0
  28. eq(0, option.get_sts_value())
  29. end)
  30. itp([[returns "effective shiftwidth" when 'softtabstop' is negative]], function()
  31. local shiftwidth = 2
  32. globals.curbuf.b_p_sw = shiftwidth
  33. local tabstop = 5
  34. globals.curbuf.b_p_ts = tabstop
  35. globals.curbuf.b_p_sts = -2
  36. eq(shiftwidth, option.get_sts_value())
  37. shiftwidth = 0
  38. globals.curbuf.b_p_sw = shiftwidth
  39. eq(tabstop, option.get_sts_value())
  40. end)
  41. end)