-
Notifications
You must be signed in to change notification settings - Fork 0
/
Reader.ReadHeader_test.go
87 lines (82 loc) · 1.55 KB
/
Reader.ReadHeader_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
82
83
84
85
86
87
package mxt
import (
"strings"
"testing"
)
func TestValidHeaders(t *testing.T) {
var allTests = []struct {
input string
name string
comment string
}{
{
`// filename -->`,
"filename",
"",
},
{
`// file.name this is a comment -->`,
"file.name",
"this is a comment",
},
{
`// file/name
// this is a comment line -->`,
"file/name",
"this is a comment line",
},
{
`// file.name this is a comment line 1
// and line 2 -->`,
"file.name",
"this is a comment line 1 and line 2",
},
{
`// file-name.txt this is a comment line 1
// and line 2
//
// line 3
// -->`,
"file-name.txt",
"this is a comment line 1 and line 2\nline 3",
},
{
`//--------------------- file.name.txt
// ------------------------------------------------>`,
"file.name.txt",
"",
},
{
`// file@sys:cfg --> XYZ`,
"file@sys:cfg",
"",
},
}
for _, test := range allTests {
r := NewReader(strings.NewReader(test.input))
c, err := r.ReadChunk()
h := c.Header
if h.Name != test.name {
t.Errorf("invalid name: %q != %q", h.Name, test.name)
}
if h.Comment != test.comment {
t.Errorf("invalid comment: %q != %q", h.Comment, test.comment)
}
if err != nil {
t.Errorf("unexpected error: %v", err)
}
}
}
func TestInvalidHeader(t *testing.T) {
var allTests = []struct {
input string
err error
}{}
for _, test := range allTests {
r := NewReader(strings.NewReader(test.input))
_, err := r.ReadChunk()
if err != test.err {
t.Errorf("invalid error: %v != %v", err, test.err)
}
}
}