text_utils_spec.lua 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local exec_lua = n.exec_lua
  4. local eq = t.eq
  5. local function md_to_vimdoc(text, start_indent, indent, text_width)
  6. return exec_lua(
  7. [[
  8. local text, start_indent, indent, text_width = ...
  9. start_indent = start_indent or 0
  10. indent = indent or 0
  11. text_width = text_width or 70
  12. local util = require('scripts/util')
  13. return util.md_to_vimdoc(table.concat(text, '\n'), start_indent, indent, text_width)
  14. ]],
  15. text,
  16. start_indent,
  17. indent,
  18. text_width
  19. )
  20. end
  21. local function test(what, act, exp, ...)
  22. local argc, args = select('#', ...), { ... }
  23. it(what, function()
  24. eq(table.concat(exp, '\n'), md_to_vimdoc(act, unpack(args, 1, argc)))
  25. end)
  26. end
  27. describe('md_to_vimdoc', function()
  28. before_each(function()
  29. n.clear()
  30. end)
  31. test('can render para after fenced code', {
  32. '- Para1',
  33. ' ```',
  34. ' code',
  35. ' ```',
  36. ' Para2',
  37. }, {
  38. '• Para1 >',
  39. ' code',
  40. '<',
  41. ' Para2',
  42. '',
  43. })
  44. test('start_indent only applies to first line', {
  45. 'para1',
  46. '',
  47. 'para2',
  48. }, {
  49. 'para1',
  50. '',
  51. ' para2',
  52. '',
  53. }, 0, 10, 78)
  54. test('inline 1', { '(`string`)' }, { '(`string`)', '' })
  55. end)