File: misc.lisp

package info (click to toggle)
cl-cxml 20110619-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 888 kB
  • sloc: lisp: 9,331; xml: 1,925; sh: 32; makefile: 18
file content (45 lines) | stat: -rw-r--r-- 1,458 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
;;;
;;; When I'll grow up, I'll be a complete test suite.

(deftest utf-8
    (flet ((doit (from below)
	     (loop for code from from below below do
		  (when (and (code-char code)
			     (not (eql code #xfffe))
			     (not (eql code #xffff)))
		    (let* ((a (if (< code #x10000)
				  (format nil "abc~C" (code-char code))
				  (let* ((x (- code #x10000))
					 (lo (ldb (byte 10 0) x))
					 (hi (ldb (byte 10 10) x)))
				    (format nil "abc~C~C"
					    (code-char (logior #xD800 hi))
					    (code-char 
					     (logior #xDC00 lo))))))
			   (b (cxml:utf8-string-to-rod
			       (cxml:rod-to-utf8-string
				a))))
		      (unless (string= a b)
			(format t "FAIL: ~S ~A ~A~%"
				(code-char code)
				(map 'vector #'char-code a)
				(map 'vector #'char-code b))))))))
      (doit 32 #xD800)
      (doit #x10000 char-code-limit)
      (values)))

;; <4824D34F.5000002@acceleration.net>
(deftest chtml-encoding
  (with-output-to-string (stream)
   (let ((doc (dom:create-document
             'rune-dom:implementation
             nil nil
             (dom:create-document-type
              'rune-dom:implementation
              "html"
              "-//W3C//DTD XHTML 1.0 Transitional//EN"
              "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"))))
     (dom:map-document (chtml:make-character-stream-sink stream)
           doc
           :include-xmlns-attributes nil
           :include-doctype :full-internal-subset))))