<commit_before>'use strict';

// MODULES //

var tape = require( 'tape' );
var join = require( 'path' ).join;
var isBrowser = require( '@stdlib/assert/is-browser' );
var noop = require( '@stdlib/utils/noop' );
var readJSON = require( './../lib/async.js' );


// FIXME //

// Don't run tests in the browser...for now...
var opts = {
	'skip': isBrowser
};


// FIXTURES //

var goodJSON = join( __dirname, 'fixtures', 'good.json' );
var badJSON = join( __dirname, 'fixtures', 'bad.json.txt' );
var bomJSON = join( __dirname, 'fixtures', 'bom.json.txt' );


// TESTS //

tape( 'main export is a function', function test( t ) {
	t.ok( true, __filename );
	t.equal( typeof readJSON, 'function', 'main export is a function' );
	t.end();
});

tape( 'the function throws an error if provided an options argument which is neither a string or object', function test( t ) {
	var values;
	var i;

	values = [
		5,
		NaN,
		true,
		null,
		undefined,
		[],
		function noop() {}
	];

	for ( i = 0; i < values.length; i++ ) {
		t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] );
	}
	t.end();

	function badValue( value ) {
		return function badValue() {
			readJSON( goodJSON, value, noop );
		};
	}
});

tape( 'the function throws an error if provided a callback argument which is not a function', function test( t ) {
	var values;
	var i;

	values = [
		'5',
		5,
		NaN,
		true,
		null,
		undefined,
		[],
		{}
	];

	for ( i = 0; i < values.length; i++ ) {
		t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] );
	}
	t.end();

	function badValue( value ) {
		return function badValue() {
			readJSON( goodJSON, value );
		};
	}
});

tape( 'the function throws an error if provided a callback argument which is not a function (encoding)', function test( t ) {
	var values;
	var i;

	values = [
		'5',
		5,
		NaN,
		true,
		null,
		undefined,
		[],
		{}
	];

	for ( i = 0; i < values.length; i++ ) {
		t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] );
	}
	t.end();

	function badValue( value ) {
		return function badValue() {
			readJSON( goodJSON, 'utf8', value );
		};
	}
});

tape( 'the function throws an error if provided a callback argument which is not a function (options object)', function test( t ) {
	var values;
	var i;

	values = [
		'5',
		5,
		NaN,
		true,
		null,
		undefined,
		[],
		{}
	];

	for ( i = 0; i < values.length; i++ ) {
		t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] );
	}
	t.end();

	function badValue( value ) {
		return function badValue() {
			readJSON( goodJSON, {}, value );
		};<commit_msg>Rename variable and use strict equality<commit_after>'use strict';

// MODULES //

var tape = require( 'tape' );
var join = require( 'path' ).join;
var IS_BROWSER = require( '@stdlib/assert/is-browser' );
var noop = require( '@stdlib/utils/noop' );
var readJSON = require( './../lib/async.js' );


// FIXME //

// Don't run tests in the browser...for now...
var opts = {
	'skip': IS_BROWSER
};


// FIXTURES //

var goodJSON = join( __dirname, 'fixtures', 'good.json' );
var badJSON = join( __dirname, 'fixtures', 'bad.json.txt' );
var bomJSON = join( __dirname, 'fixtures', 'bom.json.txt' );


// TESTS //

tape( 'main export is a function', function test( t ) {
	t.ok( true, __filename );
	t.strictEqual( typeof readJSON, 'function', 'main export is a function' );
	t.end();
});

tape( 'the function throws an error if provided an options argument which is neither a string or object', function test( t ) {
	var values;
	var i;

	values = [
		5,
		NaN,
		true,
		false,
		null,
		void 0,
		[],
		function noop() {}
	];

	for ( i = 0; i < values.length; i++ ) {
		t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] );
	}
	t.end();

	function badValue( value ) {
		return function badValue() {
			readJSON( goodJSON, value, noop );
		};
	}
});

tape( 'the function throws an error if provided a callback argument which is not a function', function test( t ) {
	var values;
	var i;

	values = [
		'5',
		5,
		NaN,
		true,
		false,
		null,
		void 0,
		[],
		{}
	];

	for ( i = 0; i < values.length; i++ ) {
		t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] );
	}
	t.end();

	function badValue( value ) {
		return function badValue() {
			readJSON( goodJSON, value );
		};
	}
});

tape( 'the function throws an error if provided a callback argument which is not a function (encoding)', function test( t ) {
	var values;
	var i;

	values = [
		'5',
		5,
		NaN,
		true,
		false,
		null,
		void 0,
		[],
		{}
	];

	for ( i = 0; i < values.length; i++ ) {
		t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] );
	}
	t.end();

	function badValue( value ) {
		return function badValue() {
			readJSON( goodJSON, 'utf8', value );
		};
	}
});

tape( 'the function throws an error if provided a callback argument which is not a function (options object)', function test( t ) {
	var values;
	var i;

	values = [
		'5',
		5,
		NaN,
		true,
		false,
		null,
		void 0,
		[],
		{}
	];

	for ( i = 0; i < values.length; i++ ) {
		t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] );
	}
	t.end();

	function badValue( value ) {
		return function badValue() {
			readJSON( goodJSON, {}, value );
		};
{'fraction_non_alphanumeric': 0.16316758747697974, 'fraction_numerical': 0.005156537753222836, 'mean_word_length': 3.0896084337349397, 'pattern_counts': {'":': 0, '<': 11, '<?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': '2400151', 'n_tokens_mistral': 2090, 'n_tokens_neox': 1933, 'n_words': 641}