-
Notifications
You must be signed in to change notification settings - Fork 1
/
assert_unit.go
126 lines (114 loc) · 3.99 KB
/
assert_unit.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package asttest
import (
"testing"
"github.com/akm/tparser/ast"
"github.com/stretchr/testify/assert"
)
func AssertUnits(t *testing.T, expected, actual ast.Units) {
if !assert.Equal(t, len(expected), len(actual)) {
return
}
for i, exp := range expected {
act := actual[i]
if !assert.Equal(t, exp, act) {
AssertUnit(t, exp, act)
}
}
}
func AssertUnit(t *testing.T, expected, actual *ast.Unit) {
assert.Equal(t, expected.Path, actual.Path)
if !assert.Equal(t, expected.Ident, actual.Ident) {
AssertIdent(t, expected.Ident, actual.Ident)
}
if !assert.Equal(t, expected.PortabilityDirective, actual.PortabilityDirective) {
AssertPortabilityDirective(t, expected.PortabilityDirective, actual.PortabilityDirective)
}
if !assert.Equal(t, expected.InterfaceSection, actual.InterfaceSection) {
AssertInterfaceSection(t, expected.InterfaceSection, actual.InterfaceSection)
}
if !assert.Equal(t, expected.ImplementationSection, actual.ImplementationSection) {
AssertImplementationSection(t, expected.ImplementationSection, actual.ImplementationSection)
}
if !assert.Equal(t, expected.InitSection, actual.InitSection) {
AssertInitSection(t, expected.InitSection, actual.InitSection)
}
}
func AssertInterfaceSection(t *testing.T, expected, actual *ast.InterfaceSection) {
if !assert.Equal(t, expected.UsesClause, actual.UsesClause) {
AssertUsesClause(t, expected.UsesClause, actual.UsesClause)
}
if !assert.Equal(t, expected.InterfaceDecls, actual.InterfaceDecls) {
AssertInterfaceDecls(t, expected.InterfaceDecls, actual.InterfaceDecls)
}
}
func AssertInterfaceDecls(t *testing.T, expected, actual ast.InterfaceDecls) {
if !assert.Equal(t, len(expected), len(actual)) {
return
}
for i, exp := range expected {
act := actual[i]
if !assert.Equal(t, exp, act) {
AssertInterfaceDecl(t, exp, act)
}
}
}
func AssertInterfaceDecl(t *testing.T, expected, actual ast.InterfaceDecl) {
if !assert.IsType(t, expected, actual) {
return
}
switch exp := expected.(type) {
case ast.ConstSection:
AssertConstSection(t, exp, actual.(ast.ConstSection))
case ast.TypeSection:
AssertTypeSection(t, exp, actual.(ast.TypeSection))
case ast.VarSection:
AssertVarSection(t, exp, actual.(ast.VarSection))
case ast.ThreadVarSection:
AssertThreadVarSection(t, exp, actual.(ast.ThreadVarSection))
case *ast.ExportedHeading:
AssertExportedHeading(t, exp, actual.(*ast.ExportedHeading))
default:
assert.Fail(t, "unexpected interface decl type: %T", exp)
}
}
func AssertImplementationSection(t *testing.T, expected, actual *ast.ImplementationSection) {
if !assert.Equal(t, expected.UsesClause, actual.UsesClause) {
AssertUsesClause(t, expected.UsesClause, actual.UsesClause)
}
if !assert.Equal(t, expected.DeclSections, actual.DeclSections) {
AssertDeclSections(t, expected.DeclSections, actual.DeclSections)
}
if !assert.Equal(t, expected.ExportsStmts, actual.ExportsStmts) {
AssertExportsStmts(t, expected.ExportsStmts, actual.ExportsStmts)
}
}
func AssertInitSection(t *testing.T, expected, actual *ast.InitSection) {
if !assert.Equal(t, expected.InitializationStmts, actual.InitializationStmts) {
AssertStmtList(t, expected.InitializationStmts, actual.InitializationStmts)
}
if !assert.Equal(t, expected.FinalizationStmts, actual.FinalizationStmts) {
AssertStmtList(t, expected.FinalizationStmts, actual.FinalizationStmts)
}
}
func AssertUnitId(t *testing.T, expected, actual *ast.UnitId) {
AssertIdent(t, (*ast.Ident)(expected), (*ast.Ident)(actual))
}
func AssertQualId(t *testing.T, expected, actual *ast.QualId) {
if !assert.Equal(t, expected.NamespaceId, actual.NamespaceId) {
AssertIdentRef(t, expected.NamespaceId, actual.NamespaceId)
}
if !assert.Equal(t, expected.Ident, actual.Ident) {
AssertIdentRef(t, expected.Ident, actual.Ident)
}
}
func AssertQualIds(t *testing.T, expected, actual ast.QualIds) {
if !assert.Equal(t, len(expected), len(actual)) {
return
}
for i, exp := range expected {
act := actual[i]
if !assert.Equal(t, exp, act) {
AssertQualId(t, exp, act)
}
}
}