forked from howeyc/ledger
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ledgerReader_test.go
81 lines (67 loc) · 1.67 KB
/
ledgerReader_test.go
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
69
70
71
72
73
74
75
76
77
78
79
80
81
package ledger
import (
"bytes"
"io/ioutil"
"path/filepath"
"testing"
)
func TestLedgerScannerBasic(t *testing.T) {
r, err := NewLedgerReader("testdata/ledgerReader_input_0")
if err != nil {
t.Fatal(err)
}
parsed, err := ioutil.ReadAll(r)
if err != nil {
t.Fatal(err)
}
expected, _ := ioutil.ReadFile(filepath.Join("testdata", "ledgerReader_expected_0"))
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(parsed, expected) {
t.Fatalf("expected:\n%s\n\ngot:\n%s\n", expected, parsed)
}
}
func TestLedgerScannerSingleInclude(t *testing.T) {
r, err := NewLedgerReader("testdata/ledgerReader_input_1_root")
if err != nil {
t.Fatal(err)
}
parsed, err := ioutil.ReadAll(r)
if err != nil {
t.Fatal(err)
}
expected, _ := ioutil.ReadFile(filepath.Join("testdata", "ledgerReader_expected_1"))
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(parsed, expected) {
t.Fatalf("expected:\n%s\n\n got:\n%s", expected, parsed)
}
}
func TestLedgerScannerWildcardInclude(t *testing.T) {
r, err := NewLedgerReader("testdata/ledgerReader_input_wildcard_root")
if err != nil {
t.Fatal(err)
}
parsed, err := ioutil.ReadAll(r)
if err != nil {
t.Fatal(err)
}
expected, _ := ioutil.ReadFile(filepath.Join("testdata", "ledgerReader_expected_wildcard"))
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(parsed, expected) {
t.Fatalf("expected:\n%s\n\n got:\n%s", expected, parsed)
}
}
func TestMarkerSplit(t *testing.T) {
filename, lineNum := parseMarker(";__ledger_file*-*/somedir/somefile*-*45")
if filename != "/somedir/somefile" {
t.Fatalf("expected: %s got:%s", "/somedir/somefile", filename)
}
if lineNum != 45 {
t.Fatalf("expected: %d got:%d", 45, lineNum)
}
}