Skip to content

Commit e834ff9

Browse files
committed
docs: add comments
--- 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent b942e0e commit e834ff9

File tree

1 file changed

+14
-1
lines changed
  • lib/node_modules/@stdlib/_tools/doctest/compare-values/lib

1 file changed

+14
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ function compareValues( actual, expected ) {
472472
var a;
473473
var b;
474474

475+
// Case: compareValues( true, 'true || false' )
475476
if ( contains( expected, '||' ) ) {
476477
parts = expected.split( '||' );
477478
a = trim( parts[ 0 ] );
@@ -483,23 +484,28 @@ function compareValues( actual, expected ) {
483484
}
484485
return null;
485486
}
487+
// Case: compareValues( ???, '' )
486488
if ( isEmptyString( expected ) ) {
487489
return 'Return annotation is empty';
488490
}
491+
// Case: compareValues( ???, 'e.g., returns 5' )
489492
if ( contains( expected, 'e.g.' ) ) {
490493
// Early return since we cannot compare actual value to return annotation value:
491494
return null;
492495
}
496+
// Case: compareValues( [], '<Array>' )
493497
if ( startsWith( expected, '<' ) && endsWith( expected, '>' ) ) {
494498
if ( !checkForPlaceholders( actual, expected ) ) {
495499
return 'Expected a '+expected+', but received: `'+actual+'`';
496500
}
501+
// Case: compareValues( new Number( 5 ), '<Number>' )
497502
if (
498503
contains( BOXED_TYPE_ANNOTATIONS, expected ) &&
499504
isPrimitive( actual )
500505
) {
501506
return 'Expected a '+expected+', but received an unboxed primitive: `'+actual+'`';
502507
}
508+
// Case: compareValues( 5, '<number>' )
503509
if (
504510
contains( PRIMITIVE_TYPE_ANNOTATIONS, expected ) &&
505511
isBoxedPrimitive( actual )
@@ -508,6 +514,7 @@ function compareValues( actual, expected ) {
508514
}
509515
return null;
510516
}
517+
// Case: compareValues( 5, '5' )
511518
if ( isPrimitive( actual ) ) {
512519
if ( isString( actual) ) {
513520
if (
@@ -523,32 +530,38 @@ function compareValues( actual, expected ) {
523530
}
524531
return null;
525532
}
526-
if ( isTypedArray( actual ) || isComplexTypedArray( actual ) || isBooleanArray( actual ) ) {
533+
// Case: compareValues( new Float64Array( [ 1.0, 2.0 ] ), '<Float64Array>[ 1.0, 2.0 ]' )
534+
if ( isTypedArray( actual ) || isComplexTypedArray( actual ) || isBooleanArray( actual ) ) { // eslint-disable-line max-len
527535
return checkTypedArrays( actual, expected );
528536
}
537+
// Case: compareValues( [ 1.0, 2.0 ], '[ 1.0, 2.0 ]' )
529538
if ( isArray( actual ) ) {
530539
if ( !checkArray( actual, expected ) ) {
531540
return 'Displayed return value is `'+expected+'`, but expected `'+createAnnotationValue( actual )+'` instead';
532541
}
533542
return null;
534543
}
544+
// Case: compareValues( new Complex64( 1.0, 2.0 ), '<Complex64>[ 1.0, 2.0 ]' )
535545
if ( isComplex64( actual ) || isComplex128( actual ) ) {
536546
return checkComplex( actual, expected );
537547
}
548+
// Case: compareValues( /foo/, '/foo/' )
538549
if ( isRegExp( actual ) ) {
539550
actual = actual.toString();
540551
if ( actual !== expected ) {
541552
return 'Displayed return value is `'+expected+'`, but expected `'+actual+'` instead';
542553
}
543554
return null;
544555
}
556+
// Case: compareValues( function noop() {}, 'function noop() {}' )
545557
if ( isFunction( actual ) ) {
546558
actual = actual.toString();
547559
if ( actual !== expected ) {
548560
return 'Displayed return value is `'+expected+'`, but expected `'+actual+'` instead';
549561
}
550562
return null;
551563
}
564+
// Case: compareValues( {}, '{}' )
552565
if ( isObjectLike( actual ) ) {
553566
if ( !contains( expected, '...' ) ) {
554567
try {

0 commit comments

Comments
 (0)