Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,53 @@ tape( 'the function returns an integer-formatted token argument (precision)', fu

t.end();
});

tape( 'the function throws an error for non-numeric input', function test( t ) {
var token;

token = {
'specifier': 'd',
'arg': 'abc'
};

t.throws( badToken( token ), Error, 'throws an error when provided arg '+token.arg );

t.end();

function badToken( token ) {
return function badToken() {
formatInteger( token );
};
}
});

tape( 'the function coerces non-finite numeric input to empty string', function test( t ) {
var expected;
var actual;
var token;

expected = '';

token = {
'specifier': 'd',
'arg': NaN
};
actual = formatInteger( token );
t.strictEqual( actual, expected, 'returns expected empty string' );

token = {
'specifier': 'd',
'arg': Infinity
};
actual = formatInteger( token );
t.strictEqual( actual, expected, 'returns expected empty string' );

token = {
'specifier': 'd',
'arg': -Infinity
};
actual = formatInteger( token );
t.strictEqual( actual, expected, 'returns expected empty string' );

t.end();
});