2
2
var common = require ( '../common' ) ;
3
3
var assert = require ( 'assert' ) ;
4
4
var util = require ( 'util' ) ;
5
-
6
5
var repl = require ( 'repl' ) ;
6
+ var referenceErrors = 0 ;
7
+ var completionCount = 0 ;
8
+
9
+ function doNotCall ( ) {
10
+ assert ( false ) ;
11
+ }
12
+
13
+ process . on ( 'exit' , function ( ) {
14
+ assert . strictEqual ( referenceErrors , 6 ) ;
15
+ assert . strictEqual ( completionCount , 12 ) ;
16
+ } ) ;
7
17
8
18
// A stream to push an array into a REPL
9
19
function ArrayStream ( ) {
@@ -21,27 +31,37 @@ ArrayStream.prototype.resume = function() {};
21
31
ArrayStream . prototype . write = function ( ) { } ;
22
32
23
33
var works = [ [ 'inner.one' ] , 'inner.o' ] ;
24
- var doesNotBreak = [ [ ] , 'inner.o' ] ;
25
-
26
34
var putIn = new ArrayStream ( ) ;
27
35
var testMe = repl . start ( '' , putIn ) ;
28
36
37
+ // Some errors are passed to the domain, but do not callback
38
+ testMe . _domain . on ( 'error' , function ( err ) {
39
+ // Errors come from another context, so instanceof doesn't work
40
+ var str = err . toString ( ) ;
41
+
42
+ if ( / ^ R e f e r e n c e E r r o r : / . test ( str ) )
43
+ referenceErrors ++ ;
44
+ else
45
+ assert ( false ) ;
46
+ } ) ;
47
+
29
48
// Tab Complete will not break in an object literal
30
49
putIn . run ( [ '.clear' ] ) ;
31
50
putIn . run ( [
32
51
'var inner = {' ,
33
52
'one:1'
34
53
] ) ;
35
- testMe . complete ( 'inner.o' , function ( error , data ) {
36
- assert . deepEqual ( data , doesNotBreak ) ;
37
- } ) ;
54
+ testMe . complete ( 'inner.o' , doNotCall ) ;
55
+
38
56
testMe . complete ( 'console.lo' , function ( error , data ) {
57
+ completionCount ++ ;
39
58
assert . deepEqual ( data , [ [ 'console.log' ] , 'console.lo' ] ) ;
40
59
} ) ;
41
60
42
61
// Tab Complete will return globaly scoped variables
43
62
putIn . run ( [ '};' ] ) ;
44
63
testMe . complete ( 'inner.o' , function ( error , data ) {
64
+ completionCount ++ ;
45
65
assert . deepEqual ( data , works ) ;
46
66
} ) ;
47
67
@@ -53,9 +73,7 @@ putIn.run([
53
73
'?' ,
54
74
'{one: 1} : '
55
75
] ) ;
56
- testMe . complete ( 'inner.o' , function ( error , data ) {
57
- assert . deepEqual ( data , doesNotBreak ) ;
58
- } ) ;
76
+ testMe . complete ( 'inner.o' , doNotCall ) ;
59
77
60
78
putIn . run ( [ '.clear' ] ) ;
61
79
@@ -65,15 +83,14 @@ putIn.run([
65
83
'var inner = {one:1};'
66
84
] ) ;
67
85
testMe . complete ( 'inner.o' , function ( error , data ) {
86
+ completionCount ++ ;
68
87
assert . deepEqual ( data , works ) ;
69
88
} ) ;
70
89
71
90
// When you close the function scope tab complete will not return the
72
91
// locally scoped variable
73
92
putIn . run ( [ '};' ] ) ;
74
- testMe . complete ( 'inner.o' , function ( error , data ) {
75
- assert . deepEqual ( data , doesNotBreak ) ;
76
- } ) ;
93
+ testMe . complete ( 'inner.o' , doNotCall ) ;
77
94
78
95
putIn . run ( [ '.clear' ] ) ;
79
96
@@ -85,6 +102,7 @@ putIn.run([
85
102
'};'
86
103
] ) ;
87
104
testMe . complete ( 'inner.o' , function ( error , data ) {
105
+ completionCount ++ ;
88
106
assert . deepEqual ( data , works ) ;
89
107
} ) ;
90
108
@@ -99,6 +117,7 @@ putIn.run([
99
117
'};'
100
118
] ) ;
101
119
testMe . complete ( 'inner.o' , function ( error , data ) {
120
+ completionCount ++ ;
102
121
assert . deepEqual ( data , works ) ;
103
122
} ) ;
104
123
@@ -114,12 +133,12 @@ putIn.run([
114
133
'};'
115
134
] ) ;
116
135
testMe . complete ( 'inner.o' , function ( error , data ) {
136
+ completionCount ++ ;
117
137
assert . deepEqual ( data , works ) ;
118
138
} ) ;
119
139
120
140
putIn . run ( [ '.clear' ] ) ;
121
141
122
- // currently does not work, but should not break note the inner function
123
142
// def has the params and { on a separate line
124
143
putIn . run ( [
125
144
'var top = function() {' ,
@@ -129,9 +148,7 @@ putIn.run([
129
148
' one:1' ,
130
149
'};'
131
150
] ) ;
132
- testMe . complete ( 'inner.o' , function ( error , data ) {
133
- assert . deepEqual ( data , doesNotBreak ) ;
134
- } ) ;
151
+ testMe . complete ( 'inner.o' , doNotCall ) ;
135
152
136
153
putIn . run ( [ '.clear' ] ) ;
137
154
@@ -144,9 +161,7 @@ putIn.run([
144
161
' one:1' ,
145
162
'};'
146
163
] ) ;
147
- testMe . complete ( 'inner.o' , function ( error , data ) {
148
- assert . deepEqual ( data , doesNotBreak ) ;
149
- } ) ;
164
+ testMe . complete ( 'inner.o' , doNotCall ) ;
150
165
151
166
putIn . run ( [ '.clear' ] ) ;
152
167
@@ -160,9 +175,7 @@ putIn.run([
160
175
' one:1' ,
161
176
'};'
162
177
] ) ;
163
- testMe . complete ( 'inner.o' , function ( error , data ) {
164
- assert . deepEqual ( data , doesNotBreak ) ;
165
- } ) ;
178
+ testMe . complete ( 'inner.o' , doNotCall ) ;
166
179
167
180
putIn . run ( [ '.clear' ] ) ;
168
181
@@ -171,6 +184,7 @@ putIn.run([
171
184
'var str = "test";'
172
185
] ) ;
173
186
testMe . complete ( 'str.len' , function ( error , data ) {
187
+ completionCount ++ ;
174
188
assert . deepEqual ( data , [ [ 'str.length' ] , 'str.len' ] ) ;
175
189
} ) ;
176
190
@@ -182,29 +196,40 @@ var spaceTimeout = setTimeout(function() {
182
196
} , 1000 ) ;
183
197
184
198
testMe . complete ( ' ' , function ( error , data ) {
199
+ completionCount ++ ;
185
200
assert . deepEqual ( data , [ [ ] , undefined ] ) ;
186
201
clearTimeout ( spaceTimeout ) ;
187
202
} ) ;
188
203
189
204
// tab completion should pick up the global "toString" object, and
190
205
// any other properties up the "global" object's prototype chain
191
206
testMe . complete ( 'toSt' , function ( error , data ) {
207
+ completionCount ++ ;
192
208
assert . deepEqual ( data , [ [ 'toString' ] , 'toSt' ] ) ;
193
209
} ) ;
194
210
195
211
// Tab complete provides built in libs for require()
196
212
putIn . run ( [ '.clear' ] ) ;
197
213
198
214
testMe . complete ( 'require(\'' , function ( error , data ) {
215
+ completionCount ++ ;
199
216
assert . strictEqual ( error , null ) ;
200
217
repl . _builtinLibs . forEach ( function ( lib ) {
201
218
assert . notStrictEqual ( data [ 0 ] . indexOf ( lib ) , - 1 , lib + ' not found' ) ;
202
219
} ) ;
203
220
} ) ;
204
221
205
222
testMe . complete ( 'require(\'n' , function ( error , data ) {
223
+ completionCount ++ ;
206
224
assert . strictEqual ( error , null ) ;
207
- assert . deepEqual ( data , [ [ 'net' ] , 'n' ] ) ;
225
+ assert . strictEqual ( data . length , 2 ) ;
226
+ assert . strictEqual ( data [ 1 ] , 'n' ) ;
227
+ assert . notStrictEqual ( data [ 0 ] . indexOf ( 'net' ) , - 1 ) ;
228
+ // It's possible to pick up non-core modules too
229
+ data [ 0 ] . forEach ( function ( completion ) {
230
+ if ( completion )
231
+ assert ( / ^ n / . test ( completion ) ) ;
232
+ } ) ;
208
233
} ) ;
209
234
210
235
// Make sure tab completion works on context properties
@@ -214,5 +239,6 @@ putIn.run([
214
239
'var custom = "test";'
215
240
] ) ;
216
241
testMe . complete ( 'cus' , function ( error , data ) {
242
+ completionCount ++ ;
217
243
assert . deepEqual ( data , [ [ 'custom' ] , 'cus' ] ) ;
218
244
} ) ;
0 commit comments