77let s: x11_based_gui = has (' gui_athena' ) || has (' gui_motif' )
88 \ || has (' gui_gtk2' ) || has (' gui_gnome' ) || has (' gui_gtk3' )
99
10+ " Reasons for 'skipped'.
11+ let s: not_supported = " Skipped: Feature/Option not supported by this GUI: "
12+ let s: not_implemented = " Skipped: Test not implemented yet for this GUI"
13+ let s: not_hosted = " Skipped: Test not hosted by the system/environment"
14+
1015" For KDE set a font, empty 'guifont' may cause a hang.
1116func SetUp ()
1217 if has (" gui_kde" )
@@ -36,61 +41,77 @@ func Test_1_set_secure()
3641endfunc
3742
3843func Test_getfontname_with_arg ()
39- if has (' gui_athena' ) || has (' gui_motif' )
44+ let skipped = ' '
45+
46+ if ! s: x11_based_gui
47+ let skipped = s: not_implemented
48+ elseif has (' gui_athena' ) || has (' gui_motif' )
4049 " Invalid font name. The result should be an empty string.
4150 call assert_equal (' ' , getfontname (' notexist' ))
4251
4352 " Valid font name. This is usually the real name of 7x13 by default.
44- let l: fname = ' -misc-fixed-medium-r-normal--13-120-75-75-c-70-iso8859-1'
45- call assert_equal (l: fname , getfontname (l: fname ))
53+ let fname = ' -misc-fixed-medium-r-normal--13-120-75-75-c-70-iso8859-1'
54+ call assert_equal (fname, getfontname (fname))
4655
4756 elseif has (' gui_gtk2' ) || has (' gui_gnome' ) || has (' gui_gtk3' )
4857 " Invalid font name. The result should be the name plus the default size.
4958 call assert_equal (' notexist 10' , getfontname (' notexist' ))
5059
5160 " Valid font name. This is usually the real name of Monospace by default.
52- let l: fname = ' Bitstream Vera Sans Mono 12'
53- call assert_equal (l: fname , getfontname (l: fname ))
54- else
55- throw " Skipped: Matched font name unpredictable to test on this GUI"
61+ let fname = ' Bitstream Vera Sans Mono 12'
62+ call assert_equal (fname, getfontname (fname))
63+ endif
64+
65+ if ! empty (skipped)
66+ throw skipped
5667 endif
5768endfunc
5869
5970func Test_getfontname_without_arg ()
60- let l: fname = getfontname ()
61- if has (' gui_kde' )
71+ let skipped = ' '
72+
73+ let fname = getfontname ()
74+
75+ if ! s: x11_based_gui
76+ let skipped = s: not_implemented
77+ elseif has (' gui_kde' )
6278 " 'expected' is the value specified by SetUp() above.
63- call assert_equal (' Courier 10 Pitch/8/-1/5/50/0/0/0/0/0' , l: fname )
79+ call assert_equal (' Courier 10 Pitch/8/-1/5/50/0/0/0/0/0' , fname)
6480 elseif has (' gui_athena' ) || has (' gui_motif' )
6581 " 'expected' is DFLT_FONT of gui_x11.c.
66- call assert_equal (' 7x13' , l: fname )
82+ call assert_equal (' 7x13' , fname)
6783 elseif has (' gui_gtk2' ) || has (' gui_gnome' ) || has (' gui_gtk3' )
6884 " 'expected' is DEFAULT_FONT of gui_gtk_x11.c.
69- call assert_equal (' Monospace 10' , l: fname )
70- else
71- throw " Skipped: Default font name unpredictable to test on this GUI"
85+ call assert_equal (' Monospace 10' , fname)
86+ endif
87+
88+ if ! empty (skipped)
89+ throw skipped
7290 endif
7391endfunc
7492
7593func Test_set_guifont ()
76- let l: guifont_saved = &guifont
94+ let skipped = ' '
95+
96+ let guifont_saved = &guifont
7797 if has (' xfontset' )
7898 " Prevent 'guifontset' from canceling 'guifont'.
79- let l: guifontset_saved = &guifontset
99+ let guifontset_saved = &guifontset
80100 set guifontset =
81101 endif
82102
83- let skipped = 0
84- if has (' gui_athena' ) || has (' gui_motif' )
103+ if ! s: x11_based_gui
104+ let skipped = s: not_implemented
105+ elseif has (' gui_athena' ) || has (' gui_motif' )
85106 " Non-empty font list with invalid font names.
86107 "
87108 " This test is twofold: (1) It checks if the command fails as expected
88109 " when there are no loadable fonts found in the list. (2) It checks if
89110 " 'guifont' remains the same after the command loads none of the fonts
90111 " listed.
91- let l: flist = &guifont
112+ let flist = &guifont
92113 call assert_fails (' set guifont=-notexist1-*,-notexist2-*' )
93- call assert_equal (l: flist , &guifont )
114+ call assert_equal (flist, &guifont )
94115
95116 " Non-empty font list with a valid font name. Should pick up the first
96117 " valid font.
@@ -116,107 +137,124 @@ func Test_set_guifont()
116137 " Empty list. Should fallback to the built-in default.
117138 set guifont =
118139 call assert_equal (' Monospace 10' , getfontname ())
119-
120- else
121- let skipped = 1
122140 endif
123141
124142 if has (' xfontset' )
125- let &guifontset = l: guifontset_saved
143+ let &guifontset = guifontset_saved
126144 endif
127- let &guifont = l: guifont_saved
145+ let &guifont = guifont_saved
128146
129- if skipped
130- throw " Skipped: Test not implemented yet for this GUI "
147+ if ! empty ( skipped)
148+ throw skipped
131149 endif
132150endfunc
133151
134152func Test_set_guifontset ()
135- let skipped = 0
153+ let skipped = ' '
136154
137- if has (' xfontset' )
138- let l: ctype_saved = v: ctype
139-
140- " For UTF-8 locales, XCreateFontSet(3) is likely to fail in constructing a
141- " fontset automatically from one or two simple XLFDs because it requires
142- " the host system to have a fairly comprehensive collection of fixed-width
143- " fonts with various sizes and registries/encodings in order to get the
144- " job done. To make the test meaningful for a wide variety of hosts, we
145- " confine ourselves to the following locale for which X11 historically has
146- " the fonts to use with.
147- language ctype ja_JP.eucJP
148-
149- " Since XCreateFontSet(3) is very sensitive to locale, fonts must be
150- " chosen meticulously.
151- let l: font_head = ' -misc-fixed-medium-r-normal--14'
152-
153- let l: font_aw70 = l: font_head . ' -130-75-75-c-70'
154- let l: font_aw140 = l: font_head . ' -130-75-75-c-140'
155+ if ! has (' xfontset' )
156+ let skipped = s: not_supported . ' xfontset'
157+ else
158+ let ctype_saved = v: ctype
155159
156- let l: font_jisx0201 = l: font_aw70 . ' -jisx0201.1976-0'
157- let l: font_jisx0208 = l: font_aw140 . ' -jisx0208.1983-0'
160+ " First, since XCreateFontSet(3) is very sensitive to locale, fonts must
161+ " be chosen meticulously.
162+ let font_head = ' -misc-fixed-medium-r-normal--14'
158163
159- " Full XLFDs
160- let l: fontset_name = join ([ l: font_jisx0208 , l: font_jisx0201 ], ' ,' )
161- exec ' set guifontset=' . l: fontset_name
162- call assert_equal (l: fontset_name , &guifontset )
164+ let font_aw70 = font_head . ' -130-75-75-c-70'
165+ let font_aw140 = font_head . ' -130-75-75-c-140'
163166
164- " XLFDs w/o CharSetRegistry and CharSetEncoding
165- let l: fontset_name = join ([ l: font_aw140 , l: font_aw70 ], ' ,' )
166- exec ' set guifontset=' . l: fontset_name
167- call assert_equal (l: fontset_name , &guifontset )
167+ let font_jisx0201 = font_aw70 . ' -jisx0201.1976-0'
168+ let font_jisx0208 = font_aw140 . ' -jisx0208.1983-0'
168169
169- " Singleton
170- let l: fontset_name = l: font_head . ' -* '
171- exec ' set guifontset= ' . l: fontset_name
172- call assert_equal ( l: fontset_name , & guifontset )
170+ let full_XLFDs = join ([ font_jisx0208, font_jisx0201 ], ' , ' )
171+ let short_XLFDs = join ([ font_aw140, font_aw70 ], ' , ' )
172+ let singleton = font_head . ' -* '
173+ let aliases = ' k14,r14 '
173174
174- " Aliases
175- let l: fontset_name = ' k14,r14'
176- exec ' set guifontset=' . l: fontset_name
177- call assert_equal (l: fontset_name , &guifontset )
175+ " Second, among 'locales', look up such a locale that gets 'set
176+ " guifontset=' to work successfully with every fontset specified with
177+ " 'fontsets'.
178+ let locales = [ ' ja_JP.UTF-8' , ' ja_JP.eucJP' , ' ja_JP.SJIS' ]
179+ let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ]
178180
179- exec ' language ctype' l: ctype_saved
181+ let feasible = 0
182+ for locale in locales
183+ try
184+ exec ' language ctype' locale
185+ catch /^Vim\%((\a\+)\)\=:E197/
186+ continue
187+ endtry
188+ let done = 0
189+ for fontset in fontsets
190+ try
191+ exec ' set guifontset=' . fontset
192+ catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/
193+ break
194+ endtry
195+ let done += 1
196+ endfor
197+ if done == len (fontsets)
198+ let feasible = 1
199+ break
200+ endif
201+ endfor
202+
203+ " Third, give a set of tests if it is found feasible.
204+ if ! feasible
205+ let skipped = s: not_hosted
206+ else
207+ " N.B. 'v:ctype' has already been set to an appropriate value in the
208+ " previous loop.
209+ for fontset in fontsets
210+ exec ' set guifontset=' . fontset
211+ call assert_equal (fontset, &guifontset )
212+ endfor
213+ endif
180214
181- else
182- let skipped = 1
215+ " Finally, restore ctype.
216+ exec ' language ctype ' ctype_saved
183217 endif
184218
185- if skipped
186- throw " Skipped: Not supported by this GUI "
219+ if ! empty ( skipped)
220+ throw skipped
187221 endif
188222endfunc
189223
190224func Test_set_guifontwide ()
191- let skipped = 0
192-
193- if has (' gui_gtk' )
194- let l: guifont_saved = &guifont
195- let l: guifontwide_saved = &guifontwide
196-
197- let l: fc_match = exepath (' fc-match' )
198- if l: fc_match != ' '
199- let &guifont = system (' fc-match -f "%{family[0]} %{size}" monospace:size=10' )
200- let l: wide = system (' fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=ja' )
201- exec ' set guifontwide=' . fnameescape (l: wide )
202- call assert_equal (l: wide , &guifontwide )
225+ let skipped = ' '
226+
227+ if ! s: x11_based_gui
228+ let skipped = s: not_implemented
229+ elseif has (' gui_gtk' )
230+ let guifont_saved = &guifont
231+ let guifontwide_saved = &guifontwide
232+
233+ let fc_match = exepath (' fc-match' )
234+ if empty (fc_match)
235+ let skipped = s: not_hosted
203236 else
204- let skipped = 3
237+ let &guifont = system (' fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=en' )
238+ let wide = system (' fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=ja' )
239+ exec ' set guifontwide=' . fnameescape (wide)
240+ call assert_equal (wide, &guifontwide )
205241 endif
206242
207- let &guifontwide = l: guifontwide_saved
208- let &guifont = l: guifont_saved
243+ let &guifontwide = guifontwide_saved
244+ let &guifont = guifont_saved
209245
210246 elseif has (' gui_athena' ) || has (' gui_motif' )
211247 " guifontwide is premised upon the xfontset feature.
212- if has (' xfontset' )
213- let l: encoding_saved = &encoding
214- let l: guifont_saved = &guifont
215- let l: guifontset_saved = &guifontset
216- let l: guifontwide_saved = &guifontwide
248+ if ! has (' xfontset' )
249+ let skipped = s: not_supported . ' xfontset'
250+ else
251+ let encoding_saved = &encoding
252+ let guifont_saved = &guifont
253+ let guifontset_saved = &guifontset
254+ let guifontwide_saved = &guifontwide
217255
218- let l: nfont = ' -misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1'
219- let l: wfont = ' -misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1'
256+ let nfont = ' -misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1'
257+ let wfont = ' -misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1'
220258
221259 set encoding = utf- 8
222260
@@ -225,18 +263,18 @@ func Test_set_guifontwide()
225263
226264 " Case 1-1: Automatic selection
227265 set guifontwide =
228- exec ' set guifont=' . l: nfont
229- call assert_equal (l: wfont , &guifontwide )
266+ exec ' set guifont=' . nfont
267+ call assert_equal (wfont, &guifontwide )
230268
231269 " Case 1-2: Manual selection
232- exec ' set guifontwide=' . l: wfont
233- exec ' set guifont=' . l: nfont
234- call assert_equal (l: wfont , &guifontwide )
270+ exec ' set guifontwide=' . wfont
271+ exec ' set guifont=' . nfont
272+ call assert_equal (wfont, &guifontwide )
235273
236274 " Case 2: guifontset is invalid
237275 try
238276 set guifontset = -*- notexist-*
239- call assert_false (1 , " 'set guifontset=notexist' should have failed" )
277+ call assert_false (1 , " 'set guifontset=-*- notexist-* ' should have failed" )
240278 catch
241279 call assert_exception (' E598' )
242280 endtry
@@ -245,31 +283,23 @@ func Test_set_guifontwide()
245283
246284 " Case 2-1: Automatic selection
247285 set guifontwide =
248- exec ' set guifont=' . l: nfont
249- call assert_equal (l: wfont , &guifontwide )
286+ exec ' set guifont=' . nfont
287+ call assert_equal (wfont, &guifontwide )
250288
251289 " Case 2-2: Manual selection
252- exec ' set guifontwide=' . l: wfont
253- exec ' set guifont=' . l: nfont
254- call assert_equal (l: wfont , &guifontwide )
255-
256- let &guifontwide = l: guifontwide_saved
257- let &guifontset = l: guifontset_saved
258- let &guifont = l: guifont_saved
259- let &encoding = l: encoding_saved
260- else
261- let skipped = 2
290+ exec ' set guifontwide=' . wfont
291+ exec ' set guifont=' . nfont
292+ call assert_equal (wfont, &guifontwide )
293+
294+ let &guifontwide = guifontwide_saved
295+ let &guifontset = guifontset_saved
296+ let &guifont = guifont_saved
297+ let &encoding = encoding_saved
262298 endif
263- else
264- let skipped = 1
265299 endif
266300
267- if skipped == 1
268- throw " Skipped: Test not implemented yet for this GUI"
269- elseif skipped == 2
270- throw " Skipped: Not supported by this GUI"
271- elseif skipped == 3
272- throw " Skipped: Test not supported by the environment"
301+ if ! empty (skipped)
302+ throw skipped
273303 endif
274304endfunc
275305
0 commit comments