Skip to content

Commit 718525f

Browse files
committed
refactor: move entry comparison logic to separate function
--- 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: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent f08e6b0 commit 718525f

File tree

1 file changed

+22
-7
lines changed
  • lib/node_modules/@stdlib/_tools/doctest/compare-values/lib

1 file changed

+22
-7
lines changed

lib/node_modules/@stdlib/_tools/doctest/compare-values/lib/main.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,27 @@ function checkForPlaceholders( actual, expected ) {
209209
}
210210
}
211211

212+
/**
213+
* Compares array entries with a list of actual values.
214+
*
215+
* @private
216+
* @param {Collection} actual - list of actual values
217+
* @param {Collection} expected - list of expected values
218+
* @returns {(string|null)} result
219+
*/
220+
function compareEntries( actual, expected ) {
221+
var i;
222+
if ( actual.length !== expected.length ) {
223+
return 'Expected array entries ['+expected+'], but observed ['+actual+']';
224+
}
225+
for ( i = 0; i < expected.length; i++ ) {
226+
if ( !checkPrimitive( actual[ i ], String( expected[ i ] ) ) ) {
227+
return 'Expected array entries ['+expected+'], but observed ['+actual+']';
228+
}
229+
}
230+
return null;
231+
}
232+
212233
/**
213234
* For a typed array, if the return annotation asserts deep instance equality, check whether it corresponds to the actual value; otherwise, check whether the return annotation signals the correct type.
214235
*
@@ -221,7 +242,6 @@ function checkTypedArrays( actual, expected ) {
221242
var entries;
222243
var match;
223244
var type;
224-
var i;
225245

226246
match = RE_INSTANCE_ANNOTATION.exec( expected );
227247
if ( match ) {
@@ -231,12 +251,7 @@ function checkTypedArrays( actual, expected ) {
231251
return 'Expected instance type <'+actual.constructor.name+'>, but observed <'+type+'>';
232252
}
233253
if ( entries ) {
234-
entries = parse( entries );
235-
for ( i = 0; i < entries.length; i++ ) {
236-
if ( !checkPrimitive( actual[ i ], String( entries[ i ] ) ) ) {
237-
return 'Expected array entries ['+entries+'], but observed ['+actual+']';
238-
}
239-
}
254+
return compareEntries( actual, parse( entries ) );
240255
}
241256
return null;
242257
}

0 commit comments

Comments
 (0)