Update Iot.js
[platform/upstream/iotjs.git] / test / run_pass / test_stream.js
1 /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16
17 var Readable = require('stream').Readable;
18 var assert = require('assert');
19
20
21 var readable = new Readable();
22 var d = "";
23 var e = "";
24
25
26 readable.on('error', function(err) {
27   e += ".";
28 });
29
30 readable.on('data', function(data) {
31   d += data.toString();
32 });
33
34 readable.on('end', function() {
35   e += 'e';
36 });
37
38
39 readable.pause();
40 readable.push('abcde');
41 readable.push('12345');
42 assert.equal(d, '');
43 assert.equal(e, '');
44
45 readable.resume();
46 assert.equal(d, 'abcde12345');
47 assert.equal(e, '');
48
49 readable.push('a');
50 readable.push('1');
51 readable.push('b');
52 readable.push('2');
53 assert.equal(d, 'abcde12345a1b2');
54 assert.equal(e, '');
55
56 readable.pause();
57 assert.equal(d, 'abcde12345a1b2');
58 assert.equal(e, '');
59
60 readable.push('c');
61 readable.push('3');
62 readable.push('d');
63 readable.push('4');
64 assert.equal(d, 'abcde12345a1b2');
65 assert.equal(e, '');
66
67 readable.resume();
68 assert.equal(d, 'abcde12345a1b2c3d4');
69 assert.equal(e, '');
70
71 readable.push(null);
72 assert.equal(d, 'abcde12345a1b2c3d4');
73 assert.equal(e, 'e');
74
75 readable.push('push after eof');
76 assert.equal(d, 'abcde12345a1b2c3d4');
77 assert.equal(e, 'e.');