aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2011-01-27 18:45:04 -0500
committerChong Yidong2011-01-27 18:45:04 -0500
commit372fb76be972e1d8769a83331da3b87632b423b3 (patch)
tree61e075421c2cf0b64205a2114ad1da1a2e1c9389
parent19cc66979d336c0b62cf770ecb5863a86cfd510e (diff)
downloademacs-372fb76be972e1d8769a83331da3b87632b423b3.tar.gz
emacs-372fb76be972e1d8769a83331da3b87632b423b3.zip
Convert font parse testsuite to an ERT test.
* test/automated/font-parse-tests.el: Move from font-parse-testsuite.el. * src/font.c (font_parse_fcname): Undefine a temporary macro.
-rw-r--r--src/ChangeLog4
-rw-r--r--src/font.c1
-rw-r--r--test/ChangeLog5
-rw-r--r--test/automated/font-parse-tests.el163
-rw-r--r--test/font-parse-testsuite.el135
5 files changed, 173 insertions, 135 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 62782e63eef..2caec5e5d11 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
12011-01-27 Chong Yidong <cyd@stupidchicken.com>
2
3 * font.c (font_parse_fcname): Undefine a temporary macro.
4
12011-01-26 Stefan Monnier <monnier@iro.umontreal.ca> 52011-01-26 Stefan Monnier <monnier@iro.umontreal.ca>
2 6
3 Let the debugger continue to the normal handler (bug#7825). 7 Let the debugger continue to the normal handler (bug#7825).
diff --git a/src/font.c b/src/font.c
index 52b239569bd..449169dad1b 100644
--- a/src/font.c
+++ b/src/font.c
@@ -1513,6 +1513,7 @@ font_parse_fcname (char *name, Lisp_Object font)
1513 } 1513 }
1514 } 1514 }
1515#undef PROP_MATCH 1515#undef PROP_MATCH
1516#undef PROP_SAVE
1516 1517
1517 if (family_end) 1518 if (family_end)
1518 ASET (font, FONT_FAMILY_INDEX, 1519 ASET (font, FONT_FAMILY_INDEX,
diff --git a/test/ChangeLog b/test/ChangeLog
index b03e372b8b9..f555878cb49 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
12011-01-27 Chong Yidong <cyd@stupidchicken.com>
2
3 * automated/font-parse-tests.el: Move from
4 font-parse-testsuite.el.
5
12011-01-26 Chong Yidong <cyd@stupidchicken.com> 62011-01-26 Chong Yidong <cyd@stupidchicken.com>
2 7
3 * font-parse-testsuite.el (test-font-parse-data): New file. 8 * font-parse-testsuite.el (test-font-parse-data): New file.
diff --git a/test/automated/font-parse-tests.el b/test/automated/font-parse-tests.el
new file mode 100644
index 00000000000..5fc0f6c604f
--- /dev/null
+++ b/test/automated/font-parse-tests.el
@@ -0,0 +1,163 @@
1;;; font-parse-tests.el --- Test suite for font parsing.
2
3;; Copyright (C) 2011 Free Software Foundation, Inc.
4
5;; Author: Chong Yidong <cyd@stupidchicken.com>
6;; Keywords: internal
7;; Human-Keywords: internal
8
9;; This file is part of GNU Emacs.
10
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.
15
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.
20
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/>.
23
24;;; Commentary:
25
26;; Type M-x test-font-parse RET to generate the test buffer.
27
28;; TODO: Convert to ERT format.
29
30;;; Code:
31
32(require 'ert)
33
34(defvar font-parse-tests--data
35 `((" " ,(intern " ") nil nil nil nil)
36 ("Monospace" Monospace nil nil nil nil)
37 ("Foo1" Foo1 nil nil nil nil)
38 ("12" nil 12.0 nil nil nil)
39 ("12 " ,(intern "12 ") nil nil nil nil)
40 ;; Fontconfig format
41 ("Foo:" Foo nil nil nil nil)
42 ("Foo-8" Foo 8.0 nil nil nil)
43 ("Foo-18:" Foo 18.0 nil nil nil)
44 ("Foo-18:light" Foo 18.0 light nil nil)
45 ("Foo 10:weight=bold" ,(intern "Foo 10") nil bold nil nil)
46 ("Foo-12:weight=bold" Foo 12.0 bold nil nil)
47 ("Foo 8-20:slant=oblique" ,(intern "Foo 8") 20.0 nil oblique nil)
48 ("Foo:light:roman" Foo nil light roman nil)
49 ("Foo:italic:roman" Foo nil nil roman nil)
50 ("Foo 12:light:oblique" ,(intern "Foo 12") nil light oblique nil)
51 ("Foo-12:demibold:oblique" Foo 12.0 demibold oblique nil)
52 ("Foo:black:proportional" Foo nil black nil 0)
53 ("Foo-10:black:proportional" Foo 10.0 black nil 0)
54 ("Foo:weight=normal" Foo nil normal nil nil)
55 ("Foo:weight=bold" Foo nil bold nil nil)
56 ("Foo:weight=bold:slant=italic" Foo nil bold italic)
57 ("Foo:weight=bold:slant=italic:mono" Foo nil bold italic 100)
58 ("Foo-10:demibold:slant=normal" Foo 10.0 demibold normal nil)
59 ("Foo 11-16:oblique:weight=bold" ,(intern "Foo 11") 16.0 bold oblique nil)
60 ("Foo:oblique:randomprop=randomtag:weight=bold" Foo nil bold oblique nil)
61 ("Foo:randomprop=randomtag:bar=baz" Foo nil nil nil nil)
62 ("Foo Book Light:bar=baz" ,(intern "Foo Book Light") nil nil nil nil)
63 ("Foo Book Light 10:bar=baz" ,(intern "Foo Book Light 10") nil nil nil nil)
64 ("Foo Book Light-10:bar=baz" ,(intern "Foo Book Light") 10.0 nil nil nil)
65 ;; GTK format
66 ("Oblique" nil nil nil oblique nil)
67 ("Bold 17" nil 17.0 bold nil nil)
68 ("17 Bold" ,(intern "17") nil bold nil nil)
69 ("Book Oblique 2" nil 2.0 book oblique nil)
70 ("Bar 7" Bar 7.0 nil nil nil)
71 ("Bar Ultra-Light" Bar nil ultra-light nil nil)
72 ("Bar Light 8" Bar 8.0 light nil nil)
73 ("Bar Book Medium 9" Bar 9.0 medium nil nil)
74 ("Bar Semi-Bold Italic 10" Bar 10.0 semi-bold italic nil)
75 ("Bar Semi-Condensed Bold Italic 11" Bar 11.0 bold italic nil)
76 ("Foo 10 11" ,(intern "Foo 10") 11.0 nil nil nil)
77 ("Foo 1985 Book" ,(intern "Foo 1985") nil book nil nil)
78 ("Foo 1985 A Book" ,(intern "Foo 1985 A") nil book nil nil)
79 ("Foo 1 Book 12" ,(intern "Foo 1") 12.0 book nil nil)
80 ("Foo A Book 12 A" ,(intern "Foo A Book 12 A") nil nil nil nil)
81 ("Foo 1985 Book 12 Oblique" ,(intern "Foo 1985 Book 12") nil nil oblique nil)
82 ("Foo 1985 Book 12 Italic 10" ,(intern "Foo 1985 Book 12") 10.0 nil italic nil)
83 ("Foo Book Bar 6 Italic" ,(intern "Foo Book Bar 6") nil nil italic nil)
84 ("Foo Book Bar Bold" ,(intern "Foo Book Bar") nil bold nil nil))
85 "List of font names parse data.
86Each element should have the form
87 (NAME FAMILY SIZE WEIGHT SLANT SPACING)
88where NAME is the name to parse, and the remainder are the
89expected font properties from parsing NAME.")
90
91(defun font-parse-check (name prop expected)
92 (let ((result (font-get (font-spec :name name) prop)))
93 (if (and (symbolp result) (symbolp expected))
94 (eq result expected)
95 (equal result expected))))
96
97(put 'font-parse-check 'ert-explainer 'font-parse-explain)
98
99(defun font-parse-explain (name prop expected)
100 (let ((result (font-get (font-spec :name name) prop))
101 (propname (symbol-name prop)))
102 (format "Parsing `%s': expected %s `%s', got `%s'."
103 name (substring propname 1) expected
104 (font-get (font-spec :name name) prop))))
105
106(ert-deftest font-parse-tests ()
107 "Test parsing of Fontconfig-style and GTK-style font names."
108 (dolist (test font-parse-tests--data)
109 (let* ((name (nth 0 test)))
110 (should (font-parse-check name :family (nth 1 test)))
111 (should (font-parse-check name :size (nth 2 test)))
112 (should (font-parse-check name :weight (nth 3 test)))
113 (should (font-parse-check name :slant (nth 4 test)))
114 (should (font-parse-check name :spacing (nth 5 test))))))
115
116
117(defun test-font-parse ()
118 "Test font name parsing."
119 (interactive)
120 (switch-to-buffer (generate-new-buffer "*Font Pase Test*"))
121 (setq show-trailing-whitespace nil)
122 (let ((pass-face '((t :foreground "green")))
123 (fail-face '((t :foreground "red"))))
124 (dolist (test font-parse-tests--data)
125 (let* ((name (nth 0 test))
126 (fs (font-spec :name name))
127 (family (font-get fs :family))
128 (size (font-get fs :size))
129 (weight (font-get fs :weight))
130 (slant (font-get fs :slant))
131 (spacing (font-get fs :spacing)))
132 (insert name)
133 (if (> (current-column) 20)
134 (insert "\n"))
135 (indent-to-column 21)
136 (insert (propertize (symbol-name family)
137 'face (if (eq family (nth 1 test))
138 pass-face
139 fail-face)))
140 (indent-to-column 40)
141 (insert (propertize (format "%s" size)
142 'face (if (equal size (nth 2 test))
143 pass-face
144 fail-face)))
145 (indent-to-column 48)
146 (insert (propertize (format "%s" weight)
147 'face (if (eq weight (nth 3 test))
148 pass-face
149 fail-face)))
150 (indent-to-column 60)
151 (insert (propertize (format "%s" slant)
152 'face (if (eq slant (nth 4 test))
153 pass-face
154 fail-face)))
155 (indent-to-column 69)
156 (insert (propertize (format "%s" spacing)
157 'face (if (eq spacing (nth 5 test))
158 pass-face
159 fail-face)))
160 (insert "\n"))))
161 (goto-char (point-min)))
162
163;;; font-parse-tests.el ends here.
diff --git a/test/font-parse-testsuite.el b/test/font-parse-testsuite.el
deleted file mode 100644
index 02923159e83..00000000000
--- a/test/font-parse-testsuite.el
+++ /dev/null
@@ -1,135 +0,0 @@
1;;; redisplay-testsuite.el --- Test suite for redisplay.
2
3;; Copyright (C) 2011 Free Software Foundation, Inc.
4
5;; Author: Chong Yidong <cyd@stupidchicken.com>
6;; Keywords: internal
7;; Human-Keywords: internal
8
9;; This file is part of GNU Emacs.
10
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.
15
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.
20
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/>.
23
24;;; Commentary:
25
26;; Type M-x test-font-parse RET to generate the test buffer.
27
28;; TODO: Convert to ERT format.
29
30;;; Code:
31
32(defvar test-font-parse-data
33 '((" " " " nil nil nil nil)
34 ("Monospace" "Monospace" nil nil nil nil)
35 ("Foo1" "Foo1" nil nil nil nil)
36 ("12" "nil" 12.0 nil nil nil)
37 ("12 " "12 " nil nil nil nil)
38 ;; Fontconfig format
39 ("Foo:" "Foo" nil nil nil nil)
40 ("Foo-8" "Foo" 8.0 nil nil nil)
41 ("Foo-18:" "Foo" 18.0 nil nil nil)
42 ("Foo-18:light" "Foo" 18.0 light nil nil)
43 ("Foo 10:weight=bold" "Foo 10" nil bold nil nil)
44 ("Foo-12:weight=bold" "Foo" 12.0 bold nil nil)
45 ("Foo 8-20:slant=oblique" "Foo 8" 20.0 nil oblique nil)
46 ("Foo:light:roman" "Foo" nil light roman nil)
47 ("Foo:italic:roman" "Foo" nil nil roman nil)
48 ("Foo 12:light:oblique" "Foo 12" nil light oblique nil)
49 ("Foo-12:demibold:oblique" "Foo" 12.0 demibold oblique nil)
50 ("Foo:black:proportional" "Foo" nil black nil 0)
51 ("Foo-10:black:proportional" "Foo" 10.0 black nil 0)
52 ("Foo:weight=normal" "Foo" nil normal nil nil)
53 ("Foo:weight=bold" "Foo" nil bold nil nil)
54 ("Foo:weight=bold:slant=italic" "Foo" nil bold italic)
55 ("Foo:weight=bold:slant=italic:mono" "Foo" nil bold italic 100)
56 ("Foo-10:demibold:slant=normal" "Foo" 10.0 demibold normal nil)
57 ("Foo 11-16:oblique:weight=bold" "Foo 11" 16.0 bold oblique nil)
58 ("Foo:oblique:randomprop=randomtag:weight=bold"
59 "Foo" nil bold oblique nil)
60 ("Foo:randomprop=randomtag:bar=baz" "Foo" nil nil nil nil)
61 ("Foo Book Light:bar=baz" "Foo Book Light" nil nil nil nil)
62 ("Foo Book Light 10:bar=baz" "Foo Book Light 10" nil nil nil nil)
63 ("Foo Book Light-10:bar=baz" "Foo Book Light" 10.0 nil nil nil)
64 ;; GTK format
65 ("Oblique" "nil" nil nil oblique nil)
66 ("Bold 17" "nil" 17.0 bold nil nil)
67 ("17 Bold" "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" "Foo 10" 11.0 nil nil nil)
76 ("Foo 1985 Book" "Foo 1985" nil book nil nil)
77 ("Foo 1985 A Book" "Foo 1985 A" nil book nil nil)
78 ("Foo A Book 12 A" "Foo A Book 12 A" nil nil nil nil)
79 ("Foo 1985 Book 12 Oblique" "Foo 1985 Book 12" nil nil oblique nil)
80 ("Foo 1985 Book 12 Italic 10" "Foo 1985 Book 12" 10.0 nil italic nil)
81 ("Foo Book Bar 6 Italic" "Foo Book Bar 6" nil nil italic nil)
82 ("Foo Book Bar Bold" "Foo Book Bar" nil bold nil nil))
83 "List of font names parse data.
84Each element should have the form
85 (NAME FAMILY SIZE WEIGHT SLANT SPACING)
86where NAME is the name to parse, and the remainder are the
87expected font properties from parsing NAME.")
88
89(defun test-font-parse ()
90 "Test font name parsing."
91 (interactive)
92 (switch-to-buffer (generate-new-buffer "*Font Pase Test*"))
93 (setq show-trailing-whitespace nil)
94 (let ((pass-face '((t :foreground "green")))
95 (fail-face '((t :foreground "red"))))
96 (dolist (test test-font-parse-data)
97 (let* ((name (nth 0 test))
98 (fs (font-spec :name name))
99 (family (symbol-name (font-get fs :family)))
100 (size (font-get fs :size))
101 (weight (font-get fs :weight))
102 (slant (font-get fs :slant))
103 (spacing (font-get fs :spacing)))
104 (insert name)
105 (if (> (current-column) 20)
106 (insert "\n"))
107 (indent-to-column 21)
108 (insert (propertize family
109 'face (if (equal family (nth 1 test))
110 pass-face
111 fail-face)))
112 (indent-to-column 40)
113 (insert (propertize (format "%s" size)
114 'face (if (equal size (nth 2 test))
115 pass-face
116 fail-face)))
117 (indent-to-column 48)
118 (insert (propertize (format "%s" weight)
119 'face (if (eq weight (nth 3 test))
120 pass-face
121 fail-face)))
122 (indent-to-column 60)
123 (insert (propertize (format "%s" slant)
124 'face (if (eq slant (nth 4 test))
125 pass-face
126 fail-face)))
127 (indent-to-column 69)
128 (insert (propertize (format "%s" spacing)
129 'face (if (eq spacing (nth 5 test))
130 pass-face
131 fail-face)))
132 (insert "\n"))))
133 (goto-char (point-min)))
134
135;;; font-parse-testsuite.el ends here.