218c522063be9a9ca9b0bd47485db99aa45ccd57
[platform/framework/web/crosswalk-tizen.git] /
1 var concat = require('../')
2 var test = require('tape')
3 var TA = require('typedarray')
4 var U8 = typeof Uint8Array !== 'undefined' ? Uint8Array : TA.Uint8Array
5
6 test('string -> buffer stream', function (t) {
7   t.plan(2)
8   var strings = concat({ encoding: 'buffer'}, function(out) {
9     t.ok(Buffer.isBuffer(out))
10     t.equal(out.toString('utf8'), 'nacho dogs')
11   })
12   strings.write("nacho ")
13   strings.write("dogs")
14   strings.end()
15 })
16
17 test('string stream', function (t) {
18   t.plan(2)
19   var strings = concat({ encoding: 'string' }, function(out) {
20     t.equal(typeof out, 'string')
21     t.equal(out, 'nacho dogs')
22   })
23   strings.write("nacho ")
24   strings.write("dogs")
25   strings.end()
26 })
27
28 test('end chunk', function (t) {
29   t.plan(1)
30   var endchunk = concat({ encoding: 'string' }, function(out) {
31     t.equal(out, 'this is the end')
32   })
33   endchunk.write("this ")
34   endchunk.write("is the ")
35   endchunk.end("end")
36 })
37
38 test('string from mixed write encodings', function (t) {
39   t.plan(2)
40   var strings = concat({ encoding: 'string' }, function(out) {
41     t.equal(typeof out, 'string')
42     t.equal(out, 'nacho dogs')
43   })
44   strings.write('na')
45   strings.write(Buffer('cho'))
46   strings.write([ 32, 100 ])
47   var u8 = new U8(3)
48   u8[0] = 111; u8[1] = 103; u8[2] = 115;
49   strings.end(u8)
50 })
51
52 test('string from buffers with multibyte characters', function (t) {
53   t.plan(2)
54   var strings = concat({ encoding: 'string' }, function(out) {
55     t.equal(typeof out, 'string')
56     t.equal(out, '☃☃☃☃☃☃☃☃')
57   })
58   var snowman = new Buffer('☃')
59   for (var i = 0; i < 8; i++) {
60     strings.write(snowman.slice(0, 1))
61     strings.write(snowman.slice(1))    
62   }
63   strings.end()
64 })
65
66 test('string infer encoding with empty string chunk', function (t) {
67   t.plan(2)
68   var strings = concat(function(out) {
69     t.equal(typeof out, 'string')
70     t.equal(out, 'nacho dogs')
71   })
72   strings.write("")
73   strings.write("nacho ")
74   strings.write("dogs")
75   strings.end()
76 })