-
Notifications
You must be signed in to change notification settings - Fork 1
/
type_section_test_runner.go
48 lines (42 loc) · 1.35 KB
/
type_section_test_runner.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
package runners
import (
"testing"
"github.com/akm/tparser/ast"
"github.com/akm/tparser/ast/astcore"
"github.com/akm/tparser/ast/asttest"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
func RunTypeSection(t *testing.T, name string, text []rune, expected ast.TypeSection, args ...interface{}) {
NewTypeSectionTestRunner(t, name, text, expected, args...).Run()
}
type TypeSectionTestRunner struct {
*BaseTestRunner
Expected ast.TypeSection
}
func NewTypeSectionTestRunner(t *testing.T, name string, text []rune, expected ast.TypeSection, args ...interface{}) *TypeSectionTestRunner {
parserArgFuncs, rest1 := FilterParserArgFuncs(args)
baseRunnerFuncs, rest2 := FilterBaseTestRunnerFuncs(rest1)
if len(rest2) > 0 {
panic(errors.Errorf("unexpected arguments: %v", rest2))
}
return &TypeSectionTestRunner{
BaseTestRunner: NewBaseTestRunner(t, name, &text, true, parserArgFuncs, baseRunnerFuncs),
Expected: expected,
}
}
func (tt *TypeSectionTestRunner) Run() *TypeSectionTestRunner {
tt.BaseTestRunner.Run(
func() (astcore.Node, error) {
return tt.NewParser().ParseTypeSection(true)
},
func(t *testing.T, actual astcore.Node) {
if !assert.Equal(t, tt.Expected, actual) {
if assert.IsType(t, tt.Expected, actual) {
asttest.AssertTypeSection(t, tt.Expected, actual.(ast.TypeSection))
}
}
},
)
return tt
}