-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtest.el
197 lines (143 loc) · 9.63 KB
/
test.el
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
;;; test.el --- Testing for blamer -*- lexical-binding:t -*-
(require 'blamer)
;;; Code:
(ert-deftest test-parse-regexp ()
"Test blame parser regexp."
(let* ((blame-msg-1 "44307898 (artawower 2021-10-16 14:06:06 +0300 241) commit-message")
(blame-msg-2 "b3a30c6ae (Andrey Tokarev 2020-12-16 16:28:09 +0800 4) $tooltip-border-radius: 2px;")
(blame-msg-3 "^3130q6ze (@s!~range$><name-+\/ 2020-12-16 16:28:09 +0800 4) $tooltip-border-radius: 2px;")
(blame-msg-4 "^3130q6ze (Tom Bombadil (he/him) 2020-12-16 16:28:09 +0800 4) $tooltip-border-radius: 2px;")
(blame-msg-5 "^3130q6ze (TomBombadil(he/him) 2020-12-16 16:28:09 +0800 4) $tooltip-border-radius: 2px;")
(blame-msg-6 "3b90f8b82 lib/project_web/live/installation_live/show.html.heex (TomBombadil(he/him) 2023-03-16 08:08:26 -0500 25) <div class=\"flex justify-between gap-4\">"))
(string-match blamer--regexp-info blame-msg-1)
(should (equal (match-string 1 blame-msg-1) "44307898"))
(should (equal (match-string 2 blame-msg-1) "artawower"))
(should (equal (match-string 3 blame-msg-1) "2021-10-16"))
(should (equal (match-string 4 blame-msg-1) "14:06:06"))
(string-match blamer--regexp-info blame-msg-2)
(should (equal (match-string 1 blame-msg-2) "b3a30c6ae"))
(should (equal (match-string 2 blame-msg-2) "Andrey Tokarev"))
(should (equal (match-string 3 blame-msg-2) "2020-12-16"))
(should (equal (match-string 4 blame-msg-2) "16:28:09"))
(string-match blamer--regexp-info blame-msg-3)
(should (equal (match-string 1 blame-msg-3) "^3130q6ze"))
(should (equal (match-string 2 blame-msg-3) "@s!~range$><name-+\/"))
(should (equal (match-string 3 blame-msg-3) "2020-12-16"))
(should (equal (match-string 4 blame-msg-3) "16:28:09"))
(string-match blamer--regexp-info blame-msg-4)
(should (equal (match-string 1 blame-msg-4) "^3130q6ze"))
(should (equal (match-string 2 blame-msg-4) "Tom Bombadil (he/him)"))
(should (equal (match-string 3 blame-msg-4) "2020-12-16"))
(should (equal (match-string 4 blame-msg-4) "16:28:09"))
(string-match blamer--regexp-info blame-msg-5)
(should (equal (match-string 1 blame-msg-5) "^3130q6ze"))
(should (equal (match-string 2 blame-msg-5) "TomBombadil(he/him)"))
(should (equal (match-string 3 blame-msg-5) "2020-12-16"))
(should (equal (match-string 4 blame-msg-5) "16:28:09"))
(string-match blamer--regexp-info blame-msg-6)
(should (equal (match-string 2 blame-msg-6) "TomBombadil(he/him)"))))
(ert-deftest test-parse-commit-message ()
"Test commit parser regexp."
(let ((commit-msg-1 "commit 3783fafc6e14cb3fc27fbede7bb039262437e192
Author: artawower <[email protected]>
Date: Thu Oct 14 21:59:43 2021 +0300
refactor, global mode, rerender after line changed
")
(commit-msg-2 "commit 3dec28d846da16b4f02958fe7173bf2f0f2bd0bf
Author: Deins S@s~1!] <[email protected]>
Date: Fri Feb 28 12:45:39 2020 +0400
Very bing commit. С несколькикми языками. and its so illogical cause its realy big.
But! What we can do with this enormous commit message? Nothing. 123955!!.~
"))
(string-match blamer--commit-message-regexp commit-msg-1)
(should (equal (match-string 1 commit-msg-1) "refactor, global mode, rerender after line changed\n\n"))
(string-match blamer--commit-message-regexp commit-msg-2)
(should (equal (match-string 1 commit-msg-2) "Very bing commit. С несколькикми языками. and its so illogical cause its realy big.
But! What we can do with this enormous commit message? Nothing. 123955!!.~\n\n"))
))
(ert-deftest test-parse-commit-message-from-windows-machine ()
"Test commit parser regexp for windows commit message."
(let ((commit-msg-1 "[email protected] commit b645fb973309696f51719b03f8a4f478a0e670f2
Author: ISouthRain <[email protected]>
Date: Sun Aug 4 12:35:21 2024 +0800
deadgrep: Add this package: 替代 rg(ripgrep) 包
"))
(string-match blamer--commit-message-regexp commit-msg-1)
(should (equal (match-string 1 commit-msg-1) "deadgrep: Add this package: 替代 rg(ripgrep) 包\n\n"))))
(ert-deftest test-parse-commit-message-with-cjk-characters ()
"Test commit parser regexp for windows commit message."
(let ((commit-msg-1 "[email protected] commit b645fb973309696f51719b03f8a4f478a0e670f2
Author: ISouthRain <[email protected]>
Date: Sun Aug 4 12:35:21 2024 +0800
magit: 添加自动分裂窗口功能
"))
(string-match blamer--commit-message-regexp commit-msg-1)
(should (equal (match-string 1 commit-msg-1) "magit: 添加自动分裂窗口功能\n\n"))))
(defun format-date-to-string (date)
"Format date to test string."
(format-time-string "%Y-%m-%d" date))
(defun format-time-to-string (time)
"Format time to test string."
(format-time-string "%H:%M:%S" time))
(ert-deftest test-pretty-time-format ()
"Test prettified time format."
(let* ((yesterday (time-subtract (current-time) (days-to-time 1)))
(formatted-date (format-date-to-string yesterday))
(formatted-time (format-time-to-string yesterday))
(12-minutes-ago (time-subtract (current-time) (seconds-to-time 760)))
(59-minutes-ago (time-subtract (current-time) (seconds-to-time 3540)))
(2-hours-ago (time-subtract (current-time) (seconds-to-time (* 60 60 2))))
(1-hour-ago (time-subtract (current-time) (seconds-to-time (* 60 60))))
(23-hours-ago (time-subtract (current-time) (seconds-to-time (* 60 60 23))))
(2-days-ago (time-subtract (current-time) (seconds-to-time (* 60 60 24 2))))
(week-ago (time-subtract (current-time) (seconds-to-time (* 60 60 24 7))))
(4-weeks-ago (time-subtract (current-time) (seconds-to-time (* 60 60 24 7 4))))
(month-ago (time-subtract (current-time) (seconds-to-time (* 60 60 24 35))))
(9-months-ago (time-subtract (current-time) (seconds-to-time (* 60 60 24 30 9))))
(year-ago (time-subtract (current-time) (seconds-to-time (* 60 60 24 366))))
(4-years-ago (time-subtract (current-time) (seconds-to-time (* 60 60 24 365 4))))
(11-years-ago (time-subtract (current-time) (seconds-to-time (* 60 60 24 365 11))))
(11-years-ago-prettified (concat
(format-date-to-string 11-years-ago)
" "
(blamer--truncate-time (format-time-to-string 11-years-ago)))))
(should (equal "Yesterday" (blamer--prettify-time formatted-date formatted-time)))
(should (equal "Now" (blamer--prettify-time (format-date-to-string (current-time))
(format-time-to-string (current-time)))))
(should (equal "12 minutes ago" (blamer--prettify-time (format-date-to-string 12-minutes-ago)
(format-time-to-string 12-minutes-ago))))
(should (equal "59 minutes ago" (blamer--prettify-time (format-date-to-string 59-minutes-ago)
(format-time-to-string 59-minutes-ago))))
(should (equal "2 hours ago" (blamer--prettify-time (format-date-to-string 2-hours-ago)
(format-time-to-string 2-hours-ago))))
(should (equal "Hour ago" (blamer--prettify-time (format-date-to-string 1-hour-ago)
(format-time-to-string 1-hour-ago))))
(should (equal "23 hours ago" (blamer--prettify-time (format-date-to-string 23-hours-ago)
(format-time-to-string 23-hours-ago))))
(should (equal "2 days ago" (blamer--prettify-time (format-date-to-string 2-days-ago)
(format-time-to-string 2-days-ago))))
(should (equal "Last week" (blamer--prettify-time (format-date-to-string week-ago)
(format-time-to-string week-ago))))
(should (equal "4 weeks ago" (blamer--prettify-time (format-date-to-string 4-weeks-ago)
(format-time-to-string 4-weeks-ago))))
(should (equal "Previous month" (blamer--prettify-time (format-date-to-string month-ago)
(format-time-to-string month-ago))))
(should (equal "9 months ago" (blamer--prettify-time (format-date-to-string 9-months-ago)
(format-time-to-string 9-months-ago))))
(should (equal "Previous year" (blamer--prettify-time (format-date-to-string year-ago)
(format-time-to-string year-ago))))
(should (equal "4 years ago" (blamer--prettify-time (format-date-to-string 4-years-ago)
(format-time-to-string 4-years-ago))))
(should (equal 11-years-ago-prettified (blamer--prettify-time (format-date-to-string 11-years-ago)
(format-time-to-string 11-years-ago))))))
(ert-deftest test-time-truncating ()
"Test prettified time format."
(should (equal "15:40" (blamer--truncate-time "15:40:22")))
(should (equal "00:00" (blamer--truncate-time "00:00:00")))
(should (equal "12:30" (blamer--truncate-time "12:30:21"))))
(ert-deftest test-replace-caret-in-sha-commit ()
"Test replacing caret in commit sha."
(should (equal "fcb7278" (blamer--remove-commit-hash-caret "^fcb7278"))))
(ert-deftest test-note-replace-caret-in-sha-commit ()
"Test not replacing caret in commit sha."
(should (equal "fcb7278" (blamer--remove-commit-hash-caret "fcb7278"))))