-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathliterals_test.go
67 lines (58 loc) · 1.24 KB
/
literals_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
// 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"
)
// test literal syntax
const literalgopp = `
Start => <Rule>
Rule => {field=R} 'Success!'
Rule => {field=S} '1'
Rule => {field=T} <symbol>
Rule => {field=X} {Success!} 'X'
Rule => {field=Y} {1} 'Y'
Rule => {field=Z} {1} 'Z'
symbol = /(2)/
`
type LiteralTester struct {
R string
S int
T int
X string
Y int
Z uint
}
var LiteralTestTable = [...]struct {
expected LiteralTester
src string
}{
{LiteralTester{X: "Success!"}, "X"},
{LiteralTester{Y: 1}, "Y"},
{LiteralTester{Z: 1}, "Z"},
{LiteralTester{R: "Success!"}, "Success!"},
{LiteralTester{S: 1}, "1"},
{LiteralTester{T: 2}, "2"},
}
func TestLiteral(t *testing.T) {
df, err := gopp.NewDecoderFactory(literalgopp, "Start")
if err != nil {
t.Error(err)
return
}
for _, test := range LiteralTestTable {
dec := df.NewDecoder(strings.NewReader(test.src))
var lit LiteralTester
err = dec.Decode(&lit)
if err != nil {
t.Error(err)
return
}
if lit != test.expected {
t.Errorf("Expected %+v, got %+v.", test.expected, lit)
}
}
}