characters.k (5571B)
1 ;; check.k & test-helpers.k should be loaded 2 ;; 3 ;; Tests of character features. 4 ;; 5 6 ;; 14.?.? char? 7 8 ($check-predicate (char?)) 9 ($check-predicate (char? #\newline #\space #\0 #\A #\a #\~)) 10 11 ($check-not-predicate (char? "")) 12 ($check-not-predicate (char? "a")) 13 ($check-not-predicate (char? 0)) 14 ($check-not-predicate (char? #f)) 15 ($check-not-predicate (char? ())) 16 ($check-not-predicate (char? #inert)) 17 18 ;; XXX char=? char<? char<=? char>? char>=? 19 20 ($check-predicate (char=? #\A #\A)) 21 ($check-not-predicate (char=? #\A #\B)) 22 ($check-not-predicate (char=? #\a #\A)) 23 24 ($check-predicate (char<? #\A #\B)) 25 ($check-not-predicate (char<? #\A #\A)) 26 ($check-not-predicate (char<? #\B #\A)) 27 28 ($check-predicate (char<=? #\A #\A)) 29 ($check-predicate (char<=? #\A #\B)) 30 ($check-not-predicate (char<=? #\B #\A)) 31 32 ($check-predicate (char>? #\B #\A)) 33 ($check-not-predicate (char>? #\A #\A)) 34 ($check-not-predicate (char>? #\A #\B)) 35 36 ($check-predicate (char>=? #\A #\A)) 37 ($check-predicate (char>=? #\B #\A)) 38 ($check-not-predicate (char>=? #\A #\B)) 39 40 ;; XXX char-ci=? char-ci<? char-ci<=? char-ci>? char-ci>=? 41 42 ($check-predicate ($true-for-all-combinations? char-ci=? (#\A #\a) (#\A #\a))) 43 ($check-predicate ($false-for-all-combinations? char-ci=? (#\A #\a) (#\B #\b))) 44 45 ($check-predicate ($true-for-all-combinations? char-ci<? (#\A #\a) (#\B #\b))) 46 ($check-predicate ($false-for-all-combinations? char-ci<? (#\A #\a #\B #\b) (#\A #\a))) 47 48 ($check-predicate ($true-for-all-combinations? char-ci<=? (#\A #\a) (#\A #\a #\B #\b))) 49 ($check-predicate ($false-for-all-combinations? char-ci<=? (#\B #\b) (#\A #\a))) 50 51 ($check-predicate ($true-for-all-combinations? char-ci>? (#\B #\b) (#\A #\a))) 52 ($check-predicate ($false-for-all-combinations? char-ci>? (#\A #\a #\B #\b) (#\B #\b))) 53 54 ($check-predicate ($true-for-all-combinations? char-ci>=? (#\A #\a #\B #\b) (#\A #\a))) 55 ($check-predicate ($false-for-all-combinations? char-ci>=? (#\A #\a) (#\B #\b))) 56 57 ;; XXX char-alphabetic? char-numeric? char-whitespace? 58 59 ($check-predicate (char-alphabetic? #\a #\A #\b #\B #\k #\T #\y #\Y #\Z #\z)) 60 ($check-predicate ($false-for-all? char-alphabetic? #\newline #\0 #\` #\@ #\{ #\[ #\~)) 61 62 ($check-predicate (char-numeric? #\0 #\1 #\5 #\8 #\9)) 63 ($check-predicate ($false-for-all? char-numeric? #\space #\/ #\: #\A)) 64 65 ($check-predicate (char-whitespace? #\space #\newline)) 66 ($check-predicate ($false-for-all? char-whitespace? #\0 #\a #\A #\:)) 67 ; TODO ($check-predicate (char-whitespace? #\tab #\return ....)) 68 69 ;; XXX char-upper-case? char-lower-case? 70 71 ($check-predicate (char-upper-case? #\A #\B #\R #\Y #\Z)) 72 ($check-predicate ($false-for-all? char-upper-case? #\0 #\a #\z #\' #\@ #\{ #\[ #\~)) 73 ($check-predicate (char-lower-case? #\a #\b #\j #\y #\z)) 74 ($check-predicate ($false-for-all? char-lower-case? #\0 #\A #\Z #\' #\@ #\{ #\[ #\~)) 75 76 ;; XXX char-upcase char-downcase char-titlecase char-foldcase 77 ($check equal? (char-upcase #\a) #\A) 78 ($check equal? (char-upcase #\z) #\Z) 79 ($check equal? (char-upcase #\R) #\R) 80 ($check equal? (char-upcase #\2) #\2) 81 82 ($check equal? (char-downcase #\A) #\a) 83 ($check equal? (char-downcase #\Z) #\z) 84 ($check equal? (char-downcase #\r) #\r) 85 ($check equal? (char-downcase #\9) #\9) 86 87 ($check equal? (char-titlecase #\a) #\A) 88 ($check equal? (char-titlecase #\z) #\Z) 89 ($check equal? (char-titlecase #\R) #\R) 90 ($check equal? (char-titlecase #\2) #\2) 91 92 ($check equal? (char-foldcase #\A) #\a) 93 ($check equal? (char-foldcase #\Z) #\z) 94 ($check equal? (char-foldcase #\r) #\r) 95 ($check equal? (char-foldcase #\9) #\9) 96 97 ;; XXX char->integer integer->char 98 99 ($check equal? (char->integer #\space) #x20) 100 ($check equal? (char->integer #\0) #x30) 101 ($check equal? (char->integer #\A) #x41) 102 ($check equal? (char->integer #\a) #x61) 103 104 ($check equal? (integer->char #x20) #\space) 105 ($check equal? (integer->char #x30) #\0) 106 ($check equal? (integer->char #x41) #\A) 107 ($check equal? (integer->char #x61) #\a) 108 109 ;; XXX char-digit? 110 ($check-predicate (char-digit? #\0)) 111 ($check-predicate (char-digit? #\9)) 112 ($check-not-predicate (char-digit? #\a)) 113 ($check-not-predicate (char-digit? #\2 2)) 114 ($check-predicate (char-digit? #\f 16)) 115 ($check-predicate (char-digit? #\F 16)) 116 ($check-not-predicate (char-digit? #\!)) 117 118 ;; errors 119 120 ($check-error (char-digit?)) 121 ($check-error (char-digit? 12)) 122 ($check-error (char-digit? #\9 10 #\a)) 123 ($check-error (char-digit? #\9 10 10)) 124 ($check-error (char-digit? #\0 1)) 125 ($check-error (char-digit? #\0 0)) 126 ($check-error (char-digit? #\0 -1)) 127 ($check-error (char-digit? #\0 37)) 128 129 ;; XXX char->digit 130 ($check =? (char->digit #\0) 0) 131 ($check =? (char->digit #\9) 9) 132 ($check =? (char->digit #\f 16) 15) 133 ($check =? (char->digit #\F 16) 15) 134 ($check =? (char->digit #\z 36) 35) 135 ($check =? (char->digit #\Z 36) 35) 136 137 ;; errors 138 ($check-error (char->digit)) 139 ($check-error (char->digit 0)) 140 ($check-error (char->digit #\0 10 10)) 141 ($check-error (char->digit #\0 1)) 142 ($check-error (char->digit #\0 37)) 143 ($check-error (char->digit #\0 0)) 144 ($check-error (char->digit #\0 -1)) 145 ($check-error (char->digit #\a 10)) 146 ($check-error (char->digit #\2 2)) 147 148 ;; XXX digit->char 149 ($check char=? (digit->char 0) #\0) 150 ($check char=? (digit->char 9) #\9) 151 ($check char=? (char-downcase (digit->char 15 16)) #\f) 152 ($check char=? (char-downcase (digit->char 35 36)) #\z) 153 154 ;; errors 155 ($check-error (digit->char)) 156 ($check-error (digit->char #\0)) 157 ($check-error (digit->char 0 10 10)) 158 ($check-error (digit->char 0 1)) 159 ($check-error (digit->char 0 37)) 160 ($check-error (digit->char 0 0)) 161 ($check-error (digit->char 0 -1)) 162 ($check-error (digit->char 10 10)) 163 ($check-error (digit->char 2 2))