1;; -*- Lisp -*- vim:filetype=lisp 2;; some tests for READLINE 3;; clisp -q -norc -i ../tests/tests -x '(run-test "../modules/readline/test" :logname "readline/test")' 4 5(null (require "readline")) T 6(listp (show (multiple-value-list (ext:module-info "readline" t)) :pretty t)) T 7 8(let ((ver-num (and (boundp 'readline:readline-version) 9 readline:readline-version))) 10 (format t "~&readline version ~S (~D=0~O=x~X)~%" 11 (and (boundp 'readline:library-version) readline:library-version) 12 ver-num ver-num ver-num)) 13nil 14 15(integerp (show readline:gnu-readline-p)) T 16(typep (show readline:terminal-name) '(or null string)) T 17(integerp (show readline:prefer-env-winsize)) T 18 19(if (boundp 'readline:editing-mode) readline:editing-mode 1) 1 20(if (boundp 'readline:insert-mode) readline:insert-mode 1) 1 21(if (boundp 'readline:readline-name) readline:readline-name "CLISP") "CLISP" 22(setq readline:readline-name "abazonk") "abazonk" 23readline:readline-name "abazonk" 24 25(readline:history-stifled-p) 0 26(readline:stifle-history 100) NIL 27(readline:history-stifled-p) 1 28(abs (readline:unstifle-history)) 100 ; 5=>100, 4.2=>-100 29(readline:history-stifled-p) 0 30 31(readline:where-history) 0 32(readline:history-total-bytes) 0 33 34(defparameter *history-file* "readline-history-file") *history-file* 35(readline:write-history *history-file*) 0 36(readline:append-history 1000 *history-file*) 0 37(readline:read-history *history-file*) 0 38(readline:read-history-range *history-file* 0 -1) 0 39(readline:history-truncate-file *history-file* 10) 0 40(probe-file (delete-file *history-file*)) NIL 41 42(when (zerop (logand readline:readline-state readline:STATE-INITIALIZED)) 43 (not (zerop (readline:initialize)))) 44NIL 45 46(readline:resize-terminal) NIL 47 48(readline:reset-screen-size) NIL 49 50(multiple-value-bind (rows cols) (readline:get-screen-size) 51 (show (list rows cols)) 52 (readline:set-screen-size rows cols)) 53NIL 54 55(equal (merge-pathnames (readline:tilde-expand "~/foo")) 56 (merge-pathnames "foo" (user-homedir-pathname))) 57T 58 59;;; This tests readline-from-string, and indirectly getc-function 60(progn 61 (defun stuff-string (string) 62 "Stuff a string (with NewLine added) to readline buffer" 63 (assert (< (length string) 255)) ; stuff-char limit 64 (map 'nil (lambda (char) (readline:stuff-char (char-code char))) string) 65 (readline:stuff-char (char-code #\NewLine))) 66 (defun readline-from-string (string) 67 "Run readline:readline, with fake input." 68 (stuff-string string) 69 (readline:readline "")) 70 (readline-from-string "test")) "test" 71 72;;; Bind key and test that function works 73(let ((a 0)) 74 (readline:bind-key (char-code #\t) (lambda (? ??) (incf a))) 75 (readline-from-string "test") 76 a) 2 77 78;;; Now key is unbound, but still ignored 79(readline:unbind-key (char-code #\t)) 0 80(readline-from-string "test") "es" 81 82;;; Bind it back to insert-self 83(progn 84 (readline:parse-and-bind "\"t\": self-insert") 85 (readline-from-string "test")) 86"test" 87 88(progn 89 (stuff-string "(1 2") 90 (stuff-string "3 4) 5") 91 (read readline:*readline-input-stream*)) (1 2 3 4) 92 93(read readline:*readline-input-stream*) 5 94