-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_test.go
37 lines (32 loc) · 1022 Bytes
/
parser_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
package lexer
import (
"reflect"
"testing"
)
type parseTest struct {
name string
input string
err bool
errVal string
sections section
}
var parseTests = []parseTest{
{"empty", "", true, "parse error: nothing to parse", nil},
{"brokensection", "[foo\nfoo=bar\n", true, "parse error: no right bracket found", nil},
{"brokenkey", "[foo]\nfoo\n", true, "parse error: no equal sign found", nil},
{"brokenvalue", "[foo]\nfoo=bar", true, "parse error: no new line found", nil},
{"success", "[foo]\nfoo=FOO\n", false, "", section{"foo": kp{"foo": "FOO"}}},
{"successcomplex", "[foo]\nfoo=FOO\n\n[bar]\nbar=BAR\n", false, "", section{
"foo": kp{"foo": "FOO"},
"bar": kp{"bar": "BAR"},
}},
}
func TestParser(t *testing.T) {
for _, pt := range parseTests {
p, err := parse(pt.input)
if (pt.err && (p != nil || err == nil || err.Error() != pt.errVal)) ||
(!pt.err && (p == nil || err != nil || !reflect.DeepEqual(pt.sections, p))) {
t.Errorf("test %s did not pass\n", pt.name)
}
}
}