'use strict';

// MODULES //

var tape = require( 'tape' );
var startsWith = require( './../lib' );


// TESTS //

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

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

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

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

	function badValue( value ) {
		return function() {
			startsWith( value, 'abc' );
		};
	}
});

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

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

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

	function badValue( value ) {
		return function() {
			startsWith( 'abc', value );
		};
	}
});

tape( 'the function throws an error if the third argument is not an integer', function test( t ) {
	var values;
	var i;

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

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

	function badValue( value ) {
		return function() {
			startsWith( 'abc', 'a', value );
		};
	}
});

tape( 'the function returns `true` if the input string starts with the search value', function test( t ) {
	var out;

	out = startsWith( 'Too late, I\'m afraid', 'Too' );
	t.equal( out, true, 'returns true' );

	out = startsWith( 'Not too late, I\'m afraid', 'Not' );
	t.equal( out, true, 'returns true' );

	out = startsWith( 'Welcome home!', 'Welcome home' );
	t.equal( out, true, 'returns true' );

	t.end();
});

tape( 'the function returns `false` if the input string does not start with the search value', function test( t ) {
	var out;

	out = startsWith( 'Too late, I\'m afraid', 'too' );
	t.equal( out, false, 'returns false' );

	out = startsWith( 'Not too late, I\'m afraid', 'Never' );
	t.equal( out, false, 'returns false' );

	out = startsWith( 'Welcome home!', 'Welcome at home' );
	t.equal( out, false, 'returns false' );

	t.end();
});

tape( 'the function starts the search at a specified position', function test( t ) {
	var out;

	out = startsWith( 'Too late, I\'m afraid', 'late', 3 );
	t.equal( out, false, 'returns false' );

	out = startsWith( 'Too late, I\'m afraid', 'late', 4 );
	t.equal( out, true, 'returns true' );

	out = startsWith( 'Too late, I\'m afraid', 'late', 6 );
	t.equal( out, false, 'returns false' );

	t.end();
});

tape( 'the function returns `false` if provided a position exceeding the input string length', function test( t ) {
	var out = startsWith( 'abc', 'c', 99999 );
	t.equal( out, false, 'returns false' );
	t.end();
});

@@ -3095,24 +3095,195 @@
 false' );%0A%09t.end();%0A%7D);%0A
+%0Atape( 'the function ignores negative position values', function test( t ) %7B%0A%09var out = startsWith( 'abc', 'a', -5 );%0A%09t.equal( out, true, 'returns true' );%0A%09t.end();%0A%7D);%0A

Add test case for negative position values