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 dd8f37d264dd..af66083e87ca 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 @@ -435,6 +435,9 @@ function checkArray( actual, expected ) { return false; } } else if ( isPrimitive( a ) ) { + if ( !isPrimitive( b ) ) { + return false; + } b = String( b ); if ( !checkPrimitive( a, b ) ) { return false; diff --git a/lib/node_modules/@stdlib/_tools/doctest/compare-values/test/test.js b/lib/node_modules/@stdlib/_tools/doctest/compare-values/test/test.js index 5a004ff6869f..032c70c03533 100644 --- a/lib/node_modules/@stdlib/_tools/doctest/compare-values/test/test.js +++ b/lib/node_modules/@stdlib/_tools/doctest/compare-values/test/test.js @@ -611,3 +611,55 @@ tape( 'the function compares a function and a corresponding return annotation', return x; } }); + +tape( 'the function detects a mismatch when an actual array element is a primitive and the expected array element is an array', function test( t ) { + var expected; + var actual; + var msg; + + actual = [ 300, 700 ]; + expected = '[[ 300, 700 ]]'; + msg = 'Displayed return value is `[[ 300, 700 ]]`, but expected `[ 300, 700 ]` instead'; + t.strictEqual( compareValues( actual, expected ), msg, 'returns expected message' ); + + t.end(); +}); + +tape( 'the function detects a mismatch when an actual array element is a primitive and the expected array element is an object', function test( t ) { + var expected; + var actual; + var msg; + + actual = [ 1 ]; + expected = '[ {} ]'; + msg = 'Displayed return value is `[ {} ]`, but expected `[ 1 ]` instead'; + t.strictEqual( compareValues( actual, expected ), msg, 'returns expected message' ); + + t.end(); +}); + +tape( 'the function detects a mismatch when an actual array element is a primitive and the expected array element is a RegExp', function test( t ) { + var expected; + var actual; + var msg; + + actual = [ 1 ]; + expected = '[ /abc/ ]'; + msg = 'Displayed return value is `[ /abc/ ]`, but expected `[ 1 ]` instead'; + t.strictEqual( compareValues( actual, expected ), msg, 'returns expected message' ); + + t.end(); +}); + +tape( 'the function detects a mismatch in a mixed array where a primitive corresponds to an array', function test( t ) { + var expected; + var actual; + var msg; + + actual = [ 1, 2 ]; + expected = '[ 1, [ 2 ] ]'; + msg = 'Displayed return value is `[ 1, [ 2 ] ]`, but expected `[ 1, 2 ]` instead'; + t.strictEqual( compareValues( actual, expected ), msg, 'returns expected message' ); + + t.end(); +});