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