Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion spec/unit/MessageDiff.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('messageDiff', function() {
'should only show changes from the line that has changed in multiline messages',
'in a marmalade forest\nbetween the make-believe trees\nI forgot the third verse, sorry',
'in a marmalade forest\nbetween the make-believe trees\nin a cottage-cheese cottage...',
's/I forgot the third verse, sorry/in a cottage-cheese cottage.../',
's/I forgot the third verse, sorry$/in a cottage-cheese cottage.../',
],
[
'should not use diffs with newlines in them',
Expand Down Expand Up @@ -58,6 +58,12 @@ describe('messageDiff', function() {
'Lorem ipsum dolor sit amet - an arbitrary amount of trailing text will be duplicated in the sed expression, even though it should only include a few words of context',
undefined,
],
[
'should append to end of string if incomplete',
'how many wood would a woodchuck c',
'how many wood would a woodchuck chuck if a woodchuck would chuck wood',
's/c$/chuck if a woodchuck would chuck wood/'
]
].forEach(c => it(c[0], () => {
const result = messageDiff(c[1], c[2]);
expect(result).toBe(c[3]);
Expand Down
6 changes: 5 additions & 1 deletion src/util/MessageDiff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ function formatChanges(diff: Diff.Change[]): string[] {
while (i < diff.length - 1) {
if (diff[i].removed) {
let replacement: string;
let replaced: string = diff[i].value.trim();
if (diff[i+1].added) {
replacement = diff[i+1].value;
if (i+1 == diff.length-1) {
replaced += '$';
}
}
else if (noChanges(diff[i+1])) {
replacement = '';
Expand All @@ -35,7 +39,7 @@ function formatChanges(diff: Diff.Change[]): string[] {
i++;
continue;
}
substitutions.push([diff[i].value.trim(), replacement]);
substitutions.push([replaced, replacement]);
}
i++;
}
Expand Down