Browse Source

Get RAW if LABEL is not present

custom-labels
Damien Cassou 3 years ago
parent
commit
a0ed318d38
No known key found for this signature in database GPG Key ID: A7123815F5DCE914
2 changed files with 26 additions and 1 deletions
  1. +8
    -0
      elbank-common.el
  2. +18
    -1
      test/elbank-common-test.el

+ 8
- 0
elbank-common.el View File

@ -126,6 +126,14 @@ Data is cached to `elbank-data'."
If the result is nil, return DEFAULT."
(map-elt transaction key default))
(cl-defmethod elbank-transaction-elt (transaction (_key (eql label)) &optional default)
"Return the label of TRANSACTION.
The label is defined as the value at symbol `label' if present,
the value at symbol `raw' if not. If both are nil, return DEFAULT."
(or (map-elt transaction 'label nil)
(map-elt transaction 'raw default)))
(cl-defmethod elbank-transaction-elt (transaction (_key (eql category)) &optional default)
"Return the category of TRANSACTION.


+ 18
- 1
test/elbank-common-test.el View File

@ -60,7 +60,24 @@
(let ((tr1 '((category . (("foo" . 20) ("bar" . 10)))))
(tr2 '((category . "foo"))))
(expect (elbank-transaction-split-p tr1) :to-be-truthy)
(expect (elbank-transaction-split-p tr2) :to-be nil))))
(expect (elbank-transaction-split-p tr2) :to-be nil)))
(describe "when asked for label"
(it "returns label if present"
(let ((tr '((label . "foo"))))
(expect (elbank-transaction-elt tr 'label) :to-equal "foo")))
(it "prefers label over raw"
(let ((tr '((label . "foo") (raw . "bar"))))
(expect (elbank-transaction-elt tr 'label) :to-equal "foo")))
(it "returns raw if present and label is not"
(let ((tr '((raw . "foo"))))
(expect (elbank-transaction-elt tr 'label) :to-equal "foo")))
(it "returns default if neither label nor raw are present"
(let ((tr '((something-else . "bar"))))
(expect (elbank-transaction-elt tr 'label "foo") :to-equal "foo")))))
(provide 'elbank-common-test)
;;; elbank-common-test.el ends here

Loading…
Cancel
Save