GeezerVison is showing github.com — assert: fix the string length check for printing the simple diff · nodejs/node@7af76ef
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/assert/assertion_error.js +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -134,7 +134,14 @@ function getStackedDiff(actual, expected) { | 134 | 134 | } | 135 | 135 |
| 136 | 136 | function getSimpleDiff(originalActual, actual, originalExpected, expected) { | 137 | | - const stringsLen = actual.length + expected.length; | | 137 | + let stringsLen = actual.length + expected.length; | | 138 | + // Accounting for the quotes wrapping strings | | 139 | + if (typeof originalActual === 'string') { | | 140 | + stringsLen -= 2; | | 141 | + } | | 142 | + if (typeof originalExpected === 'string') { | | 143 | + stringsLen -= 2; | | 144 | + } | 138 | 145 | if (stringsLen <= kMaxShortStringLength && (originalActual !== 0 || originalExpected !== 0)) { | 139 | 146 | return { message: `${actual} !== ${expected}`, header: '' }; | 140 | 147 | } | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-assert-deep.js +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -846,6 +846,26 @@ test('Additional tests', () => { | 846 | 846 | } | 847 | 847 | ); | 848 | 848 |
| | 849 | + assert.throws( | | 850 | + () => assert.strictEqual('apple', 'pear'), | | 851 | + { | | 852 | + name: 'AssertionError', | | 853 | + message: 'Expected values to be strictly equal:\n\n\'apple\' !== \'pear\'\n' | | 854 | + } | | 855 | + ); | | 856 | + | | 857 | + assert.throws( | | 858 | + () => assert.strictEqual('ABABABABABAB', 'BABABABABABA'), | | 859 | + { | | 860 | + name: 'AssertionError', | | 861 | + message: 'Expected values to be strictly equal:\n' + | | 862 | + '+ actual - expected\n' + | | 863 | + '\n' + | | 864 | + "+ 'ABABABABABAB'\n" + | | 865 | + "- 'BABABABABABA'\n" | | 866 | + } | | 867 | + ); | | 868 | + | 849 | 869 | assert.notDeepStrictEqual(new Date(), new Date(2000, 3, 14)); | 850 | 870 |
| 851 | 871 | assert.throws( | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-assert.js +3-15Lines changed: 3 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -919,11 +919,7 @@ test('Additional asserts', () => { | 919 | 919 | { | 920 | 920 | code: 'ERR_ASSERTION', | 921 | 921 | constructor: assert.AssertionError, | 922 | | - message: 'Expected values to be strictly equal:\n' + | 923 | | - '+ actual - expected\n' + | 924 | | - '\n' + | 925 | | - "+ 'string'\n" + | 926 | | - '- false\n' | | 922 | + message: 'Expected values to be strictly equal:\n\n\'string\' !== false\n' | 927 | 923 | } | 928 | 924 | ); | 929 | 925 |
| @@ -935,11 +931,7 @@ test('Additional asserts', () => { | 935 | 931 | { | 936 | 932 | code: 'ERR_ASSERTION', | 937 | 933 | constructor: assert.AssertionError, | 938 | | - message: 'Expected values to be strictly equal:\n' + | 939 | | - '+ actual - expected\n' + | 940 | | - '\n' + | 941 | | - "+ 'string'\n" + | 942 | | - '- false\n' | | 934 | + message: 'Expected values to be strictly equal:\n\n\'string\' !== false\n' | 943 | 935 | } | 944 | 936 | ); | 945 | 937 |
| @@ -951,11 +943,7 @@ test('Additional asserts', () => { | 951 | 943 | }, { | 952 | 944 | code: 'ERR_ASSERTION', | 953 | 945 | constructor: assert.AssertionError, | 954 | | - message: 'Expected values to be strictly equal:\n' + | 955 | | - '+ actual - expected\n' + | 956 | | - '\n' + | 957 | | - "+ 'string'\n" + | 958 | | - '- false\n' | | 946 | + message: 'Expected values to be strictly equal:\n\n\'string\' !== false\n' | 959 | 947 | } | 960 | 948 | ); | 961 | 949 | /* eslint-enable @stylistic/js/indent */ | |
|