8546abcdc9077022afbc474489239793aa89d64a
[sbcl.git] / tests / character.pure.lisp
1 ;;;; various CHARACTER tests without side effects
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
8 ;;;; from CMU CL.
9 ;;;; 
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
13
14 (cl:in-package :cl-user)
15
16 (load "assertoid.lisp")
17
18 ;;; ANSI's specification of #'CHAR-NAME imposes these constraints.
19 ;;;
20 ;;; (Obviously, the numeric values in this test implicitly assume
21 ;;; we're using an ASCII-based character set.)
22 (dolist (i '(("Newline" 10)
23              ;; (ANSI also imposes a constraint on the "semi-standard
24              ;; character" "Linefeed", but in ASCII as interpreted by
25              ;; Unix it's shadowed by "Newline" and so doesn't exist
26              ;; as a separate character.)
27              ("Space" 32)
28              ("Tab" 9)
29              ("Page" 12)
30              ("Rubout" 127)
31              ("Return" 13)
32              ("Backspace" 8)))
33   (destructuring-bind (name code) i
34     (let ((named-char (name-char name))
35           (coded-char (code-char code)))
36       (assert (eql named-char coded-char))
37       (assert (characterp named-char))
38       (let ((coded-char-name (char-name coded-char)))
39         (assert (string= name coded-char-name))))))
40
41 ;;; bug 230: CHAR= didn't check types of &REST arguments
42 (dolist (form '((code-char char-code-limit)
43                 (standard-char-p "a")
44                 (graphic-char-p "a")
45                 (alpha-char-p "a")
46                 (upper-case-p "a")
47                 (lower-case-p "a")
48                 (both-case-p "a")
49                 (digit-char-p "a")
50                 (alphanumericp "a")
51                 (char= #\a "a")
52                 (char/= #\a "a")
53                 (char< #\a #\b "c")
54                 (char-equal #\a #\a "b")
55                 (digit-char -1)
56                 (digit-char 4 1)
57                 (digit-char 4 37)))
58   (assert (raises-error? (apply (car form) (mapcar 'eval (cdr form))) type-error)))