;;;; locale-test.scm ;TZ='America/Phoenix' csi -R locale -P '(current-locale-components)' ; Remove ALL envvars (use posix) (for-each unsetenv '("TZ" "LANG" "LC_ALL" "LC_COLLATE" "LC_CTYPE" "LC_MESSAGES" "LC_MONETARY" "LC_NUMERIC" "LC_ADDRESS" "LC_IDENTIFICATION" "LC_MEASUREMENT" "LC_NAME" "LC_PAPER" "LC_TELEPHONE" "LC_TIME" "LANGUAGE")) (use test) (use locale) ;Should test ;LC_ALL ;LC_COLLATE, etc. ;LANGUAGE (test-group "Locale" #; ;FIXME need to test locale-timezone (test-group "Local Timezone" (test "TZN (fail)" "" (local-timezone (seconds->local-time (current-seconds)))) (test "TZO (fail)" -1 (local-timezone-offset (seconds->local-time (current-seconds)))) #;(with-tzset "" (lambda () )) ) (test-group "Posix Timezone" ; unsupported but not an error (test-assert "T1a" (not (posix-timezone-string->timezone-components ":foo,bar,baz"))) ; (test-assert "T1b" (posix-timezone-string->timezone-components "+03-3:0:0XXXX-4:0:0")) ; 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")) ;; This screws up any further testing of TZ related info (setenv "TZ" "PST+8:00PDT+7:00:00,M4.1.0,M10.5") (posix-load-timezone) (let ((tzc (current-timezone-components))) (when (locale-component-exists? tzc 'dst?) (set-timezone-component! tz1 'dst? (locale-component-ref tzc 'dst?))) (test "TS4" tz1 tzc) ) ) ) (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" 'country "US" 'region "US")) (set! lc1 (update-locale-components! lc1 'language "en" 'script "Latn" 'country "US" '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-assert "LS1" (locale-components=? lc0 (posix-locale-string->locale-components "en_US" '("POSIX" "LANG")))) (test-assert "LS2" (locale-components=? lc1 (posix-locale-string->locale-components "en-Latn_US.UTF8@foo,bar,baz" "TEST"))) (setenv "LANG" "en_US") (posix-load-locale) (test-assert "LS3" (locale-components=? lc0 (current-locale-components))) (test-assert "LS4" (locale-components=? lc0 (locale-category-ref 'monetary))) ) ) ) (test-exit)