@@ -11,35 +11,33 @@ function toComment(fn, filename) {
11
11
} ) [ 0 ] ;
12
12
}
13
13
14
+ function toDoctrineType ( flowType ) {
15
+ return flowDoctrine ( toComment (
16
+ '/** add */function add(a: ' + flowType + ' ) { }'
17
+ ) . context . ast . node . params [ 0 ] . typeAnnotation . typeAnnotation ) ;
18
+ }
19
+
14
20
/* eslint-disable */
15
21
test ( 'flowDoctrine' , function ( t ) {
16
22
17
- t . deepEqual ( flowDoctrine ( toComment (
18
- "/** add */function add(a: number) { }"
19
- ) . context . ast . node . params [ 0 ] . typeAnnotation . typeAnnotation ) ,
23
+ t . deepEqual ( toDoctrineType ( 'number' ) ,
20
24
{
21
25
type : 'NameExpression' ,
22
26
name : 'number'
23
27
} , 'number' ) ;
24
28
25
- t . deepEqual ( flowDoctrine ( toComment (
26
- "/** add */function add(a: string) { }"
27
- ) . context . ast . node . params [ 0 ] . typeAnnotation . typeAnnotation ) ,
29
+ t . deepEqual ( toDoctrineType ( 'string' ) ,
28
30
{
29
31
type : 'NameExpression' ,
30
32
name : 'string'
31
33
} , 'string' ) ;
32
34
33
- t . deepEqual ( flowDoctrine ( toComment (
34
- "/** add */function add(a: any) { }"
35
- ) . context . ast . node . params [ 0 ] . typeAnnotation . typeAnnotation ) ,
35
+ t . deepEqual ( toDoctrineType ( 'any' ) ,
36
36
{
37
37
type : 'AllLiteral'
38
38
} , 'all' ) ;
39
39
40
- t . deepEqual ( flowDoctrine ( toComment (
41
- "/** add */function add(a: ?number) { }"
42
- ) . context . ast . node . params [ 0 ] . typeAnnotation . typeAnnotation ) ,
40
+ t . deepEqual ( toDoctrineType ( '?number' ) ,
43
41
{
44
42
type : 'NullableType' ,
45
43
expression : {
@@ -48,9 +46,7 @@ test('flowDoctrine', function (t) {
48
46
}
49
47
} , 'nullable' ) ;
50
48
51
- t . deepEqual ( flowDoctrine ( toComment (
52
- "/** add */function add(a: number | string) { }"
53
- ) . context . ast . node . params [ 0 ] . typeAnnotation . typeAnnotation ) ,
49
+ t . deepEqual ( toDoctrineType ( 'number | string' ) ,
54
50
{
55
51
type : 'UnionType' ,
56
52
elements : [
@@ -65,25 +61,19 @@ test('flowDoctrine', function (t) {
65
61
]
66
62
} , 'union' ) ;
67
63
68
- t . deepEqual ( flowDoctrine ( toComment (
69
- "/** add */function add(a: Object) { }"
70
- ) . context . ast . node . params [ 0 ] . typeAnnotation . typeAnnotation ) ,
64
+ t . deepEqual ( toDoctrineType ( 'Object' ) ,
71
65
{
72
66
type : 'NameExpression' ,
73
67
name : 'Object'
74
68
} , 'object' ) ;
75
69
76
- t . deepEqual ( flowDoctrine ( toComment (
77
- "/** add */function add(a: Array) { }"
78
- ) . context . ast . node . params [ 0 ] . typeAnnotation . typeAnnotation ) ,
70
+ t . deepEqual ( toDoctrineType ( 'Array' ) ,
79
71
{
80
72
type : 'NameExpression' ,
81
73
name : 'Array'
82
74
} , 'array' ) ;
83
75
84
- t . deepEqual ( flowDoctrine ( toComment (
85
- "/** add */function add(a: Array<number>) { }"
86
- ) . context . ast . node . params [ 0 ] . typeAnnotation . typeAnnotation ) ,
76
+ t . deepEqual ( toDoctrineType ( 'Array<number>' ) ,
87
77
{
88
78
type : 'TypeApplication' ,
89
79
expression : {
@@ -96,46 +86,89 @@ test('flowDoctrine', function (t) {
96
86
} ]
97
87
} , 'Array<number>' ) ;
98
88
99
- t . deepEqual ( flowDoctrine ( toComment (
100
- "/** add */function add(a: boolean) { }"
101
- ) . context . ast . node . params [ 0 ] . typeAnnotation . typeAnnotation ) ,
89
+ t . deepEqual ( toDoctrineType ( 'number[]' ) ,
90
+ {
91
+ type : 'TypeApplication' ,
92
+ expression : {
93
+ type : 'NameExpression' ,
94
+ name : 'Array'
95
+ } ,
96
+ applications : [ {
97
+ type : 'NameExpression' ,
98
+ name : 'number'
99
+ } ]
100
+ } , 'number[]' ) ;
101
+
102
+ t . deepEqual ( toDoctrineType ( '[]' ) ,
103
+ {
104
+ type : 'ArrayType' ,
105
+ elements : [ ]
106
+ } , '[]' ) ;
107
+
108
+ t . deepEqual ( toDoctrineType ( '[number]' ) ,
109
+ {
110
+ type : 'ArrayType' ,
111
+ elements : [
112
+ {
113
+ type : 'NameExpression' ,
114
+ name : 'number'
115
+ }
116
+ ]
117
+ } , '[number]' ) ;
118
+
119
+ t . deepEqual ( toDoctrineType ( '[string, boolean]' ) ,
120
+ {
121
+ type : 'ArrayType' ,
122
+ elements : [
123
+ {
124
+ type : 'NameExpression' ,
125
+ name : 'string'
126
+ } ,
127
+ {
128
+ type : 'NameExpression' ,
129
+ name : 'boolean'
130
+ }
131
+ ]
132
+ } , '[string, boolean]' ) ;
133
+
134
+
135
+ t . deepEqual ( toDoctrineType ( 'boolean' ) ,
102
136
{
103
137
type : 'NameExpression' ,
104
138
name : 'boolean'
105
139
} , 'boolean' ) ;
106
140
107
- t . deepEqual ( flowDoctrine ( toComment (
108
- "/** add */function add(a: undefined) { }"
109
- ) . context . ast . node . params [ 0 ] . typeAnnotation . typeAnnotation ) ,
141
+ t . deepEqual ( toDoctrineType ( 'undefined' ) ,
110
142
{
111
143
type : 'NameExpression' ,
112
144
name : 'undefined'
113
145
} , 'undefined' ) ;
114
146
115
- t . deepEqual ( flowDoctrine ( toComment (
116
- "/** add */function add(a: \"value\") { }"
117
- ) . context . ast . node . params [ 0 ] . typeAnnotation . typeAnnotation ) ,
147
+ t . deepEqual ( toDoctrineType ( '"value"' ) ,
118
148
{
119
149
type : 'StringLiteral' ,
120
150
name : 'value'
121
151
} , 'StringLiteral' ) ;
122
152
123
- t . deepEqual ( flowDoctrine ( toComment (
124
- "/** add */function add(a: 1) { }"
125
- ) . context . ast . node . params [ 0 ] . typeAnnotation . typeAnnotation ) ,
153
+ t . deepEqual ( toDoctrineType ( '1' ) ,
126
154
{
127
155
type : 'NumberLiteral' ,
128
156
name : '1'
129
157
} , 'NumberLiteral' ) ;
130
158
131
- t . deepEqual ( flowDoctrine ( toComment (
132
- "/** add */function add(a: true) { }"
133
- ) . context . ast . node . params [ 0 ] . typeAnnotation . typeAnnotation ) ,
159
+ t . deepEqual ( toDoctrineType ( 'true' ) ,
134
160
{
135
161
type : 'BooleanLiteral' ,
136
162
name : true
137
163
} , 'BooleanLiteral' ) ;
138
164
165
+ t . deepEqual ( toDoctrineType ( 'true' ) ,
166
+ {
167
+ type : 'BooleanLiteral' ,
168
+ name : true
169
+ } , 'BooleanLiteral' ) ;
170
+
171
+
139
172
t . end ( ) ;
140
173
} ) ;
141
174
/* eslint-enable */
0 commit comments