break out for take 2
This commit is contained in:
66
ledger/transaction_test.go
Normal file
66
ledger/transaction_test.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package ledger
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestReadTransaction(t *testing.T) {
|
||||
cases := map[string]struct {
|
||||
input string
|
||||
want transaction
|
||||
err error
|
||||
}{
|
||||
"empty": {
|
||||
input: "",
|
||||
want: transaction{},
|
||||
err: io.EOF,
|
||||
},
|
||||
"white space": {
|
||||
input: " ",
|
||||
want: transaction{},
|
||||
err: io.EOF,
|
||||
},
|
||||
"verbose": {
|
||||
input: `
|
||||
2003-04-05 Reasoning here
|
||||
A:B $1.00
|
||||
C:D $-1.00
|
||||
`,
|
||||
want: transaction{
|
||||
date: "2003-04-05",
|
||||
description: "Reasoning here",
|
||||
payee: "",
|
||||
recipients: []transactionRecipient{
|
||||
{
|
||||
name: "A:B",
|
||||
value: 1.0,
|
||||
currency: "$",
|
||||
},
|
||||
{
|
||||
name: "C:D",
|
||||
value: -1.0,
|
||||
currency: "$",
|
||||
},
|
||||
},
|
||||
},
|
||||
err: io.EOF,
|
||||
},
|
||||
}
|
||||
|
||||
for name, d := range cases {
|
||||
c := d
|
||||
t.Run(name, func(t *testing.T) {
|
||||
_, got, err := readTransaction(strings.NewReader(c.input))
|
||||
if err != c.err {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if fmt.Sprintf("%+v", got) != fmt.Sprintf("%+v", c.want) {
|
||||
t.Errorf("want\n\t%+v, got\n\t%+v", c.want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user