Skip to content

Commit

Permalink
refactor: move entry comparison logic to separate function
Browse files Browse the repository at this point in the history
---
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
---
  • Loading branch information
kgryte committed Jan 20, 2025
1 parent f08e6b0 commit 718525f
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions lib/node_modules/@stdlib/_tools/doctest/compare-values/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -221,7 +242,6 @@ function checkTypedArrays( actual, expected ) {
var entries;
var match;
var type;
var i;

match = RE_INSTANCE_ANNOTATION.exec( expected );
if ( match ) {
Expand All @@ -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;
}
Expand Down

0 comments on commit 718525f

Please sign in to comment.