1 ;;; font-parse-tests.el --- Test suite for font parsing.
3 ;; Copyright (C) 2011-2016 Free Software Foundation, Inc.
5 ;; Author: Chong Yidong <cyd@stupidchicken.com>
7 ;; Human-Keywords: internal
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; Type M-x test-font-parse RET to generate the test buffer.
32 (defvar font-parse-tests--data
33 `((" " ,(intern " ") nil nil nil nil
)
34 ("Monospace" Monospace nil nil nil nil
)
35 ("Monospace Serif" ,(intern "Monospace Serif") nil nil nil nil
)
36 ("Foo1" Foo1 nil nil nil nil
)
37 ("12" nil
12.0 nil nil nil
)
38 ("12 " ,(intern "12 ") nil nil nil nil
)
40 ("Foo:" Foo nil nil nil nil
)
41 ("Foo-8" Foo
8.0 nil nil nil
)
42 ("Foo-18:" Foo
18.0 nil nil nil
)
43 ("Foo-18:light" Foo
18.0 light nil nil
)
44 ("Foo 10:weight=bold" ,(intern "Foo 10") nil bold nil nil
)
45 ("Foo-12:weight=bold" Foo
12.0 bold nil nil
)
46 ("Foo 8-20:slant=oblique" ,(intern "Foo 8") 20.0 nil oblique nil
)
47 ("Foo:light:roman" Foo nil light roman nil
)
48 ("Foo:italic:roman" Foo nil nil roman nil
)
49 ("Foo 12:light:oblique" ,(intern "Foo 12") nil light oblique nil
)
50 ("Foo-12:demibold:oblique" Foo
12.0 demibold oblique nil
)
51 ("Foo:black:proportional" Foo nil black nil
0)
52 ("Foo-10:black:proportional" Foo
10.0 black nil
0)
53 ("Foo:weight=normal" Foo nil normal nil nil
)
54 ("Foo:weight=bold" Foo nil bold nil nil
)
55 ("Foo:weight=bold:slant=italic" Foo nil bold italic
)
56 ("Foo:weight=bold:slant=italic:mono" Foo nil bold italic
100)
57 ("Foo-10:demibold:slant=normal" Foo
10.0 demibold normal nil
)
58 ("Foo 11-16:oblique:weight=bold" ,(intern "Foo 11") 16.0 bold oblique nil
)
59 ("Foo:oblique:randomprop=randomtag:weight=bold" Foo nil bold oblique nil
)
60 ("Foo:randomprop=randomtag:bar=baz" Foo nil nil nil nil
)
61 ("Foo Book Light:bar=baz" ,(intern "Foo Book Light") nil nil nil nil
)
62 ("Foo Book Light 10:bar=baz" ,(intern "Foo Book Light 10") nil nil nil nil
)
63 ("Foo Book Light-10:bar=baz" ,(intern "Foo Book Light") 10.0 nil nil nil
)
65 ("Oblique" nil nil nil oblique nil
)
66 ("Bold 17" nil
17.0 bold nil nil
)
67 ("17 Bold" ,(intern "17") nil bold nil nil
)
68 ("Book Oblique 2" nil
2.0 book oblique nil
)
69 ("Bar 7" Bar
7.0 nil nil nil
)
70 ("Bar Ultra-Light" Bar nil ultra-light nil nil
)
71 ("Bar Light 8" Bar
8.0 light nil nil
)
72 ("Bar Book Medium 9" Bar
9.0 medium nil nil
)
73 ("Bar Semi-Bold Italic 10" Bar
10.0 semi-bold italic nil
)
74 ("Bar Semi-Condensed Bold Italic 11" Bar
11.0 bold italic nil
)
75 ("Foo 10 11" ,(intern "Foo 10") 11.0 nil nil nil
)
76 ("Foo 1985 Book" ,(intern "Foo 1985") nil book nil nil
)
77 ("Foo 1985 A Book" ,(intern "Foo 1985 A") nil book nil nil
)
78 ("Foo 1 Book 12" ,(intern "Foo 1") 12.0 book nil nil
)
79 ("Foo A Book 12 A" ,(intern "Foo A Book 12 A") nil nil nil nil
)
80 ("Foo 1985 Book 12 Oblique" ,(intern "Foo 1985 Book 12") nil nil oblique nil
)
81 ("Foo 1985 Book 12 Italic 10" ,(intern "Foo 1985 Book 12") 10.0 nil italic nil
)
82 ("Foo Book Bar 6 Italic" ,(intern "Foo Book Bar 6") nil nil italic nil
)
83 ("Foo Book Bar Bold" ,(intern "Foo Book Bar") nil bold nil nil
))
84 "List of font names parse data.
85 Each element should have the form
86 (NAME FAMILY SIZE WEIGHT SLANT SPACING)
87 where NAME is the name to parse, and the remainder are the
88 expected font properties from parsing NAME.")
90 (defun font-parse-check (name prop expected
)
91 (let ((result (font-get (font-spec :name name
) prop
)))
92 (if (and (symbolp result
) (symbolp expected
))
94 (equal result expected
))))
96 (put 'font-parse-check
'ert-explainer
'font-parse-explain
)
98 (defun font-parse-explain (name prop expected
)
99 (let ((result (font-get (font-spec :name name
) prop
))
100 (propname (symbol-name prop
)))
101 (format "Parsing `%s': expected %s `%s', got `%s'."
102 name
(substring propname
1) expected
103 (font-get (font-spec :name name
) prop
))))
105 (ert-deftest font-parse-tests
()
106 "Test parsing of Fontconfig-style and GTK-style font names."
107 (dolist (test font-parse-tests--data
)
108 (let* ((name (nth 0 test
)))
109 (should (font-parse-check name
:family
(nth 1 test
)))
110 (should (font-parse-check name
:size
(nth 2 test
)))
111 (should (font-parse-check name
:weight
(nth 3 test
)))
112 (should (font-parse-check name
:slant
(nth 4 test
)))
113 (should (font-parse-check name
:spacing
(nth 5 test
))))))
116 (defun test-font-parse ()
117 "Test font name parsing."
119 (switch-to-buffer (generate-new-buffer "*Font Pase Test*"))
120 (setq show-trailing-whitespace nil
)
121 (let ((pass-face '((t :foreground
"green")))
122 (fail-face '((t :foreground
"red"))))
123 (dolist (test font-parse-tests--data
)
124 (let* ((name (nth 0 test
))
125 (fs (font-spec :name name
))
126 (family (font-get fs
:family
))
127 (size (font-get fs
:size
))
128 (weight (font-get fs
:weight
))
129 (slant (font-get fs
:slant
))
130 (spacing (font-get fs
:spacing
)))
132 (if (> (current-column) 20)
134 (indent-to-column 21)
135 (insert (propertize (symbol-name family
)
136 'face
(if (eq family
(nth 1 test
))
139 (indent-to-column 40)
140 (insert (propertize (format "%s" size
)
141 'face
(if (equal size
(nth 2 test
))
144 (indent-to-column 48)
145 (insert (propertize (format "%s" weight
)
146 'face
(if (eq weight
(nth 3 test
))
149 (indent-to-column 60)
150 (insert (propertize (format "%s" slant
)
151 'face
(if (eq slant
(nth 4 test
))
154 (indent-to-column 69)
155 (insert (propertize (format "%s" spacing
)
156 'face
(if (eq spacing
(nth 5 test
))
160 (goto-char (point-min)))
163 ;; no-byte-compile: t
166 ;;; font-parse-tests.el ends here.