-
Notifications
You must be signed in to change notification settings - Fork 1
/
assert_block.go
121 lines (109 loc) · 3.35 KB
/
assert_block.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
package asttest
import (
"testing"
"github.com/akm/tparser/ast"
"github.com/stretchr/testify/assert"
)
func AssertBlock(t *testing.T, expected, actual *ast.Block) {
if !assert.Equal(t, expected.DeclSections, actual.DeclSections) {
AssertDeclSections(t, expected.DeclSections, actual.DeclSections)
}
if !assert.Equal(t, expected.ExportsStmts1, actual.ExportsStmts1) {
AssertExportsStmts(t, expected.ExportsStmts1, actual.ExportsStmts1)
}
if !assert.Equal(t, expected.Body, actual.Body) {
AssertBlockBody(t, expected.Body, actual.Body)
}
if !assert.Equal(t, expected.ExportsStmts2, actual.ExportsStmts2) {
AssertExportsStmts(t, expected.ExportsStmts2, actual.ExportsStmts2)
}
}
func AssertExportsStmts(t *testing.T, expected, actual ast.ExportsStmts) {
if !assert.Equal(t, len(expected), len(actual)) {
return
}
for i, exp := range expected {
act := actual[i]
if !assert.Equal(t, exp, act) {
AssertExportsStmt(t, exp, act)
}
}
}
func AssertBlockBody(t *testing.T, expected, actual ast.BlockBody) {
if !assert.IsType(t, expected, actual) {
return
}
switch exp := expected.(type) {
case *ast.CompoundStmt:
AssertCompoundStmt(t, exp, actual.(*ast.CompoundStmt))
case *ast.AssemblerStatement:
AssertAssemblerStatement(t, exp, actual.(*ast.AssemblerStatement))
default:
assert.Fail(t, "unexpected type: %T", exp)
}
}
func AssertExportsStmt(t *testing.T, expected, actual *ast.ExportsStmt) {
if !assert.Equal(t, expected.ExportsItems, actual.ExportsItems) {
AssertExportsItems(t, expected.ExportsItems, actual.ExportsItems)
}
}
func AssertExportsItems(t *testing.T, expected, actual []*ast.ExportsItem) {
if !assert.Equal(t, len(expected), len(actual)) {
return
}
for i, exp := range expected {
act := actual[i]
if !assert.Equal(t, exp, act) {
AssertExportsItem(t, exp, act)
}
}
}
func AssertExportsItem(t *testing.T, expected, actual *ast.ExportsItem) {
if !assert.Equal(t, expected.Ident, actual.Ident) {
AssertIdent(t, expected.Ident, actual.Ident)
}
if !assert.Equal(t, expected.Name, actual.Name) {
AssertConstExpr(t, expected.Name, actual.Name)
}
if !assert.Equal(t, expected.Index, actual.Index) {
AssertConstExpr(t, expected.Index, actual.Index)
}
}
func AssertDeclSections(t *testing.T, expected, actual ast.DeclSections) {
if !assert.Equal(t, len(expected), len(actual)) {
return
}
for i, exp := range expected {
act := actual[i]
if !assert.Equal(t, exp, act) {
AssertDeclSection(t, exp, act)
}
}
}
func AssertDeclSection(t *testing.T, expected, actual ast.DeclSection) {
if !assert.IsType(t, expected, actual) {
return
}
switch exp := expected.(type) {
case *ast.LabelDeclSection:
AssertLabelDeclSection(t, exp, actual.(*ast.LabelDeclSection))
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.FunctionDecl:
AssertFunctionDecl(t, exp, actual.(*ast.FunctionDecl))
default:
assert.Fail(t, "unexpected type: %T", exp)
}
}
func AssertLabelDeclSection(t *testing.T, expected, actual *ast.LabelDeclSection) {
if !assert.Equal(t, expected.LabelId, actual.LabelId) {
AssertIdent(t, expected.LabelId, actual.LabelId)
}
}
func AssertLbelId(t *testing.T, expected, actual *ast.LabelId) {
AssertIdent(t, expected, actual)
}