1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
package multicase
import "testing"
var header = []string{"Firma", "Year", "Month", "Day", "Konto", "Bilagsnummer", "Belop", "MvaKode",
"BilagsArt", "BilagsArtTekst", "Tekst", "Faktura kundenr", "LevNr.", "BuntHodeID"}
func row(account, number, amount, vat, typ, typeText, customer, batch string) []string {
return []string{"Demo AS", "2026", "10", "1", account, number, amount, vat, typ, typeText, "Demo", customer, "", batch}
}
func TestParse(t *testing.T) {
grid := [][]string{
header,
row("3000", "100", "-125", "3", "11", "Faktura", "20001", "1"),
row("20001", "100", "125", "", "11", "Faktura", "20001", "1"),
row("1460", "0", "-10", "", "31", "Lagerkorrigering", "", "1"),
row("4301", "0", "10", "", "31", "Lagerkorrigering", "", "1"),
row("1460", "0", "5", "", "31", "Lagerkorrigering", "", "2"),
row("4301", "0", "-5", "", "31", "Lagerkorrigering", "", "2"),
}
vs, err := Parse(grid)
if err != nil {
t.Fatal(err)
}
if len(vs) != 3 {
t.Fatalf("got %d vouchers, want 3", len(vs))
}
keys := map[string]bool{}
for _, v := range vs {
keys[v.Key()] = true
if v.Balance() != 0 {
t.Errorf("%s does not balance", v.Label())
}
}
for _, k := range []string{"multicase:11:100", "multicase:31:bunt-1", "multicase:31:bunt-2"} {
if !keys[k] {
t.Errorf("missing voucher %s in %v", k, keys)
}
}
if got := vs[0].Lines[0].Amount; got != -12500 {
t.Errorf("amount = %d øre, want -12500", got)
}
}
func TestParseRejectsMissingColumns(t *testing.T) {
if _, err := Parse([][]string{{"Konto", "Belop"}}); err == nil {
t.Fatal("expected an error for a file that is not a buntfil")
}
}
func TestParseAmount(t *testing.T) {
tests := map[string]int64{
"": 0,
"46.7": 4670,
"-46.7": -4670,
"44587.125": 4458713,
"-4053.375": -405338,
"0.1": 10,
"1,5": 150,
}
for in, want := range tests {
got, err := ParseAmount(in)
if err != nil || got != want {
t.Errorf("ParseAmount(%q) = %d, %v; want %d", in, got, err, want)
}
}
}
|