"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/isstream/test.js" (8 Mar 2017, 6975 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 var tape             = require('tape')
    2   , EE               = require('events').EventEmitter
    3   , util             = require('util')
    4 
    5 
    6   , isStream         = require('./')
    7   , isReadable       = require('./').isReadable
    8   , isWritable       = require('./').isWritable
    9   , isDuplex         = require('./').isDuplex
   10 
   11   , CoreStreams      = require('stream')
   12   , ReadableStream10 = require('./readable-stream-1.0/')
   13   , ReadableStream11 = require('./readable-stream-1.1/')
   14 
   15 
   16 function test (pass, type, stream) {
   17   tape('isStream('  + type + ')', function (t) {
   18     t.plan(1)
   19     t.ok(pass === isStream(stream), type)
   20   })
   21 }
   22 
   23 
   24 function testReadable (pass, type, stream) {
   25   tape('isReadable('  + type + ')', function (t) {
   26     t.plan(1)
   27     t.ok(pass === isReadable(stream), type)
   28   })
   29 }
   30 
   31 
   32 function testWritable (pass, type, stream) {
   33   tape('isWritable('  + type + ')', function (t) {
   34     t.plan(1)
   35     t.ok(pass === isWritable(stream), type)
   36   })
   37 }
   38 
   39 
   40 function testDuplex (pass, type, stream) {
   41   tape('isDuplex('  + type + ')', function (t) {
   42     t.plan(1)
   43     t.ok(pass === isDuplex(stream), type)
   44   })
   45 }
   46 
   47 
   48 [ undefined, null, '', true, false, 0, 1, 1.0, 'string', {}, function foo () {} ].forEach(function (o) {
   49   test(false, 'non-stream / primitive: ' + (JSON.stringify(o) || (o && o.toString()) || o), o)
   50 })
   51 
   52 
   53 test(false, 'fake stream obj', { pipe: function () {} })
   54 
   55 
   56 ;(function () {
   57 
   58   // looks like a stream!
   59 
   60   function Stream () {
   61     EE.call(this)
   62   }
   63   util.inherits(Stream, EE)
   64   Stream.prototype.pipe = function () {}
   65   Stream.Stream = Stream
   66 
   67   test(false, 'fake stream "new Stream()"', new Stream())
   68 
   69 }())
   70 
   71 
   72 test(true, 'CoreStreams.Stream', new (CoreStreams.Stream)())
   73 test(true, 'CoreStreams.Readable', new (CoreStreams.Readable)())
   74 test(true, 'CoreStreams.Writable', new (CoreStreams.Writable)())
   75 test(true, 'CoreStreams.Duplex', new (CoreStreams.Duplex)())
   76 test(true, 'CoreStreams.Transform', new (CoreStreams.Transform)())
   77 test(true, 'CoreStreams.PassThrough', new (CoreStreams.PassThrough)())
   78 
   79 test(true, 'ReadableStream10.Readable', new (ReadableStream10.Readable)())
   80 test(true, 'ReadableStream10.Writable', new (ReadableStream10.Writable)())
   81 test(true, 'ReadableStream10.Duplex', new (ReadableStream10.Duplex)())
   82 test(true, 'ReadableStream10.Transform', new (ReadableStream10.Transform)())
   83 test(true, 'ReadableStream10.PassThrough', new (ReadableStream10.PassThrough)())
   84 
   85 test(true, 'ReadableStream11.Readable', new (ReadableStream11.Readable)())
   86 test(true, 'ReadableStream11.Writable', new (ReadableStream11.Writable)())
   87 test(true, 'ReadableStream11.Duplex', new (ReadableStream11.Duplex)())
   88 test(true, 'ReadableStream11.Transform', new (ReadableStream11.Transform)())
   89 test(true, 'ReadableStream11.PassThrough', new (ReadableStream11.PassThrough)())
   90 
   91 
   92 testReadable(false, 'CoreStreams.Stream', new (CoreStreams.Stream)())
   93 testReadable(true, 'CoreStreams.Readable', new (CoreStreams.Readable)())
   94 testReadable(false, 'CoreStreams.Writable', new (CoreStreams.Writable)())
   95 testReadable(true, 'CoreStreams.Duplex', new (CoreStreams.Duplex)())
   96 testReadable(true, 'CoreStreams.Transform', new (CoreStreams.Transform)())
   97 testReadable(true, 'CoreStreams.PassThrough', new (CoreStreams.PassThrough)())
   98 
   99 testReadable(true, 'ReadableStream10.Readable', new (ReadableStream10.Readable)())
  100 testReadable(false, 'ReadableStream10.Writable', new (ReadableStream10.Writable)())
  101 testReadable(true, 'ReadableStream10.Duplex', new (ReadableStream10.Duplex)())
  102 testReadable(true, 'ReadableStream10.Transform', new (ReadableStream10.Transform)())
  103 testReadable(true, 'ReadableStream10.PassThrough', new (ReadableStream10.PassThrough)())
  104 
  105 testReadable(true, 'ReadableStream11.Readable', new (ReadableStream11.Readable)())
  106 testReadable(false, 'ReadableStream11.Writable', new (ReadableStream11.Writable)())
  107 testReadable(true, 'ReadableStream11.Duplex', new (ReadableStream11.Duplex)())
  108 testReadable(true, 'ReadableStream11.Transform', new (ReadableStream11.Transform)())
  109 testReadable(true, 'ReadableStream11.PassThrough', new (ReadableStream11.PassThrough)())
  110 
  111 
  112 testWritable(false, 'CoreStreams.Stream', new (CoreStreams.Stream)())
  113 testWritable(false, 'CoreStreams.Readable', new (CoreStreams.Readable)())
  114 testWritable(true, 'CoreStreams.Writable', new (CoreStreams.Writable)())
  115 testWritable(true, 'CoreStreams.Duplex', new (CoreStreams.Duplex)())
  116 testWritable(true, 'CoreStreams.Transform', new (CoreStreams.Transform)())
  117 testWritable(true, 'CoreStreams.PassThrough', new (CoreStreams.PassThrough)())
  118 
  119 testWritable(false, 'ReadableStream10.Readable', new (ReadableStream10.Readable)())
  120 testWritable(true, 'ReadableStream10.Writable', new (ReadableStream10.Writable)())
  121 testWritable(true, 'ReadableStream10.Duplex', new (ReadableStream10.Duplex)())
  122 testWritable(true, 'ReadableStream10.Transform', new (ReadableStream10.Transform)())
  123 testWritable(true, 'ReadableStream10.PassThrough', new (ReadableStream10.PassThrough)())
  124 
  125 testWritable(false, 'ReadableStream11.Readable', new (ReadableStream11.Readable)())
  126 testWritable(true, 'ReadableStream11.Writable', new (ReadableStream11.Writable)())
  127 testWritable(true, 'ReadableStream11.Duplex', new (ReadableStream11.Duplex)())
  128 testWritable(true, 'ReadableStream11.Transform', new (ReadableStream11.Transform)())
  129 testWritable(true, 'ReadableStream11.PassThrough', new (ReadableStream11.PassThrough)())
  130 
  131 
  132 testDuplex(false, 'CoreStreams.Stream', new (CoreStreams.Stream)())
  133 testDuplex(false, 'CoreStreams.Readable', new (CoreStreams.Readable)())
  134 testDuplex(false, 'CoreStreams.Writable', new (CoreStreams.Writable)())
  135 testDuplex(true, 'CoreStreams.Duplex', new (CoreStreams.Duplex)())
  136 testDuplex(true, 'CoreStreams.Transform', new (CoreStreams.Transform)())
  137 testDuplex(true, 'CoreStreams.PassThrough', new (CoreStreams.PassThrough)())
  138 
  139 testDuplex(false, 'ReadableStream10.Readable', new (ReadableStream10.Readable)())
  140 testDuplex(false, 'ReadableStream10.Writable', new (ReadableStream10.Writable)())
  141 testDuplex(true, 'ReadableStream10.Duplex', new (ReadableStream10.Duplex)())
  142 testDuplex(true, 'ReadableStream10.Transform', new (ReadableStream10.Transform)())
  143 testDuplex(true, 'ReadableStream10.PassThrough', new (ReadableStream10.PassThrough)())
  144 
  145 testDuplex(false, 'ReadableStream11.Readable', new (ReadableStream11.Readable)())
  146 testDuplex(false, 'ReadableStream11.Writable', new (ReadableStream11.Writable)())
  147 testDuplex(true, 'ReadableStream11.Duplex', new (ReadableStream11.Duplex)())
  148 testDuplex(true, 'ReadableStream11.Transform', new (ReadableStream11.Transform)())
  149 testDuplex(true, 'ReadableStream11.PassThrough', new (ReadableStream11.PassThrough)())
  150 
  151 
  152 ;[ CoreStreams, ReadableStream10, ReadableStream11 ].forEach(function (p) {
  153   [ 'Stream', 'Readable', 'Writable', 'Duplex', 'Transform', 'PassThrough' ].forEach(function (k) {
  154     if (!p[k])
  155       return
  156 
  157     function SubStream () {
  158       p[k].call(this)
  159     }
  160     util.inherits(SubStream, p[k])
  161 
  162     test(true, 'Stream subclass: ' + p.name + '.' + k, new SubStream())
  163 
  164   })
  165 })
  166 
  167 
  168