Skip to content

Commit aabf197

Browse files
authored
fix(foldtext): handle negative balance assertions (#165) (#166)
1 parent dbc683e commit aabf197

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

ftplugin/ledger.vim

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,18 @@ let s:valreg = '\('.
222222
\ '\|'.
223223
\ '[,.][0-9]\+'.
224224
\ '\)'
225-
let s:optional_balance_assertion = '\(\s*=\s*'.s:cursym.'\s*'.s:valreg.'\)\?'
225+
let s:optsgn = '[+-]\?'
226+
let s:cursgn = '\('.
227+
\ s:optsgn.
228+
\ '\s*'.
229+
\ s:cursym.
230+
\ '\|'.
231+
\ s:cursym.
232+
\ '\s*'.
233+
\ s:optsgn.
234+
\ '\)'
235+
236+
let s:optional_balance_assertion = '\(\s*=\s*'.s:cursgn.'\s*'.s:valreg.'\)\?'
226237

227238
let s:rx_amount = s:valreg.
228239
\ s:optional_balance_assertion.

test/vim-ledger-test.journal

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
; tests transactions for folds
2+
3+
2025-01-01 test simple fold, no assertion, should read 100.10
4+
io:income
5+
assets:bank £ 100.10
6+
7+
2025-01-01 test positive assertion. should read 100.20
8+
io:income
9+
assets:bank £ 100.20 = £ 200.10
10+
11+
2025-01-01 no assertion, negative txn, should read -13
12+
io:income
13+
assets:bank £ -13
14+
15+
2025-01-01 test negative assertion. should read -400
16+
io:income
17+
assets:bank £ -400 = £ -199.7
18+
19+
2025-01-01 as above, sign and currency swapped. should read -400
20+
io:income
21+
assets:bank £ -400 = - £199.7
22+
23+
2025-01-01 test positive assert. should be 10
24+
io:income
25+
assets:bank £ 10 = £ +12
26+
27+
2025-01-01 test positive assert 2. should be 9
28+
io:income
29+
assets:bank £ 9 = + £ 12

0 commit comments

Comments
 (0)