; time-stamp: Rename some internal symbols
* lisp/time-stamp.el: (time-stamp-string-preprocess): Rename 'alt-form' to 'colon-cnt' because it is now an integer. * test/lisp/time-stamp-tests.el: Rename 'formatz-generate-tests' to 'define-formatz-tests'.
This commit is contained in:
parent
77fe4fbeff
commit
a00e6e7143
2 changed files with 80 additions and 80 deletions
|
@ -532,7 +532,7 @@ and all `time-stamp-format' compatibility."
|
|||
(let ((prev-char nil)
|
||||
(field-width "")
|
||||
field-result
|
||||
(alt-form 0)
|
||||
(colon-cnt 0)
|
||||
(change-case nil)
|
||||
(title-case nil)
|
||||
(upcase nil)
|
||||
|
@ -579,7 +579,7 @@ and all `time-stamp-format' compatibility."
|
|||
(setq prev-char cur-char)
|
||||
;; some characters we actually use
|
||||
(cond ((eq cur-char ?:)
|
||||
(setq alt-form (1+ alt-form)))
|
||||
(setq colon-cnt (1+ colon-cnt)))
|
||||
((eq cur-char ?#)
|
||||
(setq change-case t))
|
||||
((eq cur-char ?^)
|
||||
|
@ -601,67 +601,67 @@ and all `time-stamp-format' compatibility."
|
|||
((eq cur-char ?a) ;day of week
|
||||
(time-stamp-do-letter-case
|
||||
nil upcase title-case change-case
|
||||
(if (> alt-form 0)
|
||||
(if (> colon-cnt 0)
|
||||
(if (string-equal field-width "")
|
||||
(time-stamp--format "%A" time)
|
||||
"") ;discourage "%:3a"
|
||||
(time-stamp--format "%a" time))))
|
||||
((eq cur-char ?A)
|
||||
(if (and (>= (string-to-number field-width) 1)
|
||||
(<= (string-to-number field-width) 3)
|
||||
(not flag-minimize)
|
||||
(not flag-pad-with-spaces))
|
||||
(progn
|
||||
(time-stamp-conv-warn "%3A" "%#a")
|
||||
(time-stamp--format "%#a" time))
|
||||
(if (or (> alt-form 0)
|
||||
change-case upcase title-case
|
||||
flag-minimize flag-pad-with-spaces
|
||||
(string-equal field-width ""))
|
||||
(time-stamp-do-letter-case
|
||||
nil upcase title-case change-case
|
||||
(time-stamp--format "%A" time))
|
||||
(time-stamp-conv-warn (format "%%%sA" field-width)
|
||||
(cond
|
||||
((and (>= (string-to-number field-width) 1)
|
||||
(<= (string-to-number field-width) 3)
|
||||
(not flag-minimize)
|
||||
(not flag-pad-with-spaces))
|
||||
(time-stamp-conv-warn "%3A" "%#a")
|
||||
(time-stamp--format "%#a" time))
|
||||
((or (> colon-cnt 0)
|
||||
change-case upcase title-case
|
||||
flag-minimize flag-pad-with-spaces
|
||||
(string-equal field-width ""))
|
||||
(time-stamp-do-letter-case
|
||||
nil upcase title-case change-case
|
||||
(time-stamp--format "%A" time)))
|
||||
(t (time-stamp-conv-warn (format "%%%sA" field-width)
|
||||
(format "%%#%sA" field-width)
|
||||
(format "%%:%sA" field-width))
|
||||
(time-stamp--format "%#A" time))))
|
||||
((eq cur-char ?b) ;month name
|
||||
(time-stamp-do-letter-case
|
||||
nil upcase title-case change-case
|
||||
(if (> alt-form 0)
|
||||
(if (> colon-cnt 0)
|
||||
(if (string-equal field-width "")
|
||||
(time-stamp--format "%B" time)
|
||||
"") ;discourage "%:3b"
|
||||
(time-stamp--format "%b" time))))
|
||||
((eq cur-char ?B)
|
||||
(if (and (>= (string-to-number field-width) 1)
|
||||
(<= (string-to-number field-width) 3)
|
||||
(not flag-minimize)
|
||||
(not flag-pad-with-spaces))
|
||||
(progn
|
||||
(time-stamp-conv-warn "%3B" "%#b")
|
||||
(time-stamp--format "%#b" time))
|
||||
(if (or (> alt-form 0)
|
||||
change-case upcase title-case
|
||||
flag-minimize flag-pad-with-spaces
|
||||
(string-equal field-width ""))
|
||||
(time-stamp-do-letter-case
|
||||
nil upcase title-case change-case
|
||||
(time-stamp--format "%B" time))
|
||||
(time-stamp-conv-warn (format "%%%sB" field-width)
|
||||
(cond
|
||||
((and (>= (string-to-number field-width) 1)
|
||||
(<= (string-to-number field-width) 3)
|
||||
(not flag-minimize)
|
||||
(not flag-pad-with-spaces))
|
||||
(time-stamp-conv-warn "%3B" "%#b")
|
||||
(time-stamp--format "%#b" time))
|
||||
((or (> colon-cnt 0)
|
||||
change-case upcase title-case
|
||||
flag-minimize flag-pad-with-spaces
|
||||
(string-equal field-width ""))
|
||||
(time-stamp-do-letter-case
|
||||
nil upcase title-case change-case
|
||||
(time-stamp--format "%B" time)))
|
||||
(t (time-stamp-conv-warn (format "%%%sB" field-width)
|
||||
(format "%%#%sB" field-width)
|
||||
(format "%%:%sB" field-width))
|
||||
(time-stamp--format "%#B" time))))
|
||||
((eq cur-char ?d) ;day of month, 1-31
|
||||
(time-stamp-do-number cur-char alt-form field-width time))
|
||||
(time-stamp-do-number cur-char colon-cnt field-width time))
|
||||
((eq cur-char ?H) ;hour, 0-23
|
||||
(time-stamp-do-number cur-char alt-form field-width time))
|
||||
(time-stamp-do-number cur-char colon-cnt field-width time))
|
||||
((eq cur-char ?I) ;hour, 1-12
|
||||
(time-stamp-do-number cur-char alt-form field-width time))
|
||||
(time-stamp-do-number cur-char colon-cnt field-width time))
|
||||
((eq cur-char ?m) ;month number, 1-12
|
||||
(time-stamp-do-number cur-char alt-form field-width time))
|
||||
(time-stamp-do-number cur-char colon-cnt field-width time))
|
||||
((eq cur-char ?M) ;minute, 0-59
|
||||
(time-stamp-do-number cur-char alt-form field-width time))
|
||||
(time-stamp-do-number cur-char colon-cnt field-width time))
|
||||
((eq cur-char ?p) ;AM or PM
|
||||
(time-stamp-do-letter-case
|
||||
t upcase title-case change-case
|
||||
|
@ -673,11 +673,11 @@ and all `time-stamp-format' compatibility."
|
|||
t upcase title-case change-case
|
||||
(time-stamp--format "%p" time))))
|
||||
((eq cur-char ?S) ;seconds, 00-60
|
||||
(time-stamp-do-number cur-char alt-form field-width time))
|
||||
(time-stamp-do-number cur-char colon-cnt field-width time))
|
||||
((eq cur-char ?w) ;weekday number, Sunday is 0
|
||||
(time-stamp--format "%w" time))
|
||||
((eq cur-char ?y) ;year
|
||||
(if (= alt-form 0)
|
||||
(if (= colon-cnt 0)
|
||||
(if (or (string-equal field-width "")
|
||||
(<= (string-to-number field-width) 2))
|
||||
(string-to-number (time-stamp--format "%y" time))
|
||||
|
@ -706,7 +706,7 @@ and all `time-stamp-format' compatibility."
|
|||
(setq field-width "")
|
||||
(cond (change-case
|
||||
"") ;discourage %z variations
|
||||
((and (= alt-form 0)
|
||||
((and (= colon-cnt 0)
|
||||
(not flag-minimize)
|
||||
(not flag-pad-with-spaces)
|
||||
(not flag-pad-with-zeros)
|
||||
|
@ -717,7 +717,7 @@ and all `time-stamp-format' compatibility."
|
|||
flag-minimize
|
||||
flag-pad-with-spaces
|
||||
flag-pad-with-zeros
|
||||
alt-form
|
||||
colon-cnt
|
||||
field-width-num
|
||||
offset-secs)))))
|
||||
((eq cur-char ?Z) ;time zone name
|
||||
|
@ -757,7 +757,7 @@ and all `time-stamp-format' compatibility."
|
|||
(system-name))
|
||||
))
|
||||
(and (numberp field-result)
|
||||
(= alt-form 0)
|
||||
(= colon-cnt 0)
|
||||
(or (string-equal field-width "")
|
||||
(string-equal field-width "0"))
|
||||
;; no width provided; set width for default
|
||||
|
@ -793,13 +793,13 @@ This is an internal helper for `time-stamp-string-preprocess'."
|
|||
(t
|
||||
text)))
|
||||
|
||||
(defun time-stamp-do-number (format-char alt-form field-width time)
|
||||
(defun time-stamp-do-number (format-char colon-count field-width time)
|
||||
"Handle compatible FORMAT-CHAR where only default width/padding will change.
|
||||
ALT-FORM is non-0 if \":\" was specified. FIELD-WIDTH is the string
|
||||
COLON-COUNT is non-0 if \":\" was specified. FIELD-WIDTH is the string
|
||||
width specification or \"\". TIME is the time to convert.
|
||||
This is an internal helper for `time-stamp-string-preprocess'."
|
||||
(let ((format-string (concat "%" (char-to-string format-char))))
|
||||
(if (and (> alt-form 0) (not (string-equal field-width "")))
|
||||
(if (and (> colon-count 0) (not (string-equal field-width "")))
|
||||
"" ;discourage "%:2d" and the like
|
||||
(string-to-number (time-stamp--format format-string time)))))
|
||||
|
||||
|
|
|
@ -69,8 +69,8 @@
|
|||
(lambda (_old _new &optional _newer)
|
||||
(setq warning-count (1+ warning-count)))))
|
||||
(should ,form)
|
||||
(if (not (= warning-count 1))
|
||||
(ert-fail (format "Should have warned about format: %S" ',form))))))
|
||||
(unless (= warning-count 1)
|
||||
(ert-fail (format "Should have warned about format: %S" ',form))))))
|
||||
|
||||
;;; Tests:
|
||||
|
||||
|
@ -104,16 +104,16 @@
|
|||
(nth cur-index part-list)
|
||||
(nth 0 part-list))))))
|
||||
;; Don't repeat the default pattern.
|
||||
(if (or (= cur 0) (> cur-index 0))
|
||||
;; The whole format must start with %, so not all
|
||||
;; generated combinations are valid
|
||||
(if (or (not (equal (extract-part 2) ""))
|
||||
(when (or (= cur 0) (> cur-index 0))
|
||||
;; The whole format must start with %, so not all
|
||||
;; generated combinations are valid
|
||||
(when (or (not (equal (extract-part 2) ""))
|
||||
(equal (extract-part 3) ""))
|
||||
(iter-yield (list (extract-part 0)
|
||||
(extract-part 1)
|
||||
(apply #'concat
|
||||
(mapcar #'extract-part '(2 3 4)))
|
||||
(extract-part 5))))))))))
|
||||
(iter-yield (list (extract-part 0)
|
||||
(extract-part 1)
|
||||
(apply #'concat
|
||||
(mapcar #'extract-part '(2 3 4)))
|
||||
(extract-part 5))))))))))
|
||||
|
||||
(iter-defun time-stamp-test-pattern-multiply ()
|
||||
"Iterate through every combination of parts of `time-stamp-pattern'."
|
||||
|
@ -130,9 +130,9 @@
|
|||
;; so not all generated combinations are valid.
|
||||
;; (This is why the format can be supplied as "%%" to
|
||||
;; preserve the default format.)
|
||||
(if (or (not (equal format ""))
|
||||
(equal end ""))
|
||||
(iter-yield (list line-limit start format end)))))))))
|
||||
(when (or (not (equal format ""))
|
||||
(equal end ""))
|
||||
(iter-yield (list line-limit start format end)))))))))
|
||||
|
||||
(iter-defun time-stamp-test-pattern-all ()
|
||||
(iter-yield-from (time-stamp-test-pattern-sequential))
|
||||
|
@ -1035,7 +1035,7 @@ The functions in `pattern-mod' are composed left to right."
|
|||
|
||||
;; Convenience macro for generating groups of test cases.
|
||||
|
||||
(defmacro formatz-generate-tests
|
||||
(defmacro define-formatz-tests
|
||||
(form-strings hour-mod mins-mod secs-mod big-mod secbig-mod)
|
||||
"Define tests for time formats FORM-STRINGS.
|
||||
FORM-STRINGS is a list of formats, each \"%z\" or some variation thereof.
|
||||
|
@ -1065,10 +1065,10 @@ the other expected results for hours greater than 99 with non-zero seconds."
|
|||
;; Generate a form to create a list of tests to define. When this
|
||||
;; macro is called, the form is evaluated, thus defining the tests.
|
||||
;; We will modify this list, so start with a list consed at runtime.
|
||||
(let ((ert-test-list (list 'list))
|
||||
(let ((ert-test-list (list 'progn))
|
||||
(common-description
|
||||
(concat "\nThis test expands from a call to"
|
||||
" the macro `formatz-generate-tests'.\n"
|
||||
" the macro `define-formatz-tests'.\n"
|
||||
"To find the specific call, search the source file for \"")))
|
||||
(dolist (form-string form-strings ert-test-list)
|
||||
(nconc
|
||||
|
@ -1108,7 +1108,7 @@ the other expected results for hours greater than 99 with non-zero seconds."
|
|||
;;; Test %z formats without colons.
|
||||
|
||||
;; Option character "-" (minus) minimizes; it removes "00" minutes.
|
||||
(formatz-generate-tests ("%-z" "%-3z")
|
||||
(define-formatz-tests ("%-z" "%-3z")
|
||||
("+00")
|
||||
("+0030" formatz-mod-del-colons)
|
||||
("+000030" formatz-mod-del-colons)
|
||||
|
@ -1116,7 +1116,7 @@ the other expected results for hours greater than 99 with non-zero seconds."
|
|||
("+100:00:30"))
|
||||
|
||||
;; Minus with padding pads with spaces.
|
||||
(formatz-generate-tests ("%-12z")
|
||||
(define-formatz-tests ("%-12z")
|
||||
("+00 " formatz-mod-pad-r12)
|
||||
("+0030 " formatz-mod-del-colons formatz-mod-pad-r12)
|
||||
("+000030 " formatz-mod-del-colons formatz-mod-pad-r12)
|
||||
|
@ -1124,7 +1124,7 @@ the other expected results for hours greater than 99 with non-zero seconds."
|
|||
("+100:00:30 " formatz-mod-pad-r12))
|
||||
|
||||
;; 0 after other digits becomes padding of ten, not zero flag.
|
||||
(formatz-generate-tests ("%-10z")
|
||||
(define-formatz-tests ("%-10z")
|
||||
("+00 " formatz-mod-pad-r10)
|
||||
("+0030 " formatz-mod-del-colons formatz-mod-pad-r10)
|
||||
("+000030 " formatz-mod-del-colons formatz-mod-pad-r10)
|
||||
|
@ -1146,7 +1146,7 @@ the other expected results for hours greater than 99 with non-zero seconds."
|
|||
|
||||
;; Basic %z outputs 4 digits.
|
||||
;; Small padding values do not extend the result.
|
||||
(formatz-generate-tests (;; We don't check %z here because time-stamp
|
||||
(define-formatz-tests (;; We don't check %z here because time-stamp
|
||||
;; has a legacy behavior for it.
|
||||
;;"%z"
|
||||
"%5z" "%0z" "%05z")
|
||||
|
@ -1157,7 +1157,7 @@ the other expected results for hours greater than 99 with non-zero seconds."
|
|||
("+100:00:30"))
|
||||
|
||||
;; Padding adds spaces.
|
||||
(formatz-generate-tests ("%12z")
|
||||
(define-formatz-tests ("%12z")
|
||||
("+0000 " formatz-mod-add-00 formatz-mod-pad-r12)
|
||||
("+0030 " formatz-mod-del-colons formatz-mod-pad-r12)
|
||||
("+000030 " formatz-mod-del-colons formatz-mod-pad-r12)
|
||||
|
@ -1165,7 +1165,7 @@ the other expected results for hours greater than 99 with non-zero seconds."
|
|||
("+100:00:30 " formatz-mod-pad-r12))
|
||||
|
||||
;; Requiring 0-padding to 6 adds seconds (only) as needed.
|
||||
(formatz-generate-tests ("%06z")
|
||||
(define-formatz-tests ("%06z")
|
||||
("+000000" formatz-mod-add-00 formatz-mod-add-00)
|
||||
("+003000" formatz-mod-del-colons formatz-mod-add-00)
|
||||
("+000030" formatz-mod-del-colons)
|
||||
|
@ -1173,7 +1173,7 @@ the other expected results for hours greater than 99 with non-zero seconds."
|
|||
("+100:00:30"))
|
||||
|
||||
;; Option character "_" always adds seconds.
|
||||
(formatz-generate-tests ("%_z" "%_7z")
|
||||
(define-formatz-tests ("%_z" "%_7z")
|
||||
("+000000" formatz-mod-add-00 formatz-mod-add-00)
|
||||
("+003000" formatz-mod-del-colons formatz-mod-add-00)
|
||||
("+000030" formatz-mod-del-colons)
|
||||
|
@ -1181,7 +1181,7 @@ the other expected results for hours greater than 99 with non-zero seconds."
|
|||
("+100:00:30"))
|
||||
|
||||
;; Enough 0-padding adds seconds, then adds spaces.
|
||||
(formatz-generate-tests ("%012z" "%_12z")
|
||||
(define-formatz-tests ("%012z" "%_12z")
|
||||
("+000000 " formatz-mod-add-00 formatz-mod-add-00 formatz-mod-pad-r12)
|
||||
("+003000 " formatz-mod-del-colons formatz-mod-add-00 formatz-mod-pad-r12)
|
||||
("+000030 " formatz-mod-del-colons formatz-mod-pad-r12)
|
||||
|
@ -1192,7 +1192,7 @@ the other expected results for hours greater than 99 with non-zero seconds."
|
|||
|
||||
;; Three colons can output hours only,
|
||||
;; like %-z, but uses colons with non-zero minutes and seconds.
|
||||
(formatz-generate-tests ("%:::z" "%0:::z"
|
||||
(define-formatz-tests ("%:::z" "%0:::z"
|
||||
"%3:::z" "%03:::z")
|
||||
("+00")
|
||||
("+00:30")
|
||||
|
@ -1201,7 +1201,7 @@ the other expected results for hours greater than 99 with non-zero seconds."
|
|||
("+100:00:30"))
|
||||
|
||||
;; Padding with three colons adds spaces.
|
||||
(formatz-generate-tests ("%12:::z")
|
||||
(define-formatz-tests ("%12:::z")
|
||||
("+00 " formatz-mod-pad-r12)
|
||||
("+00:30 " formatz-mod-pad-r12)
|
||||
("+00:00:30 " formatz-mod-pad-r12)
|
||||
|
@ -1209,7 +1209,7 @@ the other expected results for hours greater than 99 with non-zero seconds."
|
|||
("+100:00:30 " formatz-mod-pad-r12))
|
||||
|
||||
;; 0 after other digits becomes padding of ten, not zero flag.
|
||||
(formatz-generate-tests ("%10:::z")
|
||||
(define-formatz-tests ("%10:::z")
|
||||
("+00 " formatz-mod-pad-r10)
|
||||
("+00:30 " formatz-mod-pad-r10)
|
||||
("+00:00:30 " formatz-mod-pad-r10)
|
||||
|
@ -1217,7 +1217,7 @@ the other expected results for hours greater than 99 with non-zero seconds."
|
|||
("+100:00:30"))
|
||||
|
||||
;; One colon outputs minutes, like %z but with colon.
|
||||
(formatz-generate-tests ("%:z" "%6:z" "%0:z" "%06:z" "%06:::z")
|
||||
(define-formatz-tests ("%:z" "%6:z" "%0:z" "%06:z" "%06:::z")
|
||||
("+00:00" formatz-mod-add-colon00)
|
||||
("+00:30")
|
||||
("+00:00:30")
|
||||
|
@ -1225,7 +1225,7 @@ the other expected results for hours greater than 99 with non-zero seconds."
|
|||
("+100:00:30"))
|
||||
|
||||
;; Padding with one colon adds spaces.
|
||||
(formatz-generate-tests ("%12:z")
|
||||
(define-formatz-tests ("%12:z")
|
||||
("+00:00 " formatz-mod-add-colon00 formatz-mod-pad-r12)
|
||||
("+00:30 " formatz-mod-pad-r12)
|
||||
("+00:00:30 " formatz-mod-pad-r12)
|
||||
|
@ -1233,7 +1233,7 @@ the other expected results for hours greater than 99 with non-zero seconds."
|
|||
("+100:00:30 " formatz-mod-pad-r12))
|
||||
|
||||
;; Requiring 0-padding to 7 adds seconds (only) as needed.
|
||||
(formatz-generate-tests ("%07:z" "%07:::z")
|
||||
(define-formatz-tests ("%07:z" "%07:::z")
|
||||
("+00:00:00" formatz-mod-add-colon00 formatz-mod-add-colon00)
|
||||
("+00:30:00" formatz-mod-add-colon00)
|
||||
("+00:00:30")
|
||||
|
@ -1241,7 +1241,7 @@ the other expected results for hours greater than 99 with non-zero seconds."
|
|||
("+100:00:30"))
|
||||
|
||||
;; Two colons outputs HH:MM:SS, like %_z but with colons.
|
||||
(formatz-generate-tests ("%::z" "%9::z" "%0::z" "%09::z")
|
||||
(define-formatz-tests ("%::z" "%9::z" "%0::z" "%09::z")
|
||||
("+00:00:00" formatz-mod-add-colon00 formatz-mod-add-colon00)
|
||||
("+00:30:00" formatz-mod-add-colon00)
|
||||
("+00:00:30")
|
||||
|
@ -1249,7 +1249,7 @@ the other expected results for hours greater than 99 with non-zero seconds."
|
|||
("+100:00:30"))
|
||||
|
||||
;; Enough padding adds minutes and seconds, then adds spaces.
|
||||
(formatz-generate-tests ("%012:z" "%012::z" "%12::z" "%012:::z")
|
||||
(define-formatz-tests ("%012:z" "%012::z" "%12::z" "%012:::z")
|
||||
("+00:00:00 " formatz-mod-add-colon00 formatz-mod-add-colon00
|
||||
formatz-mod-pad-r12)
|
||||
("+00:30:00 " formatz-mod-add-colon00 formatz-mod-pad-r12)
|
||||
|
|
Loading…
Add table
Reference in a new issue