<commit_before>mocha.setup({
    ui: "bdd",
    globals: ["console","__fxdriver_unwrapped"],
    timeout: 300000
});
chai.should();

function aSquare(x,cb) {
	cb( x * x );
}
function square(a){
	switch(typeof a){
		case "string": 
			throw a;
		case "number":
			return a*a;
	}
}
function sum(a, b) {
	return a + b;
}

function product(a){
	return a[0]*a[1];
}

var buf =(new Uint8Array([1,2,3,4,5,6,7,8])).buffer;
//cw.URL=true;
describe('cw()', function () {
	describe('Basic', function () {
		it('should work when given a function and data directly', function (done) {
			cw(square, 9).then(function (a) { a.should.equal(81); }).then(done, done);
		});
		it('should work when given a function and data async', function (done) {
			cw(aSquare, 9).then(function (a) { a.should.equal(81); }).then(done, done);
		});
		it('should allow chaining of data functions, with callback passed to cw()', function (done) {
			var count = 0;
			var comrade = cw(square, function (a) { count++; a.should.equal(81); if (count === 2) { comrade.close();done(); } });
			comrade.data(9).data(9);
		});
		it('should allow chaining of data functions, with callback passed to cw() async', function (done) {
			var count = 0;
			var comrade = cw(aSquare, function (a) { count++; a.should.equal(81); if (count === 2) { comrade.close();done(); } });
			comrade.data(9).data(9);
		});
		it('should be able to handle an array buffer', function(done){
			function wrapUp(){
				comrade.close();
				done();
			}
			var comrade = cw(function(data,cb){cb(data)});
			comrade.data((new Uint8Array([1,2,3,4,5,6,7,8])).buffer).then(function(a){a.byteLength.should.equal(8)}).then(wrapUp,wrapUp);
		});
		it('should be able to handle an array buffer as a transferable object', function(done){
			function wrapUp(){
				comrade.close();
				done();
			}
			var comrade = cw(function(data,cb){cb(data,[data])});
			comrade.data(buf,[buf]).then(function(a){a.byteLength.should.equal(8)}).then(wrapUp,wrapUp);
		});
	});
	describe('errors', function () {
		it('should gracefully handle an error', function (done) {
			var count = 0;
			var comrade = cw(square,function(a){
				a.should.equal(100);
				afterEach();
			},function(a){
				a.preventDefault();
				a.message.indexOf("Ermahgerd").should.be.at.least(0);
				afterEach();
			});
			function afterEach(){
				count++;
				if(count === 3){
					comrade.close();
					done();
				}
			}
			comrade.data(10).data("Ermahgerd").data(10);
		});
		it('should gracefully handle an error in a sticksaround', function (done) {
			function wrapUp(){
				comrade.close();
				done();
			}
			var comrade = cw(square);
			comrade.data("Ermahgerd").then(function(a){a.should.be.an('undefined');},function(a){a.indexOf("Ermahgerd").should.be.at.least(0);}).then(wrapUp, wrapUp);
		});
		it('should gracefully handle an error as a oneoff', function (done) {
			cw(square,"Ermahgerd").then(function(a){a.should.be.an('undefined');},function(a){a.indexOf("Ermahgerd").should.be.at.least(0);}).then(done, done);
		});
	});
	describe('Worker reuse', function () {
		<commit_msg>good enough<commit_after>mocha.setup({
    ui: "bdd",
    globals: ["console","__fxdriver_unwrapped"],
    timeout: 300000
});
chai.should();

function aSquare(x,cb) {
	cb( x * x );
}
function square(a){
	switch(typeof a){
		case "string": 
			throw a;
		case "number":
			return a*a;
	}
}
function sum(a, b) {
	return a + b;
}

function product(a){
	return a[0]*a[1];
}

var buf =(new Uint8Array([1,2,3,4,5,6,7,8])).buffer;
//cw.URL=true;
describe('cw()', function () {
	describe('Basic', function () {
		it('should work when given a function and data directly', function (done) {
			cw(square, 9).then(function (a) { a.should.equal(81); }).then(done, done);
		});
		it('should work when given a function and data async', function (done) {
			cw(aSquare, 9).then(function (a) { a.should.equal(81); }).then(done, done);
		});
		it('should allow chaining of data functions, with callback passed to cw()', function (done) {
			var count = 0;
			var comrade = cw(square, function (a) { count++; a.should.equal(81); if (count === 2) { comrade.close();done(); } });
			comrade.data(9).data(9);
		});
		it('should allow chaining of data functions, with callback passed to cw() async', function (done) {
			var count = 0;
			var comrade = cw(aSquare, function (a) { count++; a.should.equal(81); if (count === 2) { comrade.close();done(); } });
			comrade.data(9).data(9);
		});
		it('should be able to handle an array buffer', function(done){
			function wrapUp(){
				comrade.close();
				done();
			}
			var comrade = cw(function(data,cb){cb(data)});
			comrade.data((new Uint8Array([1,2,3,4,5,6,7,8])).buffer).then(function(a){a.byteLength.should.equal(8)}).then(wrapUp,wrapUp);
		});
		it('should be able to handle an array buffer as a transferable object', function(done){
			function wrapUp(){
				comrade.close();
				done();
			}
			var comrade = cw(function(data,cb){cb(data,[data])});
			comrade.data(buf,[buf]).then(function(a){a.byteLength.should.equal(8)}).then(wrapUp,wrapUp);
		});
	});
	describe('errors', function () {
		it('should gracefully handle an error', function (done) {
			var count = 0;
			var comrade = cw(square,function(a){
				a.should.equal(100);
				afterEach();
			},function(a){
				a.preventDefault();
				a.message.indexOf("Ermahgerd").should.be.at.least(0);
				afterEach();
			});
			function afterEach(){
				count++;
				if(count === 3){
					comrade.close();
					done();
				}
			}
			comrade.data(10).data("Ermahgerd").data(10);
		});
		it('should gracefully handle an error in a sticksaround', function (done) {
			function wrapUp(){
				comrade.close();
				done();
			}
			var comrade = cw(square);
			comrade.data("Ermahgerd").then(function(a){a.should.be.an('undefined');},function(a){a.indexOf("Ermahgerd").should.be.at.least(0);}).then(wrapUp, wrapUp);
		});
		it('should gracefully handle an error as a oneoff', function (done) {
			cw(square,"Ermahgerd").then(function(a){a.should.be.an('undefined');},function(a){a.should.be.a('string');}).then(done, done);
		});
	});
	describe('Worker reuse', function () {
		
{'fraction_non_alphanumeric': 0.2023130803062388, 'fraction_numerical': 0.018732692620948038, 'mean_word_length': 4.116666666666666, 'pattern_counts': {'":': 4, '<': 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': '563574', 'n_tokens_mistral': 2539, 'n_tokens_neox': 2218, 'n_words': 475}