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

fix(foldtext): handle negative balance assertions (#165) #166

Merged
merged 1 commit into from
Jan 28, 2025
Merged
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
13 changes: 12 additions & 1 deletion ftplugin/ledger.vim
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,18 @@ let s:valreg = '\('.
\ '\|'.
\ '[,.][0-9]\+'.
\ '\)'
let s:optional_balance_assertion = '\(\s*=\s*'.s:cursym.'\s*'.s:valreg.'\)\?'
let s:optsgn = '[+-]\?'
let s:cursgn = '\('.
\ s:optsgn.
\ '\s*'.
\ s:cursym.
\ '\|'.
\ s:cursym.
\ '\s*'.
\ s:optsgn.
\ '\)'

let s:optional_balance_assertion = '\(\s*=\s*'.s:cursgn.'\s*'.s:valreg.'\)\?'

let s:rx_amount = s:valreg.
\ s:optional_balance_assertion.
Expand Down
29 changes: 29 additions & 0 deletions test/vim-ledger-test.journal
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
; tests transactions for folds

2025-01-01 test simple fold, no assertion, should read 100.10
io:income
assets:bank £ 100.10

2025-01-01 test positive assertion. should read 100.20
io:income
assets:bank £ 100.20 = £ 200.10

2025-01-01 no assertion, negative txn, should read -13
io:income
assets:bank £ -13

2025-01-01 test negative assertion. should read -400
io:income
assets:bank £ -400 = £ -199.7

2025-01-01 as above, sign and currency swapped. should read -400
io:income
assets:bank £ -400 = - £199.7

2025-01-01 test positive assert. should be 10
io:income
assets:bank £ 10 = £ +12

2025-01-01 test positive assert 2. should be 9
io:income
assets:bank £ 9 = + £ 12
Loading