diff --git a/ledger/file_test.go b/ledger/file_test.go new file mode 100644 index 0000000..33d6410 --- /dev/null +++ b/ledger/file_test.go @@ -0,0 +1,58 @@ +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]) + } + } +} diff --git a/ledger/testdata/happy.dat b/ledger/testdata/happy.dat new file mode 100644 index 0000000..027dcb7 --- /dev/null +++ b/ledger/testdata/happy.dat @@ -0,0 +1,7 @@ +2022-12-12 Electricity / Power Bill TG2PJ-2PLP5 OK + AssetAccount:Cash:Fidelity76 $-97.92 + Withdrawal:0:SharedHome:DominionEnergy +2022-12-12 Test pay chase TG32S-BT2FF OK + AssetAccount:Cash:Fidelity76 $-1.00 + Debts:Credit:ChaseFreedomUltdVisa +