Skip to content

Commit e6b22ec

Browse files
committed
test: add non-numeric argument test to string/base/format-interpolate
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 350c422 commit e6b22ec

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

lib/node_modules/@stdlib/string/base/format-interpolate/test/test.format_integer.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,53 @@ tape( 'the function returns an integer-formatted token argument (precision)', fu
168168

169169
t.end();
170170
});
171+
172+
tape( 'the function throws an error for non-numeric input', function test( t ) {
173+
var token;
174+
175+
token = {
176+
'specifier': 'd',
177+
'arg': 'abc'
178+
};
179+
180+
t.throws( badToken( token ), Error, 'throws an error when provided arg '+token.arg );
181+
182+
t.end();
183+
184+
function badToken( token ) {
185+
return function badToken() {
186+
formatInteger( token );
187+
};
188+
}
189+
});
190+
191+
tape( 'the function coerces non-finite numeric input to empty string', function test( t ) {
192+
var expected;
193+
var actual;
194+
var token;
195+
196+
expected = '';
197+
198+
token = {
199+
'specifier': 'd',
200+
'arg': NaN
201+
};
202+
actual = formatInteger( token );
203+
t.strictEqual( actual, expected, 'returns expected empty string' );
204+
205+
token = {
206+
'specifier': 'd',
207+
'arg': Infinity
208+
};
209+
actual = formatInteger( token );
210+
t.strictEqual( actual, expected, 'returns expected empty string' );
211+
212+
token = {
213+
'specifier': 'd',
214+
'arg': -Infinity
215+
};
216+
actual = formatInteger( token );
217+
t.strictEqual( actual, expected, 'returns expected empty string' );
218+
219+
t.end();
220+
});

0 commit comments

Comments
 (0)