Do not distinguish between unset and empty a/b

The gerrit API will not set a/b for added/removed files, but
conceptually it makes more sense for the API to be permissive and treat
empty list the same.

There may be other places this is distinguished, and we can fix them as
we find them.

Change-Id: I85608392dbc5b82a3f98ca9fce2a0e900d474c19
(cherry picked from commit a3a78a91da)
This commit is contained in:
Ole Rehmsen
2019-10-22 15:38:46 +02:00
committed by Paladox none
parent 5d29e77678
commit 18f9267ea7
2 changed files with 21 additions and 3 deletions

View File

@@ -908,7 +908,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));