source: trip-planner-front/node_modules/isstream/test.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 6.8 KB
Line 
1var 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
16function 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
24function 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
32function 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
40function 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
53test(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
72test(true, 'CoreStreams.Stream', new (CoreStreams.Stream)())
73test(true, 'CoreStreams.Readable', new (CoreStreams.Readable)())
74test(true, 'CoreStreams.Writable', new (CoreStreams.Writable)())
75test(true, 'CoreStreams.Duplex', new (CoreStreams.Duplex)())
76test(true, 'CoreStreams.Transform', new (CoreStreams.Transform)())
77test(true, 'CoreStreams.PassThrough', new (CoreStreams.PassThrough)())
78
79test(true, 'ReadableStream10.Readable', new (ReadableStream10.Readable)())
80test(true, 'ReadableStream10.Writable', new (ReadableStream10.Writable)())
81test(true, 'ReadableStream10.Duplex', new (ReadableStream10.Duplex)())
82test(true, 'ReadableStream10.Transform', new (ReadableStream10.Transform)())
83test(true, 'ReadableStream10.PassThrough', new (ReadableStream10.PassThrough)())
84
85test(true, 'ReadableStream11.Readable', new (ReadableStream11.Readable)())
86test(true, 'ReadableStream11.Writable', new (ReadableStream11.Writable)())
87test(true, 'ReadableStream11.Duplex', new (ReadableStream11.Duplex)())
88test(true, 'ReadableStream11.Transform', new (ReadableStream11.Transform)())
89test(true, 'ReadableStream11.PassThrough', new (ReadableStream11.PassThrough)())
90
91
92testReadable(false, 'CoreStreams.Stream', new (CoreStreams.Stream)())
93testReadable(true, 'CoreStreams.Readable', new (CoreStreams.Readable)())
94testReadable(false, 'CoreStreams.Writable', new (CoreStreams.Writable)())
95testReadable(true, 'CoreStreams.Duplex', new (CoreStreams.Duplex)())
96testReadable(true, 'CoreStreams.Transform', new (CoreStreams.Transform)())
97testReadable(true, 'CoreStreams.PassThrough', new (CoreStreams.PassThrough)())
98
99testReadable(true, 'ReadableStream10.Readable', new (ReadableStream10.Readable)())
100testReadable(false, 'ReadableStream10.Writable', new (ReadableStream10.Writable)())
101testReadable(true, 'ReadableStream10.Duplex', new (ReadableStream10.Duplex)())
102testReadable(true, 'ReadableStream10.Transform', new (ReadableStream10.Transform)())
103testReadable(true, 'ReadableStream10.PassThrough', new (ReadableStream10.PassThrough)())
104
105testReadable(true, 'ReadableStream11.Readable', new (ReadableStream11.Readable)())
106testReadable(false, 'ReadableStream11.Writable', new (ReadableStream11.Writable)())
107testReadable(true, 'ReadableStream11.Duplex', new (ReadableStream11.Duplex)())
108testReadable(true, 'ReadableStream11.Transform', new (ReadableStream11.Transform)())
109testReadable(true, 'ReadableStream11.PassThrough', new (ReadableStream11.PassThrough)())
110
111
112testWritable(false, 'CoreStreams.Stream', new (CoreStreams.Stream)())
113testWritable(false, 'CoreStreams.Readable', new (CoreStreams.Readable)())
114testWritable(true, 'CoreStreams.Writable', new (CoreStreams.Writable)())
115testWritable(true, 'CoreStreams.Duplex', new (CoreStreams.Duplex)())
116testWritable(true, 'CoreStreams.Transform', new (CoreStreams.Transform)())
117testWritable(true, 'CoreStreams.PassThrough', new (CoreStreams.PassThrough)())
118
119testWritable(false, 'ReadableStream10.Readable', new (ReadableStream10.Readable)())
120testWritable(true, 'ReadableStream10.Writable', new (ReadableStream10.Writable)())
121testWritable(true, 'ReadableStream10.Duplex', new (ReadableStream10.Duplex)())
122testWritable(true, 'ReadableStream10.Transform', new (ReadableStream10.Transform)())
123testWritable(true, 'ReadableStream10.PassThrough', new (ReadableStream10.PassThrough)())
124
125testWritable(false, 'ReadableStream11.Readable', new (ReadableStream11.Readable)())
126testWritable(true, 'ReadableStream11.Writable', new (ReadableStream11.Writable)())
127testWritable(true, 'ReadableStream11.Duplex', new (ReadableStream11.Duplex)())
128testWritable(true, 'ReadableStream11.Transform', new (ReadableStream11.Transform)())
129testWritable(true, 'ReadableStream11.PassThrough', new (ReadableStream11.PassThrough)())
130
131
132testDuplex(false, 'CoreStreams.Stream', new (CoreStreams.Stream)())
133testDuplex(false, 'CoreStreams.Readable', new (CoreStreams.Readable)())
134testDuplex(false, 'CoreStreams.Writable', new (CoreStreams.Writable)())
135testDuplex(true, 'CoreStreams.Duplex', new (CoreStreams.Duplex)())
136testDuplex(true, 'CoreStreams.Transform', new (CoreStreams.Transform)())
137testDuplex(true, 'CoreStreams.PassThrough', new (CoreStreams.PassThrough)())
138
139testDuplex(false, 'ReadableStream10.Readable', new (ReadableStream10.Readable)())
140testDuplex(false, 'ReadableStream10.Writable', new (ReadableStream10.Writable)())
141testDuplex(true, 'ReadableStream10.Duplex', new (ReadableStream10.Duplex)())
142testDuplex(true, 'ReadableStream10.Transform', new (ReadableStream10.Transform)())
143testDuplex(true, 'ReadableStream10.PassThrough', new (ReadableStream10.PassThrough)())
144
145testDuplex(false, 'ReadableStream11.Readable', new (ReadableStream11.Readable)())
146testDuplex(false, 'ReadableStream11.Writable', new (ReadableStream11.Writable)())
147testDuplex(true, 'ReadableStream11.Duplex', new (ReadableStream11.Duplex)())
148testDuplex(true, 'ReadableStream11.Transform', new (ReadableStream11.Transform)())
149testDuplex(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
Note: See TracBrowser for help on using the repository browser.