package ledger import ( "path/filepath" "testing" ) func TestFileTestdata(t *testing.T) { paths, err := filepath.Glob("./testdata/*") if err != nil { t.Fatal(err) } for _, pathd := range paths { path := pathd t.Run(path, func(t *testing.T) { f, err := NewFile(path) if err != nil { t.Fatal(err) } transactions, err := f.Deltas() if err != nil { t.Fatal(err) } for i := range transactions { t.Logf("%+v", transactions[i].Debug()) } }) } } func TestFileDeltas(t *testing.T) { happy := []Delta{ { Date: "2022-12-12", Account: "AssetAccount:Cash:Fidelity76", Value: -97.92, Currency: USD, Description: "Electricity / Power Bill TG2PJ-2PLP5", }, { Date: "2022-12-12", Account: "Withdrawal:0:SharedHome:DominionEnergy", Value: 97.92, Currency: USD, Description: "Electricity / Power Bill TG2PJ-2PLP5", }, { Date: "2022-12-12", Account: "AssetAccount:Cash:Fidelity76", Value: -1.00, Currency: USD, Description: "Test pay chase TG32S-BT2FF", }, { Date: "2022-12-12", Account: "Debts:Credit:ChaseFreedomUltdVisa", Value: 1.00, Currency: USD, Description: "Test pay chase TG32S-BT2FF", }, } 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 i >= len(deltas) { break } if want[i] != deltas[i] { t.Errorf("[%d] \n\twant=%s, \n\t got=%s", i, want[i].Debug(), deltas[i].Debug()) } } }) } }