Skip to content

Commit d2c8d00

Browse files
committed
Add baseline tests for ledger-insert-effective-date command
1 parent 17983be commit d2c8d00

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

test/mode-test.el

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,85 @@ http://bugs.ledger-cli.org/show_bug.cgi?id=256"
205205
Assets:Cash
206206
")))))
207207

208+
(ert-deftest ledger-mode/test-008 ()
209+
"Baseline test for `ledger-insert-effective-date'."
210+
:tags '(mode baseline)
211+
212+
(let ((orig-file-contents
213+
"\
214+
2024-01-01 Grocery Store
215+
Expenses:Groceries $30
216+
Liabilities:Credit Card
217+
218+
2024-01-02 Grocery Store
219+
Expenses:Groceries $10
220+
Expenses:Tax $1.50
221+
Liabilities:Credit Card -$11.50
222+
"))
223+
(ledger-tests-with-temp-file
224+
orig-file-contents
225+
226+
;; insert effective date for xact
227+
(ledger-insert-effective-date "2024-01-02")
228+
(should (equal
229+
(buffer-string)
230+
"\
231+
2024-01-01=2024-01-02 Grocery Store
232+
Expenses:Groceries $30
233+
Liabilities:Credit Card
234+
235+
2024-01-02 Grocery Store
236+
Expenses:Groceries $10
237+
Expenses:Tax $1.50
238+
Liabilities:Credit Card -$11.50
239+
"))
240+
241+
;; With prefix arg, remove the effective date
242+
(let ((current-prefix-arg '(4)))
243+
(call-interactively 'ledger-insert-effective-date))
244+
(should (equal (buffer-string) orig-file-contents))
245+
246+
;; insert effective date after posting with no amount
247+
(forward-line 2)
248+
(ledger-insert-effective-date "2024-01-02")
249+
(should (equal
250+
(buffer-string)
251+
"\
252+
2024-01-01 Grocery Store
253+
Expenses:Groceries $30
254+
Liabilities:Credit Card ; [=2024-01-02]
255+
256+
2024-01-02 Grocery Store
257+
Expenses:Groceries $10
258+
Expenses:Tax $1.50
259+
Liabilities:Credit Card -$11.50
260+
"))
261+
(should (eolp))
262+
(beginning-of-line)
263+
(let ((current-prefix-arg '(4)))
264+
(call-interactively 'ledger-insert-effective-date))
265+
(should (equal (buffer-string) orig-file-contents))
266+
267+
;; insert effective date after posting with amount
268+
(forward-line 5)
269+
(ledger-insert-effective-date "2024-01-03")
270+
(should (equal
271+
(buffer-string)
272+
"\
273+
2024-01-01 Grocery Store
274+
Expenses:Groceries $30
275+
Liabilities:Credit Card
276+
277+
2024-01-02 Grocery Store
278+
Expenses:Groceries $10
279+
Expenses:Tax $1.50
280+
Liabilities:Credit Card -$11.50 ; [=2024-01-03]
281+
"))
282+
(should (eolp))
283+
(let ((current-prefix-arg '(4)))
284+
(call-interactively 'ledger-insert-effective-date))
285+
(should (equal (buffer-string) orig-file-contents)))))
286+
208287
(provide 'mode-test)
209288

210289
;;; mode-test.el ends here

0 commit comments

Comments
 (0)