Debian Codegraph @

src/tests/normal-tests/unicode.lsp

raw
1 ;;;; -*- encoding:utf-8; Mode: Lisp; Syntax: Common-Lisp; indent-tabs-mode: nil -*-
2 ;;;; vim: set filetype=lisp tabstop=8 shiftwidth=2 expandtab:
3
4 ;;;; Author: Vladimir Sedach <[email protected]>
5 ;;;; Created: 2020-05-03
6 ;;;; Contains: Unicode handling in the compiler and runtime
7
8 (in-package :cl-test)
9
10 (suite 'unicode)
11
12 ;;; Date: 2020-05-03
13 ;;; From: Vladimir Sedach <[email protected]>
14 ;;; Fixed: 2020-05-03 (Vladimir Sedach)
15 ;;; Description:
16 ;;;
17 ;;; Compiler does not handle non-ASCII symbols correctly when
18 ;;; READTABLE-CASE is :INVERT
19 ;;;
20 (test unicode.0001.compiler-unicode-inverted-case
21 (let ((test-readtable (copy-readtable)))
22 (dolist (case '(:invert :upcase :downcase :preserve))
23 (setf (readtable-case test-readtable) case)
24 (let ((*readtable* test-readtable))
25 (is (= 3
26 (funcall
27 (compile nil
28 (cons 'lambda
29 (read-from-string "((𝛅 𝛜) (+ 𝛅 𝛜))")))
30 1 2)))))))
31
32 ;;; Date: 2020-05-03
33 ;;; From: Vladimir Sedach <[email protected]>
34 ;;; Fixed: 2020-05-03 (Vladimir Sedach)
35 ;;; Description:
36 ;;;
37 ;;; Pathname :common case conversion fails on Unicode pathnames
38 ;;;
39 (test unicode.0002.pathname-common-unicode
40 (is (equal
41 "ДАННЫЕ"
42 (pathname-name (pathname "/tmp/данные.txt") :case :common))))
43
44 ;;; Date: 2020-05-03
45 ;;; From: Vladimir Sedach <[email protected]>
46 ;;; Fixed: 2020-05-03 (Vladimir Sedach)
47 ;;; Description:
48 ;;;
49 ;;; Symbol names that contain Unicode are not printed correctly
50 ;;;
51 (test unicode.0003.print-unicode-symbols
52 (is (string-equal
53 "АБРАКАДАБРА"
54 (format nil "~A" (read-from-string "абракадабра")))))
55
56 ;;; Date: 2020-05-03
57 ;;; From: Vladimir Sedach <[email protected]>
58 ;;; Fixed: 2020-05-03 (Vladimir Sedach)
59 ;;; Description:
60 ;;;
61 ;;; unicode.0003.print-unicode-symbols shows up as a compiler
62 ;;; error for symbol names that contain char codes between 128
63 ;;; and 255, possibly others
64 ;;;
65 (test unicode.0004.compile-unicode-symbols
66 (with-compiler ("unicode.0004.lsp" :load t)
67 "(defun unicode.0004 (x¹ y²)
68 (+ x¹ y²))")
69 (is (= 7 (unicode.0004 5 2))))
70
71 ;;; Date: 2021-02-28
72 ;;; From: Marius Gerbershagen
73 ;;; Description:
74 ;;;
75 ;;; Check that various pathname functions work correctly with
76 ;;; unicode characters
77 ;;;
78 (test unicode.0005.pathnames
79 ;; ensure-directories-exist
80 (multiple-value-bind (pathspec created)
81 (ensure-directories-exist #P"рецепты/")
82 (is (equal pathspec #P"рецепты/")))
83 (let ((files '(#P"рецепты/Spätzle-mit-Soß.txt"
84 #P"рецепты/Kartoffelklöße.txt"
85 #P"рецепты/Thüringer-Klöße.txt")))
86 ;; open, truename
87 (with-open-file (s (first files) :if-does-not-exist :create :if-exists :supersede :direction :output)
88 (is (equal (truename s) (merge-pathnames (first files)))))
89 (with-open-file (s (second files) :if-does-not-exist :create :if-exists :supersede :direction :output)
90 (is (equal (truename s) (merge-pathnames (second files)))))
91 ;; ext:copy-file
92 (is (ext:copy-file (second files) (third files)))
93 ;; directory
94 (is (equal (sort (directory "рецепты/*.txt") #'string< :key #'pathname-name)
95 (sort (mapcar #'merge-pathnames files) #'string< :key #'pathname-name)))
96 (is (equal (sort (directory "рецепты/*löße.txt") #'string< :key #'pathname-name)
97 (mapcar #'merge-pathnames (rest files))))
98 ;; probe-file
99 (is (equal (mapcar #'probe-file files) (mapcar #'merge-pathnames files)))
100 (is (null (probe-file #P"рецепты/Dosenkohl.txt")))
101 ;; file-author
102 (finishes (mapcar #'file-author files))
103 ;; file-write-date
104 (finishes (mapcar #'file-write-date files))
105 ;; rename-file
106 (let ((truename-2nd-file (truename (second files))))
107 (multiple-value-bind (default-new-name old-truename new-truename)
108 (rename-file (second files) #P"Semmelknödel.txt")
109 (is (equal default-new-name #P"рецепты/Semmelknödel.txt"))
110 (is (equal old-truename truename-2nd-file))
111 (is (equal new-truename (truename #P"рецепты/Semmelknödel.txt")))))
112 ;; delete-file
113 (is (delete-file #P"рецепты/Semmelknödel.txt"))
114 ;; file-error-pathname
115 (is (handler-case
116 (progn (open #P"рецепты/Semmelknödel.txt" :if-does-not-exist :error :if-exists nil)
117 nil)
118 (file-error (f)
119 (equal (file-error-pathname f) #P"рецепты/Semmelknödel.txt"))))
120 ;; check that we respect ext:*default-external-format*
121 #-windows
122 (let ((ext:*default-external-format* :pass-through))
123 (is (member (ext:string-to-octets "рецепты" :external-format :utf-8)
124 (directory "*/")
125 :test #'equalp
126 :key #'(lambda (p)
127 (map 'vector #'char-code
128 (first (last (pathname-directory p))))))))
129 ;; clean up
130 (is (delete-file (first files)))
131 (is (delete-file (third files)))
132 (is (delete-file #P"рецепты/"))))