-
Notifications
You must be signed in to change notification settings - Fork 1
/
base.go
68 lines (62 loc) · 1.63 KB
/
base.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
package runners
import (
"github.com/akm/tparser/parser"
"github.com/pkg/errors"
)
func NewTestParser(text *[]rune, origArgs ...interface{}) *parser.Parser {
var ctx parser.Context
for _, origArg := range origArgs {
switch v := origArg.(type) {
case parser.Context:
ctx = v
default:
panic(errors.Errorf("Unsupported type %T (%v) is given for NewTestParser", origArg, origArg))
}
}
if ctx == nil {
ctx = NewTestUnitContext()
}
p := parser.NewParser(ctx)
p.SetText(text)
return p
}
func NewTestProgramParser(text *[]rune, origArgs ...interface{}) *parser.ProgramParser {
var ctx *parser.ProgramContext
for _, origArg := range origArgs {
switch v := origArg.(type) {
case *parser.ProgramContext:
ctx = v
default:
panic(errors.Errorf("Unsupported type %T (%v) is given for NewTestParser", origArg, origArg))
}
}
if ctx == nil {
ctx = NewTestProgramContext()
}
p := parser.NewProgramParser(ctx)
p.SetText(text)
return p
}
func NewTestUnitParser(text *[]rune, origArgs ...interface{}) *parser.UnitParser {
var ctx *parser.UnitContext
for _, origArg := range origArgs {
switch v := origArg.(type) {
case *parser.UnitContext:
ctx = v
default:
panic(errors.Errorf("Unsupported type %T (%v) is given for NewTestParser", origArg, origArg))
}
}
if ctx == nil {
ctx = NewTestUnitContext()
}
p := parser.NewUnitParser(ctx)
p.SetText(text)
return p
}
func NewTestProgramContext(args ...interface{}) *parser.ProgramContext {
return parser.NewProgramContext(args...)
}
func NewTestUnitContext(args ...interface{}) *parser.UnitContext {
return parser.NewUnitContext(NewTestProgramContext(), args...)
}