@@ -4,15 +4,17 @@ var assert = require('assert');
4
4
var util = require ( 'util' ) ;
5
5
var repl = require ( 'repl' ) ;
6
6
var referenceErrors = 0 ;
7
- var completionCount = 0 ;
7
+ var expectedReferenceErrors = 0 ;
8
8
9
- function doNotCall ( ) {
10
- assert ( false ) ;
9
+ function getDoNotCallFunction ( ) {
10
+ expectedReferenceErrors += 1 ;
11
+ return function ( ) {
12
+ assert ( false ) ;
13
+ } ;
11
14
}
12
15
13
16
process . on ( 'exit' , function ( ) {
14
- assert . strictEqual ( referenceErrors , 6 ) ;
15
- assert . strictEqual ( completionCount , 12 ) ;
17
+ assert . strictEqual ( referenceErrors , expectedReferenceErrors ) ;
16
18
} ) ;
17
19
18
20
// A stream to push an array into a REPL
@@ -51,19 +53,17 @@ putIn.run([
51
53
'var inner = {' ,
52
54
'one:1'
53
55
] ) ;
54
- testMe . complete ( 'inner.o' , doNotCall ) ;
56
+ testMe . complete ( 'inner.o' , getDoNotCallFunction ( ) ) ;
55
57
56
- testMe . complete ( 'console.lo' , function ( error , data ) {
57
- completionCount ++ ;
58
+ testMe . complete ( 'console.lo' , common . mustCall ( function ( error , data ) {
58
59
assert . deepEqual ( data , [ [ 'console.log' ] , 'console.lo' ] ) ;
59
- } ) ;
60
+ } ) ) ;
60
61
61
62
// Tab Complete will return globaly scoped variables
62
63
putIn . run ( [ '};' ] ) ;
63
- testMe . complete ( 'inner.o' , function ( error , data ) {
64
- completionCount ++ ;
64
+ testMe . complete ( 'inner.o' , common . mustCall ( function ( error , data ) {
65
65
assert . deepEqual ( data , works ) ;
66
- } ) ;
66
+ } ) ) ;
67
67
68
68
putIn . run ( [ '.clear' ] ) ;
69
69
@@ -73,7 +73,7 @@ putIn.run([
73
73
'?' ,
74
74
'{one: 1} : '
75
75
] ) ;
76
- testMe . complete ( 'inner.o' , doNotCall ) ;
76
+ testMe . complete ( 'inner.o' , getDoNotCallFunction ( ) ) ;
77
77
78
78
putIn . run ( [ '.clear' ] ) ;
79
79
@@ -82,15 +82,14 @@ putIn.run([
82
82
'var top = function() {' ,
83
83
'var inner = {one:1};'
84
84
] ) ;
85
- testMe . complete ( 'inner.o' , function ( error , data ) {
86
- completionCount ++ ;
85
+ testMe . complete ( 'inner.o' , common . mustCall ( function ( error , data ) {
87
86
assert . deepEqual ( data , works ) ;
88
- } ) ;
87
+ } ) ) ;
89
88
90
89
// When you close the function scope tab complete will not return the
91
90
// locally scoped variable
92
91
putIn . run ( [ '};' ] ) ;
93
- testMe . complete ( 'inner.o' , doNotCall ) ;
92
+ testMe . complete ( 'inner.o' , getDoNotCallFunction ( ) ) ;
94
93
95
94
putIn . run ( [ '.clear' ] ) ;
96
95
@@ -101,10 +100,9 @@ putIn.run([
101
100
' one:1' ,
102
101
'};'
103
102
] ) ;
104
- testMe . complete ( 'inner.o' , function ( error , data ) {
105
- completionCount ++ ;
103
+ testMe . complete ( 'inner.o' , common . mustCall ( function ( error , data ) {
106
104
assert . deepEqual ( data , works ) ;
107
- } ) ;
105
+ } ) ) ;
108
106
109
107
putIn . run ( [ '.clear' ] ) ;
110
108
@@ -116,10 +114,9 @@ putIn.run([
116
114
' one:1' ,
117
115
'};'
118
116
] ) ;
119
- testMe . complete ( 'inner.o' , function ( error , data ) {
120
- completionCount ++ ;
117
+ testMe . complete ( 'inner.o' , common . mustCall ( function ( error , data ) {
121
118
assert . deepEqual ( data , works ) ;
122
- } ) ;
119
+ } ) ) ;
123
120
124
121
putIn . run ( [ '.clear' ] ) ;
125
122
@@ -132,10 +129,9 @@ putIn.run([
132
129
' one:1' ,
133
130
'};'
134
131
] ) ;
135
- testMe . complete ( 'inner.o' , function ( error , data ) {
136
- completionCount ++ ;
132
+ testMe . complete ( 'inner.o' , common . mustCall ( function ( error , data ) {
137
133
assert . deepEqual ( data , works ) ;
138
- } ) ;
134
+ } ) ) ;
139
135
140
136
putIn . run ( [ '.clear' ] ) ;
141
137
@@ -148,7 +144,7 @@ putIn.run([
148
144
' one:1' ,
149
145
'};'
150
146
] ) ;
151
- testMe . complete ( 'inner.o' , doNotCall ) ;
147
+ testMe . complete ( 'inner.o' , getDoNotCallFunction ( ) ) ;
152
148
153
149
putIn . run ( [ '.clear' ] ) ;
154
150
@@ -161,7 +157,7 @@ putIn.run([
161
157
' one:1' ,
162
158
'};'
163
159
] ) ;
164
- testMe . complete ( 'inner.o' , doNotCall ) ;
160
+ testMe . complete ( 'inner.o' , getDoNotCallFunction ( ) ) ;
165
161
166
162
putIn . run ( [ '.clear' ] ) ;
167
163
@@ -175,18 +171,17 @@ putIn.run([
175
171
' one:1' ,
176
172
'};'
177
173
] ) ;
178
- testMe . complete ( 'inner.o' , doNotCall ) ;
174
+ testMe . complete ( 'inner.o' , getDoNotCallFunction ( ) ) ;
179
175
180
176
putIn . run ( [ '.clear' ] ) ;
181
177
182
178
// make sure tab completion works on non-Objects
183
179
putIn . run ( [
184
180
'var str = "test";'
185
181
] ) ;
186
- testMe . complete ( 'str.len' , function ( error , data ) {
187
- completionCount ++ ;
182
+ testMe . complete ( 'str.len' , common . mustCall ( function ( error , data ) {
188
183
assert . deepEqual ( data , [ [ 'str.length' ] , 'str.len' ] ) ;
189
- } ) ;
184
+ } ) ) ;
190
185
191
186
putIn . run ( [ '.clear' ] ) ;
192
187
@@ -195,32 +190,28 @@ var spaceTimeout = setTimeout(function() {
195
190
throw new Error ( 'timeout' ) ;
196
191
} , 1000 ) ;
197
192
198
- testMe . complete ( ' ' , function ( error , data ) {
199
- completionCount ++ ;
193
+ testMe . complete ( ' ' , common . mustCall ( function ( error , data ) {
200
194
assert . deepEqual ( data , [ [ ] , undefined ] ) ;
201
195
clearTimeout ( spaceTimeout ) ;
202
- } ) ;
196
+ } ) ) ;
203
197
204
198
// tab completion should pick up the global "toString" object, and
205
199
// any other properties up the "global" object's prototype chain
206
- testMe . complete ( 'toSt' , function ( error , data ) {
207
- completionCount ++ ;
200
+ testMe . complete ( 'toSt' , common . mustCall ( function ( error , data ) {
208
201
assert . deepEqual ( data , [ [ 'toString' ] , 'toSt' ] ) ;
209
- } ) ;
202
+ } ) ) ;
210
203
211
204
// Tab complete provides built in libs for require()
212
205
putIn . run ( [ '.clear' ] ) ;
213
206
214
- testMe . complete ( 'require(\'' , function ( error , data ) {
215
- completionCount ++ ;
207
+ testMe . complete ( 'require(\'' , common . mustCall ( function ( error , data ) {
216
208
assert . strictEqual ( error , null ) ;
217
209
repl . _builtinLibs . forEach ( function ( lib ) {
218
210
assert . notStrictEqual ( data [ 0 ] . indexOf ( lib ) , - 1 , lib + ' not found' ) ;
219
211
} ) ;
220
- } ) ;
212
+ } ) ) ;
221
213
222
- testMe . complete ( 'require(\'n' , function ( error , data ) {
223
- completionCount ++ ;
214
+ testMe . complete ( 'require(\'n' , common . mustCall ( function ( error , data ) {
224
215
assert . strictEqual ( error , null ) ;
225
216
assert . strictEqual ( data . length , 2 ) ;
226
217
assert . strictEqual ( data [ 1 ] , 'n' ) ;
@@ -230,15 +221,14 @@ testMe.complete('require(\'n', function(error, data) {
230
221
if ( completion )
231
222
assert ( / ^ n / . test ( completion ) ) ;
232
223
} ) ;
233
- } ) ;
224
+ } ) ) ;
234
225
235
226
// Make sure tab completion works on context properties
236
227
putIn . run ( [ '.clear' ] ) ;
237
228
238
229
putIn . run ( [
239
230
'var custom = "test";'
240
231
] ) ;
241
- testMe . complete ( 'cus' , function ( error , data ) {
242
- completionCount ++ ;
232
+ testMe . complete ( 'cus' , common . mustCall ( function ( error , data ) {
243
233
assert . deepEqual ( data , [ [ 'custom' ] , 'cus' ] ) ;
244
- } ) ;
234
+ } ) ) ;
0 commit comments