package ledger import ( "testing" "time" ) func TestFileDeltas(t *testing.T) { d := func(s string) time.Time { v, _ := time.Parse("2006-01-02", s) return v } happy := []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, }, } cases := map[string][]Delta{ "empty": nil, "one": happy[:2], "happy": happy[:], } for name, d := range cases { want := d t.Run(name, func(t *testing.T) { f, err := NewFile("./testdata/" + name + ".dat") if err != nil { t.Fatal(err) } deltas, err := f.Deltas() if err != nil { t.Fatal(err) } if len(deltas) != len(want) { t.Error(len(deltas)) } for i := range want { if want[i] != deltas[i] { t.Errorf("[%d] \n\twant=%+v, \n\t got=%+v", i, want[i], deltas[i]) } } }) } }