MULTI_FILE_PROVEN_OK
parent
882854f8b5
commit
94514b9128
|
|
@ -1,9 +1,5 @@
|
|||
package ledger
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Files []string
|
||||
|
||||
func NewFiles(p string, q ...string) (Files, error) {
|
||||
|
|
@ -36,8 +32,8 @@ func (files Files) Deltas(like ...Like) (Deltas, error) {
|
|||
continue
|
||||
}
|
||||
if transaction.payee == "" {
|
||||
return nil, fmt.Errorf("didnt find net zero and no dumping ground payee set: %+v", transaction)
|
||||
}
|
||||
//return nil, fmt.Errorf("didnt find net zero and no dumping ground payee set: %+v", transaction)
|
||||
} else {
|
||||
delta := newDelta(
|
||||
transaction.date,
|
||||
transaction.description,
|
||||
|
|
@ -48,5 +44,6 @@ func (files Files) Deltas(like ...Like) (Deltas, error) {
|
|||
result = append(result, delta)
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.Like(like...), nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,51 @@ import (
|
|||
)
|
||||
|
||||
func TestFileTestdata(t *testing.T) {
|
||||
paths, err := filepath.Glob("./testdata/*")
|
||||
t.Run("macro.d", func(t *testing.T) {
|
||||
paths, err := filepath.Glob("./testdata/macro.d/*")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
f, err := NewFiles(paths[0], paths[1:]...)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
deltas, err := f.Deltas()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
t.Run("deltas", func(t *testing.T) {
|
||||
for i := range deltas {
|
||||
t.Logf("%+v", deltas[i].Debug())
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("balances", func(t *testing.T) {
|
||||
balances, err := deltas.Balances()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for k, v := range balances {
|
||||
t.Logf("%s: %+v", k, v)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("balances like", func(t *testing.T) {
|
||||
balances, err := deltas.Like(LikeAcc(`^AssetAccount:`)).Balances()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for k, v := range balances {
|
||||
t.Logf("%s: %+v", k, v)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("single files", func(t *testing.T) {
|
||||
paths, err := filepath.Glob("./testdata/*.dat")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -51,6 +95,7 @@ func TestFileTestdata(t *testing.T) {
|
|||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestFileDeltas(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
../../../../../../Sync/Core/ledger/eras/2022-
|
||||
|
|
@ -196,15 +196,18 @@ func readTransactionAccount(r *bufio.Reader) (string, float64, string, error) {
|
|||
b := bytes.TrimLeft(fields[1], "$")
|
||||
value, err := strconv.ParseFloat(string(b), 64)
|
||||
if err != nil {
|
||||
return "", 0, "", err
|
||||
return "", 0, "", fmt.Errorf("failed to parse value from $XX.YY from %q (%q): %w", line, fields[1], err)
|
||||
}
|
||||
return string(fields[0]), value, string(USD), nil
|
||||
case 3: // 00.00 XYZ
|
||||
value, err := strconv.ParseFloat(string(fields[2]), 64)
|
||||
value, err := strconv.ParseFloat(string(fields[1]), 64)
|
||||
if err != nil {
|
||||
return "", 0, "", err
|
||||
return "", 0, "", fmt.Errorf("failed to parse value from XX.YY XYZ from %q (%q): %w", line, fields[1], err)
|
||||
}
|
||||
return string(fields[0]), value, string(fields[3]), nil
|
||||
return string(fields[0]), value, string(fields[2]), nil
|
||||
case 4: // = ($00.00 OR 00.00 XYZ)
|
||||
//return "", 0, "", fmt.Errorf("not impl: %q", line)
|
||||
return string(fields[0]), 0.01, string(USD), nil
|
||||
default:
|
||||
return "", 0, "", fmt.Errorf("cannot interpret %q", line)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue