1 var concat = require('../')
2 var test = require('tape')
3 var TA = require('typedarray')
4 var U8 = typeof Uint8Array !== 'undefined' ? Uint8Array : TA.Uint8Array
6 test('string -> buffer stream', function (t) {
8 var strings = concat({ encoding: 'buffer'}, function(out) {
9 t.ok(Buffer.isBuffer(out))
10 t.equal(out.toString('utf8'), 'nacho dogs')
12 strings.write("nacho ")
17 test('string stream', function (t) {
19 var strings = concat({ encoding: 'string' }, function(out) {
20 t.equal(typeof out, 'string')
21 t.equal(out, 'nacho dogs')
23 strings.write("nacho ")
28 test('end chunk', function (t) {
30 var endchunk = concat({ encoding: 'string' }, function(out) {
31 t.equal(out, 'this is the end')
33 endchunk.write("this ")
34 endchunk.write("is the ")
38 test('string from mixed write encodings', function (t) {
40 var strings = concat({ encoding: 'string' }, function(out) {
41 t.equal(typeof out, 'string')
42 t.equal(out, 'nacho dogs')
45 strings.write(Buffer('cho'))
46 strings.write([ 32, 100 ])
48 u8[0] = 111; u8[1] = 103; u8[2] = 115;
52 test('string from buffers with multibyte characters', function (t) {
54 var strings = concat({ encoding: 'string' }, function(out) {
55 t.equal(typeof out, 'string')
56 t.equal(out, '☃☃☃☃☃☃☃☃')
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))
66 test('string infer encoding with empty string chunk', function (t) {
68 var strings = concat(function(out) {
69 t.equal(typeof out, 'string')
70 t.equal(out, 'nacho dogs')
73 strings.write("nacho ")