/
errors_test.go
57 lines (51 loc) · 1.11 KB
/
errors_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
// Copyright 2013 The gopp AUTHORS. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gopp_test
import (
"github.com/skelterjohn/gopp"
"strings"
"testing"
)
type ErrorCase struct {
Document string
ExpectedError string
}
type ErrorSubject struct {
Name string
Gopp string
Grammar gopp.Grammar
Cases []ErrorCase
}
var ErrorSubjects = []ErrorSubject{
ErrorSubject{
Name: "LiteralConjunction",
Gopp: `
Start => 'x' 'y' 'z'
`,
Cases: []ErrorCase{
ErrorCase{`xyz`, ``},
ErrorCase{`xzy`, `Expected "y" at 0:1.`},
ErrorCase{`x`, `Expected "y" at EOF.`},
},
},
}
func TestErrors(t *testing.T) {
subject:
for _, s := range ErrorSubjects {
df, err := gopp.NewDecoderFactory(s.Gopp, "Start")
if err != nil {
t.Error(err)
continue subject
}
scase:
for _, c := range s.Cases {
dec := df.NewDecoder(strings.NewReader(c.Document))
err = dec.Decode(&XYZ{})
if !(err == nil && c.ExpectedError == "") && (err != nil && err.Error() != c.ExpectedError) {
t.Error(err)
continue scase
}
}
}
}