Mercurial > core / lisp/lib/cli/tests/pkg.lisp
changeset 688: |
517c65b51e6b |
child: |
2e7d93b892a5 |
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Tue, 01 Oct 2024 21:52:17 -0400 |
permissions: |
-rw-r--r-- |
description: |
clap tests |
1 ;;; cli/tests.lisp --- CLI Tests 7 (:use :cl :std :rt :cli :cli/shell :cli/progress :cli/spark :cli/repl :cli/ansi :cli/prompt :cli/clap :cli/tools/sbcl :dat/sxp)) 9 (in-package :cli/tests) 10 (declaim (optimize (debug 3) (safety 3))) 20 (cursor-position 5 15) 22 (cursor-position 10 15) 24 (with-input-from-string (in (format nil "test~%~%")) 25 (let ((a (read-line in))) 26 (cursor-position 12 15) 35 (print "bold underline") 37 (print "bold underline reverse") 39 (print "underline reverse") 45 (print "bold underline reverse") 51 "Display the 256 color palette." 53 (loop for i from 0 to 255 do 58 (loop for i from 0 to 255 do 68 "Hide and show the cursor." 69 (princ "Cursor visible:") 73 (princ "Cursor invisible:") 78 (princ "Cursor visible:") 85 "Switch to and back from the alternate screen buffer." 86 (princ "Normal screen buffer. ") 89 (save-cursor-position) 90 (use-alternate-screen-buffer) 92 (princ "Alternate screen buffer.") 95 (use-normal-screen-buffer) 96 (restore-cursor-position) 97 (princ "Back to Normal screen buffer.") 103 "Set individual termios flags to enable raw and disable echo mode. 105 Enabling raw mode allows read-char to return immediately after a key is pressed. 107 In the default cooked mode, the entry has to be confirmed by pressing enter." 108 (set-tty-mode t :ignbrk nil 127 (cursor-position 1 1) 129 (let ((a (read-char))) 130 (cursor-position 10 5) 134 (set-tty-mode t :echo t 146 "Use combination modes that consist of several individual flags. 148 Cooked and raw are opposite modes. Enabling cooked disbles raw and vice versa." 149 (set-tty-mode t :cooked nil) 151 (cursor-position 1 1) 153 (let ((a (read-char))) 154 (cursor-position 3 1) 157 (set-tty-mode t :raw nil)) 160 "Why doesnt calling the stty utility work?" 161 (uiop:run-program "stty raw -echo" :ignore-error-status t) 163 (cursor-position 1 1) 165 (let ((a (read-char))) 166 (cursor-position 2 1) 169 (uiop:run-program "stty -raw echo" :ignore-error-status t)) 172 "Query terminal size with ANSI escape sequences." 173 ;; Put the terminal into raw mode so we can read the "user input" 174 ;; of the reply char by char 175 ;; Turn off the echo or the sequence will be displayed 176 (set-tty-mode t :cooked nil :echo nil) 177 (save-cursor-position) 178 ;; Go to the bottom right corner of the terminal by attempting 179 ;; to go to some high value of row and column 180 (cursor-position 999 999) 182 ;; The terminal returns an escape sequence to the standard input 183 (device-status-report) 185 ;; The reply isnt immediately available, the terminal does need 186 ;; some time to answer 188 ;; The reply has to be read as if the user typed an escape sequence 189 (loop for i = (read-char-no-hang *standard-input* nil) 192 ;; Put the terminal back into its initial cooked state 193 (set-tty-mode t :raw nil :echo t) 194 (restore-cursor-position) 195 ;; Return the read sequence as a list of characters. 199 (with-input-from-string (in (format nil "~%~%")) 206 ;; TODO: needs to be compiled outside scope of test - contender for 208 (defprompt tpfoo :prompt "testing:") 210 (deftest cli-prompt (:skip t) 214 (let ((*standard-input* (make-string-input-stream 215 (format nil "~A~%~A~%~%" "foobar" "foobar")))) 217 (is (string= (tpfoo-prompt) "foobar")) 218 (is (string= "foobar" 219 (completing-read "nothing: " tcoll :history thist :default "foobar"))))) 222 (flet ((%step () (cli/progress::update 1))) 223 (let ((*progress-bar-enabled* t) 225 (with-progress-bar (n "TEST: # of steps = ~a" n) 226 (dotimes (i n) (%step)))))) 230 (spark '(1 5 22 13 5)) 236 (spark '(1 2 3 4 100 5 10 20 50 300)) 248 (spark '(0 30 55 80 33 150)) 264 (spark '(0 30 55 80 33 150) :min -100) 267 (spark '(0 30 55 80 33 150) :max 50) 270 (spark '(0 30 55 80 33 150) :min 30 :max 80) 272 ;; double-float, minus 274 (spark '(1.000000000005d0 0.000000000005d0 1.0d0)) 280 (spark '(-1.000000000005d0 0.000000000005d0 -1.0d0)) 283 (let ((ternary '(-1 0 1 -1 1 0 0 -1 1 1 0))) 288 (let ((*ticks* #(#\_ #\- #\¯))) 292 (let ((*ticks* #(#\▄ #\⎯ #\▀))) 296 (let ((*ticks* #(#\E #\O))) 297 (spark '(4 8 15 22 42) :key (lambda (n) (mod n 2)))) 300 (flet ((range (start end) (loop for i from start below end collect i)) 301 (fib (n) (loop for x = 0 then y 302 and y = 1 then (+ x y) 305 (fac (n) (labels ((rec (n acc) (if (<= n 1) acc (rec (1- n) (* n acc))))) 309 :key (lambda (x) (sin (* x pi 1/4)))) 310 "▄▆█▆▄▂▁▂▄▆█▆▄▂▁▂▄▆█▆▄▂▁▂▄▆█▆▄▂▁▂▄▆█▆▄▂▁▂▄▆█▆▄▂▁▂▄▆█")) 313 :key (lambda (x) (cos (* x pi 1/4)))) 314 "█▆▄▂▁▂▄▆█▆▄▂▁▂▄▆█▆▄▂▁▂▄▆█▆▄▂▁▂▄▆█▆▄▂▁▂▄▆█▆▄▂▁▂▄▆█▆▄")) 318 :key (lambda (x) (abs (cis (* x pi 1/4))))) 319 "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁")) 323 :key (lambda (x) (float (phase (cis (* x pi 1/4))) 1.0))) 324 "▄▅▆▇█▁▁▂▄▅▆▇█▁▁▂▄▅▆▇█▁▁▂▄▅▆▇█▁▁▂▄▅▆▇█▁▁▂▄▅▆▇█▁▁▂▄▅▆")) 327 (spark (range 1 7) :key #'log) 331 (spark (range 1 7) :key #'sqrt) 337 (spark (range 1 7) :key #'fib) 340 (spark (range 1 7) :key #'exp) 343 (spark (range 1 7) :key #'fac) 346 (spark (range 1 7) :key #'isqrt) 349 (flet ((lbits (n) (spark (map 'list #'digit-char-p (write-to-string n :base 2))))) 372 ˫-----------------------+------------------------˧ 381 ˫-----------------------+------------------------˧ 388 (vspark '(0 30 55 80 33 150)) 391 ˫-----------------------+------------------------˧ 395 ██████████████████████████▋ 397 ██████████████████████████████████████████████████ 404 (vspark '(0 30 55 80 33 150) :min -100) 407 ˫-----------------------+------------------------˧ 408 ████████████████████▏ 409 ██████████████████████████▏ 410 ███████████████████████████████▏ 411 ████████████████████████████████████▏ 412 ██████████████████████████▋ 413 ██████████████████████████████████████████████████ 417 (vspark '(0 30 55 80 33 150) :max 50) 420 ˫-----------------------+------------------------˧ 422 ██████████████████████████████▏ 423 ██████████████████████████████████████████████████ 424 ██████████████████████████████████████████████████ 425 █████████████████████████████████▏ 426 ██████████████████████████████████████████████████ 431 (vspark '(0 30 55 80 33 150) :min 30 :max 80) 434 ˫-----------------------+------------------------˧ 437 █████████████████████████▏ 438 ██████████████████████████████████████████████████ 440 ██████████████████████████████████████████████████ 445 (vspark '(1 0 .5) :labels '("on" "off" "unknown") 455 (vspark '(1 0 .5) :labels '("on" "off") 465 (vspark '(1 0) :labels '("on" "off" "unknown") 475 (vspark '(0 1 2 3 4 5 6 7 8) :key (lambda (x) (sin (* x pi 1/4)))) 478 ˫-----------------------+------------------------˧ 479 █████████████████████████▏ 480 ██████████████████████████████████████████▋ 481 ██████████████████████████████████████████████████ 482 ██████████████████████████████████████████▋ 483 █████████████████████████▏ 487 ████████████████████████▉ 492 (vspark '(0 1 2 3 4 5 6 7 8) :key (lambda (x) (sin (* x pi 1/4))) 510 (vspark '(0 1 2 3 4 5 6 7 8) :key (lambda (x) (sin (* x pi 1/4))) 526 (let ((life-expectancies '(("Africa" 56) 528 ("South-East Asia" 67) 530 ("Eastern Mediterranean" 68) 531 ("Western Pacific" 76) 535 (vspark life-expectancies :key #'second) 538 ˫-----------------------+------------------------˧ 540 ██████████████████████████████████████████████████ 541 ███████████████████████████▌ 542 ██████████████████████████████████████████████████ 543 ██████████████████████████████▏ 544 ██████████████████████████████████████████████████ 545 ███████████████████████████████████▏ 550 (vspark life-expectancies :key #'second :scale? nil :newline? nil) 552 ██████████████████████████████████████████████████ 553 ███████████████████████████▌ 554 ██████████████████████████████████████████████████ 555 ██████████████████████████████▏ 556 ██████████████████████████████████████████████████ 557 ███████████████████████████████████▏")) 561 (vspark life-expectancies :key #'second :scale? nil) 564 ██████████████████████████████████████████████████ 565 ███████████████████████████▌ 566 ██████████████████████████████████████████████████ 567 ██████████████████████████████▏ 568 ██████████████████████████████████████████████████ 569 ███████████████████████████████████▏ 574 (vspark life-expectancies 576 :labels (mapcar #'first life-expectancies)) 579 ˫------------+-------------˧ 581 Americans ████████████████████████████ 582 South-East Asia ███████████████▍ 583 Europe ████████████████████████████ 584 Eastern Mediterranean ████████████████▊ 585 Western Pacific ████████████████████████████ 586 Global ███████████████████▋ 591 (vspark life-expectancies 594 :labels (mapcar #'first life-expectancies) 595 :title "Life Expectancy") 599 ˫------------+-------------˧ 601 Americans ████████████████████████▎ 602 South-East Asia ███████████████▉ 603 Europe ████████████████████████▎ 604 Eastern Mediterranean ████████████████▊ 605 Western Pacific ████████████████████████▎ 606 Global ██████████████████▋ 610 (spark (range 0 15) :key #'fib) 614 (vspark (range 0 15) :key #'fib) 617 ˫-----------------------+------------------------˧ 631 ██████████████████████████████▉ 632 ██████████████████████████████████████████████████ 638 (ld-library-path-list) 639 (is (exec-path-list)) 640 (is (find-exe "sbcl"))) 642 (deftest sbcl-tools () 643 (with-sbcl (:noinform t :quit t)