Revert "ES6ify /gr-diff-processor/*"
This reverts commit fb62c1768184698f6855851cd202c0389cbce591.
Reason for revert: Incorrectly added file
Change-Id: I4970d5b796a8b3ae59368445223323b529516ca0
diff --git a/polygerrit-ui/app/.eslintrc.json b/polygerrit-ui/app/.eslintrc.json
index 205370d..8c4ee99 100644
--- a/polygerrit-ui/app/.eslintrc.json
+++ b/polygerrit-ui/app/.eslintrc.json
@@ -58,7 +58,6 @@
"prefer-arrow-callback": "error",
"prefer-const": "error",
"prefer-spread": "error",
- "prefer-template": "error",
"quote-props": ["error", "consistent-as-needed"],
"require-jsdoc": "off",
"semi": [2, "always"],
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-processor/gr-diff-processor.js b/polygerrit-ui/app/elements/diff/gr-diff-processor/gr-diff-processor.js
index 32ccfff..30d01cb 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-processor/gr-diff-processor.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-processor/gr-diff-processor.js
@@ -14,20 +14,20 @@
(function() {
'use strict';
- const WHOLE_FILE = -1;
+ var WHOLE_FILE = -1;
- const DiffSide = {
+ var DiffSide = {
LEFT: 'left',
RIGHT: 'right',
};
- const DiffGroupType = {
+ var DiffGroupType = {
ADDED: 'b',
BOTH: 'ab',
REMOVED: 'a',
};
- const DiffHighlights = {
+ var 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.
*/
- const MAX_GROUP_SIZE = 120;
+ var MAX_GROUP_SIZE = 120;
Polymer({
is: 'gr-diff-processor',
@@ -66,7 +66,7 @@
*/
keyLocations: {
type: Object,
- value() { return {left: {}, right: {}}; },
+ value: function() { return {left: {}, right: {}}; },
},
/**
@@ -81,18 +81,18 @@
_isScrolling: Boolean,
},
- attached() {
+ attached: function() {
this.listen(window, 'scroll', '_handleWindowScroll');
},
- detached() {
+ detached: function() {
this.cancel();
this.unlisten(window, 'scroll', '_handleWindowScroll');
},
- _handleWindowScroll() {
+ _handleWindowScroll: function() {
this._isScrolling = true;
- this.debounce('resetIsScrolling', () => {
+ this.debounce('resetIsScrolling', function() {
this._isScrolling = false;
}, 50);
},
@@ -103,23 +103,23 @@
* @return {Promise} A promise that resolves when the diff is completely
* processed.
*/
- process(content, isImageDiff) {
+ process: function(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(resolve => {
- const state = {
+ return new Promise(function(resolve) {
+ var state = {
lineNums: {left: 0, right: 0},
sectionIndex: 0,
};
content = this._splitCommonGroupsWithComments(content);
- let currentBatch = 0;
- const nextStep = () => {
+ var currentBatch = 0;
+ var nextStep = function() {
if (this._isScrolling) {
this.async(nextStep, 100);
return;
@@ -132,11 +132,11 @@
}
// Process the next section and incorporate the result.
- const result = this._processNext(state, content);
- for (const group of result.groups) {
+ var result = this._processNext(state, content);
+ result.groups.forEach(function(group) {
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() {
+ cancel: function() {
if (this._nextStepHandle !== undefined) {
this.cancelAsync(this._nextStepHandle);
this._nextStepHandle = undefined;
@@ -167,29 +167,29 @@
/**
* Process the next section of the diff.
*/
- _processNext(state, content) {
- const section = content[state.sectionIndex];
+ _processNext: function(state, content) {
+ var section = content[state.sectionIndex];
- const rows = {
+ var rows = {
both: section[DiffGroupType.BOTH] || null,
added: section[DiffGroupType.ADDED] || null,
removed: section[DiffGroupType.REMOVED] || null,
};
- const highlights = {
+ var highlights = {
added: section[DiffHighlights.ADDED] || null,
removed: section[DiffHighlights.REMOVED] || null,
};
if (rows.both) { // If it's a shared section.
- let sectionEnd = null;
+ var sectionEnd = null;
if (state.sectionIndex === 0) {
sectionEnd = 'first';
} else if (state.sectionIndex === content.length - 1) {
sectionEnd = 'last';
}
- const sharedGroups = this._sharedGroupsFromRows(
+ var sharedGroups = this._sharedGroupsFromRows(
rows.both,
content.length > 1 ? this.context : WHOLE_FILE,
state.lineNums.left,
@@ -204,7 +204,8 @@
groups: sharedGroups,
};
} else { // Otherwise it's a delta section.
- const deltaGroup = this._deltaGroupFromRows(
+
+ var deltaGroup = this._deltaGroupFromRows(
rows.added,
rows.removed,
state.lineNums.left,
@@ -233,14 +234,14 @@
* 'last' and null respectively.
* @return {Array<GrDiffGroup>}
*/
- _sharedGroupsFromRows(rows, context, startLineNumLeft,
+ _sharedGroupsFromRows: function(rows, context, startLineNumLeft,
startLineNumRight, opt_sectionEnd) {
- const result = [];
- const lines = [];
- let line;
+ var result = [];
+ var lines = [];
+ var line;
// Map each row to a GrDiffLine.
- for (let i = 0; i < rows.length; i++) {
+ for (var i = 0; i < rows.length; i++) {
line = new GrDiffLine(GrDiffLine.Type.BOTH);
line.text = rows[i];
line.beforeNumber = ++startLineNumLeft;
@@ -251,7 +252,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.
- const hiddenRange = [context, rows.length - context];
+ var hiddenRange = [context, rows.length - context];
if (opt_sectionEnd === 'first') {
hiddenRange[0] = 0;
} else if (opt_sectionEnd === 'last') {
@@ -260,15 +261,15 @@
// If there is a range to hide.
if (context !== WHOLE_FILE && hiddenRange[1] - hiddenRange[0] > 1) {
- const linesBeforeCtx = lines.slice(0, hiddenRange[0]);
- const hiddenLines = lines.slice(hiddenRange[0], hiddenRange[1]);
- const linesAfterCtx = lines.slice(hiddenRange[1]);
+ var linesBeforeCtx = lines.slice(0, hiddenRange[0]);
+ var hiddenLines = lines.slice(hiddenRange[0], hiddenRange[1]);
+ var linesAfterCtx = lines.slice(hiddenRange[1]);
if (linesBeforeCtx.length > 0) {
result.push(new GrDiffGroup(GrDiffGroup.Type.BOTH, linesBeforeCtx));
}
- const ctxLine = new GrDiffLine(GrDiffLine.Type.CONTEXT_CONTROL);
+ var ctxLine = new GrDiffLine(GrDiffLine.Type.CONTEXT_CONTROL);
ctxLine.contextGroup =
new GrDiffGroup(GrDiffGroup.Type.BOTH, hiddenLines);
result.push(new GrDiffGroup(GrDiffGroup.Type.CONTEXT_CONTROL,
@@ -293,9 +294,9 @@
* @param {Number} startLineNumRight
* @return {GrDiffGroup}
*/
- _deltaGroupFromRows(rowsAdded, rowsRemoved, startLineNumLeft,
+ _deltaGroupFromRows: function(rowsAdded, rowsRemoved, startLineNumLeft,
startLineNumRight, highlights) {
- let lines = [];
+ var lines = [];
if (rowsRemoved) {
lines = lines.concat(this._deltaLinesFromRows(GrDiffLine.Type.REMOVE,
rowsRemoved, startLineNumLeft, highlights.removed));
@@ -310,7 +311,7 @@
/**
* @return {Array<GrDiffLine>}
*/
- _deltaLinesFromRows(lineType, rows, startLineNum,
+ _deltaLinesFromRows: function(lineType, rows, startLineNum,
opt_highlights) {
// Normalize highlights if they have been passed.
if (opt_highlights) {
@@ -318,9 +319,9 @@
opt_highlights);
}
- const lines = [];
- let line;
- for (let i = 0; i < rows.length; i++) {
+ var lines = [];
+ var line;
+ for (var i = 0; i < rows.length; i++) {
line = new GrDiffLine(lineType);
line.text = rows[i];
if (lineType === GrDiffLine.Type.ADD) {
@@ -329,15 +330,16 @@
line.beforeNumber = ++startLineNum;
}
if (opt_highlights) {
- line.highlights = opt_highlights.filter(hl => hl.contentIndex === i);
+ line.highlights = opt_highlights.filter(
+ function(hl) { return hl.contentIndex === i; });
}
lines.push(line);
}
return lines;
},
- _makeFileComments() {
- const line = new GrDiffLine(GrDiffLine.Type.BOTH);
+ _makeFileComments: function() {
+ var line = new GrDiffLine(GrDiffLine.Type.BOTH);
line.beforeNumber = GrDiffLine.FILE;
line.afterNumber = GrDiffLine.FILE;
return new GrDiffGroup(GrDiffGroup.Type.BOTH, [line]);
@@ -350,18 +352,18 @@
* @param {Object} content The diff content object.
* @return {Object} A new diff content object with regions split up.
*/
- _splitCommonGroupsWithComments(content) {
- const result = [];
- let leftLineNum = 0;
- let rightLineNum = 0;
+ _splitCommonGroupsWithComments: function(content) {
+ var result = [];
+ var leftLineNum = 0;
+ var 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) {
- const newContent = [];
- for (const group of content) {
+ var newContent = [];
+ content.forEach(function(group) {
if (group.ab && group.ab.length > MAX_GROUP_SIZE * 2) {
// Split large shared groups in two, where the first is the maximum
// group size.
@@ -370,12 +372,13 @@
} else {
newContent.push(group);
}
- }
+ }.bind(this));
content = newContent;
}
// For each section in the diff.
- for (let i = 0; i < content.length; i++) {
+ for (var 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) {
@@ -385,24 +388,25 @@
rightLineNum += content[i].b.length;
}
- for (const group of this._breakdownGroup(content[i])) {
+ this._breakdownGroup(content[i]).forEach(function(group) {
result.push(group);
- }
+ });
continue;
}
- const chunk = content[i].ab;
- let currentChunk = {ab: []};
+ var chunk = content[i].ab;
+ var currentChunk = {ab: []};
// For each line in the common group.
- for (const subChunk of chunk) {
+ for (var j = 0; j < chunk.length; j++) {
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.
@@ -412,10 +416,10 @@
}
// Add the non-collapse line as its own chunk.
- result.push({ab: [subChunk]});
+ result.push({ab: [chunk[j]]});
} else {
// Append the current line to the current chunk.
- currentChunk.ab.push(subChunk);
+ currentChunk.ab.push(chunk[j]);
}
}
@@ -445,24 +449,25 @@
* - endIndex: (optional) Where the highlight should end. If omitted, the
* highlight is meant to be a continuation onto the next line.
*/
- _normalizeIntralineHighlights(content, highlights) {
- let contentIndex = 0;
- let idx = 0;
- const normalized = [];
- for (const hl of highlights) {
- let line = `${content[contentIndex]}\n`;
- let j = 0;
+ _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;
while (j < hl[0]) {
if (idx === line.length) {
idx = 0;
- line = `${content[++contentIndex]}\n`;
+ line = content[++contentIndex] + '\n';
continue;
}
idx++;
j++;
}
- let lineHighlight = {
- contentIndex,
+ var lineHighlight = {
+ contentIndex: contentIndex,
startIndex: idx,
};
@@ -470,10 +475,10 @@
while (line && j < hl[1]) {
if (idx === line.length) {
idx = 0;
- line = `${content[++contentIndex]}\n`;
+ line = content[++contentIndex] + '\n';
normalized.push(lineHighlight);
lineHighlight = {
- contentIndex,
+ contentIndex: contentIndex,
startIndex: idx,
};
continue;
@@ -494,8 +499,8 @@
* @param {!Object} A raw chunk from a diff response.
* @return {!Array<!Array<!Object>>}
*/
- _breakdownGroup(group) {
- let key = null;
+ _breakdownGroup: function(group) {
+ var key = null;
if (group.a && !group.b) {
key = 'a';
} else if (group.b && !group.a) {
@@ -507,11 +512,11 @@
if (!key) { return [group]; }
return this._breakdown(group[key], MAX_GROUP_SIZE)
- .map(subgroupLines => {
- const subGroup = {};
- subGroup[key] = subgroupLines;
- return subGroup;
- });
+ .map(function(subgroupLines) {
+ var subGroup = {};
+ subGroup[key] = subgroupLines;
+ return subGroup;
+ });
},
/**
@@ -522,12 +527,12 @@
* @return {!Array<!Array<T>>}
* @template T
*/
- _breakdown(array, size) {
+ _breakdown: function(array, size) {
if (!array.length) { return []; }
if (array.length < size) { return [array]; }
- const head = array.slice(0, array.length - size);
- const tail = array.slice(array.length - size);
+ var head = array.slice(0, array.length - size);
+ var tail = array.slice(array.length - size);
return this._breakdown(head, size).concat([tail]);
},
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-processor/gr-diff-processor_test.html b/polygerrit-ui/app/elements/diff/gr-diff-processor/gr-diff-processor_test.html
index 4785351..1a5ccc5 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-processor/gr-diff-processor_test.html
+++ b/polygerrit-ui/app/elements/diff/gr-diff-processor/gr-diff-processor_test.html
@@ -33,40 +33,40 @@
</test-fixture>
<script>
- suite('gr-diff-processor tests', () => {
- const WHOLE_FILE = -1;
- const loremIpsum =
- 'Lorem ipsum dolor sit amet, ei nonumes vituperata ius. ' +
+ suite('gr-diff-processor tests', function() {
+ var WHOLE_FILE = -1;
+ var 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.';
- let element;
- let sandbox;
+ var element;
+ var sandbox;
- setup(() => {
+ setup(function() {
sandbox = sinon.sandbox.create();
});
- teardown(() => {
+ teardown(function() {
sandbox.restore();
});
- suite('not logged in', () => {
- setup(() => {
+ suite('not logged in', function() {
+
+ setup(function() {
element = fixture('basic');
element.context = 4;
});
- test('process loaded content', done => {
- const content = [
+ test('process loaded content', function(done) {
+ var content = [
{
ab: [
'<!DOCTYPE html>',
'<meta charset="utf-8">',
- ],
+ ]
},
{
a: [
@@ -82,16 +82,16 @@
'Leela: This is the only place the ship can’t hear us, so ',
'everyone pretend to shower.',
'Fry: Same as every day. Got it.',
- ],
+ ]
},
];
- element.process(content).then(() => {
- const groups = element.groups;
+ element.process(content).then(function() {
+ var groups = element.groups;
assert.equal(groups.length, 4);
- let group = groups[0];
+ var 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 @@
});
});
- test('insert context groups', done => {
- const content = [
+ test('insert context groups', function(done) {
+ var content = [
{ab: []},
{a: ['all work and no play make andybons a dull boy']},
{ab: []},
{b: ['elgoog elgoog elgoog']},
{ab: []},
];
- for (let i = 0; i < 100; i++) {
+ for (var 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 (let i = 0; i < 5; i++) {
+ for (var i = 0; i < 5; i++) {
content[2].ab.push('no tv and no beer make homer go crazy');
}
- const context = 10;
+ var context = 10;
element.context = context;
- element.process(content).then(() => {
- const groups = element.groups;
+ element.process(content).then(function() {
+ var groups = element.groups;
assert.equal(groups[0].type, GrDiffGroup.Type.BOTH);
assert.equal(groups[0].lines.length, 1);
@@ -175,15 +175,15 @@
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);
- for (const l of groups[1].lines[0].contextGroup.lines) {
+ groups[1].lines[0].contextGroup.lines.forEach(function(l) {
assert.equal(l.text, content[0].ab[0]);
- }
+ });
assert.equal(groups[2].type, GrDiffGroup.Type.BOTH);
assert.equal(groups[2].lines.length, context);
- for (const l of groups[2].lines) {
+ groups[2].lines.forEach(function(l) {
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 @@
assert.equal(groups[4].type, GrDiffGroup.Type.BOTH);
assert.equal(groups[4].lines.length, 5);
- for (const l of groups[4].lines) {
+ groups[4].lines.forEach(function(l) {
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 @@
assert.equal(groups[6].type, GrDiffGroup.Type.BOTH);
assert.equal(groups[6].lines.length, context);
- for (const l of groups[6].lines) {
+ groups[6].lines.forEach(function(l) {
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);
- for (const l of groups[7].lines[0].contextGroup.lines) {
+ groups[7].lines[0].contextGroup.lines.forEach(function(l) {
assert.equal(l.text, content[4].ab[0]);
- }
+ });
done();
});
});
- test('insert context groups', done => {
- const content = [
+ test('insert context groups', function(done) {
+ var content = [
{a: ['all work and no play make andybons a dull boy']},
{ab: []},
{b: ['elgoog elgoog elgoog']},
];
- for (let i = 0; i < 50; i++) {
+ for (var i = 0; i < 50; i++) {
content[1].ab.push('no tv and no beer make homer go crazy');
}
- const context = 10;
+ var context = 10;
element.context = context;
- element.process(content).then(() => {
- const groups = element.groups;
+ element.process(content).then(function() {
+ var groups = element.groups;
assert.equal(groups[0].type, GrDiffGroup.Type.BOTH);
assert.equal(groups[0].lines.length, 1);
@@ -249,22 +249,22 @@
assert.equal(groups[2].type, GrDiffGroup.Type.BOTH);
assert.equal(groups[2].lines.length, context);
- for (const l of groups[2].lines) {
+ groups[2].lines.forEach(function(l) {
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);
- for (const l of groups[3].lines[0].contextGroup.lines) {
+ groups[3].lines[0].contextGroup.lines.forEach(function(l) {
assert.equal(l.text, content[1].ab[0]);
- }
+ });
assert.equal(groups[4].type, GrDiffGroup.Type.BOTH);
assert.equal(groups[4].lines.length, context);
- for (const l of groups[4].lines) {
+ groups[4].lines.forEach(function(l) {
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 @@
});
});
- test('break up common diff chunks', () => {
+ test('break up common diff chunks', function() {
element.keyLocations = {
left: {1: true},
right: {10: true},
};
- const lineNums = {left: 0, right: 0};
+ var lineNums = {left: 0, right: 0};
- const content = [
+ var content = [
{
ab: [
'Copyright (C) 2015 The Android Open Source Project',
@@ -300,11 +300,10 @@
'either express or implied. See the License for the specific ',
'language governing permissions and limitations under the ' +
'License.',
- ],
- },
+ ]
+ }
];
- const result =
- element._splitCommonGroupsWithComments(content, lineNums);
+ var result = element._splitCommonGroupsWithComments(content, lineNums);
assert.deepEqual(result, [
{
ab: ['Copyright (C) 2015 The Android Open Source Project'],
@@ -320,11 +319,11 @@
'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: [
@@ -332,50 +331,48 @@
'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', () => {
- const size = 120 * 2 + 5;
- const lineNums = {left: 0, right: 0};
- const content = [{
- ab: _.times(size, () => { return `${Math.random()}`; }),
+ 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(); }),
}];
element.context = -1;
- const result =
- element._splitCommonGroupsWithComments(content, lineNums);
+ var 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', () => {
- const lineNums = {left: 0, right: 0};
- const content = [{
- ab: _.times(75, () => { return `${Math.random()}`; }),
+ 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(); }),
}];
element.context = 4;
- const result =
- element._splitCommonGroupsWithComments(content, lineNums);
+ var result = element._splitCommonGroupsWithComments(content, lineNums);
assert.deepEqual(result, content);
});
- test('intraline normalization', () => {
+ test('intraline normalization', function() {
// The content and highlights are in the format returned by the Gerrit
// REST API.
- let content = [
+ var content = [
' <section class="summary">',
' <gr-linked-text content="' +
'[[_computeCurrentRevisionMessage(change)]]"></gr-linked-text>',
' </section>',
];
- let highlights = [
- [31, 34], [42, 26],
+ var highlights = [
+ [31, 34], [42, 26]
];
- let results = element._normalizeIntralineHighlights(content,
+ var results = element._normalizeIntralineHighlights(content,
highlights);
assert.deepEqual(results, [
{
@@ -395,7 +392,7 @@
contentIndex: 2,
startIndex: 0,
endIndex: 6,
- },
+ }
]);
content = [
@@ -442,18 +439,18 @@
contentIndex: 5,
startIndex: 12,
endIndex: 41,
- },
+ }
]);
});
- test('scrolling pauses rendering', () => {
- const contentRow = {
+ test('scrolling pauses rendering', function() {
+ var contentRow = {
ab: [
'<!DOCTYPE html>',
'<meta charset="utf-8">',
- ],
+ ]
};
- const content = _.times(200, _.constant(contentRow));
+ var content = _.times(200, _.constant(contentRow));
sandbox.stub(element, 'async');
element._isScrolling = true;
element.process(content);
@@ -463,14 +460,14 @@
assert.equal(element.groups.length, 33);
});
- test('image diffs', () => {
- const contentRow = {
+ test('image diffs', function() {
+ var contentRow = {
ab: [
'<!DOCTYPE html>',
'<meta charset="utf-8">',
- ],
+ ]
};
- const content = _.times(200, _.constant(contentRow));
+ var content = _.times(200, _.constant(contentRow));
sandbox.stub(element, 'async');
element.process(content, true);
assert.equal(element.groups.length, 1);
@@ -480,17 +477,17 @@
});
- suite('gr-diff-processor helpers', () => {
- let rows;
+ suite('gr-diff-processor helpers', function() {
+ var rows;
- setup(() => {
+ setup(function() {
rows = loremIpsum.split(' ');
});
- test('_sharedGroupsFromRows WHOLE_FILE', () => {
- const context = WHOLE_FILE;
- const lineNumbers = {left: 10, right: 100};
- const result = element._sharedGroupsFromRows(
+ test('_sharedGroupsFromRows WHOLE_FILE', function() {
+ var context = WHOLE_FILE;
+ var lineNumbers = {left: 10, right: 100};
+ var result = element._sharedGroupsFromRows(
rows, context, lineNumbers.left, lineNumbers.right, null);
// Results in one, uncollapsed group with all rows.
@@ -508,11 +505,11 @@
lineNumbers.right + rows.length);
});
- test('_sharedGroupsFromRows context', () => {
- const context = 10;
- const result = element._sharedGroupsFromRows(
+ test('_sharedGroupsFromRows context', function() {
+ var context = 10;
+ var result = element._sharedGroupsFromRows(
rows, context, 10, 100, null);
- const expectedCollapseSize = rows.length - 2 * context;
+ var expectedCollapseSize = rows.length - 2 * context;
assert.equal(result.length, 3, 'Results in three groups');
@@ -527,11 +524,11 @@
expectedCollapseSize);
});
- test('_sharedGroupsFromRows first', () => {
- const context = 10;
- const result = element._sharedGroupsFromRows(
+ test('_sharedGroupsFromRows first', function() {
+ var context = 10;
+ var result = element._sharedGroupsFromRows(
rows, context, 10, 100, 'first');
- const expectedCollapseSize = rows.length - context;
+ var expectedCollapseSize = rows.length - context;
assert.equal(result.length, 2, 'Results in two groups');
@@ -544,11 +541,11 @@
expectedCollapseSize);
});
- test('_sharedGroupsFromRows few-rows', () => {
+ test('_sharedGroupsFromRows few-rows', function() {
// Only ten rows.
rows = rows.slice(0, 10);
- const context = 10;
- const result = element._sharedGroupsFromRows(
+ var context = 10;
+ var result = element._sharedGroupsFromRows(
rows, context, 10, 100, 'first');
// Results in one uncollapsed group with all rows.
@@ -556,10 +553,10 @@
assert.equal(result[0].lines.length, rows.length);
});
- test('_sharedGroupsFromRows no single line collapse', () => {
+ test('_sharedGroupsFromRows no single line collapse', function() {
rows = rows.slice(0, 7);
- const context = 3;
- const result = element._sharedGroupsFromRows(
+ var context = 3;
+ var result = element._sharedGroupsFromRows(
rows, context, 10, 100);
// Results in one uncollapsed group with all rows.
@@ -567,9 +564,9 @@
assert.equal(result[0].lines.length, rows.length);
});
- test('_deltaLinesFromRows', () => {
- const startLineNum = 10;
- let result = element._deltaLinesFromRows(GrDiffLine.Type.ADD, rows,
+ test('_deltaLinesFromRows', function() {
+ var startLineNum = 10;
+ var result = element._deltaLinesFromRows(GrDiffLine.Type.ADD, rows,
startLineNum);
assert.equal(result.length, rows.length);
@@ -593,54 +590,54 @@
});
});
- suite('_breakdown*', () => {
- test('_breakdownGroup breaks down additions', () => {
+ suite('_breakdown*', function() {
+ test('_breakdownGroup breaks down additions', function() {
sandbox.spy(element, '_breakdown');
- const chunk = {b: ['blah', 'blah', 'blah']};
- const result = element._breakdownGroup(chunk);
+ var chunk = {b: ['blah', 'blah', 'blah']};
+ var result = element._breakdownGroup(chunk);
assert.deepEqual(result, [chunk]);
assert.isTrue(element._breakdown.called);
});
- test('_breakdown common case', () => {
- const array = 'Lorem ipsum dolor sit amet, suspendisse inceptos'
+ test('_breakdown common case', function() {
+ var array = 'Lorem ipsum dolor sit amet, suspendisse inceptos'
.split(' ');
- const size = 3;
+ var size = 3;
- const result = element._breakdown(array, size);
+ var result = element._breakdown(array, size);
- for (const subResult of result) {
+ result.forEach(function(subResult) {
assert.isAtMost(subResult.length, size);
- }
- const flattened = result
- .reduce((a, b) => { return a.concat(b); }, []);
+ });
+ var flattened = result
+ .reduce(function(a, b) { return a.concat(b); }, []);
assert.deepEqual(flattened, array);
});
- test('_breakdown smaller than size', () => {
- const array = 'Lorem ipsum dolor sit amet, suspendisse inceptos'
+ test('_breakdown smaller than size', function() {
+ var array = 'Lorem ipsum dolor sit amet, suspendisse inceptos'
.split(' ');
- const size = 10;
- const expected = [array];
+ var size = 10;
+ var expected = [array];
- const result = element._breakdown(array, size);
+ var result = element._breakdown(array, size);
assert.deepEqual(result, expected);
});
- test('_breakdown empty', () => {
- const array = [];
- const size = 10;
- const expected = [];
+ test('_breakdown empty', function() {
+ var array = [];
+ var size = 10;
+ var expected = [];
- const result = element._breakdown(array, size);
+ var result = element._breakdown(array, size);
assert.deepEqual(result, expected);
});
});
});
- test('detaching cancels', () => {
+ test('detaching cancels', function() {
element = fixture('basic');
sandbox.stub(element, 'cancel');
element.detached();