<commit_before>/*
 * test/command.js - Tests for hanson CLI
 * https://github.com/timjansen/handson
 */
var exec = require('child_process').exec;
var expect = require('chai').expect;
var hanson = require("../hanson.js");
var fs = require('fs');

// Change to root project dir
process.chdir(__dirname + '/..');

describe('command', function() {
	after(function(done) {
		fs.unlink('output.json', done);
	});

	it('accepts file -> file', function(done) {
		exec('node hansoncmd.js test/data/sample.hson output.json', function(err, stdout, stderr) {
			expect(err).to.be.not.ok;
			expect(stdout).to.be.a.string;
			expect(stdout).to.be.not.ok;
			expect(stderr).to.be.not.ok;

			var obj = JSON.parse(fs.readFileSync('output.json', 'utf-8'));
			expect(obj).to.have.property('listName', 'Sesame Street Monsters');
			expect(obj).to.have.property('content');
			expect(obj.content).to.be.an.array;
			expect(obj.content[0]).to.have.property('name', 'Cookie Monster');
			expect(obj.content[1]).to.have.property('name', 'Herry Monster');

			done();
		});
	});

	it('accepts STDIN -> file', function(done) {
		exec('node hansoncmd.js - output.json <test/data/sample.hson', function(err, stdout, stderr) {
			expect(err).to.be.not.ok;
			expect(stdout).to.be.a.string;
			expect(stdout).to.be.not.ok;
			expect(stderr).to.be.not.ok;

			var obj = JSON.parse(fs.readFileSync('output.json', 'utf-8'));
			expect(obj).to.have.property('listName', 'Sesame Street Monsters');
			expect(obj).to.have.property('content');
			expect(obj.content).to.be.an.array;
			expect(obj.content[0]).to.have.property('name', 'Cookie Monster');
			expect(obj.content[1]).to.have.property('name', 'Herry Monster');

			done();
		});
	});

	it('accepts file -> STDOUT', function(done) {
		exec('node hansoncmd.js test/data/sample.hson - >output.json', function(err, stdout, stderr) {
			expect(err).to.be.not.ok;
			expect(stdout).to.be.a.string;
			expect(stdout).to.be.not.ok;
			expect(stderr).to.be.not.ok;

			var obj = JSON.parse(fs.readFileSync('output.json', 'utf-8'));
			expect(obj).to.have.property('listName', 'Sesame Street Monsters');
			expect(obj).to.have.property('content');
			expect(obj.content).to.be.an.array;
			expect(obj.content[0]).to.have.property('name', 'Cookie Monster');
			expect(obj.content[1]).to.have.property('name', 'Herry Monster');

			done();
		});
	});

	it('accepts STDIN -> STDOUT', function(done) {
		exec('node hansoncmd.js - - <test/data/sample.hson >output.json', function(err, stdout, stderr) {
			expect(err).to.be.not.ok;
			expect(stdout).to.be.a.string;
			expect(stdout).to.be.not.ok;
			expect(stderr).to.be.not.ok;

			var obj = JSON.parse(fs.readFileSync('output.json', 'utf-8'));
			expect(obj).to.have.property('listName', 'Sesame Street Monsters');
			expect(obj).to.have.property('content');
			expect(obj.content).to.be.an.array;
			expect(obj.content[0]).to.have.property('name', 'Cookie Monster');
			expect(obj.content[1]).to.have.property('name', 'Herry Monster');

			done();
		});
	});
});<commit_msg>Added test for pipe mode REFACTOR: Tidied up tests to remove redundency<commit_after>/*
 * test/command.js - Tests for hanson CLI
 * https://github.com/timjansen/handson
 */
var exec = require('child_process').exec;
var expect = require('chai').expect;
var hanson = require("../hanson.js");
var fs = require('fs');

// Change to root project dir
process.chdir(__dirname + '/..');

describe('command', function() {

	// Clean up temporary file
	after(function(done) {
		fs.unlink('output.json', done);
	});

	// Verify object is correct
	var output;
	afterEach(function() {
		expect(output).to.have.property('listName', 'Sesame Street Monsters');
		expect(output).to.have.property('content');
		expect(output.content).to.be.an.array;
		expect(output.content[0]).to.have.property('name', 'Cookie Monster');
		expect(output.content[1]).to.have.property('name', 'Herry Monster');
	});

	it('accepts file -> file', function(done) {
		exec('node hansoncmd.js test/data/sample.hson output.json', function(err, stdout, stderr) {
			expect(err).to.be.not.ok;
			expect(stdout).to.be.a.string;
			expect(stdout).to.be.not.ok;
			expect(stderr).to.be.not.ok;

			output = JSON.parse(fs.readFileSync('output.json', 'utf-8'));
			done();
		});
	});

	it('accepts STDIN -> file', function(done) {
		exec('node hansoncmd.js - output.json <test/data/sample.hson', function(err, stdout, stderr) {
			expect(err).to.be.not.ok;
			expect(stdout).to.be.a.string;
			expect(stdout).to.be.not.ok;
			expect(stderr).to.be.not.ok;

			output = JSON.parse(fs.readFileSync('output.json', 'utf-8'));
			done();
		});
	});

	it('accepts file -> STDOUT', function(done) {
		exec('node hansoncmd.js test/data/sample.hson - >output.json', function(err, stdout, stderr) {
			expect(err).to.be.not.ok;
			expect(stdout).to.be.a.string;
			expect(stdout).to.be.not.ok;
			expect(stderr).to.be.not.ok;

			output = JSON.parse(fs.readFileSync('output.json', 'utf-8'));
			done();
		});
	});

	it('accepts STDIN -> STDOUT', function(done) {
		exec('node hansoncmd.js - - <test/data/sample.hson >output.json', function(err, stdout, stderr) {
			expect(err).to.be.not.ok;
			expect(stdout).to.be.a.string;
			expect(stdout).to.be.not.ok;
			expect(stderr).to.be.not.ok;

			output = JSON.parse(fs.readFileSync('output.json', 'utf-8'));
			done();
		});
	});

	it('accepts pipemode (-p)', function(done) {
		exec('node hansoncmd.js -p <test/data/sample.hson >output.json', function(err, stdout, stderr) {
			expect(err).to.be.not.ok;
			expect(stdout).to.be.a.string;
			expect(stdout).to.be.not.ok;
			expect(stderr).to.be.not.ok;

			output = JSON.parse(fs.readFileSync('output.json', 'utf-8'));
			done();
		});
	});
});
{'fraction_non_alphanumeric': 0.20845710291804997, 'fraction_numerical': 0.003319937095928709, 'mean_word_length': 4.0431718061674005, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 16, 'https://': 2, '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': '1626555', 'n_tokens_mistral': 2301, 'n_tokens_neox': 2087, 'n_words': 318}