Debian Codegraph @

ext/text/test-gettext.scm

raw
1 (use gauche.test)
2 (use gauche.charconv)
3
4 (test-start "text.gettext")
5
6 (add-load-path "../../test")
7 (define *test-locale-dirs* '("../../test/data/locale"))
8
9 ;; This hack is to avoid conversion errors due to supported encodings.
10 ;; If you compile Gauche with utf8, most encodings should be OK.
11 (define *available-locales*
12 (filter-map (^p (and (ces-conversion-supported? (car p) #f)
13 (cdr p)))
14 '(("ISO-8859-15" . "en")
15 ("eucJP" . "ja"))))
16
17 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18 ;; load test data. this defines *tests*
19
20 (let1 test-file #"data/gettext.data.~(gauche-character-encoding)"
21 (load test-file))
22
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24 ;; run the tests
25
26 (test-section "text.gettext")
27 (use text.gettext)
28 (test-module 'text.gettext)
29
30
31 (dolist [domain '("test" "motest")]
32 (test-section domain)
33
34 (bindtextdomain (list domain) *test-locale-dirs*)
35
36 (dolist [locale *available-locales*]
37 (let* ([gettext-dispatch (make-gettext domain locale)]
38 [get (gettext-dispatch 'getter)])
39 (for-each (^t (test* (format "get-~A: ~S" locale (car t))
40 (get-optional (cdr t) (car t))
41 (get (car t))))
42 (assoc-ref *tests* locale))))
43
44 ;; plural forms
45 (dolist [locale *available-locales*]
46 (let* ([gettext-dispatch (make-gettext domain locale)]
47 [nget (gettext-dispatch 'ngetter)])
48 (for-each
49 (^t (let ([msg (car t)] [msg2 (cadr t)])
50 (for-each
51 (^[t2] (test* (format "nget-~A: ~S (~D)" locale msg (car t2))
52 (cadr t2)
53 (format #f (nget msg msg2 (car t2)) (car t2))))
54 (cddr t))))
55 (assoc-ref *plural-tests* locale))))
56
57 ;; using the GNU gettext interface
58 (dolist [locale *available-locales*]
59 (textdomain domain locale)
60 (for-each (^t (test* (format "gettext-~A: ~S" locale (car t))
61 (get-optional (cdr t) (car t))
62 (gettext (car t)))
63 (test* (format "dcgettext-~A: ~S" locale (car t))
64 (get-optional (cdr t) (car t))
65 (dcgettext domain (car t) locale)))
66 (assoc-ref *tests* locale)))
67 )
68
69 (test-end)