diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/automated/cl-lib-tests.el | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/automated/cl-lib-tests.el b/test/automated/cl-lib-tests.el index ce0e5918653..d272f3a5ee2 100644 --- a/test/automated/cl-lib-tests.el +++ b/test/automated/cl-lib-tests.el | |||
| @@ -422,6 +422,47 @@ | |||
| 422 | ;; should return a copy | 422 | ;; should return a copy |
| 423 | (should-not (eq (cl-ldiff l '()) l)))) | 423 | (should-not (eq (cl-ldiff l '()) l)))) |
| 424 | 424 | ||
| 425 | (ert-deftest cl-lib-adjoin-test () | ||
| 426 | (let ((nums '(1 2)) | ||
| 427 | (myfn-p '=)) | ||
| 428 | ;; add non-existing item to the front | ||
| 429 | (should (equal '(3 1 2) (cl-adjoin 3 nums))) | ||
| 430 | ;; just add - don't copy rest | ||
| 431 | (should (eq nums (cdr (cl-adjoin 3 nums)))) | ||
| 432 | ;; add only when not already there | ||
| 433 | (should (eq nums (cl-adjoin 2 nums))) | ||
| 434 | (should (equal '(2 1 (2)) (cl-adjoin 2 '(1 (2))))) | ||
| 435 | ;; default test function is eql | ||
| 436 | (should (equal '(1.0 1 2) (cl-adjoin 1.0 nums))) | ||
| 437 | ;; own :test function - returns true if match | ||
| 438 | (should (equal '(1.0 1 2) (cl-adjoin 1.0 nums :test nil))) ;defaults to eql | ||
| 439 | (should (eq nums (cl-adjoin 2 nums :test myfn-p))) ;match | ||
| 440 | (should (equal '(3 1 2) (cl-adjoin 3 nums :test myfn-p))) ;no match | ||
| 441 | ;; own :test-not function - returns false if match | ||
| 442 | (should (equal '(1.0 1 2) (cl-adjoin 1.0 nums :test-not nil))) ;defaults to eql | ||
| 443 | (should (equal '(2 2) (cl-adjoin 2 '(2) :test-not myfn-p))) ; no match | ||
| 444 | (should (eq nums (cl-adjoin 2 nums :test-not myfn-p))) ; 1 matches | ||
| 445 | (should (eq nums (cl-adjoin 3 nums :test-not myfn-p))) ; 1 and 2 matches | ||
| 446 | |||
| 447 | ;; according to CLTL2 passing both :test and :test-not should signal error | ||
| 448 | ;;(should-error (cl-adjoin 3 nums :test 'myfn-p :test-not myfn-p)) | ||
| 449 | |||
| 450 | ;; own :key fn | ||
| 451 | (should (eq nums (cl-adjoin 3 nums :key (lambda (x) (if (evenp x) (1+ x) x))))) | ||
| 452 | (should (equal '(3 1 2) (cl-adjoin 3 nums :key (lambda (x) (if (evenp x) (+ 2 x) x))))) | ||
| 453 | |||
| 454 | ;; convert using :key, then compare with :test | ||
| 455 | (should (eq nums (cl-adjoin 1 nums :key 'int-to-string :test 'string=))) | ||
| 456 | (should (equal '(3 1 2) (cl-adjoin 3 nums :key 'int-to-string :test 'string=))) | ||
| 457 | (should-error (cl-adjoin 3 nums :key 'int-to-string :test myfn-p) | ||
| 458 | :type 'wrong-type-argument) | ||
| 459 | |||
| 460 | ;; convert using :key, then compare with :test-not | ||
| 461 | (should (eq nums (cl-adjoin 3 nums :key 'int-to-string :test-not 'string=))) | ||
| 462 | (should (equal '(1 1) (cl-adjoin 1 '(1) :key 'int-to-string :test-not 'string=))) | ||
| 463 | (should-error (cl-adjoin 1 nums :key 'int-to-string :test-not myfn-p) | ||
| 464 | :type 'wrong-type-argument))) | ||
| 465 | |||
| 425 | (ert-deftest cl-parse-integer () | 466 | (ert-deftest cl-parse-integer () |
| 426 | (should-error (cl-parse-integer "abc")) | 467 | (should-error (cl-parse-integer "abc")) |
| 427 | (should (null (cl-parse-integer "abc" :junk-allowed t))) | 468 | (should (null (cl-parse-integer "abc" :junk-allowed t))) |