A data directory holds one folder per account. Statements dropped into those folders are parsed into a rebuildable SQLite index, categorised by ordered glob rules in rules.toml, and browsed or hand-tagged in a Bubble Tea TUI. Movements between the user's own accounts are marked as transfers by the same rules and excluded from spending totals. Manual tags and transfer marks are stored separately from the rule-derived ones and always win, so editing rules.toml and re-running retag never destroys hand edits. Parsers are pluggable. Three are ported from the Python extractors they replace -- nlb and traderepublic read PDFs via pdftotext -layout, revolut reads the CSV export -- alongside a configurable-column CSV parser and a cmd parser that shells out to an external script. Both ports fix two latent bugs in the originals: the sign character class rejected the typographic minus U+2212 that some PDF fonts emit, and NLB's hardcoded continuation indent broke when pdftotext compressed runs of spaces, so the threshold is now measured from the description column. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package parser
|
||
|
||
import "testing"
|
||
|
||
func TestParseAmount(t *testing.T) {
|
||
cases := []struct {
|
||
in string
|
||
decimal string
|
||
thousands string
|
||
digits int
|
||
want int64
|
||
}{
|
||
{"45.20", ".", "", 2, 4520},
|
||
{"-45.20", ".", "", 2, -4520},
|
||
{"45,20", ",", ".", 2, 4520},
|
||
{"1.234,56", ",", ".", 2, 123456},
|
||
{"1,234.56", ".", ",", 2, 123456},
|
||
{"1 234.56", ".", " ", 2, 123456},
|
||
{"45.20 EUR", ".", "", 2, 4520},
|
||
{"BGN 45.20", ".", "", 2, 4520},
|
||
{"45,20-", ",", "", 2, -4520},
|
||
{"(45.20)", ".", "", 2, -4520},
|
||
{"+45.20", ".", "", 2, 4520},
|
||
{"0.00", ".", "", 2, 0},
|
||
{".50", ".", "", 2, 50},
|
||
{"45", ".", "", 2, 4500},
|
||
{"45.2", ".", "", 2, 4520},
|
||
{"45.205", ".", "", 2, 4521}, // round half away from zero
|
||
{"45.204", ".", "", 2, 4520}, // round down
|
||
{"-45.205", ".", "", 2, -4521},
|
||
{"1234", ".", "", 0, 1234}, // zero-digit currency
|
||
{"1234.6", ".", "", 0, 1235},
|
||
{"1.234567", ".", "", 3, 1235},
|
||
{"−45.20", ".", "", 2, -4520}, // U+2212 minus
|
||
}
|
||
for _, c := range cases {
|
||
got, err := ParseAmount(c.in, c.decimal, c.thousands, c.digits)
|
||
if err != nil {
|
||
t.Errorf("ParseAmount(%q) error: %v", c.in, err)
|
||
continue
|
||
}
|
||
if got != c.want {
|
||
t.Errorf("ParseAmount(%q, decimal=%q, digits=%d) = %d, want %d",
|
||
c.in, c.decimal, c.digits, got, c.want)
|
||
}
|
||
}
|
||
}
|
||
|
||
func TestParseAmountErrors(t *testing.T) {
|
||
for _, in := range []string{"", " ", "abc", "-", "."} {
|
||
if v, err := ParseAmount(in, ".", "", 2); err == nil {
|
||
t.Errorf("ParseAmount(%q) = %d, want error", in, v)
|
||
}
|
||
}
|
||
}
|