Document quit and exit
[bpt/guile.git] / test-suite / tests / texinfo.test
CommitLineData
de9df04a
AW
1;;;; texinfo.test -*- scheme -*-
2;;;;
be52f329 3;;;; Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc.
de9df04a
AW
4;;;; Copyright (C) 2001,2002 Oleg Kiselyov <oleg at pobox dot com>
5;;;;
6;;;; This library is free software; you can redistribute it and/or
7;;;; modify it under the terms of the GNU Lesser General Public
8;;;; License as published by the Free Software Foundation; either
9;;;; version 3 of the License, or (at your option) any later version.
10;;;;
11;;;; This library is distributed in the hope that it will be useful,
12;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14;;;; Lesser General Public License for more details.
15;;;;
16;;;; You should have received a copy of the GNU Lesser General Public
17;;;; License along with this library; if not, write to the Free Software
18;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
500f6a47
AW
19
20;;; Commentary:
21;;
22;; Unit tests for (sxml texinfo). Adapted from xml.ssax.scm.
23;;
24;;; Code:
25
26(define-module (test-suite texinfo)
27 #:use-module (test-suite lib)
28 #:use-module (texinfo))
29
30(define exception:eof-while-reading-token
31 '(parser-error . "^EOF while reading a token"))
32(define exception:wrong-character
33 '(parser-error . "^Wrong character"))
34(define exception:eof-while-reading-char-data
35 '(parser-error . "^EOF while reading char data"))
36(define exception:no-settitle
37 '(parser-error . "^No \\\\n@settitle found"))
38(define exception:unexpected-arg
39 '(parser-error . "^@-command didn't expect more arguments"))
40(define exception:bad-enumerate
41 '(parser-error . "^Invalid"))
42
43(define nl (string #\newline))
44
45(define texinfo:read-verbatim-body
46 (@@ (texinfo) read-verbatim-body))
47(with-test-prefix "test-read-verbatim-body"
48 (define (read-verbatim-body-from-string str)
49 (define (consumer fragment foll-fragment seed)
50 (cons* (if (equal? foll-fragment (string #\newline))
51 (string-append " NL" nl)
52 foll-fragment)
53 fragment seed))
54 (reverse
55 (call-with-input-string
56 str
57 (lambda (port) (texinfo:read-verbatim-body port consumer '())))))
58
59 (pass-if (equal? '()
60 (read-verbatim-body-from-string "@end verbatim\n")))
61
62 ;; after @verbatim, the current position will always directly after
63 ;; the newline.
64 (pass-if-exception "@end verbatim needs a newline"
65 exception:eof-while-reading-token
66 (read-verbatim-body-from-string "@end verbatim"))
67
68 (pass-if (equal? '("@@end verbatim" " NL\n")
69 (read-verbatim-body-from-string "@@end verbatim\n@end verbatim\n")))
70
71 (pass-if (equal? '("@@@@faosfasf adsfas " " NL\n" " asf @foo{asdf}" " NL\n")
72 (read-verbatim-body-from-string
73 "@@@@faosfasf adsfas \n asf @foo{asdf}\n@end verbatim\n")))
74
75 (pass-if (equal? '("@end verbatim " " NL\n")
76 (read-verbatim-body-from-string "@end verbatim \n@end verbatim\n"))))
77
78(define texinfo:read-arguments
79 (@@ (texinfo) read-arguments))
80(with-test-prefix "test-read-arguments"
81 (define (read-arguments-from-string str)
82 (call-with-input-string
83 str
84 (lambda (port) (texinfo:read-arguments port #\}))))
85
86 (define (test str expected-res)
87 (pass-if (equal? expected-res
88 (read-arguments-from-string str))))
89
90 (test "}" '())
91 (test "foo}" '("foo"))
92 (test "foo,bar}" '("foo" "bar"))
93 (test " foo , bar }" '("foo" "bar"))
94 (test " foo , , bar }" '("foo" #f "bar"))
95 (test "foo,,bar}" '("foo" #f "bar"))
96 (pass-if-exception "need a } when reading arguments"
97 exception:eof-while-reading-token
98 (call-with-input-string
99 "foo,,bar"
100 (lambda (port) (texinfo:read-arguments port #\})))))
101
102(define texinfo:complete-start-command
103 (@@ (texinfo) complete-start-command))
104(with-test-prefix "test-complete-start-command"
105 (define (test command str)
106 (call-with-input-string
107 str
108 (lambda (port)
109 (call-with-values
110 (lambda ()
111 (texinfo:complete-start-command command port))
112 list))))
113
114 (pass-if (equal? '(section () EOL-TEXT)
115 (test 'section "foo bar baz bonzerts")))
116 (pass-if (equal? '(deffnx ((category "Function") (name "foo") (arguments)) EOL-TEXT-ARGS)
117 (test 'deffnx "Function foo")))
118 (pass-if-exception "@emph missing a start brace"
119 exception:wrong-character
120 (test 'emph "no brace here"))
121 (pass-if (equal? '(emph () INLINE-TEXT)
122 (test 'emph "{foo bar baz bonzerts")))
123 (pass-if (equal? '(ref ((node "foo bar") (section "baz") (info-file "bonzerts"))
124 INLINE-ARGS)
125 (test 'ref "{ foo bar ,, baz, bonzerts}")))
126 (pass-if (equal? '(node ((name "referenced node")) EOL-ARGS)
127 (test 'node " referenced node\n"))))
128
129(define texinfo:read-char-data
130 (@@ (texinfo) read-char-data))
131(define make-texinfo-token cons)
132(with-test-prefix "test-read-char-data"
133 (let* ((code (make-texinfo-token 'START 'code))
134 (ref (make-texinfo-token 'EMPTY 'ref))
135 (title (make-texinfo-token 'LINE 'title))
136 (node (make-texinfo-token 'EMPTY 'node))
137 (eof-object (with-input-from-string "" read))
138 (str-handler (lambda (fragment foll-fragment seed)
139 (if (string-null? foll-fragment)
140 (cons fragment seed)
141 (cons* foll-fragment fragment seed)))))
142 (define (test str expect-eof? preserve-ws? expected-data expected-token)
143 (call-with-values
144 (lambda ()
145 (call-with-input-string
146 str
147 (lambda (port)
148 (texinfo:read-char-data
149 port expect-eof? preserve-ws? str-handler '()))))
150 (lambda (seed token)
151 (let ((result (reverse seed)))
152 (pass-if (equal? expected-data result))
153 (pass-if (equal? expected-token token))))))
154
155 ;; add some newline-related tests here
156 (test "" #t #f '() eof-object)
157 (test "foo bar baz" #t #f '("foo bar baz") eof-object)
158 (pass-if-exception "eof reading char data"
159 exception:eof-while-reading-token
160 (test "" #f #f '() eof-object))
161 (test " " #t #f '(" ") eof-object)
162 (test " @code{foo} " #f #f '(" ") code)
163 (test " @code" #f #f '(" ") code)
164 (test " {text here} asda" #f #f '(" ") (make-texinfo-token 'START '*braces*))
165 (test " blah blah} asda" #f #f '(" blah blah") (make-texinfo-token 'END #f))))
166
167
168(with-test-prefix "test-texinfo->stexinfo"
169 (define (test str expected-res)
170 (pass-if (equal? expected-res
171 (call-with-input-string str texi->stexi))))
172 (define (try-with-title title str)
173 (call-with-input-string
174 (string-append "foo bar baz\n@settitle " title "\n" str)
175 texi->stexi))
176 (define (test-with-title title str expected-res)
177 (test (string-append "foo bar baz\n@settitle " title "\n" str)
178 expected-res))
179 (define (test-body str expected-res)
be52f329
AW
180 (pass-if str
181 (equal? expected-res
182 (cddr (try-with-title "zog" str)))))
500f6a47
AW
183
184 (define (list-intersperse src-l elem)
185 (if (null? src-l) src-l
186 (let loop ((l (cdr src-l)) (dest (cons (car src-l) '())))
187 (if (null? l) (reverse dest)
188 (loop (cdr l) (cons (car l) (cons elem dest)))))))
189 (define (join-lines . lines)
190 (apply string-append (list-intersperse lines "\n")))
191
192 (pass-if-exception "missing @settitle"
193 exception:no-settitle
194 (call-with-input-string "@dots{}\n" texi->stexi))
195
196 (test "\\input texinfo\n@settitle my title\n@dots{}\n"
197 '(texinfo (% (title "my title")) (para (dots))))
198 (test-with-title "my title" "@dots{}\n"
199 '(texinfo (% (title "my title")) (para (dots))))
200 (test-with-title "my title" "@dots{}"
201 '(texinfo (% (title "my title")) (para (dots))))
202
203 (pass-if-exception "arg to @dots{}"
204 exception:unexpected-arg
205 (call-with-input-string
206 "foo bar baz\n@settitle my title\n@dots{arg}"
207 texi->stexi))
208
209 (test-body "@code{arg}"
210 '((para (code "arg"))))
31d59769 211 (test-body "@url{arg}"
fd99e505 212 '((para (uref (% (url "arg"))))))
500f6a47
AW
213 (test-body "@code{ }"
214 '((para (code))))
215 (test-body "@code{ @code{} }"
216 '((para (code (code)))))
217 (test-body "@code{ abc @code{} }"
218 '((para (code "abc " (code)))))
219 (test-body "@code{ arg }"
220 '((para (code "arg"))))
be52f329
AW
221
222 (test-body "@acronym{GNU}"
223 '((para (acronym (% (acronym "GNU"))))))
224
225 (test-body "@acronym{GNU, not unix}"
226 '((para (acronym (% (acronym "GNU")
227 (meaning "not unix"))))))
228
229 (test-body "@acronym{GNU, @acronym{GNU}'s Not Unix}"
230 '((para (acronym (% (acronym "GNU")
231 (meaning (acronym (% (acronym "GNU")))
232 "'s Not Unix"))))))
233
500f6a47
AW
234 (test-body "@example\n foo asdf asd sadf asd \n@end example\n"
235 '((example " foo asdf asd sadf asd ")))
236 (test-body (join-lines
237 "@quotation"
238 "@example"
239 " foo asdf asd sadf asd "
240 "@end example"
241 "@end quotation"
242 "")
243 '((quotation (example " foo asdf asd sadf asd "))))
244 (test-body (join-lines
245 "@quotation"
246 "@example"
247 " foo asdf @var{asd} sadf asd "
248 "@end example"
249 "@end quotation"
250 "")
251 '((quotation (example " foo asdf " (var "asd") " sadf asd "))))
252 (test-body (join-lines
253 "@quotation"
254 "@example"
255 " foo asdf @var{asd} sadf asd "
256 ""
257 "not in new para, this is an example"
258 "@end example"
259 "@end quotation"
260 "")
261 '((quotation
262 (example
263 " foo asdf " (var "asd")
264 " sadf asd \n\nnot in new para, this is an example"))))
265 (test-body (join-lines
266 "@titlepage"
267 "@quotation"
268 " foo asdf @var{asd} sadf asd "
269 ""
270 "should be in new para"
271 "@end quotation"
272 "@end titlepage"
273 "")
274 '((titlepage
275 (quotation (para "foo asdf " (var "asd") " sadf asd")
276 (para "should be in new para")))))
277 (test-body (join-lines
278 ""
279 "@titlepage"
280 ""
281 "@quotation"
282 " foo asdf @var{asd} sadf asd "
283 ""
284 "should be in new para"
285 ""
286 ""
287 "@end quotation"
288 "@end titlepage"
289 ""
290 "@bye"
291 ""
292 "@foo random crap at the end"
293 "")
294 '((titlepage
295 (quotation (para "foo asdf " (var "asd") " sadf asd")
296 (para "should be in new para")))))
297 (test-body (join-lines
298 ""
299 "random notes"
300 "@quotation"
301 " foo asdf @var{asd} sadf asd "
302 ""
303 "should be in new para"
304 ""
305 ""
306 "@end quotation"
307 ""
308 " hi mom"
309 "")
310 '((para "random notes")
311 (quotation (para "foo asdf " (var "asd") " sadf asd")
312 (para "should be in new para"))
313 (para "hi mom")))
314 (test-body (join-lines
315 "@enumerate"
316 "@item one"
317 "@item two"
318 "@item three"
319 "@end enumerate"
320 )
321 '((enumerate (item (para "one"))
322 (item (para "two"))
323 (item (para "three")))))
324 (test-body (join-lines
325 "@enumerate 44"
326 "@item one"
327 "@item two"
328 "@item three"
329 "@end enumerate"
330 )
331 '((enumerate (% (start "44"))
332 (item (para "one"))
333 (item (para "two"))
334 (item (para "three")))))
335 (pass-if-exception "bad enumerate formatter"
336 exception:bad-enumerate
337 (try-with-title "foo" (join-lines
338 "@enumerate string"
339 "@item one"
340 "@item two"
341 "@item three"
342 "@end enumerate"
343 )))
344 (pass-if-exception "bad itemize formatter"
345 exception:bad-enumerate
346 (try-with-title "foo" (join-lines
347 "@itemize string"
348 "@item one"
349 "@item two"
350 "@item three"
351 "@end itemize"
352 )))
353 (test-body (join-lines
354 "@itemize" ;; no formatter, should default to bullet
355 "@item one"
356 "@item two"
357 "@item three"
358 "@end itemize"
359 )
360 '((itemize (% (bullet (bullet)))
361 (item (para "one"))
362 (item (para "two"))
363 (item (para "three")))))
364 (test-body (join-lines
365 "@itemize @bullet"
366 "@item one"
367 "@item two"
368 "@item three"
369 "@end itemize"
370 )
371 '((itemize (% (bullet (bullet)))
372 (item (para "one"))
373 (item (para "two"))
374 (item (para "three")))))
375 (test-body (join-lines
376 "@itemize -"
377 "@item one"
378 "@item two"
379 "@item three"
380 "@end itemize"
381 )
382 '((itemize (% (bullet "-"))
383 (item (para "one"))
384 (item (para "two"))
385 (item (para "three")))))
386 (test-body (join-lines
387 "@table @code"
388 "preliminary text -- should go in a pre-item para"
389 "@item one"
390 "item one text"
391 "@item two"
392 "item two text"
393 ""
394 "includes a paragraph"
395 "@item three"
396 "@end itemize"
397 )
398 '((table (% (formatter (code)))
399 (para "preliminary text -- should go in a pre-item para")
400 (entry (% (heading "one"))
401 (para "item one text"))
402 (entry (% (heading "two"))
403 (para "item two text")
404 (para "includes a paragraph"))
405 (entry (% (heading "three"))))))
406 (test-body (join-lines
407 "@chapter @code{foo} bar"
408 "text that should be in a para"
409 )
410 '((chapter (code "foo") " bar")
411 (para "text that should be in a para")))
412 (test-body (join-lines
413 "@deffnx Method foo bar @code{baz}"
414 "text that should be in a para"
415 )
416 '((deffnx (% (category "Method")
417 (name "foo")
418 (arguments "bar " (code "baz"))))
419 (para "text that should be in a para")))
420 )