Skip to content

Commit a1a5621

Browse files
authored
fix(diff): allow comparison with empty strings (#59)
1 parent d2f2504 commit a1a5621

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/diff.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export function chars(input, expect) {
8989

9090
if (l1 === l2) {
9191
// no length offsets
92-
} else if (tmp.removed) {
92+
} else if (tmp.removed && arr[i + 1]) {
9393
let del = tmp.count - arr[i + 1].count;
9494
if (del == 0) {
9595
// wash~

test/diff.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,22 @@ chars('should print "→" character for tab', () => {
547547
);
548548
});
549549

550+
chars('should handle empty string', () => {
551+
assert.is(
552+
strip($.chars('foo bar', '')),
553+
'++ (Expected)\n' +
554+
'--foo·bar (Actual)\n' +
555+
' ^^^^^^^'
556+
);
557+
558+
assert.is(
559+
strip($.chars('', 'foo bar')),
560+
'++foo·bar (Expected)\n' +
561+
'-- (Actual)\n' +
562+
' ^^^^^^^'
563+
);
564+
})
565+
550566
chars.run();
551567

552568
// ---

0 commit comments

Comments
 (0)