YAY
parent
3ea29abf8b
commit
2495e06d53
|
|
@ -1,5 +1,7 @@
|
|||
package ledger
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Currency string
|
||||
|
||||
const (
|
||||
|
|
@ -32,3 +34,7 @@ func (delta Delta) Plus(other Delta) Delta {
|
|||
Currency: other.Currency,
|
||||
}
|
||||
}
|
||||
|
||||
func (delta Delta) Debug() string {
|
||||
return fmt.Sprintf("{@%s %s:\"%s\" %.2f %s}", delta.Date, delta.Account, delta.Description, delta.Value, delta.Currency)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,35 @@ package ledger
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"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{
|
||||
{
|
||||
|
|
@ -66,7 +91,7 @@ func TestFileDeltas(t *testing.T) {
|
|||
break
|
||||
}
|
||||
if want[i] != deltas[i] {
|
||||
t.Errorf("[%d] \n\twant=%+v, \n\t got=%+v", i, want[i], deltas[i])
|
||||
t.Errorf("[%d] \n\twant=%s, \n\t got=%s", i, want[i].Debug(), deltas[i].Debug())
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue