test_lispindent.vim 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. " Tests for 'lispwords' settings being global-local.
  2. " And other lisp indent stuff.
  3. set nocompatible viminfo+=nviminfo
  4. func Test_global_local_lispwords()
  5. setglobal lispwords=foo,bar,baz
  6. setlocal lispwords-=foo | setlocal lispwords+=quux
  7. call assert_equal('foo,bar,baz', &g:lispwords)
  8. call assert_equal('bar,baz,quux', &l:lispwords)
  9. call assert_equal('bar,baz,quux', &lispwords)
  10. setlocal lispwords<
  11. call assert_equal('foo,bar,baz', &g:lispwords)
  12. call assert_equal('foo,bar,baz', &l:lispwords)
  13. call assert_equal('foo,bar,baz', &lispwords)
  14. endfunc
  15. func Test_lisp_indent()
  16. enew!
  17. call append(0, [
  18. \ '(defun html-file (base)',
  19. \ '(format nil "~(~A~).html" base))',
  20. \ '',
  21. \ '(defmacro page (name title &rest body)',
  22. \ '(let ((ti (gensym)))',
  23. \ '`(with-open-file (*standard-output*',
  24. \ '(html-file ,name)',
  25. \ ':direction :output',
  26. \ ':if-exists :supersede)',
  27. \ '(let ((,ti ,title))',
  28. \ '(as title ,ti)',
  29. \ '(with center ',
  30. \ '(as h2 (string-upcase ,ti)))',
  31. \ '(brs 3)',
  32. \ ',@body))))',
  33. \ '',
  34. \ ';;; Utilities for generating links',
  35. \ '',
  36. \ '(defmacro with-link (dest &rest body)',
  37. \ '`(progn',
  38. \ '(format t "<a href=\"~A\">" (html-file ,dest))',
  39. \ ',@body',
  40. \ '(princ "</a>")))'
  41. \ ])
  42. call assert_equal(7, lispindent(2))
  43. call assert_equal(5, 6->lispindent())
  44. call assert_equal(-1, lispindent(-1))
  45. set lisp
  46. set lispwords&
  47. throw 'Skipped: cpo+=p not supported'
  48. let save_copt = &cpoptions
  49. set cpoptions+=p
  50. normal 1G=G
  51. call assert_equal([
  52. \ '(defun html-file (base)',
  53. \ ' (format nil "~(~A~).html" base))',
  54. \ '',
  55. \ '(defmacro page (name title &rest body)',
  56. \ ' (let ((ti (gensym)))',
  57. \ ' `(with-open-file (*standard-output*',
  58. \ ' (html-file ,name)',
  59. \ ' :direction :output',
  60. \ ' :if-exists :supersede)',
  61. \ ' (let ((,ti ,title))',
  62. \ ' (as title ,ti)',
  63. \ ' (with center ',
  64. \ ' (as h2 (string-upcase ,ti)))',
  65. \ ' (brs 3)',
  66. \ ' ,@body))))',
  67. \ '',
  68. \ ';;; Utilities for generating links',
  69. \ '',
  70. \ '(defmacro with-link (dest &rest body)',
  71. \ ' `(progn',
  72. \ ' (format t "<a href=\"~A\">" (html-file ,dest))',
  73. \ ' ,@body',
  74. \ ' (princ "</a>")))',
  75. \ ''
  76. \ ], getline(1, "$"))
  77. enew!
  78. let &cpoptions=save_copt
  79. set nolisp
  80. endfunc
  81. func Test_lispindent_negative()
  82. " in legacy script there is no error
  83. call assert_equal(-1, lispindent(-1))
  84. endfunc
  85. func Test_lispindent_with_indentexpr()
  86. enew
  87. setl ai lisp nocin indentexpr=11
  88. exe "normal a(x\<CR>1\<CR>2)\<Esc>"
  89. let expected = ['(x', ' 1', ' 2)']
  90. call assert_equal(expected, getline(1, 3))
  91. " with Lisp indenting the first line is not indented
  92. normal 1G=G
  93. call assert_equal(expected, getline(1, 3))
  94. %del
  95. setl lispoptions=expr:1 indentexpr=5
  96. exe "normal a(x\<CR>1\<CR>2)\<Esc>"
  97. let expected_expr = ['(x', ' 1', ' 2)']
  98. call assert_equal(expected_expr, getline(1, 3))
  99. normal 2G2<<=G
  100. call assert_equal(expected_expr, getline(1, 3))
  101. setl lispoptions=expr:0
  102. " with Lisp indenting the first line is not indented
  103. normal 1G3<<=G
  104. call assert_equal(expected, getline(1, 3))
  105. bwipe!
  106. endfunc
  107. func Test_lisp_indent_works()
  108. " This was reading beyond the end of the line
  109. new
  110. exe "norm a\tü(\<CR>="
  111. set lisp
  112. norm ==
  113. bwipe!
  114. endfunc
  115. " vim: shiftwidth=2 sts=2 expandtab