summaryrefslogtreecommitdiff
path: root/tests/test-config-utilities-format-build-time.el
blob: 70473e2d2b2723d8d537fac87f6f16dd00bbfccf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
;;; test-config-utilities-format-build-time.el --- Tests for cj/emacs-build--format-build-time -*- lexical-binding: t; -*-

;;; Commentary:
;; Tests for cj/emacs-build--format-build-time from config-utilities.el.
;;
;; Pure function that converts various time value representations to a
;; human-readable string. Branches on input type: nil, string, cons of
;; integers (Emacs time value), number (epoch seconds), and fallback.

;;; Code:

(require 'ert)

(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(require 'config-utilities)

;;; Normal Cases

(ert-deftest test-config-utilities-format-build-time-normal-nil-returns-unknown ()
  "Nil input should return \"unknown\"."
  (should (equal (cj/emacs-build--format-build-time nil) "unknown")))

(ert-deftest test-config-utilities-format-build-time-normal-string-returned-as-is ()
  "String input should be returned unchanged."
  (should (equal (cj/emacs-build--format-build-time "2026-01-15 10:30:00 CST")
                 "2026-01-15 10:30:00 CST")))

(ert-deftest test-config-utilities-format-build-time-normal-cons-formats-timestamp ()
  "Cons of integers (Emacs time value) should produce formatted date string."
  (let* ((time-val (encode-time 0 30 14 15 2 2026))
         (result (cj/emacs-build--format-build-time time-val)))
    (should (string-match-p "2026-02-15" result))
    (should (string-match-p "14:30:00" result))))

(ert-deftest test-config-utilities-format-build-time-normal-number-formats-timestamp ()
  "Numeric epoch seconds should produce formatted date string."
  (let* ((time-val (float-time (encode-time 0 30 14 15 2 2026)))
         (result (cj/emacs-build--format-build-time time-val)))
    (should (string-match-p "2026-02-15" result))
    (should (string-match-p "14:30:00" result))))

(ert-deftest test-config-utilities-format-build-time-normal-fallback-formats-with-format ()
  "Unrecognized types should be stringified via `format'."
  (should (equal (cj/emacs-build--format-build-time 'some-symbol) "some-symbol")))

;;; Boundary Cases

(ert-deftest test-config-utilities-format-build-time-boundary-empty-string ()
  "Empty string input should be returned as empty string."
  (should (equal (cj/emacs-build--format-build-time "") "")))

(ert-deftest test-config-utilities-format-build-time-boundary-zero-epoch ()
  "Zero epoch (Unix epoch start) should produce a valid formatted date string."
  (let ((result (cj/emacs-build--format-build-time 0)))
    (should (stringp result))
    (should (string-match-p "19[67][0-9]" result))))

(ert-deftest test-config-utilities-format-build-time-boundary-integer-epoch ()
  "Integer (not float) epoch should be handled by numberp branch."
  (let* ((time-val (truncate (float-time (encode-time 0 0 12 1 1 2025))))
         (result (cj/emacs-build--format-build-time time-val)))
    (should (string-match-p "2025-01-01" result))
    (should (string-match-p "12:00:00" result))))

(ert-deftest test-config-utilities-format-build-time-boundary-cons-not-integers ()
  "Cons where car is not integer should hit the fallback branch."
  (let ((result (cj/emacs-build--format-build-time '("not" "integers"))))
    (should (equal result "(not integers)"))))

(ert-deftest test-config-utilities-format-build-time-boundary-vector-fallback ()
  "Vector input should hit the fallback branch."
  (should (equal (cj/emacs-build--format-build-time [1 2 3]) "[1 2 3]")))

(ert-deftest test-config-utilities-format-build-time-boundary-cons-and-number-agree ()
  "Cons time value and its float-time equivalent should produce the same output."
  (let* ((cons-time (encode-time 0 30 14 15 2 2026))
         (num-time (float-time cons-time))
         (result-cons (cj/emacs-build--format-build-time cons-time))
         (result-num (cj/emacs-build--format-build-time num-time)))
    (should (equal result-cons result-num))))

(provide 'test-config-utilities-format-build-time)
;;; test-config-utilities-format-build-time.el ends here