1 | ;;;; locale-test.scm |
---|
2 | |
---|
3 | (use test) |
---|
4 | (use locale posix) |
---|
5 | |
---|
6 | (test-group "Locale" |
---|
7 | |
---|
8 | (test-group "Posix Timezone" |
---|
9 | |
---|
10 | ; unsupported but not an error |
---|
11 | (test-assert "T1" (not (posix-timezone-string->timezone-components ":foo,bar,baz"))) |
---|
12 | |
---|
13 | ; cannot have a name composed of digits |
---|
14 | (test-error "T2" (posix-timezone-string->timezone-components "23,foo")) |
---|
15 | |
---|
16 | ; this is actually legal! |
---|
17 | (test-assert "T3" (posix-timezone-string->timezone-components "foo/23")) |
---|
18 | |
---|
19 | ; this is actually legal! |
---|
20 | (test-assert "T4" (posix-timezone-string->timezone-components "foo-23bar/23")) |
---|
21 | |
---|
22 | ; the dst section is bad |
---|
23 | (test-error "T5" (posix-timezone-string->timezone-components "foo-23bar-22/23")) |
---|
24 | |
---|
25 | (let ((tz0 (make-timezone-components "PST+8:00" "TEST")) |
---|
26 | (tz1 (make-timezone-components "PST+8:00PDT+7:00:00,M4.1.0,M10.5" '("POSIX" "TZ"))) |
---|
27 | (tz2 (make-timezone-components "PST+8:00PDT7,J23/12:34,34/1:00:01" "TEST")) ) |
---|
28 | |
---|
29 | (set! tz0 |
---|
30 | (update-timezone-components! tz0 |
---|
31 | 'std-name "PST" 'std-offset (* 8 60 60))) |
---|
32 | (test "TS1" tz0 |
---|
33 | (posix-timezone-string->timezone-components "PST+8:00" "TEST")) |
---|
34 | |
---|
35 | (set! tz1 |
---|
36 | (update-timezone-components! tz1 |
---|
37 | 'std-name "PST" 'std-offset (* 8 60 60) |
---|
38 | 'dst-name "PDT" 'dst-offset (* 7 60 60) |
---|
39 | 'dst-start (make-timezone-dst-rule-mwd 4 1 0 (* 2 60 60)) |
---|
40 | 'dst-end (make-timezone-dst-rule-mwd 10 5 0 (* 2 60 60)))) |
---|
41 | (test "TS2" tz1 |
---|
42 | (posix-timezone-string->timezone-components "PST+8:00PDT+7:00:00,M4.1.0,M10.5" '("POSIX" "TZ"))) |
---|
43 | |
---|
44 | (set! tz2 |
---|
45 | (update-timezone-components! tz2 |
---|
46 | 'std-name "PST" 'std-offset (* 8 60 60) |
---|
47 | 'dst-name "PDT" 'dst-offset (* 7 60 60) |
---|
48 | 'dst-start (make-timezone-dst-rule-julian-noleap 23 (+ (* 12 60 60) (* 34 60))) |
---|
49 | 'dst-end (make-timezone-dst-rule-julian-leap 34 (+ (* 1 60 60) 1)))) |
---|
50 | (test "TS3" tz2 |
---|
51 | (posix-timezone-string->timezone-components "PST+8:00PDT7,J23/12:34,34/1:00:01" "TEST")) |
---|
52 | |
---|
53 | (setenv "TZ" "PST+8:00PDT+7:00:00,M4.1.0,M10.5") |
---|
54 | (posix-load-timezone) |
---|
55 | (test "TS4" tz1 (current-timezone-components)) ) |
---|
56 | ) |
---|
57 | |
---|
58 | (test-group "Posix Locale" |
---|
59 | |
---|
60 | (let ((lc0 (make-locale-components "en_US" '("POSIX" "LANG"))) |
---|
61 | (lc1 (make-locale-components "en-Latn_US.UTF8@foo,bar,baz" "TEST")) ) |
---|
62 | |
---|
63 | (set! lc0 |
---|
64 | (update-locale-components! lc0 |
---|
65 | 'language "en" |
---|
66 | 'region "US")) |
---|
67 | (set! lc1 |
---|
68 | (update-locale-components! lc1 |
---|
69 | 'language "en" |
---|
70 | 'script "Latn" |
---|
71 | 'region "US" |
---|
72 | 'codeset "UTF8" |
---|
73 | 'modifier "foo,bar,baz")) |
---|
74 | |
---|
75 | (test-assert "L1" (not (posix-locale-string->locale-components "/foo,bar,baz" "TEST"))) |
---|
76 | (test-assert "L2" (not (posix-locale-string->locale-components "23,bar,baz" "TEST"))) |
---|
77 | (test-assert "L3" (not (posix-locale-string->locale-components "foo-bar_1" "TEST"))) |
---|
78 | |
---|
79 | (test "LS1" lc0 (posix-locale-string->locale-components "en_US" '("POSIX" "LANG"))) |
---|
80 | (test "LS2" lc1 (posix-locale-string->locale-components "en-Latn_US.UTF8@foo,bar,baz" "TEST")) |
---|
81 | |
---|
82 | (setenv "LANG" "en_US") |
---|
83 | (posix-load-locale) |
---|
84 | (test "LS3" lc0 (current-locale-components)) |
---|
85 | (test "LS4" lc0 (locale-category-ref 'monetary)) ) |
---|
86 | ) |
---|
87 | |
---|
88 | #; |
---|
89 | (test-group "Local Timezone" |
---|
90 | (with-tzset "" (lambda () )) |
---|
91 | ) |
---|
92 | ) |
---|