neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

test_lispindent.vim (3600B)


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