ana-ledger/ledger/file_test.go

59 lines
1013 B
Go

package ledger
import (
"testing"
"time"
)
func TestFileDeltas(t *testing.T) {
f, err := NewFile("./testdata/happy.dat")
if err != nil {
t.Fatal(err)
}
deltas, err := f.Deltas()
if err != nil {
t.Fatal(err)
}
d := func(s string) time.Time {
v, _ := time.Parse("2006-01-02", s)
return v
}
want := []Delta{
{
Date: d("2022-12-12"),
Account: "AssetAccount:Cash:Fidelity76",
Value: -97.92,
Currency: USD,
},
{
Date: d("2022-12-12"),
Account: "Withdrawal:0:SharedHome:DominionEnergy",
Value: 97.92,
Currency: USD,
},
{
Date: d("2022-12-12"),
Account: "AssetAccount:Cash:Fidelity76",
Value: -1.00,
Currency: USD,
},
{
Date: d("2022-12-12"),
Account: "Debts:Credit:ChaseFreedomUltdVisa",
Value: 1.00,
Currency: USD,
},
}
if len(deltas) != len(want) {
t.Error(len(deltas))
}
for i := range want {
if want[i] != deltas[i] {
t.Errorf("[%d] want=%+v, got=%+v", i, want[i], deltas[i])
}
}
}