test file shows ledger pkg cant parse for nothin

main
Bel LaPointe 2023-10-23 10:55:41 -06:00
parent b29bae4727
commit 94f3031724
2 changed files with 65 additions and 0 deletions

58
ledger/file_test.go Normal file
View File

@ -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])
}
}
}

7
ledger/testdata/happy.dat vendored Normal file
View File

@ -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