Merge "ES6ify /gr-diff-processor/*"

This commit is contained in:
Kasper Nilsson
2017-05-17 22:50:12 +00:00
committed by Gerrit Code Review
2 changed files with 213 additions and 215 deletions

View File

@@ -14,20 +14,20 @@
(function() {
'use strict';
var WHOLE_FILE = -1;
const WHOLE_FILE = -1;
var DiffSide = {
const DiffSide = {
LEFT: 'left',
RIGHT: 'right',
};
var DiffGroupType = {
const DiffGroupType = {
ADDED: 'b',
BOTH: 'ab',
REMOVED: 'a',
};
var DiffHighlights = {
const DiffHighlights = {
ADDED: 'edit_b',
REMOVED: 'edit_a',
};
@@ -40,7 +40,7 @@
* _asyncThreshold of 64, but feel free to tune this constant to your
* performance needs.
*/
var MAX_GROUP_SIZE = 120;
const MAX_GROUP_SIZE = 120;
Polymer({
is: 'gr-diff-processor',
@@ -66,7 +66,7 @@
*/
keyLocations: {
type: Object,
value: function() { return {left: {}, right: {}}; },
value() { return {left: {}, right: {}}; },
},
/**
@@ -81,18 +81,18 @@
_isScrolling: Boolean,
},
attached: function() {
attached() {
this.listen(window, 'scroll', '_handleWindowScroll');
},
detached: function() {
detached() {
this.cancel();
this.unlisten(window, 'scroll', '_handleWindowScroll');
},
_handleWindowScroll: function() {
_handleWindowScroll() {
this._isScrolling = true;
this.debounce('resetIsScrolling', function() {
this.debounce('resetIsScrolling', () => {
this._isScrolling = false;
}, 50);
},
@@ -103,23 +103,23 @@
* @return {Promise} A promise that resolves when the diff is completely
* processed.
*/
process: function(content, isImageDiff) {
process(content, isImageDiff) {
this.groups = [];
this.push('groups', this._makeFileComments());
// If image diff, only render the file lines.
if (isImageDiff) { return Promise.resolve(); }
return new Promise(function(resolve) {
var state = {
return new Promise(resolve => {
const state = {
lineNums: {left: 0, right: 0},
sectionIndex: 0,
};
content = this._splitCommonGroupsWithComments(content);
var currentBatch = 0;
var nextStep = function() {
let currentBatch = 0;
const nextStep = () => {
if (this._isScrolling) {
this.async(nextStep, 100);
return;
@@ -132,11 +132,11 @@
}
// Process the next section and incorporate the result.
var result = this._processNext(state, content);
result.groups.forEach(function(group) {
const result = this._processNext(state, content);
for (const group of result.groups) {
this.push('groups', group);
currentBatch += group.lines.length;
}, this);
}
state.lineNums.left += result.lineDelta.left;
state.lineNums.right += result.lineDelta.right;
@@ -151,13 +151,13 @@
};
nextStep.call(this);
}.bind(this));
});
},
/**
* Cancel any jobs that are running.
*/
cancel: function() {
cancel() {
if (this._nextStepHandle !== undefined) {
this.cancelAsync(this._nextStepHandle);
this._nextStepHandle = undefined;
@@ -167,29 +167,29 @@
/**
* Process the next section of the diff.
*/
_processNext: function(state, content) {
var section = content[state.sectionIndex];
_processNext(state, content) {
const section = content[state.sectionIndex];
var rows = {
const rows = {
both: section[DiffGroupType.BOTH] || null,
added: section[DiffGroupType.ADDED] || null,
removed: section[DiffGroupType.REMOVED] || null,
};
var highlights = {
const highlights = {
added: section[DiffHighlights.ADDED] || null,
removed: section[DiffHighlights.REMOVED] || null,
};
if (rows.both) { // If it's a shared section.
var sectionEnd = null;
let sectionEnd = null;
if (state.sectionIndex === 0) {
sectionEnd = 'first';
} else if (state.sectionIndex === content.length - 1) {
sectionEnd = 'last';
}
var sharedGroups = this._sharedGroupsFromRows(
const sharedGroups = this._sharedGroupsFromRows(
rows.both,
content.length > 1 ? this.context : WHOLE_FILE,
state.lineNums.left,
@@ -204,8 +204,7 @@
groups: sharedGroups,
};
} else { // Otherwise it's a delta section.
var deltaGroup = this._deltaGroupFromRows(
const deltaGroup = this._deltaGroupFromRows(
rows.added,
rows.removed,
state.lineNums.left,
@@ -234,14 +233,14 @@
* 'last' and null respectively.
* @return {Array<GrDiffGroup>}
*/
_sharedGroupsFromRows: function(rows, context, startLineNumLeft,
_sharedGroupsFromRows(rows, context, startLineNumLeft,
startLineNumRight, opt_sectionEnd) {
var result = [];
var lines = [];
var line;
const result = [];
const lines = [];
let line;
// Map each row to a GrDiffLine.
for (var i = 0; i < rows.length; i++) {
for (let i = 0; i < rows.length; i++) {
line = new GrDiffLine(GrDiffLine.Type.BOTH);
line.text = rows[i];
line.beforeNumber = ++startLineNumLeft;
@@ -252,7 +251,7 @@
// Find the hidden range based on the user's context preference. If this
// is the first or the last section of the diff, make sure the collapsed
// part of the section extends to the edge of the file.
var hiddenRange = [context, rows.length - context];
const hiddenRange = [context, rows.length - context];
if (opt_sectionEnd === 'first') {
hiddenRange[0] = 0;
} else if (opt_sectionEnd === 'last') {
@@ -261,15 +260,15 @@
// If there is a range to hide.
if (context !== WHOLE_FILE && hiddenRange[1] - hiddenRange[0] > 1) {
var linesBeforeCtx = lines.slice(0, hiddenRange[0]);
var hiddenLines = lines.slice(hiddenRange[0], hiddenRange[1]);
var linesAfterCtx = lines.slice(hiddenRange[1]);
const linesBeforeCtx = lines.slice(0, hiddenRange[0]);
const hiddenLines = lines.slice(hiddenRange[0], hiddenRange[1]);
const linesAfterCtx = lines.slice(hiddenRange[1]);
if (linesBeforeCtx.length > 0) {
result.push(new GrDiffGroup(GrDiffGroup.Type.BOTH, linesBeforeCtx));
}
var ctxLine = new GrDiffLine(GrDiffLine.Type.CONTEXT_CONTROL);
const ctxLine = new GrDiffLine(GrDiffLine.Type.CONTEXT_CONTROL);
ctxLine.contextGroup =
new GrDiffGroup(GrDiffGroup.Type.BOTH, hiddenLines);
result.push(new GrDiffGroup(GrDiffGroup.Type.CONTEXT_CONTROL,
@@ -294,9 +293,9 @@
* @param {Number} startLineNumRight
* @return {GrDiffGroup}
*/
_deltaGroupFromRows: function(rowsAdded, rowsRemoved, startLineNumLeft,
_deltaGroupFromRows(rowsAdded, rowsRemoved, startLineNumLeft,
startLineNumRight, highlights) {
var lines = [];
let lines = [];
if (rowsRemoved) {
lines = lines.concat(this._deltaLinesFromRows(GrDiffLine.Type.REMOVE,
rowsRemoved, startLineNumLeft, highlights.removed));
@@ -311,7 +310,7 @@
/**
* @return {Array<GrDiffLine>}
*/
_deltaLinesFromRows: function(lineType, rows, startLineNum,
_deltaLinesFromRows(lineType, rows, startLineNum,
opt_highlights) {
// Normalize highlights if they have been passed.
if (opt_highlights) {
@@ -319,9 +318,9 @@
opt_highlights);
}
var lines = [];
var line;
for (var i = 0; i < rows.length; i++) {
const lines = [];
let line;
for (let i = 0; i < rows.length; i++) {
line = new GrDiffLine(lineType);
line.text = rows[i];
if (lineType === GrDiffLine.Type.ADD) {
@@ -330,16 +329,15 @@
line.beforeNumber = ++startLineNum;
}
if (opt_highlights) {
line.highlights = opt_highlights.filter(
function(hl) { return hl.contentIndex === i; });
line.highlights = opt_highlights.filter(hl => hl.contentIndex === i);
}
lines.push(line);
}
return lines;
},
_makeFileComments: function() {
var line = new GrDiffLine(GrDiffLine.Type.BOTH);
_makeFileComments() {
const line = new GrDiffLine(GrDiffLine.Type.BOTH);
line.beforeNumber = GrDiffLine.FILE;
line.afterNumber = GrDiffLine.FILE;
return new GrDiffGroup(GrDiffGroup.Type.BOTH, [line]);
@@ -352,18 +350,18 @@
* @param {Object} content The diff content object.
* @return {Object} A new diff content object with regions split up.
*/
_splitCommonGroupsWithComments: function(content) {
var result = [];
var leftLineNum = 0;
var rightLineNum = 0;
_splitCommonGroupsWithComments(content) {
const result = [];
let leftLineNum = 0;
let rightLineNum = 0;
// If the context is set to "whole file", then break down the shared
// chunks so they can be rendered incrementally. Note: this is not enabled
// for any other context preference because manipulating the chunks in
// this way violates assumptions by the context grouper logic.
if (this.context === -1) {
var newContent = [];
content.forEach(function(group) {
const newContent = [];
for (const group of content) {
if (group.ab && group.ab.length > MAX_GROUP_SIZE * 2) {
// Split large shared groups in two, where the first is the maximum
// group size.
@@ -372,13 +370,12 @@
} else {
newContent.push(group);
}
}.bind(this));
}
content = newContent;
}
// For each section in the diff.
for (var i = 0; i < content.length; i++) {
for (let i = 0; i < content.length; i++) {
// If it isn't a common group, append it as-is and update line numbers.
if (!content[i].ab) {
if (content[i].a) {
@@ -388,25 +385,24 @@
rightLineNum += content[i].b.length;
}
this._breakdownGroup(content[i]).forEach(function(group) {
for (const group of this._breakdownGroup(content[i])) {
result.push(group);
});
}
continue;
}
var chunk = content[i].ab;
var currentChunk = {ab: []};
const chunk = content[i].ab;
let currentChunk = {ab: []};
// For each line in the common group.
for (var j = 0; j < chunk.length; j++) {
for (const subChunk of chunk) {
leftLineNum++;
rightLineNum++;
// If this line should not be collapsed.
if (this.keyLocations[DiffSide.LEFT][leftLineNum] ||
this.keyLocations[DiffSide.RIGHT][rightLineNum]) {
// If any lines have been accumulated into the chunk leading up to
// this non-collapse line, then add them as a chunk and start a new
// one.
@@ -416,10 +412,10 @@
}
// Add the non-collapse line as its own chunk.
result.push({ab: [chunk[j]]});
result.push({ab: [subChunk]});
} else {
// Append the current line to the current chunk.
currentChunk.ab.push(chunk[j]);
currentChunk.ab.push(subChunk);
}
}
@@ -449,14 +445,13 @@
* - endIndex: (optional) Where the highlight should end. If omitted, the
* highlight is meant to be a continuation onto the next line.
*/
_normalizeIntralineHighlights: function(content, highlights) {
var contentIndex = 0;
var idx = 0;
var normalized = [];
for (var i = 0; i < highlights.length; i++) {
var line = content[contentIndex] + '\n';
var hl = highlights[i];
var j = 0;
_normalizeIntralineHighlights(content, highlights) {
let contentIndex = 0;
let idx = 0;
const normalized = [];
for (const hl of highlights) {
let line = content[contentIndex] + '\n';
let j = 0;
while (j < hl[0]) {
if (idx === line.length) {
idx = 0;
@@ -466,8 +461,8 @@
idx++;
j++;
}
var lineHighlight = {
contentIndex: contentIndex,
let lineHighlight = {
contentIndex,
startIndex: idx,
};
@@ -478,7 +473,7 @@
line = content[++contentIndex] + '\n';
normalized.push(lineHighlight);
lineHighlight = {
contentIndex: contentIndex,
contentIndex,
startIndex: idx,
};
continue;
@@ -499,8 +494,8 @@
* @param {!Object} A raw chunk from a diff response.
* @return {!Array<!Array<!Object>>}
*/
_breakdownGroup: function(group) {
var key = null;
_breakdownGroup(group) {
let key = null;
if (group.a && !group.b) {
key = 'a';
} else if (group.b && !group.a) {
@@ -512,11 +507,11 @@
if (!key) { return [group]; }
return this._breakdown(group[key], MAX_GROUP_SIZE)
.map(function(subgroupLines) {
var subGroup = {};
subGroup[key] = subgroupLines;
return subGroup;
});
.map(subgroupLines => {
const subGroup = {};
subGroup[key] = subgroupLines;
return subGroup;
});
},
/**
@@ -527,12 +522,12 @@
* @return {!Array<!Array<T>>}
* @template T
*/
_breakdown: function(array, size) {
_breakdown(array, size) {
if (!array.length) { return []; }
if (array.length < size) { return [array]; }
var head = array.slice(0, array.length - size);
var tail = array.slice(array.length - size);
const head = array.slice(0, array.length - size);
const tail = array.slice(array.length - size);
return this._breakdown(head, size).concat([tail]);
},

View File

@@ -33,40 +33,40 @@ limitations under the License.
</test-fixture>
<script>
suite('gr-diff-processor tests', function() {
var WHOLE_FILE = -1;
var loremIpsum = 'Lorem ipsum dolor sit amet, ei nonumes vituperata ius. ' +
suite('gr-diff-processor tests', () => {
const WHOLE_FILE = -1;
const loremIpsum =
'Lorem ipsum dolor sit amet, ei nonumes vituperata ius. ' +
'Duo animal omnesque fabellas et. Id has phaedrum dignissim ' +
'deterruisset, pro ei petentium comprehensam, ut vis solum dicta. ' +
'Eos cu aliquam labores qualisque, usu postea inermis te, et solum ' +
'fugit assum per.';
var element;
var sandbox;
let element;
let sandbox;
setup(function() {
setup(() => {
sandbox = sinon.sandbox.create();
});
teardown(function() {
teardown(() => {
sandbox.restore();
});
suite('not logged in', function() {
setup(function() {
suite('not logged in', () => {
setup(() => {
element = fixture('basic');
element.context = 4;
});
test('process loaded content', function(done) {
var content = [
test('process loaded content', done => {
const content = [
{
ab: [
'<!DOCTYPE html>',
'<meta charset="utf-8">',
]
],
},
{
a: [
@@ -82,16 +82,16 @@ limitations under the License.
'Leela: This is the only place the ship cant hear us, so ',
'everyone pretend to shower.',
'Fry: Same as every day. Got it.',
]
],
},
];
element.process(content).then(function() {
var groups = element.groups;
element.process(content).then(() => {
const groups = element.groups;
assert.equal(groups.length, 4);
var group = groups[0];
let group = groups[0];
assert.equal(group.type, GrDiffGroup.Type.BOTH);
assert.equal(group.lines.length, 1);
assert.equal(group.lines[0].text, '');
@@ -144,27 +144,27 @@ limitations under the License.
});
});
test('insert context groups', function(done) {
var content = [
test('insert context groups', done => {
const content = [
{ab: []},
{a: ['all work and no play make andybons a dull boy']},
{ab: []},
{b: ['elgoog elgoog elgoog']},
{ab: []},
];
for (var i = 0; i < 100; i++) {
for (let i = 0; i < 100; i++) {
content[0].ab.push('all work and no play make jack a dull boy');
content[4].ab.push('all work and no play make jill a dull girl');
}
for (var i = 0; i < 5; i++) {
for (let i = 0; i < 5; i++) {
content[2].ab.push('no tv and no beer make homer go crazy');
}
var context = 10;
const context = 10;
element.context = context;
element.process(content).then(function() {
var groups = element.groups;
element.process(content).then(() => {
const groups = element.groups;
assert.equal(groups[0].type, GrDiffGroup.Type.BOTH);
assert.equal(groups[0].lines.length, 1);
@@ -175,15 +175,15 @@ limitations under the License.
assert.equal(groups[1].type, GrDiffGroup.Type.CONTEXT_CONTROL);
assert.instanceOf(groups[1].lines[0].contextGroup, GrDiffGroup);
assert.equal(groups[1].lines[0].contextGroup.lines.length, 90);
groups[1].lines[0].contextGroup.lines.forEach(function(l) {
for (const l of groups[1].lines[0].contextGroup.lines) {
assert.equal(l.text, content[0].ab[0]);
});
}
assert.equal(groups[2].type, GrDiffGroup.Type.BOTH);
assert.equal(groups[2].lines.length, context);
groups[2].lines.forEach(function(l) {
for (const l of groups[2].lines) {
assert.equal(l.text, content[0].ab[0]);
});
}
assert.equal(groups[3].type, GrDiffGroup.Type.DELTA);
assert.equal(groups[3].lines.length, 1);
@@ -193,9 +193,9 @@ limitations under the License.
assert.equal(groups[4].type, GrDiffGroup.Type.BOTH);
assert.equal(groups[4].lines.length, 5);
groups[4].lines.forEach(function(l) {
for (const l of groups[4].lines) {
assert.equal(l.text, content[2].ab[0]);
});
}
assert.equal(groups[5].type, GrDiffGroup.Type.DELTA);
assert.equal(groups[5].lines.length, 1);
@@ -204,36 +204,36 @@ limitations under the License.
assert.equal(groups[6].type, GrDiffGroup.Type.BOTH);
assert.equal(groups[6].lines.length, context);
groups[6].lines.forEach(function(l) {
for (const l of groups[6].lines) {
assert.equal(l.text, content[4].ab[0]);
});
}
assert.equal(groups[7].type, GrDiffGroup.Type.CONTEXT_CONTROL);
assert.instanceOf(groups[7].lines[0].contextGroup, GrDiffGroup);
assert.equal(groups[7].lines[0].contextGroup.lines.length, 90);
groups[7].lines[0].contextGroup.lines.forEach(function(l) {
for (const l of groups[7].lines[0].contextGroup.lines) {
assert.equal(l.text, content[4].ab[0]);
});
}
done();
});
});
test('insert context groups', function(done) {
var content = [
test('insert context groups', done => {
const content = [
{a: ['all work and no play make andybons a dull boy']},
{ab: []},
{b: ['elgoog elgoog elgoog']},
];
for (var i = 0; i < 50; i++) {
for (let i = 0; i < 50; i++) {
content[1].ab.push('no tv and no beer make homer go crazy');
}
var context = 10;
const context = 10;
element.context = context;
element.process(content).then(function() {
var groups = element.groups;
element.process(content).then(() => {
const groups = element.groups;
assert.equal(groups[0].type, GrDiffGroup.Type.BOTH);
assert.equal(groups[0].lines.length, 1);
@@ -249,22 +249,22 @@ limitations under the License.
assert.equal(groups[2].type, GrDiffGroup.Type.BOTH);
assert.equal(groups[2].lines.length, context);
groups[2].lines.forEach(function(l) {
for (const l of groups[2].lines) {
assert.equal(l.text, content[1].ab[0]);
});
}
assert.equal(groups[3].type, GrDiffGroup.Type.CONTEXT_CONTROL);
assert.instanceOf(groups[3].lines[0].contextGroup, GrDiffGroup);
assert.equal(groups[3].lines[0].contextGroup.lines.length, 30);
groups[3].lines[0].contextGroup.lines.forEach(function(l) {
for (const l of groups[3].lines[0].contextGroup.lines) {
assert.equal(l.text, content[1].ab[0]);
});
}
assert.equal(groups[4].type, GrDiffGroup.Type.BOTH);
assert.equal(groups[4].lines.length, context);
groups[4].lines.forEach(function(l) {
for (const l of groups[4].lines) {
assert.equal(l.text, content[1].ab[0]);
});
}
assert.equal(groups[5].type, GrDiffGroup.Type.DELTA);
assert.equal(groups[5].lines.length, 1);
@@ -275,14 +275,14 @@ limitations under the License.
});
});
test('break up common diff chunks', function() {
test('break up common diff chunks', () => {
element.keyLocations = {
left: {1: true},
right: {10: true},
};
var lineNums = {left: 0, right: 0};
const lineNums = {left: 0, right: 0};
var content = [
const content = [
{
ab: [
'Copyright (C) 2015 The Android Open Source Project',
@@ -300,10 +300,11 @@ limitations under the License.
'either express or implied. See the License for the specific ',
'language governing permissions and limitations under the ' +
'License.',
]
}
],
},
];
var result = element._splitCommonGroupsWithComments(content, lineNums);
const result =
element._splitCommonGroupsWithComments(content, lineNums);
assert.deepEqual(result, [
{
ab: ['Copyright (C) 2015 The Android Open Source Project'],
@@ -319,11 +320,11 @@ limitations under the License.
'http://www.apache.org/licenses/LICENSE-2.0',
'',
'Unless required by applicable law or agreed to in writing, ',
]
],
},
{
ab: [
'software distributed under the License is distributed on an '],
'software distributed under the License is distributed on an '],
},
{
ab: [
@@ -331,48 +332,50 @@ limitations under the License.
'either express or implied. See the License for the specific ',
'language governing permissions and limitations under the ' +
'License.',
]
}
],
},
]);
});
test('breaks-down shared chunks w/ whole-file', function() {
var size = 120 * 2 + 5;
var lineNums = {left: 0, right: 0};
var content = [{
ab: _.times(size, function() { return '' + Math.random(); }),
test('breaks-down shared chunks w/ whole-file', () => {
const size = 120 * 2 + 5;
const lineNums = {left: 0, right: 0};
const content = [{
ab: _.times(size, () => { return `${Math.random()}`; }),
}];
element.context = -1;
var result = element._splitCommonGroupsWithComments(content, lineNums);
const result =
element._splitCommonGroupsWithComments(content, lineNums);
assert.equal(result.length, 2);
assert.deepEqual(result[0].ab, content[0].ab.slice(0, 120));
assert.deepEqual(result[1].ab, content[0].ab.slice(120));
});
test('does not break-down shared chunks w/ context', function() {
var lineNums = {left: 0, right: 0};
var content = [{
ab: _.times(75, function() { return '' + Math.random(); }),
test('does not break-down shared chunks w/ context', () => {
const lineNums = {left: 0, right: 0};
const content = [{
ab: _.times(75, () => { return `${Math.random()}`; }),
}];
element.context = 4;
var result = element._splitCommonGroupsWithComments(content, lineNums);
const result =
element._splitCommonGroupsWithComments(content, lineNums);
assert.deepEqual(result, content);
});
test('intraline normalization', function() {
test('intraline normalization', () => {
// The content and highlights are in the format returned by the Gerrit
// REST API.
var content = [
let content = [
' <section class="summary">',
' <gr-linked-text content="' +
'[[_computeCurrentRevisionMessage(change)]]"></gr-linked-text>',
' </section>',
];
var highlights = [
[31, 34], [42, 26]
let highlights = [
[31, 34], [42, 26],
];
var results = element._normalizeIntralineHighlights(content,
let results = element._normalizeIntralineHighlights(content,
highlights);
assert.deepEqual(results, [
{
@@ -392,7 +395,7 @@ limitations under the License.
contentIndex: 2,
startIndex: 0,
endIndex: 6,
}
},
]);
content = [
@@ -439,18 +442,18 @@ limitations under the License.
contentIndex: 5,
startIndex: 12,
endIndex: 41,
}
},
]);
});
test('scrolling pauses rendering', function() {
var contentRow = {
test('scrolling pauses rendering', () => {
const contentRow = {
ab: [
'<!DOCTYPE html>',
'<meta charset="utf-8">',
]
],
};
var content = _.times(200, _.constant(contentRow));
const content = _.times(200, _.constant(contentRow));
sandbox.stub(element, 'async');
element._isScrolling = true;
element.process(content);
@@ -460,14 +463,14 @@ limitations under the License.
assert.equal(element.groups.length, 33);
});
test('image diffs', function() {
var contentRow = {
test('image diffs', () => {
const contentRow = {
ab: [
'<!DOCTYPE html>',
'<meta charset="utf-8">',
]
],
};
var content = _.times(200, _.constant(contentRow));
const content = _.times(200, _.constant(contentRow));
sandbox.stub(element, 'async');
element.process(content, true);
assert.equal(element.groups.length, 1);
@@ -477,17 +480,17 @@ limitations under the License.
});
suite('gr-diff-processor helpers', function() {
var rows;
suite('gr-diff-processor helpers', () => {
let rows;
setup(function() {
setup(() => {
rows = loremIpsum.split(' ');
});
test('_sharedGroupsFromRows WHOLE_FILE', function() {
var context = WHOLE_FILE;
var lineNumbers = {left: 10, right: 100};
var result = element._sharedGroupsFromRows(
test('_sharedGroupsFromRows WHOLE_FILE', () => {
const context = WHOLE_FILE;
const lineNumbers = {left: 10, right: 100};
const result = element._sharedGroupsFromRows(
rows, context, lineNumbers.left, lineNumbers.right, null);
// Results in one, uncollapsed group with all rows.
@@ -505,11 +508,11 @@ limitations under the License.
lineNumbers.right + rows.length);
});
test('_sharedGroupsFromRows context', function() {
var context = 10;
var result = element._sharedGroupsFromRows(
test('_sharedGroupsFromRows context', () => {
const context = 10;
const result = element._sharedGroupsFromRows(
rows, context, 10, 100, null);
var expectedCollapseSize = rows.length - 2 * context;
const expectedCollapseSize = rows.length - 2 * context;
assert.equal(result.length, 3, 'Results in three groups');
@@ -524,11 +527,11 @@ limitations under the License.
expectedCollapseSize);
});
test('_sharedGroupsFromRows first', function() {
var context = 10;
var result = element._sharedGroupsFromRows(
test('_sharedGroupsFromRows first', () => {
const context = 10;
const result = element._sharedGroupsFromRows(
rows, context, 10, 100, 'first');
var expectedCollapseSize = rows.length - context;
const expectedCollapseSize = rows.length - context;
assert.equal(result.length, 2, 'Results in two groups');
@@ -541,11 +544,11 @@ limitations under the License.
expectedCollapseSize);
});
test('_sharedGroupsFromRows few-rows', function() {
test('_sharedGroupsFromRows few-rows', () => {
// Only ten rows.
rows = rows.slice(0, 10);
var context = 10;
var result = element._sharedGroupsFromRows(
const context = 10;
const result = element._sharedGroupsFromRows(
rows, context, 10, 100, 'first');
// Results in one uncollapsed group with all rows.
@@ -553,10 +556,10 @@ limitations under the License.
assert.equal(result[0].lines.length, rows.length);
});
test('_sharedGroupsFromRows no single line collapse', function() {
test('_sharedGroupsFromRows no single line collapse', () => {
rows = rows.slice(0, 7);
var context = 3;
var result = element._sharedGroupsFromRows(
const context = 3;
const result = element._sharedGroupsFromRows(
rows, context, 10, 100);
// Results in one uncollapsed group with all rows.
@@ -564,9 +567,9 @@ limitations under the License.
assert.equal(result[0].lines.length, rows.length);
});
test('_deltaLinesFromRows', function() {
var startLineNum = 10;
var result = element._deltaLinesFromRows(GrDiffLine.Type.ADD, rows,
test('_deltaLinesFromRows', () => {
const startLineNum = 10;
let result = element._deltaLinesFromRows(GrDiffLine.Type.ADD, rows,
startLineNum);
assert.equal(result.length, rows.length);
@@ -590,54 +593,54 @@ limitations under the License.
});
});
suite('_breakdown*', function() {
test('_breakdownGroup breaks down additions', function() {
suite('_breakdown*', () => {
test('_breakdownGroup breaks down additions', () => {
sandbox.spy(element, '_breakdown');
var chunk = {b: ['blah', 'blah', 'blah']};
var result = element._breakdownGroup(chunk);
const chunk = {b: ['blah', 'blah', 'blah']};
const result = element._breakdownGroup(chunk);
assert.deepEqual(result, [chunk]);
assert.isTrue(element._breakdown.called);
});
test('_breakdown common case', function() {
var array = 'Lorem ipsum dolor sit amet, suspendisse inceptos'
test('_breakdown common case', () => {
const array = 'Lorem ipsum dolor sit amet, suspendisse inceptos'
.split(' ');
var size = 3;
const size = 3;
var result = element._breakdown(array, size);
const result = element._breakdown(array, size);
result.forEach(function(subResult) {
for (const subResult of result) {
assert.isAtMost(subResult.length, size);
});
var flattened = result
.reduce(function(a, b) { return a.concat(b); }, []);
}
const flattened = result
.reduce((a, b) => { return a.concat(b); }, []);
assert.deepEqual(flattened, array);
});
test('_breakdown smaller than size', function() {
var array = 'Lorem ipsum dolor sit amet, suspendisse inceptos'
test('_breakdown smaller than size', () => {
const array = 'Lorem ipsum dolor sit amet, suspendisse inceptos'
.split(' ');
var size = 10;
var expected = [array];
const size = 10;
const expected = [array];
var result = element._breakdown(array, size);
const result = element._breakdown(array, size);
assert.deepEqual(result, expected);
});
test('_breakdown empty', function() {
var array = [];
var size = 10;
var expected = [];
test('_breakdown empty', () => {
const array = [];
const size = 10;
const expected = [];
var result = element._breakdown(array, size);
const result = element._breakdown(array, size);
assert.deepEqual(result, expected);
});
});
});
test('detaching cancels', function() {
test('detaching cancels', () => {
element = fixture('basic');
sandbox.stub(element, 'cancel');
element.detached();