Merge "Do not distinguish between unset and empty a/b"

This commit is contained in:
Ben Rohlfs
2019-10-23 10:39:41 +00:00
committed by Gerrit Code Review
2 changed files with 21 additions and 3 deletions

View File

@@ -917,7 +917,8 @@
!chunk.ab &&
// The chunk doesn't have the given side.
((leftSide && !chunk.a) || (!leftSide && !chunk.b)));
((leftSide && (!chunk.a || !chunk.a.length)) ||
(!leftSide && (!chunk.b || !chunk.b.length))));
// If we reached the beginning of the diff and failed to find a chunk
// with the given side, return null.

View File

@@ -851,7 +851,7 @@ limitations under the License.
assert.equal(element._lastChunkForSide(diff, true), diff.content[3]);
});
test('addition', () => {
test('addition with a undefined', () => {
const diff = {content: [
{b: ['foo', 'bar', 'baz']},
]};
@@ -859,7 +859,16 @@ limitations under the License.
assert.isNull(element._lastChunkForSide(diff, true));
});
test('deletion', () => {
test('addition with a empty', () => {
const diff = {content: [
{a: [], b: ['foo', 'bar', 'baz']},
]};
assert.equal(element._lastChunkForSide(diff, false), diff.content[0]);
assert.isNull(element._lastChunkForSide(diff, true));
});
test('deletion with b undefined', () => {
const diff = {content: [
{a: ['foo', 'bar', 'baz']},
]};
@@ -867,6 +876,14 @@ limitations under the License.
assert.equal(element._lastChunkForSide(diff, true), diff.content[0]);
});
test('deletion with b empty', () => {
const diff = {content: [
{a: ['foo', 'bar', 'baz'], b: []},
]};
assert.isNull(element._lastChunkForSide(diff, false));
assert.equal(element._lastChunkForSide(diff, true), diff.content[0]);
});
test('empty', () => {
const diff = {content: []};
assert.isNull(element._lastChunkForSide(diff, false));