-
Notifications
You must be signed in to change notification settings - Fork 1
/
assert_type_simple.go
108 lines (98 loc) · 2.74 KB
/
assert_type_simple.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
package asttest
import (
"testing"
"github.com/akm/tparser/ast"
"github.com/stretchr/testify/assert"
)
func AssertSimpleType(t *testing.T, expected, actual ast.SimpleType) {
if !assert.IsType(t, expected, actual) {
return
}
switch exp := expected.(type) {
case ast.RealType:
AssertRealType(t, exp, actual.(ast.RealType))
case ast.OrdinalType:
AssertOrdinalType(t, exp, actual.(ast.OrdinalType))
default:
assert.Fail(t, "unexpected type: %T", exp)
}
}
func AssertRealType(t *testing.T, expected, actual ast.RealType) {
if !assert.IsType(t, expected, actual) {
return
}
switch exp := expected.(type) {
case *ast.TypeEmbedded:
AssertTypeEmbedded(t, exp, actual.(*ast.TypeEmbedded))
case *ast.TypeId:
AssertTypeId(t, exp, actual.(*ast.TypeId))
default:
assert.Fail(t, "unexpected type: %T", exp)
}
}
func AssertOrdinalTypes(t *testing.T, expected, actual []ast.OrdinalType) {
if !assert.Equal(t, len(expected), len(actual)) {
return
}
for i, exp := range expected {
act := actual[i]
if !assert.Equal(t, exp, act) {
AssertOrdinalType(t, exp, act)
}
}
}
func AssertOrdinalType(t *testing.T, expected, actual ast.OrdinalType) {
if !assert.IsType(t, expected, actual) {
return
}
switch exp := expected.(type) {
case ast.OrdIdent:
AssertOrdIdent(t, exp, actual.(ast.OrdIdent))
case ast.EnumeratedType:
AssertEnumeratedType(t, exp, actual.(ast.EnumeratedType))
case *ast.SubrangeType:
AssertSubrangeType(t, exp, actual.(*ast.SubrangeType))
default:
assert.Fail(t, "unexpected type: %T", exp)
}
}
func AssertOrdIdent(t *testing.T, expected, actual ast.OrdIdent) {
if !assert.IsType(t, expected, actual) {
return
}
switch exp := expected.(type) {
case *ast.TypeEmbedded:
AssertTypeEmbedded(t, exp, actual.(*ast.TypeEmbedded))
case *ast.TypeId:
AssertTypeId(t, exp, actual.(*ast.TypeId))
default:
assert.Fail(t, "unexpected type: %T", exp)
}
}
func AssertEnumeratedType(t *testing.T, expected, actual ast.EnumeratedType) {
if !assert.Equal(t, len(expected), len(actual)) {
return
}
for i, exp := range expected {
act := actual[i]
if !assert.Equal(t, exp, act) {
AssertEnumeratedTypeElement(t, exp, act)
}
}
}
func AssertEnumeratedTypeElement(t *testing.T, expected, actual *ast.EnumeratedTypeElement) {
if !assert.Equal(t, expected.Ident, actual.Ident) {
AssertIdent(t, expected.Ident, actual.Ident)
}
if !assert.Equal(t, expected.ConstExpr, actual.ConstExpr) {
AssertConstExpr(t, expected.ConstExpr, actual.ConstExpr)
}
}
func AssertSubrangeType(t *testing.T, expected, actual *ast.SubrangeType) {
if !assert.Equal(t, expected.Low, actual.Low) {
AssertConstExpr(t, expected.Low, actual.Low)
}
if !assert.Equal(t, expected.High, actual.High) {
AssertConstExpr(t, expected.High, actual.High)
}
}