From 718525ff3f9c59da987e096f996b28061625dd96 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sun, 19 Jan 2025 19:46:39 -0800 Subject: [PATCH] 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 --- --- .../_tools/doctest/compare-values/lib/main.js | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/_tools/doctest/compare-values/lib/main.js b/lib/node_modules/@stdlib/_tools/doctest/compare-values/lib/main.js index 63fb9c05356..a9fcdf1235e 100644 --- a/lib/node_modules/@stdlib/_tools/doctest/compare-values/lib/main.js +++ b/lib/node_modules/@stdlib/_tools/doctest/compare-values/lib/main.js @@ -209,6 +209,27 @@ function checkForPlaceholders( actual, expected ) { } } +/** +* Compares array entries with a list of actual values. +* +* @private +* @param {Collection} actual - list of actual values +* @param {Collection} expected - list of expected values +* @returns {(string|null)} result +*/ +function compareEntries( actual, expected ) { + var i; + if ( actual.length !== expected.length ) { + return 'Expected array entries ['+expected+'], but observed ['+actual+']'; + } + for ( i = 0; i < expected.length; i++ ) { + if ( !checkPrimitive( actual[ i ], String( expected[ i ] ) ) ) { + return 'Expected array entries ['+expected+'], but observed ['+actual+']'; + } + } + return null; +} + /** * 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. * @@ -221,7 +242,6 @@ function checkTypedArrays( actual, expected ) { var entries; var match; var type; - var i; match = RE_INSTANCE_ANNOTATION.exec( expected ); if ( match ) { @@ -231,12 +251,7 @@ function checkTypedArrays( actual, expected ) { return 'Expected instance type <'+actual.constructor.name+'>, but observed <'+type+'>'; } if ( entries ) { - entries = parse( entries ); - for ( i = 0; i < entries.length; i++ ) { - if ( !checkPrimitive( actual[ i ], String( entries[ i ] ) ) ) { - return 'Expected array entries ['+entries+'], but observed ['+actual+']'; - } - } + return compareEntries( actual, parse( entries ) ); } return null; }