tdd les go
parent
703b7b632d
commit
79effffc47
|
|
@ -6,21 +6,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFileDeltas(t *testing.T) {
|
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 {
|
d := func(s string) time.Time {
|
||||||
v, _ := time.Parse("2006-01-02", s)
|
v, _ := time.Parse("2006-01-02", s)
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
want := []Delta{
|
happy := []Delta{
|
||||||
{
|
{
|
||||||
Date: d("2022-12-12"),
|
Date: d("2022-12-12"),
|
||||||
Account: "AssetAccount:Cash:Fidelity76",
|
Account: "AssetAccount:Cash:Fidelity76",
|
||||||
|
|
@ -47,6 +37,25 @@ func TestFileDeltas(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
if len(deltas) != len(want) {
|
||||||
t.Error(len(deltas))
|
t.Error(len(deltas))
|
||||||
}
|
}
|
||||||
|
|
@ -55,4 +64,6 @@ func TestFileDeltas(t *testing.T) {
|
||||||
t.Errorf("[%d] \n\twant=%+v, \n\t got=%+v", i, want[i], deltas[i])
|
t.Errorf("[%d] \n\twant=%+v, \n\t got=%+v", i, want[i], deltas[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
2022-12-12 Electricity / Power Bill TG2PJ-2PLP5 OK
|
||||||
|
AssetAccount:Cash:Fidelity76 $-97.92
|
||||||
|
Withdrawal:0:SharedHome:DominionEnergy
|
||||||
Loading…
Reference in New Issue