<commit_before>'use strict';
var assert = require('assert');
var firstChunkStream = require('./');
var streamtest = require('streamtest');

describe('firstChunk()', function () {
	var content = 'unicorn rainbows \ncake';

	streamtest.versions.forEach(function (version) {

		describe('for ' + version + ' streams', function () {

			it('should should work for a single oversized chunk', function (cb) {
				streamtest[version].fromChunks([content])
					.pipe(firstChunkStream(function (chunk, enc, cb) {
						this.push(chunk);
						cb();
					}))
					.pipe(streamtest[version].toText(function (err, text) {
						if(err) {
							return done(err);
						}
						assert.deepEqual(text, content);
						cb();
					}));
			});


			it('should should work for required size chunk', function (cb) {
				streamtest[version].fromChunks([content.substr(0, 7), content.substr(7)])
					.pipe(firstChunkStream({minSize: 7}, function (chunk, enc, cb) {
						this.push(chunk);
						cb();
					}))
					.pipe(streamtest[version].toText(function (err, text) {
						if(err) {
							return done(err);
						}
						assert.deepEqual(text, content);
						cb();
					}));
			});

			it('should should work for several small chunks', function (cb) {
				streamtest[version].fromChunks(content.split(''))
					.pipe(firstChunkStream(function (chunk, enc, cb) {
						this.push(chunk);
						cb();
					}))
					.pipe(streamtest[version].toText(function (err, text) {
						if(err) {
							return done(err);
						}
						assert.deepEqual(text, content);
						cb();
					}));
			});

		});

	});

});
<commit_msg>Changing tests for the new API<commit_after>'use strict';
var assert = require('assert');
var firstChunkStream = require('./');
var streamtest = require('streamtest');

describe('firstChunk()', function () {
	var content = 'unicorn rainbows \ncake';

	streamtest.versions.forEach(function (version) {

		describe('for ' + version + ' streams', function () {

			describe('and leaving content as is', function () {

				it('should work for a single oversized chunk', function (cb) {
					streamtest[version].fromChunks([content])
						.pipe(firstChunkStream({firstChunkSize: 7}, function (chunk, enc, cb) {
							assert.equal(chunk.toString('utf-8'), content.substr(0, 7));
							cb(null, chunk);
						}))
						.pipe(streamtest[version].toText(function (err, text) {
							if(err) {
								return done(err);
							}
							assert.deepEqual(text, content);
							cb();
						}));
				});


				it('should work for required size chunk', function (cb) {
					streamtest[version].fromChunks([content.substr(0, 7), content.substr(7)])
						.pipe(firstChunkStream({firstChunkSize: 7}, function (chunk, enc, cb) {
							assert.equal(chunk.toString('utf-8'), content.substr(0, 7));
							cb(null, chunk);
						}))
						.pipe(streamtest[version].toText(function (err, text) {
							if(err) {
								return done(err);
							}
							assert.deepEqual(text, content);
							cb();
						}));
				});

				it('should work for several small chunks', function (cb) {
					streamtest[version].fromChunks(content.split(''))
						.pipe(firstChunkStream({firstChunkSize: 7}, function (chunk, enc, cb) {
							assert.equal(chunk.toString('utf-8'), content.substr(0, 7));
							cb(null, chunk);
						}))
						.pipe(streamtest[version].toText(function (err, text) {
							if(err) {
								return done(err);
							}
							assert.deepEqual(text, content);
							cb();
						}));
				});

			});

			describe('and changing content', function () {

				it('should work when removing the first chunk', function (cb) {
					streamtest[version].fromChunks([content])
						.pipe(firstChunkStream({firstChunkSize: 7}, function (chunk, enc, cb) {
							assert.equal(chunk.toString('utf-8'), content.substr(0, 7));
							cb(null, new Buffer(''));
						}))
						.pipe(streamtest[version].toText(function (err, text) {
							if(err) {
								return done(err);
							}
							assert.deepEqual(text, content.substr(8));
							cb();
						}));
				});


				it('should work when replacing per a larger chunk', function (cb) {
					streamtest[version].fromChunks([content.substr(0, 7), content.substr(7)])
						.pipe(firstChunkStream({firstChunkSize: 7}, function (chunk, enc, cb) {
							assert.equal(chunk.toString('utf-8'), content.substr(0, 7));
							cb(null, Buffer.concat([chunk, new Buffer('plop')], 2));
						}))
						.pipe(streamtest[version].toText(function (err, text) {
							if(err) {
								return done(err);
							}
							assert.deepEqual(text, content.substr(0, 7) + 'plop' + content.substr(8));
							cb();
						}));
				});

				it('should work when replacing per a smaller chunk', function (cb) {
					streamtest[version].fromChunks(content.split(''))
						.pipe(firstChunkStream({firstChunkSize: 7}, function (chunk, enc, cb) {
							assert.equal(chunk.toString('utf-8'), content.substr(0, 7));
							cb(null, new Buffer('plop'));
						}))
						.pipe(streamtest[version].toText(function (err, text) {
							if(err) {
								return done(err);
							}
							assert.deepEqual(text, 'plop' + content.substr(8));
							cb();
						}));
				});

			});

		});

	});

});

{'fraction_non_alphanumeric': 0.1729106628242075, 'fraction_numerical': 0.007684918347742555, 'mean_word_length': 2.8821774794929156, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '991434', 'n_tokens_mistral': 2266, 'n_tokens_neox': 1591, 'n_words': 336}