| 1 |
;;; -*- Mode: LISP; Syntax: Ansi-Common-Lisp; Base: 10; Package: UAX-15-TESTS -*- |
| 2 |
|
| 3 |
(in-package :uax-15-tests) |
| 4 |
|
| 5 |
(define-test uax-15) |
| 6 |
|
| 7 |
(defun parse-hex-string-to-string (str) |
| 8 |
"Takes a string which may be one or more hex numbers e.g. '0044 0307', builds an array of characters, coerces to string and returns the string. Mostly used for testing." |
| 9 |
(let* ((split-str (split-sequence:split-sequence #\Space str :remove-empty-subseqs t)) |
| 10 |
(arry (make-array (length split-str)))) |
| 11 |
(loop for x in split-str counting x into y do |
| 12 |
(setf (aref arry (- y 1)) (parse-integer x :radix 16))) |
| 13 |
(uax-15:from-unicode-string (coerce arry 'uax-15:unicode-string)))) |
| 14 |
|
| 15 |
(defun hs-to-cs (str) |
| 16 |
"Syntactic sugar" |
| 17 |
(parse-hex-string-to-string str)) |
| 18 |
|
| 19 |
(defparameter *test-directory* (uiop:merge-pathnames* |
| 20 |
(make-pathname :directory (list :relative "t") :name nil :type nil) |
| 21 |
(asdf:system-source-directory (asdf:find-system 'uax-15 nil)))) |
| 22 |
|
| 23 |
(defun read-test-data (fname) |
| 24 |
(with-open-file (in (uiop:merge-pathnames* *test-directory* fname)) |
| 25 |
(loop for line = (read-line in nil nil) |
| 26 |
while line |
| 27 |
collect (cl-ppcre:split ";" line)))) |
| 28 |
|
| 29 |
(defun first-failure (fname fmt) |
| 30 |
"Reports the data line for the first failure for debugging purposes where fname is the test data filename and fmt is e.g. :nfkc" |
| 31 |
(loop for x in (read-test-data fname) counting x into y do |
| 32 |
(when (not (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (first x)) fmt))) |
| 33 |
(format t "Failure Line ~a ~a fourth should equal normalized first" y x) |
| 34 |
(return-from first-failure)))) |
| 35 |
|
| 36 |
(defparameter *part0* (read-test-data "test-part0-15.txt")) |
| 37 |
(defparameter *part1* (read-test-data "test-part1-15.txt")) |
| 38 |
(defparameter *part2* (read-test-data "test-part2-15.txt")) |
| 39 |
(defparameter *part3* (read-test-data "test-part3-15.txt")) |
| 40 |
|
| 41 |
(define-test suite) |
| 42 |
|
| 43 |
(define-test part0-nfkc |
| 44 |
:parent suite |
| 45 |
(loop for x in *part0* do |
| 46 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (first x)) :nfkc))) |
| 47 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (second x)) :nfkc))) |
| 48 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (third x)) :nfkc))) |
| 49 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (fifth x)) :nfkc))))) |
| 50 |
|
| 51 |
(define-test part1-nfkc |
| 52 |
:parent suite |
| 53 |
(loop for x in *part1* do |
| 54 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (first x)) :nfkc))) |
| 55 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (second x)) :nfkc))) |
| 56 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (third x)) :nfkc))) |
| 57 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (fifth x)) :nfkc))))) |
| 58 |
|
| 59 |
(define-test part2-nfkc |
| 60 |
:parent suite |
| 61 |
(loop for x in *part2* do |
| 62 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (first x)) :nfkc))) |
| 63 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (second x)) :nfkc))) |
| 64 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (third x)) :nfkc))) |
| 65 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (fifth x)) :nfkc))))) |
| 66 |
|
| 67 |
(define-test part3-nfkc |
| 68 |
:parent suite |
| 69 |
(loop for x in *part3* do |
| 70 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (first x)) :nfkc))) |
| 71 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (second x)) :nfkc))) |
| 72 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (third x)) :nfkc))) |
| 73 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (fifth x)) :nfkc))))) |
| 74 |
|
| 75 |
(define-test part0-nfkd |
| 76 |
:parent suite |
| 77 |
(loop for x in *part0* do |
| 78 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (first x)) :nfkd))) |
| 79 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (second x)) :nfkd))) |
| 80 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (third x)) :nfkd))) |
| 81 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (fourth x)) :nfkd))))) |
| 82 |
|
| 83 |
(define-test part1-nfkd |
| 84 |
:parent suite |
| 85 |
(loop for x in *part1* do |
| 86 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (first x)) :nfkd))) |
| 87 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (second x)) :nfkd))) |
| 88 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (third x)) :nfkd))) |
| 89 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (fourth x)) :nfkd))))) |
| 90 |
|
| 91 |
(define-test part2-nfkd |
| 92 |
:parent suite |
| 93 |
(loop for x in *part2* do |
| 94 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (first x)) :nfkd))) |
| 95 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (second x)) :nfkd))) |
| 96 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (third x)) :nfkd))) |
| 97 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (fourth x)) :nfkd))))) |
| 98 |
|
| 99 |
(define-test part3-nfkd |
| 100 |
:parent suite |
| 101 |
(loop for x in *part3* do |
| 102 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (first x)) :nfkd))) |
| 103 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (second x)) :nfkd))) |
| 104 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (third x)) :nfkd))) |
| 105 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (fourth x)) :nfkd))))) |
| 106 |
|
| 107 |
(define-test part0-nfc |
| 108 |
:parent suite |
| 109 |
(loop for x in *part0* do |
| 110 |
(true (equal (hs-to-cs (second x)) (normalize (hs-to-cs (first x)) :nfc))) |
| 111 |
(true (equal (hs-to-cs (second x)) (normalize (hs-to-cs (second x)) :nfc))) |
| 112 |
(true (equal (hs-to-cs (second x)) (normalize (hs-to-cs (third x)) :nfc))) |
| 113 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (fourth x)) :nfc))) |
| 114 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (fifth x)) :nfc))))) |
| 115 |
|
| 116 |
(define-test part1-nfc |
| 117 |
:parent suite |
| 118 |
(loop for x in *part1* do |
| 119 |
(true (equal (hs-to-cs (second x)) (normalize (hs-to-cs (first x)) :nfc))) |
| 120 |
(true (equal (hs-to-cs (second x)) (normalize (hs-to-cs (second x)) :nfc))) |
| 121 |
(true (equal (hs-to-cs (second x)) (normalize (hs-to-cs (third x)) :nfc))) |
| 122 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (fourth x)) :nfc))) |
| 123 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (fifth x)) :nfc))))) |
| 124 |
|
| 125 |
(define-test part2-nfc |
| 126 |
:parent suite |
| 127 |
(loop for x in *part2* do |
| 128 |
(true (equal (hs-to-cs (second x)) (normalize (hs-to-cs (first x)) :nfc))) |
| 129 |
(true (equal (hs-to-cs (second x)) (normalize (hs-to-cs (second x)) :nfc))) |
| 130 |
(true (equal (hs-to-cs (second x)) (normalize (hs-to-cs (third x)) :nfc))) |
| 131 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (fourth x)) :nfc))) |
| 132 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (fifth x)) :nfc))))) |
| 133 |
|
| 134 |
(define-test part3-nfc |
| 135 |
:parent suite |
| 136 |
(loop for x in *part3* do |
| 137 |
(true (equal (hs-to-cs (second x)) (normalize (hs-to-cs (first x)) :nfc))) |
| 138 |
(true (equal (hs-to-cs (second x)) (normalize (hs-to-cs (second x)) :nfc))) |
| 139 |
(true (equal (hs-to-cs (second x)) (normalize (hs-to-cs (third x)) :nfc))) |
| 140 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (fourth x)) :nfc))) |
| 141 |
(true (equal (hs-to-cs (fourth x)) (normalize (hs-to-cs (fifth x)) :nfc))))) |
| 142 |
|
| 143 |
(define-test part0-nfd |
| 144 |
:parent suite |
| 145 |
(loop for x in *part0* do |
| 146 |
(true (equal (hs-to-cs (third x)) (normalize (hs-to-cs (first x)) :nfd))) |
| 147 |
(true (equal (hs-to-cs (third x)) (normalize (hs-to-cs (second x)) :nfd))) |
| 148 |
(true (equal (hs-to-cs (third x)) (normalize (hs-to-cs (third x)) :nfd))) |
| 149 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (fourth x)) :nfd))) |
| 150 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (fifth x)) :nfd))))) |
| 151 |
|
| 152 |
(define-test part1-nfd |
| 153 |
:parent suite |
| 154 |
(loop for x in *part1* do |
| 155 |
(true (equal (hs-to-cs (third x)) (normalize (hs-to-cs (first x)) :nfd))) |
| 156 |
(true (equal (hs-to-cs (third x)) (normalize (hs-to-cs (second x)) :nfd))) |
| 157 |
(true (equal (hs-to-cs (third x)) (normalize (hs-to-cs (third x)) :nfd))) |
| 158 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (fourth x)) :nfd))) |
| 159 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (fifth x)) :nfd))))) |
| 160 |
|
| 161 |
(define-test part2-nfd |
| 162 |
:parent suite |
| 163 |
(loop for x in *part2* do |
| 164 |
(true (equal (hs-to-cs (third x)) (normalize (hs-to-cs (first x)) :nfd))) |
| 165 |
(true (equal (hs-to-cs (third x)) (normalize (hs-to-cs (second x)) :nfd))) |
| 166 |
(true (equal (hs-to-cs (third x)) (normalize (hs-to-cs (third x)) :nfd))) |
| 167 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (fourth x)) :nfd))) |
| 168 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (fifth x)) :nfd))))) |
| 169 |
|
| 170 |
(define-test part3-nfd |
| 171 |
:parent suite |
| 172 |
(loop for x in *part3* do |
| 173 |
(true (equal (hs-to-cs (third x)) (normalize (hs-to-cs (first x)) :nfd))) |
| 174 |
(true (equal (hs-to-cs (third x)) (normalize (hs-to-cs (second x)) :nfd))) |
| 175 |
(true (equal (hs-to-cs (third x)) (normalize (hs-to-cs (third x)) :nfd))) |
| 176 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (fourth x)) :nfd))) |
| 177 |
(true (equal (hs-to-cs (fifth x)) (normalize (hs-to-cs (fifth x)) :nfd))))) |
| 178 |
|
| 179 |
(define-test unicode-letters |
| 180 |
:parent suite |
| 181 |
(true (every #'unicode-letter-p "새우")) |
| 182 |
(true (every #'unicode-letter-p "이해")) |
| 183 |
(false (every #'unicode-letter-p "zAp2")) |
| 184 |
(true (every #'unicode-letter-p "タイムゾーン")) |
| 185 |
(true (every #'unicode-letter-p "タイムゾーン")) |
| 186 |
(true (every #'unicode-letter-p "时区")) |
| 187 |
(true (every #'unicode-letter-p "時區"))) |