@@ -171,6 +171,25 @@ describe("errors", function() {
171
171
} ) . should . throw ( ) ;
172
172
fs . readdirSync ( "/test/" ) . should . be . eql ( [ "dir" , "file" ] ) ;
173
173
} ) ;
174
+ it ( "should throw on readlink" , function ( ) {
175
+ var fs = new MemoryFileSystem ( ) ;
176
+ fs . mkdirpSync ( "/test/dir" ) ;
177
+ ( function ( ) {
178
+ fs . readlinkSync ( "/" ) ;
179
+ } ) . should . throw ( ) ;
180
+ ( function ( ) {
181
+ fs . readlinkSync ( "/link" ) ;
182
+ } ) . should . throw ( ) ;
183
+ ( function ( ) {
184
+ fs . readlinkSync ( "/test" ) ;
185
+ } ) . should . throw ( ) ;
186
+ ( function ( ) {
187
+ fs . readlinkSync ( "/test/dir" ) ;
188
+ } ) . should . throw ( ) ;
189
+ ( function ( ) {
190
+ fs . readlinkSync ( "/test/dir/link" ) ;
191
+ } ) . should . throw ( ) ;
192
+ } ) ;
174
193
} ) ;
175
194
describe ( "async" , function ( ) {
176
195
it ( "should be able to use the async versions" , function ( done ) {
@@ -205,18 +224,139 @@ describe("async", function() {
205
224
} ) ;
206
225
} ) ;
207
226
} ) ;
227
+ describe ( "normalize" , function ( ) {
228
+ it ( "should normalize paths" , function ( ) {
229
+ var fs = new MemoryFileSystem ( ) ;
230
+ fs . normalize ( "/a/b/c" ) . should . be . eql ( "/a/b/c" ) ;
231
+ fs . normalize ( "/a//b/c" ) . should . be . eql ( "/a/b/c" ) ;
232
+ fs . normalize ( "/a//b//c" ) . should . be . eql ( "/a/b/c" ) ;
233
+ fs . normalize ( "//a//b//c" ) . should . be . eql ( "/a/b/c" ) ;
234
+ fs . normalize ( "/a/////b/c" ) . should . be . eql ( "/a/b/c" ) ;
235
+ fs . normalize ( "/./a/d///..////b/c" ) . should . be . eql ( "/a/b/c" ) ;
236
+ fs . normalize ( "/.." ) . should . be . eql ( "/" ) ;
237
+ fs . normalize ( "/." ) . should . be . eql ( "/" ) ;
238
+ fs . normalize ( "/.git" ) . should . be . eql ( "/.git" ) ;
239
+ fs . normalize ( "/a/b/c/.git" ) . should . be . eql ( "/a/b/c/.git" ) ;
240
+ fs . normalize ( "/a/b/c/..git" ) . should . be . eql ( "/a/b/c/..git" ) ;
241
+ fs . normalize ( "/a/b/c/.." ) . should . be . eql ( "/a/b" ) ;
242
+ fs . normalize ( "/a/b/c/../.." ) . should . be . eql ( "/a" ) ;
243
+ fs . normalize ( "/a/b/c/../../.." ) . should . be . eql ( "/" ) ;
244
+ fs . normalize ( "C:\\a\\.." ) . should . be . eql ( "C:\\" ) ;
245
+ fs . normalize ( "C:\\a\\b\\.." ) . should . be . eql ( "C:\\a" ) ;
246
+ fs . normalize ( "C:\\a\\b\\\c\\..\\.." ) . should . be . eql ( "C:\\a" ) ;
247
+ fs . normalize ( "C:\\a\\b\\d\\..\\c\\..\\.." ) . should . be . eql ( "C:\\a" ) ;
248
+ fs . normalize ( "C:\\a\\b\\d\\\\.\\\\.\\c\\.\\.." ) . should . be . eql ( "C:\\a\\b\\d" ) ;
249
+ } ) ;
250
+ } ) ;
208
251
describe ( "join" , function ( ) {
209
252
it ( "should join paths" , function ( ) {
210
253
var fs = new MemoryFileSystem ( ) ;
211
254
fs . join ( "/" , "a/b/c" ) . should . be . eql ( "/a/b/c" ) ;
212
255
fs . join ( "/a" , "b/c" ) . should . be . eql ( "/a/b/c" ) ;
213
256
fs . join ( "/a/b" , "c" ) . should . be . eql ( "/a/b/c" ) ;
214
257
fs . join ( "/a/" , "b/c" ) . should . be . eql ( "/a/b/c" ) ;
215
- fs . join ( "/a//" , "b/c" ) . should . be . eql ( "/a// b/c" ) ;
258
+ fs . join ( "/a//" , "b/c" ) . should . be . eql ( "/a/b/c" ) ;
216
259
fs . join ( "a" , "b/c" ) . should . be . eql ( "a/b/c" ) ;
217
260
fs . join ( "a/b" , "c" ) . should . be . eql ( "a/b/c" ) ;
218
- fs . join ( "C:" , "a/b" ) . should . be . eql ( "C:/a/ b" ) ;
219
- fs . join ( "C:\\" , "a/b" ) . should . be . eql ( "C:\\a/ b" ) ;
261
+ fs . join ( "C:" , "a/b" ) . should . be . eql ( "C:\\a\\ b" ) ;
262
+ fs . join ( "C:\\" , "a/b" ) . should . be . eql ( "C:\\a\\ b" ) ;
220
263
fs . join ( "C:\\" , "a\\b" ) . should . be . eql ( "C:\\a\\b" ) ;
221
264
} ) ;
265
+ it ( "should join paths (weird cases)" , function ( ) {
266
+ var fs = new MemoryFileSystem ( ) ;
267
+ fs . join ( "/" , "" ) . should . be . eql ( "/" ) ;
268
+ fs . join ( "/a/b/" , "" ) . should . be . eql ( "/a/b/" ) ;
269
+ fs . join ( "/a/b/c" , "" ) . should . be . eql ( "/a/b/c" ) ;
270
+ fs . join ( "C:" , "" ) . should . be . eql ( "C:" ) ;
271
+ fs . join ( "C:\\a\\b" , "" ) . should . be . eql ( "C:\\a\\b" ) ;
272
+ } ) ;
273
+ it ( "should join paths (absolute request)" , function ( ) {
274
+ var fs = new MemoryFileSystem ( ) ;
275
+ fs . join ( "/a/b/c" , "/d/e/f" ) . should . be . eql ( "/d/e/f" ) ;
276
+ fs . join ( "C:\\a\\b\\c" , "/d/e/f" ) . should . be . eql ( "/d/e/f" ) ;
277
+ fs . join ( "/a/b/c" , "C:\\d\\e\\f" ) . should . be . eql ( "C:\\d\\e\\f" ) ;
278
+ fs . join ( "C:\\a\\b\\c" , "C:\\d\\e\\f" ) . should . be . eql ( "C:\\d\\e\\f" ) ;
279
+ } ) ;
280
+ } ) ;
281
+ describe ( "os" , function ( ) {
282
+ var fileSystem ;
283
+
284
+ beforeEach ( function ( ) {
285
+ fileSystem = new MemoryFileSystem ( {
286
+ "" : true ,
287
+ a : {
288
+ "" : true ,
289
+ index : new Buffer ( "1" ) , // /a/index
290
+ dir : {
291
+ "" : true ,
292
+ index : new Buffer ( "2" ) // /a/dir/index
293
+ }
294
+ } ,
295
+ "C:" : {
296
+ "" : true ,
297
+ a : {
298
+ "" : true ,
299
+ index : new Buffer ( "3" ) , // C:\files\index
300
+ dir : {
301
+ "" : true ,
302
+ index : new Buffer ( "4" ) // C:\files\a\index
303
+ }
304
+ }
305
+ }
306
+ } ) ;
307
+ } ) ;
308
+
309
+ describe ( "unix" , function ( ) {
310
+ it ( "should stat stuff" , function ( ) {
311
+ fileSystem . statSync ( "/a" ) . isDirectory ( ) . should . be . eql ( true ) ;
312
+ fileSystem . statSync ( "/a" ) . isFile ( ) . should . be . eql ( false ) ;
313
+ fileSystem . statSync ( "/a/index" ) . isDirectory ( ) . should . be . eql ( false ) ;
314
+ fileSystem . statSync ( "/a/index" ) . isFile ( ) . should . be . eql ( true ) ;
315
+ fileSystem . statSync ( "/a/dir" ) . isDirectory ( ) . should . be . eql ( true ) ;
316
+ fileSystem . statSync ( "/a/dir" ) . isFile ( ) . should . be . eql ( false ) ;
317
+ fileSystem . statSync ( "/a/dir/index" ) . isDirectory ( ) . should . be . eql ( false ) ;
318
+ fileSystem . statSync ( "/a/dir/index" ) . isFile ( ) . should . be . eql ( true ) ;
319
+ } ) ;
320
+ it ( "should readdir directories" , function ( ) {
321
+ fileSystem . readdirSync ( "/a" ) . should . be . eql ( [ "index" , "dir" ] ) ;
322
+ fileSystem . readdirSync ( "/a/dir" ) . should . be . eql ( [ "index" ] ) ;
323
+ } ) ;
324
+ it ( "should readdir directories" , function ( ) {
325
+ fileSystem . readFileSync ( "/a/index" , "utf-8" ) . should . be . eql ( "1" ) ;
326
+ fileSystem . readFileSync ( "/a/dir/index" , "utf-8" ) . should . be . eql ( "2" ) ;
327
+ } ) ;
328
+ it ( "should also accept multi slashs" , function ( ) {
329
+ fileSystem . statSync ( "/a///dir//index" ) . isFile ( ) . should . be . eql ( true ) ;
330
+ } ) ;
331
+ } ) ;
332
+
333
+ describe ( "windows" , function ( ) {
334
+ it ( "should stat stuff" , function ( ) {
335
+ fileSystem . statSync ( "C:\\a" ) . isDirectory ( ) . should . be . eql ( true ) ;
336
+ fileSystem . statSync ( "C:\\a" ) . isFile ( ) . should . be . eql ( false ) ;
337
+ fileSystem . statSync ( "C:\\a\\index" ) . isDirectory ( ) . should . be . eql ( false ) ;
338
+ fileSystem . statSync ( "C:\\a\\index" ) . isFile ( ) . should . be . eql ( true ) ;
339
+ fileSystem . statSync ( "C:\\a\\dir" ) . isDirectory ( ) . should . be . eql ( true ) ;
340
+ fileSystem . statSync ( "C:\\a\\dir" ) . isFile ( ) . should . be . eql ( false ) ;
341
+ fileSystem . statSync ( "C:\\a\\dir\\index" ) . isDirectory ( ) . should . be . eql ( false ) ;
342
+ fileSystem . statSync ( "C:\\a\\dir\\index" ) . isFile ( ) . should . be . eql ( true ) ;
343
+ } ) ;
344
+ it ( "should readdir directories" , function ( ) {
345
+ fileSystem . readdirSync ( "C:\\a" ) . should . be . eql ( [ "index" , "dir" ] ) ;
346
+ fileSystem . readdirSync ( "C:\\a\\dir" ) . should . be . eql ( [ "index" ] ) ;
347
+ } ) ;
348
+ it ( "should readdir directories" , function ( ) {
349
+ fileSystem . readFileSync ( "C:\\a\\index" , "utf-8" ) . should . be . eql ( "3" ) ;
350
+ fileSystem . readFileSync ( "C:\\a\\dir\\index" , "utf-8" ) . should . be . eql ( "4" ) ;
351
+ } ) ;
352
+ it ( "should also accept multi slashs" , function ( ) {
353
+ fileSystem . statSync ( "C:\\\\a\\\\\\dir\\\\index" ) . isFile ( ) . should . be . eql ( true ) ;
354
+ } ) ;
355
+ it ( "should also accept a normal slash" , function ( ) {
356
+ fileSystem . statSync ( "C:\\a\\dir/index" ) . isFile ( ) . should . be . eql ( true ) ;
357
+ fileSystem . statSync ( "C:\\a\\dir\\index" ) . isFile ( ) . should . be . eql ( true ) ;
358
+ fileSystem . statSync ( "C:\\a/dir/index" ) . isFile ( ) . should . be . eql ( true ) ;
359
+ fileSystem . statSync ( "C:\\a/dir\\index" ) . isFile ( ) . should . be . eql ( true ) ;
360
+ } ) ;
361
+ } ) ;
222
362
} ) ;
0 commit comments