;;;; locale-test.scm (use test) (use locale posix) (test-group "Locale" (test-group "Posix Timezone" ; unsupported but not an error (test-assert "T1" (not (posix-timezone-string->timezone-components ":foo,bar,baz"))) ; cannot have a name composed of digits (test-error "T2" (posix-timezone-string->timezone-components "23,foo")) ; this is actually legal! (test-assert "T3" (posix-timezone-string->timezone-components "foo/23")) ; this is actually legal! (test-assert "T4" (posix-timezone-string->timezone-components "foo-23bar/23")) ; the dst section is bad (test-error "T5" (posix-timezone-string->timezone-components "foo-23bar-22/23")) (let ((tz0 (make-timezone-components "PST+8:00" "TEST")) (tz1 (make-timezone-components "PST+8:00PDT+7:00:00,M4.1.0,M10.5" '("POSIX" "TZ"))) (tz2 (make-timezone-components "PST+8:00PDT7,J23/12:34,34/1:00:01" "TEST")) ) (set! tz0 (update-timezone-components! tz0 'std-name "PST" 'std-offset (* 8 60 60))) (test "TS1" tz0 (posix-timezone-string->timezone-components "PST+8:00" "TEST")) (set! tz1 (update-timezone-components! tz1 'std-name "PST" 'std-offset (* 8 60 60) 'dst-name "PDT" 'dst-offset (* 7 60 60) 'dst-start (make-timezone-dst-rule-mwd 4 1 0 (* 2 60 60)) 'dst-end (make-timezone-dst-rule-mwd 10 5 0 (* 2 60 60)))) (test "TS2" tz1 (posix-timezone-string->timezone-components "PST+8:00PDT+7:00:00,M4.1.0,M10.5" '("POSIX" "TZ"))) (set! tz2 (update-timezone-components! tz2 'std-name "PST" 'std-offset (* 8 60 60) 'dst-name "PDT" 'dst-offset (* 7 60 60) 'dst-start (make-timezone-dst-rule-julian-noleap 23 (+ (* 12 60 60) (* 34 60))) 'dst-end (make-timezone-dst-rule-julian-leap 34 (+ (* 1 60 60) 1)))) (test "TS3" tz2 (posix-timezone-string->timezone-components "PST+8:00PDT7,J23/12:34,34/1:00:01" "TEST")) (setenv "TZ" "PST+8:00PDT+7:00:00,M4.1.0,M10.5") (posix-load-timezone) (test "TS4" tz1 (current-timezone-components)) ) ) (test-group "Posix Locale" (let ((lc0 (make-locale-components "en_US" '("POSIX" "LANG"))) (lc1 (make-locale-components "en-Latn_US.UTF8@foo,bar,baz" "TEST")) ) (set! lc0 (update-locale-components! lc0 'language "en" 'region "US")) (set! lc1 (update-locale-components! lc1 'language "en" 'script "Latn" 'region "US" 'codeset "UTF8" 'modifier "foo,bar,baz")) (test-assert "L1" (not (posix-locale-string->locale-components "/foo,bar,baz" "TEST"))) (test-assert "L2" (not (posix-locale-string->locale-components "23,bar,baz" "TEST"))) (test-assert "L3" (not (posix-locale-string->locale-components "foo-bar_1" "TEST"))) (test "LS1" lc0 (posix-locale-string->locale-components "en_US" '("POSIX" "LANG"))) (test "LS2" lc1 (posix-locale-string->locale-components "en-Latn_US.UTF8@foo,bar,baz" "TEST")) (setenv "LANG" "en_US") (posix-load-locale) (test "LS3" lc0 (current-locale-components)) (test "LS4" lc0 (locale-category-ref 'monetary)) ) ) #; (test-group "Local Timezone" (with-tzset "" (lambda () )) ) )