Mercurial > core / lisp/std/tests/pkg.lisp
changeset 698: |
96958d3eb5b0 |
parent: |
f51b73f49946
|
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 04 Oct 2024 22:04:59 -0400 |
permissions: |
-rw-r--r-- |
description: |
fixes |
1 ;;; tests.lisp --- std system tests 5 ;; TODO: fix false positives when using (eval-test) 10 (:use :cl :std :rt :sb-thread :std/fu)) 11 (in-package :std/tests) 15 ;; prevent threadlocks 16 ;; (setf sb-unix::*on-dangerous-wait* :error) 18 ;; TODO 2024-05-14: fix compilation order of std/fu vs std/readtables 19 (deftest readtables (:skip nil) 21 (is (typep #`(,a1 ,a1 ',a1 ,@a1) 'function)) 22 (is (string= #"test "foo" "# "test \"foo\" ")) 23 ;; from curry-compose-reader-macros test suite 24 (is (equal (funcall {list 1} 2) '(1 2))) ;; curry.1 25 (is (equal (mapcar {+ 1} '(1 2 3 4)) '(2 3 4 5))) ;; curry.2 26 (is (equal (funcall {1 list 1} 2) '(1 2))) ;; curry.fixed-arity 27 (is (equal (funcall {2 list _ 2} 3 4) '(3 4 2))) ;; curry.fixed-arity.2 30 (progn (funcall f) nil))) ;; curry.fixed-arity.1 32 (locally (declare (optimize safety)) 34 (progn (funcall f 'a 'b) nil)))) ;; curry.fixed-arity-error.2 35 (is (equal (funcall {list _ 1} 2) '(2 1))) ;; rcurry.1 36 (is (equal (mapcar {- _ 1} '(1 2 3 4)) '(0 1 2 3))) ;; rcurry.2 37 (is (equal (funcall [{* 3} #'1+] 1) 6)) ;; compose.1 38 (is (equal (funcall ['1+ '1+] 1) 3)) ;; compose.2 39 (is (equal (funcall [#'1+] 1) 2)) ;; compose.3 40 (is (equal (funcall [#'values] 1 2 3) (values 1 2 3))) ;; compose.4 41 (is (equal (funcall «list {* 2} {* 3}» 4) '(8 12))) ;; join.1 42 (is (equal (mapcar «and {< 2} 'evenp (constantly t)» '(1 2 3 4)) (list nil nil nil t))) ;; join.2 44 (is (equal (mapcar ‹typecase (number #'1+) (string :str)› '(1 "this" 2 "that")) '(2 :str 3 :str))) 46 (is (equal (mapcar ‹cond (#'evenp {+ 100}) (#'oddp {+ 200})› '(1 2 3 4)) '(201 102 203 104))) 48 (is (equal (mapcar ‹if #'evenp {list :a} {list :b}› '(1 2 3 4)) 49 '((:b 1) (:a 2) (:b 3) (:a 4)))) 51 (is (equal (mapcar ‹when 'evenp {+ 4}› '(1 2 3 4)) (list nil 6 nil 8))) 53 (is (equal (mapcar ‹unless 'evenp {+ 4}› '(1 2 3 4)) (list 5 nil 7 nil)))) 56 "Test standard symbol utils" 58 (is (not (equalp (make-gensym 'a) (make-gensym 'a)))) 59 (is (eq 'std/tests::foo (format-symbol :std/tests "~A" 'foo))) 60 (is (eq (make-keyword 'fizz) :fizz))) 64 "Test standard string utils" 65 (is (typep "test" 'string-designator)) 66 (is (typep 'test 'string-designator)) 67 (is (typep #\C 'string-designator)) 68 (is (not (typep 0 'string-designator)))) 71 "Test standard list utils" 72 ;; same object - a literal 73 (is (eq (ensure-car '(0)) (ensure-car 0))) 74 (is (eq (ensure-car '(nil)) (ensure-car nil))) 76 (is (not (eq (ensure-cons 0) (ensure-cons 0)))) 77 (is (equal (ensure-cons 0) (ensure-cons 0)))) 80 "Test standard error handlers" 81 (is (eql 'testing-err (deferror testing-err (std-error) nil (:auto t) (:documentation "testing"))))) 84 "Test standard formatters" 85 (is (string= (format nil "| 1 | 2 | 3 |~%") (fmt-row '(1 2 3)))) 87 ;; note the read-time-eval.. 88 #.(fmt-tree nil '(foobar (:a) (:b) (c) (d)) :layout :down) 97 #.(std:fmt-tree nil '(sk-project :name "foobar" :path "/a/b/c.asd" :vc :hg) :layout :down :plist t) 108 "Test standard anaphoric macros" 112 (is (= 42 (awhen 42 it))) 113 (is (= 3 (acond ((1+ 1) (1+ it))))) 114 (loop for x in '(1 2 3) 115 for y in (funcall (alet ((a 1) (b 2) (c 3)) 116 (lambda () (mapc #'1+ (list a b c))))) 117 collect (is (= x y)))) 120 "Test standard pandoric macros" 126 (progn (incf b a) (incf c a)))))) 127 (with-pandoric (b c) p 128 (is (= 0 (funcall p nil))) 129 (is (= 1 (funcall p 1))) 130 (is (= 11 (funcall p 10))) 131 (is (= 0 (funcall p nil))) 135 "Test standard alien utils" 136 (is (= 0 (foreign-int-to-integer 0 4))) 137 (is (= 1 (bool-to-foreign-int t)))) 140 "Test curry functions from Alexandria, found in std/fu. 141 These tests are copied directly from the Alexandria test suite." 143 (let ((curried (curry '+ 3))) 144 (is (= (funcall curried 1 5) 9))) 146 (let ((curried (locally (declare (notinline curry)) 148 (is (= (funcall curried 7) 42))) 150 (let ((curried-form (funcall (compiler-macro-function 'curry) 153 (let ((fun (funcall (compile nil `(lambda () ,curried-form))))) 154 (is (= (funcall fun 2) 4)))) ;; maybe fails? 157 (curried (curry (progn 159 (lambda (y z) (* x y z))) 161 (is (equal (list (funcall curried 7) 166 (let ((r (rcurry '/ 2))) 167 (is (= (funcall r 8) 4))) 170 (curried (rcurry (progn 172 (lambda (y z) (* x y z))) 175 (list (funcall curried 7) ;; 42 176 (funcall curried 7) ;; 42 180 (define-bitfield testbits 183 (c (unsigned-byte 3) :initform 1) 184 (d (integer -100 100)) 185 (e (member foo bar baz))) 188 (let ((bits (make-testbits))) 189 (is (not (testbits-a bits))) 190 (is (= 0 (testbits-b bits))) 191 (is (= 1 (testbits-c bits))) 192 (is (= -100 (testbits-d bits))) 193 (is (eql 'foo (testbits-e bits)))))