GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — assert: fix the string length check for printing the simple diff · nodejs/node@7af76ef

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/assert
    • assertion_error.js
  • test/parallel
    • test-assert-deep.js
    • test-assert.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/assert/assertion_error.js‎

Copy file name to clipboardExpand all lines: lib/internal/assert/assertion_error.js
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,14 @@ function getStackedDiff(actual, expected) {
134134
}
135135

136136
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+
}
138145
if (stringsLen <= kMaxShortStringLength && (originalActual !== 0 || originalExpected !== 0)) {
139146
return { message: `${actual} !== ${expected}`, header: '' };
140147
}
Collapse file

‎test/parallel/test-assert-deep.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-assert-deep.js
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,26 @@ test('Additional tests', () => {
846846
}
847847
);
848848

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+
849869
assert.notDeepStrictEqual(new Date(), new Date(2000, 3, 14));
850870

851871
assert.throws(
Collapse file

‎test/parallel/test-assert.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-assert.js
+3-15Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -919,11 +919,7 @@ test('Additional asserts', () => {
919919
{
920920
code: 'ERR_ASSERTION',
921921
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'
927923
}
928924
);
929925

@@ -935,11 +931,7 @@ test('Additional asserts', () => {
935931
{
936932
code: 'ERR_ASSERTION',
937933
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'
943935
}
944936
);
945937

@@ -951,11 +943,7 @@ test('Additional asserts', () => {
951943
}, {
952944
code: 'ERR_ASSERTION',
953945
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'
959947
}
960948
);
961949
/* eslint-enable @stylistic/js/indent */

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.