Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle prefixed negation on commoditized amounts #212

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions ledger-regex.el
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,22 @@
(ledger-define-regexp commoditized-amount
(macroexpand
`(rx (group
(or (and (regexp ,ledger-commodity-no-group-regexp)
(*? blank)
(regexp ,ledger-amount-no-group-regexp))
(and (regexp ,ledger-amount-no-group-regexp)
(*? blank)
(regexp ,ledger-commodity-no-group-regexp))))))
"")
(or
;; Match commodity before amount, with optional
;; minus sign allowed before commodity.

;; Ex: "$100" or "-$100"
(and (opt ?-)
(regexp ,ledger-commodity-no-group-regexp)
(*? blank)
(regexp ,ledger-amount-no-group-regexp))
;; Match commodity after amount

;; Ex: "100 Dollars"
(and (regexp ,ledger-amount-no-group-regexp)
(*? blank)
(regexp ,ledger-commodity-no-group-regexp))))))
"Regexp to match a commodity with ammount such as \"$100\" or \"100 Dollars\"")

(ledger-define-regexp commodity-annotations
(macroexpand
Expand Down
16 changes: 16 additions & 0 deletions test/context-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,22 @@ http://bugs.ledger-cli.org/show_bug.cgi?id=257"
(should (equal "$1,000.00"
(ledger-context-field-value context 'commoditized-amount))))))

(ert-deftest ledger-context/test-009 ()
"Regress test for #211
https://github.com/ledger/ledger-mode/issues/211"
:tags '(context regress)

(ledger-tests-with-temp-file
"2004/05/01 * Checking balance
Assets:Bank:Checking -$1,000.00
Equity:Opening Balances
"
(goto-char 65) ; on the amount 1,000.00
(let ((context (ledger-context-at-point)))
(should (eq (ledger-context-current-field context) 'commoditized-amount))
(should (equal "-$1,000.00"
(ledger-context-field-value context 'commoditized-amount))))))


(provide 'context-test)

Expand Down