Bram Moolenaar | d26c580 | 2022-10-13 12:30:08 +0100 | [diff] [blame] | 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 | def Test_lisp_indent() |
| 20 | enew! |
| 21 | |
| 22 | 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 | assert_equal(7, lispindent(2)) |
| 48 | assert_equal(5, 6->lispindent()) |
| 49 | assert_fails('lispindent(-1)', 'E966: Invalid line number: -1') |
| 50 | |
| 51 | set lisp |
| 52 | set lispwords& |
| 53 | var save_copt = &cpoptions |
| 54 | set cpoptions+=p |
| 55 | normal 1G=G |
| 56 | |
| 57 | assert_equal([ |
| 58 | '(defun html-file (base)', |
| 59 | ' (format nil "~(~A~).html" base))', |
| 60 | '', |
| 61 | '(defmacro page (name title &rest body)', |
| 62 | ' (let ((ti (gensym)))', |
| 63 | ' `(with-open-file (*standard-output*', |
| 64 | ' (html-file ,name)', |
| 65 | ' :direction :output', |
| 66 | ' :if-exists :supersede)', |
| 67 | ' (let ((,ti ,title))', |
| 68 | ' (as title ,ti)', |
| 69 | ' (with center ', |
| 70 | ' (as h2 (string-upcase ,ti)))', |
| 71 | ' (brs 3)', |
| 72 | ' ,@body))))', |
| 73 | '', |
| 74 | ';;; Utilities for generating links', |
| 75 | '', |
| 76 | '(defmacro with-link (dest &rest body)', |
| 77 | ' `(progn', |
| 78 | ' (format t "<a href=\"~A\">" (html-file ,dest))', |
| 79 | ' ,@body', |
| 80 | ' (princ "</a>")))', |
| 81 | '' |
| 82 | ], getline(1, "$")) |
| 83 | |
| 84 | enew! |
| 85 | &cpoptions = save_copt |
| 86 | set nolisp |
| 87 | enddef |
| 88 | |
| 89 | func Test_lispindent_negative() |
| 90 | " in legacy script there is no error |
| 91 | call assert_equal(-1, lispindent(-1)) |
| 92 | endfunc |
| 93 | |
| 94 | func Test_lisp_indent_works() |
| 95 | " This was reading beyond the end of the line |
| 96 | new |
| 97 | exe "norm a\tü(\<CR>=" |
| 98 | set lisp |
| 99 | norm == |
| 100 | bwipe! |
| 101 | endfunc |
| 102 | |
| 103 | " vim: shiftwidth=2 sts=2 expandtab |